9f5431a840f419a50b4b258b2a9150c793d3171a
[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 OBJC_CLASS NSUndoManager;
35
36 namespace WebCore {
37 class FloatRect;
38 }
39
40 namespace WTR {
41
42 class UIScriptContext;
43
44 enum class DeviceOrientation {
45     Portrait,
46     PortraitUpsideDown,
47     LandscapeLeft,
48     LandscapeRight
49 };
50
51 DeviceOrientation* toDeviceOrientation(JSContextRef, JSValueRef);
52
53 class UIScriptController : public JSWrappable {
54 public:
55     static Ref<UIScriptController> create(UIScriptContext& context)
56     {
57         return adoptRef(*new UIScriptController(context));
58     }
59
60     void contextDestroyed();
61     void checkForOutstandingCallbacks();
62
63     void makeWindowObject(JSContextRef, JSObjectRef windowObject, JSValueRef* exception);
64     
65     void doAsyncTask(JSValueRef callback);
66     void doAfterPresentationUpdate(JSValueRef callback);
67     void doAfterNextStablePresentationUpdate(JSValueRef callback);
68     void doAfterVisibleContentRectUpdate(JSValueRef callback);
69
70     void zoomToScale(double scale, JSValueRef callback);
71     void setViewScale(double);
72     void setMinimumEffectiveWidth(double);
73
74     void resignFirstResponder();
75
76     void simulateAccessibilitySettingsChangeNotification(JSValueRef callback);
77
78     void touchDownAtPoint(long x, long y, long touchCount, JSValueRef callback);
79     void liftUpAtPoint(long x, long y, long touchCount, JSValueRef callback);
80     void singleTapAtPoint(long x, long y, JSValueRef callback);
81     void singleTapAtPointWithModifiers(long x, long y, JSValueRef modifierArray, JSValueRef callback);
82     void doubleTapAtPoint(long x, long y, JSValueRef callback);
83     void dragFromPointToPoint(long startX, long startY, long endX, long endY, double durationSeconds, JSValueRef callback);
84
85     void stylusDownAtPoint(long x, long y, float azimuthAngle, float altitudeAngle, float pressure, JSValueRef callback);
86     void stylusMoveToPoint(long x, long y, float azimuthAngle, float altitudeAngle, float pressure, JSValueRef callback);
87     void stylusUpAtPoint(long x, long y, JSValueRef callback);
88     void stylusTapAtPoint(long x, long y, float azimuthAngle, float altitudeAngle, float pressure, JSValueRef callback);
89     void stylusTapAtPointWithModifiers(long x, long y, float azimuthAngle, float altitudeAngle, float pressure, JSValueRef modifierArray, JSValueRef callback);
90
91     void longPressAtPoint(long x, long y, JSValueRef callback);
92
93     void sendEventStream(JSStringRef eventsJSON, JSValueRef callback);
94
95     void enterText(JSStringRef);
96     void typeCharacterUsingHardwareKeyboard(JSStringRef character, JSValueRef callback);
97
98     void keyDown(JSStringRef character, JSValueRef modifierArray);
99     void toggleCapsLock(JSValueRef callback);
100
101     void keyboardAccessoryBarNext();
102     void keyboardAccessoryBarPrevious();
103
104     void applyAutocorrection(JSStringRef newString, JSStringRef oldString, JSValueRef callback);
105     
106     void dismissFormAccessoryView();
107     void selectFormAccessoryPickerRow(long);
108     JSRetainPtr<JSStringRef> textContentType() const;
109     JSRetainPtr<JSStringRef> selectFormPopoverTitle() const;
110     JSRetainPtr<JSStringRef> formInputLabel() const;
111     void setTimePickerValue(long hour, long minute);
112
113     void setShareSheetCompletesImmediatelyWithResolution(bool resolved);
114
115     bool isShowingDataListSuggestions() const;
116
117     JSObjectRef contentsOfUserInterfaceItem(JSStringRef) const;
118     void overridePreference(JSStringRef preference, JSStringRef value);
119
120     bool isPresentingModally() const;
121     
122     double contentOffsetX() const;
123     double contentOffsetY() const;
124
125     void scrollToOffset(long x, long y);
126
127     void immediateScrollToOffset(long x, long y);
128     void immediateZoomToScale(double scale);
129
130     void beginBackSwipe(JSValueRef callback);
131     void completeBackSwipe(JSValueRef callback);
132
133     void setDidStartFormControlInteractionCallback(JSValueRef);
134     JSValueRef didStartFormControlInteractionCallback() const;
135
136     void setDidEndFormControlInteractionCallback(JSValueRef);
137     JSValueRef didEndFormControlInteractionCallback() const;
138     
139     void setDidShowForcePressPreviewCallback(JSValueRef);
140     JSValueRef didShowForcePressPreviewCallback() const;
141     
142     void setDidDismissForcePressPreviewCallback(JSValueRef);
143     JSValueRef didDismissForcePressPreviewCallback() const;
144
145     void setWillBeginZoomingCallback(JSValueRef);
146     JSValueRef willBeginZoomingCallback() const;
147
148     void setDidEndZoomingCallback(JSValueRef);
149     JSValueRef didEndZoomingCallback() const;
150
151     void setDidShowKeyboardCallback(JSValueRef);
152     JSValueRef didShowKeyboardCallback() const;
153
154     void setDidHideKeyboardCallback(JSValueRef);
155     JSValueRef didHideKeyboardCallback() const;
156
157     bool isShowingKeyboard() const;
158
159     void setDidEndScrollingCallback(JSValueRef);
160     JSValueRef didEndScrollingCallback() const;
161
162     void playBackEventStream(JSStringRef stream, JSValueRef callback);
163
164     double zoomScale() const;
165     double minimumZoomScale() const;
166     double maximumZoomScale() const;
167     
168     Optional<bool> stableStateOverride() const;
169     void setStableStateOverride(Optional<bool>);
170
171     JSObjectRef contentVisibleRect() const;
172     
173     JSObjectRef textSelectionRangeRects() const;
174     JSObjectRef textSelectionCaretRect() const;
175     JSObjectRef selectionStartGrabberViewRect() const;
176     JSObjectRef selectionEndGrabberViewRect() const;
177     JSObjectRef selectionCaretViewRect() const;
178     JSObjectRef selectionRangeViewRects() const;
179     JSObjectRef calendarType() const;
180     void setDefaultCalendarType(JSStringRef calendarIdentifier);
181     JSObjectRef inputViewBounds() const;
182
183     void setKeyboardInputModeIdentifier(JSStringRef);
184
185     void replaceTextAtRange(JSStringRef, int location, int length);
186     void removeAllDynamicDictionaries();
187     
188     JSRetainPtr<JSStringRef> scrollingTreeAsText() const;
189
190     JSObjectRef propertiesOfLayerWithID(uint64_t layerID) const;
191
192     void uiScriptComplete(JSStringRef result);
193     
194     void retrieveSpeakSelectionContent(JSValueRef);
195     JSRetainPtr<JSStringRef> accessibilitySpeakSelectionContent() const;
196     
197     void simulateRotation(DeviceOrientation*, JSValueRef);
198     void simulateRotationLikeSafari(DeviceOrientation*, JSValueRef);
199
200     void findString(JSStringRef, unsigned long options, unsigned long maxCount);
201
202     // These use a callback to allow the client to know when view visibility state updates get to the web process.
203     void removeViewFromWindow(JSValueRef);
204     void addViewToWindow(JSValueRef);
205
206     void setSafeAreaInsets(double top, double right, double bottom, double left);
207
208     void firstResponderSuppressionForWebView(bool);
209     void makeWindowContentViewFirstResponder();
210     bool isWindowContentViewFirstResponder() const;
211
212     void drawSquareInEditableImage();
213     long numberOfStrokesInEditableImage();
214
215     JSRetainPtr<JSStringRef> lastUndoLabel() const;
216     JSRetainPtr<JSStringRef> firstRedoLabel() const;
217
218     JSObjectRef attachmentInfo(JSStringRef attachmentIdentifier);
219
220 private:
221     UIScriptController(UIScriptContext&);
222     
223     UIScriptContext* context() { return m_context; }
224
225     void platformSetDidStartFormControlInteractionCallback();
226     void platformSetDidEndFormControlInteractionCallback();
227     void platformSetDidShowForcePressPreviewCallback();
228     void platformSetDidDismissForcePressPreviewCallback();
229     void platformSetWillBeginZoomingCallback();
230     void platformSetDidEndZoomingCallback();
231     void platformSetDidShowKeyboardCallback();
232     void platformSetDidHideKeyboardCallback();
233     void platformSetDidEndScrollingCallback();
234     void platformClearAllCallbacks();
235     void platformPlayBackEventStream(JSStringRef, JSValueRef);
236
237 #if PLATFORM(COCOA)
238     NSUndoManager *platformUndoManager() const;
239 #endif
240
241     JSClassRef wrapperClass() final;
242
243     JSObjectRef objectFromRect(const WebCore::FloatRect&) const;
244
245     UIScriptContext* m_context;
246
247 #if PLATFORM(COCOA)
248     bool m_capsLockOn { false };
249 #endif
250 };
251
252 }
253
254 #endif // UIScriptController_h