[GTK] Add initial gestures support
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 20 Oct 2014 08:44:19 +0000 (08:44 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 20 Oct 2014 08:44:19 +0000 (08:44 +0000)
https://bugs.webkit.org/show_bug.cgi?id=137812

Reviewed by Sergio Villar Senin.

.:

Check if the GTK+ version supports gestures or not.

* Source/cmake/FindGTK3.cmake:
* Source/cmake/OptionsGTK.cmake:

Source/WebKit2:

Now that GTK+ has support for gestures, we can use it to handle
touch events and allow to scroll, zoom and tap with the fingers.

* PlatformGTK.cmake: Add new files to compilation.
* UIProcess/API/gtk/PageClientImpl.cpp:
(WebKit::PageClientImpl::doneWithTouchEvent): When the touch event
hasn't been handled by the web process pass it to the
GestureController and only fallback to pointer emulation when the
GestureController doesn't handle the event.
* UIProcess/API/gtk/WebKitWebViewBase.cpp:
(webkitWebViewBaseTouchEvent): If the GestureController is
currently processing gestures is because the START touch event was
not handled by the web process, so pass any successive touch
events to the GestureController directly.
(webkitWebViewBaseGestureController): Create the GestureController
on demand and return a reference.
* UIProcess/API/gtk/WebKitWebViewBasePrivate.h:
* UIProcess/gtk/GestureController.cpp: Added.
(WebKit::GestureController::create): Create a GestureController.
(WebKit::GestureController::GestureController): Initialize the
Gesture memebers.
(WebKit::GestureController::handleEvent): Pass the event to the gestures.
(WebKit::GestureController::isProcessingGestures): Whether
Gestures are active.
(WebKit::GestureController::Gesture::Gesture): Base class for gestures.
(WebKit::GestureController::Gesture::isActive): Whether the
gesture is active.
(WebKit::GestureController::Gesture::handleEvent): Pass the event
to the GtkGesture to process it.
(WebKit::GestureController::DragGesture::handleDrag): Send a wheel
event corresponding to the drag gesture to the web process.
(WebKit::GestureController::DragGesture::handleTap): Send move,
press and release events corresponding to a tap gesture to the web process.
(WebKit::GestureController::DragGesture::begin): Start a drag
gesture and schedule a timer to discard tap gesture in case of
long press.
(WebKit::GestureController::DragGesture::update): If the actual
drag hasn't started yet, check the drag threshold to decide
whether to start the drag or not. Otherwise call handleDrag() to
send the appropriate events to the web process.
(WebKit::GestureController::DragGesture::end): If the drag gesture
finishes and the drag didn't happen (it wasn't a long press and
drag threshold was not reached), call handleTap() to emulate a
click event.
(WebKit::GestureController::DragGesture::DragGesture): Initialize
the GtkGestureDrag.
(WebKit::GestureController::ZoomGesture::begin): Save the current
page scale factor and the center point of the gesture.
(WebKit::GestureController::ZoomGesture::scaleChanged): Schedule a
page scale change in an idle for the given scale value.
(WebKit::GestureController::ZoomGesture::ZoomGesture): Initialize
the GtkGestureZoom.
* UIProcess/gtk/GestureController.h: Added.

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

ChangeLog
Source/WebKit2/ChangeLog
Source/WebKit2/PlatformGTK.cmake
Source/WebKit2/UIProcess/API/gtk/PageClientImpl.cpp
Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp
Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBasePrivate.h
Source/WebKit2/UIProcess/gtk/GestureController.cpp [new file with mode: 0644]
Source/WebKit2/UIProcess/gtk/GestureController.h [new file with mode: 0644]
Source/cmake/FindGTK3.cmake
Source/cmake/OptionsGTK.cmake

