[iOS DnD] Elements in the DOM with the `draggable` attribute should be draggable
[WebKit-https.git] / Source / WebKit / UIProcess / ios / WKContentViewInteraction.h
1 /*
2  * Copyright (C) 2012-2017 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
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.
12  *
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.
24  */
25
26 #if PLATFORM(IOS)
27
28 #import "WKContentView.h"
29
30 #import "AssistedNodeInformation.h"
31 #import "DragDropInteractionState.h"
32 #import "EditorState.h"
33 #import "GestureTypes.h"
34 #import "InteractionInformationAtPosition.h"
35 #import "UIKitSPI.h"
36 #import "WKActionSheetAssistant.h"
37 #import "WKAirPlayRoutePicker.h"
38 #import "WKFileUploadPanel.h"
39 #import "WKFormPeripheral.h"
40 #import "WKSyntheticClickTapGestureRecognizer.h"
41 #import <UIKit/UIView.h>
42 #import <WebCore/Color.h>
43 #import <WebCore/FloatQuad.h>
44 #import <wtf/BlockPtr.h>
45 #import <wtf/Forward.h>
46 #import <wtf/Vector.h>
47 #import <wtf/text/WTFString.h>
48
49 namespace API {
50 class OpenPanelParameters;
51 }
52
53 namespace WTF {
54 class TextStream;
55 }
56
57 namespace WebCore {
58 class Color;
59 class FloatQuad;
60 class IntSize;
61 class SelectionRect;
62 }
63
64 #if ENABLE(DRAG_SUPPORT)
65 namespace WebCore {
66 struct DragItem;
67 }
68 #endif
69
70 namespace WebKit {
71 class InputViewUpdateDeferrer;
72 class NativeWebTouchEvent;
73 class SmartMagnificationController;
74 class WebOpenPanelResultListenerProxy;
75 class WebPageProxy;
76 }
77
78 @class WKActionSheetAssistant;
79 @class WKFormInputSession;
80 @class WKInspectorNodeSearchGestureRecognizer;
81 @class WebEvent;
82 @class _UIHighlightView;
83 @class _UIWebHighlightLongPressGestureRecognizer;
84
85 #if ENABLE(DATA_INTERACTION)
86 @class _UITextDragCaretView;
87 #endif
88
89 typedef void (^UIWKAutocorrectionCompletionHandler)(UIWKAutocorrectionRects *rectsForInput);
90 typedef void (^UIWKAutocorrectionContextHandler)(UIWKAutocorrectionContext *autocorrectionContext);
91 typedef void (^UIWKDictationContextHandler)(NSString *selectedText, NSString *beforeText, NSString *afterText);
92 typedef void (^UIWKSelectionCompletionHandler)(void);
93 typedef void (^UIWKSelectionWithDirectionCompletionHandler)(BOOL selectionEndIsMoving);
94 typedef void (^UIWKKeyWebEventCompletionHandler)(::WebEvent *theEvent, BOOL wasHandled);
95
96 typedef BlockPtr<void(WebKit::InteractionInformationAtPosition)> InteractionInformationCallback;
97 typedef std::pair<WebKit::InteractionInformationRequest, InteractionInformationCallback> InteractionInformationRequestAndCallback;
98
99 #define FOR_EACH_WKCONTENTVIEW_ACTION(M) \
100     M(_addShortcut) \
101     M(_arrowKey) \
102     M(_define) \
103     M(_lookup) \
104     M(_promptForReplace) \
105     M(_reanalyze) \
106     M(_share) \
107     M(_showTextStyleOptions) \
108     M(_transliterateChinese) \
109     M(copy) \
110     M(cut) \
111     M(paste) \
112     M(replace) \
113     M(select) \
114     M(selectAll) \
115     M(toggleBoldface) \
116     M(toggleItalics) \
117     M(toggleUnderline)
118
119 namespace WebKit {
120
121 struct WKSelectionDrawingInfo {
122     enum class SelectionType { None, Plugin, Range };
123     WKSelectionDrawingInfo();
124     explicit WKSelectionDrawingInfo(const EditorState&);
125     SelectionType type;
126     WebCore::IntRect caretRect;
127     Vector<WebCore::SelectionRect> selectionRects;
128 };
129
130 WTF::TextStream& operator<<(WTF::TextStream&, const WKSelectionDrawingInfo&);
131
132 struct WKAutoCorrectionData {
133     String fontName;
134     CGFloat fontSize;
135     uint64_t fontTraits;
136     CGRect textFirstRect;
137     CGRect textLastRect;
138     UIWKAutocorrectionCompletionHandler autocorrectionHandler;
139     UIWKAutocorrectionContextHandler autocorrectionContextHandler;
140 };
141
142 }
143
144 @interface WKContentView () {
145     RetainPtr<UIWebTouchEventsGestureRecognizer> _touchEventGestureRecognizer;
146
147     BOOL _canSendTouchEventsAsynchronously;
148
149     RetainPtr<WKSyntheticClickTapGestureRecognizer> _singleTapGestureRecognizer;
150     RetainPtr<_UIWebHighlightLongPressGestureRecognizer> _highlightLongPressGestureRecognizer;
151     RetainPtr<UILongPressGestureRecognizer> _longPressGestureRecognizer;
152     RetainPtr<UITapGestureRecognizer> _doubleTapGestureRecognizer;
153     RetainPtr<UITapGestureRecognizer> _nonBlockingDoubleTapGestureRecognizer;
154     RetainPtr<UITapGestureRecognizer> _twoFingerDoubleTapGestureRecognizer;
155     RetainPtr<UITapGestureRecognizer> _twoFingerSingleTapGestureRecognizer;
156     RetainPtr<WKInspectorNodeSearchGestureRecognizer> _inspectorNodeSearchGestureRecognizer;
157
158     RetainPtr<UIWKTextInteractionAssistant> _textSelectionAssistant;
159     RetainPtr<UIWKSelectionAssistant> _webSelectionAssistant;
160     BOOL _suppressAssistantSelectionView;
161
162     RetainPtr<UITextInputTraits> _traits;
163     RetainPtr<UIWebFormAccessory> _formAccessoryView;
164     RetainPtr<_UIHighlightView> _highlightView;
165     RetainPtr<UIView> _interactionViewsContainerView;
166     RetainPtr<NSString> _markedText;
167     RetainPtr<WKActionSheetAssistant> _actionSheetAssistant;
168     RetainPtr<WKAirPlayRoutePicker> _airPlayRoutePicker;
169     RetainPtr<WKFormInputSession> _formInputSession;
170     RetainPtr<WKFileUploadPanel> _fileUploadPanel;
171     RetainPtr<UIGestureRecognizer> _previewGestureRecognizer;
172     RetainPtr<UIGestureRecognizer> _previewSecondaryGestureRecognizer;
173 #if HAVE(LINK_PREVIEW)
174     RetainPtr<UIPreviewItemController> _previewItemController;
175 #endif
176
177     std::unique_ptr<WebKit::SmartMagnificationController> _smartMagnificationController;
178
179     id <UITextInputDelegate> _inputDelegate;
180
181     uint64_t _latestTapID;
182     struct TapHighlightInformation {
183         WebCore::Color color;
184         Vector<WebCore::FloatQuad> quads;
185         WebCore::IntSize topLeftRadius;
186         WebCore::IntSize topRightRadius;
187         WebCore::IntSize bottomLeftRadius;
188         WebCore::IntSize bottomRightRadius;
189     };
190     TapHighlightInformation _tapHighlightInformation;
191
192     WebKit::WKAutoCorrectionData _autocorrectionData;
193     WebKit::InteractionInformationAtPosition _positionInformation;
194     WebKit::AssistedNodeInformation _assistedNodeInformation;
195     RetainPtr<NSObject<WKFormPeripheral>> _inputPeripheral;
196     RetainPtr<UIEvent> _uiEventBeingResent;
197     UIWKKeyWebEventCompletionHandler _keyWebEventHandler;
198
199     CGPoint _lastInteractionLocation;
200     uint64_t _layerTreeTransactionIdAtLastTouchStart;
201
202     WebKit::WKSelectionDrawingInfo _lastSelectionDrawingInfo;
203
204     std::optional<WebKit::InteractionInformationRequest> _outstandingPositionInformationRequest;
205
206     uint64_t _positionInformationCallbackDepth;
207     Vector<std::optional<InteractionInformationRequestAndCallback>> _pendingPositionInformationHandlers;
208     
209     std::unique_ptr<WebKit::InputViewUpdateDeferrer> _inputViewUpdateDeferrer;
210
211     BOOL _isEditable;
212     BOOL _showingTextStyleOptions;
213     BOOL _hasValidPositionInformation;
214     BOOL _isTapHighlightIDValid;
215     BOOL _potentialTapInProgress;
216     BOOL _isDoubleTapPending;
217     BOOL _highlightLongPressCanClick;
218     BOOL _hasTapHighlightForPotentialTap;
219     BOOL _selectionNeedsUpdate;
220     BOOL _shouldRestoreSelection;
221     BOOL _usingGestureForSelection;
222     BOOL _inspectorNodeSearchEnabled;
223     BOOL _didAccessoryTabInitiateFocus;
224     BOOL _isExpectingFastSingleTapCommit;
225     BOOL _showDebugTapHighlightsForFastClicking;
226
227     BOOL _becomingFirstResponder;
228     BOOL _resigningFirstResponder;
229     BOOL _needsDeferredEndScrollingSelectionUpdate;
230
231 #if ENABLE(DATA_INTERACTION)
232     WebKit::DragDropInteractionState _dragDropInteractionState;
233     RetainPtr<UIDragInteraction> _dragInteraction;
234     RetainPtr<UIDropInteraction> _dropInteraction;
235     BOOL _shouldRestoreCalloutBarAfterDrop;
236     BOOL _isAnimatingConcludeEditDrag;
237     RetainPtr<UIView> _visibleContentViewSnapshot;
238     RetainPtr<_UITextDragCaretView> _editDropCaretView;
239 #endif
240 }
241
242 @end
243
244 @interface WKContentView (WKInteraction) <UIGestureRecognizerDelegate, UIWebTouchEventsGestureRecognizerDelegate, UITextInputPrivate, UIWebFormAccessoryDelegate, UIWKInteractionViewProtocol, WKFileUploadPanelDelegate, WKActionSheetAssistantDelegate
245 #if ENABLE(DATA_INTERACTION)
246     , UIDragInteractionDelegate, UIDropInteractionDelegate
247 #endif
248 >
249
250 @property (nonatomic, readonly) CGPoint lastInteractionLocation;
251 @property (nonatomic, readonly) BOOL isEditable;
252 @property (nonatomic, readonly) BOOL shouldHideSelectionWhenScrolling;
253 @property (nonatomic, readonly) const WebKit::InteractionInformationAtPosition& positionInformation;
254 @property (nonatomic, readonly) const WebKit::WKAutoCorrectionData& autocorrectionData;
255 @property (nonatomic, readonly) const WebKit::AssistedNodeInformation& assistedNodeInformation;
256 @property (nonatomic, readonly) UIWebFormAccessory *formAccessoryView;
257 @property (nonatomic) BOOL suppressAssistantSelectionView;
258
259 - (void)setupInteraction;
260 - (void)cleanupInteraction;
261
262 - (void)scrollViewWillStartPanOrPinchGesture;
263
264 - (BOOL)canBecomeFirstResponderForWebView;
265 - (BOOL)becomeFirstResponderForWebView;
266 - (BOOL)resignFirstResponderForWebView;
267 - (BOOL)canPerformActionForWebView:(SEL)action withSender:(id)sender;
268 - (id)targetForActionForWebView:(SEL)action withSender:(id)sender;
269
270 #define DECLARE_WKCONTENTVIEW_ACTION_FOR_WEB_VIEW(_action) \
271     - (void)_action ## ForWebView:(id)sender;
272 FOR_EACH_WKCONTENTVIEW_ACTION(DECLARE_WKCONTENTVIEW_ACTION_FOR_WEB_VIEW)
273 #undef DECLARE_WKCONTENTVIEW_ACTION_FOR_WEB_VIEW
274
275 #if ENABLE(TOUCH_EVENTS)
276 - (void)_webTouchEvent:(const WebKit::NativeWebTouchEvent&)touchEvent preventsNativeGestures:(BOOL)preventsDefault;
277 #endif
278 - (void)_commitPotentialTapFailed;
279 - (void)_didNotHandleTapAsClick:(const WebCore::IntPoint&)point;
280 - (void)_didCompleteSyntheticClick;
281 - (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;
282
283 - (BOOL)_mayDisableDoubleTapGesturesDuringSingleTap;
284 - (void)_disableDoubleTapGesturesDuringTapIfNecessary:(uint64_t)requestID;
285 - (void)_startAssistingNode:(const WebKit::AssistedNodeInformation&)information userIsInteracting:(BOOL)userIsInteracting blurPreviousNode:(BOOL)blurPreviousNode userObject:(NSObject <NSSecureCoding> *)userObject;
286 - (void)_stopAssistingNode;
287 - (void)_selectionChanged;
288 - (void)_updateChangedSelection;
289 - (BOOL)_interpretKeyEvent:(::WebEvent *)theEvent isCharEvent:(BOOL)isCharEvent;
290 - (void)_positionInformationDidChange:(const WebKit::InteractionInformationAtPosition&)info;
291 - (void)_attemptClickAtLocation:(CGPoint)location;
292 - (void)_willStartScrollingOrZooming;
293 - (void)_didScroll;
294 - (void)_didEndScrollingOrZooming;
295 - (void)_overflowScrollingWillBegin;
296 - (void)_overflowScrollingDidEnd;
297 - (void)_didUpdateBlockSelectionWithTouch:(WebKit::SelectionTouch)touch withFlags:(WebKit::SelectionFlags)flags growThreshold:(CGFloat)growThreshold shrinkThreshold:(CGFloat)shrinkThreshold;
298 - (void)_showPlaybackTargetPicker:(BOOL)hasVideo fromRect:(const WebCore::IntRect&)elementRect;
299 - (void)_showRunOpenPanel:(API::OpenPanelParameters*)parameters resultListener:(WebKit::WebOpenPanelResultListenerProxy*)listener;
300 - (void)accessoryDone;
301 - (void)_didHandleKeyEvent:(::WebEvent *)event eventWasHandled:(BOOL)eventWasHandled;
302 - (Vector<WebKit::OptionItem>&) assistedNodeSelectOptions;
303 - (void)_enableInspectorNodeSearch;
304 - (void)_disableInspectorNodeSearch;
305 - (void)_becomeFirstResponderWithSelectionMovingForward:(BOOL)selectingForward completionHandler:(void (^)(BOOL didBecomeFirstResponder))completionHandler;
306 - (void)_setDoubleTapGesturesEnabled:(BOOL)enabled;
307 #if ENABLE(DATA_DETECTION)
308 - (NSArray *)_dataDetectionResults;
309 #endif
310 - (NSArray<NSValue *> *)_uiTextSelectionRects;
311 - (void)accessibilityRetrieveSpeakSelectionContent;
312 - (void)_accessibilityRetrieveRectsEnclosingSelectionOffset:(NSInteger)offset withGranularity:(UITextGranularity)granularity;
313 - (void)_accessibilityRetrieveRectsAtSelectionOffset:(NSInteger)offset withText:(NSString *)text completionHandler:(void (^)(const Vector<WebCore::SelectionRect>& rects))completionHandler;
314 - (void)_accessibilityRetrieveRectsAtSelectionOffset:(NSInteger)offset withText:(NSString *)text;
315
316 @property (nonatomic, readonly) WebKit::InteractionInformationAtPosition currentPositionInformation;
317 - (void)doAfterPositionInformationUpdate:(void (^)(WebKit::InteractionInformationAtPosition))action forRequest:(WebKit::InteractionInformationRequest)request;
318 - (BOOL)ensurePositionInformationIsUpToDate:(WebKit::InteractionInformationRequest)request;
319
320 #if ENABLE(DATA_INTERACTION)
321 - (void)_didChangeDragInteractionPolicy;
322 - (void)_didPerformDataInteractionControllerOperation:(BOOL)handled;
323 - (void)_didHandleStartDataInteractionRequest:(BOOL)started;
324 - (void)_didHandleAdditionalDragItemsRequest:(BOOL)added;
325 - (void)_startDrag:(RetainPtr<CGImageRef>)image item:(const WebCore::DragItem&)item;
326 - (void)_didConcludeEditDataInteraction:(std::optional<WebCore::TextIndicatorData>)data;
327 - (void)_didChangeDataInteractionCaretRect:(CGRect)previousRect currentRect:(CGRect)rect;
328 #endif
329
330 @end
331
332 @interface WKContentView (WKTesting)
333
334 - (void)_simulateLongPressActionAtLocation:(CGPoint)location;
335 - (void)selectFormAccessoryPickerRow:(NSInteger)rowIndex;
336 - (NSDictionary *)_contentsOfUserInterfaceItem:(NSString *)userInterfaceItem;
337
338 @end
339
340 #if HAVE(LINK_PREVIEW)
341 @interface WKContentView (WKInteractionPreview) <UIPreviewItemDelegate>
342
343 - (void)_registerPreview;
344 - (void)_unregisterPreview;
345 @end
346 #endif
347
348 #endif // PLATFORM(IOS)