[Extra zoom mode] Adopt list view controller UI for select menus
[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 WKNumberPadViewController;
90 @class WKSelectMenuListViewController;
91 @class WKTextInputListViewController;
92 @class WKTimePickerViewController;
93 #endif
94
95 typedef void (^UIWKAutocorrectionCompletionHandler)(UIWKAutocorrectionRects *rectsForInput);
96 typedef void (^UIWKAutocorrectionContextHandler)(UIWKAutocorrectionContext *autocorrectionContext);
97 typedef void (^UIWKDictationContextHandler)(NSString *selectedText, NSString *beforeText, NSString *afterText);
98 typedef void (^UIWKSelectionCompletionHandler)(void);
99 typedef void (^UIWKSelectionWithDirectionCompletionHandler)(BOOL selectionEndIsMoving);
100 typedef void (^UIWKKeyWebEventCompletionHandler)(::WebEvent *theEvent, BOOL wasHandled);
101
102 typedef BlockPtr<void(WebKit::InteractionInformationAtPosition)> InteractionInformationCallback;
103 typedef std::pair<WebKit::InteractionInformationRequest, InteractionInformationCallback> InteractionInformationRequestAndCallback;
104
105 #define FOR_EACH_WKCONTENTVIEW_ACTION(M) \
106     M(_addShortcut) \
107     M(_arrowKey) \
108     M(_define) \
109     M(_lookup) \
110     M(_promptForReplace) \
111     M(_reanalyze) \
112     M(_share) \
113     M(_showTextStyleOptions) \
114     M(_transliterateChinese) \
115     M(copy) \
116     M(cut) \
117     M(paste) \
118     M(replace) \
119     M(select) \
120     M(selectAll) \
121     M(toggleBoldface) \
122     M(toggleItalics) \
123     M(toggleUnderline)
124
125 namespace WebKit {
126
127 struct WKSelectionDrawingInfo {
128     enum class SelectionType { None, Plugin, Range };
129     WKSelectionDrawingInfo();
130     explicit WKSelectionDrawingInfo(const EditorState&);
131     SelectionType type;
132     WebCore::IntRect caretRect;
133     Vector<WebCore::SelectionRect> selectionRects;
134 };
135
136 WTF::TextStream& operator<<(WTF::TextStream&, const WKSelectionDrawingInfo&);
137
138 struct WKAutoCorrectionData {
139     String fontName;
140     CGFloat fontSize;
141     uint64_t fontTraits;
142     CGRect textFirstRect;
143     CGRect textLastRect;
144     UIWKAutocorrectionCompletionHandler autocorrectionHandler;
145     UIWKAutocorrectionContextHandler autocorrectionContextHandler;
146 };
147
148 }
149
150 @interface WKContentView () {
151     RetainPtr<UIWebTouchEventsGestureRecognizer> _touchEventGestureRecognizer;
152
153     BOOL _canSendTouchEventsAsynchronously;
154
155     RetainPtr<WKSyntheticClickTapGestureRecognizer> _singleTapGestureRecognizer;
156     RetainPtr<_UIWebHighlightLongPressGestureRecognizer> _highlightLongPressGestureRecognizer;
157     RetainPtr<UILongPressGestureRecognizer> _longPressGestureRecognizer;
158     RetainPtr<UITapGestureRecognizer> _doubleTapGestureRecognizer;
159     RetainPtr<UITapGestureRecognizer> _nonBlockingDoubleTapGestureRecognizer;
160     RetainPtr<UITapGestureRecognizer> _twoFingerDoubleTapGestureRecognizer;
161     RetainPtr<UITapGestureRecognizer> _twoFingerSingleTapGestureRecognizer;
162     RetainPtr<WKInspectorNodeSearchGestureRecognizer> _inspectorNodeSearchGestureRecognizer;
163
164     RetainPtr<UIWKTextInteractionAssistant> _textSelectionAssistant;
165     RetainPtr<UIWKSelectionAssistant> _webSelectionAssistant;
166     BOOL _suppressAssistantSelectionView;
167
168     RetainPtr<UITextInputTraits> _traits;
169     RetainPtr<UIWebFormAccessory> _formAccessoryView;
170     RetainPtr<_UIHighlightView> _highlightView;
171     RetainPtr<UIView> _interactionViewsContainerView;
172     RetainPtr<NSString> _markedText;
173     RetainPtr<WKActionSheetAssistant> _actionSheetAssistant;
174     RetainPtr<WKAirPlayRoutePicker> _airPlayRoutePicker;
175     RetainPtr<WKFormInputSession> _formInputSession;
176     RetainPtr<WKFileUploadPanel> _fileUploadPanel;
177     RetainPtr<UIGestureRecognizer> _previewGestureRecognizer;
178     RetainPtr<UIGestureRecognizer> _previewSecondaryGestureRecognizer;
179     Vector<bool> _focusStateStack;
180 #if HAVE(LINK_PREVIEW)
181     RetainPtr<UIPreviewItemController> _previewItemController;
182 #endif
183
184     std::unique_ptr<WebKit::SmartMagnificationController> _smartMagnificationController;
185
186     id <UITextInputDelegate> _inputDelegate;
187
188     uint64_t _latestTapID;
189     struct TapHighlightInformation {
190         WebCore::Color color;
191         Vector<WebCore::FloatQuad> quads;
192         WebCore::IntSize topLeftRadius;
193         WebCore::IntSize topRightRadius;
194         WebCore::IntSize bottomLeftRadius;
195         WebCore::IntSize bottomRightRadius;
196     };
197     TapHighlightInformation _tapHighlightInformation;
198
199     WebKit::WKAutoCorrectionData _autocorrectionData;
200     WebKit::InteractionInformationAtPosition _positionInformation;
201     WebKit::AssistedNodeInformation _assistedNodeInformation;
202     RetainPtr<NSObject<WKFormPeripheral>> _inputPeripheral;
203     RetainPtr<UIEvent> _uiEventBeingResent;
204     UIWKKeyWebEventCompletionHandler _keyWebEventHandler;
205
206     CGPoint _lastInteractionLocation;
207     uint64_t _layerTreeTransactionIdAtLastTouchStart;
208
209     WebKit::WKSelectionDrawingInfo _lastSelectionDrawingInfo;
210
211     std::optional<WebKit::InteractionInformationRequest> _outstandingPositionInformationRequest;
212
213     uint64_t _positionInformationCallbackDepth;
214     Vector<std::optional<InteractionInformationRequestAndCallback>> _pendingPositionInformationHandlers;
215     
216     std::unique_ptr<WebKit::InputViewUpdateDeferrer> _inputViewUpdateDeferrer;
217
218     BOOL _isEditable;
219     BOOL _showingTextStyleOptions;
220     BOOL _hasValidPositionInformation;
221     BOOL _isTapHighlightIDValid;
222     BOOL _potentialTapInProgress;
223     BOOL _isDoubleTapPending;
224     BOOL _highlightLongPressCanClick;
225     BOOL _hasTapHighlightForPotentialTap;
226     BOOL _selectionNeedsUpdate;
227     BOOL _shouldRestoreSelection;
228     BOOL _usingGestureForSelection;
229     BOOL _inspectorNodeSearchEnabled;
230     BOOL _didAccessoryTabInitiateFocus;
231     BOOL _isExpectingFastSingleTapCommit;
232     BOOL _showDebugTapHighlightsForFastClicking;
233
234     BOOL _becomingFirstResponder;
235     BOOL _resigningFirstResponder;
236     BOOL _needsDeferredEndScrollingSelectionUpdate;
237     BOOL _isChangingFocus;
238     BOOL _isBlurringFocusedNode;
239
240     BOOL _focusRequiresStrongPasswordAssistance;
241
242 #if ENABLE(DATA_INTERACTION)
243     WebKit::DragDropInteractionState _dragDropInteractionState;
244     RetainPtr<UIDragInteraction> _dragInteraction;
245     RetainPtr<UIDropInteraction> _dropInteraction;
246     BOOL _shouldRestoreCalloutBarAfterDrop;
247     BOOL _isAnimatingConcludeEditDrag;
248     RetainPtr<UIView> _visibleContentViewSnapshot;
249     RetainPtr<_UITextDragCaretView> _editDropCaretView;
250 #endif
251
252 #if ENABLE(EXTRA_ZOOM_MODE)
253     RetainPtr<WKDatePickerViewController> _datePickerViewController;
254     RetainPtr<WKTextInputListViewController> _textInputListViewController;
255     RetainPtr<WKFocusedFormControlViewController> _focusedFormControlViewController;
256     RetainPtr<WKNumberPadViewController> _numberPadViewController;
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)