Commit Graph
1 Commits
Author SHA1 Message Date
yetone 87c51cd6bb gui: a tap that comes let go before it is pressed clicks its control once (refeccd)
refeccd on Discord (magpie 0.1.3014, macOS 27.2 26B123): with Tap to click
on, a tap often does nothing, in the tray panel and the window, and almost
always inside a dialog, sheet or menu opened from the active window.

Cause: WebKit's WebViewImpl::nativeMouseEventHandler hands every mouse event
to NSTextInputContext handleEvent:completionHandler: while an editable
element has focus, and before WebKit ba0432f3f5 (2026-11-04, bug 329642,
"Dispatch mouse events to the page in the order sent to the input method",
rdar://102126328) each event was dispatched from its own completion handler.
Some input methods answer out of order, so a tap, whose down and up are a
few ms apart, reaches the page as mouseup then mousedown: no click, :active
stuck, and the next tap's mouseup pairs with the left press and clicks
where the two meet (the "second tap works" of the earlier reports). A
physical press is ~100ms long, so its order holds. Dialogs focus their
first field when they open and menus focus their search box, which is why
dialogs are almost always hit. macOS 27.2's system WebKit predates the fix.
Not proven on refeccd's machine: no real trackpad with an input method was
used; the order is reproduced, not observed there.

Change (app.js, the one capture-phase tap net every control goes through):
a press within 300ms and 12px of a release that had no press, and not let
go within 100ms, is such a tap (tapBack). Its control (the lost-click net's
selector) is clicked once after 100ms, and the trusted click the next
release pairs with it (detail > 0, so never a keyboard click) is dropped.
A release within the 100ms means the press was in order after all: nothing
is clicked by the page and the browser's click is kept. The segs press
tracker and the lost-click net ignore a tapBack press. Comments in app.js
were condensed to keep the core script budget (main was already 380 bytes
over it, #4526's test); no budget raised.

Not covered: an inverted tap on a dialog's backdrop doesn't close it
(backdropClick pairs pointerdown/up); nothing is clicked for it.

Run (mote, at this tree rebased on origin/main 9d143eaca):
- internal/gui/tests/tap-inverted.test.cjs (new): Chromium and WebKit, en,
  zh, zh-TW, ja, de, 1100 and 390 wide: 22/22 pass. Playwright's
  mouse.up then mouse.down gives the page that order with trusted events.
- The old app.js with the new test: 22/22 red at the first inverted tap
  (0 clicks).
- Broken by hand: the dropped paired click off -> red at the second tap
  (0 clicks where 1 expected; the click landed on .segs); the 100ms
  in-order cancel off -> red, a no-control press after a stray release
  lost its click.
- tap-*, click-scroll, segs-*, modal-*, menu-*, dialog-*, library-mcp-*,
  tray-cell-click, i18n-* GUI files; go test -run TestCoreScriptBudget
  ./internal/gui: 437 pass, 25 red. Every red is the same at origin/main
  9d143eaca, run there alone on mote (30 pass, 24 red in the four files;
  tray-cell-click chromium zh passed there once, red 4 of 4 in #5215):
  segs-press-redraw "clicks its new self once" (16, #4566),
  menu-input-scroll (4, #3402), tray-cell-click (4, #5215), i18n-keys
  "a plugin's words are its own" (1, filed as #5327).
  TestCoreScriptBudget ok.
- go test ./internal/gui: TestMainWindowCorners/macOS_26_SDK red, #3949
  (macOS 27, AppKit), not touched here.

Not tried: a real trackpad with Tap to click and a third-party input method
(Baidu, Sogou, WeType), the Wails app itself, the tray panel's NSPanel.
2026-11-05 13:26:17 +08:00