[WK2][CoordinatedGraphics][EFL] WKViewUserViewportToContents() function doesn't do...
authormarcelo.lira@openbossa.org <marcelo.lira@openbossa.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 May 2013 14:34:19 +0000 (14:34 +0000)
committermarcelo.lira@openbossa.org <marcelo.lira@openbossa.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 May 2013 14:34:19 +0000 (14:34 +0000)
https://bugs.webkit.org/show_bug.cgi?id=116683

Reviewed by Noam Rosenthal.

Source/WebKit2:

WKViewUserViewportToContents now converts WebView coordinates to
page contents coordinates, taking into account factors as content
scale and scroll, and also device scale.

The function WKViewUserViewportToScene was added to convert WebView
coordinates to the coordinates of the canvas/scene where the view
is drawn, and EwkView was fixed to use it, instead of
WKViewUserViewportToContents.

* UIProcess/API/C/CoordinatedGraphics/WKView.cpp:
(WKViewUserViewportToScene):
* UIProcess/API/C/CoordinatedGraphics/WKView.h:
* UIProcess/API/efl/EwkView.cpp:
(EwkView::createGLSurface):
* UIProcess/CoordinatedGraphics/WebView.cpp:
(WebKit::WebView::userViewportToContents):
(WebKit):
(WebKit::WebView::userViewportToScene):
(WebKit::WebView::transformToScene):
* UIProcess/CoordinatedGraphics/WebView.h:
(WebView):

Tools:

A coordinates conversion test for WKViewUserViewportToContents was
added to WebKit2 API tests.

* TestWebKitAPI/PlatformEfl.cmake:
* TestWebKitAPI/Tests/WebKit2/CoordinatedGraphics/WKViewUserViewportToContents.cpp: Added.
(TestWebKitAPI):
(TestWebKitAPI::TEST):

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/C/CoordinatedGraphics/WKView.cpp
Source/WebKit2/UIProcess/API/C/CoordinatedGraphics/WKView.h
Source/WebKit2/UIProcess/API/efl/EwkView.cpp
Source/WebKit2/UIProcess/CoordinatedGraphics/WebView.cpp
Source/WebKit2/UIProcess/CoordinatedGraphics/WebView.h
Tools/ChangeLog
Tools/TestWebKitAPI/PlatformEfl.cmake
Tools/TestWebKitAPI/Tests/WebKit2/CoordinatedGraphics/WKViewUserViewportToContents.cpp [new file with mode: 0644]

index 3341f3f..253cafe 100644 (file)
@@ -1,3 +1,32 @@
+2013-05-29  Marcelo Lira  <marcelo.lira@openbossa.org>
+
+        [WK2][CoordinatedGraphics][EFL] WKViewUserViewportToContents() function doesn't do what it says
+        https://bugs.webkit.org/show_bug.cgi?id=116683
+
+        Reviewed by Noam Rosenthal.
+
+        WKViewUserViewportToContents now converts WebView coordinates to
+        page contents coordinates, taking into account factors as content
+        scale and scroll, and also device scale.
+
+        The function WKViewUserViewportToScene was added to convert WebView
+        coordinates to the coordinates of the canvas/scene where the view
+        is drawn, and EwkView was fixed to use it, instead of
+        WKViewUserViewportToContents.
+
+        * UIProcess/API/C/CoordinatedGraphics/WKView.cpp:
+        (WKViewUserViewportToScene):
+        * UIProcess/API/C/CoordinatedGraphics/WKView.h:
+        * UIProcess/API/efl/EwkView.cpp:
+        (EwkView::createGLSurface):
+        * UIProcess/CoordinatedGraphics/WebView.cpp:
+        (WebKit::WebView::userViewportToContents):
+        (WebKit):
+        (WebKit::WebView::userViewportToScene):
+        (WebKit::WebView::transformToScene):
+        * UIProcess/CoordinatedGraphics/WebView.h:
+        (WebView):
+
 2013-05-29  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         Unreviewed. Fix make distcheck.
index 60f9dd4..c241dd9 100644 (file)
@@ -106,6 +106,12 @@ WKPoint WKViewUserViewportToContents(WKViewRef viewRef, WKPoint point)
     return WKPointMake(result.x(), result.y());
 }
 
