Title: [279574] trunk/Source/WebKit
Revision
279574
Author
[email protected]
Date
2021-07-05 22:45:23 -0700 (Mon, 05 Jul 2021)

Log Message

[GTK] Navigation swipe gesture can be triggered with mouse
https://bugs.webkit.org/show_bug.cgi?id=227678

Patch by Alexander Mikhaylenko <[email protected]> on 2021-07-05
Reviewed by Carlos Garcia Campos.

Originally, the navigation swipe gesture had a few checks to only make it possible to
trigger it with a touchpad or touchscreen, with an exception for simulated swipes
where we couldn't set the source easily.

During the rewrite in https://bugs.webkit.org/show_bug.cgi?id=212324, the check got
dropped, but it has a good reason to be there: not all devices are capable of
performing a gesture. Touchpads and touchscreens should be fine, trackpoints are
finicky, though can still technically work, but mouse are a no-go. While they can
start a swipe, they will never end it and the gesture will get stuck.

So, add the check back. Don't bother with the scroll direction this time though, while
that check made sense when it got added, at some point since then all scroll events
had GDK_SCROLL_SMOOTH direction and just set their deltas to (1, 0), (-1, 0), (0, 1)
or (0, -1), so that check stopped working, and the source type check should filter
mouse events anyway.

* UIProcess/API/gtk/PageClientImpl.cpp:
(WebKit::PageClientImpl::wheelEventWasNotHandledByWebCore):
* UIProcess/API/gtk/WebKitWebViewBase.cpp:
(webkitWebViewBaseHandleWheelEvent):
(webkitWebViewBaseScroll):
(webkitWebViewBaseTouchDragUpdate):
(webkitWebViewBaseTouchDragEnd):
* UIProcess/ViewGestureController.h:
* UIProcess/gtk/ViewGestureControllerGtk.cpp:
(WebKit::ViewGestureController::PendingSwipeTracker::scrollEventCanInfluenceSwipe):
(WebKit::isTouchEvent):
(WebKit::ViewGestureController::beginSimulatedSwipeInDirectionForTesting):
(WebKit::ViewGestureController::completeSimulatedSwipeInDirectionForTesting):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (279573 => 279574)


--- trunk/Source/WebKit/ChangeLog	2021-07-06 00:56:02 UTC (rev 279573)
+++ trunk/Source/WebKit/ChangeLog	2021-07-06 05:45:23 UTC (rev 279574)
@@ -1,5 +1,42 @@
 2021-07-05  Alexander Mikhaylenko  <[email protected]>
 
+        [GTK] Navigation swipe gesture can be triggered with mouse
+        https://bugs.webkit.org/show_bug.cgi?id=227678
+
+        Reviewed by Carlos Garcia Campos.
+
+        Originally, the navigation swipe gesture had a few checks to only make it possible to
+        trigger it with a touchpad or touchscreen, with an exception for simulated swipes
+        where we couldn't set the source easily.
+
+        During the rewrite in https://bugs.webkit.org/show_bug.cgi?id=212324, the check got
+        dropped, but it has a good reason to be there: not all devices are capable of
+        performing a gesture. Touchpads and touchscreens should be fine, trackpoints are
+        finicky, though can still technically work, but mouse are a no-go. While they can
+        start a swipe, they will never end it and the gesture will get stuck.
+
+        So, add the check back. Don't bother with the scroll direction this time though, while
+        that check made sense when it got added, at some point since then all scroll events
+        had GDK_SCROLL_SMOOTH direction and just set their deltas to (1, 0), (-1, 0), (0, 1)
+        or (0, -1), so that check stopped working, and the source type check should filter
+        mouse events anyway.
+
+        * UIProcess/API/gtk/PageClientImpl.cpp:
+        (WebKit::PageClientImpl::wheelEventWasNotHandledByWebCore):
+        * UIProcess/API/gtk/WebKitWebViewBase.cpp:
+        (webkitWebViewBaseHandleWheelEvent):
+        (webkitWebViewBaseScroll):
+        (webkitWebViewBaseTouchDragUpdate):
+        (webkitWebViewBaseTouchDragEnd):
+        * UIProcess/ViewGestureController.h:
+        * UIProcess/gtk/ViewGestureControllerGtk.cpp:
+        (WebKit::ViewGestureController::PendingSwipeTracker::scrollEventCanInfluenceSwipe):
+        (WebKit::isTouchEvent):
+        (WebKit::ViewGestureController::beginSimulatedSwipeInDirectionForTesting):
+        (WebKit::ViewGestureController::completeSimulatedSwipeInDirectionForTesting):
+
+2021-07-05  Alexander Mikhaylenko  <[email protected]>
+
         [GTK] Kinetic scrolling interferes with gestures
         https://bugs.webkit.org/show_bug.cgi?id=226680
 

