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