Allow WebKit clients to specify a minimum effective width for layout.
[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     void setMinimumEffectiveWidth(double);
71
72     void resignFirstResponder();
73
74     void simulateAccessibilitySettingsChangeNotification(JSValueRef callback);
75
76     void touchDownAtPoint(long x, long y, long touchCount, JSValueRef callback);
77     void liftUpAtPoint(long x, long y, long touchCount, JSValueRef callback);
78     void singleTapAtPoint(long x, long y, JSValueRef callback);
79     void doubleTapAtPoint(long x, long y, JSValueRef callback);
80     void dragFromPointToPoint(long startX, long startY, long endX, long endY, double durationSeconds, JSValueRef callback);
81
82     void stylusDownAtPoint(long x, long y, float azimuthAngle, float altitudeAngle, float pressure, JSValueRef callback);
83     void stylusMoveToPoint(long x, long y, float azimuthAngle, float altitudeAngle, float pressure, JSValueRef callback);
84     void stylusUpAtPoint(long x, long y, JSValueRef callback);
85     void stylusTapAtPoint(long x, long y, float azimuthAngle, float altitudeAngle, float pressure, JSValueRef callback);
86
87     void longPressAtPoint(long x, long y, JSValueRef callback);
88
89     void sendEventStream(JSStringRef eventsJSON, JSValueRef callback);
90
91     void enterText(JSStringRef);
92     void typeCharacterUsingHardwareKeyboard(JSStringRef character, JSValueRef callback);
93
94     void keyDown(JSStringRef character, JSValueRef modifierArray);
95     void toggleCapsLock(JSValueRef callback);
96
97     void keyboardAccessoryBarNext();
98     void keyboardAccessoryBarPrevious();
99
100     void applyAutocorrection(JSStringRef newString, JSStringRef oldString, JSValueRef callback);
101     
102     void dismissFormAccessoryView();
103     void selectFormAccessoryPickerRow(long);
104     JSRetainPtr<JSStringRef> textContentType() const;
105     JSRetainPtr<JSStringRef> selectFormPopoverTitle() const;
106     JSRetainPtr<JSStringRef> formInputLabel() const;
107     void setTimePickerValue(long hour, long minute);
108
109     void setShareSheetCompletesImmediatelyWithResolution(bool resolved);
110
111     bool isShowingDataListSuggestions() const;
112
113     JSObjectRef contentsOfUserInterfaceItem(JSStringRef) const;
114     void overridePreference(JSStringRef preference, JSStringRef value);
115     
116     void scrollToOffset(long x, long y);
117
118     void immediateScrollToOffset(long x, long y);
119     void immediateZoomToScale(double scale);
120
121     void beginBackSwipe(JSValueRef callback);
122     void completeBackSwipe(JSValueRef callback);
123
124     void setDidStartFormControlInteractionCallback(JSValueRef);
125     JSValueRef didStartFormControlInteractionCallback() const;
126
127     void setDidEndFormControlInteractionCallback(JSValueRef);
128     JSValueRef didEndFormControlInteractionCallback() const;
129     
130     void setDidShowForcePressPreviewCallback(JSValueRef);
131     JSValueRef didShowForcePressPreviewCallback() const;
132     
133     void setDidDismissForcePressPreviewCallback(JSValueRef);
134     JSValueRef didDismissForcePressPreviewCallback() const;
135
136     void setWillBeginZoomingCallback(JSValueRef);
137     JSValueRef willBeginZoomingCallback() const;
138
139     void setDidEndZoomingCallback(JSValueRef);
140     JSValueRef didEndZoomingCallback() const;
141
142     void setDidShowKeyboardCallback(JSValueRef);
143     JSValueRef didShowKeyboardCallback() const;
144
145     void setDidHideKeyboardCallback(JSValueRef);
146     JSValueRef didHideKeyboardCallback() const;
147
148     bool isShowingKeyboard() const;
149
150     void setDidEndScrollingCallback(JSValueRef);
151     JSValueRef didEndScrollingCallback() const;
152
153     void playBackEventStream(JSStringRef stream, JSValueRef callback);
154
155     double zoomScale() const;
156     double minimumZoomScale() const;
157     double maximumZoomScale() const;
158     
159     std::optional<bool> stableStateOverride() const;
160     void setStableStateOverride(std::optional<bool>);
161
162     JSObjectRef contentVisibleRect() const;
163     
164     JSObjectRef textSelectionRangeRects() const;
165     JSObjectRef textSelectionCaretRect() const;
166     JSObjectRef selectionStartGrabberViewRect() const;
167     JSObjectRef selectionEndGrabberViewRect() const;
168     JSObjectRef selectionCaretViewRect() const;
169     JSObjectRef selectionRangeViewRects() const;
170     JSObjectRef calendarType() const;
171     void setDefaultCalendarType(JSStringRef calendarIdentifier);
172     JSObjectRef inputViewBounds() const;
173
174     void replaceTextAtRange(JSStringRef, int location, int length);
175     void removeAllDynamicDictionaries();
176     
177     JSRetainPtr<JSStringRef> scrollingTreeAsText() const;
178
179     JSObjectRef propertiesOfLayerWithID(uint64_t layerID) const;
180
181     void uiScriptComplete(JSStringRef result);
182     
183     void retrieveSpeakSelectionContent(JSValueRef);
184     JSRetainPtr<JSStringRef> accessibilitySpeakSelectionContent() const;
185     
186     void simulateRotation(DeviceOrientation*, JSValueRef);
187     void simulateRotationLikeSafari(DeviceOrientation*, JSValueRef);
188
189     void findString(JSStringRef, unsigned long options, unsigned long maxCount);
190
191     // These use a callback to allow the client to know when view visibility state updates get to the web process.
192     void removeViewFromWindow(JSValueRef);
193     void addViewToWindow(JSValueRef);
194
195     void setSafeAreaInsets(double top, double right, double bottom, double left);
196
197     void firstResponderSuppressionForWebView(bool);
198     void makeWindowContentViewFirstResponder();
199     bool isWindowContentViewFirstResponder() const;
200
201     void drawSquareInEditableImage();
202     long numberOfStrokesInEditableImage();
203
204     JSObjectRef attachmentInfo(JSStringRef attachmentIdentifier);
205
206 private:
207     UIScriptController(UIScriptContext&);
208     
209     UIScriptContext* context() { return m_context; }
210
211     void platformSetDidStartFormControlInteractionCallback();
212     void platformSetDidEndFormControlInteractionCallback();
213     void platformSetDidShowForcePressPreviewCallback();
214     void platformSetDidDismissForcePressPreviewCallback();
215     void platformSetWillBeginZoomingCallback();
216     void platformSetDidEndZoomingCallback();
217     void platformSetDidShowKeyboardCallback();
218     void platformSetDidHideKeyboardCallback();
219     void platformSetDidEndScrollingCallback();
220     void platformClearAllCallbacks();
221     void platformPlayBackEventStream(JSStringRef, JSValueRef);
222
223     JSClassRef wrapperClass() final;
224
225     JSObjectRef objectFromRect(const WebCore::FloatRect&) const;
226
227     UIScriptContext* m_context;
228
229 #if PLATFORM(MAC)
230     bool m_capsLockOn { false };
231 #endif
232 };
233
234 }
235
236 #endif // UIScriptController_h