Truly independent web browser
LibCompositing+Compositor: Name each wheel and scrollbar decision
Aliaksandr Kalenik6347dbe43e68
diff --git a/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cpp b/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cppindex f860cb5c95d..06e4862cf57 100644--- a/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cpp+++ b/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cpp@@ -29,6 +29,23 @@ void AsyncScrollTree::set_state(AsyncScrollingState&& state)m_visual_context_tree_structural_epoch.clear();}+Web::InputRoutingDecision input_routing_decision_for_first_wheel_step(WheelHitTestOutcome outcome)+{+ switch (outcome) {+ case WheelHitTestOutcome::FoundScrollTarget:+ return Web::InputRoutingDecision::Latched;+ case WheelHitTestOutcome::NoScrollTarget:+ return Web::InputRoutingDecision::NoScrollTarget;+ case WheelHitTestOutcome::BlockedByMainThreadRegion:+ return Web::InputRoutingDecision::BlockedByMainThreadRegion;+ case WheelHitTestOutcome::BlockedByWheelEventRegion:+ return Web::InputRoutingDecision::BlockedByWheelEventRegion;+ case WheelHitTestOutcome::HitTestTargetsOfAnotherVisualContextTree:+ return Web::InputRoutingDecision::HitTestTargetsOfAnotherVisualContextTree;+ }+ VERIFY_NOT_REACHED();+}+AsyncScrollNode const* AsyncScrollTree::scroll_node_for_id(AsyncScrollNodeID node_id) const{for (auto const& node : m_scroll_nodes) {diff --git a/Libraries/LibCompositing/Scrolling/AsyncScrollTree.h b/Libraries/LibCompositing/Scrolling/AsyncScrollTree.hindex cf401c1542b..8035398eb02 100644--- a/Libraries/LibCompositing/Scrolling/AsyncScrollTree.h+++ b/Libraries/LibCompositing/Scrolling/AsyncScrollTree.h@@ -44,6 +44,10 @@ struct WheelHitTestResult {}};+// A first step of a wheel gesture is latched to the scroller the hit test found, and is otherwise left to the main+// thread for the outcome's reason.+COMPOSITING_API Web::InputRoutingDecision input_routing_decision_for_first_wheel_step(WheelHitTestOutcome);+struct WheelScrollTarget {Web::AsyncScrollNodeStableID stable_node_id;Gfx::FloatPoint current_offset;diff --git a/Libraries/LibCompositing/Scrolling/AsyncScrollingState.cpp b/Libraries/LibCompositing/Scrolling/AsyncScrollingState.cppindex 04912da6efa..233e278780d 100644--- a/Libraries/LibCompositing/Scrolling/AsyncScrollingState.cpp+++ b/Libraries/LibCompositing/Scrolling/AsyncScrollingState.cpp@@ -213,6 +213,23 @@ WheelRoutingAdmission wheel_routing_admission_for(AsyncScrollingState const& stareturn WheelRoutingAdmission::Accepted;}+Web::InputRoutingDecision input_routing_decision_for_wheel_step_not_admitted_by(WheelRoutingAdmission admission)+{+ switch (admission) {+ case WheelRoutingAdmission::Accepted:+ VERIFY_NOT_REACHED();+ case WheelRoutingAdmission::NoAsyncScrollingState:+ return Web::InputRoutingDecision::NoAsyncScrollingState;+ case WheelRoutingAdmission::BlockingWheelEventListeners:+ return Web::InputRoutingDecision::BlockingWheelEventListeners;+ case WheelRoutingAdmission::NoScrollNode:+ return Web::InputRoutingDecision::NoScrollNode;+ case WheelRoutingAdmission::StaleWheelEventListeners:+ return Web::InputRoutingDecision::StaleWheelEventListeners;+ }+ VERIFY_NOT_REACHED();+}+Utf16View wheel_routing_admission_to_utf16_view(WheelRoutingAdmission admission){switch (admission) {diff --git a/Libraries/LibCompositing/Scrolling/AsyncScrollingState.h b/Libraries/LibCompositing/Scrolling/AsyncScrollingState.hindex 1ce65b29352..d39df9f9855 100644--- a/Libraries/LibCompositing/Scrolling/AsyncScrollingState.h+++ b/Libraries/LibCompositing/Scrolling/AsyncScrollingState.h@@ -23,6 +23,7 @@#include <LibGfx/Point.h>#include <LibGfx/Rect.h>#include <LibWebCommon/Page/AsyncScrollNodeStableID.h>+#include <LibWebCommon/Page/InputRoutingDecision.h>namespace Compositing {@@ -182,6 +183,8 @@ enum class WheelScrollAdmission {COMPOSITING_API AsyncScrollingState async_scrolling_state_from_display_list(Compositing::DisplayList const&);COMPOSITING_API WheelRoutingAdmission wheel_routing_admission_for(AsyncScrollingState const&);COMPOSITING_API Utf16View wheel_routing_admission_to_utf16_view(WheelRoutingAdmission);+// Why a wheel step that the admission does not let the compositor scroll is left to the main thread.+COMPOSITING_API Web::InputRoutingDecision input_routing_decision_for_wheel_step_not_admitted_by(WheelRoutingAdmission);COMPOSITING_API bool blocks_wheel_event_at_position(AsyncScrollingState const&, RefPtr<Compositing::DisplayList const> const&, Compositing::AccumulatedVisualContextTree const*, Compositing::ScrollStateSnapshot const&, Gfx::FloatPoint position);COMPOSITING_API WheelScrollAdmission admit_wheel_scroll(AsyncScrollingState const&, RefPtr<Compositing::DisplayList const> const&, Compositing::AccumulatedVisualContextTree const*, Compositing::ScrollStateSnapshot const&, Gfx::FloatPoint position, Gfx::FloatPoint delta, bool blocking_wheel_event_regions_are_current);diff --git a/Libraries/LibCompositing/Types.cpp b/Libraries/LibCompositing/Types.cppindex df1b9609703..c574a71b166 100644--- a/Libraries/LibCompositing/Types.cpp+++ b/Libraries/LibCompositing/Types.cpp@@ -166,6 +166,8 @@ ErrorOr<void> encode(Encoder& encoder, Compositing::AsyncScrollEnqueueResult con{TRY(encoder.encode(result.accepted));TRY(encoder.encode(result.operation_id));+ TRY(encoder.encode(result.routing_decision));+ TRY(encoder.encode(result.routed_scroller));return {};}@@ -175,6 +177,8 @@ ErrorOr<Compositing::AsyncScrollEnqueueResult> decode(Decoder& decoder)return Compositing::AsyncScrollEnqueueResult {.accepted = TRY(decoder.decode<bool>()),.operation_id = TRY(decoder.decode<Optional<Compositing::AsyncScrollOperationID>>()),+ .routing_decision = TRY(decoder.decode<Optional<Web::InputRoutingDecision>>()),+ .routed_scroller = TRY(decoder.decode<Optional<Web::AsyncScrollNodeStableID>>()),};}diff --git a/Libraries/LibCompositing/Types.h b/Libraries/LibCompositing/Types.hindex d250b133d7f..414937ac535 100644--- a/Libraries/LibCompositing/Types.h+++ b/Libraries/LibCompositing/Types.h@@ -17,6 +17,7 @@#include <LibCompositing/Scrolling/AsyncScrollingState.h>#include <LibIPC/Forward.h>#include <LibWebCommon/Page/CompositorContextId.h>+#include <LibWebCommon/Page/InputRoutingDecision.h>#include <LibWebCommon/Page/PageId.h>#include <LibWebCommon/PixelUnits.h>@@ -90,7 +91,10 @@ struct PendingAsyncScrollUpdates {struct AsyncScrollEnqueueResult {bool accepted { false };- Optional<AsyncScrollOperationID> operation_id;+ Optional<AsyncScrollOperationID> operation_id {};+ // Why the compositor took or turned away a wheel step, and the scroller it routed the step to.+ Optional<Web::InputRoutingDecision> routing_decision {};+ Optional<Web::AsyncScrollNodeStableID> routed_scroller {};};enum class AsyncScrollOperationTracking {diff --git a/Libraries/LibWebCommon/CMakeLists.txt b/Libraries/LibWebCommon/CMakeLists.txtindex 878e15d9db9..9af250e4c78 100644--- a/Libraries/LibWebCommon/CMakeLists.txt+++ b/Libraries/LibWebCommon/CMakeLists.txt@@ -47,6 +47,7 @@ set(SOURCESPage/AsyncScrollNodeStableID.cppPage/DragEvent.cppPage/InputEvent.cpp+ Page/InputRoutingDecision.cppPage/MediaContextMenu.cppPage/SpellingError.cppPixelUnits.cppdiff --git a/Libraries/LibWebCommon/Page/InputRoutingDecision.cpp b/Libraries/LibWebCommon/Page/InputRoutingDecision.cppnew file mode 100644index 00000000000..3d34d6a43a2--- /dev/null+++ b/Libraries/LibWebCommon/Page/InputRoutingDecision.cpp@@ -0,0 +1,24 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#include <AK/Assertions.h>+#include <LibWebCommon/Page/InputRoutingDecision.h>++namespace Web {++StringView input_routing_decision_name(InputRoutingDecision decision)+{+ switch (decision) {+#define __ENUMERATE_INPUT_ROUTING_DECISION(name, string) \+ case InputRoutingDecision::name: \+ return string##sv;+ ENUMERATE_INPUT_ROUTING_DECISIONS(__ENUMERATE_INPUT_ROUTING_DECISION)+#undef __ENUMERATE_INPUT_ROUTING_DECISION+ }+ VERIFY_NOT_REACHED();+}++}diff --git a/Libraries/LibWebCommon/Page/InputRoutingDecision.h b/Libraries/LibWebCommon/Page/InputRoutingDecision.hnew file mode 100644index 00000000000..e7343024a9a--- /dev/null+++ b/Libraries/LibWebCommon/Page/InputRoutingDecision.h@@ -0,0 +1,52 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#pragma once++#include <AK/StringView.h>+#include <AK/Types.h>+#include <LibWebCommon/Export.h>++namespace Web {++// What decided where an input event went, and why, at one step of its way from the UI to the page.+#define ENUMERATE_INPUT_ROUTING_DECISIONS(X) \+ X(ContextNotPresenting, "context-not-presenting") \+ X(NoAsyncScrollingState, "no-async-scrolling-state") \+ X(BlockingWheelEventListeners, "blocking-wheel-event-listeners") \+ X(NoScrollNode, "no-scroll-node") \+ X(StaleWheelEventListeners, "stale-wheel-event-listeners") \+ X(StepOvertakenByUI, "step-overtaken-by-ui") \+ X(GestureEndWithNothingToSnap, "gesture-end-with-nothing-to-snap") \+ X(SnappedAtGestureEnd, "snapped-at-gesture-end") \+ X(HitTestTargetsOfAnotherVisualContextTree, "hit-test-targets-of-another-visual-context-tree") \+ X(BlockedByMainThreadRegion, "blocked-by-main-thread-region") \+ X(BlockedByWheelEventRegion, "blocked-by-wheel-event-region") \+ X(NoScrollTarget, "no-scroll-target") \+ X(ScrollerInOtherDocument, "scroller-in-other-document") \+ X(StepWithoutDelta, "step-without-delta") \+ X(PannedVisualViewport, "panned-visual-viewport") \+ X(Latched, "latched") \+ X(LatchedOutermostScrollerToStretch, "latched-outermost-scroller-to-stretch") \+ X(ContinuedLatch, "continued-latch") \+ X(NotOverAScrollbar, "not-over-a-scrollbar") \+ X(NotPrimaryButton, "not-primary-button") \+ X(HoveringScrollbarPaintedByCompositor, "hovering-scrollbar-painted-by-compositor") \+ X(BeganScrollbarDrag, "began-scrollbar-drag") \+ X(ContinuedScrollbarDrag, "continued-scrollbar-drag") \+ X(EndedScrollbarDrag, "ended-scrollbar-drag") \+ X(NoScrollbarDrag, "no-scrollbar-drag") \+ X(LeftDuringScrollbarDrag, "left-during-scrollbar-drag")++enum class InputRoutingDecision : u8 {+#define __ENUMERATE_INPUT_ROUTING_DECISION(name, string) name,+ ENUMERATE_INPUT_ROUTING_DECISIONS(__ENUMERATE_INPUT_ROUTING_DECISION)+#undef __ENUMERATE_INPUT_ROUTING_DECISION+};++WEBCOMMON_API StringView input_routing_decision_name(InputRoutingDecision);++}diff --git a/Services/Compositor/CompositorState.cpp b/Services/Compositor/CompositorState.cppindex 61bd39649e7..0193d7036b7 100644--- a/Services/Compositor/CompositorState.cpp+++ b/Services/Compositor/CompositorState.cpp@@ -568,6 +568,8 @@ void CompositorState::handle_and_dispatch_mouse_event(Web::CompositorContextId cresult = context->handle_wheel_event(event);elseresult = context->handle_mouse_event(event);+ if (result.routing_decision.has_value())+ dbgln_if(COMPOSITOR_DEBUG, "[Compositor] Context {} routed input event {}: {}", context_id, event.id, Web::input_routing_decision_name(*result.routing_decision));// Schedules the present, publishes the scroll updates the event produced and asks for a rendering update, all of// which reach WebContent ahead of the event itself on the same connection.diff --git a/Services/Compositor/ContextState.cpp b/Services/Compositor/ContextState.cppindex be11693ffb4..5711f740f64 100644--- a/Services/Compositor/ContextState.cpp+++ b/Services/Compositor/ContextState.cpp@@ -360,7 +360,7 @@ Compositing::ScrollStateSnapshot ContextState::scroll_state_snapshot_at_keyboardContextState::ContextUpdateResult ContextState::handle_mouse_event(Web::MouseEvent const& event){if (!presents_to_client())- return {};+ return ContextUpdateResult::declined(Web::InputRoutingDecision::ContextNotPresenting);auto position = Gfx::FloatPoint {static_cast<float>(event.position.x().value()),@@ -368,7 +368,11 @@ ContextState::ContextUpdateResult ContextState::handle_mouse_event(Web::MouseEve};if (m_scrollbar_controller.is_empty())- return {};+ return ContextUpdateResult::declined(Web::InputRoutingDecision::NotOverAScrollbar);++ auto scroller_of_scrollbar = [&](size_t scrollbar_index) {+ return m_scrollbar_controller.scrollbars()[scrollbar_index].scroller_stable_node_id;+ };// The compositor paints how its own scrollbars expand, outside of what damage tracking sees.auto frame_repainting_scrollbars_painted_by_compositor = [&]() -> Optional<PendingFrame> {@@ -380,14 +384,16 @@ ContextState::ContextUpdateResult ContextState::handle_mouse_event(Web::MouseEveswitch (event.type) {case Web::MouseEvent::Type::MouseDown: {if (event.button != Web::UIEvents::MouseButton::Primary)- return {};+ return ContextUpdateResult::declined(Web::InputRoutingDecision::NotPrimaryButton);auto drag = m_scrollbar_controller.begin_drag(m_async_scroll_tree, m_scene.visual_context_tree_for_compositing(), m_scroll_state_snapshot, position);if (!drag.has_value())- return {};+ return ContextUpdateResult::declined(Web::InputRoutingDecision::NotOverAScrollbar);ContextUpdateResult result;result.accepted = true;+ result.routing_decision = Web::InputRoutingDecision::BeganScrollbarDrag;+ result.routed_scroller = scroller_of_scrollbar(drag->scrollbar_index);result.scrollbar_dragged_by_compositor = m_scrollbar_controller.captured_scrollbar_painted_by_display_list();if (!result.scrollbar_dragged_by_compositor.has_value())result.frame_to_present = frame_repainting_scrollbars_painted_by_compositor();@@ -408,6 +414,8 @@ ContextState::ContextUpdateResult ContextState::handle_mouse_event(Web::MouseEve.frame_to_present = frame_to_present,.should_request_rendering_update = frame_to_present.has_value(),.scrollbar_dragged_by_compositor = scrollbar_dragged_by_compositor,+ .routing_decision = Web::InputRoutingDecision::ContinuedScrollbarDrag,+ .routed_scroller = scroller_of_scrollbar(drag->scrollbar_index),};}@@ -416,26 +424,32 @@ ContextState::ContextUpdateResult ContextState::handle_mouse_event(Web::MouseEveOptional<PendingFrame> frame_to_present;if (m_scrollbar_controller.set_hovered_scrollbar(hovered_scrollbar_index))frame_to_present = frame_repainting_scrollbars_painted_by_compositor();+ if (!hovered_scrollbar_index.has_value())+ return { .frame_to_present = frame_to_present, .routing_decision = Web::InputRoutingDecision::NotOverAScrollbar };return {- .accepted = hovered_scrollbar_index.has_value(),+ .accepted = true,.frame_to_present = frame_to_present,.should_request_rendering_update = false,+ .routing_decision = Web::InputRoutingDecision::HoveringScrollbarPaintedByCompositor,+ .routed_scroller = scroller_of_scrollbar(*hovered_scrollbar_index),};}case Web::MouseEvent::Type::MouseUp: {if (event.button != Web::UIEvents::MouseButton::Primary)- return {};+ return ContextUpdateResult::declined(Web::InputRoutingDecision::NotPrimaryButton);auto was_dragging_scrollbar = m_scrollbar_controller.has_captured_scrollbar();auto scrollbar_dragged_by_compositor = m_scrollbar_controller.captured_scrollbar_painted_by_display_list();auto drag = m_scrollbar_controller.release_captured_drag(m_scene.visual_context_tree_for_compositing(), m_scroll_state_snapshot, position);if (!drag.has_value())- return {};+ return ContextUpdateResult::declined(Web::InputRoutingDecision::NoScrollbarDrag);note_user_scroll_gesture_end_if_drag_ended(was_dragging_scrollbar);ContextUpdateResult result;result.accepted = true;+ result.routing_decision = Web::InputRoutingDecision::EndedScrollbarDrag;+ result.routed_scroller = scroller_of_scrollbar(drag->scrollbar_index);result.scrollbar_dragged_by_compositor = scrollbar_dragged_by_compositor;// The main thread learns of the release from the next update it takes, so one is asked for even when the// release scrolls nothing.@@ -463,6 +477,7 @@ ContextState::ContextUpdateResult ContextState::handle_mouse_event(Web::MouseEve.frame_to_present = frame_to_present,.should_request_rendering_update = false,.scrollbar_dragged_by_compositor = m_scrollbar_controller.captured_scrollbar_painted_by_display_list(),+ .routing_decision = had_capture ? Web::InputRoutingDecision::LeftDuringScrollbarDrag : Web::InputRoutingDecision::NoScrollbarDrag,};}case Web::MouseEvent::Type::MouseWheel:@@ -755,7 +770,7 @@ ContextState::AsyncScrollResult ContextState::async_scroll_by(// since nothing would be left to let go of either.bool step_came_from_ui = input_event_id != 0 && presents_to_client();if (step_came_from_ui && m_wheel_gesture_routing.step_was_overtaken_by_ui(scroll_gesture_phase, input_event_id))- return {};+ return AsyncScrollResult::declined(Web::InputRoutingDecision::StepOvertakenByUI);// The end of a gesture lets go of the scroller it stretched even if the context has stopped taking wheel events.if (scroll_gesture_phase == Web::ScrollGesturePhase::Ended)@@ -779,7 +794,7 @@ ContextState::AsyncScrollResult ContextState::async_scroll_by(if (!m_wheel_gesture_routing.admits_async_wheel()&& !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 {};+ return AsyncScrollResult::declined(Compositing::input_routing_decision_for_wheel_step_not_admitted_by(m_wheel_gesture_routing.admission()));m_scroll_snap_controller.note_gesture_phase(scroll_gesture_phase);@@ -787,24 +802,31 @@ ContextState::AsyncScrollResult ContextState::async_scroll_by(if (scroll_gesture_phase == Web::ScrollGesturePhase::Ended && delta.is_zero()) {auto operation_id = snap_at_gesture_end(now);if (!operation_id.has_value())- return {};+ return AsyncScrollResult::declined(Web::InputRoutingDecision::GestureEndWithNothingToSnap);m_async_scrolling_viewport_rect = viewport_rect;return {- .enqueue_result = { true, operation_tracking == Compositing::AsyncScrollOperationTracking::Yes ? operation_id : Optional<Compositing::AsyncScrollOperationID> {} },+ .enqueue_result = {+ .accepted = true,+ .operation_id = operation_tracking == Compositing::AsyncScrollOperationTracking::Yes ? operation_id : Optional<Compositing::AsyncScrollOperationID> {},+ .routing_decision = Web::InputRoutingDecision::SnappedAtGestureEnd,+ },.frame_to_present = PendingFrame::repainting_changes(viewport_rect),};}bool is_first_step_of_gesture = !latched_node_id.has_value();+ auto routing_decision = Web::InputRoutingDecision::ContinuedLatch;if (is_first_step_of_gesture) {auto wheel_step_dispatch_for_hit_test = page_let_touchpad_step_through ? Compositing::WheelStepDispatch::DispatchedAndNotCanceled : Compositing::WheelStepDispatch::NotYetDispatched;- latched_node_id = hit_test_and_latch_wheel_gesture(position, delta, wheel_delta_precision, scroll_gesture_phase, modifiers, now, expected_document_id, wheel_step_dispatch_for_hit_test);- if (!latched_node_id.has_value())- return {};+ auto latch_attempt = hit_test_and_latch_wheel_gesture(position, delta, wheel_delta_precision, scroll_gesture_phase, modifiers, now, expected_document_id, wheel_step_dispatch_for_hit_test);+ if (!latch_attempt.latched_node_id.has_value())+ return AsyncScrollResult::declined(latch_attempt.decision);+ latched_node_id = latch_attempt.latched_node_id;+ routing_decision = latch_attempt.decision;} else if (latched_node_id->document_id != expected_document_id) {// A step over another document than the latched scroller's is left to the navigable hosting that scroller,// which reports the same step with its own document.- return {};+ return AsyncScrollResult::declined(Web::InputRoutingDecision::ScrollerInOtherDocument);}if (page_let_touchpad_step_through)m_wheel_gesture_routing.note_page_let_latched_gesture_through();@@ -812,7 +834,12 @@ ContextState::AsyncScrollResult ContextState::async_scroll_by(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);return {- .enqueue_result = { true, outcome.operation_id },+ .enqueue_result = {+ .accepted = true,+ .operation_id = outcome.operation_id,+ .routing_decision = routing_decision,+ .routed_scroller = m_wheel_gesture_routing.latched_scroller(),+ },.frame_to_present = outcome.viewport_rect_to_present.map([](auto const& rect) { return PendingFrame::repainting_changes(rect); }),};}@@ -1111,7 +1138,7 @@ ContextState::ScrollFlingStep ContextState::scroll_for_fling_event(Web::MouseEveContextState::ContextUpdateResult ContextState::scroll_for_wheel_event(Web::MouseEvent const& event, MonotonicTime now){if (!presents_to_client())- return {};+ return ContextUpdateResult::declined(Web::InputRoutingDecision::ContextNotPresenting);auto position = wheel_event_position(event);auto delta = wheel_event_delta_in_device_pixels(event);@@ -1126,14 +1153,19 @@ ContextState::ContextUpdateResult ContextState::scroll_for_wheel_event(Web::Mous&& m_scene.visual_viewport_scale().value_or(1.0f) > 1.0f;if (!m_wheel_gesture_routing.admits_async_wheel() && !can_pan_zoomed_visual_viewport&& !step_continues_touchpad_gesture_the_page_let_through(latched_node_id, event.wheel_delta_precision, event.scroll_gesture_phase))- return {};+ return ContextUpdateResult::declined(Compositing::input_routing_decision_for_wheel_step_not_admitted_by(m_wheel_gesture_routing.admission()));m_scroll_snap_controller.note_gesture_phase(event.scroll_gesture_phase);if (event.scroll_gesture_phase == Web::ScrollGesturePhase::Ended && delta.is_zero()) {if (!snap_at_gesture_end(now).has_value())- return {};- return { .accepted = true, .frame_to_present = PendingFrame::repainting_changes(m_async_scrolling_viewport_rect), .should_request_rendering_update = true };+ return ContextUpdateResult::declined(Web::InputRoutingDecision::GestureEndWithNothingToSnap);+ return {+ .accepted = true,+ .frame_to_present = PendingFrame::repainting_changes(m_async_scrolling_viewport_rect),+ .should_request_rendering_update = true,+ .routing_decision = Web::InputRoutingDecision::SnappedAtGestureEnd,+ };}// Whether a gesture scrolls here or on the main thread is decided by its first step; the steps of a latched@@ -1142,22 +1174,38 @@ ContextState::ContextUpdateResult ContextState::scroll_for_wheel_event(Web::Mousif (is_first_step_of_gesture) {auto initial_scroll_target = m_async_scroll_tree.hit_test_scroll_node_for_wheel(m_scene.visual_context_tree_for_compositing(), position, delta);if (initial_scroll_target.is_blocked_by_a_region())- return {};+ return ContextUpdateResult::declined(Compositing::input_routing_decision_for_first_wheel_step(initial_scroll_target.outcome));}- if (delta.is_zero())- return { .accepted = true, .frame_to_present = {}, .should_request_rendering_update = false };+ if (delta.is_zero()) {+ return {+ .accepted = true,+ .frame_to_present = {},+ .should_request_rendering_update = false,+ .routing_decision = Web::InputRoutingDecision::StepWithoutDelta,+ .routed_scroller = m_wheel_gesture_routing.latched_scroller(),+ };+ }// A gesture is latched before its first step pans the visual viewport, so that the scroller it belongs to is known// for as long as the gesture only pans.- if (is_first_step_of_gesture)- latched_node_id = hit_test_and_latch_wheel_gesture(position, delta.scaled(1.0f / m_scene.visual_viewport_magnification()), event.wheel_delta_precision, event.scroll_gesture_phase, event.modifiers, now, {}, Compositing::WheelStepDispatch::NotYetDispatched);+ auto routing_decision = Web::InputRoutingDecision::ContinuedLatch;+ if (is_first_step_of_gesture) {+ auto latch_attempt = hit_test_and_latch_wheel_gesture(position, delta.scaled(1.0f / m_scene.visual_viewport_magnification()), event.wheel_delta_precision, event.scroll_gesture_phase, event.modifiers, now, {}, Compositing::WheelStepDispatch::NotYetDispatched);+ latched_node_id = latch_attempt.latched_node_id;+ routing_decision = latch_attempt.decision;+ }// A zoomed page still pans its visual viewport by a gesture that no scroller takes.if (!latched_node_id.has_value()) {if (pan_visual_viewport_by(delta).is_zero())- return {};- return { .accepted = true, .frame_to_present = PendingFrame::repainting_changes(m_async_scrolling_viewport_rect), .should_request_rendering_update = true };+ return ContextUpdateResult::declined(routing_decision);+ return {+ .accepted = true,+ .frame_to_present = PendingFrame::repainting_changes(m_async_scrolling_viewport_rect),+ .should_request_rendering_update = true,+ .routing_decision = Web::InputRoutingDecision::PannedVisualViewport,+ };}auto scroll_chaining = is_first_step_of_gesture ? Compositing::ScrollChaining::ToScrollableAncestors : Compositing::ScrollChaining::None;@@ -1166,6 +1214,8 @@ ContextState::ContextUpdateResult ContextState::scroll_for_wheel_event(Web::Mous.accepted = true,.frame_to_present = outcome.viewport_rect_to_present.map([](auto const& rect) { return PendingFrame::repainting_changes(rect); }),.should_request_rendering_update = outcome.viewport_rect_to_present.has_value() && !outcome.only_elastic_overscroll_changed,+ .routing_decision = routing_decision,+ .routed_scroller = m_wheel_gesture_routing.latched_scroller(),};}@@ -1415,31 +1465,34 @@ Optional<Compositing::AsyncScrollNodeID> ContextState::resolve_wheel_scroll_latcreturn m_wheel_gesture_routing.resolve_latch(m_async_scroll_tree, m_scene.current_visual_context_tree(), position, scroll_gesture_phase, modifiers, now);}-Optional<Compositing::AsyncScrollNodeID> ContextState::hit_test_and_latch_wheel_gesture(Gfx::FloatPoint position, Gfx::FloatPoint delta, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, u32 modifiers, MonotonicTime now, Optional<Web::UniqueNodeID> expected_document_id, Compositing::WheelStepDispatch wheel_step_dispatch)+ContextState::WheelGestureLatchAttempt ContextState::hit_test_and_latch_wheel_gesture(Gfx::FloatPoint position, Gfx::FloatPoint delta, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, u32 modifiers, MonotonicTime now, Optional<Web::UniqueNodeID> expected_document_id, Compositing::WheelStepDispatch wheel_step_dispatch){Function<Optional<Gfx::FloatPoint>(Web::AsyncScrollNodeStableID)> in_flight_destination_for;if (wheel_delta_precision == Web::WheelDeltaPrecision::Discrete)in_flight_destination_for = [this](auto stable_node_id) { return in_flight_wheel_destination(stable_node_id); };auto scroll_target = m_async_scroll_tree.hit_test_scroll_node_for_wheel(m_scene.visual_context_tree_for_compositing(), position, delta, in_flight_destination_for, wheel_step_dispatch);if (scroll_target.is_blocked_by_a_region())- return {};+ return { Compositing::input_routing_decision_for_first_wheel_step(scroll_target.outcome) };auto node_id_to_latch = scroll_target.node_id;+ auto decision = Web::InputRoutingDecision::Latched;// Fingers that start to pull where every scroller under them is already at its edge stretch the outermost one. A// context nested in another one turns the gesture away instead, which passes it on to the document around it.bool fingers_start_a_gesture_at_an_edge = !node_id_to_latch.has_value() && scroll_target.innermost_scroll_node_id.has_value() && !delta.is_zero()&& scroll_gesture_phase == Web::ScrollGesturePhase::Ongoing && wheel_step_can_stretch_elastically(wheel_delta_precision, scroll_gesture_phase);- if (fingers_start_a_gesture_at_an_edge)+ if (fingers_start_a_gesture_at_an_edge) {node_id_to_latch = m_async_scroll_tree.outermost_scroll_node_wheel_scrollable_along_main_axis_of(*scroll_target.innermost_scroll_node_id, delta);+ decision = Web::InputRoutingDecision::LatchedOutermostScrollerToStretch;+ }if (!node_id_to_latch.has_value())- return {};+ return { Compositing::input_routing_decision_for_first_wheel_step(scroll_target.outcome) };if (expected_document_id.has_value() && node_id_to_latch->document_id != *expected_document_id)- return {};+ return { Web::InputRoutingDecision::ScrollerInOtherDocument };auto const* node = m_async_scroll_tree.scroll_node_for_id(*node_id_to_latch);VERIFY(node);m_wheel_gesture_routing.latch(node->stable_node_id, position, scroll_gesture_phase, modifiers, now);- return node_id_to_latch;+ return { decision, node_id_to_latch };}void ContextState::report_started_user_scroll(Compositing::AsyncScrollOperationID operation_id, Web::AsyncScrollNodeStableID stable_node_id, Gfx::FloatPoint step_start_offset, Gfx::FloatPoint destination_offset, Compositing::ScrollAnimationKind animation_kind, bool is_absolute_scroll)diff --git a/Services/Compositor/ContextState.h b/Services/Compositor/ContextState.hindex 0b122018136..34fe12c4ad1 100644--- a/Services/Compositor/ContextState.h+++ b/Services/Compositor/ContextState.h@@ -65,14 +65,21 @@ public:struct AsyncScrollResult {Compositing::AsyncScrollEnqueueResult enqueue_result;- Optional<PendingFrame> frame_to_present;+ Optional<PendingFrame> frame_to_present {};++ static AsyncScrollResult declined(Web::InputRoutingDecision decision) { return { .enqueue_result = { .routing_decision = decision } }; }};struct ContextUpdateResult {bool accepted { false };- Optional<PendingFrame> frame_to_present;+ Optional<PendingFrame> frame_to_present {};bool should_request_rendering_update { false };Optional<Web::ScrollbarDraggedByCompositor> scrollbar_dragged_by_compositor {};+ // Why a wheel or mouse event was taken or turned away, and the scroller it was routed to.+ Optional<Web::InputRoutingDecision> routing_decision {};+ Optional<Web::AsyncScrollNodeStableID> routed_scroller {};++ static ContextUpdateResult declined(Web::InputRoutingDecision decision) { return { .routing_decision = decision }; }};ContextState(Web::CompositorContextId, Optional<u64> page_id, CompositorStateWebContentClient&, Compositing::CanvasSurfaceRegistry const&, Function<void(Gfx::IntRect)> schedule_caret_repaint = {});@@ -231,8 +238,12 @@ private:};NodeScrollByWheelDelta scroll_node_by_wheel_delta(Compositing::AsyncScrollNodeID, Gfx::FloatPoint delta, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, Compositing::AsyncScrollOperationTracking, Gfx::IntRect viewport_rect, MonotonicTime now, Compositing::ScrollChaining);Optional<Compositing::AsyncScrollNodeID> resolve_wheel_scroll_latch(Gfx::FloatPoint position, Web::ScrollGesturePhase, u32 modifiers, MonotonicTime now);+ struct WheelGestureLatchAttempt {+ Web::InputRoutingDecision decision;+ Optional<Compositing::AsyncScrollNodeID> latched_node_id {};+ };// The scroller the first step of a wheel gesture is routed to, which the gesture is latched to.- Optional<Compositing::AsyncScrollNodeID> hit_test_and_latch_wheel_gesture(Gfx::FloatPoint position, Gfx::FloatPoint delta, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, u32 modifiers, MonotonicTime now, Optional<Web::UniqueNodeID> expected_document_id, Compositing::WheelStepDispatch);+ WheelGestureLatchAttempt hit_test_and_latch_wheel_gesture(Gfx::FloatPoint position, Gfx::FloatPoint delta, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, u32 modifiers, MonotonicTime now, Optional<Web::UniqueNodeID> expected_document_id, Compositing::WheelStepDispatch);Gfx::IntRect note_async_scrolling_viewport_rect(Gfx::IntRect viewport_rect, Optional<Compositing::AsyncScrollOffset> const&);Optional<Compositing::AsyncScrollOperationID> snap_at_gesture_end(MonotonicTime now);Compositing::AsyncScrollOperationID start_snap_scroll(Compositing::AsyncScrollNodeID, ScrollSnapController::SnapScrollStart&&, bool settles_gesture, MonotonicTime now);diff --git a/Services/Compositor/WheelGestureRouting.cpp b/Services/Compositor/WheelGestureRouting.cppindex 9a64412a224..d30860446bb 100644--- a/Services/Compositor/WheelGestureRouting.cpp+++ b/Services/Compositor/WheelGestureRouting.cpp@@ -107,6 +107,13 @@ Optional<Compositing::AsyncScrollNodeID> WheelGestureRouting::resolve_latch(Compreturn node_id;}+Optional<Web::AsyncScrollNodeStableID> WheelGestureRouting::latched_scroller() const+{+ if (!m_latch.has_value())+ return {};+ return m_latch->stable_node_id;+}+void WheelGestureRouting::latch(Web::AsyncScrollNodeStableID stable_node_id, Gfx::FloatPoint position, Web::ScrollGesturePhase scroll_gesture_phase, u32 modifiers, MonotonicTime now){m_latch = Latch {diff --git a/Services/Compositor/WheelGestureRouting.h b/Services/Compositor/WheelGestureRouting.hindex 99a907612d5..f057bef1c12 100644--- a/Services/Compositor/WheelGestureRouting.h+++ b/Services/Compositor/WheelGestureRouting.h@@ -38,6 +38,7 @@ public:bool step_was_overtaken_by_ui(Web::ScrollGesturePhase, u64 input_event_id) const;bool has_latch() const { return m_latch.has_value(); }+ Optional<Web::AsyncScrollNodeStableID> latched_scroller() const;// The latched scroller of the gesture the wheel event continues, in the current scroll tree, with the gesture// advanced to the event. A latch the event does not continue, or whose scroller the current display list no// longer has, is dropped here.