Truly independent web browser
Compositor: Let momentum go on under a script's instant scroll
Aliaksandr Kalenik5704de643207
diff --git a/Services/Compositor/CompositorState.cpp b/Services/Compositor/CompositorState.cppindex 29239b6459c..dd5f4e406e3 100644--- a/Services/Compositor/CompositorState.cpp+++ b/Services/Compositor/CompositorState.cpp@@ -637,7 +637,7 @@ void CompositorState::handle_and_dispatch_mouse_event(Web::CompositorContextId cauto is_wheel_event = event.type == Web::MouseEvent::Type::MouseWheel;bool is_first_wheel_event_with_delta = false;if (is_wheel_event) {- // A key or a script that scrolls takes over from momentum, until wheel input other than the momentum takes+ // A key, or a script's smooth scroll, takes over from momentum, until wheel input other than the momentum takes// over again.if (context->absorbs_wheel_event_of_interrupted_momentum(event)) {record_routing(Web::InputRoutingDecision::MomentumInterrupted);@@ -1298,11 +1298,8 @@ void CompositorState::forget_wheel_gesture_the_page_canceled(Web::CompositorContcontext_if_present(*routing_context_id)->forget_wheel_latch_of_gesture(gesture_id);}-static bool scroll_request_scrolls_for_script(Compositing::ScrollRequest const& scroll_request)+static bool scroll_request_smoothly_scrolls_for_script(Compositing::ScrollRequest const& scroll_request){- bool has_instant_scroll = scroll_request.jump_offset.has_value() || scroll_request.relative_scroll.has_value();- if (has_instant_scroll && !scroll_request.instant_scroll_is_for_user_input)- return true;return scroll_request.smooth_scroll.has_value() && scroll_request.smooth_scroll->initiator == Compositing::SmoothScrollInitiator::Programmatic;}@@ -1312,10 +1309,11 @@ void CompositorState::apply_scroll_requests(Web::CompositorContextId context_id,if (!context)return;- // A script's scroll of a box ends the momentum scrolling it, as a key's does.+ // A script's smooth scroll of a box ends the momentum scrolling it, as a key's does. A script's instant scroll only+ // moves the box, and the momentum goes on from there: pages keep their content in place under a flick that way.auto now = MonotonicTime::now();for (auto const& scroll_request : scroll_requests) {- if (scroll_request.takes_over_from_momentum || scroll_request_scrolls_for_script(scroll_request))+ if (scroll_request.takes_over_from_momentum || scroll_request_smoothly_scrolls_for_script(scroll_request))dispatch_scroll_fling_step(context_id, *context, context->end_momentum_scrolling(scroll_request.stable_node_id), now);}if (auto frame_to_present = context->apply_scroll_requests(scroll_requests); frame_to_present.has_value())diff --git a/Tests/LibWeb/Text/expected/async-scrolling/script-scroll-carries-momentum-along.txt b/Tests/LibWeb/Text/expected/async-scrolling/script-scroll-carries-momentum-along.txtnew file mode 100644index 00000000000..14edfb9a59d--- /dev/null+++ b/Tests/LibWeb/Text/expected/async-scrolling/script-scroll-carries-momentum-along.txt@@ -0,0 +1,2 @@+scrollY after the momentum: 620+scrollY after the next gesture: 670diff --git a/Tests/LibWeb/Text/expected/async-scrolling/script-scroll-stops-a-fling.txt b/Tests/LibWeb/Text/expected/async-scrolling/script-scroll-stops-a-fling.txtdeleted file mode 100644index dfe6d62cb0c..00000000000--- a/Tests/LibWeb/Text/expected/async-scrolling/script-scroll-stops-a-fling.txt+++ /dev/null@@ -1,2 +0,0 @@-scrollY after the fling: 500-scrollY after the next gesture: 550diff --git a/Tests/LibWeb/Text/expected/async-scrolling/script-smooth-scroll-takes-over-from-momentum.txt b/Tests/LibWeb/Text/expected/async-scrolling/script-smooth-scroll-takes-over-from-momentum.txtnew file mode 100644index 00000000000..eac9b1ab571--- /dev/null+++ b/Tests/LibWeb/Text/expected/async-scrolling/script-smooth-scroll-takes-over-from-momentum.txt@@ -0,0 +1 @@+scrollY after the smooth scroll: 1000diff --git a/Tests/LibWeb/Text/input/async-scrolling/script-scroll-stops-a-fling.html b/Tests/LibWeb/Text/input/async-scrolling/script-scroll-carries-momentum-along.htmlsimilarity index 85%rename from Tests/LibWeb/Text/input/async-scrolling/script-scroll-stops-a-fling.htmlrename to Tests/LibWeb/Text/input/async-scrolling/script-scroll-carries-momentum-along.htmlindex 760f8b3d05e..a6b8ac5ca6e 100644--- a/Tests/LibWeb/Text/input/async-scrolling/script-scroll-stops-a-fling.html+++ b/Tests/LibWeb/Text/input/async-scrolling/script-scroll-carries-momentum-along.html@@ -17,7 +17,8 @@await animationFrame();await animationFrame();- // The script takes the page somewhere of its own, and the rest of the fling goes nowhere.+ // The script moves the page, as one that keeps its content in place under a flick does, and the rest of the+ // momentum scrolls on from there.window.scrollTo(0, 500);await animationFrame();await animationFrame();@@ -26,7 +27,7 @@internals.wheelThroughUIProcess(50, 50, 0, 0, true, "ended");for (let frame = 0; frame < 4; frame++)await animationFrame();- println(`scrollY after the fling: ${window.scrollY}`);+ println(`scrollY after the momentum: ${window.scrollY}`);// The next gesture scrolls as usual.await internals.wheelThroughUIProcess(50, 50, 0, 0, true, "ongoing");diff --git a/Tests/LibWeb/Text/input/async-scrolling/script-smooth-scroll-takes-over-from-momentum.html b/Tests/LibWeb/Text/input/async-scrolling/script-smooth-scroll-takes-over-from-momentum.htmlnew file mode 100644index 00000000000..0696c56b3c9--- /dev/null+++ b/Tests/LibWeb/Text/input/async-scrolling/script-smooth-scroll-takes-over-from-momentum.html@@ -0,0 +1,33 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<style>+ body {+ margin: 0;+ height: 5000px;+ }+</style>+<script>+ promiseTest(async () => {+ await animationFrame();+ await animationFrame();++ await internals.wheelThroughUIProcess(50, 50, 0, 0, true, "ongoing");+ await internals.wheelThroughUIProcess(50, 50, 0, 50, true, "ongoing");+ await internals.wheelThroughUIProcess(50, 50, 0, 40, true, "momentum");+ await animationFrame();+ await animationFrame();++ // A smooth scroll of the script's takes over from the momentum, whose rest scrolls nothing.+ const smoothScrollEnded = scrollendEvent(document);+ window.scrollTo({ top: 1000, behavior: "smooth" });+ await animationFrame();+ await animationFrame();+ for (let step = 0; step < 3; step++)+ await internals.wheelThroughUIProcess(50, 50, 0, 40, true, "momentum");+ internals.wheelThroughUIProcess(50, 50, 0, 0, true, "ended");+ await smoothScrollEnded;+ for (let frame = 0; frame < 4; frame++)+ await animationFrame();+ println(`scrollY after the smooth scroll: ${window.scrollY}`);+ });+</script>