Title: [174880] trunk
Revision
174880
Author
[email protected]
Date
2014-10-20 01:44:19 -0700 (Mon, 20 Oct 2014)

Log Message

[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:

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.

Modified Paths

Added Paths

Diff

Modified: trunk/ChangeLog (174879 => 174880)


--- trunk/ChangeLog	2014-10-20 08:23:26 UTC (rev 174879)
+++ trunk/ChangeLog	2014-10-20 08:44:19 UTC (rev 174880)
@@ -1,3 +1,15 @@
+2014-10-20  Carlos Garcia Campos  <[email protected]>
+
+        [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  <[email protected]>
 
         REGRESSION(CMake): [GTK] WebKitSettings:enable-smooth-scrolling does nothing

Modified: trunk/Source/WebKit2/ChangeLog (174879 => 174880)


--- trunk/Source/WebKit2/ChangeLog	2014-10-20 08:23:26 UTC (rev 174879)
+++ trunk/Source/WebKit2/ChangeLog	2014-10-20 08:44:19 UTC (rev 174880)
@@ -1,3 +1,64 @@
+2014-10-20  Carlos Garcia Campos  <[email protected]>
+
+        [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  <[email protected]>
 
         Use is<>() / downcast<>() for all remaining RenderObject subclasses

Modified: trunk/Source/WebKit2/PlatformGTK.cmake (174879 => 174880)


--- trunk/Source/WebKit2/PlatformGTK.cmake	2014-10-20 08:23:26 UTC (rev 174879)
+++ trunk/Source/WebKit2/PlatformGTK.cmake	2014-10-20 08:44:19 UTC (rev 174880)
@@ -253,6 +253,7 @@
 
     UIProcess/gtk/DragAndDropHandler.cpp
     UIProcess/gtk/ExperimentalFeatures.cpp
+    UIProcess/gtk/GestureController.cpp
     UIProcess/gtk/TextCheckerGtk.cpp
     UIProcess/gtk/WebContextGtk.cpp
     UIProcess/gtk/WebContextMenuProxyGtk.cpp

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/PageClientImpl.cpp (174879 => 174880)


--- trunk/Source/WebKit2/UIProcess/API/gtk/PageClientImpl.cpp	2014-10-20 08:23:26 UTC (rev 174879)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/PageClientImpl.cpp	2014-10-20 08:44:19 UTC (rev 174880)
@@ -340,6 +340,12 @@
     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();
 

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp (174879 => 174880)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp	2014-10-20 08:23:26 UTC (rev 174879)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp	2014-10-20 08:44:19 UTC (rev 174880)
@@ -138,6 +138,10 @@
 #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 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);
+
+#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 @@
     }
 
     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;

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBasePrivate.h (174879 => 174880)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBasePrivate.h	2014-10-20 08:23:26 UTC (rev 174879)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBasePrivate.h	2014-10-20 08:44:19 UTC (rev 174880)
@@ -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 @@
 WebKit::DragAndDropHandler& webkitWebViewBaseDragAndDropHandler(WebKitWebViewBase*);
 #endif
 
+#if HAVE(GTK_GESTURES)
+WebKit::GestureController& webkitWebViewBaseGestureController(WebKitWebViewBase*);
+#endif
+
 #endif // WebKitWebViewBasePrivate_h

Added: trunk/Source/WebKit2/UIProcess/gtk/GestureController.cpp (0 => 174880)


--- trunk/Source/WebKit2/UIProcess/gtk/GestureController.cpp	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/gtk/GestureController.cpp	2014-10-20 08:44:19 UTC (rev 174880)
@@ -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)

Added: trunk/Source/WebKit2/UIProcess/gtk/GestureController.h (0 => 174880)


--- trunk/Source/WebKit2/UIProcess/gtk/GestureController.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/gtk/GestureController.h	2014-10-20 08:44:19 UTC (rev 174880)
@@ -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

Modified: trunk/Source/cmake/FindGTK3.cmake (174879 => 174880)


--- trunk/Source/cmake/FindGTK3.cmake	2014-10-20 08:23:26 UTC (rev 174879)
+++ trunk/Source/cmake/FindGTK3.cmake	2014-10-20 08:44:19 UTC (rev 174880)
@@ -64,5 +64,11 @@
         "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)

Modified: trunk/Source/cmake/OptionsGTK.cmake (174879 => 174880)


--- trunk/Source/cmake/OptionsGTK.cmake	2014-10-20 08:23:26 UTC (rev 174879)
+++ trunk/Source/cmake/OptionsGTK.cmake	2014-10-20 08:44:19 UTC (rev 174880)
@@ -261,6 +261,10 @@
     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
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to