Modified: trunk/Source/WebKit/UIProcess/API/gtk/PageClientImpl.cpp (279573 => 279574)


--- trunk/Source/WebKit/UIProcess/API/gtk/PageClientImpl.cpp	2021-07-06 00:56:02 UTC (rev 279573)
+++ trunk/Source/WebKit/UIProcess/API/gtk/PageClientImpl.cpp	2021-07-06 05:45:23 UTC (rev 279574)
@@ -427,9 +427,15 @@
     if (controller && controller->isSwipeGestureEnabled()) {
         double deltaX;
         gdk_event_get_scroll_deltas(event.nativeEvent(), &deltaX, nullptr);
+
+        int32_t eventTime = static_cast<int32_t>(gdk_event_get_time(event.nativeEvent()));
+
+        GdkDevice* device = gdk_event_get_source_device(event.nativeEvent());
+        GdkInputSource source = gdk_device_get_source(device);
+
         bool isEnd = gdk_event_is_scroll_stop_event(event.nativeEvent()) ? true : false;
-        int32_t eventTime = static_cast<int32_t>(gdk_event_get_time(event.nativeEvent()));
-        PlatformGtkScrollData scrollData = { .delta = deltaX, .eventTime = eventTime, .isTouch = false, .isEnd = isEnd };
+
+        PlatformGtkScrollData scrollData = { .delta = deltaX, .eventTime = eventTime, .source = source, .isEnd = isEnd };
         controller->wheelEventWasNotHandledByWebCore(&scrollData);
         return;
     }

Modified: trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp (279573 => 279574)


--- trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp	2021-07-06 00:56:02 UTC (rev 279573)
+++ trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp	2021-07-06 05:45:23 UTC (rev 279574)
@@ -1266,9 +1266,15 @@
     if (controller && controller->isSwipeGestureEnabled()) {
         double deltaX;
         gdk_event_get_scroll_deltas(event, &deltaX, nullptr);
+
+        int32_t eventTime = static_cast<int32_t>(gdk_event_get_time(event));
+
+        GdkDevice* device = gdk_event_get_source_device(event);
+        GdkInputSource source = gdk_device_get_source(device);
+
         bool isEnd = gdk_event_is_scroll_stop_event(event) ? true : false;
-        int32_t eventTime = static_cast<int32_t>(gdk_event_get_time(event));
-        PlatformGtkScrollData scrollData = { .delta = deltaX, .eventTime = eventTime, .isTouch = false, .isEnd = isEnd };
+
+        PlatformGtkScrollData scrollData = { .delta = deltaX, .eventTime = eventTime, .source = source, .isEnd = isEnd };
         if (controller->handleScrollWheelEvent(&scrollData))
             return;
     }
@@ -1329,9 +1335,14 @@
 
     ViewGestureController* controller = webkitWebViewBaseViewGestureController(webViewBase);
     if (controller && controller->isSwipeGestureEnabled()) {
+        int32_t eventTime = static_cast<int32_t>(gtk_event_controller_get_current_event_time(eventController));
+
+        GdkDevice* device = gdk_event_get_device(event);
+        GdkInputSource source = gdk_device_get_source(device);
+
         bool isEnd = gdk_scroll_event_is_stop(event) ? true : false;
-        int32_t eventTime = static_cast<int32_t>(gtk_event_controller_get_current_event_time(eventController));
-        PlatformGtkScrollData scrollData = { .delta = deltaX, .eventTime = eventTime, .isTouch = false, .isEnd = isEnd };
+
+        PlatformGtkScrollData scrollData = { .delta = deltaX, .eventTime = eventTime, .source = source, .isEnd = isEnd };
         if (controller->handleScrollWheelEvent(&scrollData))
             return GDK_EVENT_STOP;
     }
@@ -1971,7 +1982,7 @@
         ViewGestureController* controller = webkitWebViewBaseViewGestureController(webViewBase);
         if (controller && controller->isSwipeGestureEnabled()) {
             int32_t eventTime = static_cast<int32_t>(gtk_event_controller_get_current_event_time(GTK_EVENT_CONTROLLER(gesture)));
-            PlatformGtkScrollData scrollData = { .delta = deltaX, .eventTime = eventTime, .isTouch = true, .isEnd = false };
+            PlatformGtkScrollData scrollData = { .delta = deltaX, .eventTime = eventTime, .source = GDK_SOURCE_TOUCHSCREEN, .isEnd = false };
             if (controller->handleScrollWheelEvent(&scrollData))
                 return;
         }