+WKPoint WKViewUserViewportToScene(WKViewRef viewRef, WKPoint point)
+{
+    WebCore::IntPoint result = toImpl(viewRef)->userViewportToScene(toIntPoint(point));
+    return WKPointMake(result.x(), result.y());
+}
+
 void WKViewPaintToCurrentGLContext(WKViewRef viewRef)
 {
     toImpl(viewRef)->paintToCurrentGLContext();
index f689254..9bf95db 100644 (file)
@@ -79,6 +79,7 @@ WK_EXPORT void WKViewSetContentPosition(WKViewRef, WKPoint);
 
 WK_EXPORT void WKViewSetUserViewportTranslation(WKViewRef, double tx, double ty);
 WK_EXPORT WKPoint WKViewUserViewportToContents(WKViewRef, WKPoint);
+WK_EXPORT WKPoint WKViewUserViewportToScene(WKViewRef, WKPoint);
 
 WK_EXPORT void WKViewPaintToCurrentGLContext(WKViewRef);
 
index 09f49a6..7635a0f 100644 (file)
@@ -774,7 +774,7 @@ bool EwkView::createGLSurface()
 
     Evas_GL_API* gl = evas_gl_api_get(m_evasGL.get());
 
-    const WKPoint& boundsEnd = WKViewUserViewportToContents(wkView(), WKPointMake(deviceSize().width(), deviceSize().height()));
+    WKPoint boundsEnd = WKViewUserViewportToScene(wkView(), WKPointMake(deviceSize().width(), deviceSize().height()));
     gl->glViewport(0, 0, boundsEnd.x, boundsEnd.y);
     gl->glClearColor(1.0, 1.0, 1.0, 0);
     gl->glClear(GL_COLOR_BUFFER_BIT);
index 4ea46cd..57e61fc 100644 (file)
@@ -110,6 +110,11 @@ void WebView::setUserViewportTranslation(double tx, double ty)
 
 IntPoint WebView::userViewportToContents(const IntPoint& point) const
 {
+    return transformFromScene().mapPoint(point);
+}
+
+IntPoint WebView::userViewportToScene(const WebCore::IntPoint& point) const
+{
     return m_userViewportTransform.mapPoint(point);
 }
 
@@ -202,12 +207,13 @@ AffineTransform WebView::transformFromScene() const
 
 AffineTransform WebView::transformToScene() const
 {
-    TransformationMatrix transform = m_userViewportTransform;
+    FloatPoint position = -m_contentPosition;
+    float effectiveScale = m_contentScaleFactor * m_page->deviceScaleFactor();
+    position.scale(effectiveScale, effectiveScale);
 
-    const FloatPoint& position = contentPosition();
-    transform.scale(m_page->deviceScaleFactor());
-    transform.translate(-position.x(), -position.y());
-    transform.scale(contentScaleFactor());
+    TransformationMatrix transform = m_userViewportTransform;
+    transform.translate(position.x(), position.y());
+    transform.scale(effectiveScale);
 
     return transform.toAffineTransform();
 }
index c7719ce..f982832 100644 (file)
@@ -71,6 +71,7 @@ public:
 
     void setUserViewportTranslation(double tx, double ty);
     WebCore::IntPoint userViewportToContents(const WebCore::IntPoint&) const;
+    WebCore::IntPoint userViewportToScene(const WebCore::IntPoint&) const;
 
     void paintToCurrentGLContext();
 
index a1438f9..3ff81b7 100644 (file)
@@ -1,3 +1,18 @@
+2013-05-29  Marcelo Lira  <marcelo.lira@openbossa.org>
+
+        [WK2][CoordinatedGraphics][EFL] WKViewUserViewportToContents() function doesn't do what it says
+        https://bugs.webkit.org/show_bug.cgi?id=116683
+
+        Reviewed by Noam Rosenthal.
+
+        A coordinates conversion test for WKViewUserViewportToContents was
+        added to WebKit2 API tests.
+
+        * TestWebKitAPI/PlatformEfl.cmake:
+        * TestWebKitAPI/Tests/WebKit2/CoordinatedGraphics/WKViewUserViewportToContents.cpp: Added.
+        (TestWebKitAPI):
+        (TestWebKitAPI::TEST):
+
 2013-05-29  Yong Li  <yong.li.webkit@outlook.com>
 
         Unreviewed. Update my info.
index 1ee0142..870dc1b 100644 (file)
@@ -94,6 +94,7 @@ set(test_webkit2_api_BINARIES
     WKStringJSString
     WKURL
     WillSendSubmitEvent
+    CoordinatedGraphics/WKViewUserViewportToContents
     efl/WKViewClientWebProcessCallbacks
 )
 
diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/CoordinatedGraphics/WKViewUserViewportToContents.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/CoordinatedGraphics/WKViewUserViewportToContents.cpp
new file mode 100644 (file)
index 0000000..de80f44
--- /dev/null
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies).
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include "WebKit2/WKView.h"
+#include "WebKit2/WKRetainPtr.h"
+
+namespace TestWebKitAPI {
+
+TEST(WebKit2, WKViewUserViewportToContents)
+{
+    // This test creates a WKView and uses the WKViewUserViewportToContents
+    // function to convert viewport coordinates to contents (page) coordinates.
+    // It scrolls and scales around the contents and check if the coordinates
+    // conversion math is right.
+
+    WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate());
+    WKRetainPtr<WKViewRef> webView(AdoptWK, WKViewCreate(context.get(), 0));
+
+    WKViewInitialize(webView.get());
+    WKPageSetUseFixedLayout(WKViewGetPage(webView.get()), false);
+
+    WKPoint out;
+
+    // At scale 1.0 the viewport and contents coordinates should match.
+
+    WKViewSetContentScaleFactor(webView.get(), 1.0);
+    WKViewSetContentPosition(webView.get(), WKPointMake(0, 0));
+
+    out = WKViewUserViewportToContents(webView.get(), WKPointMake(0, 0));
+    EXPECT_EQ(out.x, 0);
+    EXPECT_EQ(out.y, 0);
+
+    out = WKViewUserViewportToContents(webView.get(), WKPointMake(10, 10));
+    EXPECT_EQ(out.x, 10);
+    EXPECT_EQ(out.y, 10);
+
+    WKViewSetContentPosition(webView.get(), WKPointMake(20, 20));
+
+    out = WKViewUserViewportToContents(webView.get(), WKPointMake(0, 0));
+    EXPECT_EQ(out.x, 20);
+    EXPECT_EQ(out.y, 20);
+
+    out = WKViewUserViewportToContents(webView.get(), WKPointMake(10, 10));
+    EXPECT_EQ(out.x, 30);
+    EXPECT_EQ(out.y, 30);
+
+    // At scale 2.0 the viewport distance values will be half
+    // the ones seem in the contents.
+
+    WKViewSetContentScaleFactor(webView.get(), 2.0);
+    WKViewSetContentPosition(webView.get(), WKPointMake(0, 0));
+
+    out = WKViewUserViewportToContents(webView.get(), WKPointMake(0, 0));
+    EXPECT_EQ(out.x, 0);
+    EXPECT_EQ(out.y, 0);
+
+    out = WKViewUserViewportToContents(webView.get(), WKPointMake(10, 10));
+    EXPECT_EQ(out.x, 5);
+    EXPECT_EQ(out.y, 5);
+
+    WKViewSetContentPosition(webView.get(), WKPointMake(20, 20));
+
+    out = WKViewUserViewportToContents(webView.get(), WKPointMake(0, 0));
+    EXPECT_EQ(out.x, 20);
+    EXPECT_EQ(out.y, 20);
+
+    out = WKViewUserViewportToContents(webView.get(), WKPointMake(10, 10));
+    EXPECT_EQ(out.x, 25);
+    EXPECT_EQ(out.y, 25);
+
+    // At scale 0.5 the viewport distance values will be twice
+    // the ones seem in the contents.
+
+    WKViewSetContentScaleFactor(webView.get(), 0.5);
+    WKViewSetContentPosition(webView.get(), WKPointMake(0, 0));
+
+    out = WKViewUserViewportToContents(webView.get(), WKPointMake(0, 0));
+    EXPECT_EQ(out.x, 0);
+    EXPECT_EQ(out.y, 0);
+
+    out = WKViewUserViewportToContents(webView.get(), WKPointMake(10, 10));
+    EXPECT_EQ(out.x, 20);
+    EXPECT_EQ(out.y, 20);
+
+    WKViewSetContentPosition(webView.get(), WKPointMake(20, 20));
+
+    out = WKViewUserViewportToContents(webView.get(), WKPointMake(0, 0));
+    EXPECT_EQ(out.x, 20);
+    EXPECT_EQ(out.y, 20);
+
+    out = WKViewUserViewportToContents(webView.get(), WKPointMake(10, 10));
+    EXPECT_EQ(out.x, 40);
+    EXPECT_EQ(out.y, 40);
+
+    // Let's add translation to the viewport.
+
+    const int delta = 10;
+    WKViewSetUserViewportTranslation(webView.get(), delta, delta);
+
+    WKViewSetContentPosition(webView.get(), WKPointMake(0, 0));
+
+    out = WKViewUserViewportToContents(webView.get(), WKPointMake(0, 0));
+    EXPECT_EQ(out.x, 0 - delta / 0.5);
+    EXPECT_EQ(out.y, 0 - delta / 0.5);
+
+    out = WKViewUserViewportToContents(webView.get(), WKPointMake(10, 10));
+    EXPECT_EQ(out.x, 20 - delta / 0.5);
+    EXPECT_EQ(out.y, 20 - delta / 0.5);
+
+    WKViewSetContentPosition(webView.get(), WKPointMake(20, 20));
+
+    out = WKViewUserViewportToContents(webView.get(), WKPointMake(0, 0));
+    EXPECT_EQ(out.x, 20 - delta / 0.5);
+    EXPECT_EQ(out.y, 20 - delta / 0.5);
+
+    out = WKViewUserViewportToContents(webView.get(), WKPointMake(10, 10));
+    EXPECT_EQ(out.x, 40 - delta / 0.5);
+    EXPECT_EQ(out.y, 40 - delta / 0.5);
+}
+
+}