Truly independent web browser
Compositor: Keep scrolling touchpad gestures that the page let through
Aliaksandr Kalenikc81f594b9d76
diff --git a/Services/Compositor/ContextState.cpp b/Services/Compositor/ContextState.cppindex 9d9d5120595..86c9a733876 100644--- a/Services/Compositor/ContextState.cpp+++ b/Services/Compositor/ContextState.cpp@@ -948,16 +948,20 @@ ContextState::AsyncScrollResult ContextState::async_scroll_by(&& first_is_one_of(scroll_gesture_phase, Web::ScrollGesturePhase::Ongoing, Web::ScrollGesturePhase::Momentum);bool only_blocking_wheel_event_listeners_hold_steps_back = first_is_one_of(m_wheel_routing_admission,Compositing::WheelRoutingAdmission::BlockingWheelEventListeners, Compositing::WheelRoutingAdmission::StaleWheelEventListeners);- if (!m_can_accept_async_wheel_events && !(page_let_touchpad_step_through && only_blocking_wheel_event_listeners_hold_steps_back))- return {};- m_scroll_snap_controller.note_gesture_phase(scroll_gesture_phase);auto latched_node_id = resolve_wheel_scroll_latch(position, scroll_gesture_phase, modifiers, now);// The end of the gesture before this one may never have arrived. Whether a step of the UI starts another gesture// was decided when the UI sent it.if (!latched_node_id.has_value() && !step_came_from_ui)end_gesture_that_stretches_elastically(now);+ if (!m_can_accept_async_wheel_events+ && !step_continues_touchpad_gesture_the_page_let_through(latched_node_id, wheel_delta_precision, scroll_gesture_phase)+ && !(page_let_touchpad_step_through && only_blocking_wheel_event_listeners_hold_steps_back))+ return {};++ m_scroll_snap_controller.note_gesture_phase(scroll_gesture_phase);+// The end of a gesture carries no delta to hit test; it snaps the boxes the gesture panned.if (scroll_gesture_phase == Web::ScrollGesturePhase::Ended && delta.is_zero()) {auto operation_id = snap_at_gesture_end(now);@@ -981,6 +985,8 @@ ContextState::AsyncScrollResult ContextState::async_scroll_by(// which reports the same step with its own document.return {};}+ if (page_let_touchpad_step_through)+ m_wheel_scroll_latch->wheel_event_listener_state_generation_the_page_let_the_gesture_through_at = m_wheel_event_listener_state_generation;auto scroll_chaining = is_first_step_of_gesture ? Compositing::ScrollChaining::ToScrollableAncestors : Compositing::ScrollChaining::None;auto outcome = perform_wheel_scroll_of_node(*latched_node_id, delta, wheel_delta_precision, scroll_gesture_phase, operation_tracking, viewport_rect, now, scroll_chaining, VisualViewportPanning::No);@@ -1237,6 +1243,15 @@ bool ContextState::wheel_step_was_overtaken_by_ui(Web::ScrollGesturePhase phase,VERIFY_NOT_REACHED();}+bool ContextState::step_continues_touchpad_gesture_the_page_let_through(Optional<Compositing::AsyncScrollNodeID> const& latched_node_id, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase) const+{+ if (!latched_node_id.has_value() || !m_wheel_scroll_latch.has_value() || !presents_to_client())+ return false;+ if (wheel_delta_precision != Web::WheelDeltaPrecision::Precise || scroll_gesture_phase == Web::ScrollGesturePhase::None)+ return false;+ return m_wheel_scroll_latch->wheel_event_listener_state_generation_the_page_let_the_gesture_through_at == m_wheel_event_listener_state_generation;+}+ContextState::ContextUpdateResult ContextState::scroll_for_wheel_event(Web::MouseEvent const& event, MonotonicTime now){return async_scroll_by(wheel_event_position(event), wheel_event_delta_in_device_pixels(event), event.wheel_delta_precision, event.scroll_gesture_phase, event.modifiers, now);@@ -1387,14 +1402,16 @@ ContextState::ContextUpdateResult ContextState::async_scroll_by(Gfx::FloatPointif (scroll_gesture_phase == Web::ScrollGesturePhase::Ended)end_gesture_that_stretches_elastically(now);+ auto latched_node_id = resolve_wheel_scroll_latch(position, scroll_gesture_phase, modifiers, now);+// A page without scroll nodes still has a visual viewport to pan once it is zoomed in.auto can_pan_zoomed_visual_viewport = m_wheel_routing_admission == Compositing::WheelRoutingAdmission::NoScrollNode&& visual_viewport_scale_for_compositing().value_or(1.0f) > 1.0f;- if (!m_can_accept_async_wheel_events && !can_pan_zoomed_visual_viewport)+ if (!m_can_accept_async_wheel_events && !can_pan_zoomed_visual_viewport+ && !step_continues_touchpad_gesture_the_page_let_through(latched_node_id, wheel_delta_precision, scroll_gesture_phase))return {};m_scroll_snap_controller.note_gesture_phase(scroll_gesture_phase);- auto latched_node_id = resolve_wheel_scroll_latch(position, scroll_gesture_phase, modifiers, now);if (scroll_gesture_phase == Web::ScrollGesturePhase::Ended && delta.is_zero()) {if (!snap_at_gesture_end(now).has_value())diff --git a/Services/Compositor/ContextState.h b/Services/Compositor/ContextState.hindex 073da843514..e9c9eddfb45 100644--- a/Services/Compositor/ContextState.h+++ b/Services/Compositor/ContextState.h@@ -262,6 +262,10 @@ private:// The momentum of the gesture has gone into a rebound of the scroller. Momentum outlasts that rebound, and the// rest of it must not start another one.bool momentum_has_sprung_the_scroller_back { false };+ // Set once the page dispatched a step of a touchpad gesture that blocking wheel event listeners held back, and+ // did not cancel it. The rest of the gesture is scrolled here first, without asking the page again, for as long+ // as no blocking listener has been added or removed since.+ Optional<u64> wheel_event_listener_state_generation_the_page_let_the_gesture_through_at {};};// A scroller that a touchpad gesture holds past an edge of its scroll range, or that is springing back from there.@@ -348,6 +352,7 @@ private:// Whether the UI sent a later wheel event that this step cannot come before in one gesture, which makes it a step// of a gesture this context has already ended or moved past.bool wheel_step_was_overtaken_by_ui(Web::ScrollGesturePhase, u64 input_event_id) const;+ bool step_continues_touchpad_gesture_the_page_let_through(Optional<Compositing::AsyncScrollNodeID> const& latched_node_id, Web::WheelDeltaPrecision, Web::ScrollGesturePhase) const;Web::MouseEvent scroll_fling_event(Gfx::FloatPoint delta, Web::ScrollGesturePhase) const;Optional<Gfx::FloatPoint> in_flight_wheel_destination(Web::AsyncScrollNodeStableID) const;AsyncScrollResult smooth_wheel_scroll_by(Optional<Compositing::WheelScrollTarget> const&, Gfx::IntRect viewport_rect, MonotonicTime now);diff --git a/Tests/LibWeb/Text/expected/async-scrolling/elastic-overscroll-after-the-page-cancels-the-first-step.txt b/Tests/LibWeb/Text/expected/async-scrolling/elastic-overscroll-after-the-page-cancels-the-first-step.txtindex d10aa87e558..5f6438d456d 100644--- a/Tests/LibWeb/Text/expected/async-scrolling/elastic-overscroll-after-the-page-cancels-the-first-step.txt+++ b/Tests/LibWeb/Text/expected/async-scrolling/elastic-overscroll-after-the-page-cancels-the-first-step.txt@@ -1,4 +1,4 @@after the canceled step: viewport stretch=0 window.scrollY=0after the steps let through: viewport stretch=-20 window.scrollY=0-wheel events the page could have canceled: 3 of 3+wheel events the page could have canceled: 2 of 3sprung back: viewport stretch=0 window.scrollY=0diff --git a/Tests/LibWeb/Text/expected/async-scrolling/elastic-overscroll-under-a-wheel-listener-covering-the-viewport.txt b/Tests/LibWeb/Text/expected/async-scrolling/elastic-overscroll-under-a-wheel-listener-covering-the-viewport.txtindex 3dae4ad02fa..a6395078758 100644--- a/Tests/LibWeb/Text/expected/async-scrolling/elastic-overscroll-under-a-wheel-listener-covering-the-viewport.txt+++ b/Tests/LibWeb/Text/expected/async-scrolling/elastic-overscroll-under-a-wheel-listener-covering-the-viewport.txt@@ -1,3 +1,3 @@pulled past the top: viewport stretch=-20 window.scrollY=0-wheel events the page could have canceled: 2 of 2+wheel events the page could have canceled: 1 of 2sprung back: viewport stretch=0 window.scrollY=0diff --git a/Tests/LibWeb/Text/expected/async-scrolling/wheel-listener-added-mid-gesture-sees-the-next-step-first.txt b/Tests/LibWeb/Text/expected/async-scrolling/wheel-listener-added-mid-gesture-sees-the-next-step-first.txtnew file mode 100644index 00000000000..cde7808b1ca--- /dev/null+++ b/Tests/LibWeb/Text/expected/async-scrolling/wheel-listener-added-mid-gesture-sees-the-next-step-first.txt@@ -0,0 +1,2 @@+cancelable steps: true, false, true, false+window.scrollY: 700diff --git a/Tests/LibWeb/Text/input/async-scrolling/elastic-overscroll-after-the-page-cancels-the-first-step.html b/Tests/LibWeb/Text/input/async-scrolling/elastic-overscroll-after-the-page-cancels-the-first-step.htmlindex 4912fe8c037..ab0c55f2a2a 100644--- a/Tests/LibWeb/Text/input/async-scrolling/elastic-overscroll-after-the-page-cancels-the-first-step.html+++ b/Tests/LibWeb/Text/input/async-scrolling/elastic-overscroll-after-the-page-cancels-the-first-step.html@@ -24,7 +24,8 @@await internals.wheelThroughUIProcess(400, 300, 0, -200, true, "ongoing");println(`after the canceled step: viewport stretch=${internals.elasticOverscrollStretchY()} window.scrollY=${window.scrollY}`);- // The page asks about the next step too, and the steps it lets through stretch the page.+ // The page can cancel the next step too. Once it lets a step through, that step and the rest of the gesture+ // stretch the page without asking the page again.await internals.wheelThroughUIProcess(400, 300, 0, -200, true, "ongoing");await internals.wheelThroughUIProcess(400, 300, 0, -200, true, "ongoing");println(`after the steps let through: viewport stretch=${internals.elasticOverscrollStretchY()} window.scrollY=${window.scrollY}`);diff --git a/Tests/LibWeb/Text/input/async-scrolling/elastic-overscroll-under-a-wheel-listener-covering-the-viewport.html b/Tests/LibWeb/Text/input/async-scrolling/elastic-overscroll-under-a-wheel-listener-covering-the-viewport.htmlindex 7b426676088..b994b2fe0ad 100644--- a/Tests/LibWeb/Text/input/async-scrolling/elastic-overscroll-under-a-wheel-listener-covering-the-viewport.html+++ b/Tests/LibWeb/Text/input/async-scrolling/elastic-overscroll-under-a-wheel-listener-covering-the-viewport.html@@ -18,7 +18,8 @@await animationFrame();await animationFrame();- // The page sees every step first, cancels none of them, and the page still stretches past its top.+ // The page sees the first step before anything scrolls and does not cancel it. The compositor then stretches the+ // page past its top, and scrolls the rest of the gesture without asking the page again.await internals.wheelThroughUIProcess(400, 300, 0, -200, true, "ongoing");await internals.wheelThroughUIProcess(400, 300, 0, -200, true, "ongoing");println(`pulled past the top: viewport stretch=${internals.elasticOverscrollStretchY()} window.scrollY=${window.scrollY}`);diff --git a/Tests/LibWeb/Text/input/async-scrolling/wheel-listener-added-mid-gesture-sees-the-next-step-first.html b/Tests/LibWeb/Text/input/async-scrolling/wheel-listener-added-mid-gesture-sees-the-next-step-first.htmlnew file mode 100644index 00000000000..84f15446ebe--- /dev/null+++ b/Tests/LibWeb/Text/input/async-scrolling/wheel-listener-added-mid-gesture-sees-the-next-step-first.html@@ -0,0 +1,35 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<style>+ body {+ margin: 0;+ height: 3000px;+ }+</style>+<script>+ promiseTest(async () => {+ let cancelableSteps = [];+ window.addEventListener("wheel", event => {+ if (event.deltaY !== 0)+ cancelableSteps.push(event.cancelable);+ }, { passive: false });+ window.scrollTo(0, 500);+ await animationFrame();+ await animationFrame();++ // The page lets the first step through, and the compositor scrolls the rest of the gesture without asking.+ await internals.wheelThroughUIProcess(400, 300, 0, 50, true, "ongoing");+ await internals.wheelThroughUIProcess(400, 300, 0, 50, true, "ongoing");++ // A blocking listener added during the gesture is asked about the next step, which the page could cancel.+ document.addEventListener("wheel", () => {}, { passive: false });+ // A synchronous call to the compositor, so that it has heard about the new listener before the next step.+ internals.elasticOverscrollStretchY();+ await internals.wheelThroughUIProcess(400, 300, 0, 50, true, "ongoing");+ await internals.wheelThroughUIProcess(400, 300, 0, 50, true, "ongoing");+ println(`cancelable steps: ${cancelableSteps.join(", ")}`);+ println(`window.scrollY: ${window.scrollY}`);++ await internals.wheelThroughUIProcess(400, 300, 0, 0, true, "ended");+ });+</script>