2 * Copyright (C) 2015 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #import "UIScriptController.h"
31 #import "DumpRenderTreeBrowserView.h"
32 #import "UIScriptContext.h"
33 #import <WebCore/FloatRect.h>
34 #import <wtf/MainThread.h>
36 extern DumpRenderTreeBrowserView *gWebBrowserView;
37 extern DumpRenderTreeWebScrollView *gWebScrollView;
41 void UIScriptController::doAsyncTask(JSValueRef callback)
43 unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
45 dispatch_async(dispatch_get_main_queue(), ^{
48 m_context->asyncTaskComplete(callbackID);
52 void UIScriptController::doAfterPresentationUpdate(JSValueRef callback)
54 return doAsyncTask(callback);
57 void UIScriptController::zoomToScale(double scale, JSValueRef callback)
59 RefPtr<UIScriptController> protectedThis(this);
60 unsigned callbackID = protectedThis->context()->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
62 dispatch_async(dispatch_get_main_queue(), ^{
63 [gWebScrollView zoomToScale:scale animated:YES completionHandler:^{
64 if (!protectedThis->context())
66 protectedThis->context()->asyncTaskComplete(callbackID);
71 void UIScriptController::simulateAccessibilitySettingsChangeNotification(JSValueRef)
75 double UIScriptController::zoomScale() const
77 return gWebScrollView.zoomScale;
80 void UIScriptController::touchDownAtPoint(long x, long y, long touchCount, JSValueRef callback)
84 void UIScriptController::liftUpAtPoint(long x, long y, long touchCount, JSValueRef callback)
88 void UIScriptController::singleTapAtPoint(long x, long y, JSValueRef callback)
92 void UIScriptController::doubleTapAtPoint(long x, long y, JSValueRef callback)
96 void UIScriptController::dragFromPointToPoint(long startX, long startY, long endX, long endY, double durationSeconds, JSValueRef callback)
100 void UIScriptController::longPressAtPoint(long x, long y, JSValueRef)
104 void UIScriptController::stylusDownAtPoint(long x, long y, float azimuthAngle, float altitudeAngle, float pressure, JSValueRef callback)
108 void UIScriptController::stylusMoveToPoint(long x, long y, float azimuthAngle, float altitudeAngle, float pressure, JSValueRef callback)
112 void UIScriptController::stylusUpAtPoint(long x, long y, JSValueRef callback)
116 void UIScriptController::stylusTapAtPoint(long x, long y, float azimuthAngle, float altitudeAngle, float pressure, JSValueRef callback)
120 void UIScriptController::sendEventStream(JSStringRef eventsJSON, JSValueRef callback)
124 void UIScriptController::typeCharacterUsingHardwareKeyboard(JSStringRef character, JSValueRef callback)
128 void UIScriptController::selectTextCandidateAtIndex(long, JSValueRef)
132 void UIScriptController::keyDownUsingHardwareKeyboard(JSStringRef character, JSValueRef callback)
136 void UIScriptController::keyUpUsingHardwareKeyboard(JSStringRef character, JSValueRef callback)
140 void UIScriptController::dismissFormAccessoryView()
144 void UIScriptController::selectFormAccessoryPickerRow(long rowIndex)
148 JSObjectRef UIScriptController::contentsOfUserInterfaceItem(JSStringRef interfaceItem) const
153 static CGPoint contentOffsetBoundedInValidRange(UIScrollView *scrollView, CGPoint contentOffset)
155 UIEdgeInsets contentInsets = scrollView.contentInset;
156 CGSize contentSize = scrollView.contentSize;
157 CGSize scrollViewSize = scrollView.bounds.size;
159 CGFloat maxHorizontalOffset = contentSize.width + contentInsets.right - scrollViewSize.width;
160 contentOffset.x = std::min(maxHorizontalOffset, contentOffset.x);
161 contentOffset.x = std::max(-contentInsets.left, contentOffset.x);
163 CGFloat maxVerticalOffset = contentSize.height + contentInsets.bottom - scrollViewSize.height;
164 contentOffset.y = std::min(maxVerticalOffset, contentOffset.y);
165 contentOffset.y = std::max(-contentInsets.top, contentOffset.y);
166 return contentOffset;
169 void UIScriptController::scrollToOffset(long x, long y)
171 [gWebScrollView setContentOffset:contentOffsetBoundedInValidRange(gWebScrollView, CGPointMake(x, y)) animated:YES];
174 void UIScriptController::immediateScrollToOffset(long x, long y)
176 [gWebScrollView setContentOffset:contentOffsetBoundedInValidRange(gWebScrollView, CGPointMake(x, y)) animated:NO];
179 void UIScriptController::immediateZoomToScale(double scale)
181 [gWebScrollView setZoomScale:scale animated:NO];
184 void UIScriptController::keyboardAccessoryBarNext()
188 void UIScriptController::keyboardAccessoryBarPrevious()
192 double UIScriptController::minimumZoomScale() const
194 return gWebScrollView.minimumZoomScale;
197 double UIScriptController::maximumZoomScale() const
199 return gWebScrollView.maximumZoomScale;
202 Optional<bool> UIScriptController::stableStateOverride() const
207 void UIScriptController::setStableStateOverride(Optional<bool>)
212 JSObjectRef UIScriptController::contentVisibleRect() const
214 CGRect contentVisibleRect = [gWebBrowserView documentVisibleRect];
215 WebCore::FloatRect rect(contentVisibleRect.origin.x, contentVisibleRect.origin.y, contentVisibleRect.size.width, contentVisibleRect.size.height);
216 return m_context->objectFromRect(rect);
219 void UIScriptController::platformSetDidStartFormControlInteractionCallback()
223 void UIScriptController::platformSetDidEndFormControlInteractionCallback()
227 void UIScriptController::platformSetDidShowForcePressPreviewCallback()
231 void UIScriptController::platformSetDidDismissForcePressPreviewCallback()
235 void UIScriptController::platformSetWillBeginZoomingCallback()
239 void UIScriptController::platformSetDidEndZoomingCallback()
243 void UIScriptController::platformSetDidShowKeyboardCallback()
247 void UIScriptController::platformSetDidHideKeyboardCallback()
251 void UIScriptController::platformSetDidEndScrollingCallback()
255 void UIScriptController::platformClearAllCallbacks()
259 JSObjectRef UIScriptController::selectionRangeViewRects() const
264 void UIScriptController::removeAllDynamicDictionaries()
268 JSRetainPtr<JSStringRef> UIScriptController::scrollingTreeAsText() const
275 #endif // PLATFORM(IOS)