[iOS] Can't select text after dismissing the keyboard when changing focus
[WebKit-https.git] / Tools / TestRunnerShared / UIScriptContext / UIScriptController.h
1 /*
2  * Copyright (C) 2015 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 #ifndef UIScriptController_h
27 #define UIScriptController_h
28
29 #include "JSWrappable.h"
30 #include <JavaScriptCore/JSRetainPtr.h>
31 #include <wtf/Optional.h>
32 #include <wtf/Ref.h>
33
34 namespace WebCore {
35 class FloatRect;
36 }
37
38 namespace WTR {
39
40 class UIScriptContext;
41
42 enum class DeviceOrientation {
43     Portrait,
44     PortraitUpsideDown,
45     LandscapeLeft,
46     LandscapeRight
47 };
48
49 DeviceOrientation* toDeviceOrientation(JSContextRef, JSValueRef);
50
51 class UIScriptController : public JSWrappable {
52 public:
53     static Ref<UIScriptController> create(UIScriptContext& context)
54     {
55         return adoptRef(*new UIScriptController(context));
56     }
57
58     void contextDestroyed();
59     void checkForOutstandingCallbacks();
60
61     void makeWindowObject(JSContextRef, JSObjectRef windowObject, JSValueRef* exception);
62     
63     void doAsyncTask(JSValueRef callback);
64     void doAfterPresentationUpdate(JSValueRef callback);
65     void doAfterNextStablePresentationUpdate(JSValueRef callback);
66     void doAfterVisibleContentRectUpdate(JSValueRef callback);
67
68     void zoomToScale(double scale, JSValueRef callback);
69     void setViewScale(double);
70
71     void simulateAccessibilitySettingsChangeNotification(JSValueRef callback);
72
73     void touchDownAtPoint(long x, long y, long touchCount, JSValueRef callback);
74     void liftUpAtPoint(long x, long y, long touchCount, JSValueRef callback);
75     void singleTapAtPoint(long x, long y, JSValueRef callback);
76     void doubleTapAtPoint(long x, long y, JSValueRef callback);
77     void dragFromPointToPoint(long startX, long startY, long endX, long endY, double durationSeconds, JSValueRef callback);
78
79     void stylusDownAtPoint(long x, long y, float azimuthAngle, float altitudeAngle, float pressure, JSValueRef callback);
80     void stylusMoveToPoint(long x, long y, float azimuthAngle, float altitudeAngle, float pressure, JSValueRef callback);
81     void stylusUpAtPoint(long x, long y, JSValueRef callback);
82     void stylusTapAtPoint(long x, long y, float azimuthAngle, float altitudeAngle, float pressure, JSValueRef callback);
83
84     void longPressAtPoint(long x, long y, JSValueRef callback);
85
86     void sendEventStream(JSStringRef eventsJSON, JSValueRef callback);
87
88     void enterText(JSStringRef);
89     void typeCharacterUsingHardwareKeyboard(JSStringRef character, JSValueRef callback);
90     void keyDownUsingHardwareKeyboard(JSStringRef character, JSValueRef callback);
91     void keyUpUsingHardwareKeyboard(JSStringRef character, JSValueRef callback);
92
93     void keyboardAccessoryBarNext();
94     void keyboardAccessoryBarPrevious();
95
96     void applyAutocorrection(JSStringRef newString, JSStringRef oldString, JSValueRef callback);
97     
98     void dismissFormAccessoryView();
99     void selectFormAccessoryPickerRow(long);
100     JSRetainPtr<JSStringRef> textContentType() const;
101     JSRetainPtr<JSStringRef> selectFormPopoverTitle() const;
102     JSRetainPtr<JSStringRef> formInputLabel() const;
103     void setTimePickerValue(long hour, long minute);
104
105     void setShareSheetCompletesImmediatelyWithResolution(bool resolved);
106
107     bool isShowingDataListSuggestions() const;
108
109     JSObjectRef contentsOfUserInterfaceItem(JSStringRef) const;
110     void overridePreference(JSStringRef preference, JSStringRef value);
111     
112     void scrollToOffset(long x, long y);
113
114     void immediateScrollToOffset(long x, long y);
115     void immediateZoomToScale(double scale);
116
117     void beginBackSwipe(JSValueRef callback);
118     void completeBackSwipe(JSValueRef callback);
119
120     void setDidStartFormControlInteractionCallback(JSValueRef);
121     JSValueRef didStartFormControlInteractionCallback() const;
122
123     void setDidEndFormControlInteractionCallback(JSValueRef);
124     JSValueRef didEndFormControlInteractionCallback() const;
125     
126     void setDidShowForcePressPreviewCallback(JSValueRef);
127     JSValueRef didShowForcePressPreviewCallback() const;
128     
129     void setDidDismissForcePressPreviewCallback(JSValueRef);
130     JSValueRef didDismissForcePressPreviewCallback() const;
131
132     void setWillBeginZoomingCallback(JSValueRef);
133     JSValueRef willBeginZoomingCallback() const;
134
135     void setDidEndZoomingCallback(JSValueRef);
136     JSValueRef didEndZoomingCallback() const;
137
138     void setDidShowKeyboardCallback(JSValueRef);
139     JSValueRef didShowKeyboardCallback() const;
140
141     void setDidHideKeyboardCallback(JSValueRef);
142     JSValueRef didHideKeyboardCallback() const;
143
144     bool isShowingKeyboard() const;
145
146     void setDidEndScrollingCallback(JSValueRef);
147     JSValueRef didEndScrollingCallback() const;
148
149     void playBackEventStream(JSStringRef stream, JSValueRef callback);
150
151     double zoomScale() const;
152     double minimumZoomScale() const;
153     double maximumZoomScale() const;
154     
155     std::optional<bool> stableStateOverride() const;
156     void setStableStateOverride(std::optional<bool>);
157
158     JSObjectRef contentVisibleRect() const;
159     
160     JSObjectRef selectionRangeViewRects() const;
161     JSObjectRef textSelectionCaretRect() const;
162     JSObjectRef selectionStartGrabberViewRect() const;
163     JSObjectRef selectionEndGrabberViewRect() const;
164     JSObjectRef inputViewBounds() const;
165
166     void replaceTextAtRange(JSStringRef, int location, int length);
167     void removeAllDynamicDictionaries();
168     
169     JSRetainPtr<JSStringRef> scrollingTreeAsText() const;
170
171     JSObjectRef propertiesOfLayerWithID(uint64_t layerID) const;
172
173     void uiScriptComplete(JSStringRef result);
174     
175     void retrieveSpeakSelectionContent(JSValueRef);
176     JSRetainPtr<JSStringRef> accessibilitySpeakSelectionContent() const;
177     
178     void simulateRotation(DeviceOrientation*, JSValueRef);
179     void simulateRotationLikeSafari(DeviceOrientation*, JSValueRef);
180
181     void findString(JSStringRef, unsigned long options, unsigned long maxCount);
182
183     // These use a callback to allow the client to know when view visibility state updates get to the web process.
184     void removeViewFromWindow(JSValueRef);
185     void addViewToWindow(JSValueRef);
186
187     void setSafeAreaInsets(double top, double right, double bottom, double left);
188
189     void firstResponderSuppressionForWebView(bool);
190     void makeWindowContentViewFirstResponder();
191     bool isWindowContentViewFirstResponder() const;
192
193 private:
194     UIScriptController(UIScriptContext&);
195     
196     UIScriptContext* context() { return m_context; }
197
198     void platformSetDidStartFormControlInteractionCallback();
199     void platformSetDidEndFormControlInteractionCallback();
200     void platformSetDidShowForcePressPreviewCallback();
201     void platformSetDidDismissForcePressPreviewCallback();
202     void platformSetWillBeginZoomingCallback();
203     void platformSetDidEndZoomingCallback();
204     void platformSetDidShowKeyboardCallback();
205     void platformSetDidHideKeyboardCallback();
206     void platformSetDidEndScrollingCallback();
207     void platformClearAllCallbacks();
208     void platformPlayBackEventStream(JSStringRef, JSValueRef);
209
210     JSClassRef wrapperClass() final;
211
212     JSObjectRef objectFromRect(const WebCore::FloatRect&) const;
213
214     UIScriptContext* m_context;
215 };
216
217 }
218
219 #endif // UIScriptController_h