Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 80675181b655ab80779cdf67fbab5e2f4ecbffb9
https://github.com/WebKit/WebKit/commit/80675181b655ab80779cdf67fbab5e2f4ecbffb9
Author: Richard Robinson <[email protected]>
Date: 2026-05-05 (Tue, 05 May 2026)
Changed paths:
M Source/WebKit/UIProcess/mac/WKAppKitGestureController.h
M Source/WebKit/UIProcess/mac/WKAppKitGestureController.mm
M Source/WebKit/UIProcess/mac/WKTextSelectionController.swift
M Source/WebKit/UIProcess/mac/WebViewImpl.h
M Source/WebKit/UIProcess/mac/WebViewImpl.mm
M Tools/TestWebKitAPI/Tests/WebKit/WebPage/AppKitGesturesTests.swift
Log Message:
-----------
[AppKit Gestures] Double clicking text in Safari does not highlight text
(selection flickers)
https://bugs.webkit.org/show_bug.cgi?id=314048
rdar://172217561
Reviewed by Abrar Rahman Protyasha.
Double-clicking text to select a word sometimes briefly shows the selection
highlight and then
clears it on pages where the clicked text has a clickable ancestor (elements
with click handlers,
links, etc.). The selection survives on simpler pages where no ancestor passes
`Node::willRespondToMouseClickEvents`, which masks the bug.
The root cause is that when a user double-clicks, two things happen
simultaneously via gesture
recognizers that are allowed to recognize together:
1. `WKAppKitGestureController`'s single-click press gesture fires
`_handleClickBegan` (sending
`potentialClickAtPosition`) and then `_handleClickEnded` (sending
`commitPotentialClick`).
2. The system calls into the `beginRangeSelection` on
`WKTextSelectionController`, which sends
`selectTextWithGranularityAtPoint`.
In the web process, `commitPotentialClick` calls `handleSyntheticClick`. This
then enters a 32 ms
content-observation window before dispatching the synthetic click via
`completeSyntheticClick`.
Meanwhile, `selectTextWithGranularityAtPoint` arrives and creates the word
selection. When the
32 ms observation window expires, `completeSyntheticClick` fires a synthetic
mouse press event
that clears the just-created selection, producing the flicker.
The timing between the gesture recognizer actions and the text selection
manager callbacks is
non-deterministic:
- Order A: single-click Began fires, then `beginRangeSelection`, then
single-click Ended. In
this ordering, cancelling the click before Ended prevents the commit entirely.
- Order B: single-click Began and Ended both fire (committing the click) before
`beginRangeSelection`. The commit IPC is already in flight, but the observation
timer in the web
process has not yet fired.
Fix by cancelling the click in both the UI process and the web process when
`beginRangeSelection`
is called:
- `_handleClickCancelled` handles Order A by setting
`_potentialClickInProgress` to false so
`_handleClickEnded` becomes a no-op.
- An unconditional `cancelPotentialClick` IPC handles Order B: even though the
commit was already
sent, the cancel arrives in the web process and invokes
`ContentChangeObserver::didCancelPotentialClick`, which cancels the pending
observation timer and
prevents `completeSyntheticClick` from ever firing.
Test: Tools/TestWebKitAPI/Tests/WebKit/WebPage/AppKitGesturesTests.swift
* Source/WebKit/UIProcess/mac/WKAppKitGestureController.h:
* Source/WebKit/UIProcess/mac/WKAppKitGestureController.mm:
(-[WKAppKitGestureController cancelClick]):
* Source/WebKit/UIProcess/mac/WKTextSelectionController.swift:
(WKTextSelectionController.beginRangeSelection(at:with:)):
* Source/WebKit/UIProcess/mac/WebViewImpl.h:
* Source/WebKit/UIProcess/mac/WebViewImpl.mm:
(WebKit::WebViewImpl::cancelClick):
* Tools/TestWebKitAPI/Tests/WebKit/WebPage/AppKitGesturesTests.swift:
(AppKitGesturesTests.doubleClickingInWordSelectsWord(_:clickHandler:)):
(AppKitGesturesTests.loadHTML(_:clickHandler:)):
(AppKitGesturesTests.doubleClickingInWordSelectsWord(_:)): Deleted.
(AppKitGesturesTests.loadHTML(_:)): Deleted.
Canonical link: https://commits.webkit.org/312666@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications