Truly independent web browser
LibWeb: Snap a box that input scrolled just after its snap scroll
sideshowbarkerb1abab4f94a3
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cppindex 3f414867f90..82148df7875 100644--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp@@ -5943,8 +5943,9 @@ void LocalNavigable::adopt_pending_async_scroll_offsets(Compositing::AsyncScrollbool adopted_any_scroll_offset = false;for (auto const& async_scroll_offset : async_scroll_updates.scroll_offsets) {auto& user_input_scroll_count = m_compositor_user_input_scroll_counts.ensure(async_scroll_offset.stable_node_id);+ bool user_input_scrolled_the_box = async_scroll_offset.user_input_scroll_count > user_input_scroll_count;// User input the compositor scrolled the box for keeps the box's gesture going, even where the box stayed put.- if (async_scroll_offset.user_input_scroll_count > user_input_scroll_count)+ if (user_input_scrolled_the_box)extend_user_scroll_gesture_of(async_scroll_offset.stable_node_id);user_input_scroll_count = max(user_input_scroll_count, async_scroll_offset.user_input_scroll_count);m_compositor_context_user_input_scroll_count = max(m_compositor_context_user_input_scroll_count, async_scroll_offset.context_user_input_scroll_count);@@ -5972,8 +5973,17 @@ void LocalNavigable::adopt_pending_async_scroll_offsets(Compositing::AsyncScrollasync_scroll_offset.compositor_scroll_offset.x(), async_scroll_offset.compositor_scroll_offset.y());}- // The input that took the scroll over goes on with the box's sequence as a gesture of its own.- if (user_input_took_over_the_scroll_of(async_scroll_offset.stable_node_id))+ // The input that took the scroll over goes on with the box's sequence as a gesture of its own. So does input+ // the compositor applied once the scroll was done, which these updates report along with the scroll's+ // completion when they were merged while this process was busy: The box is no longer where the scroll took+ // it, and nothing else would snap it once that input ends.+ auto user_input_moved_the_box_after_its_scroll = user_input_scrolled_the_box && any_of(m_pending_async_scroll_operations, [&](auto const& pending_operation) {+ return pending_operation.stable_node_id == async_scroll_offset.stable_node_id+ && pending_operation.destination_scroll_offset.has_value()+ && pending_operation.destination_scroll_offset.value() != css_scroll_offset+ && async_scroll_updates.completed_operation_ids.contains_slow(pending_operation.operation_id);+ });+ if (user_input_moved_the_box_after_its_scroll || user_input_took_over_the_scroll_of(async_scroll_offset.stable_node_id))note_user_scroll_gesture_of(async_scroll_offset.stable_node_id, scroll_offset_before_scroll, UserScrollMovedBox::No);continue;}diff --git a/Tests/LibWeb/Text/expected/scroll-snap-after-input-applied-once-a-snap-scroll-was-done.txt b/Tests/LibWeb/Text/expected/scroll-snap-after-input-applied-once-a-snap-scroll-was-done.txtnew file mode 100644index 00000000000..ecb15de39f0--- /dev/null+++ b/Tests/LibWeb/Text/expected/scroll-snap-after-input-applied-once-a-snap-scroll-was-done.txt@@ -0,0 +1,2 @@+scroll offset after the input: 220+scroll offset after the gesture settled: 200diff --git a/Tests/LibWeb/Text/input/scroll-snap-after-input-applied-once-a-snap-scroll-was-done.html b/Tests/LibWeb/Text/input/scroll-snap-after-input-applied-once-a-snap-scroll-was-done.htmlnew file mode 100644index 00000000000..8bf324a840d--- /dev/null+++ b/Tests/LibWeb/Text/input/scroll-snap-after-input-applied-once-a-snap-scroll-was-done.html@@ -0,0 +1,65 @@+<!DOCTYPE html>+<script src="include.js"></script>+<style>+ #scroller {+ width: 200px;+ height: 200px;+ overflow: scroll;+ scroll-snap-type: y mandatory;+ }+ .item {+ height: 200px;+ scroll-snap-align: start;+ }+</style>+<div id="scroller">+ <div class="item"></div>+ <div class="item"></div>+ <div class="item"></div>+</div>+<script>+ function keepThisProcessBusyFor(milliseconds) {+ const until = performance.now() + milliseconds;+ while (performance.now() < until) {}+ }++ promiseTest(async () => {+ const scroller = document.getElementById("scroller");++ await animationFrame();+ await animationFrame();++ // The gesture settles off a snap position, so a snap scroll to 200 follows. This process has to see that scroll+ // still on its way, or it already has the scroll's completion before it gets busy.+ while (true) {+ await internals.wheel(50, 50, 0, 120, true);+ while (scroller.scrollTop === 120)+ await animationFrame();+ if (scroller.scrollTop !== 200)+ break;+ await scrollSettled(scroller, () => (scroller.scrollTop = 0));+ }++ // While this process is busy, the compositor finishes the snap scroll and then scrolls the box for the input of+ // a new gesture, so this process gets the end of the snap scroll and that input's offset in one update.+ keepThisProcessBusyFor(500);+ const wheeled = internals.wheelThroughUIProcess(50, 50, 0, 20, true);+ keepThisProcessBusyFor(500);+ await wheeled;++ // The input moves the box off its snap position, once this process has the update. Nothing is printed until the+ // end, since a change to the document's layout would snap the box as well.+ const giveUpAt = performance.now() + 3000;+ while (scroller.scrollTop === 200 && performance.now() < giveUpAt)+ await animationFrame();+ const offsetAfterTheInput = scroller.scrollTop;++ // The new gesture snaps the box back once its input ends.+ while (scroller.scrollTop % 200 !== 0 && performance.now() < giveUpAt)+ await animationFrame();+ const offsetOnceTheGestureSettled = scroller.scrollTop;++ println(`scroll offset after the input: ${offsetAfterTheInput}`);+ println(`scroll offset after the gesture settled: ${offsetOnceTheGestureSettled}`);+ });+</script>