index cc7c551e2dcfbd4ce5e2561e00dd84a0b44d7762..c415320af0cfe45f3740d71b1f5f8b335e0c1db9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2014-10-20  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Add initial gestures support
+        https://bugs.webkit.org/show_bug.cgi?id=137812
+
+        Reviewed by Sergio Villar Senin.
+
+        Check if the GTK+ version supports gestures or not.
+
+        * Source/cmake/FindGTK3.cmake:
+        * Source/cmake/OptionsGTK.cmake:
+
 2014-10-16  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         REGRESSION(CMake): [GTK] WebKitSettings:enable-smooth-scrolling does nothing
index 2d10e272247232a85bbcd8006742539fba1940c4..109fb5857b349c360bc536c1cda2b27a1e058410 100644 (file)
@@ -1,3 +1,64 @@
+2014-10-20  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Add initial gestures support
+        https://bugs.webkit.org/show_bug.cgi?id=137812
+
+        Reviewed by Sergio Villar Senin.
+
+        Now that GTK+ has support for gestures, we can use it to handle
+        touch events and allow to scroll, zoom and tap with the fingers.
+
+        * PlatformGTK.cmake: Add new files to compilation.
+        * UIProcess/API/gtk/PageClientImpl.cpp:
+        (WebKit::PageClientImpl::doneWithTouchEvent): When the touch event
+        hasn't been handled by the web process pass it to the
+        GestureController and only fallback to pointer emulation when the
+        GestureController doesn't handle the event.
+        * UIProcess/API/gtk/WebKitWebViewBase.cpp:
+        (webkitWebViewBaseTouchEvent): If the GestureController is
+        currently processing gestures is because the START touch event was
+        not handled by the web process, so pass any successive touch
+        events to the GestureController directly.
+        (webkitWebViewBaseGestureController): Create the GestureController
+        on demand and return a reference.
+        * UIProcess/API/gtk/WebKitWebViewBasePrivate.h:
+        * UIProcess/gtk/GestureController.cpp: Added.
+        (WebKit::GestureController::create): Create a GestureController.
+        (WebKit::GestureController::GestureController): Initialize the
+        Gesture memebers.
+        (WebKit::GestureController::handleEvent): Pass the event to the gestures.
+        (WebKit::GestureController::isProcessingGestures): Whether
+        Gestures are active.
+        (WebKit::GestureController::Gesture::Gesture): Base class for gestures.
+        (WebKit::GestureController::Gesture::isActive): Whether the
+        gesture is active.
+        (WebKit::GestureController::Gesture::handleEvent): Pass the event
+        to the GtkGesture to process it.
+        (WebKit::GestureController::DragGesture::handleDrag): Send a wheel
+        event corresponding to the drag gesture to the web process.
+        (WebKit::GestureController::DragGesture::handleTap): Send move,
+        press and release events corresponding to a tap gesture to the web process.
+        (WebKit::GestureController::DragGesture::begin): Start a drag
+        gesture and schedule a timer to discard tap gesture in case of
+        long press.
+        (WebKit::GestureController::DragGesture::update): If the actual
+        drag hasn't started yet, check the drag threshold to decide
+        whether to start the drag or not. Otherwise call handleDrag() to
+        send the appropriate events to the web process.
+        (WebKit::GestureController::DragGesture::end): If the drag gesture
+        finishes and the drag didn't happen (it wasn't a long press and
+        drag threshold was not reached), call handleTap() to emulate a
+        click event.
+        (WebKit::GestureController::DragGesture::DragGesture): Initialize
+        the GtkGestureDrag.
+        (WebKit::GestureController::ZoomGesture::begin): Save the current
+        page scale factor and the center point of the gesture.
+        (WebKit::GestureController::ZoomGesture::scaleChanged): Schedule a
+        page scale change in an idle for the given scale value.
+        (WebKit::GestureController::ZoomGesture::ZoomGesture): Initialize
+        the GtkGestureZoom.
+        * UIProcess/gtk/GestureController.h: Added.
+
 2014-10-19  Chris Dumez  <cdumez@apple.com>
 
         Use is<>() / downcast<>() for all remaining RenderObject subclasses
