Closed Bug 2087341 Opened 1 month ago Closed 18 days ago

[wpt-sync] Sync PR 64203 - [Blink] Fix layout lifecycle crash on gesture long-press

Categories

(Core :: DOM: Selection, task, P4)

task

Tracking

()

RESOLVED FIXED
162 Branch
Tracking Status
firefox162 --- fixed

People

(Reporter: wpt-sync, Unassigned)

References

()

Details

(Whiteboard: [wptsync downstream])

Attachments

(1 file)

Sync web-platform-tests PR 64203 into mozilla-central (this bug is closed when the sync is complete).

PR: https://github.com/web-platform-tests/wpt/pull/64203
Details from upstream follow.

Samuel Huang <huangs@chromium.org> wrote:

[Blink] Fix layout lifecycle crash on gesture long-press

Fix a layout lifecycle assertion crash in HitTestResult::GetPosition()
during touch long-press gestures.

When a touch long-press occurs, HandleGestureLongPress() calls
SelectClosestWordFromHitTestResult() to select the word. If word
selection fails or is cancelled by a selectstart event listener, it
falls back to placing a caret via SetCaretAtHitTestResult(). Both
methods query HitTestResult::GetPosition(), which asserts (DCHECK)
that the document lifecycle is at least kPrePaintClean.

However, gesture selection previously lacked proper layout lifecycle
updates:

  • HandleGestureLongPress() only invoked UpdateStyleAndLayoutTree(),
    skipping layout geometry and pre-paint property tree updates needed
    by SelectClosestWordFromHitTestResult().
  • When SelectClosestWordFromHitTestResult() dispatches selectstart,
    author JavaScript can mutate styles or DOM and cancel selection.
    This re-dirties the document lifecycle mid-gesture before the
    fallback caret placement in SetCaretAtHitTestResult().

While mouse press paths were long ago guarded with full lifecycle
updates in MouseEventManager::HandleMousePressEvent(), gesture paths
were missing these guards.

Change details: In blink::SelectionController:

  • HandleGestureLongPress(): Advance all lifecycle phases through
    pre-paint by replacing UpdateStyleAndLayoutTree() call with
    UpdateAllLifecyclePhasesExceptPaint().
  • SetCaretAtHitTestResult(): Add the same call to ensure any
    mid-gesture mutations (and other callers like
    HandleGestureTwoFingerTap()) operate on clean layout geometry.
  • Add regression unit tests in selection_controller_test.cc, covering
    both pre-gesture dirty layout and mid-gesture selectstart mutations.
  • Add WPT crashtest in longpress-selection-crash.html.

Bug: 570656468
Change-Id: Ic00654959ef8b61e7645a0f55a780d634133a05e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8520941
Commit-Queue: Samuel Huang \<huangs@chromium.org>
Reviewed-by: Robert Flack \<flackr@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1726736}

Component: web-platform-tests → DOM: Selection
Product: Testing → Core
Whiteboard: [wptsync downstream] → [wptsync downstream error]
Whiteboard: [wptsync downstream error] → [wptsync downstream]
Attached file Notable wpt changes —

CI Results

Ran 11 Firefox configurations based on mozilla-central, and Firefox, Chrome, and Safari on GitHub CI

Total 194 tests

Status Summary

Firefox

OK : 1[GitHub] 134[Gecko-android-em-14-x86_64-debug-geckoview, Gecko-android-em-14-x86_64-lite-opt-geckoview, Gecko-android-em-14-x86_64-opt-geckoview, Gecko-linux2404-64-debug, Gecko-linux2404-64-opt, Gecko-windows11-32-25h2-debug, Gecko-windows11-32-25h2-opt, Gecko-windows11-64-25h2-debug, Gecko-windows11-64-25h2-opt]
PASS: 1[GitHub] 36[Gecko-linux2204-64-wayland-debug, Gecko-linux2204-64-wayland-opt] 33610[Gecko-windows11-32-25h2-debug, Gecko-windows11-32-25h2-opt] 33629[Gecko-android-em-14-x86_64-debug-geckoview, Gecko-android-em-14-x86_64-lite-opt-geckoview, Gecko-android-em-14-x86_64-opt-geckoview, Gecko-linux2404-64-debug, Gecko-linux2404-64-opt] 33633[Gecko-windows11-64-25h2-debug, Gecko-windows11-64-25h2-opt]
FAIL: 847[Gecko-windows11-32-25h2-debug, Gecko-windows11-32-25h2-opt] 848[Gecko-windows11-64-25h2-debug, Gecko-windows11-64-25h2-opt] 851[Gecko-android-em-14-x86_64-debug-geckoview, Gecko-android-em-14-x86_64-lite-opt-geckoview, Gecko-android-em-14-x86_64-opt-geckoview] 852[Gecko-linux2404-64-debug, Gecko-linux2404-64-opt]

Chrome

OK : 1
PASS: 1

Safari

OK : 1
PASS: 1

Links

Gecko CI (Treeherder)
GitHub PR Head
GitHub PR Base

Details

(See attachment for full changes)

Pushed by wptsync@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/e1947c0a281f https://hg.mozilla.org/integration/autoland/rev/5d3f5ced7eae [wpt PR 64203] - [Blink] Fix layout lifecycle crash on gesture long-press, a=testonly
Status: NEW → RESOLVED
Closed: 18 days ago
Resolution: --- → FIXED
Target Milestone: --- → 162 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: