Title: [174882] trunk/Source/WebKit2
Revision
174882
Author
[email protected]
Date
2014-10-20 03:39:58 -0700 (Mon, 20 Oct 2014)

Log Message

[GTK] Improve zooming gesture positioning
https://bugs.webkit.org/show_bug.cgi?id=137822

Patch by Carlos Garnacho <[email protected]> on 2014-10-20
Reviewed by Carlos Garcia Campos.

* UIProcess/WebPageProxy.h:
* UIProcess/gtk/GestureController.cpp:
(WebKit::GestureController::ZoomGesture::center):
(WebKit::GestureController::ZoomGesture::begin):
(WebKit::GestureController::ZoomGesture::handleZoom):
(WebKit::GestureController::ZoomGesture::scaleChanged): Calculate
the proper view coordinates for the current offset/scale, based
on the initial gesture center point in document coordinates, and
the current center/scale.
* UIProcess/gtk/GestureController.h:
* UIProcess/gtk/WebPageProxyGtk.cpp:
(WebKit::WebPageProxy::getCenterForZoomGesture): Added. Synchronous
call to retrieve the zoom gesture anchor point, in document coordinates.
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in: Added stub.
* WebProcess/WebPage/gtk/WebPageGtk.cpp:
(WebKit::WebPage::getCenterForZoomGesture): Added. Getter for the
translated coordinates used as the anchor point of the zoom gesture.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (174881 => 174882)


--- trunk/Source/WebKit2/ChangeLog	2014-10-20 09:54:50 UTC (rev 174881)
+++ trunk/Source/WebKit2/ChangeLog	2014-10-20 10:39:58 UTC (rev 174882)
@@ -1,3 +1,29 @@
+2014-10-20  Carlos Garnacho  <[email protected]>
+
+        [GTK] Improve zooming gesture positioning
+        https://bugs.webkit.org/show_bug.cgi?id=137822
+
+        Reviewed by Carlos Garcia Campos.
+
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/gtk/GestureController.cpp:
+        (WebKit::GestureController::ZoomGesture::center):
+        (WebKit::GestureController::ZoomGesture::begin):
+        (WebKit::GestureController::ZoomGesture::handleZoom):
+        (WebKit::GestureController::ZoomGesture::scaleChanged): Calculate
+        the proper view coordinates for the current offset/scale, based
+        on the initial gesture center point in document coordinates, and
+        the current center/scale.
+        * UIProcess/gtk/GestureController.h:
+        * UIProcess/gtk/WebPageProxyGtk.cpp:
+        (WebKit::WebPageProxy::getCenterForZoomGesture): Added. Synchronous
+        call to retrieve the zoom gesture anchor point, in document coordinates.
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in: Added stub.
+        * WebProcess/WebPage/gtk/WebPageGtk.cpp:
+        (WebKit::WebPage::getCenterForZoomGesture): Added. Getter for the
+        translated coordinates used as the anchor point of the zoom gesture.
+
 2014-10-20  Carlos Garcia Campos  <[email protected]>
 
         [GTK] Remove the factory method from DragAndDropHandler

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (174881 => 174882)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2014-10-20 09:54:50 UTC (rev 174881)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2014-10-20 10:39:58 UTC (rev 174882)
@@ -471,6 +471,10 @@
     void setInputMethodState(bool enabled);
 #endif
 
+#if PLATFORM (GTK) && HAVE(GTK_GESTURES)
+    void getCenterForZoomGesture(const WebCore::IntPoint& centerInViewCoordinates, WebCore::IntPoint& center);
+#endif
+
 #if PLATFORM(COCOA)
     void windowAndViewFramesChanged(const WebCore::FloatRect& viewFrameInWindowCoordinates, const WebCore::FloatPoint& accessibilityViewCoordinates);
     void setMainFrameIsScrollable(bool);

Modified: trunk/Source/WebKit2/UIProcess/gtk/GestureController.cpp (174881 => 174882)


--- trunk/Source/WebKit2/UIProcess/gtk/GestureController.cpp	2014-10-20 09:54:50 UTC (rev 174881)
+++ trunk/Source/WebKit2/UIProcess/gtk/GestureController.cpp	2014-10-20 10:39:58 UTC (rev 174882)
@@ -168,26 +168,41 @@
     g_signal_connect_swapped(m_gesture.get(), "end", G_CALLBACK(end), this);
 }
 
+IntPoint GestureController::ZoomGesture::center() const
+{
+    double x, y;
+    gtk_gesture_get_bounding_box_center(m_gesture.get(), &x, &y);
+    return IntPoint(x, y);
+}
+
 void GestureController::ZoomGesture::begin(ZoomGesture* zoomGesture, GdkEventSequence*, GtkGesture* gesture)
 {
     gtk_gesture_set_state(gesture, GTK_EVENT_SEQUENCE_CLAIMED);
 
     zoomGesture->m_initialScale = zoomGesture->m_page.pageScaleFactor();
-    double x, y;
-    gtk_gesture_get_bounding_box_center(gesture, &x, &y);
-    zoomGesture->m_point = IntPoint(x, y);
+    zoomGesture->m_page.getCenterForZoomGesture(zoomGesture->center(), zoomGesture->m_initialPoint);
 }
 
