db24ef5a5d4d942ba5263fe4313b32257ab6c257
[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 class UIScriptController : public JSWrappable {
43 public:
44     static Ref<UIScriptController> create(UIScriptContext& context)
45     {
46         return adoptRef(*new UIScriptController(context));
47     }
48
49     void contextDestroyed();
50     void checkForOutstandingCallbacks();
51
52     void makeWindowObject(JSContextRef, JSObjectRef windowObject, JSValueRef* exception);
53     
54     void doAsyncTask(JSValueRef callback);
55     void doAfterPresentationUpdate(JSValueRef callback);
56     void doAfterNextStablePresentationUpdate(JSValueRef callback);
57     void doAfterVisibleContentRectUpdate(JSValueRef callback);
58
59     void zoomToScale(double scale, JSValueRef callback);
60
61     void simulateAccessibilitySettingsChangeNotification(JSValueRef callback);
62
63     void touchDownAtPoint(long x, long y, long touchCount, JSValueRef callback);
64     void liftUpAtPoint(long x, long y, long touchCount, JSValueRef callback);
65     void singleTapAtPoint(long x, long y, JSValueRef callback);
66     void doubleTapAtPoint(long x, long y, JSValueRef callback);
67     void dragFromPointToPoint(long startX, long startY, long endX, long endY, double durationSeconds, JSValueRef callback);
68
69     void stylusDownAtPoint(long x, long y, float azimuthAngle, float altitudeAngle, float pressure, JSValueRef callback);
70     void stylusMoveToPoint(long x, long y, float azimuthAngle, float altitudeAngle, float pressure, JSValueRef callback);
71     void stylusUpAtPoint(long x, long y, JSValueRef callback);
72     void stylusTapAtPoint(long x, long y, float azimuthAngle, float altitudeAngle, float pressure, JSValueRef callback);
73
74     void longPressAtPoint(long x, long y, JSValueRef callback);
75
76     void sendEventStream(JSStringRef eventsJSON, JSValueRef callback);
77
78     void typeCharacterUsingHardwareKeyboard(JSStringRef character, JSValueRef callback);
79     void keyDownUsingHardwareKeyboard(JSStringRef character, JSValueRef callback);
80     void keyUpUsingHardwareKeyboard(JSStringRef character, JSValueRef callback);
81
82     void selectTextCandidateAtIndex(long index, JSValueRef callback);
83
84     void keyboardAccessoryBarNext();
85     void keyboardAccessoryBarPrevious();
86     
87     void dismissFormAccessoryView();
88     void selectFormAccessoryPickerRow(long);
89     
90     JSObjectRef contentsOfUserInterfaceItem(JSStringRef) const;
91     void overridePreference(JSStringRef preference, JSStringRef value);
92     
93     void scrollToOffset(long x, long y);
94
95     void immediateScrollToOffset(long x, long y);
96     void immediateZoomToScale(double scale);
97
98     void setDidStartFormControlInteractionCallback(JSValueRef);
99     JSValueRef didStartFormControlInteractionCallback() const;
100
101     void setDidEndFormControlInteractionCallback(JSValueRef);
102     JSValueRef didEndFormControlInteractionCallback() const;
103     
104     void setDidShowForcePressPreviewCallback(JSValueRef);
105     JSValueRef didShowForcePressPreviewCallback() const;
106     
107     void setDidDismissForcePressPreviewCallback(JSValueRef);
108     JSValueRef didDismissForcePressPreviewCallback() const;
109
110     void setWillBeginZoomingCallback(JSValueRef);
111     JSValueRef willBeginZoomingCallback() const;
112
113     void setDidEndZoomingCallback(JSValueRef);
114     JSValueRef didEndZoomingCallback() const;
115
116     void setDidShowKeyboardCallback(JSValueRef);
117     JSValueRef didShowKeyboardCallback() const;
118
119     void setDidHideKeyboardCallback(JSValueRef);
120     JSValueRef didHideKeyboardCallback() const;
121
122     void setDidEndScrollingCallback(JSValueRef);
123     JSValueRef didEndScrollingCallback() const;
124
125     double zoomScale() const;
126     double minimumZoomScale() const;
127     double maximumZoomScale() const;
128     
129     std::optional<bool> stableStateOverride() const;
130     void setStableStateOverride(std::optional<bool>);
131
132     JSObjectRef contentVisibleRect() const;
133     
134     JSObjectRef selectionRangeViewRects() const;
135     JSObjectRef textSelectionCaretRect() const;
136     JSObjectRef inputViewBounds() const;
137
138     void insertText(JSStringRef, int location, int length);
139     void removeAllDynamicDictionaries();
140     
141     JSRetainPtr<JSStringRef> scrollingTreeAsText() const;
142
143     JSObjectRef propertiesOfLayerWithID(uint64_t layerID) const;
144
145     void uiScriptComplete(JSStringRef result);
146     
147     void retrieveSpeakSelectionContent(JSValueRef);
148     JSRetainPtr<JSStringRef> accessibilitySpeakSelectionContent() const;
149
150     // These use a callback to allow the client to know when view visibility state updates get to the web process.
151     void removeViewFromWindow(JSValueRef);
152     void addViewToWindow(JSValueRef);
153
154 private:
155     UIScriptController(UIScriptContext&);
156     
157     UIScriptContext* context() { return m_context; }
158
159     void platformSetDidStartFormControlInteractionCallback();
160     void platformSetDidEndFormControlInteractionCallback();
161     void platformSetDidShowForcePressPreviewCallback();
162     void platformSetDidDismissForcePressPreviewCallback();
163     void platformSetWillBeginZoomingCallback();
164     void platformSetDidEndZoomingCallback();
165     void platformSetDidShowKeyboardCallback();
166     void platformSetDidHideKeyboardCallback();
167     void platformSetDidEndScrollingCallback();
168     void platformClearAllCallbacks();
169
170     JSClassRef wrapperClass() final;
171
172     JSObjectRef objectFromRect(const WebCore::FloatRect&) const;
173     void waitForTextPredictionsViewAndSelectCandidateAtIndex(long index, unsigned callbackID, float interval);
174
175     UIScriptContext* m_context;
176 };
177
178 }
179
180 #endif // UIScriptController_h