@@ -1995,7 +2006,7 @@
         ViewGestureController* controller = webkitWebViewBaseViewGestureController(webViewBase);
         if (controller && controller->isSwipeGestureEnabled()) {
             int32_t eventTime = static_cast<int32_t>(gtk_event_controller_get_current_event_time(GTK_EVENT_CONTROLLER(gesture)));
-            PlatformGtkScrollData scrollData = { .delta = 0, .eventTime = eventTime, .isTouch = false, .isEnd = true };
+            PlatformGtkScrollData scrollData = { .delta = 0, .eventTime = eventTime, .source = GDK_SOURCE_TOUCHSCREEN, .isEnd = true };
             controller->handleScrollWheelEvent(&scrollData);
         }
     }

Modified: trunk/Source/WebKit/UIProcess/ViewGestureController.h (279573 => 279574)


--- trunk/Source/WebKit/UIProcess/ViewGestureController.h	2021-07-06 00:56:02 UTC (rev 279573)
+++ trunk/Source/WebKit/UIProcess/ViewGestureController.h	2021-07-06 05:45:23 UTC (rev 279574)
@@ -82,7 +82,7 @@
 typedef struct {
     double delta;
     int32_t eventTime;
-    bool isTouch;
+    GdkInputSource source;
     bool isEnd;
 } PlatformGtkScrollData;
 typedef PlatformGtkScrollData* PlatformScrollEvent;
@@ -472,10 +472,8 @@
     int m_swipeOutlineSize;
     GRefPtr<GtkCssProvider> m_cssProvider;
 #endif
+#endif // PLATFORM(GTK)
 
-    bool m_isSimulatedSwipe { false };
-#endif
-
     bool m_isConnectedToProcess { false };
     bool m_didStartProvisionalLoad { false };
 

Modified: trunk/Source/WebKit/UIProcess/gtk/ViewGestureControllerGtk.cpp (279573 => 279574)


--- trunk/Source/WebKit/UIProcess/gtk/ViewGestureControllerGtk.cpp	2021-07-06 00:56:02 UTC (rev 279573)
+++ trunk/Source/WebKit/UIProcess/gtk/ViewGestureControllerGtk.cpp	2021-07-06 05:45:23 UTC (rev 279574)
@@ -85,12 +85,12 @@
 
 bool ViewGestureController::PendingSwipeTracker::scrollEventCanInfluenceSwipe(PlatformGtkScrollData* event)
 {
-    return true;
+    return event->source == GDK_SOURCE_TOUCHPAD || event->source == GDK_SOURCE_TOUCHSCREEN;
 }
 
 static bool isTouchEvent(PlatformGtkScrollData* event)
 {
-    return event->isTouch;
+    return event->source == GDK_SOURCE_TOUCHSCREEN;
 }
 
 FloatSize ViewGestureController::PendingSwipeTracker::scrollEventGetScrollingDeltas(PlatformGtkScrollData* event)
@@ -638,14 +638,12 @@
     if (!canSwipeInDirection(direction))
         return false;
 
-    m_isSimulatedSwipe = true;
-
     double delta = swipeTouchpadBaseWidth / gtkScrollDeltaMultiplier * 0.75;
 
     if (isPhysicallySwipingLeft(direction))
         delta = -delta;
 
-    PlatformGtkScrollData scrollData = { .delta = delta, .eventTime = GDK_CURRENT_TIME, .isTouch = false, .isEnd = false };
+    PlatformGtkScrollData scrollData = { .delta = delta, .eventTime = GDK_CURRENT_TIME, .source = GDK_SOURCE_TOUCHPAD, .isEnd = false };
     handleScrollWheelEvent(&scrollData);
 
     return true;
@@ -653,9 +651,8 @@
 
 bool ViewGestureController::completeSimulatedSwipeInDirectionForTesting(SwipeDirection)
 {
-    PlatformGtkScrollData scrollData = { .delta = 0, .eventTime = GDK_CURRENT_TIME, .isTouch = false, .isEnd = true };
+    PlatformGtkScrollData scrollData = { .delta = 0, .eventTime = GDK_CURRENT_TIME, .source = GDK_SOURCE_TOUCHPAD, .isEnd = true };
     handleScrollWheelEvent(&scrollData);
-    m_isSimulatedSwipe = false;
 
     return true;
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to