cfa3323f745ee56f4b79b123387d7a5643b1735b
[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     void setDidEndScrollingCallback(JSValueRef);
145     JSValueRef didEndScrollingCallback() const;
146
147     void playBackEventStream(JSStringRef stream, JSValueRef callback);
148
149     double zoomScale() const;
150     double minimumZoomScale() const;
151     double maximumZoomScale() const;
152     
153     std::optional<bool> stableStateOverride() const;
154     void setStableStateOverride(std::optional<bool>);
155
156     JSObjectRef contentVisibleRect() const;
157     
158     JSObjectRef selectionRangeViewRects() const;
159     JSObjectRef textSelectionCaretRect() const;
160     JSObjectRef selectionStartGrabberViewRect() const;
161     JSObjectRef selectionEndGrabberViewRect() const;
162     JSObjectRef inputViewBounds() const;
163
164     void replaceTextAtRange(JSStringRef, int location, int length);
165     void removeAllDynamicDictionaries();
166     
167     JSRetainPtr<JSStringRef> scrollingTreeAsText() const;
168
169     JSObjectRef propertiesOfLayerWithID(uint64_t layerID) const;
170
171     void uiScriptComplete(JSStringRef result);
172     
173     void retrieveSpeakSelectionContent(JSValueRef);
174     JSRetainPtr<JSStringRef> accessibilitySpeakSelectionContent() const;
175     
176     void simulateRotation(DeviceOrientation*, JSValueRef);
177     void simulateRotationLikeSafari(DeviceOrientation*, JSValueRef);
178
179     void findString(JSStringRef, unsigned long options, unsigned long maxCount);
180
181     // These use a callback to allow the client to know when view visibility state updates get to the web process.
182     void removeViewFromWindow(JSValueRef);
183     void addViewToWindow(JSValueRef);
184
185     void setSafeAreaInsets(double top, double right, double bottom, double left);
186
187     void firstResponderSuppressionForWebView(bool);
188     void makeWindowContentViewFirstResponder();
189     bool isWindowContentViewFirstResponder() const;
190
191 private:
192     UIScriptController(UIScriptContext&);
193     
194     UIScriptContext* context() { return m_context; }
195
196     void platformSetDidStartFormControlInteractionCallback();
197     void platformSetDidEndFormControlInteractionCallback();
198     void platformSetDidShowForcePressPreviewCallback();
199     void platformSetDidDismissForcePressPreviewCallback();
200     void platformSetWillBeginZoomingCallback();
201     void platformSetDidEndZoomingCallback();
202     void platformSetDidShowKeyboardCallback();
203     void platformSetDidHideKeyboardCallback();
204     void platformSetDidEndScrollingCallback();
205     void platformClearAllCallbacks();
206     void platformPlayBackEventStream(JSStringRef, JSValueRef);
207
208     JSClassRef wrapperClass() final;
209
210     JSObjectRef objectFromRect(const WebCore::FloatRect&) const;
211
212     UIScriptContext* m_context;
213 };
214
215 }
216
217 #endif // UIScriptController_h