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