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 | void setAllowsViewportShrinkToFit(bool); |
76 | |
77 | void resignFirstResponder(); |
78 | |
79 | void simulateAccessibilitySettingsChangeNotification(JSValueRef callback); |
80 | |
81 | void touchDownAtPoint(long x, long y, long touchCount, JSValueRef callback); |
82 | void liftUpAtPoint(long x, long y, long touchCount, JSValueRef callback); |
83 | void singleTapAtPoint(long x, long y, JSValueRef callback); |
84 | void singleTapAtPointWithModifiers(long x, long y, JSValueRef modifierArray, JSValueRef callback); |
85 | void doubleTapAtPoint(long x, long y, JSValueRef callback); |
86 | void dragFromPointToPoint(long startX, long startY, long endX, long endY, double durationSeconds, JSValueRef callback); |
87 | |
88 | void stylusDownAtPoint(long x, long y, float azimuthAngle, float altitudeAngle, float pressure, JSValueRef callback); |
89 | void stylusMoveToPoint(long x, long y, float azimuthAngle, float altitudeAngle, float pressure, JSValueRef callback); |
90 | void stylusUpAtPoint(long x, long y, JSValueRef callback); |
91 | void stylusTapAtPoint(long x, long y, float azimuthAngle, float altitudeAngle, float pressure, JSValueRef callback); |
92 | void stylusTapAtPointWithModifiers(long x, long y, float azimuthAngle, float altitudeAngle, float pressure, JSValueRef modifierArray, JSValueRef callback); |
93 | |
94 | void longPressAtPoint(long x, long y, JSValueRef callback); |
95 | |
96 | void sendEventStream(JSStringRef eventsJSON, JSValueRef callback); |
97 | |
98 | void enterText(JSStringRef); |
99 | void typeCharacterUsingHardwareKeyboard(JSStringRef character, JSValueRef callback); |
100 | |
101 | void keyDown(JSStringRef character, JSValueRef modifierArray); |
102 | void toggleCapsLock(JSValueRef callback); |
103 | |
104 | void keyboardAccessoryBarNext(); |
105 | void keyboardAccessoryBarPrevious(); |
106 | |
107 | void applyAutocorrection(JSStringRef newString, JSStringRef oldString, JSValueRef callback); |
108 | |
109 | void dismissFilePicker(JSValueRef callback); |
110 | void dismissFormAccessoryView(); |
111 | void selectFormAccessoryPickerRow(long); |
112 | JSRetainPtr<JSStringRef> textContentType() const; |
113 | JSRetainPtr<JSStringRef> selectFormPopoverTitle() const; |
114 | JSRetainPtr<JSStringRef> formInputLabel() const; |
115 | void setTimePickerValue(long hour, long minute); |
116 | |
117 | void setShareSheetCompletesImmediatelyWithResolution(bool resolved); |
118 | |
119 | bool isShowingDataListSuggestions() const; |
120 | |
121 | JSObjectRef contentsOfUserInterfaceItem(JSStringRef) const; |
122 | void overridePreference(JSStringRef preference, JSStringRef value); |
123 | |
124 | bool isPresentingModally() const; |
125 | |
126 | double contentOffsetX() const; |
127 | double contentOffsetY() const; |
128 | |
129 | bool scrollUpdatesDisabled() const; |
130 | void setScrollUpdatesDisabled(bool); |
131 | |
132 | void scrollToOffset(long x, long y); |
133 | |
134 | void immediateScrollToOffset(long x, long y); |
135 | void immediateScrollElementAtContentPointToOffset(long x, long y, long xScrollOffset, long yScrollOffset); |
136 | void immediateZoomToScale(double scale); |
137 | |
138 | void beginBackSwipe(JSValueRef callback); |
139 | void completeBackSwipe(JSValueRef callback); |
140 | |
141 | void setDidStartFormControlInteractionCallback(JSValueRef); |
142 | JSValueRef didStartFormControlInteractionCallback() const; |
143 | |
144 | void setDidEndFormControlInteractionCallback(JSValueRef); |
145 | JSValueRef didEndFormControlInteractionCallback() const; |
146 | |
147 | void setDidShowForcePressPreviewCallback(JSValueRef); |
148 | JSValueRef didShowForcePressPreviewCallback() const; |
149 | |
150 | void setDidDismissForcePressPreviewCallback(JSValueRef); |
151 | JSValueRef didDismissForcePressPreviewCallback() const; |
152 | |
153 | void setWillBeginZoomingCallback(JSValueRef); |
154 | JSValueRef willBeginZoomingCallback() const; |
155 | |
156 | void setDidEndZoomingCallback(JSValueRef); |
157 | JSValueRef didEndZoomingCallback() const; |
158 | |
159 | void setDidShowKeyboardCallback(JSValueRef); |
160 | JSValueRef didShowKeyboardCallback() const; |
161 | |
162 | void setDidHideKeyboardCallback(JSValueRef); |
163 | JSValueRef didHideKeyboardCallback() const; |
164 | |
165 | bool isShowingKeyboard() const; |
166 | |
167 | void (JSValueRef); |
168 | JSValueRef () const; |
169 | void (JSValueRef); |
170 | JSValueRef () const; |
171 | |
172 | bool isShowingPopover() const; |
173 | void setDidDismissPopoverCallback(JSValueRef); |
174 | JSValueRef didDismissPopoverCallback() const; |
175 | void setWillPresentPopoverCallback(JSValueRef); |
176 | JSValueRef willPresentPopoverCallback() const; |
177 | |
178 | bool () const; |
179 | bool () const; |
180 | JSObjectRef (JSStringRef action) const; |
181 | JSObjectRef () const; |
182 | |
183 | void setDidEndScrollingCallback(JSValueRef); |
184 | JSValueRef didEndScrollingCallback() const; |
185 | |
186 | void playBackEventStream(JSStringRef stream, JSValueRef callback); |
187 | |
188 | double zoomScale() const; |
189 | double minimumZoomScale() const; |
190 | double maximumZoomScale() const; |
191 | |
192 | Optional<bool> stableStateOverride() const; |
193 | void setStableStateOverride(Optional<bool>); |
194 | |
195 | JSObjectRef contentVisibleRect() const; |
196 | |
197 | JSObjectRef textSelectionRangeRects() const; |
198 | JSObjectRef textSelectionCaretRect() const; |
199 | JSObjectRef selectionStartGrabberViewRect() const; |
200 | JSObjectRef selectionEndGrabberViewRect() const; |
201 | JSObjectRef selectionCaretViewRect() const; |
202 | JSObjectRef selectionRangeViewRects() const; |
203 | JSObjectRef calendarType() const; |
204 | void setDefaultCalendarType(JSStringRef calendarIdentifier); |
205 | JSObjectRef inputViewBounds() const; |
206 | |
207 | void setKeyboardInputModeIdentifier(JSStringRef); |
208 | |
209 | void replaceTextAtRange(JSStringRef, int location, int length); |
210 | void removeAllDynamicDictionaries(); |
211 | |
212 | JSRetainPtr<JSStringRef> scrollingTreeAsText() const; |
213 | |
214 | JSObjectRef propertiesOfLayerWithID(uint64_t layerID) const; |
215 | |
216 | void uiScriptComplete(JSStringRef result); |
217 | |
218 | void retrieveSpeakSelectionContent(JSValueRef); |
219 | JSRetainPtr<JSStringRef> accessibilitySpeakSelectionContent() const; |
220 | |
221 | void simulateRotation(DeviceOrientation*, JSValueRef); |
222 | void simulateRotationLikeSafari(DeviceOrientation*, JSValueRef); |
223 | |
224 | void findString(JSStringRef, unsigned long options, unsigned long maxCount); |
225 | |
226 | // These use a callback to allow the client to know when view visibility state updates get to the web process. |
227 | void removeViewFromWindow(JSValueRef); |
228 | void addViewToWindow(JSValueRef); |
229 | |
230 | void setSafeAreaInsets(double top, double right, double bottom, double left); |
231 | |
232 | void firstResponderSuppressionForWebView(bool); |
233 | void makeWindowContentViewFirstResponder(); |
234 | bool isWindowContentViewFirstResponder() const; |
235 | |
236 | void drawSquareInEditableImage(); |
237 | long numberOfStrokesInEditableImage(); |
238 | |
239 | JSRetainPtr<JSStringRef> lastUndoLabel() const; |
240 | JSRetainPtr<JSStringRef> firstRedoLabel() const; |
241 | |
242 | JSObjectRef attachmentInfo(JSStringRef attachmentIdentifier); |
243 | |
244 | void setHardwareKeyboardAttached(bool); |
245 | |
246 | private: |
247 | UIScriptController(UIScriptContext&); |
248 | |
249 | UIScriptContext* context() { return m_context; } |
250 | |
251 | void platformSetDidStartFormControlInteractionCallback(); |
252 | void platformSetDidEndFormControlInteractionCallback(); |
253 | void platformSetDidShowForcePressPreviewCallback(); |
254 | void platformSetDidDismissForcePressPreviewCallback(); |
255 | void platformSetWillBeginZoomingCallback(); |
256 | void platformSetDidEndZoomingCallback(); |
257 | void platformSetDidShowKeyboardCallback(); |
258 | void platformSetDidHideKeyboardCallback(); |
259 | void (); |
260 | void (); |
261 | void platformSetWillPresentPopoverCallback(); |
262 | void platformSetDidDismissPopoverCallback(); |
263 | void platformSetDidEndScrollingCallback(); |
264 | void platformClearAllCallbacks(); |
265 | void platformPlayBackEventStream(JSStringRef, JSValueRef); |
266 | |
267 | #if PLATFORM(COCOA) |
268 | NSUndoManager *platformUndoManager() const; |
269 | #endif |
270 | |
271 | #if PLATFORM(IOS_FAMILY) |
272 | UIView *platformContentView() const; |
273 | #endif |
274 | #if PLATFORM(MAC) |
275 | NSView *platformContentView() const; |
276 | #endif |
277 | |
278 | JSClassRef wrapperClass() final; |
279 | |
280 | JSObjectRef objectFromRect(const WebCore::FloatRect&) const; |
281 | |
282 | UIScriptContext* m_context; |
283 | |
284 | #if PLATFORM(COCOA) |
285 | bool m_capsLockOn { false }; |
286 | #endif |
287 | }; |
288 | |
289 | } |
290 | |
291 | #endif // UIScriptController_h |
292 | |