Allow long press to cancel link preview.
[WebKit-https.git] / Source / WebKit2 / UIProcess / ios / WKContentViewInteraction.h
1 /*
2  * Copyright (C) 2012-2014 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 "EditorState.h"
32 #import "GestureTypes.h"
33 #import "InteractionInformationAtPosition.h"
34 #import "UIKitSPI.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>
46
47 namespace WebCore {
48 class Color;
49 class FloatQuad;
50 class IntSize;
51 }
52
53 namespace WebKit {
54 class NativeWebTouchEvent;
55 class SmartMagnificationController;
56 class WebOpenPanelParameters;
57 class WebOpenPanelResultListenerProxy;
58 class WebPageProxy;
59 }
60
61 @class WKActionSheetAssistant;
62 @class WKFormInputSession;
63 @class WKInspectorNodeSearchGestureRecognizer;
64 @class WebIOSEvent;
65 @class _UIHighlightView;
66 @class _UIWebHighlightLongPressGestureRecognizer;
67
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);
73
74 namespace WebKit {
75 struct WKSelectionDrawingInfo {
76     enum class SelectionType { None, Plugin, Range };
77     WKSelectionDrawingInfo();
78     explicit WKSelectionDrawingInfo(const EditorState&);
79     SelectionType type;
80     WebCore::IntRect caretRect;
81     Vector<WebCore::SelectionRect> selectionRects;
82 };
83 struct WKAutoCorrectionData {
84     String fontName;
85     CGFloat fontSize;
86     uint64_t fontTraits;
87     CGRect textFirstRect;
88     CGRect textLastRect;
89     UIWKAutocorrectionCompletionHandler autocorrectionHandler;
90     UIWKAutocorrectionContextHandler autocorrectionContextHandler;
91 };
92
93 }
94
95 @interface WKContentView () {
96     RetainPtr<UIWebTouchEventsGestureRecognizer> _touchEventGestureRecognizer;
97
98     BOOL _canSendTouchEventsAsynchronously;
99
100     RetainPtr<WKSyntheticClickTapGestureRecognizer> _singleTapGestureRecognizer;
101     RetainPtr<_UIWebHighlightLongPressGestureRecognizer> _highlightLongPressGestureRecognizer;
102     RetainPtr<UILongPressGestureRecognizer> _longPressGestureRecognizer;
103     RetainPtr<UITapGestureRecognizer> _doubleTapGestureRecognizer;
104     RetainPtr<UITapGestureRecognizer> _twoFingerDoubleTapGestureRecognizer;
105     RetainPtr<WKInspectorNodeSearchGestureRecognizer> _inspectorNodeSearchGestureRecognizer;
106
107     RetainPtr<UIWKTextInteractionAssistant> _textSelectionAssistant;
108     RetainPtr<UIWKSelectionAssistant> _webSelectionAssistant;
109
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;
123 #endif
124
125     std::unique_ptr<WebKit::SmartMagnificationController> _smartMagnificationController;
126
127     id <UITextInputDelegate> _inputDelegate;
128
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;
137     };
138     TapHighlightInformation _tapHighlightInformation;
139
140     WebKit::WKAutoCorrectionData _autocorrectionData;
141     WebKit::InteractionInformationAtPosition _positionInformation;
142     WebKit::AssistedNodeInformation _assistedNodeInformation;
143     RetainPtr<NSObject<WKFormPeripheral>> _inputPeripheral;
144
145     CGPoint _lastInteractionLocation;
146
147     WebKit::WKSelectionDrawingInfo _lastSelectionDrawingInfo;
148
149     BOOL _isEditable;
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;
161 }
162
163 @end
164
165 @interface WKContentView (WKInteraction) <UIGestureRecognizerDelegate, UIWebTouchEventsGestureRecognizerDelegate, UITextInputPrivate, UIWebFormAccessoryDelegate, UIWKInteractionViewProtocol, WKFileUploadPanelDelegate, WKActionSheetAssistantDelegate>
166
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;
173
174 - (void)setupInteraction;
175 - (void)cleanupInteraction;
176
177 - (void)scrollViewWillStartPanOrPinchGesture;
178
179 #if ENABLE(TOUCH_EVENTS)
180 - (void)_webTouchEvent:(const WebKit::NativeWebTouchEvent&)touchEvent preventsNativeGestures:(BOOL)preventsDefault;
181 #endif
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;
184
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;
193 - (void)_didScroll;
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;
206 @end
207
208 #if HAVE(LINK_PREVIEW)
209 @interface WKContentView (WKInteractionPreview) <UIPreviewItemDelegate>
210
211 - (void)_registerPreview;
212 - (void)_unregisterPreview;
213 @end
214 #endif
215
216 #endif // PLATFORM(IOS)