+void GestureController::ZoomGesture::handleZoom()
+{
+    IntPoint scaledOriginOffset = m_viewPoint;
+    scaledOriginOffset.scale(1 / m_scale, 1 / m_scale);
+
+    IntPoint newOrigin = m_initialPoint;
+    newOrigin.moveBy(-scaledOriginOffset);
+    newOrigin.scale(m_scale, m_scale);
+
+    m_page.scalePage(m_scale, newOrigin);
+}
+
 void GestureController::ZoomGesture::scaleChanged(ZoomGesture* zoomGesture, double scale, GtkGesture*)
 {
     zoomGesture->m_scale = zoomGesture->m_initialScale * scale;
+    zoomGesture->m_viewPoint = zoomGesture->center();
     if (zoomGesture->m_idle.isScheduled())
         return;
 
-    zoomGesture->m_idle.schedule("[WebKit] Zoom Gesture Idle", [zoomGesture]() {
-        // FIXME: Zoomed area is not correctly centered.
-        zoomGesture->m_page.scalePage(zoomGesture->m_scale, zoomGesture->m_point);
-    });
+    zoomGesture->m_idle.schedule("[WebKit] Zoom Gesture Idle", std::bind(&GestureController::ZoomGesture::handleZoom, zoomGesture));
 }
 
 GestureController::ZoomGesture::ZoomGesture(WebPageProxy& page)

Modified: trunk/Source/WebKit2/UIProcess/gtk/GestureController.h (174881 => 174882)


--- trunk/Source/WebKit2/UIProcess/gtk/GestureController.h	2014-10-20 09:54:50 UTC (rev 174881)
+++ trunk/Source/WebKit2/UIProcess/gtk/GestureController.h	2014-10-20 10:39:58 UTC (rev 174882)
@@ -86,12 +86,16 @@
         ZoomGesture(WebPageProxy&);
 
     private:
+        WebCore::IntPoint center() const;
+        void handleZoom();
+
         static void begin(ZoomGesture*, GdkEventSequence*, GtkGesture*);
         static void scaleChanged(ZoomGesture*, double scale, GtkGesture*);
 
         gdouble m_initialScale;
         gdouble m_scale;
-        WebCore::IntPoint m_point;
+        WebCore::IntPoint m_initialPoint;
+        WebCore::IntPoint m_viewPoint;
         GMainLoopSource m_idle;
     };
 

Modified: trunk/Source/WebKit2/UIProcess/gtk/WebPageProxyGtk.cpp (174881 => 174882)


--- trunk/Source/WebKit2/UIProcess/gtk/WebPageProxyGtk.cpp	2014-10-20 09:54:50 UTC (rev 174881)
+++ trunk/Source/WebKit2/UIProcess/gtk/WebPageProxyGtk.cpp	2014-10-20 10:39:58 UTC (rev 174882)
@@ -142,4 +142,11 @@
 }
 #endif
 
+#if HAVE(GTK_GESTURES)
+void WebPageProxy::getCenterForZoomGesture(const WebCore::IntPoint& centerInViewCoordinates, WebCore::IntPoint& center)
+{
+    process().sendSync(Messages::WebPage::GetCenterForZoomGesture(centerInViewCoordinates), Messages::WebPage::GetCenterForZoomGesture::Reply(center), m_pageID);
+}
+#endif
+
 } // namespace WebKit

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h (174881 => 174882)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2014-10-20 09:54:50 UTC (rev 174881)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2014-10-20 10:39:58 UTC (rev 174882)
@@ -578,6 +578,10 @@
     void cancelComposition();
 #endif
 
+#if PLATFORM (GTK) && HAVE(GTK_GESTURES)
+    void getCenterForZoomGesture(const WebCore::IntPoint& centerInViewCoordinates, WebCore::IntPoint& result);
+#endif
+
     void didChangeSelection();
 
 #if PLATFORM(COCOA)

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in (174881 => 174882)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in	2014-10-20 09:54:50 UTC (rev 174881)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in	2014-10-20 10:39:58 UTC (rev 174882)
@@ -310,6 +310,10 @@
     CancelComposition()
 #endif
 
+#if PLATFORM (GTK) && HAVE(GTK_GESTURES)
+    GetCenterForZoomGesture(WebCore::IntPoint centerInViewCoordinates) -> (WebCore::IntPoint center)
+#endif
+
 #if PLATFORM(COCOA)
     # Complex text input support for plug-ins.
     SendComplexTextInputToPlugin(uint64_t pluginComplexTextInputIdentifier, String textInput)

Modified: trunk/Source/WebKit2/WebProcess/WebPage/gtk/WebPageGtk.cpp (174881 => 174882)


--- trunk/Source/WebKit2/WebProcess/WebPage/gtk/WebPageGtk.cpp	2014-10-20 09:54:50 UTC (rev 174881)
+++ trunk/Source/WebKit2/WebProcess/WebPage/gtk/WebPageGtk.cpp	2014-10-20 10:39:58 UTC (rev 174882)
@@ -37,6 +37,7 @@
 #include <WebCore/EventHandler.h>
 #include <WebCore/FocusController.h>
 #include <WebCore/Frame.h>
+#include <WebCore/FrameView.h>
 #include <WebCore/KeyboardEvent.h>
 #include <WebCore/Page.h>
 #include <WebCore/PasteboardHelper.h>
@@ -181,4 +182,13 @@
     return WebCore::standardUserAgentForURL(url);
 }
 
+#if HAVE(GTK_GESTURES)
+void WebPage::getCenterForZoomGesture(const IntPoint& centerInViewCoordinates, IntPoint& result)
+{
+    result = mainFrameView()->rootViewToContents(centerInViewCoordinates);
+    double scale = m_page->pageScaleFactor();
+    result.scale(1 / scale, 1 / scale);
+}
+#endif
+
 } // namespace WebKit
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to