Bug 235436 - [GTK] REGRESSION: Touch scrolling is broken
Summary: [GTK] REGRESSION: Touch scrolling is broken
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKitGTK (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Alice Mikhaylenko
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-01-21 06:41 PST by Alice Mikhaylenko
Modified: 2022-01-26 00:12 PST (History)
6 users (show)

See Also:


Attachments
Patch (2.42 KB, patch)
2022-01-24 01:40 PST, Alice Mikhaylenko
no flags Details | Formatted Diff | Diff
Patch (15.66 KB, patch)
2022-01-24 04:30 PST, Alice Mikhaylenko
no flags Details | Formatted Diff | Diff
Patch (16.75 KB, patch)
2022-01-24 05:55 PST, Alice Mikhaylenko
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alice Mikhaylenko 2022-01-21 06:41:45 PST
There are 2 issues, I'm not sure whether they are symptoms of the same thing or not.

1. Scrolling is very very slow and delayed - I've investigated this and it's caused by unwanted smooth scroll animations
2. Kinetic scrolling is too fast

With a quick hack:

```diff
diff --git a/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp b/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp
index 559a89bfc027..c940e565bea8 100644
--- a/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp
+++ b/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp
@@ -3017,7 +3017,7 @@ void webkitWebViewBaseSynthesizeWheelEvent(WebKitWebViewBase* webViewBase, const
         delta.scale(static_cast<float>(Scrollbar::pixelsPerLineStep()));
 
     priv->pageProxy->handleWheelEvent(NativeWebWheelEvent(const_cast<GdkEvent*>(event), { x, y }, widgetRootCoords(GTK_WIDGET(webViewBase), x, y),
-        delta, wheelTicks, toWebKitWheelEventPhase(phase), toWebKitWheelEventPhase(momentumPhase), priv->wheelHasPreciseDeltas));
+        delta, wheelTicks, toWebKitWheelEventPhase(phase), toWebKitWheelEventPhase(momentumPhase), priv->wheelHasPreciseDeltas || TRUE));
 }
 
 void webkitWebViewBaseSetWheelHasPreciseDeltas(WebKitWebViewBase* webViewBase, bool hasPreciseDeltas)
```

the lag indeed goes away, but kinetic scrolling just stops working altogether. Without that hack and with smooth scrolling disabled, kinetic scrolling seems like it immediately jumps at the position where it would end up if it was animating. With it enabled I can't tell if it's smooth or kinetic scrolling animating.
Comment 1 Alice Mikhaylenko 2022-01-21 06:43:07 PST
Clarification: this is all only on touchscreen; touchpad scrolling works as expected. Seems to happen with both GTK3 and GTK4 builds too.
Comment 2 Alice Mikhaylenko 2022-01-24 01:22:40 PST
Ok, and no kinetic scrolling boils down to simply:

```diff
--- a/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp
+++ b/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp
@@ -2011,7 +2011,7 @@ static void webkitWebViewBaseTouchSwipe(WebKitWebViewBase* webViewBase, gdouble
                 return;
         }
 
-        webkitWebViewBaseSynthesizeWheelEvent(webViewBase, event, -velocityX / Scrollbar::pixelsPerLineStep(), velocityY / Scrollbar::pixelsPerLineStep(), x, y, WheelEventPhase::NoPhase, WheelEventPhase::Began);
+        webkitWebViewBaseSynthesizeWheelEvent(webViewBase, event, 0, 0, x, y, WheelEventPhase::Ended, WheelEventPhase::NoPhase);
     }
 }
 

```

Since the kinetic scroll handling currently handles event history and everything, we don't care about the velocity we get from GtkGestureSwipe. On the contrary, it messes things up as the event is no longer a scroll stop event as the deltas are non-0. Makign the event look same as the equivalent touchpad event fixes everything.
Comment 3 Alice Mikhaylenko 2022-01-24 01:40:04 PST
Created attachment 449789 [details]
Patch
Comment 4 EWS Watchlist 2022-01-24 01:41:29 PST
Thanks for the patch. If this patch contains new public API please make sure it follows the guidelines for new WebKit2 GTK+ API. See https://trac.webkit.org/wiki/WebKitGTK/AddingNewWebKit2API
Comment 5 Chris Lord 2022-01-24 02:12:52 PST
Comment on attachment 449789 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=449789&action=review

> Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp:2014
> +        webkitWebViewBaseSynthesizeWheelEvent(webViewBase, event, 0, 0, x, y, WheelEventPhase::Ended, WheelEventPhase::NoPhase);

Great that this is so simple - I don't know if this will affect test results anywhere, but EWS ought to tell us soon I suppose. Looks fine to me though.

> Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp:3020
> +        delta, wheelTicks, toWebKitWheelEventPhase(phase), toWebKitWheelEventPhase(momentumPhase), true));

This will definitely cause many tests to fail - precise deltas will need to be conditionally enabled for wheel events synthesised by touch events.
Comment 6 Alice Mikhaylenko 2022-01-24 02:15:02 PST
That codepath is only used for touch events though. :)
Comment 7 Chris Lord 2022-01-24 02:18:53 PST
(In reply to Alexander Mikhaylenko from comment #6)
> That codepath is only used for touch events though. :)

Is the patch view annotation tripping me up here? webkitWebViewBaseSynthesizeWheelEvent is used by WebKitTestRunner/gtk/EventSenderProxyGtk.cpp for synthesising wheel events in layout tests.
Comment 8 Alice Mikhaylenko 2022-01-24 02:24:26 PST
Ah ok, nevermind then. Once again I've only looked in Source/ but not Tools/.
Comment 9 Alice Mikhaylenko 2022-01-24 04:30:14 PST
Actually I have another idea.
Comment 10 Alice Mikhaylenko 2022-01-24 04:30:37 PST
Created attachment 449799 [details]
Patch
Comment 11 Chris Lord 2022-01-24 04:37:46 PST
Comment on attachment 449799 [details]
Patch

LGTM :)
Comment 12 Alice Mikhaylenko 2022-01-24 05:55:54 PST
Created attachment 449804 [details]
Patch
Comment 13 Chris Lord 2022-01-25 09:42:54 PST
Comment on attachment 449804 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=449804&action=review

LGTM. Wondering about that sign, but I assume you've tested it :)

> Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp:2013
> +        webkitWebViewBaseSynthesizeWheelEvent(webViewBase, event, -velocityX, -velocityY, x, y, WheelEventPhase::NoPhase, WheelEventPhase::Began, true);

Is flipping the sign of velocityY here intentional?
Comment 14 Alice Mikhaylenko 2022-01-25 10:05:05 PST
> but I assume you've tested it :)

I had. The path that broke was tests, not touch scrolling - hence adjustments in the new patch.

> Is flipping the sign of velocityY here intentional?

Yes, it was wrong.
Comment 15 EWS 2022-01-26 00:12:01 PST
Committed r288609 (246428@main): <https://commits.webkit.org/246428@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 449804 [details].