2 * Copyright (C) 2012-2014 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
28 #import "WKContentView.h"
30 #import "AssistedNodeInformation.h"
31 #import "EditorState.h"
32 #import "GestureTypes.h"
33 #import "InteractionInformationAtPosition.h"
35 #import "WKActionSheetAssistant.h"
36 #import "WKAirPlayRoutePicker.h"
37 #import "WKFileUploadPanel.h"
38 #import "WKFormPeripheral.h"
39 #import "WKSyntheticClickTapGestureRecognizer.h"
40 #import <UIKit/UIView.h>
41 #import <WebCore/Color.h>
42 #import <WebCore/FloatQuad.h>
43 #import <wtf/Forward.h>
44 #import <wtf/Vector.h>
45 #import <wtf/text/WTFString.h>
54 class NativeWebTouchEvent;
55 class SmartMagnificationController;
56 class WebOpenPanelParameters;
57 class WebOpenPanelResultListenerProxy;
61 @class WKActionSheetAssistant;
62 @class WKFormInputSession;
63 @class WKInspectorNodeSearchGestureRecognizer;
65 @class _UIHighlightView;
66 @class _UIWebHighlightLongPressGestureRecognizer;
68 typedef void (^UIWKAutocorrectionCompletionHandler)(UIWKAutocorrectionRects *rectsForInput);
69 typedef void (^UIWKAutocorrectionContextHandler)(UIWKAutocorrectionContext *autocorrectionContext);
70 typedef void (^UIWKDictationContextHandler)(NSString *selectedText, NSString *beforeText, NSString *afterText);
71 typedef void (^UIWKSelectionCompletionHandler)(void);
72 typedef void (^UIWKSelectionWithDirectionCompletionHandler)(BOOL selectionEndIsMoving);
75 struct WKSelectionDrawingInfo {
76 enum class SelectionType { None, Plugin, Range };
77 WKSelectionDrawingInfo();
78 explicit WKSelectionDrawingInfo(const EditorState&);
80 WebCore::IntRect caretRect;
81 Vector<WebCore::SelectionRect> selectionRects;
83 struct WKAutoCorrectionData {
89 UIWKAutocorrectionCompletionHandler autocorrectionHandler;
90 UIWKAutocorrectionContextHandler autocorrectionContextHandler;
95 @interface WKContentView () {
96 RetainPtr<UIWebTouchEventsGestureRecognizer> _touchEventGestureRecognizer;
98 BOOL _canSendTouchEventsAsynchronously;
100 RetainPtr<WKSyntheticClickTapGestureRecognizer> _singleTapGestureRecognizer;
101 RetainPtr<_UIWebHighlightLongPressGestureRecognizer> _highlightLongPressGestureRecognizer;
102 RetainPtr<UILongPressGestureRecognizer> _longPressGestureRecognizer;
103 RetainPtr<UITapGestureRecognizer> _doubleTapGestureRecognizer;
104 RetainPtr<UITapGestureRecognizer> _twoFingerDoubleTapGestureRecognizer;
105 RetainPtr<WKInspectorNodeSearchGestureRecognizer> _inspectorNodeSearchGestureRecognizer;
107 RetainPtr<UIWKTextInteractionAssistant> _textSelectionAssistant;
108 RetainPtr<UIWKSelectionAssistant> _webSelectionAssistant;
110 RetainPtr<UITextInputTraits> _traits;
111 RetainPtr<UIWebFormAccessory> _formAccessoryView;
112 RetainPtr<_UIHighlightView> _highlightView;
113 RetainPtr<UIView> _interactionViewsContainerView;
114 RetainPtr<NSString> _markedText;
115 RetainPtr<WKActionSheetAssistant> _actionSheetAssistant;
116 RetainPtr<WKAirPlayRoutePicker> _airPlayRoutePicker;
117 RetainPtr<WKFormInputSession> _formInputSession;
118 RetainPtr<WKFileUploadPanel> _fileUploadPanel;
119 RetainPtr<UIGestureRecognizer> _previewGestureRecognizer;
120 RetainPtr<UIGestureRecognizer> _previewSecondaryGestureRecognizer;
121 #if HAVE(LINK_PREVIEW)
122 RetainPtr<UIPreviewItemController> _previewItemController;
125 std::unique_ptr<WebKit::SmartMagnificationController> _smartMagnificationController;
127 id <UITextInputDelegate> _inputDelegate;
129 uint64_t _latestTapHighlightID;
130 struct TapHighlightInformation {
131 WebCore::Color color;
132 Vector<WebCore::FloatQuad> quads;
133 WebCore::IntSize topLeftRadius;
134 WebCore::IntSize topRightRadius;
135 WebCore::IntSize bottomLeftRadius;
136 WebCore::IntSize bottomRightRadius;
138 TapHighlightInformation _tapHighlightInformation;
140 WebKit::WKAutoCorrectionData _autocorrectionData;
141 WebKit::InteractionInformationAtPosition _positionInformation;
142 WebKit::AssistedNodeInformation _assistedNodeInformation;
143 RetainPtr<NSObject<WKFormPeripheral>> _inputPeripheral;
145 CGPoint _lastInteractionLocation;
147 WebKit::WKSelectionDrawingInfo _lastSelectionDrawingInfo;
150 BOOL _showingTextStyleOptions;
151 BOOL _hasValidPositionInformation;
152 BOOL _isTapHighlightIDValid;
153 BOOL _potentialTapInProgress;
154 BOOL _highlightLongPressCanClick;
155 BOOL _hasTapHighlightForPotentialTap;
156 BOOL _selectionNeedsUpdate;
157 BOOL _shouldRestoreSelection;
158 BOOL _usingGestureForSelection;
159 BOOL _inspectorNodeSearchEnabled;
160 BOOL _didAccessoryTabInitiateFocus;
165 @interface WKContentView (WKInteraction) <UIGestureRecognizerDelegate, UIWebTouchEventsGestureRecognizerDelegate, UITextInputPrivate, UIWebFormAccessoryDelegate, UIWKInteractionViewProtocol, WKFileUploadPanelDelegate, WKActionSheetAssistantDelegate>
167 @property (nonatomic, readonly) CGPoint lastInteractionLocation;
168 @property (nonatomic, readonly) BOOL isEditable;
169 @property (nonatomic, readonly) const WebKit::InteractionInformationAtPosition& positionInformation;
170 @property (nonatomic, readonly) const WebKit::WKAutoCorrectionData& autocorrectionData;
171 @property (nonatomic, readonly) const WebKit::AssistedNodeInformation& assistedNodeInformation;
172 @property (nonatomic, readonly) UIWebFormAccessory *formAccessoryView;
174 - (void)setupInteraction;
175 - (void)cleanupInteraction;
177 - (void)scrollViewWillStartPanOrPinchGesture;
179 #if ENABLE(TOUCH_EVENTS)
180 - (void)_webTouchEvent:(const WebKit::NativeWebTouchEvent&)touchEvent preventsNativeGestures:(BOOL)preventsDefault;
182 - (void)_commitPotentialTapFailed;
183 - (void)_didGetTapHighlightForRequest:(uint64_t)requestID color:(const WebCore::Color&)color quads:(const Vector<WebCore::FloatQuad>&)highlightedQuads topLeftRadius:(const WebCore::IntSize&)topLeftRadius topRightRadius:(const WebCore::IntSize&)topRightRadius bottomLeftRadius:(const WebCore::IntSize&)bottomLeftRadius bottomRightRadius:(const WebCore::IntSize&)bottomRightRadius;
185 - (void)_startAssistingNode:(const WebKit::AssistedNodeInformation&)information userIsInteracting:(BOOL)userIsInteracting blurPreviousNode:(BOOL)blurPreviousNode userObject:(NSObject <NSSecureCoding> *)userObject;
186 - (void)_stopAssistingNode;
187 - (void)_selectionChanged;
188 - (void)_updateChangedSelection;
189 - (BOOL)_interpretKeyEvent:(WebIOSEvent *)theEvent isCharEvent:(BOOL)isCharEvent;
190 - (void)_positionInformationDidChange:(const WebKit::InteractionInformationAtPosition&)info;
191 - (void)_attemptClickAtLocation:(CGPoint)location;
192 - (void)_willStartScrollingOrZooming;
194 - (void)_didEndScrollingOrZooming;
195 - (void)_overflowScrollingWillBegin;
196 - (void)_overflowScrollingDidEnd;
197 - (void)_didUpdateBlockSelectionWithTouch:(WebKit::SelectionTouch)touch withFlags:(WebKit::SelectionFlags)flags growThreshold:(CGFloat)growThreshold shrinkThreshold:(CGFloat)shrinkThreshold;
198 - (void)_showPlaybackTargetPicker:(BOOL)hasVideo fromRect:(const WebCore::IntRect&)elementRect;
199 - (void)_showRunOpenPanel:(WebKit::WebOpenPanelParameters*)parameters resultListener:(WebKit::WebOpenPanelResultListenerProxy*)listener;
200 - (void)accessoryDone;
201 - (void)_didHandleKeyEvent:(WebIOSEvent *)event;
202 - (Vector<WebKit::OptionItem>&) assistedNodeSelectOptions;
203 - (void)_enableInspectorNodeSearch;
204 - (void)_disableInspectorNodeSearch;
205 - (void)_becomeFirstResponderWithSelectionMovingForward:(BOOL)selectingForward completionHandler:(void (^)(BOOL didBecomeFirstResponder))completionHandler;
208 #if HAVE(LINK_PREVIEW)
209 @interface WKContentView (WKInteractionPreview) <UIPreviewItemDelegate>
211 - (void)_registerPreview;
212 - (void)_unregisterPreview;
216 #endif // PLATFORM(IOS)