index ce30de96517f17af81f6f33159bc906be0242844..52e59d65c523b26ccb30f6a9ba2342b02194ab26 100644 (file)
@@ -253,6 +253,7 @@ list(APPEND WebKit2_SOURCES
 
     UIProcess/gtk/DragAndDropHandler.cpp
     UIProcess/gtk/ExperimentalFeatures.cpp
+    UIProcess/gtk/GestureController.cpp
     UIProcess/gtk/TextCheckerGtk.cpp
     UIProcess/gtk/WebContextGtk.cpp
     UIProcess/gtk/WebContextMenuProxyGtk.cpp
index 9bd412dccd937059ef522bf9363e9fd466c2b63b..9f3b8826905970f5f79a8783ffb964f446ff16a2 100644 (file)
@@ -340,6 +340,12 @@ void PageClientImpl::doneWithTouchEvent(const NativeWebTouchEvent& event, bool w
     if (wasEventHandled)
         return;
 
+#if HAVE(GTK_GESTURES)
+    GestureController& gestureController = webkitWebViewBaseGestureController(WEBKIT_WEB_VIEW_BASE(m_viewWidget));
+    if (gestureController.handleEvent(event.nativeEvent()))
+        return;
+#endif
+
     // Emulate pointer events if unhandled.
     const GdkEvent* touchEvent = event.nativeEvent();
 
index f7aae5e9be28e51cc68da30192518dfe903a27cd..4988347b43debe22a5030fdd4bcdc9c4342e564d 100644 (file)
@@ -138,6 +138,10 @@ struct _WebKitWebViewBasePrivate {
 #if ENABLE(DRAG_SUPPORT)
     std::unique_ptr<DragAndDropHandler> dragAndDropHandler;
 #endif
+
+#if HAVE(GTK_GESTURES)
+    std::unique_ptr<GestureController> gestureController;
+#endif
 };
 
 WEBKIT_DEFINE_TYPE(WebKitWebViewBase, webkit_web_view_base, GTK_TYPE_CONTAINER)
@@ -777,14 +781,25 @@ static void webkitWebViewBaseGetTouchPointsForEvent(WebKitWebViewBase* webViewBa
 
 static gboolean webkitWebViewBaseTouchEvent(GtkWidget* widget, GdkEventTouch* event)
 {
-    WebKitWebViewBasePrivate* priv = WEBKIT_WEB_VIEW_BASE(widget)->priv;
+    WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget);
+    WebKitWebViewBasePrivate* priv = webViewBase->priv;
 
     if (priv->authenticationDialog)
         return TRUE;
 
     GdkEvent* touchEvent = reinterpret_cast<GdkEvent*>(event);
-    uint32_t sequence = GPOINTER_TO_UINT(gdk_event_get_event_sequence(touchEvent));
 
+#if HAVE(GTK_GESTURES)
+    GestureController& gestureController = webkitWebViewBaseGestureController(webViewBase);
+    if (gestureController.isProcessingGestures()) {
+        // If we are already processing gestures is because the WebProcess didn't handle the
+        // BEGIN touch event, so pass subsequent events to the GestureController.
+        gestureController.handleEvent(touchEvent);
+        return TRUE;
+    }
+#endif
+
+    uint32_t sequence = GPOINTER_TO_UINT(gdk_event_get_event_sequence(touchEvent));
     switch (touchEvent->type) {
     case GDK_TOUCH_BEGIN: {
         ASSERT(!priv->touchEvents.contains(sequence));
@@ -807,12 +822,22 @@ static gboolean webkitWebViewBaseTouchEvent(GtkWidget* widget, GdkEventTouch* ev
     }
 
     Vector<WebPlatformTouchPoint> touchPoints;
-    webkitWebViewBaseGetTouchPointsForEvent(WEBKIT_WEB_VIEW_BASE(widget), touchEvent, touchPoints);
+    webkitWebViewBaseGetTouchPointsForEvent(webViewBase, touchEvent, touchPoints);
     priv->pageProxy->handleTouchEvent(NativeWebTouchEvent(reinterpret_cast<GdkEvent*>(event), touchPoints));
 
     return TRUE;
 }
 
+#if HAVE(GTK_GESTURES)
+GestureController& webkitWebViewBaseGestureController(WebKitWebViewBase* webViewBase)
+{
+    WebKitWebViewBasePrivate* priv = webViewBase->priv;
+    if (!priv->gestureController)
+        priv->gestureController = std::make_unique<GestureController>(*priv->pageProxy);
+    return *priv->gestureController;
+}
+#endif
+
 static gboolean webkitWebViewBaseQueryTooltip(GtkWidget* widget, gint /* x */, gint /* y */, gboolean keyboardMode, GtkTooltip* tooltip)
 {
     WebKitWebViewBasePrivate* priv = WEBKIT_WEB_VIEW_BASE(widget)->priv;
index e499dda79ab6c61d6285c7e2c84ed8df54915259..112e4cbd46b55ee25e308cf92664f0243da050be 100644 (file)
@@ -29,6 +29,7 @@
 #define WebKitWebViewBasePrivate_h
 
 #include "DragAndDropHandler.h"
+#include "GestureController.h"
 #include "WebContextMenuProxyGtk.h"
 #include "WebInspectorProxy.h"
 #include "WebKitPrivate.h"
@@ -78,4 +79,8 @@ void webkitWebViewBaseResetClickCounter(WebKitWebViewBase*);
 WebKit::DragAndDropHandler& webkitWebViewBaseDragAndDropHandler(WebKitWebViewBase*);
 #endif
 
+#if HAVE(GTK_GESTURES)
+WebKit::GestureController& webkitWebViewBaseGestureController(WebKitWebViewBase*);
+#endif
+
 #endif // WebKitWebViewBasePrivate_h
diff --git a/Source/WebKit2/UIProcess/gtk/GestureController.cpp b/Source/WebKit2/UIProcess/gtk/GestureController.cpp
new file mode 100644 (file)
index 0000000..c3669fa
--- /dev/null
@@ -0,0 +1,204 @@
+/*
+ * Copyright (C) 2014 Igalia S.L.
+ *
+ * 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 APPLE INC. AND ITS CONTRIBUTORS ``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 APPLE INC. OR ITS 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 "GestureController.h"
+
+#if HAVE(GTK_GESTURES)
+
+#include "NativeWebMouseEvent.h"
+#include "NativeWebWheelEvent.h"
+#include "WebPageProxy.h"
+#include <WebCore/FloatPoint.h>
+#include <WebCore/Scrollbar.h>
+#include <gtk/gtk.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+GestureController::GestureController(WebPageProxy& page)
+    : m_dragGesture(page)
+    , m_zoomGesture(page)
+{
+}
+
+bool GestureController::handleEvent(const GdkEvent* event)
+{
+    bool wasProcessingGestures = isProcessingGestures();
+    m_dragGesture.handleEvent(event);
+    m_zoomGesture.handleEvent(event);
+    return event->type == GDK_TOUCH_END ? wasProcessingGestures : isProcessingGestures();
+}
+
+bool GestureController::isProcessingGestures() const
+{
+    return m_dragGesture.isActive() || m_zoomGesture.isActive();
+}
+
+GestureController::Gesture::Gesture(GtkGesture* gesture, WebPageProxy& page)
+    : m_gesture(adoptGRef(gesture))
+    , m_page(page)
+{
+    gtk_event_controller_set_propagation_phase(GTK_EVENT_CONTROLLER(m_gesture.get()), GTK_PHASE_NONE);
+}
+
+bool GestureController::Gesture::isActive() const
+{
+    return gtk_gesture_is_active(m_gesture.get());
+}
+
+void GestureController::Gesture::handleEvent(const GdkEvent* event)
+{
+    gtk_event_controller_handle_event(GTK_EVENT_CONTROLLER(m_gesture.get()), event);
+}
+
+void GestureController::DragGesture::handleDrag(const GdkEvent* event, double x, double y)
+{
+    ASSERT(m_inDrag);
+    GUniquePtr<GdkEvent> scrollEvent(gdk_event_new(GDK_SCROLL));
+    scrollEvent->scroll.time = event->touch.time;
+    scrollEvent->scroll.x = m_start.x();
+    scrollEvent->scroll.y = m_start.y();
+    scrollEvent->scroll.x_root = event->touch.x_root;
+    scrollEvent->scroll.y_root = event->touch.y_root;
+    scrollEvent->scroll.direction = GDK_SCROLL_SMOOTH;
+    scrollEvent->scroll.delta_x = (m_offset.x() - x) / Scrollbar::pixelsPerLineStep();
+    scrollEvent->scroll.delta_y = (m_offset.y() - y) / Scrollbar::pixelsPerLineStep();
+    scrollEvent->scroll.state = event->touch.state;
+    m_page.handleWheelEvent(NativeWebWheelEvent(scrollEvent.get()));
+}
+
+void GestureController::DragGesture::handleTap(const GdkEvent* event)
+{
+    ASSERT(!m_inDrag);
+    GUniquePtr<GdkEvent> pointerEvent(gdk_event_new(GDK_MOTION_NOTIFY));
+    pointerEvent->motion.time = event->touch.time;
+    pointerEvent->motion.x = event->touch.x;
+    pointerEvent->motion.y = event->touch.y;
+    pointerEvent->motion.x_root = event->touch.x_root;
+    pointerEvent->motion.y_root = event->touch.y_root;
+    pointerEvent->motion.state = event->touch.state;
+    m_page.handleMouseEvent(NativeWebMouseEvent(pointerEvent.get(), 0));
+
+    pointerEvent.reset(gdk_event_new(GDK_BUTTON_PRESS));
+    pointerEvent->button.button = 1;
+    pointerEvent->button.time = event->touch.time;
+    pointerEvent->button.x = event->touch.x;
+    pointerEvent->button.y = event->touch.y;
+    pointerEvent->button.x_root = event->touch.x_root;
+    pointerEvent->button.y_root = event->touch.y_root;
+    m_page.handleMouseEvent(NativeWebMouseEvent(pointerEvent.get(), 1));
+
+    pointerEvent->type = GDK_BUTTON_RELEASE;
+    m_page.handleMouseEvent(NativeWebMouseEvent(pointerEvent.get(), 0));
+}
+
+void GestureController::DragGesture::begin(DragGesture* dragGesture, double x, double y, GtkGesture* gesture)
+{
+    GdkEventSequence* sequence = gtk_gesture_single_get_current_sequence(GTK_GESTURE_SINGLE(gesture));
+    gtk_gesture_set_sequence_state(gesture, sequence, GTK_EVENT_SEQUENCE_CLAIMED);
+    dragGesture->m_inDrag = false;
+    dragGesture->m_start.set(x, y);
+    dragGesture->m_offset.set(0, 0);
+
+    GtkWidget* widget = gtk_event_controller_get_widget(GTK_EVENT_CONTROLLER(gesture));
+    unsigned delay;
+    g_object_get(gtk_widget_get_settings(widget), "gtk-long-press-time", &delay, nullptr);
+    dragGesture->m_longPressTimeout.scheduleAfterDelay("[WebKit] DragGesture long press timeout", [dragGesture]() {
+        dragGesture->m_inDrag = true;
+    }, std::chrono::milliseconds(delay));
+}
+
+void GestureController::DragGesture::update(DragGesture* dragGesture, double x, double y, GtkGesture* gesture)
+{
+    GdkEventSequence* sequence = gtk_gesture_single_get_current_sequence(GTK_GESTURE_SINGLE(gesture));
+    gtk_gesture_set_sequence_state(gesture, sequence, GTK_EVENT_SEQUENCE_CLAIMED);
+
+    GtkWidget* widget = gtk_event_controller_get_widget(GTK_EVENT_CONTROLLER(gesture));
+    if (!dragGesture->m_inDrag && gtk_drag_check_threshold(widget, dragGesture->m_start.x(), dragGesture->m_start.y(), dragGesture->m_start.x() + x, dragGesture->m_start.y() + y)) {
+        dragGesture->m_inDrag = true;
+        dragGesture->m_longPressTimeout.cancel();
+    }
+
+    if (dragGesture->m_inDrag)
+        dragGesture->handleDrag(gtk_gesture_get_last_event(gesture, sequence), x, y);
+    dragGesture->m_offset.set(x, y);
+}
+
+void GestureController::DragGesture::end(DragGesture* dragGesture, GdkEventSequence* sequence, GtkGesture* gesture)
+{
+    dragGesture->m_longPressTimeout.cancel();
+    if (!dragGesture->m_inDrag) {
+        dragGesture->handleTap(gtk_gesture_get_last_event(gesture, sequence));
+        gtk_gesture_set_state(gesture, GTK_EVENT_SEQUENCE_DENIED);
+    } else if (!gtk_gesture_handles_sequence(gesture, sequence))
+        gtk_gesture_set_state(gesture, GTK_EVENT_SEQUENCE_DENIED);
+}
+
+GestureController::DragGesture::DragGesture(WebPageProxy& page)
+    : Gesture(gtk_gesture_drag_new(page.viewWidget()), page)
+    , m_inDrag(false)
+{
+    gtk_gesture_single_set_touch_only(GTK_GESTURE_SINGLE(m_gesture.get()), TRUE);
+    g_signal_connect_swapped(m_gesture.get(), "drag-begin", G_CALLBACK(begin), this);
+    g_signal_connect_swapped(m_gesture.get(), "drag-update", G_CALLBACK(update), this);
+    g_signal_connect_swapped(m_gesture.get(), "end", G_CALLBACK(end), this);
+}
+
+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);
+}
+
+void GestureController::ZoomGesture::scaleChanged(ZoomGesture* zoomGesture, double scale, GtkGesture*)
+{
+    zoomGesture->m_scale = zoomGesture->m_initialScale * scale;
+    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);
+    });
+}
+
+GestureController::ZoomGesture::ZoomGesture(WebPageProxy& page)
+    : Gesture(gtk_gesture_zoom_new(page.viewWidget()), page)
+    , m_initialScale(0)
+    , m_scale(0)
+{
+    g_signal_connect_swapped(m_gesture.get(), "begin", G_CALLBACK(begin), this);
+    g_signal_connect_swapped(m_gesture.get(), "scale-changed", G_CALLBACK(scaleChanged), this);
+}
+
+} // namespace WebKit
+
+#endif // HAVE(GTK_GESTURES)
diff --git a/Source/WebKit2/UIProcess/gtk/GestureController.h b/Source/WebKit2/UIProcess/gtk/GestureController.h
new file mode 100644 (file)
index 0000000..2a778be
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2014 Igalia S.L.
+ *
+ * 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 APPLE INC. AND ITS CONTRIBUTORS ``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 APPLE INC. OR ITS 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.
+ */
+
+#ifndef GestureController_h
+#define GestureController_h
+
+#if HAVE(GTK_GESTURES)
+
+#include <WebCore/FloatPoint.h>
+#include <wtf/Noncopyable.h>
+#include <wtf/gobject/GMainLoopSource.h>
+#include <wtf/gobject/GRefPtr.h>
+
+typedef union _GdkEvent GdkEvent;
+typedef struct _GdkEventSequence GdkEventSequence;
+typedef struct _GtkGesture GtkGesture;
+
+namespace WebKit {
+class WebPageProxy;
+
+class GestureController {
+    WTF_MAKE_NONCOPYABLE(GestureController);
+
+public:
+    GestureController(WebPageProxy&);
+
+    bool isProcessingGestures() const;
+    bool handleEvent(const GdkEvent*);
+
+private:
+    class Gesture {
+    public:
+        bool isActive() const;
+        void handleEvent(const GdkEvent*);
+
+    protected:
+        Gesture(GtkGesture*, WebPageProxy&);
+
+        GRefPtr<GtkGesture> m_gesture;
+        WebPageProxy& m_page;
+    };
+
+    class DragGesture final : public Gesture {
+    public:
+        DragGesture(WebPageProxy&);
+
+    private:
+        void handleDrag(const GdkEvent*, double x, double y);
+        void handleTap(const GdkEvent*);
+
+        static void begin(DragGesture*, double x, double y, GtkGesture*);
+        static void update(DragGesture*, double x, double y, GtkGesture*);
+        static void end(DragGesture*, GdkEventSequence*, GtkGesture*);
+
+        WebCore::FloatPoint m_start;
+        WebCore::FloatPoint m_offset;
+        GMainLoopSource m_longPressTimeout;
+        GRefPtr<GtkGesture> m_longPress;
+        bool m_inDrag;
+    };
+
+    class ZoomGesture final : public Gesture {
+    public:
+        ZoomGesture(WebPageProxy&);
+
+    private:
+        static void begin(ZoomGesture*, GdkEventSequence*, GtkGesture*);
+        static void scaleChanged(ZoomGesture*, double scale, GtkGesture*);
+
+        gdouble m_initialScale;
+        gdouble m_scale;
+        WebCore::IntPoint m_point;
+        GMainLoopSource m_idle;
+    };
+
+    DragGesture m_dragGesture;
+    ZoomGesture m_zoomGesture;
+};
+
+} // namespace WebKit
+
+#endif // HAVE(GTK_GESTURES)
+
+#endif // GestureController_h
index 0d8d0579c9e4ef037fb31eaaee33ca2d79756a3a..c8e8750c6915dbac34deebd4ebdcf896a123093a 100644 (file)
@@ -64,5 +64,11 @@ if (NOT(ENABLE_X11_TARGET OR ENABLE_WAYLAND_TARGET))
         "be enabled and also supported by the GTK+ dependency: X11, Wayland")
 endif ()
 
+if (GTK3_VERSION AND VERSION_OK AND NOT("${GTK3_VERSION}" VERSION_LESS "3.14.0"))
+    set(GTK_SUPPORTS_GESTURES ON)
+else ()
+    set(GTK_SUPPORTS_GESTURES OFF)
+endif ()
+
 include(FindPackageHandleStandardArgs)
 FIND_PACKAGE_HANDLE_STANDARD_ARGS(GTK3 DEFAULT_MSG GTK3_INCLUDE_DIRS GTK3_LIBRARIES VERSION_OK)
index cb51d7f43800186e0e79c17d583060077561e81c..8ec94a48ee51910d81c773f5b5ae6fd2635e56ba 100644 (file)
@@ -261,6 +261,10 @@ if (ENABLE_CREDENTIAL_STORAGE)
     set(ENABLE_CREDENTIAL_STORAGE 1)
 endif ()
 
+if (GTK_SUPPORTS_GESTURES)
+    add_definitions(-DHAVE_GTK_GESTURES=1)
+endif ()
+
 # This part can be simplified once CMake 2.8.6 is required and
 # CMakePushCheckState can be used. We need to have OPENGL_INCLUDE_DIR as part
 # of the directories check_include_files() looks for in case OpenGL is