<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[279574] trunk/Source/WebKit</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/279574">279574</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2021-07-05 22:45:23 -0700 (Mon, 05 Jul 2021)</dd>
</dl>

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

Patch by Alexander Mikhaylenko <alexm@gnome.org> 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):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitUIProcessAPIgtkPageClientImplcpp">trunk/Source/WebKit/UIProcess/API/gtk/PageClientImpl.cpp</a></li>
<li><a href="#trunkSourceWebKitUIProcessAPIgtkWebKitWebViewBasecpp">trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp</a></li>
<li><a href="#trunkSourceWebKitUIProcessViewGestureControllerh">trunk/Source/WebKit/UIProcess/ViewGestureController.h</a></li>
<li><a href="#trunkSourceWebKitUIProcessgtkViewGestureControllerGtkcpp">trunk/Source/WebKit/UIProcess/gtk/ViewGestureControllerGtk.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (279573 => 279574)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,5 +1,42 @@
</span><span class="cx"> 2021-07-05  Alexander Mikhaylenko  <alexm@gnome.org>
</span><span class="cx"> 
</span><ins>+        [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  <alexm@gnome.org>
+
</ins><span class="cx">         [GTK] Kinetic scrolling interferes with gestures
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=226680
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessAPIgtkPageClientImplcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/API/gtk/PageClientImpl.cpp (279573 => 279574)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -427,9 +427,15 @@
</span><span class="cx">     if (controller && controller->isSwipeGestureEnabled()) {
</span><span class="cx">         double deltaX;
</span><span class="cx">         gdk_event_get_scroll_deltas(event.nativeEvent(), &deltaX, nullptr);
</span><ins>+
+        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);
+
</ins><span class="cx">         bool isEnd = gdk_event_is_scroll_stop_event(event.nativeEvent()) ? true : false;
</span><del>-        int32_t eventTime = static_cast<int32_t>(gdk_event_get_time(event.nativeEvent()));
-        PlatformGtkScrollData scrollData = { .delta = deltaX, .eventTime = eventTime, .isTouch = false, .isEnd = isEnd };
</del><ins>+
+        PlatformGtkScrollData scrollData = { .delta = deltaX, .eventTime = eventTime, .source = source, .isEnd = isEnd };
</ins><span class="cx">         controller->wheelEventWasNotHandledByWebCore(&scrollData);
</span><span class="cx">         return;
</span><span class="cx">     }
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessAPIgtkWebKitWebViewBasecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp (279573 => 279574)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1266,9 +1266,15 @@
</span><span class="cx">     if (controller && controller->isSwipeGestureEnabled()) {
</span><span class="cx">         double deltaX;
</span><span class="cx">         gdk_event_get_scroll_deltas(event, &deltaX, nullptr);
</span><ins>+
+        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);
+
</ins><span class="cx">         bool isEnd = gdk_event_is_scroll_stop_event(event) ? true : false;
</span><del>-        int32_t eventTime = static_cast<int32_t>(gdk_event_get_time(event));
-        PlatformGtkScrollData scrollData = { .delta = deltaX, .eventTime = eventTime, .isTouch = false, .isEnd = isEnd };
</del><ins>+
+        PlatformGtkScrollData scrollData = { .delta = deltaX, .eventTime = eventTime, .source = source, .isEnd = isEnd };
</ins><span class="cx">         if (controller->handleScrollWheelEvent(&scrollData))
</span><span class="cx">             return;
</span><span class="cx">     }
</span><span class="lines">@@ -1329,9 +1335,14 @@
</span><span class="cx"> 
</span><span class="cx">     ViewGestureController* controller = webkitWebViewBaseViewGestureController(webViewBase);
</span><span class="cx">     if (controller && controller->isSwipeGestureEnabled()) {
</span><ins>+        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);
+
</ins><span class="cx">         bool isEnd = gdk_scroll_event_is_stop(event) ? true : false;
</span><del>-        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 };
</del><ins>+
+        PlatformGtkScrollData scrollData = { .delta = deltaX, .eventTime = eventTime, .source = source, .isEnd = isEnd };
</ins><span class="cx">         if (controller->handleScrollWheelEvent(&scrollData))
</span><span class="cx">             return GDK_EVENT_STOP;
</span><span class="cx">     }
</span><span class="lines">@@ -1971,7 +1982,7 @@
</span><span class="cx">         ViewGestureController* controller = webkitWebViewBaseViewGestureController(webViewBase);
</span><span class="cx">         if (controller && controller->isSwipeGestureEnabled()) {
</span><span class="cx">             int32_t eventTime = static_cast<int32_t>(gtk_event_controller_get_current_event_time(GTK_EVENT_CONTROLLER(gesture)));
</span><del>-            PlatformGtkScrollData scrollData = { .delta = deltaX, .eventTime = eventTime, .isTouch = true, .isEnd = false };
</del><ins>+            PlatformGtkScrollData scrollData = { .delta = deltaX, .eventTime = eventTime, .source = GDK_SOURCE_TOUCHSCREEN, .isEnd = false };
</ins><span class="cx">             if (controller->handleScrollWheelEvent(&scrollData))
</span><span class="cx">                 return;
</span><span class="cx">         }
</span><span class="lines">@@ -1995,7 +2006,7 @@
</span><span class="cx">         ViewGestureController* controller = webkitWebViewBaseViewGestureController(webViewBase);
</span><span class="cx">         if (controller && controller->isSwipeGestureEnabled()) {
</span><span class="cx">             int32_t eventTime = static_cast<int32_t>(gtk_event_controller_get_current_event_time(GTK_EVENT_CONTROLLER(gesture)));
</span><del>-            PlatformGtkScrollData scrollData = { .delta = 0, .eventTime = eventTime, .isTouch = false, .isEnd = true };
</del><ins>+            PlatformGtkScrollData scrollData = { .delta = 0, .eventTime = eventTime, .source = GDK_SOURCE_TOUCHSCREEN, .isEnd = true };
</ins><span class="cx">             controller->handleScrollWheelEvent(&scrollData);
</span><span class="cx">         }
</span><span class="cx">     }
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessViewGestureControllerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/ViewGestureController.h (279573 => 279574)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -82,7 +82,7 @@
</span><span class="cx"> typedef struct {
</span><span class="cx">     double delta;
</span><span class="cx">     int32_t eventTime;
</span><del>-    bool isTouch;
</del><ins>+    GdkInputSource source;
</ins><span class="cx">     bool isEnd;
</span><span class="cx"> } PlatformGtkScrollData;
</span><span class="cx"> typedef PlatformGtkScrollData* PlatformScrollEvent;
</span><span class="lines">@@ -472,10 +472,8 @@
</span><span class="cx">     int m_swipeOutlineSize;
</span><span class="cx">     GRefPtr<GtkCssProvider> m_cssProvider;
</span><span class="cx"> #endif
</span><ins>+#endif // PLATFORM(GTK)
</ins><span class="cx"> 
</span><del>-    bool m_isSimulatedSwipe { false };
-#endif
-
</del><span class="cx">     bool m_isConnectedToProcess { false };
</span><span class="cx">     bool m_didStartProvisionalLoad { false };
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessgtkViewGestureControllerGtkcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/gtk/ViewGestureControllerGtk.cpp (279573 => 279574)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -85,12 +85,12 @@
</span><span class="cx"> 
</span><span class="cx"> bool ViewGestureController::PendingSwipeTracker::scrollEventCanInfluenceSwipe(PlatformGtkScrollData* event)
</span><span class="cx"> {
</span><del>-    return true;
</del><ins>+    return event->source == GDK_SOURCE_TOUCHPAD || event->source == GDK_SOURCE_TOUCHSCREEN;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static bool isTouchEvent(PlatformGtkScrollData* event)
</span><span class="cx"> {
</span><del>-    return event->isTouch;
</del><ins>+    return event->source == GDK_SOURCE_TOUCHSCREEN;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> FloatSize ViewGestureController::PendingSwipeTracker::scrollEventGetScrollingDeltas(PlatformGtkScrollData* event)
</span><span class="lines">@@ -638,14 +638,12 @@
</span><span class="cx">     if (!canSwipeInDirection(direction))
</span><span class="cx">         return false;
</span><span class="cx"> 
</span><del>-    m_isSimulatedSwipe = true;
-
</del><span class="cx">     double delta = swipeTouchpadBaseWidth / gtkScrollDeltaMultiplier * 0.75;
</span><span class="cx"> 
</span><span class="cx">     if (isPhysicallySwipingLeft(direction))
</span><span class="cx">         delta = -delta;
</span><span class="cx"> 
</span><del>-    PlatformGtkScrollData scrollData = { .delta = delta, .eventTime = GDK_CURRENT_TIME, .isTouch = false, .isEnd = false };
</del><ins>+    PlatformGtkScrollData scrollData = { .delta = delta, .eventTime = GDK_CURRENT_TIME, .source = GDK_SOURCE_TOUCHPAD, .isEnd = false };
</ins><span class="cx">     handleScrollWheelEvent(&scrollData);
</span><span class="cx"> 
</span><span class="cx">     return true;
</span><span class="lines">@@ -653,9 +651,8 @@
</span><span class="cx"> 
</span><span class="cx"> bool ViewGestureController::completeSimulatedSwipeInDirectionForTesting(SwipeDirection)
</span><span class="cx"> {
</span><del>-    PlatformGtkScrollData scrollData = { .delta = 0, .eventTime = GDK_CURRENT_TIME, .isTouch = false, .isEnd = true };
</del><ins>+    PlatformGtkScrollData scrollData = { .delta = 0, .eventTime = GDK_CURRENT_TIME, .source = GDK_SOURCE_TOUCHPAD, .isEnd = true };
</ins><span class="cx">     handleScrollWheelEvent(&scrollData);
</span><del>-    m_isSimulatedSwipe = false;
</del><span class="cx"> 
</span><span class="cx">     return true;
</span><span class="cx"> }
</span></span></pre>
</div>
</div>

</body>
</html>