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