[iOS][WK2] Distant focusable element may not be scrolled into view when focused using...
[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 "GestureTypes.h"
32 #import "InteractionInformationAtPosition.h"
33 #import "WKSyntheticClickTapGestureRecognizer.h"
34 #import "WKAirPlayRoutePicker.h"
35 #import "WKFileUploadPanel.h"
36 #import "WKFormPeripheral.h"
37 #import <UIKit/UITextInput_Private.h>
38 #import <UIKit/UIView.h>
39 #import <UIKit/UIWKSelectionAssistant.h>
40 #import <UIKit/UIWKTextInteractionAssistant.h>
41 #import <UIKit/UIWebFormAccessory.h>
42 #import <UIKit/UIWebTouchEventsGestureRecognizer.h>
43 #import <WebCore/Color.h>
44 #import <WebCore/FloatQuad.h>
45 #import <wtf/Forward.h>
46 #import <wtf/Vector.h>
47 #import <wtf/text/WTFString.h>
48
49 namespace WebCore {
50 class Color;
51 class FloatQuad;
52 class IntSize;
53 }
54
55 namespace WebKit {
56 class NativeWebTouchEvent;
57 class SmartMagnificationController;
58 class WebOpenPanelParameters;
59 class WebOpenPanelResultListenerProxy;
60 class WebPageProxy;
61 }
62
63 @class WKActionSheetAssistant;
64 @class WKFormInputSession;
65 @class WKInspectorNodeSearchGestureRecognizer;
66 @class WebIOSEvent;
67 @class _UIHighlightView;
68 @class _UIWebHighlightLongPressGestureRecognizer;
69
70 typedef void (^UIWKAutocorrectionCompletionHandler)(UIWKAutocorrectionRects *rectsForInput);
71 typedef void (^UIWKAutocorrectionContextHandler)(UIWKAutocorrectionContext *autocorrectionContext);
72 typedef void (^UIWKDictationContextHandler)(NSString *selectedText, NSString *beforeText, NSString *afterText);
73
74 namespace WebKit {
75 struct WKAutoCorrectionData {
76     String fontName;
77     CGFloat fontSize;
78     uint64_t fontTraits;
79     CGRect textFirstRect;
80     CGRect textLastRect;
81     UIWKAutocorrectionCompletionHandler autocorrectionHandler;
82     UIWKAutocorrectionContextHandler autocorrectionContextHandler;
83 };
84 }
85
86 @interface WKContentView () {
87     RetainPtr<UIWebTouchEventsGestureRecognizer> _touchEventGestureRecognizer;
88
89     BOOL _canSendTouchEventsAsynchronously;
90
91     RetainPtr<WKSyntheticClickTapGestureRecognizer> _singleTapGestureRecognizer;
92     RetainPtr<_UIWebHighlightLongPressGestureRecognizer> _highlightLongPressGestureRecognizer;
93     RetainPtr<UILongPressGestureRecognizer> _longPressGestureRecognizer;
94     RetainPtr<UITapGestureRecognizer> _doubleTapGestureRecognizer;
95     RetainPtr<UITapGestureRecognizer> _twoFingerDoubleTapGestureRecognizer;
96     RetainPtr<WKInspectorNodeSearchGestureRecognizer> _inspectorNodeSearchGestureRecognizer;
97
98     RetainPtr<UIWKTextInteractionAssistant> _textSelectionAssistant;
99     RetainPtr<UIWKSelectionAssistant> _webSelectionAssistant;
100
101     RetainPtr<UITextInputTraits> _traits;
102     RetainPtr<UIWebFormAccessory> _formAccessoryView;
103     RetainPtr<UIView> _highlightRootView;
104     RetainPtr<_UIHighlightView> _highlightView;
105     RetainPtr<UIView> _inverseScaleRootView;
106     RetainPtr<NSString> _markedText;
107     RetainPtr<WKActionSheetAssistant> _actionSheetAssistant;
108     RetainPtr<WKAirPlayRoutePicker> _airPlayRoutePicker;
109     RetainPtr<WKFormInputSession> _formInputSession;
110     RetainPtr<WKFileUploadPanel> _fileUploadPanel;
111
112     std::unique_ptr<WebKit::SmartMagnificationController> _smartMagnificationController;
113
114     id <UITextInputDelegate> _inputDelegate;
115
116     uint64_t _latestTapHighlightID;
117     struct TapHighlightInformation {
118         WebCore::Color color;
119         Vector<WebCore::FloatQuad> quads;
120         WebCore::IntSize topLeftRadius;
121         WebCore::IntSize topRightRadius;
122         WebCore::IntSize bottomLeftRadius;
123         WebCore::IntSize bottomRightRadius;
124     };
125     std::unique_ptr<TapHighlightInformation> _potentialTapHighlightInformation;
126
127     WebKit::WKAutoCorrectionData _autocorrectionData;
128     WebKit::InteractionInformationAtPosition _positionInformation;
129     WebKit::AssistedNodeInformation _assistedNodeInformation;
130     RetainPtr<NSObject<WKFormPeripheral>> _inputPeripheral;
131
132     CGPoint _lastInteractionLocation;
133
134     BOOL _isEditable;
135     BOOL _showingTextStyleOptions;
136     BOOL _hasValidPositionInformation;
137     BOOL _isTapHighlightIDValid;
138     BOOL _potentialTapInProgress;
139     BOOL _selectionNeedsUpdate;
140     BOOL _usingGestureForSelection;
141     BOOL _inspectorNodeSearchEnabled;
142     BOOL _didAccessoryTabInitiateFocus;
143 }
144
145 @end
146
147 @interface WKContentView (WKInteraction) <UIGestureRecognizerDelegate, UIWebTouchEventsGestureRecognizerDelegate, UITextInputPrivate, UIWebFormAccessoryDelegate, UIWKInteractionViewProtocol, WKFileUploadPanelDelegate>
148
149 @property (nonatomic, readonly) CGPoint lastInteractionLocation;
150 @property (nonatomic, readonly) BOOL isEditable;
151 @property (nonatomic, readonly) const WebKit::InteractionInformationAtPosition& positionInformation;
152 @property (nonatomic, readonly) const WebKit::WKAutoCorrectionData& autocorrectionData;
153 @property (nonatomic, readonly) const WebKit::AssistedNodeInformation& assistedNodeInformation;
154 @property (nonatomic, readonly) UIWebFormAccessory *formAccessoryView;
155
156 - (void)setupInteraction;
157 - (void)cleanupInteraction;
158
159 - (void)scrollViewWillStartPanOrPinchGesture;
160
161 - (void)_webTouchEvent:(const WebKit::NativeWebTouchEvent&)touchEvent preventsNativeGestures:(BOOL)preventsDefault;
162 - (void)_commitPotentialTapFailed;
163 - (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;
164
165 - (void)_startAssistingNode:(const WebKit::AssistedNodeInformation&)information userIsInteracting:(BOOL)userIsInteracting blurPreviousNode:(BOOL)blurPreviousNode userObject:(NSObject <NSSecureCoding> *)userObject;
166 - (void)_stopAssistingNode;
167 - (void)_selectionChanged;
168 - (void)_updateChangedSelection;
169 - (BOOL)_interpretKeyEvent:(WebIOSEvent *)theEvent isCharEvent:(BOOL)isCharEvent;
170 - (void)_positionInformationDidChange:(const WebKit::InteractionInformationAtPosition&)info;
171 - (void)_attemptClickAtLocation:(CGPoint)location;
172 - (void)_updatePositionInformation;
173 - (void)_performAction:(WebKit::SheetAction)action;
174 - (void)_willStartScrollingOrZooming;
175 - (void)_didScroll;
176 - (void)_didEndScrollingOrZooming;
177 - (void)_didUpdateBlockSelectionWithTouch:(WebKit::SelectionTouch)touch withFlags:(WebKit::SelectionFlags)flags growThreshold:(CGFloat)growThreshold shrinkThreshold:(CGFloat)shrinkThreshold;
178 - (void)_showPlaybackTargetPicker:(BOOL)hasVideo fromRect:(const WebCore::IntRect&)elementRect;
179 - (void)_showRunOpenPanel:(WebKit::WebOpenPanelParameters*)parameters resultListener:(WebKit::WebOpenPanelResultListenerProxy*)listener;
180 - (void)accessoryDone;
181 - (void)_didHandleKeyEvent:(WebIOSEvent *)event;
182 - (Vector<WebKit::OptionItem>&) assistedNodeSelectOptions;
183 - (void)_updateUnscaledView;
184 - (void)_enableInspectorNodeSearch;
185 - (void)_disableInspectorNodeSearch;
186 @end
187
188 #endif // PLATFORM(IOS)