Make UIScriptController::zoomToScale() work on Mac WK1 and WK2
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 1 Nov 2016 02:43:47 +0000 (02:43 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 1 Nov 2016 02:43:47 +0000 (02:43 +0000)
https://bugs.webkit.org/show_bug.cgi?id=164238

Reviewed by Dean Jackson.

Source/WebCore:

Test: fast/zooming/uiscript-zooming.html

Expose pageScaleFactor() for tests.

* testing/Internals.cpp:
(WebCore::Internals::pageScaleFactor):
* testing/Internals.h:
* testing/Internals.idl:

Tools:

Implement UIScriptController::zoomToScale() for WTR and DRT on Mac.

* DumpRenderTree/mac/UIScriptControllerMac.mm:
(WTR::UIScriptController::zoomToScale):
* TestRunnerShared/UIScriptContext/UIScriptController.cpp:
* WebKitTestRunner/mac/UIScriptControllerMac.mm:
(WTR::UIScriptController::zoomToScale):

LayoutTests:

* fast/zooming/uiscript-zooming-expected.txt: Added.
* fast/zooming/uiscript-zooming.html: Added.
* platform/ios-simulator-wk1/TestExpectations:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208207 268f45cc-cd09-0410-ab3c-d52691b4dbfc

12 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/zooming/uiscript-zooming-expected.txt [new file with mode: 0644]
LayoutTests/fast/zooming/uiscript-zooming.html [new file with mode: 0644]
LayoutTests/platform/ios-simulator-wk1/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl
Tools/ChangeLog
Tools/DumpRenderTree/mac/UIScriptControllerMac.mm
Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp
Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm

index a34d6d9..aa98b96 100644 (file)
@@ -1,3 +1,14 @@
+2016-10-31  Simon Fraser  <simon.fraser@apple.com>
+
+        Make UIScriptController::zoomToScale() work on Mac WK1 and WK2
+        https://bugs.webkit.org/show_bug.cgi?id=164238
+
+        Reviewed by Dean Jackson.
+
+        * fast/zooming/uiscript-zooming-expected.txt: Added.
+        * fast/zooming/uiscript-zooming.html: Added.
+        * platform/ios-simulator-wk1/TestExpectations:
+
 2016-10-31  Joseph Pecoraro  <pecoraro@apple.com>
 
         Remove test workaround now that original issue is fixed
diff --git a/LayoutTests/fast/zooming/uiscript-zooming-expected.txt b/LayoutTests/fast/zooming/uiscript-zooming-expected.txt
new file mode 100644 (file)
index 0000000..81dfcde
--- /dev/null
@@ -0,0 +1,10 @@
+Test that uiController.zoomToScale() works.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS internals.pageScaleFactor() is 2
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/zooming/uiscript-zooming.html b/LayoutTests/fast/zooming/uiscript-zooming.html
new file mode 100644 (file)
index 0000000..90f23c3
--- /dev/null
@@ -0,0 +1,46 @@
+<!DOCTYPE html>
+
+<html>
+<head>
+    <style>
+        body {
+            height: 2000px;
+            width: 2000px;
+        }
+    </style>
+    <script src="../../resources/js-test-pre.js"></script>
+    <script>
+        description("Test that uiController.zoomToScale() works.");
+
+        window.jsTestIsAsync = true;
+
+        function doAfterZooming()
+        {
+            shouldBe('internals.pageScaleFactor()', '2');
+            finishJSTest();
+        }
+        
+        function getUIScript()
+        {
+            return `(function() {
+                uiController.zoomToScale(2, function() {
+                    uiController.uiScriptComplete(uiController.zoomScale);
+                });
+            })();`;
+        }
+
+        function doTest()
+        {
+            if (window.testRunner)
+                testRunner.runUIScript(getUIScript(), function(zoomScale) {
+                    doAfterZooming();
+                })
+        }
+        
+        window.addEventListener('load', doTest, false);
+    </script>
+</head>
+<body>
+    <script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
index 793d20d..53e3e6a 100644 (file)
@@ -100,6 +100,9 @@ editing/undo/undo-after-event-edited.html
 editing/unsupported-content/table-type-after.html
 editing/unsupported-content/table-type-before.html
 
+# Zooming works differently in iOS DRT
+fast/zooming/uiscript-zooming.html [ Failure ]
+
 # FIXME: Tests that fail due to lack of textInputController <rdar://problem/5106287>
 editing/inserting/insert-composition-whitespace.html [ Failure ]
 
index ffae033..16eb737 100644 (file)
@@ -1,3 +1,19 @@
+2016-10-31  Simon Fraser  <simon.fraser@apple.com>
+
+        Make UIScriptController::zoomToScale() work on Mac WK1 and WK2
+        https://bugs.webkit.org/show_bug.cgi?id=164238
+
+        Reviewed by Dean Jackson.
+
+        Test: fast/zooming/uiscript-zooming.html
+        
+        Expose pageScaleFactor() for tests.
+
+        * testing/Internals.cpp:
+        (WebCore::Internals::pageScaleFactor):
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
 2016-10-31  Myles C. Maxfield  <mmaxfield@apple.com>
 
         Migrate CanvasRenderingContext's internal canvas pointer to a reference
index 70fb22d..26c772d 100644 (file)
@@ -2017,6 +2017,15 @@ ExceptionOr<String> Internals::pageSizeAndMarginsInPixels(int pageNumber, int wi
     return PrintContext::pageSizeAndMarginsInPixels(frame(), pageNumber, width, height, marginTop, marginRight, marginBottom, marginLeft);
 }
 
+ExceptionOr<float> Internals::pageScaleFactor() const
+{
+    Document* document = contextDocument();
+    if (!document || !document->page())
+        return Exception { INVALID_ACCESS_ERR };
+
+    return document->page()->pageScaleFactor();
+}
+
 ExceptionOr<void> Internals::setPageScaleFactor(float scaleFactor, int x, int y)
 {
     Document* document = contextDocument();
index 36f220e..2613bd8 100644 (file)
@@ -284,6 +284,8 @@ public:
     ExceptionOr<String> pageProperty(const String& propertyName, int pageNumber) const;
     ExceptionOr<String> pageSizeAndMarginsInPixels(int pageNumber, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft) const;
 
+    ExceptionOr<float> pageScaleFactor() const;
+
     ExceptionOr<void> setPageScaleFactor(float scaleFactor, int x, int y);
     ExceptionOr<void> setPageZoomFactor(float);
     ExceptionOr<void> setTextZoomFactor(float);
index a6fe34c..045fd8a 100644 (file)
@@ -278,6 +278,8 @@ enum UserInterfaceLayoutDirection {
     [MayThrowException] DOMString pageSizeAndMarginsInPixels(long pageIndex, long width, long height, long marginTop, long marginRight, long marginBottom, long marginLeft);
 
     [MayThrowException] void setPageScaleFactor(unrestricted float scaleFactor, long x, long y);
+    [MayThrowException] float pageScaleFactor();
+
     [MayThrowException] void setPageZoomFactor(unrestricted float zoomFactor);
     [MayThrowException] void setTextZoomFactor(unrestricted float zoomFactor);
 
index 7e096c2..6d5627b 100644 (file)
@@ -1,3 +1,18 @@
+2016-10-31  Simon Fraser  <simon.fraser@apple.com>
+
+        Make UIScriptController::zoomToScale() work on Mac WK1 and WK2
+        https://bugs.webkit.org/show_bug.cgi?id=164238
+
+        Reviewed by Dean Jackson.
+
+        Implement UIScriptController::zoomToScale() for WTR and DRT on Mac.
+
+        * DumpRenderTree/mac/UIScriptControllerMac.mm:
+        (WTR::UIScriptController::zoomToScale):
+        * TestRunnerShared/UIScriptContext/UIScriptController.cpp:
+        * WebKitTestRunner/mac/UIScriptControllerMac.mm:
+        (WTR::UIScriptController::zoomToScale):
+
 2016-10-31  Dewei Zhu  <dewei_zhu@apple.com>
 
         Update twisted version in webkitpy.thirdparty.autoinstalled module.
index 190ec14..c8aa66b 100644 (file)
 #import "config.h"
 #import "UIScriptController.h"
 
+#import "DumpRenderTree.h"
 #import "UIScriptContext.h"
+#import <WebKit/WebKit.h>
+#import <WebKit/WebViewPrivate.h>
 
 #if PLATFORM(MAC)
 
@@ -47,6 +50,20 @@ void UIScriptController::insertText(JSStringRef, int, int)
 {
 }
 
+void UIScriptController::zoomToScale(double scale, JSValueRef callback)
+{
+    unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
+
+    WebView *webView = [mainFrame webView];
+    [webView _scaleWebView:scale atOrigin:NSZeroPoint];
+
+    dispatch_async(dispatch_get_main_queue(), ^ {
+        if (!m_context)
+            return;
+        m_context->asyncTaskComplete(callbackID);
+    });
+}
+
 }
 
 #endif // PLATFORM(MAC)
index 1374e58..4b16f77 100644 (file)
@@ -157,11 +157,13 @@ JSValueRef UIScriptController::didHideKeyboardCallback() const
     return m_context->callbackWithID(CallbackTypeDidHideKeyboard);
 }
 
-#if !PLATFORM(IOS)
+#if !PLATFORM(COCOA)
 void UIScriptController::zoomToScale(double, JSValueRef)
 {
 }
+#endif
 
+#if !PLATFORM(IOS)
 void UIScriptController::touchDownAtPoint(long x, long y, long touchCount, JSValueRef)
 {
 }
index 71b7ba5..63f407d 100644 (file)
@@ -66,4 +66,23 @@ void UIScriptController::insertText(JSStringRef text, int location, int length)
 #endif
 }
 
+void UIScriptController::zoomToScale(double scale, JSValueRef callback)
+{
+#if WK_API_ENABLED
+    unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
+
+    auto* webView = TestController::singleton().mainWebView()->platformView();
+    [webView _setPageScale:scale withOrigin:CGPointZero];
+
+    [webView _doAfterNextPresentationUpdate: ^ {
+        if (!m_context)
+            return;
+        m_context->asyncTaskComplete(callbackID);
+    }];
+#else
+    UNUSED_PARAM(scale);
+    UNUSED_PARAM(callback);
+#endif
 }
+
+} // namespace WTR