Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 705dc8136413d01fa61c1819e9eb4d159b711d61
      
https://github.com/WebKit/WebKit/commit/705dc8136413d01fa61c1819e9eb4d159b711d61
  Author: Fujii Hironori <[email protected]>
  Date:   2026-09-22 (Tue, 22 Sep 2026)

  Changed paths:
    M Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp

  Log Message:
  -----------
  [GTK] Fix touch positions and cancel outstanding touch sequences
https://bugs.webkit.org/show_bug.cgi?id=324698

Reviewed by Carlos Garcia Campos.

Four problems in the GTK touch event path. Mouse input is unaffected by any of
them.

1. The touch positions are offset by the surface transform.

appendTouchEvent() takes the raw position of the GdkEvent, which in GTK4 is
relative to the GdkSurface, and converts it with
gtk_widget_translate_coordinates(). That function is a thin wrapper around
gtk_widget_compute_point() and only converts between widget coordinate spaces.
The surface transform, the offset of the native widget within the surface that
leaves room for the client-side decoration shadows, lies outside the widget
hierarchy, so it is not accounted for and every touch point lands that far away
from the finger. Maximizing the window makes the offset disappear, because the
shadows are dropped.

GTK's own translate_event_coordinates() subtracts the surface transform before
computing the point, which is why only touch is wrong. The mouse event handlers
get their coordinates from the GtkGesture signals, which have already been
through it; the touch path re-derives them from the raw event and skips it. Do
the same here.

2. Touch sequences are stranded when the view is unmapped.

priv->touchEvents was only ever modified by webkitWebViewBaseTouchEvent(), which
is not reached once the widget is unmapped: gtk_widget_event() returns early for
unmapped widgets, and GTK does not cancel the sequences on our behalf. It hands
the implicit grab over to the parent widget and synthesizes crossing events, but
no touch end. Keeping a finger down while switching to another tab therefore
left the page with a touch that is never released, and the stale touch point was
reported as Stationary in every subsequent touch event for the lifetime of the
view. In debug builds the ASSERT(!priv->touchEvents.contains(sequence)) of the
GDK_TOUCH_BEGIN case could also be hit, if GDK reused the GdkEventSequence
pointer value of a stranded sequence.

Cancel the outstanding sequences from the unmap handler, before chaining up, so
that the widget is still mapped and rooted while the touch points are converted.
A GDK_TOUCH_CANCEL that arrives afterwards is ignored, because
webkitWebViewBaseTouchEvent() returns early for a sequence that is not in the
map.

3. A cancelled touch point is reported as Released.

webkitWebViewBaseGetTouchPointsForEvent() appends the sequence that has just
been taken out of the map with State::Released for GDK_TOUCH_END and
GDK_TOUCH_CANCEL alike, even though WebEventFactory::createWebTouchEvent() types
the event itself as TouchCancel. Use State::Cancelled there, matching what the
new unmap path sends.

4. Touch sequences are stranded when a dialog is shown.

The same defect as 2, through a different door. webkitWebViewBaseTouchEvent()
returns GDK_EVENT_STOP as soon as priv->dialog is set, before the map is
touched, so a finger that is down when an authentication or script dialog comes
up never has its sequence removed. Cancel the outstanding sequences from
webkitWebViewBaseAddDialog() as well. Nothing is added to the map for as long as
the dialog is up, so it is still empty once the dialog goes away, and the
GDK_TOUCH_UPDATE and GDK_TOUCH_END of a sequence that started before it are
dropped by the same early returns that ignore a late GDK_TOUCH_CANCEL.

No new tests. The coordinate offset only shows up with client-side decoration
shadows, and the stranded sequences need the view to be unmapped or a dialog to
come up mid-gesture; the touch event synthesis of WebKitTestRunner cannot
reproduce either.

* Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp:
(webkitWebViewBaseAddDialog):
(webkitWebViewBaseUnmap):
(appendTouchEvent):
(webkitWebViewBaseGetTouchPointsForEvent):
(webkitWebViewBaseCancelTouchSequences):

Co-Authored-By: Claude Opus 5
Canonical link: https://commits.webkit.org/321593@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to