Truly independent web browser
Compositor+LibWeb: Scroll by wheel events only in the compositor
Aliaksandr Kalenikb35f65ba71c9
diff --git a/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cpp b/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cppindex d995042cc14..65d6f5f0c84 100644--- a/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cpp+++ b/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cpp@@ -497,6 +497,27 @@ Optional<NestedContextHit> AsyncScrollTree::position_in_content_of_nested_contexreturn {};}+Optional<Gfx::FloatPoint> AsyncScrollTree::position_of_nested_context_position(Web::CompositorContextId child_context_id, Gfx::FloatPoint position_in_nested_context, Gfx::FloatSize nested_context_viewport_size, Compositing::AccumulatedVisualContextTree const& visual_context_tree) const+{+ if (m_visual_context_tree_structural_epoch != visual_context_tree.structural_epoch() || nested_context_viewport_size.is_empty())+ return {};+ for (auto const& cached_region : m_cached_nested_context_wheel_regions.in_reverse()) {+ auto const& region = cached_region.region;+ if (region.child_context_id != child_context_id)+ continue;+ if (!visual_context_tree.context_is_valid(region.context))+ return {};+ // The content box of a nested context is drawn scaled to the size of its viewport.+ Gfx::FloatPoint position_in_content_box {+ position_in_nested_context.x() * region.rect.width() / nested_context_viewport_size.width(),+ position_in_nested_context.y() * region.rect.height() / nested_context_viewport_size.height(),+ };+ Gfx::FloatRect point_in_context { region.rect.location() + position_in_content_box, {} };+ return visual_context_tree.transform_rect_to_viewport(region.context.spatial, point_in_context, m_scroll_state_snapshot).location();+ }+ return {};+}+WheelHitTestResult AsyncScrollTree::hit_test_scroll_node_for_wheel(Compositing::AccumulatedVisualContextTree const& visual_context_tree, Gfx::FloatPoint position, Gfx::FloatPoint delta, Function<Optional<Gfx::FloatPoint>(Web::AsyncScrollNodeStableID)> const& in_flight_destination_for, WheelStepDispatch wheel_step_dispatch, NestedContextRegions nested_context_regions) const{if (m_visual_context_tree_structural_epoch != visual_context_tree.structural_epoch())@@ -506,16 +527,17 @@ WheelHitTestResult AsyncScrollTree::hit_test_scroll_node_for_wheel(Compositing::return visual_context_tree.context_is_valid(context);};- bool blocking_wheel_event_listeners_hold_the_step_back = wheel_step_dispatch == WheelStepDispatch::NotYetDispatched;- if (blocking_wheel_event_listeners_hold_the_step_back && m_has_blocking_wheel_event_region_covering_viewport)+ // Neither the listeners nor the main thread have anything left to say about a step the page let through.+ bool page_has_yet_to_see_the_step = wheel_step_dispatch == WheelStepDispatch::NotYetDispatched;+ if (page_has_yet_to_see_the_step && m_has_blocking_wheel_event_region_covering_viewport)return { .outcome = WheelHitTestOutcome::BlockedByWheelEventRegion };- if (main_thread_wheel_event_region_contains(visual_context_tree, position))+ if (page_has_yet_to_see_the_step && main_thread_wheel_event_region_contains(visual_context_tree, position))return { .outcome = WheelHitTestOutcome::BlockedByMainThreadRegion };if (nested_context_regions == NestedContextRegions::LeaveToMainThread && topmost_nested_context_wheel_region_at(visual_context_tree, position).has_value())return { .outcome = WheelHitTestOutcome::BlockedByMainThreadRegion };- if (blocking_wheel_event_listeners_hold_the_step_back && blocks_wheel_event_at_position(visual_context_tree, position))+ if (page_has_yet_to_see_the_step && blocks_wheel_event_at_position(visual_context_tree, position))return { .outcome = WheelHitTestOutcome::BlockedByWheelEventRegion };for (auto const& target : m_cached_wheel_hit_test_targets.in_reverse()) {diff --git a/Libraries/LibCompositing/Scrolling/AsyncScrollTree.h b/Libraries/LibCompositing/Scrolling/AsyncScrollTree.hindex bba47785fd5..6741761fd25 100644--- a/Libraries/LibCompositing/Scrolling/AsyncScrollTree.h+++ b/Libraries/LibCompositing/Scrolling/AsyncScrollTree.h@@ -47,8 +47,8 @@ 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.+// A first step of a wheel gesture is latched to the scroller the hit test found, and is otherwise left to the page for+// the outcome's reason.COMPOSITING_API Web::InputRoutingDecision input_routing_decision_for_first_wheel_step(WheelHitTestOutcome);// Where the first step of a wheel gesture over a position goes, as far as the admission and the hit test decide it.@@ -65,7 +65,7 @@ struct FirstWheelStepRouteForTesting {// What the wheel hit test does where a nested context's content is painted.enum class NestedContextRegions : u8 {- // The step is left to the main thread, which hands it to the nested navigable.+ // The step is left to the page, which hands it to the nested navigable.LeaveToMainThread,// The step is handed to the nested context under it, which only gets here if there is none.HandToNestedContext,@@ -153,6 +153,8 @@ public:// Where the position lands in the content of the nested context, even outside of that content and its clips, as// the pointer of a drag that began in there moves on.Optional<NestedContextHit> position_in_content_of_nested_context(Web::CompositorContextId, Compositing::AccumulatedVisualContextTree const&, Gfx::FloatPoint position) const;+ // Where a position in the viewport of the nested context lies in this context's viewport.+ Optional<Gfx::FloatPoint> position_of_nested_context_position(Web::CompositorContextId, Gfx::FloatPoint position_in_nested_context, Gfx::FloatSize nested_context_viewport_size, Compositing::AccumulatedVisualContextTree const&) const;bool has_nested_contexts() const { return !m_nested_context_wheel_regions.is_empty(); }bool has_wheel_hit_test_targets_for(Compositing::AccumulatedVisualContextTree const& visual_context_tree) const { return m_visual_context_tree_structural_epoch == visual_context_tree.structural_epoch(); }// Whether something painted above the given place in paint order takes pointer input at the position. It is taken@@ -168,6 +170,9 @@ public:// Of the scroller and the scrollers around it that a scroll by the delta may be passed on to, the outermost one a// wheel can scroll along the main axis of the delta at all, wherever it is scrolled to.Optional<Compositing::SpatialNodeIndex> outermost_scroll_node_wheel_scrollable_along_main_axis_of(Compositing::SpatialNodeIndex innermost_scroll_node_index, Gfx::FloatPoint delta) const;+ // The scroller, of the given one and those it passes a scroll by the delta on to, that takes a wheel step by it, as+ // the hit test finds one for a step over the given scroller.+ WheelHitTestResult hit_test_result_for_scroll_node(Compositing::SpatialNodeIndex, Gfx::FloatPoint delta, Function<Optional<Gfx::FloatPoint>(Web::AsyncScrollNodeStableID)> const& in_flight_destination_for) const;Optional<Compositing::SpatialNodeIndex> scroll_node_for_keyboard_scroll(Web::AsyncScrollNodeStableID, Gfx::FloatPoint delta, Compositing::ScrollStateSnapshot const&) const;Gfx::FloatPoint clamped_scroll_offset_for_node(Compositing::SpatialNodeIndex, Gfx::FloatPoint) const;Optional<AsyncScrollOffset> apply_scroll_delta(Compositing::SpatialNodeIndex, Gfx::FloatPoint delta, Compositing::AccumulatedVisualContextTree const&, Compositing::ScrollStateSnapshot&, ScrollChaining);@@ -180,7 +185,6 @@ private:static bool can_scroll_node_by_delta(AsyncScrollNode const&, Compositing::ScrollStateSnapshot const&, Gfx::FloatPoint);static bool can_scroll_node_from_offset_by_delta(AsyncScrollNode const&, Gfx::FloatPoint scroll_offset, Gfx::FloatPoint delta);- WheelHitTestResult hit_test_result_for_scroll_node(Compositing::SpatialNodeIndex, Gfx::FloatPoint delta, Function<Optional<Gfx::FloatPoint>(Web::AsyncScrollNodeStableID)> const& in_flight_destination_for) const;AsyncScrollNode const* scroll_node_for_stable_id(Web::AsyncScrollNodeStableID) const;bool main_thread_wheel_event_region_contains(Compositing::AccumulatedVisualContextTree const&, Gfx::FloatPoint position) const;struct NestedContextWheelRegionHit {diff --git a/Libraries/LibCompositing/Scrolling/AsyncScrollingState.h b/Libraries/LibCompositing/Scrolling/AsyncScrollingState.hindex 406b7be9c73..015ab333381 100644--- a/Libraries/LibCompositing/Scrolling/AsyncScrollingState.h+++ b/Libraries/LibCompositing/Scrolling/AsyncScrollingState.h@@ -182,7 +182,8 @@ COMPOSITING_API WheelRoutingAdmission wheel_routing_admission_for(AsyncScrolling// The admission of a scrolling state recorded before the newest change to the page's blocking wheel event listeners is// stale, as the state may not have the regions that change made.COMPOSITING_API WheelRoutingAdmission wheel_routing_admission_for(AsyncScrollingState const&, u64 newest_wheel_event_listener_state_generation);-// Why a wheel step that the admission does not let the compositor scroll is left to the main thread.+// Why a wheel step that the admission does not let the compositor scroll before the page dispatches it is left to the+// page.COMPOSITING_API Web::InputRoutingDecision input_routing_decision_for_wheel_step_not_admitted_by(WheelRoutingAdmission);}diff --git a/Libraries/LibCompositing/Types.cpp b/Libraries/LibCompositing/Types.cppindex 4fea0138d70..c1b8af8ad5c 100644--- a/Libraries/LibCompositing/Types.cpp+++ b/Libraries/LibCompositing/Types.cpp@@ -267,27 +267,6 @@ ErrorOr<Compositing::ScrollRequest> decode(Decoder& decoder)};}-template<>-ErrorOr<void> encode(Encoder& encoder, Compositing::AsyncScrollEnqueueResult const& result)-{- TRY(encoder.encode(result.accepted));- TRY(encoder.encode(result.operation_id));- TRY(encoder.encode(result.routing_decision));- TRY(encoder.encode(result.routed_scroller));- return {};-}--template<>-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>>()),- };-}-template<>ErrorOr<void> encode(Encoder& encoder, Compositing::WheelEventAnswer const& answer){@@ -313,4 +292,33 @@ ErrorOr<Compositing::WheelEventAnswer> decode(Decoder& decoder)};}+template<>+ErrorOr<void> encode(Encoder& encoder, Compositing::WheelStepLetThrough const& step)+{+ TRY(encoder.encode(step.document_id));+ TRY(encoder.encode(step.input_event_id));+ TRY(encoder.encode(step.wheel_gesture_mark));+ TRY(encoder.encode(step.position));+ TRY(encoder.encode(step.delta_in_css_pixels));+ TRY(encoder.encode(step.wheel_delta_precision));+ TRY(encoder.encode(step.scroll_gesture_phase));+ TRY(encoder.encode(step.scroll_chain));+ return {};+}++template<>+ErrorOr<Compositing::WheelStepLetThrough> decode(Decoder& decoder)+{+ return Compositing::WheelStepLetThrough {+ .document_id = TRY(decoder.decode<Web::UniqueNodeID>()),+ .input_event_id = TRY(decoder.decode<u64>()),+ .wheel_gesture_mark = TRY(decoder.decode<Web::WheelGestureMark>()),+ .position = TRY(decoder.decode<Gfx::FloatPoint>()),+ .delta_in_css_pixels = TRY(decoder.decode<Gfx::FloatPoint>()),+ .wheel_delta_precision = TRY(decoder.decode<Web::WheelDeltaPrecision>()),+ .scroll_gesture_phase = TRY(decoder.decode<Web::ScrollGesturePhase>()),+ .scroll_chain = TRY(decoder.decode<Vector<Web::AsyncScrollNodeStableID>>()),+ };+}+}diff --git a/Libraries/LibCompositing/Types.h b/Libraries/LibCompositing/Types.hindex d23a4312d6a..f8fe2740d49 100644--- a/Libraries/LibCompositing/Types.h+++ b/Libraries/LibCompositing/Types.h@@ -128,11 +128,28 @@ enum class AsyncScrollOperationTracking {Yes,};-// Who scrolls by a wheel event that WebContent's main thread passes on to the compositor, which names the gesture of-// the event either way.-enum class WheelEventScrolling : u8 {- ByCompositor,- ByMainThread,+// When the compositor routes a wheel event that WebContent's main thread passes on to it, which it names the gesture of+// either way: before the page dispatches the event, as it routes the UI's wheel events, or only once the page lets the+// event through with the scrollers around its target. The main thread asks for the latter while the compositor's+// display list misses changes to the scrollers.+enum class WheelEventRouting : u8 {+ BeforeDispatch,+ AfterDispatch,+};++// A step of a wheel gesture that WebContent's page dispatched and did not cancel, which the compositor scrolls by.+struct WheelStepLetThrough {+ Web::UniqueNodeID document_id;+ u64 input_event_id { 0 };+ Web::WheelGestureMark wheel_gesture_mark;+ // In the device pixels of the viewport of the context the step is let through in.+ Gfx::FloatPoint position;+ // In CSS pixels, with the axes already swapped for Shift.+ Gfx::FloatPoint delta_in_css_pixels;+ Web::WheelDeltaPrecision wheel_delta_precision { Web::WheelDeltaPrecision::Discrete };+ Web::ScrollGesturePhase scroll_gesture_phase { Web::ScrollGesturePhase::None };+ // The scroll containers around the target of the step, innermost first, ending at the viewport.+ Vector<Web::AsyncScrollNodeStableID> scroll_chain;};// Blocking wheel event listeners hold a wheel step back from the compositor until the page has dispatched it. A step@@ -321,13 +338,13 @@ template<>COMPOSITING_API ErrorOr<Compositing::ScrollRequest> decode(Decoder&);template<>-COMPOSITING_API ErrorOr<void> encode(Encoder&, Compositing::AsyncScrollEnqueueResult const&);+COMPOSITING_API ErrorOr<void> encode(Encoder&, Compositing::WheelEventAnswer const&);template<>-COMPOSITING_API ErrorOr<Compositing::AsyncScrollEnqueueResult> decode(Decoder&);+COMPOSITING_API ErrorOr<Compositing::WheelEventAnswer> decode(Decoder&);template<>-COMPOSITING_API ErrorOr<void> encode(Encoder&, Compositing::WheelEventAnswer const&);+COMPOSITING_API ErrorOr<void> encode(Encoder&, Compositing::WheelStepLetThrough const&);template<>-COMPOSITING_API ErrorOr<Compositing::WheelEventAnswer> decode(Decoder&);+COMPOSITING_API ErrorOr<Compositing::WheelStepLetThrough> decode(Decoder&);}diff --git a/Libraries/LibWeb/Compositor/CompositorConnection.cpp b/Libraries/LibWeb/Compositor/CompositorConnection.cppindex 93a9cfa79f8..35bba25d5b9 100644--- a/Libraries/LibWeb/Compositor/CompositorConnection.cpp+++ b/Libraries/LibWeb/Compositor/CompositorConnection.cpp@@ -486,12 +486,12 @@ void CompositorConnection::invalidate_wheel_event_listener_state(Web::Compositorasync_invalidate_wheel_event_listener_state(context_id, generation);}-Compositing::WheelEventAnswer CompositorConnection::take_wheel_event_from_main_thread(Web::CompositorContextId context_id, Web::MouseEvent const& event, Compositing::AsyncScrollOperationTracking operation_tracking, Compositing::WheelEventScrolling scrolling)+Compositing::WheelEventAnswer CompositorConnection::take_wheel_event_from_main_thread(Web::CompositorContextId context_id, Web::MouseEvent const& event, Compositing::AsyncScrollOperationTracking operation_tracking, Compositing::WheelEventRouting routing){if (!can_send_message_to_compositor())return {};- auto response = send_sync_but_allow_failure<Messages::CompositorWebContentServer::TakeWheelEventFromMainThread>(context_id, event.clone_without_browser_data(), operation_tracking, scrolling);+ auto response = send_sync_but_allow_failure<Messages::CompositorWebContentServer::TakeWheelEventFromMainThread>(context_id, event.clone_without_browser_data(), operation_tracking, routing);if (!response) {did_lose_compositor();return {};@@ -499,17 +499,24 @@ Compositing::WheelEventAnswer CompositorConnection::take_wheel_event_from_main_treturn response->take_answer();}-Compositing::AsyncScrollEnqueueResult CompositorConnection::async_scroll_by(Web::CompositorContextId context_id, Web::UniqueNodeID document_id, Gfx::FloatPoint position, Gfx::FloatPoint delta, Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, Compositing::AsyncScrollOperationTracking operation_tracking, Compositing::WheelStepDispatch wheel_step_dispatch, Optional<u64> wheel_gesture_id, u64 input_event_id)+Compositing::WheelEventAnswer CompositorConnection::wheel_event_let_through(Web::CompositorContextId context_id, Compositing::WheelStepLetThrough const& step, Compositing::AsyncScrollOperationTracking operation_tracking){if (!can_send_message_to_compositor())return {};- auto response = send_sync_but_allow_failure<Messages::CompositorWebContentServer::AsyncScrollBy>(context_id, document_id, position, delta, viewport_rect, wheel_delta_precision, scroll_gesture_phase, operation_tracking, wheel_step_dispatch, wheel_gesture_id, input_event_id);+ auto response = send_sync_but_allow_failure<Messages::CompositorWebContentServer::WheelEventLetThrough>(context_id, step, operation_tracking);if (!response) {did_lose_compositor();return {};}- return response->take_result();+ return response->take_answer();+}++void CompositorConnection::wheel_event_canceled(Web::CompositorContextId context_id, u64 wheel_gesture_id)+{+ if (!can_send_message_to_compositor())+ return;+ async_wheel_event_canceled(context_id, wheel_gesture_id);}String CompositorConnection::scroll_state_for_testing(Web::CompositorContextId context_id, Web::AsyncScrollNodeStableID stretched_scroller)diff --git a/Libraries/LibWeb/Compositor/CompositorConnection.h b/Libraries/LibWeb/Compositor/CompositorConnection.hindex e0426e55253..6c8b5f88cc9 100644--- a/Libraries/LibWeb/Compositor/CompositorConnection.h+++ b/Libraries/LibWeb/Compositor/CompositorConnection.h@@ -66,8 +66,9 @@ public:bool rasterize_display_list(Compositing::DisplayList const&, Compositing::AccumulatedVisualContextTree const&, Compositing::DisplayListResourceTransaction, NonnullRefPtr<Gfx::Bitmap> target);void invalidate_wheel_event_listener_state(Web::CompositorContextId, u64 generation);void invalidate_keyboard_scroll_state(Web::CompositorContextId, u64 generation);- Compositing::WheelEventAnswer take_wheel_event_from_main_thread(Web::CompositorContextId, Web::MouseEvent const&, Compositing::AsyncScrollOperationTracking, Compositing::WheelEventScrolling);- Compositing::AsyncScrollEnqueueResult async_scroll_by(Web::CompositorContextId, Web::UniqueNodeID document_id, Gfx::FloatPoint position, Gfx::FloatPoint delta, Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, Compositing::AsyncScrollOperationTracking, Compositing::WheelStepDispatch, Optional<u64> wheel_gesture_id, u64 input_event_id);+ Compositing::WheelEventAnswer take_wheel_event_from_main_thread(Web::CompositorContextId, Web::MouseEvent const&, Compositing::AsyncScrollOperationTracking, Compositing::WheelEventRouting);+ Compositing::WheelEventAnswer wheel_event_let_through(Web::CompositorContextId, Compositing::WheelStepLetThrough const&, Compositing::AsyncScrollOperationTracking);+ void wheel_event_canceled(Web::CompositorContextId, u64 wheel_gesture_id);String scroll_state_for_testing(Web::CompositorContextId, Web::AsyncScrollNodeStableID stretched_scroller);void synchronize_for_testing();Optional<Compositing::FirstWheelStepRouteForTesting> route_first_wheel_step_for_testing(Web::CompositorContextId, Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels);diff --git a/Libraries/LibWeb/Compositor/CompositorHost.cpp b/Libraries/LibWeb/Compositor/CompositorHost.cppindex 6bf3a2b5b78..f6584f4f58f 100644--- a/Libraries/LibWeb/Compositor/CompositorHost.cpp+++ b/Libraries/LibWeb/Compositor/CompositorHost.cpp@@ -61,15 +61,19 @@ void CompositorContextHandle::invalidate_wheel_event_listener_state(u64 generatim_host.invalidate_wheel_event_listener_state(m_context_id, generation);}-Compositing::WheelEventAnswer CompositorContextHandle::take_wheel_event_from_main_thread(Web::MouseEvent const& event, Compositing::AsyncScrollOperationTracking operation_tracking, Compositing::WheelEventScrolling scrolling)+Compositing::WheelEventAnswer CompositorContextHandle::take_wheel_event_from_main_thread(Web::MouseEvent const& event, Compositing::AsyncScrollOperationTracking operation_tracking, Compositing::WheelEventRouting routing){- return m_host.take_wheel_event_from_main_thread(m_context_id, event, operation_tracking, scrolling);+ return m_host.take_wheel_event_from_main_thread(m_context_id, event, operation_tracking, routing);}-Compositing::AsyncScrollEnqueueResult CompositorContextHandle::async_scroll_by(UniqueNodeID expected_document_id, Gfx::FloatPoint position,- Gfx::FloatPoint delta_in_device_pixels, Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, Compositing::AsyncScrollOperationTracking operation_tracking, Compositing::WheelStepDispatch wheel_step_dispatch, Optional<u64> wheel_gesture_id, u64 input_event_id)+Compositing::WheelEventAnswer CompositorContextHandle::wheel_event_let_through(Compositing::WheelStepLetThrough const& step, Compositing::AsyncScrollOperationTracking operation_tracking){- return m_host.async_scroll_by(m_context_id, expected_document_id, position, delta_in_device_pixels, viewport_rect, wheel_delta_precision, scroll_gesture_phase, operation_tracking, wheel_step_dispatch, wheel_gesture_id, input_event_id);+ return m_host.wheel_event_let_through(m_context_id, step, operation_tracking);+}++void CompositorContextHandle::wheel_event_canceled(u64 wheel_gesture_id)+{+ m_host.wheel_event_canceled(m_context_id, wheel_gesture_id);}String CompositorContextHandle::scroll_state_for_testing(Web::AsyncScrollNodeStableID stretched_scroller)@@ -467,21 +471,26 @@ void CompositorHost::invalidate_wheel_event_listener_state(Web::CompositorContexconnection->invalidate_wheel_event_listener_state(context_id, generation);}-Compositing::WheelEventAnswer CompositorHost::take_wheel_event_from_main_thread(Web::CompositorContextId context_id, Web::MouseEvent const& event, Compositing::AsyncScrollOperationTracking operation_tracking, Compositing::WheelEventScrolling scrolling)+Compositing::WheelEventAnswer CompositorHost::take_wheel_event_from_main_thread(Web::CompositorContextId context_id, Web::MouseEvent const& event, Compositing::AsyncScrollOperationTracking operation_tracking, Compositing::WheelEventRouting routing){if (auto* connection = compositor_connection())- return connection->take_wheel_event_from_main_thread(context_id, event, operation_tracking, scrolling);+ return connection->take_wheel_event_from_main_thread(context_id, event, operation_tracking, routing);return {};}-Compositing::AsyncScrollEnqueueResult CompositorHost::async_scroll_by(Web::CompositorContextId context_id, Web::UniqueNodeID expected_document_id, Gfx::FloatPoint position,- Gfx::FloatPoint delta_in_device_pixels, Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, Compositing::AsyncScrollOperationTracking operation_tracking, Compositing::WheelStepDispatch wheel_step_dispatch, Optional<u64> wheel_gesture_id, u64 input_event_id)+Compositing::WheelEventAnswer CompositorHost::wheel_event_let_through(Web::CompositorContextId context_id, Compositing::WheelStepLetThrough const& step, Compositing::AsyncScrollOperationTracking operation_tracking){if (auto* connection = compositor_connection())- return connection->async_scroll_by(context_id, expected_document_id, position, delta_in_device_pixels, viewport_rect, wheel_delta_precision, scroll_gesture_phase, operation_tracking, wheel_step_dispatch, wheel_gesture_id, input_event_id);+ return connection->wheel_event_let_through(context_id, step, operation_tracking);return {};}+void CompositorHost::wheel_event_canceled(Web::CompositorContextId context_id, u64 wheel_gesture_id)+{+ if (auto* connection = compositor_connection())+ connection->wheel_event_canceled(context_id, wheel_gesture_id);+}+String CompositorHost::scroll_state_for_testing(Web::CompositorContextId context_id, Web::AsyncScrollNodeStableID stretched_scroller){if (auto* connection = compositor_connection())diff --git a/Libraries/LibWeb/Compositor/CompositorHost.h b/Libraries/LibWeb/Compositor/CompositorHost.hindex 943dd1be8ec..78fd63cc705 100644--- a/Libraries/LibWeb/Compositor/CompositorHost.h+++ b/Libraries/LibWeb/Compositor/CompositorHost.h@@ -65,9 +65,9 @@ public:void set_video_sink_ticking(Media::VideoSinkHandle, bool should_tick);void invalidate_wheel_event_listener_state(u64 generation);void invalidate_keyboard_scroll_state(u64 generation);- Compositing::WheelEventAnswer take_wheel_event_from_main_thread(Web::MouseEvent const&, Compositing::AsyncScrollOperationTracking, Compositing::WheelEventScrolling);- Compositing::AsyncScrollEnqueueResult async_scroll_by(UniqueNodeID expected_document_id, Gfx::FloatPoint position, Gfx::FloatPoint delta_in_device_pixels,- Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, Compositing::AsyncScrollOperationTracking, Compositing::WheelStepDispatch, Optional<u64> wheel_gesture_id, u64 input_event_id);+ Compositing::WheelEventAnswer take_wheel_event_from_main_thread(Web::MouseEvent const&, Compositing::AsyncScrollOperationTracking, Compositing::WheelEventRouting);+ Compositing::WheelEventAnswer wheel_event_let_through(Compositing::WheelStepLetThrough const&, Compositing::AsyncScrollOperationTracking);+ void wheel_event_canceled(u64 wheel_gesture_id);String scroll_state_for_testing(Web::AsyncScrollNodeStableID stretched_scroller);void synchronize_for_testing();Optional<Compositing::FirstWheelStepRouteForTesting> route_first_wheel_step_for_testing(Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels);@@ -128,9 +128,9 @@ public:Compositing::VideoFrameHold::ReleaseThroughCompositor video_frame_hold_releaser_for_current_connection() const;void invalidate_wheel_event_listener_state(Web::CompositorContextId, u64 generation);void invalidate_keyboard_scroll_state(Web::CompositorContextId, u64 generation);- Compositing::WheelEventAnswer take_wheel_event_from_main_thread(Web::CompositorContextId, Web::MouseEvent const&, Compositing::AsyncScrollOperationTracking, Compositing::WheelEventScrolling);- Compositing::AsyncScrollEnqueueResult async_scroll_by(Web::CompositorContextId, UniqueNodeID expected_document_id, Gfx::FloatPoint position,- Gfx::FloatPoint delta_in_device_pixels, Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, Compositing::AsyncScrollOperationTracking, Compositing::WheelStepDispatch, Optional<u64> wheel_gesture_id, u64 input_event_id);+ Compositing::WheelEventAnswer take_wheel_event_from_main_thread(Web::CompositorContextId, Web::MouseEvent const&, Compositing::AsyncScrollOperationTracking, Compositing::WheelEventRouting);+ Compositing::WheelEventAnswer wheel_event_let_through(Web::CompositorContextId, Compositing::WheelStepLetThrough const&, Compositing::AsyncScrollOperationTracking);+ void wheel_event_canceled(Web::CompositorContextId, u64 wheel_gesture_id);String scroll_state_for_testing(Web::CompositorContextId, Web::AsyncScrollNodeStableID stretched_scroller);void synchronize_for_testing();Optional<Compositing::FirstWheelStepRouteForTesting> route_first_wheel_step_for_testing(Web::CompositorContextId, Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels);diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cppindex ce0d80dc0cb..76461cb007c 100644--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp@@ -4900,10 +4900,25 @@ void LocalNavigable::wait_for_async_scroll_operation(Compositing::AsyncScrollOpereturn;}+ if (auto ended = m_async_scroll_operations_with_expected_wait.take(operation_id); ended.has_value() && *ended) {+ queue_async_scroll_operation_promise_resolution(promise);+ return;+ }+// The compositor may have reported the scroll it started for this operation already, which registered it here.ensure_pending_async_scroll_operation(operation_id).promises.append(promise);}+void LocalNavigable::expect_wait_for_async_scroll_operation(Compositing::AsyncScrollOperationID operation_id)+{+ m_async_scroll_operations_with_expected_wait.set(operation_id, false);+}++void LocalNavigable::forget_expected_wait_for_async_scroll_operation(Compositing::AsyncScrollOperationID operation_id)+{+ m_async_scroll_operations_with_expected_wait.remove(operation_id);+}+void LocalNavigable::wait_for_wheel_scrolls(Vector<GC::Ref<WebIDL::Promise>>& promises){auto document = active_document();@@ -4927,6 +4942,9 @@ void LocalNavigable::wait_for_wheel_scrolls(Vector<GC::Ref<WebIDL::Promise>>& prvoid LocalNavigable::resolve_async_scroll_operation(Compositing::AsyncScrollOperationID operation_id){+ if (m_async_scroll_operations_with_expected_wait.contains(operation_id))+ m_async_scroll_operations_with_expected_wait.set(operation_id, true);+// Notifying a scroll's completion can start the next scroll of the same scrolling box, so the finished scroll// leaves the list of scrolls in progress before it is reported.Optional<FinishedScroll> finished;@@ -5244,10 +5262,8 @@ void LocalNavigable::extend_user_scroll_gesture_of(Web::AsyncScrollNodeStableIDschedule_end_of_user_scroll_gesture_input();}-void LocalNavigable::extend_wheel_user_scroll_gesture(Optional<Web::AsyncScrollNodeStableID> box_latched_on_this_thread)+void LocalNavigable::extend_wheel_user_scroll_gesture(){- if (box_latched_on_this_thread.has_value())- extend_user_scroll_gesture_of(box_latched_on_this_thread.value());if (m_compositor_wheel_latched_scroller.has_value())extend_user_scroll_gesture_of(m_compositor_wheel_latched_scroller.value());if (m_wheel_user_scroll_gesture_hold) {@@ -5256,12 +5272,6 @@ void LocalNavigable::extend_wheel_user_scroll_gesture(Optional<Web::AsyncScrollN}}-void LocalNavigable::note_wheel_user_scroll_gesture_scrolls(Web::AsyncScrollNodeStableID stable_node_id)-{- if (m_wheel_user_scroll_gesture_hold)- m_wheel_user_scroll_gesture_hold->hold(stable_node_id);-}-TemporaryChange<UserScrollGestureHold*> LocalNavigable::hold_boxes_user_input_scrolls_with(UserScrollGestureHold& hold){return TemporaryChange<UserScrollGestureHold*> { m_user_scroll_gesture_hold_of_current_input, &hold };diff --git a/Libraries/LibWeb/HTML/LocalNavigable.h b/Libraries/LibWeb/HTML/LocalNavigable.hindex ada126c9399..cf8b42d5446 100644--- a/Libraries/LibWeb/HTML/LocalNavigable.h+++ b/Libraries/LibWeb/HTML/LocalNavigable.h@@ -258,6 +258,10 @@ public:void adopt_started_user_scroll(DOM::Document&, Compositing::StartedUserScroll const&);void process_main_thread_smooth_scrolls();void wait_for_async_scroll_operation(Compositing::AsyncScrollOperationID, GC::Ref<WebIDL::Promise>);+ // The input that started the operation is still being handled, and whoever handed it in waits for the operation+ // once it is. An operation that ends before then is remembered until the wait begins.+ void expect_wait_for_async_scroll_operation(Compositing::AsyncScrollOperationID);+ void forget_expected_wait_for_async_scroll_operation(Compositing::AsyncScrollOperationID);void wait_for_wheel_scrolls(Vector<GC::Ref<WebIDL::Promise>>&);void clamp_viewport_scroll_offset();@@ -430,9 +434,8 @@ public:void note_user_scroll_gesture_phase(Web::ScrollGesturePhase);// A gesture that lasts until its fingers lift is held until their lift arrives, not until its events pause.void did_handle_wheel_event(bool gesture_lasts_until_fingers_lift);- void note_wheel_user_scroll_gesture_scrolls(Web::AsyncScrollNodeStableID);void extend_user_scroll_gesture_of(Web::AsyncScrollNodeStableID);- void extend_wheel_user_scroll_gesture(Optional<Web::AsyncScrollNodeStableID> box_latched_on_this_thread);+ void extend_wheel_user_scroll_gesture();void snap_user_scroll_gestures_that_awaited_layout();void end_scroll_sequences_that_completed_since_the_last_frame();// The boxes that user input scrolls on this thread while the returned change is alive are held by the hold.@@ -707,6 +710,8 @@ private:Compositing::ScrollAnimationKind animation_kind { Compositing::ScrollAnimationKind::SmoothScroll };};Vector<PendingAsyncScrollOperation> m_pending_async_scroll_operations;+ // The operations whose wait is expected to begin, and whether each has ended already.+ HashMap<Compositing::AsyncScrollOperationID, bool> m_async_scroll_operations_with_expected_wait;// A script's instant scroll, which ends once the compositor answers its request with where the box went.struct InstantScrollAwaitingAnswer {Web::AsyncScrollNodeStableID stable_node_id;diff --git a/Libraries/LibWeb/Internals/Internals.cpp b/Libraries/LibWeb/Internals/Internals.cppindex 25d27dccff7..cec5101a999 100644--- a/Libraries/LibWeb/Internals/Internals.cpp+++ b/Libraries/LibWeb/Internals/Internals.cpp@@ -953,6 +953,11 @@ void Internals::click_and_hold(double x, double y, WebIDL::UnsignedShort click_cvoid Internals::wheel(GC::Ref<WebIDL::Promise> promise, double x, double y, double delta_x, double delta_y, bool precise, Bindings::ScrollGesturePhase phase, Bindings::WheelTicks const& ticks){auto& page = this->page();+ // The compositor scrolls by the event from the frames it has. Like a user's, the event comes once the page has+ // presented what changed in it.+ for (auto& navigable : page.local_traversable()->hosted_inclusive_descendant_navigables())+ navigable->paint_next_frame_if_needed(DOM::UpdateLayoutReason::EventHandlerHandleMouseWheel);+ let_compositor_take_in_every_rendered_frame(window());auto wheel_delta_precision = wheel_delta_precision_from(precise);auto scroll_gesture_phase = scroll_gesture_phase_from(phase);diff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cppindex 571bd9cff9b..1c976b92af2 100644--- a/Libraries/LibWeb/Page/EventHandler.cpp+++ b/Libraries/LibWeb/Page/EventHandler.cpp@@ -902,19 +902,6 @@ static VisualViewportPanAxes visual_viewport_pan_axes_for_scroll_step(DOM::Docum};}-static Layout::Node* scrolling_box_for_scroll_step(Layout::Node& target, CSSPixelPoint delta)-{- auto const& read = target.held_read();- auto* scrolling_box = Painting::scrolling_box_for_scroll_step_in_containing_block_chain(read, target, delta);- if (!scrolling_box)- return nullptr;-- // The viewport is scrolled by the default action itself rather than by the chain above, so it comes last.- if (scrolling_box->is_viewport() && !visual_viewport_pan_axes_for_scroll_step(target.document(), delta.x().to_double(), delta.y().to_double()).is_empty())- return nullptr;- return scrolling_box;-}-// Each box is measured from where its user scroll of the given kind in flight is headed, as the step that continues// that scroll measures it, so a box already headed for its extent passes the step on to an ancestor. No box around// `box_ending_scroll_chain` is offered the step.@@ -967,6 +954,20 @@ void EventHandler::record_input_routing(InputRoutingDecision decision, Optional<});}+// The scroll containers around the box, innermost first, ending at the viewport.+static Vector<Web::AsyncScrollNodeStableID> wheel_scroll_chain_from(Layout::Node& node)+{+ Vector<Web::AsyncScrollNodeStableID> scroll_chain;+ for (Layout::Node* box = &node; box; box = box->containing_block()) {+ auto const* box_with_style = as_if<Layout::NodeWithStyle>(*box);+ if (!box->is_viewport() && !(box_with_style && box_with_style->is_scroll_container()))+ continue;+ if (auto stable_node_id = Painting::async_scroll_node_stable_id(*box); stable_node_id.has_value())+ scroll_chain.append(*stable_node_id);+ }+ return scroll_chain;+}+EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_position, CSSPixelPoint screen_position, u32 button, u32 buttons, u32 modifiers, double wheel_delta_x, double wheel_delta_y, double wheel_tick_120ths_x, double wheel_tick_120ths_y, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, bool async_scroll_performed_default_action, Optional<AsyncScrollOperation>* async_scroll_operation, Optional<RemoteInputEventTarget>* remote_target, Optional<Web::WheelGestureMark> wheel_gesture_mark){record_last_known_mouse_position(visual_viewport_position, screen_position, buttons, modifiers);@@ -981,13 +982,25 @@ EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_positireturn EventResult::Dropped;bool wheel_event_has_delta = wheel_delta_x != 0 || wheel_delta_y != 0;- auto can_attempt_async_scroll = m_navigable->has_compositor_context();+ auto has_compositor = m_navigable->has_compositor_context();auto operation_tracking = async_scroll_operation? Compositing::AsyncScrollOperationTracking::Yes: Compositing::AsyncScrollOperationTracking::No;+ auto follow_operation_of = [&](Compositing::WheelEventAnswer const& answer) {+ if (!async_scroll_operation || !answer.operation_id.has_value() || !answer.operation_context_id.has_value())+ return;+ auto navigable = local_navigable_with_compositor_context(m_navigable->page(), *answer.operation_context_id);+ if (!navigable)+ return;+ if (auto const& followed_operation = *async_scroll_operation; followed_operation.has_value() && followed_operation->navigable)+ followed_operation->navigable->forget_expected_wait_for_async_scroll_operation(followed_operation->operation_id);+ // The operation may end, and the navigable adopt its end, before the event is handled.+ navigable->expect_wait_for_async_scroll_operation(*answer.operation_id);+ *async_scroll_operation = AsyncScrollOperation { navigable, *answer.operation_id };+ };// NB: Layout reads can remove scrolling boxes before their updated tree reaches the compositor.- // Only fall back when the presented display list refers to an older tree structure.+ // Only treat the compositor's display list as outdated when it refers to an older tree structure.auto compositor_display_list_is_outdated = [&] {auto local_root = m_navigable->local_root();if (!local_root->needs_to_record_display_list() && !local_root->has_recording_in_flight())@@ -1002,17 +1015,10 @@ EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_positi};// An event that no compositor has seen, such as one a test makes, goes there first, as the UI's events do. The- // compositor names the gesture of the event, and scrolls by it before the page sees it unless this thread keeps- // the scrolling.- bool asked_compositor_first = false;- if (!wheel_gesture_mark.has_value() && can_attempt_async_scroll) {- Optional<InputRoutingDecision> reason_to_scroll_on_this_thread;- if (document->visual_viewport()->scale() != 1.0)- reason_to_scroll_on_this_thread = InputRoutingDecision::AsyncScrollNotAttemptedVisualViewportScaled;- else if (compositor_display_list_is_outdated())- reason_to_scroll_on_this_thread = InputRoutingDecision::AsyncScrollNotAttemptedDisplayListOutdated;- auto scrolling = reason_to_scroll_on_this_thread.has_value() ? Compositing::WheelEventScrolling::ByMainThread : Compositing::WheelEventScrolling::ByCompositor;-+ // compositor names the gesture of the event, and scrolls by it before the page sees it. A compositor whose display+ // list misses scrollers that this thread removed or added only scrolls once the page lets the event through.+ if (!wheel_gesture_mark.has_value() && has_compositor) {+ bool display_list_is_outdated = compositor_display_list_is_outdated();Web::MouseEvent event {.type = Web::MouseEvent::Type::MouseWheel,.position = m_navigable->page().css_to_device_point(visual_viewport_position),@@ -1028,26 +1034,23 @@ EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_positi.scroll_gesture_phase = scroll_gesture_phase,.id = handling_input_event_id(),};- auto answer = m_navigable->compositor_context().take_wheel_event_from_main_thread(event, operation_tracking, scrolling);- if (reason_to_scroll_on_this_thread.has_value())- record_input_routing(*reason_to_scroll_on_this_thread);+ auto routing = display_list_is_outdated ? Compositing::WheelEventRouting::AfterDispatch : Compositing::WheelEventRouting::BeforeDispatch;+ auto answer = m_navigable->compositor_context().take_wheel_event_from_main_thread(event, operation_tracking, routing);+ if (display_list_is_outdated)+ record_input_routing(InputRoutingDecision::CompositorDisplayListOutdated);elserecord_input_routing(answer.routing_decision.value_or(InputRoutingDecision::NoAnswerFromCompositor), answer.routed_scroller, {}, InputTraceStage::CompositorForMainThread);wheel_gesture_mark = answer.wheel_gesture_mark;async_scroll_performed_default_action = answer.performed_default_action;- if (async_scroll_operation && answer.operation_id.has_value() && answer.operation_context_id.has_value()) {- if (auto navigable = local_navigable_with_compositor_context(m_navigable->page(), *answer.operation_context_id))- *async_scroll_operation = AsyncScrollOperation { navigable, *answer.operation_id };- }- asked_compositor_first = true;+ follow_operation_of(answer);}// The compositor names the gesture of each event, which this navigable follows so that the two route the event// alike.auto wheel_gesture_id = wheel_gesture_mark.map([](auto const& mark) { return mark.gesture_id; });- bool continues_latched_gesture = m_wheel_scroll_latch.has_value() && wheel_gesture_id.has_value() && m_wheel_scroll_latch->wheel_gesture_id == wheel_gesture_id;+ bool continues_latched_gesture = m_wheel_event_target_latch.has_value() && wheel_gesture_id.has_value() && m_wheel_event_target_latch->wheel_gesture_id == wheel_gesture_id;if (!continues_latched_gesture)- m_wheel_scroll_latch.clear();+ m_wheel_event_target_latch.clear();bool gesture_lasts_until_fingers_lift = wheel_gesture_mark.has_value() && wheel_gesture_mark->lasts_until_fingers_lift;ScopeGuard measure_next_pause_from_end_of_handling = [this, gesture_lasts_until_fingers_lift] {@@ -1058,49 +1061,20 @@ EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_positi// have moved ahead of any rendering update.m_navigable->adopt_pending_async_scroll_offsets(Compositing::AsyncScrollUpdateFreshness::FromCompositor);- auto visual_viewport = document->visual_viewport();-- // Hands the wheel input to the compositor, which scrolls from the offsets it holds now; the operation it starts- // for the input is the one a caller follows.- auto enqueue_async_scroll = [&](Gfx::FloatPoint delta_in_device_pixels, Compositing::WheelStepDispatch wheel_step_dispatch) {- if (compositor_display_list_is_outdated()) {- record_input_routing(InputRoutingDecision::AsyncScrollNotAttemptedDisplayListOutdated);- return false;- }-- auto viewport_rect = m_navigable->page().css_to_device_rect(m_navigable->viewport_rect()).to_type<int>();- auto device_position = m_navigable->page().css_to_device_point(visual_viewport_position);- auto async_scroll_position = Gfx::FloatPoint { static_cast<float>(device_position.x().value()), static_cast<float>(device_position.y().value()) };- auto enqueue_result = m_navigable->compositor_context().async_scroll_by(- document->unique_id(), async_scroll_position, delta_in_device_pixels, viewport_rect, wheel_delta_precision, scroll_gesture_phase, operation_tracking, wheel_step_dispatch, wheel_gesture_id, handling_input_event_id());- record_input_routing(enqueue_result.routing_decision.value_or(InputRoutingDecision::NoAnswerFromCompositor), enqueue_result.routed_scroller, {}, InputTraceStage::CompositorForMainThread);- if (enqueue_result.operation_id.has_value() && async_scroll_operation)- *async_scroll_operation = AsyncScrollOperation { m_navigable, *enqueue_result.operation_id };- dbgln_if(COMPOSITOR_DEBUG, "[Compositor] {} wheel async scroll at {},{} with device delta {},{}",- enqueue_result.accepted ? "Enqueued"sv : "Could not enqueue"sv,- async_scroll_position.x(), async_scroll_position.y(),- delta_in_device_pixels.x(), delta_in_device_pixels.y());- return enqueue_result.accepted;+ // The end of a gesture settles here once the compositor has had it, so that a snap scroll the compositor starts for+ // it is the scroll the settlement finds in flight rather than one of its own.+ bool gesture_end_awaits_compositor = scroll_gesture_phase == Web::ScrollGesturePhase::Ended && !async_scroll_performed_default_action;+ auto settle_gesture_if_it_ended = [&] {+ if (gesture_end_awaits_compositor)+ m_navigable->note_user_scroll_gesture_phase(Web::ScrollGesturePhase::Ended);};-- // The end of a gesture is reported to the compositor before the gesture settles here, so that a snap scroll- // the compositor starts for it is the scroll the settlement finds in flight rather than one of its own.- if (scroll_gesture_phase == Web::ScrollGesturePhase::Ended && !async_scroll_performed_default_action && can_attempt_async_scroll && !asked_compositor_first- && visual_viewport->scale() == 1.0 && enqueue_async_scroll({}, Compositing::WheelStepDispatch::NotYetDispatched)) {- async_scroll_performed_default_action = true;- m_navigable->adopt_pending_async_scroll_offsets(Compositing::AsyncScrollUpdateFreshness::FromCompositor);- }-- m_navigable->note_user_scroll_gesture_phase(scroll_gesture_phase);+ if (!gesture_end_awaits_compositor)+ m_navigable->note_user_scroll_gesture_phase(scroll_gesture_phase);// Wheel activity marks the scroll gesture as still in progress even when it no longer moves any scrolling box. The// end of the gesture is not such activity.- if (scroll_gesture_phase != Web::ScrollGesturePhase::Ended) {- Optional<AsyncScrollNodeStableID> box_latched_on_this_thread;- if (m_wheel_scroll_latch.has_value())- box_latched_on_this_thread = m_wheel_scroll_latch->scrolling_box;- m_navigable->extend_wheel_user_scroll_gesture(box_latched_on_this_thread);- }+ if (scroll_gesture_phase != Web::ScrollGesturePhase::Ended)+ m_navigable->extend_wheel_user_scroll_gesture();m_navigable->note_user_scroll_input_intent(wheel_delta_precision == Web::WheelDeltaPrecision::Discrete? Compositing::SnapSelectionStrategy::Type::Direction: Compositing::SnapSelectionStrategy::Type::EndPosition);@@ -1108,8 +1082,10 @@ EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_positiLayout::ForcedReadScope read { *document };document->update_layout(DOM::UpdateLayoutReason::EventHandlerHandleMouseWheel);- if (!has_committed_root_box())+ if (!has_committed_root_box()) {+ settle_gesture_if_it_ended();return EventResult::Dropped;+ }if (modifiers & UIEvents::KeyModifier::Mod_Shift) {swap(wheel_delta_x, wheel_delta_y);@@ -1122,16 +1098,16 @@ EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_positiauto latch_gesture_to_wheel_event_target = [&](Target const& target, Layout::Node* target_layout_node) {if (!wheel_event_has_delta || !target.dom_node())return;- m_wheel_scroll_latch = WheelScrollLatch {+ m_wheel_event_target_latch = WheelEventTargetLatch {.wheel_gesture_id = wheel_gesture_id,.wheel_event_target = target.dom_node(),.wheel_event_target_pseudo_element = target_layout_node ? target_layout_node->generated_for_pseudo_element() : Optional<CSS::PseudoElement> {},};};if (continues_latched_gesture) {- wheel_event_target_layout_node = validated_wheel_scroll_latch_target_layout_node(read, *document);+ wheel_event_target_layout_node = validated_latched_wheel_event_target_layout_node(read, *document);if (wheel_event_target_layout_node)- wheel_event_target_node = m_wheel_scroll_latch->wheel_event_target.ptr();+ wheel_event_target_node = m_wheel_event_target_latch->wheel_event_target.ptr();elsecontinues_latched_gesture = false;}@@ -1144,230 +1120,106 @@ EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_positi}}- CSSPixelPoint wheel_step_delta { CSSPixels::nearest_value_for(wheel_delta_x), CSSPixels::nearest_value_for(wheel_delta_y) };- bool is_discrete_step = wheel_delta_precision == Web::WheelDeltaPrecision::Discrete;- bool wheel_step_may_snap = is_discrete_step || scroll_gesture_phase == Web::ScrollGesturePhase::Momentum;-- auto snap_wheel_step_in = [&](Layout::Node& scrolling_box) -> bool {- if (!wheel_step_may_snap)- return false;- if (is_discrete_step)- return m_navigable->perform_a_snapped_relative_user_scroll(scrolling_box, wheel_step_delta, Compositing::SnapSelectionStrategy::Type::Direction, HTML::LocalNavigable::SnapStepAccumulation::UntilGestureSettles, Compositing::ScrollAnimationKind::Wheel);- return m_navigable->perform_a_snapped_momentum_scroll(scrolling_box, wheel_step_delta);- };-- auto device_pixels_per_css_pixel = static_cast<float>(m_navigable->page().client().device_pixels_per_css_pixel());- auto async_scroll_delta_in_device_pixels = Gfx::FloatPoint { static_cast<float>(wheel_delta_x), static_cast<float>(wheel_delta_y) }.scaled(device_pixels_per_css_pixel);- if (can_attempt_async_scroll && async_scroll_performed_default_action) {- dbgln_if(COMPOSITOR_DEBUG, "[Compositor] Not attempting wheel async scroll: default action already performed");+ if (async_scroll_performed_default_action)record_input_routing(InputRoutingDecision::DefaultActionPerformedByCompositor);- } else if (asked_compositor_first) {- dbgln_if(COMPOSITOR_DEBUG, "[Compositor] Not attempting wheel async scroll: the compositor was asked first");- } else if (can_attempt_async_scroll && visual_viewport->scale() != 1.0) {- dbgln_if(COMPOSITOR_DEBUG, "[Compositor] Not attempting wheel async scroll: visual viewport is scaled");- record_input_routing(InputRoutingDecision::AsyncScrollNotAttemptedVisualViewportScaled);- } else if (can_attempt_async_scroll) {- if (wheel_event_target_layout_node) {- async_scroll_performed_default_action = enqueue_async_scroll(async_scroll_delta_in_device_pixels, Compositing::WheelStepDispatch::NotYetDispatched);- } else {- dbgln_if(COMPOSITOR_DEBUG, "[Compositor] Not attempting wheel async scroll: no paintable target");- }- }if (!wheel_event_target_layout_node) {record_input_routing(InputRoutingDecision::NoWheelTarget);+ settle_gesture_if_it_ended();return EventResult::Dropped;}- auto scroll_viewport_by_wheel_delta = [&](DOM::Document& document, Painting::WheelScrollableAxes viewport_scrollable_axes) -> EventResult {- auto visual_viewport_pan_axes = visual_viewport_pan_axes_for_scroll_step(document, wheel_delta_x, wheel_delta_y);- auto viewport_wheel_delta_x = viewport_scrollable_axes.horizontal || visual_viewport_pan_axes.x ? wheel_delta_x : 0;- auto viewport_wheel_delta_y = viewport_scrollable_axes.vertical || visual_viewport_pan_axes.y ? wheel_delta_y : 0;- if (viewport_wheel_delta_x == 0 && viewport_wheel_delta_y == 0)- return EventResult::Accepted;-- CSSPixelPoint viewport_wheel_delta { CSSPixels::nearest_value_for(viewport_wheel_delta_x), CSSPixels::nearest_value_for(viewport_wheel_delta_y) };- auto behavior = is_discrete_step ? Bindings::ScrollBehavior::Smooth : Bindings::ScrollBehavior::Instant;- auto viewport_took_the_scroll = m_navigable->scroll_viewport_by_delta(viewport_wheel_delta, behavior, Painting::ScrollKind::Relative, Compositing::ScrollAnimationKind::Wheel);- return viewport_took_the_scroll ? EventResult::Handled : EventResult::Accepted;- };-- auto latch_gesture_to_scrolling_box = [&](Layout::Node& scrolling_box) {- auto stable_node_id = Painting::async_scroll_node_stable_id(scrolling_box);- if (m_wheel_scroll_latch.has_value())- m_wheel_scroll_latch->scrolling_box = stable_node_id;- if (stable_node_id.has_value())- m_navigable->note_wheel_user_scroll_gesture_scrolls(stable_node_id.value());- };-- // The latched scrolling box takes every step of the gesture and drops what it cannot scroll by, so that neither an- // ancestor of it nor the navigable around this one scrolls by the rest.- auto scroll_latched_wheel_scrolling_box = [&](DOM::Document& document, Layout::Node& scrolling_box, Painting::WheelScrollableAxes scrollable_axes) {- if (scrolling_box.is_viewport()) {- if (visual_viewport_pan_axes_for_scroll_step(document, wheel_delta_x, wheel_delta_y).is_empty() && snap_wheel_step_in(scrolling_box))- return;- (void)scroll_viewport_by_wheel_delta(document, scrollable_axes);- return;- }- if (snap_wheel_step_in(scrolling_box))- return;- if (is_discrete_step) {- (void)m_navigable->scroll_scrolling_box_by_delta(scrolling_box, wheel_step_delta, Painting::ScrollKind::Relative, Compositing::ScrollAnimationKind::Wheel);- } else {- (void)Painting::scroll_by(scrolling_box, scrollable_axes.horizontal ? wheel_delta_x : 0, scrollable_axes.vertical ? wheel_delta_y : 0);- }- };-- auto perform_wheel_default_action = [&]() -> EventResult {- // Listeners ran: layout may have changed, and the target or the latched scrolling box may be gone.- auto document = m_navigable->active_document();- if (!document || !document->is_fully_active())- return EventResult::Dropped;- document->update_layout(DOM::UpdateLayoutReason::EventHandlerHandleMouseWheel);- if (!has_committed_root_box())- return EventResult::Dropped;-- if (auto* latched_scrolling_box = validated_latched_wheel_scrolling_box()) {- auto scrollable_axes = Painting::wheel_scrollable_axes(*latched_scrolling_box);- if (scrollable_axes.horizontal || scrollable_axes.vertical) {- scroll_latched_wheel_scrolling_box(*document, *latched_scrolling_box, scrollable_axes);- record_input_routing(InputRoutingDecision::MainThreadScrolledLatchedScroller, Painting::async_scroll_node_stable_id(*latched_scrolling_box));- return EventResult::Handled;- }- m_wheel_scroll_latch.clear();- }-- // No scrolling box has taken the gesture on this thread yet, e.g. because the compositor scrolled its earlier- // steps, so the walk from the target latches whichever box it moves.- auto* walk_start = validated_wheel_scroll_latch_target_layout_node(read, *document);- if (!walk_start) {- if (auto fresh_hit_test_target = target_for_mouse_position(visual_viewport_position); fresh_hit_test_target.has_value()) {- walk_start = fresh_hit_test_target->layout_node(read);- latch_gesture_to_wheel_event_target(*fresh_hit_test_target, walk_start);+ // A gesture this navigable latched to a target of its own is not offered to a nested navigable again. A nested+ // navigable that has a document takes the event; only the container of one without a document gets it here.+ bool offer_to_nested_navigable = !continues_latched_gesture || m_wheel_event_target_latch->gesture_handed_to_nested_navigable;+ if (wheel_event_target_node && offer_to_nested_navigable) {+ if (auto result = dispatch_event_to_nested_navigable(*this, *wheel_event_target_layout_node, wheel_event_target_node, visual_viewport_position, remote_target, [screen_position, button, buttons, modifiers, wheel_delta_x, wheel_delta_y, wheel_tick_120ths_x, wheel_tick_120ths_y, wheel_delta_precision, scroll_gesture_phase, async_scroll_performed_default_action, async_scroll_operation, remote_target, wheel_gesture_mark](EventHandler& event_handler, CSSPixelPoint position) -> EventResult {+ return event_handler.handle_mousewheel(position, screen_position, button, buttons, modifiers, wheel_delta_x, wheel_delta_y, wheel_tick_120ths_x, wheel_tick_120ths_y, wheel_delta_precision, scroll_gesture_phase, async_scroll_performed_default_action, async_scroll_operation, remote_target, wheel_gesture_mark);+ });+ result.has_value()) {+ record_input_routing(InputRoutingDecision::HandedToNestedNavigable, {}, wheel_event_target_node);+ if (result.value() != EventResult::Dropped) {+ if (result.value() == EventResult::Cancelled)+ m_wheel_event_target_latch.clear();+ else if (m_wheel_event_target_latch.has_value())+ m_wheel_event_target_latch->gesture_handed_to_nested_navigable = true;+ return result.value();}- }- // https://drafts.csswg.org/css-overscroll-1/#overscroll-behavior-properties- // The step scrolls this box or a box inside it. If none of them takes it, it is not passed on any further.- auto* viewport_box = document->layout_node(read);- auto const* box_ending_scroll_chain = Painting::box_ending_scroll_chain(walk_start ? *walk_start : *viewport_box, wheel_delta_x, wheel_delta_y);- if (walk_start) {- Layout::Node* snap_container = nullptr;- if (is_discrete_step)- snap_container = scrolling_box_for_continued_scroll_step(*m_navigable, *walk_start, wheel_step_delta, Compositing::ScrollAnimationKind::Wheel, box_ending_scroll_chain);- else if (wheel_step_may_snap)- snap_container = scrolling_box_for_scroll_step(*walk_start, wheel_step_delta);- Layout::Node* scrolled_box = nullptr;- if (snap_container && snap_wheel_step_in(*snap_container)) {- scrolled_box = snap_container;- } else if (is_discrete_step) {- scrolled_box = scroll_containing_block_chain_smoothly(*m_navigable, *walk_start, wheel_step_delta, Painting::ScrollKind::Relative, Compositing::ScrollAnimationKind::Wheel, box_ending_scroll_chain);+ // The listeners of the nested navigable may have changed this document.+ if (continues_latched_gesture) {+ document->update_layout(DOM::UpdateLayoutReason::EventHandlerHandleMouseWheel);+ wheel_event_target_layout_node = has_committed_root_box() ? validated_latched_wheel_event_target_layout_node(read, *document) : nullptr;} else {- scrolled_box = Painting::wheel_scroll_along_containing_block_chain(*walk_start, wheel_delta_x, wheel_delta_y);+ wheel_event_target_layout_node = hit_test_target->layout_node(read);}- if (scrolled_box) {- latch_gesture_to_scrolling_box(*scrolled_box);- record_input_routing(InputRoutingDecision::MainThreadScrolledScroller, Painting::async_scroll_node_stable_id(*scrolled_box));- return EventResult::Handled;+ if (!wheel_event_target_layout_node) {+ settle_gesture_if_it_ended();+ return EventResult::Dropped;}}+ }- // A step that a box keeps to itself is handled even though nothing scrolled, so that neither the viewport- // nor a document this one is nested in scrolls by it. No scrolling box is latched: the next step may point- // along the other axis, which the box may well pass on.- if (box_ending_scroll_chain && !box_ending_scroll_chain->is_viewport()) {- record_input_routing(InputRoutingDecision::ScrollKeptByOverscrollBehavior, Painting::async_scroll_node_stable_id(*box_ending_scroll_chain));- return EventResult::Handled;- }-- auto viewport_scroll_result = scroll_viewport_by_wheel_delta(*document, Painting::wheel_scrollable_axes(*viewport_box));- if (viewport_scroll_result == EventResult::Handled) {- latch_gesture_to_scrolling_box(*viewport_box);- record_input_routing(InputRoutingDecision::MainThreadScrolledScroller, Painting::async_scroll_node_stable_id(*viewport_box));- } else if (box_ending_scroll_chain) {- record_input_routing(InputRoutingDecision::ScrollKeptByOverscrollBehavior, Painting::async_scroll_node_stable_id(*box_ending_scroll_chain));- return EventResult::Handled;- } else {- record_input_routing(InputRoutingDecision::MainThreadScrolledNothing);- }- return viewport_scroll_result;- };-- // Blocking wheel event listeners hold the steps of a touchpad gesture back from the compositor until the page has- // dispatched them. A step the page did not cancel goes back to the compositor, which scrolls it as it scrolls the- // steps nothing holds back, so that the gesture also stretches the edges it pulls past.- auto hand_dispatched_touchpad_step_to_compositor = [&] {- if (!can_attempt_async_scroll || !wheel_event_has_delta)- return false;- bool is_touchpad_step = wheel_delta_precision == Web::WheelDeltaPrecision::Precise- && first_is_one_of(scroll_gesture_phase, Web::ScrollGesturePhase::Ongoing, Web::ScrollGesturePhase::Momentum);- if (!is_touchpad_step)- return false;- // A gesture that has moved a box on this thread keeps scrolling it here.- if (m_wheel_scroll_latch.has_value() && m_wheel_scroll_latch->scrolling_box.has_value())- return false;- // The listeners may have navigated away from the document, or zoomed it in.- if (m_navigable->active_document() != document || !document->is_fully_active() || visual_viewport->scale() != 1.0)- return false;- return enqueue_async_scroll(async_scroll_delta_in_device_pixels, Compositing::WheelStepDispatch::DispatchedAndNotCanceled);- };-- auto handled_event = EventResult::Dropped;-+ auto dispatch_result = EventResult::Accepted;if (wheel_event_target_node) {- // A gesture this navigable latched to a scrolling box of its own is not offered to a nested navigable again.- bool offer_to_nested_navigable = !continues_latched_gesture || m_wheel_scroll_latch->gesture_handed_to_nested_navigable;- if (offer_to_nested_navigable) {- if (auto result = dispatch_event_to_nested_navigable(*this, *wheel_event_target_layout_node, wheel_event_target_node, visual_viewport_position, remote_target, [screen_position, button, buttons, modifiers, wheel_delta_x, wheel_delta_y, wheel_tick_120ths_x, wheel_tick_120ths_y, wheel_delta_precision, scroll_gesture_phase, async_scroll_performed_default_action, async_scroll_operation, remote_target, wheel_gesture_mark](EventHandler& event_handler, CSSPixelPoint position) -> EventResult {- return event_handler.handle_mousewheel(position, screen_position, button, buttons, modifiers, wheel_delta_x, wheel_delta_y, wheel_tick_120ths_x, wheel_tick_120ths_y, wheel_delta_precision, scroll_gesture_phase, async_scroll_performed_default_action, async_scroll_operation, remote_target, wheel_gesture_mark);- });- result.has_value()) {- record_input_routing(InputRoutingDecision::HandedToNestedNavigable, {}, wheel_event_target_node);- if (result.value() == EventResult::Handled) {- if (m_wheel_scroll_latch.has_value())- m_wheel_scroll_latch->gesture_handed_to_nested_navigable = true;- return EventResult::Handled;- }- if (result.value() == EventResult::Cancelled) {- m_wheel_scroll_latch.clear();- return EventResult::Cancelled;- }- // The nested navigable declined the event, and its listeners may have changed this document.- if (continues_latched_gesture) {- document->update_layout(DOM::UpdateLayoutReason::EventHandlerHandleMouseWheel);- wheel_event_target_layout_node = has_committed_root_box() ? validated_wheel_scroll_latch_target_layout_node(read, *document) : nullptr;- } else {- wheel_event_target_layout_node = hit_test_target->layout_node(read);- }- if (!wheel_event_target_layout_node)- return EventResult::Dropped;- }- }-- auto is_cancelable = async_scroll_performed_default_action ? UIEvents::WheelEventIsCancelable::No : UIEvents::WheelEventIsCancelable::Yes;- auto dispatch_result = dispatch_wheel_event(read, *wheel_event_target_layout_node, visual_viewport_position, screen_position, button, buttons, modifiers, wheel_delta_x, wheel_delta_y, wheel_tick_120ths_x, wheel_tick_120ths_y, is_cancelable == UIEvents::WheelEventIsCancelable::Yes);+ dispatch_result = dispatch_wheel_event(read, *wheel_event_target_layout_node, visual_viewport_position, screen_position, button, buttons, modifiers, wheel_delta_x, wheel_delta_y, wheel_tick_120ths_x, wheel_tick_120ths_y, !async_scroll_performed_default_action);if (dispatch_result == EventResult::Accepted)record_input_routing(InputRoutingDecision::DispatchedWheelEvent, {}, wheel_event_target_node);else if (dispatch_result == EventResult::Cancelled)record_input_routing(InputRoutingDecision::PageCanceledWheelEvent, {}, wheel_event_target_node);- // A listener that cancels the event scrolls by itself, so the next event is targeted afresh.- if (dispatch_result == EventResult::Cancelled)- m_wheel_scroll_latch.clear();- if (dispatch_result == EventResult::Accepted) {- if (async_scroll_performed_default_action || hand_dispatched_touchpad_step_to_compositor())- handled_event = EventResult::Handled;- else- handled_event = perform_wheel_default_action();- } else if (dispatch_result == EventResult::Cancelled && async_scroll_performed_default_action) {- handled_event = EventResult::Handled;- } else if (dispatch_result == EventResult::Cancelled) {- handled_event = EventResult::Cancelled;- } else- handled_event = dispatch_result;- } else if (!async_scroll_performed_default_action) {- handled_event = perform_wheel_default_action();+ }+ if (async_scroll_performed_default_action)+ return EventResult::Handled;++ if (dispatch_result == EventResult::Cancelled) {+ // A listener that cancels the event scrolls by itself, so the next event is targeted afresh, by the compositor+ // too.+ m_wheel_event_target_latch.clear();+ if (wheel_gesture_id.has_value() && has_compositor)+ m_navigable->compositor_context().wheel_event_canceled(*wheel_gesture_id);+ settle_gesture_if_it_ended();+ return EventResult::Cancelled;+ }++ // Without a compositor nothing scrolls by the event.+ if (dispatch_result == EventResult::Dropped || !wheel_gesture_mark.has_value() || !has_compositor || m_navigable->active_document() != document || !document->is_fully_active()) {+ settle_gesture_if_it_ended();+ return dispatch_result;}- return handled_event;+ // The listeners ran: layout may have changed, and the target may be gone. The compositor scrolls the innermost of+ // the scrollers around the target that it knows.+ document->update_layout(DOM::UpdateLayoutReason::EventHandlerHandleMouseWheel);+ Layout::Node* scroll_chain_start = nullptr;+ if (has_committed_root_box()) {+ scroll_chain_start = validated_latched_wheel_event_target_layout_node(read, *document);+ if (!scroll_chain_start) {+ if (auto fresh_hit_test_target = target_for_mouse_position(visual_viewport_position); fresh_hit_test_target.has_value()) {+ scroll_chain_start = fresh_hit_test_target->layout_node(read);+ latch_gesture_to_wheel_event_target(*fresh_hit_test_target, scroll_chain_start);+ }+ }+ if (!scroll_chain_start)+ scroll_chain_start = document->layout_node(read);+ }++ auto device_position = m_navigable->page().css_to_device_point(visual_viewport_position);+ Compositing::WheelStepLetThrough step {+ .document_id = document->unique_id(),+ .input_event_id = handling_input_event_id(),+ .wheel_gesture_mark = *wheel_gesture_mark,+ .position = { static_cast<float>(device_position.x().value()), static_cast<float>(device_position.y().value()) },+ .delta_in_css_pixels = { static_cast<float>(wheel_delta_x), static_cast<float>(wheel_delta_y) },+ .wheel_delta_precision = wheel_delta_precision,+ .scroll_gesture_phase = scroll_gesture_phase,+ .scroll_chain = scroll_chain_start ? wheel_scroll_chain_from(*scroll_chain_start) : Vector<Web::AsyncScrollNodeStableID> {},+ };+ auto answer = m_navigable->compositor_context().wheel_event_let_through(step, operation_tracking);+ record_input_routing(answer.routing_decision.value_or(InputRoutingDecision::NoAnswerFromCompositor), answer.routed_scroller, {}, InputTraceStage::CompositorForMainThread);+ follow_operation_of(answer);+ // The compositor scrolled by the step a moment ago.+ m_navigable->adopt_pending_async_scroll_offsets(Compositing::AsyncScrollUpdateFreshness::FromCompositor);+ settle_gesture_if_it_ended();+ return answer.performed_default_action ? EventResult::Handled : EventResult::Accepted;}EventResult EventHandler::dispatch_wheel_event(Layout::BegunRead const& read, Layout::Node& hit_layout_node, CSSPixelPoint visual_viewport_position, CSSPixelPoint screen_position, u32 button, u32 buttons, u32 modifiers, double wheel_delta_x, double wheel_delta_y, double wheel_tick_120ths_x, double wheel_tick_120ths_y, bool is_cancelable)@@ -3462,15 +3314,15 @@ CSSPixelPoint EventHandler::compute_mouse_event_movement(CSSPixelPoint screen_poreturn { screen_position.x() - m_mousemove_previous_screen_position.value().x(), screen_position.y() - m_mousemove_previous_screen_position.value().y() };}-Layout::Node* EventHandler::validated_wheel_scroll_latch_target_layout_node(Layout::BegunRead const& read, DOM::Document& document)+Layout::Node* EventHandler::validated_latched_wheel_event_target_layout_node(Layout::BegunRead const& read, DOM::Document& document){- if (!m_wheel_scroll_latch.has_value())+ if (!m_wheel_event_target_latch.has_value())return nullptr;- auto target = m_wheel_scroll_latch->wheel_event_target.ptr();+ auto target = m_wheel_event_target_latch->wheel_event_target.ptr();bool target_is_in_document = target && &target->document() == &document && target->is_connected();Layout::Node* layout_node = nullptr;if (target_is_in_document) {- auto pseudo_element = m_wheel_scroll_latch->wheel_event_target_pseudo_element;+ auto pseudo_element = m_wheel_event_target_latch->wheel_event_target_pseudo_element;if (!pseudo_element.has_value())layout_node = target->layout_node(read);else if (auto* element = as_if<DOM::Element>(*target))@@ -3480,21 +3332,10 @@ Layout::Node* EventHandler::validated_wheel_scroll_latch_target_layout_node(Layoif (layout_node && layout_node->is_text_node())layout_node = layout_node->parent();if (!layout_node)- m_wheel_scroll_latch.clear();+ m_wheel_event_target_latch.clear();return layout_node;}-Layout::Node* EventHandler::validated_latched_wheel_scrolling_box()-{- if (!m_wheel_scroll_latch.has_value() || !m_wheel_scroll_latch->scrolling_box.has_value())- return nullptr;- auto* scrolling_box = m_navigable->layout_node_for_async_scroll_node_stable_id(*m_wheel_scroll_latch->scrolling_box);- if (scrolling_box && Painting::has_committed_box(*scrolling_box))- return scrolling_box;- m_wheel_scroll_latch.clear();- return nullptr;-}-Optional<EventHandler::Target> EventHandler::target_for_mouse_position(CSSPixelPoint position){auto document = m_navigable->active_document();@@ -5274,7 +5115,7 @@ void EventHandler::reset_mouse_input_tracking(Badge<Page>){clear_mousedown_tracking();stop_updating_selection();- m_wheel_scroll_latch.clear();+ m_wheel_event_target_latch.clear();// The press ended in another document, so no pointerup here releases a capture it set, and the mouse holds no// button that a capture needs.@@ -5696,7 +5537,7 @@ void EventHandler::reset_hover_for_document_replacement(Badge<HTML::LocalNavigabm_effective_legacy_mouse_pointer_position = nullptr;m_effective_legacy_mouse_pointer_type = PointerType::Mouse;m_native_mouse_hover_target = nullptr;- m_wheel_scroll_latch.clear();+ m_wheel_event_target_latch.clear();// A capture in the outgoing document ends with it, with no lostpointercapture event into that document.m_mouse_pointer.pending_capture_target = nullptr;m_mouse_pointer.capture_target = nullptr;@@ -5828,7 +5669,7 @@ void EventHandler::clear_per_test_input_state(Badge<Internals::Internals>)m_native_mouse_hover_target = nullptr;m_drag_and_drop_event_handler->reset();m_mousemove_previous_screen_position.clear();- m_wheel_scroll_latch.clear();+ m_wheel_event_target_latch.clear();m_navigable->page().clear_context_menu_request();}diff --git a/Libraries/LibWeb/Page/EventHandler.h b/Libraries/LibWeb/Page/EventHandler.hindex f7260908fdc..b71b698d3b1 100644--- a/Libraries/LibWeb/Page/EventHandler.h+++ b/Libraries/LibWeb/Page/EventHandler.h@@ -269,8 +269,7 @@ private:void update_hover_after_scroll(CSSPixelPoint visual_viewport_position, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, GC::Ptr<DOM::Node> hover_target = {});EventResult dispatch_wheel_event(Layout::BegunRead const& read, Layout::Node&, CSSPixelPoint visual_viewport_position, CSSPixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, double wheel_delta_x, double wheel_delta_y, double wheel_tick_120ths_x, double wheel_tick_120ths_y, bool is_cancelable);// Both drop the latch when what it refers to is gone from the document, so that the event is targeted afresh.- Layout::Node* validated_wheel_scroll_latch_target_layout_node(Layout::BegunRead const& read, DOM::Document&);- Layout::Node* validated_latched_wheel_scrolling_box();+ Layout::Node* validated_latched_wheel_event_target_layout_node(Layout::BegunRead const& read, DOM::Document&);EventResult dispatch_synthetic_pinch_wheel_event(CSSPixelPoint visual_viewport_position, CSSPixelPoint screen_position, unsigned modifiers, double wheel_delta_y, bool is_cancelable, Optional<RemoteInputEventTarget>* remote_target);enum class PointerEventType : u8 {@@ -357,21 +356,18 @@ private:Optional<UIEvents::KeyCode> m_held_scroll_key;OwnPtr<HTML::UserScrollGestureHold> m_scroll_key_gesture_hold;- // The target and the scrolling box of the wheel gesture in progress: the gesture's later wheel events go to them- // without hit testing, and the scrolling box absorbs the gesture at its edge. The compositor latches by the same- // rules, so the two agree on the scroller of an event.- struct WheelScrollLatch {+ // The target of the wheel gesture in progress, which the gesture's later wheel events go to without hit testing.+ // The compositor latches the scroller of the gesture.+ struct WheelEventTargetLatch {// The gesture the compositor named for the event that started the latch, which only events it names the same// gesture for continue.Optional<u64> wheel_gesture_id;GC::Weak<DOM::Node> wheel_event_target;- // The default action walks the boxes of this pseudo-element rather than the target's own.+ // The events go to the box of this pseudo-element rather than the target's own.Optional<CSS::PseudoElement> wheel_event_target_pseudo_element {};bool gesture_handed_to_nested_navigable { false };- // Unset until the default action of this thread has moved a box, so for as long as the compositor scrolls.- Optional<Web::AsyncScrollNodeStableID> scrolling_box {};};- Optional<WheelScrollLatch> m_wheel_scroll_latch;+ Optional<WheelEventTargetLatch> m_wheel_event_target_latch;};}diff --git a/Libraries/LibWeb/Painting/Scrolling.cpp b/Libraries/LibWeb/Painting/Scrolling.cppindex 15a82450ab0..511ddf0ac22 100644--- a/Libraries/LibWeb/Painting/Scrolling.cpp+++ b/Libraries/LibWeb/Painting/Scrolling.cpp@@ -236,32 +236,6 @@ ScrollHandled set_scroll_offset_from_user_input(Layout::Node& node, CSSPixelPoinreturn scroll_handled;}-Layout::Node* wheel_scroll_along_containing_block_chain(Layout::Node& node, double wheel_delta_x, double wheel_delta_y, ScrollKind scroll_kind)-{- auto const& read = node.held_read();- struct WheelScrollableBox {- Compositing::RustFFI::NodeSlotId slot;- double accepted_delta_x;- double accepted_delta_y;- };- Vector<WheelScrollableBox, 4> wheel_scrollable_boxes;- Layout::RustFFI::render_state_for_each_wheel_scrollable_box_in_containing_block_chain(- node.document_host(), committed_row_slot(node), wheel_delta_x, wheel_delta_y, &wheel_scrollable_boxes, [](void* context, Compositing::RustFFI::NodeSlotId slot, double accepted_delta_x, double accepted_delta_y) {- static_cast<Vector<WheelScrollableBox, 4>*>(context)->append({ slot, accepted_delta_x, accepted_delta_y });- });- for (auto const& wheel_scrollable_box : wheel_scrollable_boxes) {- auto* scrollable_box = node.node_arena().node_if_live(read, wheel_scrollable_box.slot);- if (scrollable_box && scroll_by(*scrollable_box, wheel_scrollable_box.accepted_delta_x, wheel_scrollable_box.accepted_delta_y, scroll_kind) == ScrollHandled::Yes)- return scrollable_box;- }- return nullptr;-}--Layout::Node* scrolling_box_for_scroll_step_in_containing_block_chain(Layout::BegunRead const& read, Layout::Node& target, CSSPixelPoint delta)-{- return target.node_arena().node_if_live(read, Layout::RustFFI::render_state_scrolling_box_for_scroll_step(target.document_host(), committed_row_slot(target), viewport_row_slot(read, target.document()), delta));-}-Layout::Node* first_wheel_scrollable_box_in_containing_block_chain(Layout::Node const& node){auto const& read = node.held_read();diff --git a/Libraries/LibWeb/Painting/Scrolling.h b/Libraries/LibWeb/Painting/Scrolling.hindex 4172c0a954a..8fdfff8ea3f 100644--- a/Libraries/LibWeb/Painting/Scrolling.h+++ b/Libraries/LibWeb/Painting/Scrolling.h@@ -53,10 +53,6 @@ WEB_API Optional<Web::AsyncScrollNodeStableID> async_scroll_node_stable_id(LayouScrollHandled set_scroll_offset(Layout::Node&, CSSPixelPoint);ScrollHandled set_scroll_offset_from_user_input(Layout::Node&, CSSPixelPoint, ScrollKind = ScrollKind::Relative);ScrollHandled scroll_by(Layout::Node&, double delta_x, double delta_y, ScrollKind = ScrollKind::Relative);-// The box the walk scrolled, if any.-Layout::Node* wheel_scroll_along_containing_block_chain(Layout::Node&, double wheel_delta_x, double wheel_delta_y, ScrollKind = ScrollKind::Relative);--WEB_API Layout::Node* scrolling_box_for_scroll_step_in_containing_block_chain(Layout::BegunRead const&, Layout::Node&, CSSPixelPoint delta);WEB_API Layout::Node* first_wheel_scrollable_box_in_containing_block_chain(Layout::Node const&);// The nearest box in the containing block chain, the given one included, that keeps a scroll step by the delta to// itself instead of passing it on to a scroller around it. The step scrolls that box or a box inside it, or nothing.diff --git a/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs b/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rsindex 10b27efa7f4..1fb5ead4a51 100644--- a/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs+++ b/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs@@ -157,66 +157,6 @@ pub extern "C" fn render_state_scroll_target_for_text_position(container}-#[unsafe(no_mangle)]-pub extern "C" fn render_state_scrolling_box_for_scroll_step(- host: &crate::render_state::DocumentHost,- target: NodeSlotId,- viewport: NodeSlotId,- delta: FfiCssPixelPoint,-) -> NodeSlotId {- read_arena(- host,- super::node_read(),- (target, viewport, delta),- |arena, (target, viewport, delta)| {- arena.settle_scrollable_overflow();- crate::painting::scroll_chain::scrolling_box_for_scroll_step(- &arena.paintable_rows(),- target,- viewport,- delta.into(),- )- },- )-}--/// # Safety-///-/// `host` must be a live document host, on its document's thread. The host callback receives the slots of live rows.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_for_each_wheel_scrollable_box_in_containing_block_chain(- host: &crate::render_state::DocumentHost,- start: NodeSlotId,- wheel_delta_x: f64,- wheel_delta_y: f64,- context: *mut c_void,- push_scrollable_box: unsafe extern "C" fn(*mut c_void, NodeSlotId, f64, f64),-) {- let boxes = {- read_arena(- host,- super::node_read(),- (start, wheel_delta_x, wheel_delta_y),- |arena, (start, wheel_delta_x, wheel_delta_y)| {- arena.settle_scrollable_overflow();- let mut boxes = Vec::new();- crate::painting::scroll_chain::for_each_wheel_scrollable_box_in_containing_block_chain(- &arena.paintable_rows(),- start,- wheel_delta_x,- wheel_delta_y,- |node, accepted_delta_x, accepted_delta_y| boxes.push((node, accepted_delta_x, accepted_delta_y)),- );- boxes- },- )- };- for (node, accepted_delta_x, accepted_delta_y) in boxes {- // SAFETY: The C++ callback appends the slot and deltas to a caller-owned collection.- unsafe { push_scrollable_box(context, node, accepted_delta_x, accepted_delta_y) };- }-}-#[unsafe(no_mangle)]pub extern "C" fn render_state_box_ending_scroll_chain(host: &crate::render_state::DocumentHost,diff --git a/Libraries/LibWeb/Rust/src/painting/scroll_chain.rs b/Libraries/LibWeb/Rust/src/painting/scroll_chain.rsindex 6a6a7d67709..ed8a7283114 100644--- a/Libraries/LibWeb/Rust/src/painting/scroll_chain.rs+++ b/Libraries/LibWeb/Rust/src/painting/scroll_chain.rs@@ -11,30 +11,6 @@ use crate::painting::paintable_geometry::{absolute_padding_box_rect, has_scrollause crate::painting::paintable_rows::PaintableRowsRead;use crate::painting::{caret, chrome_geometry, scroll_snap};-fn accepted_wheel_delta(arena: &impl PaintableRowsRead, node: NodeSlotId, delta: CssPixelPoint) -> CssPixelPoint {- let axes = chrome_geometry::wheel_scrollable_axes(arena, node);- let zero = CssPixels::from_raw(0);- CssPixelPoint::new(- if axes.horizontal { delta.x } else { zero },- if axes.vertical { delta.y } else { zero },- )-}--fn clamp_scroll_offset(arena: &impl PaintableRowsRead, node: NodeSlotId, offset: CssPixelPoint) -> CssPixelPoint {- let Some((minimum_offset, maximum_offset)) = chrome_geometry::scroll_offset_bounds(arena, node) else {- return offset;- };- CssPixelPoint::new(- offset.x.clamp(minimum_offset.x, maximum_offset.x),- offset.y.clamp(minimum_offset.y, maximum_offset.y),- )-}--fn scrolling_box_moved_by(arena: &impl PaintableRowsRead, node: NodeSlotId, delta: CssPixelPoint) -> bool {- let current_offset = arena.row_scroll_offset(node);- clamp_scroll_offset(arena, node, current_offset.translated(delta.x, delta.y)) != current_offset-}-/// The nearest box, `start` included, that keeps a scroll step by the delta to itself: neither it nor a box inside it/// passes the step on to a scroller around it. A step belongs to one scroller, and a touchpad rarely moves along one/// axis exactly, so it is the main axis of the step that decides.@@ -61,70 +37,6 @@ pub(crate) fn box_ending_scroll_chain(NodeSlotId::INVALID}-pub(crate) fn scrolling_box_for_scroll_step(- arena: &impl PaintableRowsRead,- target: NodeSlotId,- viewport: NodeSlotId,- delta: CssPixelPoint,-) -> NodeSlotId {- let scroll_step_moves = |node: NodeSlotId| {- let accepted_delta = accepted_wheel_delta(arena, node, delta);- accepted_delta != CssPixelPoint::default() && scrolling_box_moved_by(arena, node, accepted_delta)- };- let box_ending_scroll_chain = box_ending_scroll_chain(arena, target, delta.x.to_double(), delta.y.to_double());-- let mut node = target;- while let Some(data) = arena.node_data_if_live(node) {- if data.kind.get() == NodeKind::Viewport {- break;- }- if scroll_step_moves(node) {- return node;- }- if node == box_ending_scroll_chain {- return NodeSlotId::INVALID;- }- node = arena.containing_block_by_walking_ancestors(node);- }-- if arena.slot_is_live(viewport) && scroll_step_moves(viewport) {- return viewport;- }- NodeSlotId::INVALID-}--pub(crate) fn for_each_wheel_scrollable_box_in_containing_block_chain(- arena: &impl PaintableRowsRead,- start: NodeSlotId,- wheel_delta_x: f64,- wheel_delta_y: f64,- mut push_scrollable_box: impl FnMut(NodeSlotId, f64, f64),-) {- let box_ending_scroll_chain = box_ending_scroll_chain(arena, start, wheel_delta_x, wheel_delta_y);- let mut node = start;- while let Some(data) = arena.node_data_if_live(node) {- if data.kind.get() != NodeKind::Viewport {- let axes = chrome_geometry::wheel_scrollable_axes(arena, node);- let accepted_delta_x = if axes.horizontal { wheel_delta_x } else { 0.0 };- let accepted_delta_y = if axes.vertical { wheel_delta_y } else { 0.0 };- if accepted_delta_x != 0.0 || accepted_delta_y != 0.0 {- push_scrollable_box(node, accepted_delta_x, accepted_delta_y);- let accepted_delta = CssPixelPoint::new(- CssPixels::nearest_value_for(accepted_delta_x),- CssPixels::nearest_value_for(accepted_delta_y),- );- if scrolling_box_moved_by(arena, node, accepted_delta) {- return;- }- }- }- if node == box_ending_scroll_chain {- return;- }- node = arena.containing_block_by_walking_ancestors(node);- }-}-pub(crate) fn first_wheel_scrollable_box_in_containing_block_chain(arena: &impl PaintableRowsRead,start: NodeSlotId,diff --git a/Libraries/LibWebCommon/Page/InputRoutingDecision.h b/Libraries/LibWebCommon/Page/InputRoutingDecision.hindex 493130e0c93..35843dbd121 100644--- a/Libraries/LibWebCommon/Page/InputRoutingDecision.h+++ b/Libraries/LibWebCommon/Page/InputRoutingDecision.h@@ -13,63 +13,60 @@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(HandedToNestedContext, "handed-to-nested-context") \- X(NestedContextPassedStepOn, "nested-context-passed-step-on") \- X(NestedContextUnavailable, "nested-context-unavailable") \- X(NotOverAScrollbar, "not-over-a-scrollbar") \- X(NotPrimaryButton, "not-primary-button") \- X(HoveringScrollbarPaintedByCompositor, "hovering-scrollbar-painted-by-compositor") \- X(HoveringScrollbarPaintedByDisplayList, "hovering-scrollbar-painted-by-display-list") \- 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") \- X(GestureEndAbsorbedByFling, "gesture-end-absorbed-by-fling") \- X(FlingStarted, "fling-started") \- X(MomentumInterrupted, "momentum-interrupted") \- X(NotDispatchedByCompositor, "not-dispatched-by-compositor") \- X(ConsumedByCompositor, "consumed-by-compositor") \- X(ForwardedToPage, "forwarded-to-page") \- X(NoAnswerFromCompositor, "no-answer-from-compositor") \- X(CoalescedIntoLaterEvent, "coalesced-into-later-event") \- X(DroppedWithoutLocalRoot, "dropped-without-local-root") \- X(DroppedOutdatedPointerMove, "dropped-outdated-pointer-move") \- X(ForwardedToRemoteFrame, "forwarded-to-remote-frame") \- X(AsyncScrollNotAttemptedDisplayListOutdated, "async-scroll-not-attempted-display-list-outdated") \- X(AsyncScrollNotAttemptedVisualViewportScaled, "async-scroll-not-attempted-visual-viewport-scaled") \- X(DefaultActionPerformedByCompositor, "default-action-performed-by-compositor") \- X(NoWheelTarget, "no-wheel-target") \- X(HandedToNestedNavigable, "handed-to-nested-navigable") \- X(DispatchedWheelEvent, "dispatched-wheel-event") \- X(PageCanceledWheelEvent, "page-canceled-wheel-event") \- X(MainThreadScrolledLatchedScroller, "main-thread-scrolled-latched-scroller") \- X(MainThreadScrolledScroller, "main-thread-scrolled-scroller") \- X(ScrollKeptByOverscrollBehavior, "scroll-kept-by-overscroll-behavior") \- X(MainThreadScrolledNothing, "main-thread-scrolled-nothing") \- X(ScrollbarDragDrivenByCompositor, "scrollbar-drag-driven-by-compositor") \- X(FinishedAccepted, "finished-accepted") \- X(FinishedHandled, "finished-handled") \- X(FinishedCancelled, "finished-cancelled") \+#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(HandedToNestedContext, "handed-to-nested-context") \+ X(NestedContextPassedStepOn, "nested-context-passed-step-on") \+ X(NestedContextUnavailable, "nested-context-unavailable") \+ X(NotOverAScrollbar, "not-over-a-scrollbar") \+ X(NotPrimaryButton, "not-primary-button") \+ X(HoveringScrollbarPaintedByCompositor, "hovering-scrollbar-painted-by-compositor") \+ X(HoveringScrollbarPaintedByDisplayList, "hovering-scrollbar-painted-by-display-list") \+ 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") \+ X(GestureEndAbsorbedByFling, "gesture-end-absorbed-by-fling") \+ X(FlingStarted, "fling-started") \+ X(MomentumInterrupted, "momentum-interrupted") \+ X(NotDispatchedByCompositor, "not-dispatched-by-compositor") \+ X(ConsumedByCompositor, "consumed-by-compositor") \+ X(ForwardedToPage, "forwarded-to-page") \+ X(NoAnswerFromCompositor, "no-answer-from-compositor") \+ X(CoalescedIntoLaterEvent, "coalesced-into-later-event") \+ X(DroppedWithoutLocalRoot, "dropped-without-local-root") \+ X(DroppedOutdatedPointerMove, "dropped-outdated-pointer-move") \+ X(ForwardedToRemoteFrame, "forwarded-to-remote-frame") \+ X(CompositorDisplayListOutdated, "compositor-display-list-outdated") \+ X(StepExceedsInputLeftToThePage, "step-exceeds-input-left-to-the-page") \+ X(DefaultActionPerformedByCompositor, "default-action-performed-by-compositor") \+ X(NoWheelTarget, "no-wheel-target") \+ X(HandedToNestedNavigable, "handed-to-nested-navigable") \+ X(DispatchedWheelEvent, "dispatched-wheel-event") \+ X(PageCanceledWheelEvent, "page-canceled-wheel-event") \+ X(ScrollKeptByOverscrollBehavior, "scroll-kept-by-overscroll-behavior") \+ X(ScrollbarDragDrivenByCompositor, "scrollbar-drag-driven-by-compositor") \+ X(FinishedAccepted, "finished-accepted") \+ X(FinishedHandled, "finished-handled") \+ X(FinishedCancelled, "finished-cancelled") \X(FinishedDropped, "finished-dropped")enum class InputRoutingDecision : u8 {diff --git a/Services/Compositor/AsyncScrollUpdateOutbox.h b/Services/Compositor/AsyncScrollUpdateOutbox.hindex ee94291d64d..c90dcab5cb8 100644--- a/Services/Compositor/AsyncScrollUpdateOutbox.h+++ b/Services/Compositor/AsyncScrollUpdateOutbox.h@@ -17,8 +17,6 @@ class AsyncScrollUpdateOutbox {public:Compositing::AsyncScrollOperationID allocate_operation_id() { return ++m_last_allocated_operation_id; }void complete_operation(Compositing::AsyncScrollOperationID operation_id) { m_completed_operation_ids.append(operation_id); }- // Whether the operation ended since the updates were last taken.- bool has_completed_operation(Compositing::AsyncScrollOperationID operation_id) const { return m_completed_operation_ids.contains_slow(operation_id); }void note_operation_taken_over_by_user_input(Compositing::AsyncScrollOperationID operation_id) { m_operation_ids_taken_over_by_user_input.append(operation_id); }void record_scroll_offsets(ReadonlySpan<Compositing::AsyncScrollOffset>);void record_started_user_scroll(Compositing::StartedUserScroll started_user_scroll) { m_started_user_scrolls.append(move(started_user_scroll)); }diff --git a/Services/Compositor/CompositorState.cpp b/Services/Compositor/CompositorState.cppindex 57c2022b240..1326781d385 100644--- a/Services/Compositor/CompositorState.cpp+++ b/Services/Compositor/CompositorState.cpp@@ -689,6 +689,8 @@ void CompositorState::handle_and_dispatch_mouse_event(Web::CompositorContextId cschedule_animation_frames_if_needed(*context);if (is_wheel_event) {event.async_scroll_performed_default_action = handled;+ if (!handled)+ context->note_wheel_event_left_to_the_page(event);} else if (handled) {// The page still sees the events of a drag the compositor scrolls for a scrollbar the display list paints.if (!result.scrollbar_dragged_by_compositor.has_value()) {@@ -927,23 +929,45 @@ bool CompositorState::is_nested_in(Web::CompositorContextId containing_context_iContextState::ContextUpdateResult CompositorState::scroll_for_wheel_step(Web::CompositorContextId context_id, ContextState& context, Web::MouseEvent const& event, WheelStepOrigin origin, bool is_first_wheel_event_with_delta, Compositing::AsyncScrollOperationTracking operation_tracking, MonotonicTime now){+ auto gesture_id = context.wheel_gesture_id();+ auto listener_context_id = context.wheel_event_listener_context().value_or(context_id);+ auto* listener_context = listener_context_id == context_id ? &context : context_still_nested_in(context_id, listener_context_id);+ auto listener_gate = listener_context+ ? listener_context->wheel_event_listener_gate(gesture_id)+ : ContextState::WheelEventListenerGate { .reason_to_hold_latched_steps_back = Web::InputRoutingDecision::NestedContextUnavailable };+ContextState::ContextUpdateResult result;- switch (origin) {- case WheelStepOrigin::UI:- result = context.handle_wheel_event(event, is_first_wheel_event_with_delta, now);- break;- case WheelStepOrigin::Fling:- result = context.scroll_for_fling_step(event, now);- break;- case WheelStepOrigin::MainThread:- result = context.scroll_for_wheel_event_from_main_thread(event, is_first_wheel_event_with_delta, operation_tracking, now);- break;- }- bool presents_frame = result.frame_to_present.has_value();- if (result.nested_context_wheel_step.has_value()) {- auto handed_step = hand_wheel_step_to_nested_context(context_id, context, event, *result.nested_context_wheel_step, operation_tracking, now);- result = move(handed_step.result);- presents_frame = handed_step.nested_context_presents_frame;+ bool presents_frame = false;+ if (listener_context && listener_context != &context && listener_gate.page_let_the_gesture_through && !context.has_wheel_latch_for_gesture(gesture_id)) {+ // The page of a nested context let the gesture through while nothing took its steps, so they go to that context+ // again rather than to the page.+ auto step = ContextState::WheelStep::for_wheel_event(event, gesture_id, operation_tracking);+ auto position = position_in_nested_context_ignoring_clips(context_id, context, *listener_context, step.position);+ if (!position.has_value())+ return ContextState::ContextUpdateResult::declined(Web::InputRoutingDecision::NestedContextUnavailable);+ step.position = *position;+ auto applied_step = route_wheel_step_the_page_let_through(context_id, context, listener_context_id, *listener_context, step, {}, nullptr, now);+ result = move(applied_step.result);+ result.nested_context_hand_off = Web::InputRoutingDecision::HandedToNestedContext;+ presents_frame = applied_step.presents_frame;+ } else {+ switch (origin) {+ case WheelStepOrigin::UI:+ result = context.handle_wheel_event(event, is_first_wheel_event_with_delta, listener_gate, now);+ break;+ case WheelStepOrigin::Fling:+ result = context.scroll_for_fling_step(event, listener_gate, now);+ break;+ case WheelStepOrigin::MainThread:+ result = context.scroll_for_wheel_event_from_main_thread(event, is_first_wheel_event_with_delta, listener_gate, operation_tracking, now);+ break;+ }+ presents_frame = result.frame_to_present.has_value();+ if (result.nested_context_wheel_step.has_value()) {+ auto applied_step = hand_wheel_step_to_nested_context(context_id, context, event, *result.nested_context_wheel_step, listener_gate, operation_tracking, now);+ result = move(applied_step.result);+ presents_frame = applied_step.presents_frame;+ }}// If the compositor accepts a momentum step of the fling but does not scroll, the scroller is at its edge.@@ -953,26 +977,27 @@ ContextState::ContextUpdateResult CompositorState::scroll_for_wheel_step(Web::Coreturn result;}-CompositorState::WheelStepHandedToNestedContext CompositorState::hand_wheel_step_to_nested_context(Web::CompositorContextId context_id, ContextState& context, Web::MouseEvent const& event, ContextState::NestedContextWheelStep const& nested_step, Compositing::AsyncScrollOperationTracking operation_tracking, MonotonicTime now)+CompositorState::AppliedWheelStep CompositorState::apply_wheel_step_result(Web::CompositorContextId context_id, ContextState& context, ContextState::ContextUpdateResult const& result, CompositorStateWebContentClient const& reporting_client){- auto step = ContextState::WheelStepFromContainingContext::for_wheel_event(event, context.wheel_gesture_id(), operation_tracking);- // The nested context presents and publishes what its step changed, and this context reports how the step went.- auto apply_result_of_nested_context = [&](Web::CompositorContextId nested_context_id, ContextState& nested_context, ContextState::ContextUpdateResult const& nested_result) {- apply_context_update_result(nested_context_id, nested_context, nested_result);- schedule_animation_frames_if_needed(nested_context);- // Node ids are only unique within the process that made them, and only that process follows the operations of- // the context.- bool ids_are_of_this_process = nested_context.is_owned_by(context.web_content_client());- return WheelStepHandedToNestedContext {- .result = {- .accepted = nested_result.accepted,- .routing_decision = nested_result.routing_decision,- .routed_scroller = ids_are_of_this_process ? nested_result.routed_scroller : Optional<Web::AsyncScrollNodeStableID> {},- .tracked_scroll_operation = ids_are_of_this_process ? nested_result.tracked_scroll_operation : Optional<ContextState::TrackedScrollOperation> {},- },- .nested_context_presents_frame = nested_result.frame_to_present.has_value(),- };+ apply_context_update_result(context_id, context, result);+ schedule_animation_frames_if_needed(context);+ // Node ids are only unique within the process that made them, and only that process follows the operations of the+ // context.+ bool ids_are_of_reporting_process = context.is_owned_by(reporting_client);+ return {+ .result = {+ .accepted = result.accepted,+ .routing_decision = result.routing_decision,+ .routed_scroller = ids_are_of_reporting_process ? result.routed_scroller : Optional<Web::AsyncScrollNodeStableID> {},+ .tracked_scroll_operation = ids_are_of_reporting_process ? result.tracked_scroll_operation : Optional<ContextState::TrackedScrollOperation> {},+ },+ .presents_frame = result.frame_to_present.has_value(),};+}++CompositorState::AppliedWheelStep CompositorState::hand_wheel_step_to_nested_context(Web::CompositorContextId context_id, ContextState& context, Web::MouseEvent const& event, ContextState::NestedContextWheelStep const& nested_step, ContextState::WheelEventListenerGate const& listener_gate, Compositing::AsyncScrollOperationTracking operation_tracking, MonotonicTime now)+{+ auto step = ContextState::WheelStep::for_wheel_event(event, context.wheel_gesture_id(), operation_tracking);if (!nested_step.hit.has_value()) {auto* nested_context = context_if_present(nested_step.context_id);@@ -980,49 +1005,59 @@ CompositorState::WheelStepHandedToNestedContext CompositorState::hand_wheel_stepcontext.forget_wheel_gesture_latch();return { ContextState::ContextUpdateResult::declined(Web::InputRoutingDecision::NestedContextUnavailable) };}- auto nested_result = nested_context->take_latched_wheel_step_from_containing_context(step, now);- // A step that the nested context leaves to the main thread for now, as a new blocking listener may cancel it,- // does not end the gesture there.+ // A blocking listener added during the gesture holds its later steps back until the page lets one through.+ if (listener_gate.reason_to_hold_latched_steps_back.has_value())+ return { ContextState::ContextUpdateResult::declined(*listener_gate.reason_to_hold_latched_steps_back) };+ auto admission = listener_gate.page_let_the_gesture_through ? ContextState::WheelStepAdmission::LetThroughByThePage : ContextState::WheelStepAdmission::ByThisPage;+ auto nested_result = nested_context->take_latched_wheel_step_from_containing_context(step, admission, now);if (nested_result.routing_decision == Web::InputRoutingDecision::NestedContextUnavailable)context.forget_wheel_gesture_latch();- return apply_result_of_nested_context(nested_step.context_id, *nested_context, nested_result);+ return apply_wheel_step_result(nested_step.context_id, *nested_context, nested_result, context.web_content_client());}- auto taking_context = nested_context_taking_first_wheel_step(context_id, *nested_step.hit, step.delta_in_css_pixels, step.wheel_delta_precision);+ auto first_step = first_wheel_step_in_nested_contexts(context_id, *nested_step.hit, step.delta_in_css_pixels, step.wheel_delta_precision);+ context.set_wheel_event_listener_context(first_step.innermost_context_id);+ auto& taking_context = first_step.taking_context;if (!taking_context.has_value()) {auto result = context.scroll_for_wheel_event_passed_on_by_nested_context(event, operation_tracking, now);result.nested_context_hand_off = Web::InputRoutingDecision::NestedContextPassedStepOn;- return { .result = result, .nested_context_presents_frame = result.frame_to_present.has_value() };+ return { .result = result, .presents_frame = result.frame_to_present.has_value() };}- WheelStepHandedToNestedContext handed_step;+ AppliedWheelStep applied_step;if (taking_context->context && taking_context->route.kind != ContextState::FirstWheelStepRoute::Kind::Declined) {step.position = taking_context->position;auto nested_result = taking_context->context->take_first_wheel_step_from_containing_context(taking_context->route, step, now);- handed_step = apply_result_of_nested_context(taking_context->context_id, *taking_context->context, nested_result);- context.latch_wheel_gesture_to_nested_context(taking_context->context_id, handed_step.result.routed_scroller, event);+ applied_step = apply_wheel_step_result(taking_context->context_id, *taking_context->context, nested_result, context.web_content_client());+ context.latch_wheel_gesture_to_nested_context(taking_context->context_id, applied_step.result.routed_scroller, step.scroll_gesture_phase);} else {- handed_step.result = ContextState::ContextUpdateResult::declined(taking_context->route.decision);+ applied_step.result = ContextState::ContextUpdateResult::declined(taking_context->route.decision);}- handed_step.result.nested_context_hand_off = Web::InputRoutingDecision::HandedToNestedContext;- return handed_step;+ applied_step.result.nested_context_hand_off = Web::InputRoutingDecision::HandedToNestedContext;+ return applied_step;}-Optional<CompositorState::NestedContextTakingWheelStep> CompositorState::nested_context_taking_first_wheel_step(Web::CompositorContextId context_id, Compositing::NestedContextHit hit, Gfx::FloatPoint delta_in_css_pixels, Web::WheelDeltaPrecision wheel_delta_precision)+CompositorState::FirstWheelStepInNestedContexts CompositorState::first_wheel_step_in_nested_contexts(Web::CompositorContextId context_id, Compositing::NestedContextHit hit, Gfx::FloatPoint delta_in_css_pixels, Web::WheelDeltaPrecision wheel_delta_precision){using Kind = ContextState::FirstWheelStepRoute::Kind;// The contexts the step went into, outermost first, each nested in the one before.Vector<NestedContextTakingWheelStep, 4> contexts;auto containing_context_id = context_id;while (true) {+ auto declined_by_unavailable_context = [&] {+ return FirstWheelStepInNestedContexts {+ .innermost_context_id = hit.child_context_id,+ .taking_context = NestedContextTakingWheelStep { .context_id = hit.child_context_id, .route = { Kind::Declined, Web::InputRoutingDecision::NestedContextUnavailable } },+ };+ };// WebContent names the contexts its display lists draw, so a context only reaches those nested in it.auto* nested_context = context_if_present(hit.child_context_id);if (!nested_context || nested_context->parent_context_id() != containing_context_id)- return NestedContextTakingWheelStep { .context_id = hit.child_context_id, .route = { Kind::Declined, Web::InputRoutingDecision::NestedContextUnavailable } };+ return declined_by_unavailable_context();auto position = position_in_nested_context(hit, *nested_context);if (!position.has_value())- return NestedContextTakingWheelStep { .context_id = hit.child_context_id, .route = { Kind::Declined, Web::InputRoutingDecision::NestedContextUnavailable } };- auto route = nested_context->route_first_wheel_step_from_containing_context(*position, delta_in_css_pixels, wheel_delta_precision, Compositing::NestedContextRegions::HandToNestedContext);+ return declined_by_unavailable_context();+ auto route = nested_context->route_first_wheel_step_from_containing_context(*position, delta_in_css_pixels, wheel_delta_precision, Compositing::NestedContextRegions::HandToNestedContext, ContextState::WheelStepAdmission::ByThisPage);contexts.append({ .context_id = hit.child_context_id, .context = nested_context, .position = *position, .route = route });if (route.kind != Kind::NestedContext)break;@@ -1030,15 +1065,86 @@ Optional<CompositorState::NestedContextTakingWheelStep> CompositorState::nested_hit = *route.nested_context_hit;}- // What a nested context passes on goes to whatever is painted under it in the context it is nested in.+ // What a nested context passes on goes to whatever is painted under it in the context it is nested in, whose page+ // does not see the step.+ auto innermost_context_id = contexts.last().context_id;while (contexts.last().route.kind == Kind::PassedOn) {contexts.take_last();if (contexts.is_empty())- return {};+ return { .innermost_context_id = innermost_context_id };auto& containing_context = contexts.last();- containing_context.route = containing_context.context->route_first_wheel_step_from_containing_context(containing_context.position, delta_in_css_pixels, wheel_delta_precision, Compositing::NestedContextRegions::Ignore);+ containing_context.route = containing_context.context->route_first_wheel_step_from_containing_context(containing_context.position, delta_in_css_pixels, wheel_delta_precision, Compositing::NestedContextRegions::Ignore, ContextState::WheelStepAdmission::PassedOnByNestedContext);}- return contexts.take_last();+ return { .innermost_context_id = innermost_context_id, .taking_context = contexts.take_last() };+}++// The page of one process scrolls a context of another process only by what the UI left to the page in the gesture, so+// that a page cannot scroll the document around it at will.+static bool page_may_scroll_in(ContextState const& context, ContextState& routing_context, CompositorStateWebContentClient const* page_client, ContextState::WheelStep const& step)+{+ return !page_client || context.is_owned_by(*page_client) || routing_context.take_wheel_delta_left_to_the_page(step.delta_in_css_pixels);+}++CompositorState::AppliedWheelStep CompositorState::route_wheel_step_the_page_let_through(Web::CompositorContextId routing_context_id, ContextState& routing_context, Web::CompositorContextId listener_context_id, ContextState& listener_context, ContextState::WheelStep step, ReadonlySpan<Web::AsyncScrollNodeStableID> scroll_chain, CompositorStateWebContentClient const* page_client, MonotonicTime now)+{+ using Kind = ContextState::FirstWheelStepRoute::Kind;+ auto const& reporting_client = page_client ? *page_client : routing_context.web_content_client();+ auto declined = [](Web::InputRoutingDecision decision) {+ return AppliedWheelStep { .result = ContextState::ContextUpdateResult::declined(decision) };+ };++ auto context_id = listener_context_id;+ auto* context = &listener_context;+ // A walk up the parents that outlasts the number of contexts went around a loop.+ for (size_t remaining_contexts = m_contexts.size(); remaining_contexts > 0; --remaining_contexts) {+ if (context == &routing_context) {+ if (!page_may_scroll_in(routing_context, routing_context, page_client, step))+ return declined(Web::InputRoutingDecision::StepExceedsInputLeftToThePage);+ auto result = routing_context.scroll_for_first_wheel_step_the_page_let_through(step, scroll_chain, now);+ return apply_wheel_step_result(routing_context_id, routing_context, result, reporting_client);+ }++ auto route = context->route_first_wheel_step_from_containing_context(step.position, step.delta_in_css_pixels, step.wheel_delta_precision, Compositing::NestedContextRegions::Ignore, ContextState::WheelStepAdmission::LetThroughByThePage, scroll_chain);+ if (first_is_one_of(route.kind, Kind::ScrollNode, Kind::Kept)) {+ if (!page_may_scroll_in(*context, routing_context, page_client, step))+ return declined(Web::InputRoutingDecision::StepExceedsInputLeftToThePage);+ auto nested_result = context->take_first_wheel_step_from_containing_context(route, step, now);+ auto latched_scroller = context->is_owned_by(routing_context.web_content_client()) ? nested_result.routed_scroller : Optional<Web::AsyncScrollNodeStableID> {};+ routing_context.latch_wheel_gesture_to_nested_context(context_id, latched_scroller, step.scroll_gesture_phase);+ return apply_wheel_step_result(context_id, *context, nested_result, reporting_client);+ }+ if (route.kind != Kind::PassedOn)+ return declined(route.decision);++ // What a nested context passes on goes to whatever is painted under it in the context it is nested in.+ auto parent_context_id = context->parent_context_id();+ auto* parent_context = parent_context_id.has_value() ? context_if_present(*parent_context_id) : nullptr;+ if (!parent_context)+ return declined(Web::InputRoutingDecision::NestedContextUnavailable);+ auto position = parent_context->position_of_nested_context_position(context_id, step.position, context->presenter().viewport_size());+ if (!position.has_value())+ return declined(Web::InputRoutingDecision::NestedContextUnavailable);+ step.position = *position;+ scroll_chain = {};+ context_id = *parent_context_id;+ context = parent_context;+ }+ return declined(Web::InputRoutingDecision::NestedContextUnavailable);+}++Optional<Web::CompositorContextId> CompositorState::routing_context_of_wheel_gesture(Web::CompositorContextId context_id, u64 gesture_id)+{+ // A walk up the parents that outlasts the number of contexts went around a loop.+ Optional<Web::CompositorContextId> candidate_context_id = context_id;+ for (size_t remaining_contexts = m_contexts.size(); candidate_context_id.has_value() && remaining_contexts > 0; --remaining_contexts) {+ auto* candidate_context = context_if_present(*candidate_context_id);+ if (!candidate_context)+ return {};+ if (candidate_context->wheel_gesture_id() == gesture_id)+ return candidate_context_id;+ candidate_context_id = candidate_context->parent_context_id();+ }+ return {};}void CompositorState::dispatch_scroll_fling_step(Web::CompositorContextId context_id, ContextState& context, Optional<Web::MouseEvent> event, MonotonicTime now)@@ -1052,6 +1158,8 @@ void CompositorState::dispatch_scroll_fling_step(Web::CompositorContextId contexif (result.routing_decision.has_value())context.input_trace().record({ .input_event_id = event->id, .stage = Web::InputTraceStage::Compositor, .decision = *result.routing_decision, .scroller = result.routed_scroller });event->async_scroll_performed_default_action = apply_context_update_result(context_id, context, result);+ if (!event->async_scroll_performed_default_action)+ context.note_wheel_event_left_to_the_page(*event);schedule_animation_frames_if_needed(context);context.dispatch_mouse_event_to_web_content(*event);}@@ -1089,45 +1197,105 @@ void CompositorState::handle_and_dispatch_pinch_event(Web::CompositorContextId ccontext->dispatch_pinch_event_to_web_content(event);}-Compositing::WheelEventAnswer CompositorState::take_wheel_event_from_main_thread(Web::CompositorContextId context_id, Web::MouseEvent const& event, Compositing::AsyncScrollOperationTracking operation_tracking, Compositing::WheelEventScrolling scrolling)+Compositing::WheelEventAnswer CompositorState::wheel_event_answer_for(AppliedWheelStep const& applied_step, Optional<Web::WheelGestureMark> wheel_gesture_mark)+{+ auto const& tracked_scroll_operation = applied_step.result.tracked_scroll_operation;+ return {+ .performed_default_action = applied_step.result.accepted,+ .wheel_gesture_mark = wheel_gesture_mark,+ .operation_id = tracked_scroll_operation.map([](auto const& operation) { return operation.operation_id; }),+ .operation_context_id = tracked_scroll_operation.map([](auto const& operation) { return operation.context_id; }),+ .routing_decision = applied_step.result.routing_decision,+ .routed_scroller = applied_step.result.routed_scroller,+ };+}++Compositing::WheelEventAnswer CompositorState::take_wheel_event_from_main_thread(Web::CompositorContextId context_id, Web::MouseEvent const& event, Compositing::AsyncScrollOperationTracking operation_tracking, Compositing::WheelEventRouting routing){auto* context = context_if_present(context_id);VERIFY(context);auto now = MonotonicTime::now();auto noted = context->note_wheel_event_from_main_thread(event, now);- if (scrolling == Compositing::WheelEventScrolling::ByMainThread)+ if (routing == Compositing::WheelEventRouting::AfterDispatch)return { .wheel_gesture_mark = noted.wheel_gesture_mark };auto result = scroll_for_wheel_step(context_id, *context, event, WheelStepOrigin::MainThread, noted.is_first_wheel_event_with_delta, operation_tracking, now);- auto performed_default_action = apply_context_update_result(context_id, *context, result);- schedule_animation_frames_if_needed(*context);- auto const& tracked_scroll_operation = result.tracked_scroll_operation;- return {- .performed_default_action = performed_default_action,- .wheel_gesture_mark = noted.wheel_gesture_mark,- .operation_id = tracked_scroll_operation.map([](auto const& operation) { return operation.operation_id; }),- .operation_context_id = tracked_scroll_operation.map([](auto const& operation) { return operation.context_id; }),- .routing_decision = result.routing_decision,- .routed_scroller = result.routed_scroller,- };+ return wheel_event_answer_for(apply_wheel_step_result(context_id, *context, result, context->web_content_client()), noted.wheel_gesture_mark);}-Compositing::AsyncScrollEnqueueResult CompositorState::async_scroll_by(Web::CompositorContextId context_id, Web::UniqueNodeID expected_document_id, Gfx::FloatPoint position, Gfx::FloatPoint delta, Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, Compositing::AsyncScrollOperationTracking operation_tracking, Compositing::WheelStepDispatch wheel_step_dispatch, Optional<u64> wheel_gesture_id, u64 input_event_id)+Compositing::WheelEventAnswer CompositorState::scroll_for_wheel_event_the_page_let_through(Web::CompositorContextId listener_context_id, Compositing::WheelStepLetThrough const& let_through, Compositing::AsyncScrollOperationTracking operation_tracking, CompositorStateWebContentClient const& page_client){- auto* context = context_if_present(context_id);- VERIFY(context);+ auto* listener_context = context_if_present(listener_context_id);+ VERIFY(listener_context);+ if (listener_context->document_id() != let_through.document_id)+ return { .routing_decision = Web::InputRoutingDecision::ScrollerInOtherDocument };- auto result = context->async_scroll_by(expected_document_id, position, delta, viewport_rect, wheel_delta_precision, scroll_gesture_phase, operation_tracking, wheel_step_dispatch, wheel_gesture_id, input_event_id);- if (result.frame_to_present.has_value())- schedule_present_frame(context_id, *context, *result.frame_to_present);- schedule_animation_frames_if_needed(*context);- // The process adopts the offsets a scroll moved in its next rendering update, which nothing else need prompt when- // the context presents through another process's.- if (result.enqueue_result.accepted)- context->request_rendering_update();- else- publish_pending_async_scroll_updates(context_id, *context);- return result.enqueue_result;+ auto now = MonotonicTime::now();+ auto gesture_id = let_through.wheel_gesture_mark.gesture_id;+ listener_context->note_page_let_wheel_gesture_through(gesture_id);+ ContextState::WheelStep step {+ .position = let_through.position,+ .delta_in_css_pixels = let_through.delta_in_css_pixels,+ .wheel_delta_precision = let_through.wheel_delta_precision,+ .scroll_gesture_phase = let_through.scroll_gesture_phase,+ .gesture_id = gesture_id,+ .operation_tracking = operation_tracking,+ };+ auto scroll_chain = let_through.scroll_chain.span();+ auto answer = [&](AppliedWheelStep const& applied_step) { return wheel_event_answer_for(applied_step, let_through.wheel_gesture_mark); };+ auto declined = [&](Web::InputRoutingDecision decision) { return answer({ .result = ContextState::ContextUpdateResult::declined(decision) }); };++ // A step of a gesture that the contexts around the page have moved past still scrolls, as the page let it.+ auto routing_context_id = routing_context_of_wheel_gesture(listener_context_id, gesture_id);+ auto* routing_context = routing_context_id.has_value() ? context_if_present(*routing_context_id) : nullptr;+ if (!routing_context || routing_context->wheel_step_was_overtaken_by_ui(step.scroll_gesture_phase, let_through.input_event_id)) {+ auto result = listener_context->scroll_for_wheel_step_overtaken_by_ui(step, scroll_chain, now);+ return answer(apply_wheel_step_result(listener_context_id, *listener_context, result, page_client));+ }++ routing_context->set_wheel_event_listener_context(listener_context_id);+ // The end of a gesture lets go of the scroller it stretched.+ if (step.scroll_gesture_phase == Web::ScrollGesturePhase::Ended)+ routing_context->end_wheel_gesture_stretch(now);++ // A latched scroller that the page no longer has around the target of the step is gone from the page, and the step+ // is routed afresh.+ bool latch_is_to_scroller_of_this_page = *routing_context_id == listener_context_id && !routing_context->nested_context_of_wheel_latch().has_value();+ if (latch_is_to_scroller_of_this_page && !scroll_chain.is_empty()) {+ if (auto latched_scroller = routing_context->wheel_latched_scroller(); latched_scroller.has_value() && !scroll_chain.contains_slow(*latched_scroller))+ routing_context->forget_wheel_latch_of_gesture(gesture_id);+ }++ if (routing_context->has_wheel_latch_for_gesture(gesture_id)) {+ if (auto nested_context_id = routing_context->nested_context_of_wheel_latch(); nested_context_id.has_value()) {+ auto* nested_context = context_still_nested_in(*routing_context_id, nested_context_id);+ if (!nested_context) {+ routing_context->forget_wheel_latch_of_gesture(gesture_id);+ return declined(Web::InputRoutingDecision::NestedContextUnavailable);+ }+ if (!page_may_scroll_in(*nested_context, *routing_context, &page_client, step))+ return declined(Web::InputRoutingDecision::StepExceedsInputLeftToThePage);+ auto nested_result = nested_context->take_latched_wheel_step_from_containing_context(step, ContextState::WheelStepAdmission::LetThroughByThePage, now);+ return answer(apply_wheel_step_result(*nested_context_id, *nested_context, nested_result, page_client));+ }+ if (!page_may_scroll_in(*routing_context, *routing_context, &page_client, step))+ return declined(Web::InputRoutingDecision::StepExceedsInputLeftToThePage);+ if (auto result = routing_context->scroll_for_latched_wheel_step_the_page_let_through(step, now); result.has_value())+ return answer(apply_wheel_step_result(*routing_context_id, *routing_context, *result, page_client));+ }++ return answer(route_wheel_step_the_page_let_through(*routing_context_id, *routing_context, listener_context_id, *listener_context, step, scroll_chain, &page_client, now));+}++void CompositorState::forget_wheel_gesture_the_page_canceled(Web::CompositorContextId listener_context_id, u64 gesture_id)+{+ auto* listener_context = context_if_present(listener_context_id);+ if (!listener_context)+ return;+ listener_context->forget_page_let_wheel_gesture_through(gesture_id);+ // The listener scrolls by itself, so the next step of the gesture is routed afresh.+ if (auto routing_context_id = routing_context_of_wheel_gesture(listener_context_id, gesture_id); routing_context_id.has_value())+ context_if_present(*routing_context_id)->forget_wheel_latch_of_gesture(gesture_id);}static bool scroll_request_scrolls_for_script(Compositing::ScrollRequest const& scroll_request)@@ -1785,7 +1953,7 @@ Optional<Compositing::FirstWheelStepRouteForTesting> CompositorState::route_firsauto hit = context->nested_context_for_wheel_at(position);if (!hit.has_value())return context->route_first_wheel_step_for_testing(position, delta_in_css_pixels, Compositing::NestedContextRegions::HandToNestedContext);- auto taking_context = nested_context_taking_first_wheel_step(context_id, *hit, delta_in_css_pixels, Web::WheelDeltaPrecision::Precise);+ auto taking_context = first_wheel_step_in_nested_contexts(context_id, *hit, delta_in_css_pixels, Web::WheelDeltaPrecision::Precise).taking_context;if (!taking_context.has_value())return context->route_first_wheel_step_for_testing(position, delta_in_css_pixels, Compositing::NestedContextRegions::Ignore);// Node ids are only unique within the process that made them.diff --git a/Services/Compositor/CompositorState.h b/Services/Compositor/CompositorState.hindex 4a6d356ba66..57e037fc244 100644--- a/Services/Compositor/CompositorState.h+++ b/Services/Compositor/CompositorState.h@@ -131,8 +131,12 @@ public:void handle_and_dispatch_mouse_event(Web::CompositorContextId, Web::MouseEvent);void handle_and_dispatch_pinch_event(Web::CompositorContextId, Web::PinchEvent);// Routes a wheel event the UI did not send here, such as one a test makes, as the UI's wheel events are routed.- Compositing::WheelEventAnswer take_wheel_event_from_main_thread(Web::CompositorContextId, Web::MouseEvent const&, Compositing::AsyncScrollOperationTracking, Compositing::WheelEventScrolling);- Compositing::AsyncScrollEnqueueResult async_scroll_by(Web::CompositorContextId, Web::UniqueNodeID document_id, Gfx::FloatPoint position, Gfx::FloatPoint delta, Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, Compositing::AsyncScrollOperationTracking, Compositing::WheelStepDispatch, Optional<u64> wheel_gesture_id, u64 input_event_id);+ Compositing::WheelEventAnswer take_wheel_event_from_main_thread(Web::CompositorContextId, Web::MouseEvent const&, Compositing::AsyncScrollOperationTracking, Compositing::WheelEventRouting);+ // Scrolls by a step that the page of the context dispatched and did not cancel. The context that routes the+ // gesture is the nearest one, from that context out to the presenting one, that noted the gesture, and the steps the+ // compositor still has to route of the gesture no longer wait for the page.+ Compositing::WheelEventAnswer scroll_for_wheel_event_the_page_let_through(Web::CompositorContextId, Compositing::WheelStepLetThrough const&, Compositing::AsyncScrollOperationTracking, CompositorStateWebContentClient const& page_client);+ void forget_wheel_gesture_the_page_canceled(Web::CompositorContextId, u64 gesture_id);void apply_scroll_requests(Web::CompositorContextId, ReadonlySpan<Compositing::ScrollRequest>);void viewport_size_updated(Web::CompositorContextId, Gfx::IntSize, double device_pixel_ratio, Compositing::WindowResizingInProgress);void request_rendering_opportunity(Web::CompositorContextId, double maximum_frames_per_second);@@ -247,12 +251,16 @@ private:};// A fling step is scrolled at the frame time the fling synthesized it for.ContextState::ContextUpdateResult scroll_for_wheel_step(Web::CompositorContextId, ContextState&, Web::MouseEvent const&, WheelStepOrigin, bool is_first_wheel_event_with_delta, Compositing::AsyncScrollOperationTracking, MonotonicTime now);- struct WheelStepHandedToNestedContext {- // What is left for the context the step was handed from to present and report.+ // How a wheel step went in a context that presented and published what the step changed itself.+ struct AppliedWheelStep {+ // What is left for the context that routes the step to present and report.ContextState::ContextUpdateResult result;- bool nested_context_presents_frame { false };+ bool presents_frame { false };};- WheelStepHandedToNestedContext hand_wheel_step_to_nested_context(Web::CompositorContextId, ContextState&, Web::MouseEvent const&, ContextState::NestedContextWheelStep const&, Compositing::AsyncScrollOperationTracking, MonotonicTime now);+ // A process only knows the ids of its own nodes, and only follows the operations of its own contexts.+ AppliedWheelStep apply_wheel_step_result(Web::CompositorContextId, ContextState&, ContextState::ContextUpdateResult const&, CompositorStateWebContentClient const& reporting_client);+ static Compositing::WheelEventAnswer wheel_event_answer_for(AppliedWheelStep const&, Optional<Web::WheelGestureMark>);+ AppliedWheelStep hand_wheel_step_to_nested_context(Web::CompositorContextId, ContextState&, Web::MouseEvent const&, ContextState::NestedContextWheelStep const&, ContextState::WheelEventListenerGate const&, Compositing::AsyncScrollOperationTracking, MonotonicTime now);struct NestedContextTakingWheelStep {Web::CompositorContextId context_id;// Null when the step cannot be handed to the context.@@ -260,9 +268,22 @@ private:Gfx::FloatPoint position {};ContextState::FirstWheelStepRoute route;};- // The context that takes the first step of a gesture over the content of a context nested in the context- // `context_id`, among that context and the contexts nested in it. Empty when each of them passes the step on.- Optional<NestedContextTakingWheelStep> nested_context_taking_first_wheel_step(Web::CompositorContextId, Compositing::NestedContextHit, Gfx::FloatPoint delta_in_css_pixels, Web::WheelDeltaPrecision);+ struct FirstWheelStepInNestedContexts {+ // The innermost context that the step went into, whose page sees the step.+ Web::CompositorContextId innermost_context_id;+ // The context that takes the step, which is empty when each of them passes the step on.+ Optional<NestedContextTakingWheelStep> taking_context {};+ };+ // Where the first step of a gesture over the content of a context nested in the context `context_id` goes, among+ // that context and the contexts nested in it.+ FirstWheelStepInNestedContexts first_wheel_step_in_nested_contexts(Web::CompositorContextId, Compositing::NestedContextHit, Gfx::FloatPoint delta_in_css_pixels, Web::WheelDeltaPrecision);+ // Routes the first step of a gesture that the page of the listener context let through: in that context, from the+ // scrollers the page found around the target, and on to the contexts around it for what a context passes on, up to+ // the routing context, which latches the gesture. A page of another process than a context's scrolls it only by+ // what the UI left to the page in the gesture.+ AppliedWheelStep route_wheel_step_the_page_let_through(Web::CompositorContextId routing_context_id, ContextState& routing_context, Web::CompositorContextId listener_context_id, ContextState& listener_context, ContextState::WheelStep, ReadonlySpan<Web::AsyncScrollNodeStableID> scroll_chain, CompositorStateWebContentClient const* page_client, MonotonicTime now);+ // The nearest context, from the given one out to the presenting one, that noted the gesture.+ Optional<Web::CompositorContextId> routing_context_of_wheel_gesture(Web::CompositorContextId, u64 gesture_id);// The scrollbars of a context nested in the presenting context `context_id` take the pointer over that context's// content, and a drag of one of them takes the pointer wherever it goes until the drag ends.ContextState::ContextUpdateResult handle_mouse_event_in_nested_contexts(Web::CompositorContextId, ContextState&, Web::MouseEvent const&);diff --git a/Services/Compositor/CompositorWebContentServer.ipc b/Services/Compositor/CompositorWebContentServer.ipcindex e2ca6dab802..3fa29959c39 100644--- a/Services/Compositor/CompositorWebContentServer.ipc+++ b/Services/Compositor/CompositorWebContentServer.ipc@@ -69,8 +69,9 @@ endpoint CompositorWebContentServerinvalidate_wheel_event_listener_state(Web::CompositorContextId context_id, u64 generation) =|invalidate_keyboard_scroll_state(Web::CompositorContextId context_id, u64 generation) => ()- take_wheel_event_from_main_thread(Web::CompositorContextId context_id, Web::MouseEvent event, Compositing::AsyncScrollOperationTracking operation_tracking, Compositing::WheelEventScrolling scrolling) => (Compositing::WheelEventAnswer answer)- async_scroll_by(Web::CompositorContextId context_id, Web::UniqueNodeID document_id, Gfx::FloatPoint position, Gfx::FloatPoint delta, Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, Compositing::AsyncScrollOperationTracking operation_tracking, Compositing::WheelStepDispatch wheel_step_dispatch, Optional<u64> wheel_gesture_id, u64 input_event_id) => (Compositing::AsyncScrollEnqueueResult result)+ take_wheel_event_from_main_thread(Web::CompositorContextId context_id, Web::MouseEvent event, Compositing::AsyncScrollOperationTracking operation_tracking, Compositing::WheelEventRouting routing) => (Compositing::WheelEventAnswer answer)+ wheel_event_let_through(Web::CompositorContextId context_id, Compositing::WheelStepLetThrough step, Compositing::AsyncScrollOperationTracking operation_tracking) => (Compositing::WheelEventAnswer answer)+ wheel_event_canceled(Web::CompositorContextId context_id, u64 wheel_gesture_id) =|apply_scroll_requests(Web::CompositorContextId context_id, Vector<Compositing::ScrollRequest> scroll_requests) =|scroll_state_for_testing(Web::CompositorContextId context_id, Web::AsyncScrollNodeStableID stretched_scroller) => (String scroll_state)// Returns once the compositor has handled every message WebContent sent before it.diff --git a/Services/Compositor/ConnectionFromWebContent.cpp b/Services/Compositor/ConnectionFromWebContent.cppindex 4e7031269a0..774e34bc116 100644--- a/Services/Compositor/ConnectionFromWebContent.cpp+++ b/Services/Compositor/ConnectionFromWebContent.cpp@@ -485,32 +485,44 @@ void ConnectionFromWebContent::invalidate_wheel_event_listener_state(Web::Composm_compositor_state->invalidate_wheel_event_listener_state(context_id, generation);}+// Wheel deltas are scrolled by as floats.+static bool is_valid_wheel_delta(double delta)+{+ return isfinite(delta) && fabs(delta) <= NumericLimits<float>::max();+}+static bool is_valid_wheel_event(Web::MouseEvent const& event){- // Wheel deltas are scrolled by as floats.- auto is_valid_wheel_delta = [](double delta) {- return isfinite(delta) && fabs(delta) <= NumericLimits<float>::max();- };return event.type == Web::MouseEvent::Type::MouseWheel&& is_valid_wheel_delta(event.wheel_delta_x)&& is_valid_wheel_delta(event.wheel_delta_y);}-Messages::CompositorWebContentServer::TakeWheelEventFromMainThreadResponse ConnectionFromWebContent::take_wheel_event_from_main_thread(Web::CompositorContextId context_id, Web::MouseEvent event, Compositing::AsyncScrollOperationTracking operation_tracking, Compositing::WheelEventScrolling scrolling)+static bool is_valid_wheel_step_let_through(Compositing::WheelStepLetThrough const& step)+{+ return isfinite(step.position.x()) && isfinite(step.position.y())+ && isfinite(step.delta_in_css_pixels.x()) && isfinite(step.delta_in_css_pixels.y());+}++Messages::CompositorWebContentServer::TakeWheelEventFromMainThreadResponse ConnectionFromWebContent::take_wheel_event_from_main_thread(Web::CompositorContextId context_id, Web::MouseEvent event, Compositing::AsyncScrollOperationTracking operation_tracking, Compositing::WheelEventRouting routing){if (!context_is_owned_by_this_connection(context_id) || !is_valid_wheel_event(event))return Compositing::WheelEventAnswer {};- return m_compositor_state->take_wheel_event_from_main_thread(context_id, event, operation_tracking, scrolling);+ return m_compositor_state->take_wheel_event_from_main_thread(context_id, event, operation_tracking, routing);+}++Messages::CompositorWebContentServer::WheelEventLetThroughResponse ConnectionFromWebContent::wheel_event_let_through(Web::CompositorContextId context_id, Compositing::WheelStepLetThrough step, Compositing::AsyncScrollOperationTracking operation_tracking)+{+ if (!context_is_owned_by_this_connection(context_id) || !is_valid_wheel_step_let_through(step))+ return Compositing::WheelEventAnswer {};+ return m_compositor_state->scroll_for_wheel_event_the_page_let_through(context_id, step, operation_tracking, *this);}-Messages::CompositorWebContentServer::AsyncScrollByResponse ConnectionFromWebContent::async_scroll_by(Web::CompositorContextId context_id, Web::UniqueNodeID document_id, Gfx::FloatPoint position, Gfx::FloatPoint delta, Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, Compositing::AsyncScrollOperationTracking operation_tracking, Compositing::WheelStepDispatch wheel_step_dispatch, Optional<u64> wheel_gesture_id, u64 input_event_id)+void ConnectionFromWebContent::wheel_event_canceled(Web::CompositorContextId context_id, u64 wheel_gesture_id){if (!context_is_owned_by_this_connection(context_id))- return Compositing::AsyncScrollEnqueueResult {};- auto result = m_compositor_state->async_scroll_by(context_id, document_id, position, delta, viewport_rect, wheel_delta_precision, scroll_gesture_phase, operation_tracking, wheel_step_dispatch, wheel_gesture_id, input_event_id);- if (result.accepted)- async_request_rendering_update();- return result;+ return;+ m_compositor_state->forget_wheel_gesture_the_page_canceled(context_id, wheel_gesture_id);}static bool is_valid_scroll_request(Compositing::ScrollRequest const& scroll_request)diff --git a/Services/Compositor/ConnectionFromWebContent.h b/Services/Compositor/ConnectionFromWebContent.hindex 67a12dd8d37..885655fd787 100644--- a/Services/Compositor/ConnectionFromWebContent.h+++ b/Services/Compositor/ConnectionFromWebContent.h@@ -77,8 +77,9 @@ private:virtual Messages::CompositorWebContentServer::WebglReadBufferSubDataResponse webgl_read_buffer_sub_data(Compositing::CanvasId canvas_id, u32 target, i64 offset, i64 size, Core::AnonymousBuffer data) override;virtual void invalidate_wheel_event_listener_state(Web::CompositorContextId, u64 generation) override;virtual void invalidate_keyboard_scroll_state(Web::CompositorContextId, u64 generation) override;- virtual Messages::CompositorWebContentServer::TakeWheelEventFromMainThreadResponse take_wheel_event_from_main_thread(Web::CompositorContextId, Web::MouseEvent, Compositing::AsyncScrollOperationTracking, Compositing::WheelEventScrolling) override;- virtual Messages::CompositorWebContentServer::AsyncScrollByResponse async_scroll_by(Web::CompositorContextId, Web::UniqueNodeID document_id, Gfx::FloatPoint position, Gfx::FloatPoint delta, Gfx::IntRect viewport_rect, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, Compositing::AsyncScrollOperationTracking, Compositing::WheelStepDispatch, Optional<u64> wheel_gesture_id, u64 input_event_id) override;+ virtual Messages::CompositorWebContentServer::TakeWheelEventFromMainThreadResponse take_wheel_event_from_main_thread(Web::CompositorContextId, Web::MouseEvent, Compositing::AsyncScrollOperationTracking, Compositing::WheelEventRouting) override;+ virtual Messages::CompositorWebContentServer::WheelEventLetThroughResponse wheel_event_let_through(Web::CompositorContextId, Compositing::WheelStepLetThrough, Compositing::AsyncScrollOperationTracking) override;+ virtual void wheel_event_canceled(Web::CompositorContextId, u64 wheel_gesture_id) override;virtual void apply_scroll_requests(Web::CompositorContextId, Vector<Compositing::ScrollRequest>) override;virtual Messages::CompositorWebContentServer::ScrollStateForTestingResponse scroll_state_for_testing(Web::CompositorContextId, Web::AsyncScrollNodeStableID) override;virtual void synchronize_for_testing() override { }diff --git a/Services/Compositor/ContextState.cpp b/Services/Compositor/ContextState.cppindex 4db1c538fe3..88ddc42b4de 100644--- a/Services/Compositor/ContextState.cpp+++ b/Services/Compositor/ContextState.cpp@@ -960,108 +960,6 @@ ContextState::NodeScrollByWheelDelta ContextState::scroll_node_by_wheel_delta(Coreturn { outcome, delta_the_node_did_not_scroll_by };}-ContextState::AsyncScrollResult ContextState::async_scroll_by(- Web::UniqueNodeID expected_document_id,- Gfx::FloatPoint position,- Gfx::FloatPoint delta,- Gfx::IntRect viewport_rect,- Web::WheelDeltaPrecision wheel_delta_precision,- Web::ScrollGesturePhase scroll_gesture_phase,- Compositing::AsyncScrollOperationTracking operation_tracking,- Compositing::WheelStepDispatch wheel_step_dispatch,- Optional<u64> wheel_gesture_id_from_mark,- u64 input_event_id,- Optional<MonotonicTime> now_for_testing)-{- auto now = now_for_testing.value_or(MonotonicTime::now());-- // Nothing hit tests a wheel before the first display list shows where the scrollers are, and the page can let a- // touchpad step through to here before then.- if (!m_has_async_scrolling_state)- return AsyncScrollResult::declined(Web::InputRoutingDecision::NoAsyncScrollingState);-- // The UI hands this context every wheel event before WebContent's main thread passes it on. A step that the main- // thread passes on after the UI sent one it cannot come before must neither latch a scroller nor pull a stretch,- // 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 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)- m_elastic_overscroll_controller.end_gesture(now);-- // Blocking wheel event listeners have nothing left to hold back once the page has dispatched a step and did not- // cancel it. The compositor then scrolls the step of a touchpad gesture, so that the gesture stretches the edges- // it pulls past as it does where nothing holds its steps back.- bool page_let_touchpad_step_through = wheel_step_dispatch == Compositing::WheelStepDispatch::DispatchedAndNotCanceled- && step_came_from_ui- && wheel_delta_precision == Web::WheelDeltaPrecision::Precise- && first_is_one_of(scroll_gesture_phase, Web::ScrollGesturePhase::Ongoing, Web::ScrollGesturePhase::Momentum);- bool only_blocking_wheel_event_listeners_hold_steps_back = m_wheel_gesture_routing.only_blocking_wheel_event_listeners_hold_steps_back();-- // The presenting context noted the gesture of the step as the step arrived. A context nested in another one knows- // the gesture only from the mark of the event.- auto gesture_id = presents_to_client() ? m_wheel_gesture_routing.gesture_id() : wheel_gesture_id_from_mark;- auto latch = resolve_wheel_scroll_latch(scroll_gesture_phase, gesture_id);- // The compositor hands every step of a gesture latched to a nested context's scroller to that context itself.- if (latch.nested_context_id.has_value())- return AsyncScrollResult::declined(Web::InputRoutingDecision::ScrollerInOtherDocument);- auto latched_scroll_node_index = latch.scroll_node_index;-- if (!m_wheel_gesture_routing.admits_async_wheel()- && !step_continues_touchpad_gesture_the_page_let_through(latched_scroll_node_index, wheel_delta_precision, scroll_gesture_phase)- && !(page_let_touchpad_step_through && only_blocking_wheel_event_listeners_hold_steps_back))- 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);-- // 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);- if (!operation_id.has_value())- return AsyncScrollResult::declined(Web::InputRoutingDecision::GestureEndWithNothingToSnap);- m_async_scrolling_viewport_rect = viewport_rect;- return {- .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_scroll_node_index.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;- auto latch_attempt = hit_test_and_latch_wheel_gesture(position, delta, wheel_delta_precision, scroll_gesture_phase, gesture_id, expected_document_id, wheel_step_dispatch_for_hit_test, Compositing::NestedContextRegions::LeaveToMainThread);- if (!latch_attempt.latched_scroll_node_index.has_value())- return AsyncScrollResult::declined(latch_attempt.decision);- latched_scroll_node_index = latch_attempt.latched_scroll_node_index;- routing_decision = latch_attempt.decision;- } else if (m_async_scroll_tree.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 AsyncScrollResult::declined(Web::InputRoutingDecision::ScrollerInOtherDocument);- }- if (page_let_touchpad_step_through)- m_wheel_gesture_routing.note_page_let_latched_gesture_through();-- auto scroll_chaining = is_first_step_of_gesture ? Compositing::ScrollChaining::ToScrollableAncestors : Compositing::ScrollChaining::None;- auto outcome = perform_wheel_scroll_of_node(*latched_scroll_node_index, delta, wheel_delta_precision, scroll_gesture_phase, operation_tracking, viewport_rect, now, scroll_chaining, VisualViewportPanning::No);- return {- .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); }),- };-}-void ContextState::note_user_input_scrolled(Web::AsyncScrollNodeStableID stable_node_id){m_user_input_scroll_counts.ensure(stable_node_id)++;@@ -1485,20 +1383,20 @@ Optional<Gfx::IntRect> ContextState::advance_smooth_scroll_animations(MonotonicTreturn {};}-ContextState::ContextUpdateResult ContextState::handle_wheel_event(Web::MouseEvent const& event, bool is_first_wheel_event_with_delta, Optional<MonotonicTime> now_for_testing)+ContextState::ContextUpdateResult ContextState::handle_wheel_event(Web::MouseEvent const& event, bool is_first_wheel_event_with_delta, WheelEventListenerGate const& listener_gate, Optional<MonotonicTime> now_for_testing){VERIFY(event.type == Web::MouseEvent::Type::MouseWheel);if (!presents_to_client())return ContextUpdateResult::declined(Web::InputRoutingDecision::ContextNotPresenting);auto now = now_for_testing.value_or(MonotonicTime::now());m_scroll_fling_controller.note_wheel_event(event, now);- return scroll_for_wheel_event(event, is_first_wheel_event_with_delta, Compositing::AsyncScrollOperationTracking::No, now);+ return scroll_for_wheel_event(event, is_first_wheel_event_with_delta, listener_gate, Compositing::AsyncScrollOperationTracking::No, now);}-ContextState::ContextUpdateResult ContextState::scroll_for_wheel_event_from_main_thread(Web::MouseEvent const& event, bool is_first_wheel_event_with_delta, Compositing::AsyncScrollOperationTracking operation_tracking, MonotonicTime now)+ContextState::ContextUpdateResult ContextState::scroll_for_wheel_event_from_main_thread(Web::MouseEvent const& event, bool is_first_wheel_event_with_delta, WheelEventListenerGate const& listener_gate, Compositing::AsyncScrollOperationTracking operation_tracking, MonotonicTime now){VERIFY(event.type == Web::MouseEvent::Type::MouseWheel);- return scroll_for_wheel_event(event, is_first_wheel_event_with_delta, operation_tracking, now);+ return scroll_for_wheel_event(event, is_first_wheel_event_with_delta, listener_gate, operation_tracking, now);}static Gfx::FloatPoint wheel_event_position(Web::MouseEvent const& event)@@ -1519,9 +1417,17 @@ Gfx::FloatPoint ContextState::wheel_event_delta_in_device_pixels(Web::MouseEvent.scaled(static_cast<float>(m_async_scroll_tree.device_pixels_per_css_pixel()));}-bool ContextState::step_continues_touchpad_gesture_the_page_let_through(Optional<Compositing::SpatialNodeIndex> const& latched_scroll_node_index, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase) const+ContextState::WheelEventListenerGate ContextState::wheel_event_listener_gate(Optional<u64> gesture_id) const{- return latched_scroll_node_index.has_value() && presents_to_client() && m_wheel_gesture_routing.page_let_latched_touchpad_gesture_through(wheel_delta_precision, scroll_gesture_phase);+ return {+ .page_let_the_gesture_through = m_wheel_gesture_routing.page_let_gesture_through(gesture_id),+ .reason_to_hold_latched_steps_back = m_wheel_gesture_routing.reason_to_hold_latched_steps_back(gesture_id),+ };+}++void ContextState::note_wheel_event_left_to_the_page(Web::MouseEvent const& event)+{+ m_wheel_gesture_routing.note_delta_left_to_the_page(WheelStep::for_wheel_event(event, {}, Compositing::AsyncScrollOperationTracking::No).delta_in_css_pixels);}ContextState::NotedWheelEvent ContextState::note_wheel_event(Web::MouseEvent const& event, MonotonicTime now)@@ -1632,11 +1538,11 @@ Optional<Web::MouseEvent> ContextState::end_scroll_fling()return m_scroll_fling_controller.end();}-ContextState::ContextUpdateResult ContextState::scroll_for_fling_step(Web::MouseEvent const& event, MonotonicTime now)+ContextState::ContextUpdateResult ContextState::scroll_for_fling_step(Web::MouseEvent const& event, WheelEventListenerGate const& listener_gate, MonotonicTime now){if (!presents_to_client())return ContextUpdateResult::declined(Web::InputRoutingDecision::ContextNotPresenting);- return scroll_for_wheel_event(event, false, Compositing::AsyncScrollOperationTracking::No, now);+ return scroll_for_wheel_event(event, false, listener_gate, Compositing::AsyncScrollOperationTracking::No, now);}void ContextState::end_scroll_fling_on_next_step()@@ -1644,79 +1550,134 @@ void ContextState::end_scroll_fling_on_next_step()m_scroll_fling_controller.end_on_next_step();}-ContextState::ContextUpdateResult ContextState::scroll_for_wheel_event(Web::MouseEvent const& event, bool is_first_wheel_event_with_delta, Compositing::AsyncScrollOperationTracking operation_tracking, MonotonicTime now)+ContextState::ContextUpdateResult ContextState::scroll_for_wheel_event(Web::MouseEvent const& event, bool is_first_wheel_event_with_delta, WheelEventListenerGate const& listener_gate, Compositing::AsyncScrollOperationTracking operation_tracking, MonotonicTime now){- auto position = wheel_event_position(event);+ auto step = WheelStep::for_wheel_event(event, m_wheel_gesture_routing.gesture_id(), operation_tracking);// The end of a gesture lets go of the scroller it stretched even if the context has stopped taking wheel events.- if (event.scroll_gesture_phase == Web::ScrollGesturePhase::Ended)+ if (step.scroll_gesture_phase == Web::ScrollGesturePhase::Ended)m_elastic_overscroll_controller.end_gesture(now);- auto latch = resolve_wheel_scroll_latch(event.scroll_gesture_phase, m_wheel_gesture_routing.gesture_id());+ auto latch = resolve_wheel_scroll_latch(step.scroll_gesture_phase, step.gesture_id);if (latch.nested_context_id.has_value())return { .nested_context_wheel_step = NestedContextWheelStep { .context_id = *latch.nested_context_id } };+ if (latch.scroll_node_index.has_value()) {+ // A blocking listener added during the gesture holds its later steps back until the page lets one through.+ if (listener_gate.reason_to_hold_latched_steps_back.has_value())+ return ContextUpdateResult::declined(*listener_gate.reason_to_hold_latched_steps_back);+ auto admission = listener_gate.page_let_the_gesture_through ? WheelStepAdmission::LetThroughByThePage : WheelStepAdmission::ByThisPage;+ return scroll_for_wheel_step_in_this_context(step, latch.scroll_node_index, Compositing::NestedContextRegions::LeaveToMainThread, admission, {}, now);+ }++ if (listener_gate.page_let_the_gesture_through)+ return scroll_for_wheel_step_in_this_context(step, {}, Compositing::NestedContextRegions::Ignore, WheelStepAdmission::LetThroughByThePage, {}, now);// The first step of a gesture over the content of a nested context goes to that context. A gesture whose first step// went elsewhere is not handed to a nested context that comes under the pointer later.auto nested_context_regions = Compositing::NestedContextRegions::LeaveToMainThread;- bool may_hand_step_to_nested_context = !latch.scroll_node_index.has_value()- && is_first_wheel_event_with_delta- && may_hand_first_wheel_steps_to_nested_contexts();- if (may_hand_step_to_nested_context) {+ if (is_first_wheel_event_with_delta && may_hand_first_wheel_steps_to_nested_contexts()) {nested_context_regions = Compositing::NestedContextRegions::HandToNestedContext;- if (auto hit = nested_context_for_wheel_at(position); hit.has_value())+ if (auto hit = nested_context_for_wheel_at(step.position); hit.has_value())return { .nested_context_wheel_step = NestedContextWheelStep { .context_id = hit->child_context_id, .hit = hit } };}- return scroll_for_wheel_event_in_this_context(event, latch.scroll_node_index, nested_context_regions, operation_tracking, now);+ return scroll_for_wheel_step_in_this_context(step, {}, nested_context_regions, WheelStepAdmission::ByThisPage, {}, now);}ContextState::ContextUpdateResult ContextState::scroll_for_wheel_event_passed_on_by_nested_context(Web::MouseEvent const& event, Compositing::AsyncScrollOperationTracking operation_tracking, MonotonicTime now){- return scroll_for_wheel_event_in_this_context(event, {}, Compositing::NestedContextRegions::Ignore, operation_tracking, now);+ auto step = WheelStep::for_wheel_event(event, m_wheel_gesture_routing.gesture_id(), operation_tracking);+ return scroll_for_wheel_step_in_this_context(step, {}, Compositing::NestedContextRegions::Ignore, WheelStepAdmission::PassedOnByNestedContext, {}, now);+}++ContextState::ContextUpdateResult ContextState::scroll_for_first_wheel_step_the_page_let_through(WheelStep const& step, ReadonlySpan<Web::AsyncScrollNodeStableID> scroll_chain, MonotonicTime now)+{+ return scroll_for_wheel_step_in_this_context(step, {}, Compositing::NestedContextRegions::Ignore, WheelStepAdmission::LetThroughByThePage, scroll_chain, now);+}++Optional<ContextState::ContextUpdateResult> ContextState::scroll_for_latched_wheel_step_the_page_let_through(WheelStep const& step, MonotonicTime now)+{+ auto latch = resolve_wheel_scroll_latch(step.scroll_gesture_phase, step.gesture_id);+ if (!latch.scroll_node_index.has_value())+ return {};+ return scroll_for_wheel_step_in_this_context(step, latch.scroll_node_index, Compositing::NestedContextRegions::Ignore, WheelStepAdmission::LetThroughByThePage, {}, now);+}++ContextState::ContextUpdateResult ContextState::scroll_for_wheel_step_overtaken_by_ui(WheelStep const& step, ReadonlySpan<Web::AsyncScrollNodeStableID> scroll_chain, MonotonicTime now)+{+ if (!m_has_async_scrolling_state)+ return ContextUpdateResult::declined(Web::InputRoutingDecision::NoAsyncScrollingState);+ auto delta = step.delta_in_css_pixels.scaled(static_cast<float>(m_async_scroll_tree.device_pixels_per_css_pixel()));+ if (delta.is_zero())+ return ContextUpdateResult::declined(Web::InputRoutingDecision::StepOvertakenByUI);+ auto scroll_target = route_first_wheel_step(step.position, delta, step.wheel_delta_precision, Compositing::WheelStepDispatch::DispatchedAndNotCanceled, Compositing::NestedContextRegions::Ignore, scroll_chain);+ if (!scroll_target.scroll_node_index.has_value())+ return ContextUpdateResult::declined(Web::InputRoutingDecision::StepOvertakenByUI);++ m_scroll_snap_controller.note_gesture_phase(step.scroll_gesture_phase);+ auto node_scroll = scroll_node_by_wheel_delta(*scroll_target.scroll_node_index, delta, step.wheel_delta_precision, step.scroll_gesture_phase, step.operation_tracking, m_async_scrolling_viewport_rect, now, Compositing::ScrollChaining::ToScrollableAncestors);+ auto const& outcome = node_scroll.outcome;+ return {+ .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(),+ .routing_decision = Web::InputRoutingDecision::StepOvertakenByUI,+ .tracked_scroll_operation = tracked_scroll_operation(step.operation_tracking, outcome.operation_id),+ };}Optional<ContextState::TrackedScrollOperation> ContextState::tracked_scroll_operation(Compositing::AsyncScrollOperationTracking operation_tracking, Optional<Compositing::AsyncScrollOperationID> operation_id) const{if (operation_tracking == Compositing::AsyncScrollOperationTracking::No || !operation_id.has_value())return {};- // An operation that ended as the step was taken, such as an instant scroll, leaves nothing to follow. The main- // thread adopts the offsets of the step as it handles the event.- if (m_async_scroll_update_outbox.has_completed_operation(*operation_id))- return {};return TrackedScrollOperation { .context_id = m_context_id, .operation_id = *operation_id };}-ContextState::ContextUpdateResult ContextState::scroll_for_wheel_event_in_this_context(Web::MouseEvent const& event, Optional<Compositing::SpatialNodeIndex> latched_scroll_node_index, Compositing::NestedContextRegions nested_context_regions, Compositing::AsyncScrollOperationTracking operation_tracking, MonotonicTime now)+ContextState::ContextUpdateResult ContextState::scroll_for_wheel_step_in_this_context(WheelStep const& step, Optional<Compositing::SpatialNodeIndex> latched_scroll_node_index, Compositing::NestedContextRegions nested_context_regions, WheelStepAdmission admission, ReadonlySpan<Web::AsyncScrollNodeStableID> scroll_chain, MonotonicTime now){- auto position = wheel_event_position(event);- auto delta = wheel_event_delta_in_device_pixels(event);+ auto delta = step.delta_in_css_pixels.scaled(static_cast<float>(m_async_scroll_tree.device_pixels_per_css_pixel()));+ bool is_first_step_of_gesture = !latched_scroll_node_index.has_value();+ auto found_nothing_to_scroll = [&](Web::InputRoutingDecision decision) {+ bool there_is_nothing_to_scroll = first_is_one_of(decision, Web::InputRoutingDecision::NoScrollTarget, Web::InputRoutingDecision::NoScrollNode, Web::InputRoutingDecision::GestureEndWithNothingToSnap);+ if (admission == WheelStepAdmission::LetThroughByThePage && there_is_nothing_to_scroll)+ return ContextUpdateResult { .accepted = true, .routing_decision = decision };+ return ContextUpdateResult::declined(decision);+ };- // 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_gesture_routing.admission() == Compositing::WheelRoutingAdmission::NoScrollNode- && 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_scroll_node_index, event.wheel_delta_precision, event.scroll_gesture_phase))- return ContextUpdateResult::declined(Compositing::input_routing_decision_for_wheel_step_not_admitted_by(m_wheel_gesture_routing.admission()));+ if (is_first_step_of_gesture) {+ auto routing_admission = m_wheel_gesture_routing.admission();+ // A page without scroll nodes still has a visual viewport to pan once it is zoomed in.+ auto can_pan_zoomed_visual_viewport = routing_admission == Compositing::WheelRoutingAdmission::NoScrollNode+ && m_scene.visual_viewport_scale().value_or(1.0f) > 1.0f;+ // Only the listeners of the page that sees the step may hold it back.+ bool is_admitted = routing_admission == Compositing::WheelRoutingAdmission::Accepted+ || (admission != WheelStepAdmission::ByThisPage && first_is_one_of(routing_admission, Compositing::WheelRoutingAdmission::BlockingWheelEventListeners, Compositing::WheelRoutingAdmission::StaleWheelEventListeners));+ if (!is_admitted && !can_pan_zoomed_visual_viewport) {+ auto decision = Compositing::input_routing_decision_for_wheel_step_not_admitted_by(routing_admission);+ if (routing_admission == Compositing::WheelRoutingAdmission::NoScrollNode)+ return found_nothing_to_scroll(decision);+ return ContextUpdateResult::declined(decision);+ }+ }- m_scroll_snap_controller.note_gesture_phase(event.scroll_gesture_phase);+ m_scroll_snap_controller.note_gesture_phase(step.scroll_gesture_phase);- if (event.scroll_gesture_phase == Web::ScrollGesturePhase::Ended && delta.is_zero()) {+ if (step.scroll_gesture_phase == Web::ScrollGesturePhase::Ended && delta.is_zero()) {auto operation_id = snap_at_gesture_end(now);if (!operation_id.has_value())- return ContextUpdateResult::declined(Web::InputRoutingDecision::GestureEndWithNothingToSnap);+ return found_nothing_to_scroll(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,- .tracked_scroll_operation = tracked_scroll_operation(operation_tracking, operation_id),+ .tracked_scroll_operation = tracked_scroll_operation(step.operation_tracking, operation_id),};}- // Whether a gesture scrolls here or on the main thread is decided by its first step; the steps of a latched- // gesture are not held back by regions the cursor moves over later.- bool is_first_step_of_gesture = !latched_scroll_node_index.has_value();- if (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, {}, Compositing::WheelStepDispatch::NotYetDispatched, nested_context_regions);+ // Whether a gesture waits for the page is decided by its first step; the steps of a latched gesture are not held+ // back by regions the cursor moves over later.+ auto wheel_step_dispatch = admission == WheelStepAdmission::ByThisPage ? Compositing::WheelStepDispatch::NotYetDispatched : Compositing::WheelStepDispatch::DispatchedAndNotCanceled;+ if (is_first_step_of_gesture && wheel_step_dispatch == Compositing::WheelStepDispatch::NotYetDispatched) {+ auto initial_scroll_target = m_async_scroll_tree.hit_test_scroll_node_for_wheel(m_scene.visual_context_tree_for_compositing(), step.position, delta, {}, wheel_step_dispatch, nested_context_regions);if (initial_scroll_target.is_blocked_by_a_region())return ContextUpdateResult::declined(Compositing::input_routing_decision_for_first_wheel_step(initial_scroll_target.outcome));}@@ -1735,7 +1696,7 @@ ContextState::ContextUpdateResult ContextState::scroll_for_wheel_event_in_this_c// for as long as the gesture only pans.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, m_wheel_gesture_routing.gesture_id(), {}, Compositing::WheelStepDispatch::NotYetDispatched, nested_context_regions);+ auto latch_attempt = route_and_latch_wheel_gesture(step.position, delta.scaled(1.0f / m_scene.visual_viewport_magnification()), step.wheel_delta_precision, step.scroll_gesture_phase, step.gesture_id, wheel_step_dispatch, nested_context_regions, scroll_chain);latched_scroll_node_index = latch_attempt.latched_scroll_node_index;routing_decision = latch_attempt.decision;}@@ -1743,7 +1704,7 @@ ContextState::ContextUpdateResult ContextState::scroll_for_wheel_event_in_this_c// A zoomed page still pans its visual viewport by a gesture that no scroller takes.if (!latched_scroll_node_index.has_value()) {if (pan_visual_viewport_by(delta).is_zero())- return ContextUpdateResult::declined(routing_decision);+ return found_nothing_to_scroll(routing_decision);return {.accepted = true,.frame_to_present = PendingFrame::repainting_changes(m_async_scrolling_viewport_rect),@@ -1753,14 +1714,14 @@ ContextState::ContextUpdateResult ContextState::scroll_for_wheel_event_in_this_c}auto scroll_chaining = is_first_step_of_gesture ? Compositing::ScrollChaining::ToScrollableAncestors : Compositing::ScrollChaining::None;- auto outcome = perform_wheel_scroll_of_node(*latched_scroll_node_index, delta, event.wheel_delta_precision, event.scroll_gesture_phase, operation_tracking, m_async_scrolling_viewport_rect, now, scroll_chaining, VisualViewportPanning::BeforeScrolling);+ auto outcome = perform_wheel_scroll_of_node(*latched_scroll_node_index, delta, step.wheel_delta_precision, step.scroll_gesture_phase, step.operation_tracking, m_async_scrolling_viewport_rect, now, scroll_chaining, VisualViewportPanning::BeforeScrolling);return {.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(),- .tracked_scroll_operation = tracked_scroll_operation(operation_tracking, outcome.operation_id),+ .tracked_scroll_operation = tracked_scroll_operation(step.operation_tracking, outcome.operation_id),};}@@ -1778,32 +1739,38 @@ Optional<Compositing::NestedContextHit> ContextState::nested_context_for_wheel_areturn m_async_scroll_tree.nested_context_for_wheel_at(m_scene.visual_context_tree_for_compositing(), position);}-void ContextState::latch_wheel_gesture_to_nested_context(Web::CompositorContextId nested_context_id, Optional<Web::AsyncScrollNodeStableID> scroller, Web::MouseEvent const& event)+void ContextState::latch_wheel_gesture_to_nested_context(Web::CompositorContextId nested_context_id, Optional<Web::AsyncScrollNodeStableID> scroller, Web::ScrollGesturePhase scroll_gesture_phase)+{+ m_wheel_gesture_routing.latch_to_nested_context(nested_context_id, scroller, scroll_gesture_phase, m_wheel_gesture_routing.gesture_id());+}++Optional<Gfx::FloatPoint> ContextState::position_of_nested_context_position(Web::CompositorContextId nested_context_id, Gfx::FloatPoint position_in_nested_context, Gfx::IntSize nested_context_viewport_size){- m_wheel_gesture_routing.latch_to_nested_context(nested_context_id, scroller, event.scroll_gesture_phase, m_wheel_gesture_routing.gesture_id());+ if (!m_has_async_scrolling_state)+ return {};+ return m_async_scroll_tree.position_of_nested_context_position(nested_context_id, position_in_nested_context, nested_context_viewport_size.to_type<float>(), m_scene.visual_context_tree_for_compositing());}-ContextState::WheelStepFromContainingContext ContextState::WheelStepFromContainingContext::for_wheel_event(Web::MouseEvent const& event, Optional<u64> gesture_id, Compositing::AsyncScrollOperationTracking operation_tracking)+ContextState::WheelStep ContextState::WheelStep::for_wheel_event(Web::MouseEvent const& event, Optional<u64> gesture_id, Compositing::AsyncScrollOperationTracking operation_tracking){Gfx::FloatPoint delta_in_css_pixels { static_cast<float>(event.wheel_delta_x), static_cast<float>(event.wheel_delta_y) };if (event.modifiers & Web::UIEvents::KeyModifier::Mod_Shift)delta_in_css_pixels = { delta_in_css_pixels.y(), delta_in_css_pixels.x() };return {- .position = {},+ .position = wheel_event_position(event),.delta_in_css_pixels = delta_in_css_pixels,.wheel_delta_precision = event.wheel_delta_precision,.scroll_gesture_phase = event.scroll_gesture_phase,- .modifiers = event.modifiers,.gesture_id = gesture_id,.operation_tracking = operation_tracking,};}-ContextState::FirstWheelStepRoute ContextState::route_first_wheel_step_from_containing_context(Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels, Web::WheelDeltaPrecision wheel_delta_precision, Compositing::NestedContextRegions nested_context_regions)+ContextState::FirstWheelStepRoute ContextState::route_first_wheel_step_from_containing_context(Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels, Web::WheelDeltaPrecision wheel_delta_precision, Compositing::NestedContextRegions nested_context_regions, WheelStepAdmission admission, ReadonlySpan<Web::AsyncScrollNodeStableID> scroll_chain){using Kind = FirstWheelStepRoute::Kind;- auto admission = m_wheel_gesture_routing.admission();- if (!m_has_async_scrolling_state || admission == Compositing::WheelRoutingAdmission::NoAsyncScrollingState)+ auto routing_admission = m_wheel_gesture_routing.admission();+ if (!m_has_async_scrolling_state || routing_admission == Compositing::WheelRoutingAdmission::NoAsyncScrollingState)return { Kind::Declined, Web::InputRoutingDecision::NoAsyncScrollingState };// A document's wheel event listeners never see the wheel events over a document nested in it.@@ -1812,14 +1779,13 @@ ContextState::FirstWheelStepRoute ContextState::route_first_wheel_step_from_contif (auto hit = m_async_scroll_tree.nested_context_for_wheel_at(visual_context_tree, position); hit.has_value())return { .kind = Kind::NestedContext, .decision = Web::InputRoutingDecision::HandedToNestedContext, .nested_context_hit = hit };}- if (first_is_one_of(admission, Compositing::WheelRoutingAdmission::BlockingWheelEventListeners, Compositing::WheelRoutingAdmission::StaleWheelEventListeners))- return { Kind::Declined, Compositing::input_routing_decision_for_wheel_step_not_admitted_by(admission) };+ bool listeners_of_this_page_see_the_step = admission == WheelStepAdmission::ByThisPage;+ if (listeners_of_this_page_see_the_step && first_is_one_of(routing_admission, Compositing::WheelRoutingAdmission::BlockingWheelEventListeners, Compositing::WheelRoutingAdmission::StaleWheelEventListeners))+ return { Kind::Declined, Compositing::input_routing_decision_for_wheel_step_not_admitted_by(routing_admission) };auto delta = delta_in_css_pixels.scaled(static_cast<float>(m_async_scroll_tree.device_pixels_per_css_pixel()));- 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(visual_context_tree, position, delta, in_flight_destination_for, Compositing::WheelStepDispatch::NotYetDispatched, nested_context_regions);+ auto wheel_step_dispatch = listeners_of_this_page_see_the_step ? Compositing::WheelStepDispatch::NotYetDispatched : Compositing::WheelStepDispatch::DispatchedAndNotCanceled;+ auto scroll_target = route_first_wheel_step(position, delta, wheel_delta_precision, wheel_step_dispatch, nested_context_regions, scroll_chain);auto scroller_of = [&](Optional<Compositing::SpatialNodeIndex> scroll_node_index) {return scroll_node_index.map([&](auto index) { return m_async_scroll_tree.scroll_node_for_index(index)->stable_node_id; });};@@ -1838,7 +1804,7 @@ ContextState::FirstWheelStepRoute ContextState::route_first_wheel_step_from_contreturn { .kind = Kind::Kept, .decision = Web::InputRoutingDecision::ScrollKeptByOverscrollBehavior, .scroll_node_index = scroll_node_index_keeping_the_scroll, .scroller = scroller_of(scroll_node_index_keeping_the_scroll) };}-ContextState::ContextUpdateResult ContextState::take_first_wheel_step_from_containing_context(FirstWheelStepRoute const& route, WheelStepFromContainingContext const& step, MonotonicTime now)+ContextState::ContextUpdateResult ContextState::take_first_wheel_step_from_containing_context(FirstWheelStepRoute const& route, WheelStep const& step, MonotonicTime now){VERIFY(first_is_one_of(route.kind, FirstWheelStepRoute::Kind::ScrollNode, FirstWheelStepRoute::Kind::Kept));if (route.kind == FirstWheelStepRoute::Kind::Kept) {@@ -1852,14 +1818,10 @@ ContextState::ContextUpdateResult ContextState::take_first_wheel_step_from_contareturn take_wheel_step_from_containing_context(*route.scroll_node_index, route.decision, step, Compositing::ScrollChaining::ToScrollableAncestors, now);}-ContextState::ContextUpdateResult ContextState::take_latched_wheel_step_from_containing_context(WheelStepFromContainingContext const& step, MonotonicTime now)+ContextState::ContextUpdateResult ContextState::take_latched_wheel_step_from_containing_context(WheelStep const& step, WheelStepAdmission admission, MonotonicTime now){if (!m_has_async_scrolling_state)return ContextUpdateResult::declined(Web::InputRoutingDecision::NoAsyncScrollingState);- // A blocking listener added during the gesture holds its later steps back until a display list shows where it is.- auto admission = m_wheel_gesture_routing.admission();- if (first_is_one_of(admission, Compositing::WheelRoutingAdmission::BlockingWheelEventListeners, Compositing::WheelRoutingAdmission::StaleWheelEventListeners))- return ContextUpdateResult::declined(Compositing::input_routing_decision_for_wheel_step_not_admitted_by(admission));auto latch = m_wheel_gesture_routing.resolve_latch(m_async_scroll_tree, m_scene.current_visual_context_tree(), step.scroll_gesture_phase, step.gesture_id);if (latch.keeps_steps)@@ -1870,8 +1832,11 @@ ContextState::ContextUpdateResult ContextState::take_latched_wheel_step_from_conif (step.scroll_gesture_phase == Web::ScrollGesturePhase::Ended && step.delta_in_css_pixels.is_zero()) {m_scroll_snap_controller.note_gesture_phase(step.scroll_gesture_phase);auto operation_id = snap_at_gesture_end(now);- if (!operation_id.has_value())+ if (!operation_id.has_value()) {+ if (admission == WheelStepAdmission::LetThroughByThePage)+ return { .accepted = true, .routing_decision = Web::InputRoutingDecision::GestureEndWithNothingToSnap };return ContextUpdateResult::declined(Web::InputRoutingDecision::GestureEndWithNothingToSnap);+ }return {.accepted = true,.frame_to_present = PendingFrame::repainting_changes(m_async_scrolling_viewport_rect),@@ -1884,7 +1849,7 @@ ContextState::ContextUpdateResult ContextState::take_latched_wheel_step_from_conreturn take_wheel_step_from_containing_context(*latch.scroll_node_index, Web::InputRoutingDecision::ContinuedLatch, step, Compositing::ScrollChaining::None, now);}-ContextState::ContextUpdateResult ContextState::take_wheel_step_from_containing_context(Compositing::SpatialNodeIndex scroll_node_index, Web::InputRoutingDecision decision, WheelStepFromContainingContext const& step, Compositing::ScrollChaining scroll_chaining, MonotonicTime now)+ContextState::ContextUpdateResult ContextState::take_wheel_step_from_containing_context(Compositing::SpatialNodeIndex scroll_node_index, Web::InputRoutingDecision decision, WheelStep const& step, Compositing::ScrollChaining scroll_chaining, MonotonicTime now){m_scroll_snap_controller.note_gesture_phase(step.scroll_gesture_phase);auto delta = step.delta_in_css_pixels.scaled(static_cast<float>(m_async_scroll_tree.device_pixels_per_css_pixel()));@@ -2267,12 +2232,21 @@ WheelGestureRouting::ResolvedLatch ContextState::resolve_wheel_scroll_latch(Web:return m_wheel_gesture_routing.resolve_latch(m_async_scroll_tree, m_scene.current_visual_context_tree(), scroll_gesture_phase, gesture_id);}-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, Optional<u64> gesture_id, Optional<Web::UniqueNodeID> expected_document_id, Compositing::WheelStepDispatch wheel_step_dispatch, Compositing::NestedContextRegions nested_context_regions)+Compositing::WheelHitTestResult ContextState::route_first_wheel_step(Gfx::FloatPoint position, Gfx::FloatPoint delta, Web::WheelDeltaPrecision wheel_delta_precision, Compositing::WheelStepDispatch wheel_step_dispatch, Compositing::NestedContextRegions nested_context_regions, ReadonlySpan<Web::AsyncScrollNodeStableID> scroll_chain){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, nested_context_regions);+ for (auto stable_node_id : scroll_chain) {+ if (auto scroll_node_index = m_async_scroll_tree.scroll_node_index_for_stable_id(stable_node_id); scroll_node_index.has_value())+ return m_async_scroll_tree.hit_test_result_for_scroll_node(*scroll_node_index, delta, in_flight_destination_for);+ }+ return 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, nested_context_regions);+}++ContextState::WheelGestureLatchAttempt ContextState::route_and_latch_wheel_gesture(Gfx::FloatPoint position, Gfx::FloatPoint delta, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, Optional<u64> gesture_id, Compositing::WheelStepDispatch wheel_step_dispatch, Compositing::NestedContextRegions nested_context_regions, ReadonlySpan<Web::AsyncScrollNodeStableID> scroll_chain)+{+ auto scroll_target = route_first_wheel_step(position, delta, wheel_delta_precision, wheel_step_dispatch, nested_context_regions, scroll_chain);if (scroll_target.is_blocked_by_a_region())return { Compositing::input_routing_decision_for_first_wheel_step(scroll_target.outcome) };@@ -2289,8 +2263,6 @@ ContextState::WheelGestureLatchAttempt ContextState::hit_test_and_latch_wheel_geif (!scroll_node_index_to_latch.has_value())return { Compositing::input_routing_decision_for_first_wheel_step(scroll_target.outcome) };- if (expected_document_id.has_value() && m_async_scroll_tree.document_id() != *expected_document_id)- return { Web::InputRoutingDecision::ScrollerInOtherDocument };auto const* node = m_async_scroll_tree.scroll_node_for_index(*scroll_node_index_to_latch);VERIFY(node);m_wheel_gesture_routing.latch(node->stable_node_id, scroll_gesture_phase, gesture_id);diff --git a/Services/Compositor/ContextState.h b/Services/Compositor/ContextState.hindex 50da31f6dd1..2098fd15f11 100644--- a/Services/Compositor/ContextState.h+++ b/Services/Compositor/ContextState.h@@ -104,19 +104,39 @@ public:static ContextUpdateResult declined(Web::InputRoutingDecision decision) { return { .routing_decision = decision }; }};- // A step of a wheel gesture that the context this one is nested in hands to it, at a position in this context's- // device pixels. The delta is in CSS pixels, with the axes already swapped for Shift.- struct WheelStepFromContainingContext {+ // A step of a wheel gesture at a position in this context's device pixels. The delta is in CSS pixels, with the axes+ // already swapped for Shift.+ struct WheelStep {Gfx::FloatPoint position;Gfx::FloatPoint delta_in_css_pixels;Web::WheelDeltaPrecision wheel_delta_precision { Web::WheelDeltaPrecision::Discrete };Web::ScrollGesturePhase scroll_gesture_phase { Web::ScrollGesturePhase::None };- Web::UIEvents::KeyModifier modifiers { Web::UIEvents::KeyModifier::Mod_None };- // The gesture of the containing context that the step is in, which the latch this context takes is for.+ // The gesture the step is in, which the latch a context takes for the step is for. A context nested in another+ // one takes it for the gesture of the containing context.Optional<u64> gesture_id {};Compositing::AsyncScrollOperationTracking operation_tracking { Compositing::AsyncScrollOperationTracking::No };- static WheelStepFromContainingContext for_wheel_event(Web::MouseEvent const&, Optional<u64> gesture_id, Compositing::AsyncScrollOperationTracking);+ static WheelStep for_wheel_event(Web::MouseEvent const&, Optional<u64> gesture_id, Compositing::AsyncScrollOperationTracking);+ };++ // What the wheel event listeners of the page that dispatches a gesture's wheel events let through without waiting+ // for the page. That page may be the page of a context nested in this one.+ struct WheelEventListenerGate {+ // The page dispatched a step of the gesture and did not cancel it, and the listeners are as they were then.+ bool page_let_the_gesture_through { false };+ // Why the listeners hold the steps of a latched gesture back for the page, if they do.+ Optional<Web::InputRoutingDecision> reason_to_hold_latched_steps_back {};+ };++ // What may hold a step back for the page before this context scrolls by it.+ enum class WheelStepAdmission : u8 {+ // The wheel event listeners of this context's page see the step, which waits for the page if they may cancel it.+ ByThisPage,+ // A context nested in this one passed the step on. Only the page of that context sees the step.+ PassedOnByNestedContext,+ // The page let the gesture through. Nothing holds the step back, and a step that finds nothing to scroll is done+ // with all the same, so that the page is not asked about the gesture again.+ LetThroughByThePage,};// Where the first step of a gesture that the containing context hands in goes in this context. A nested context@@ -197,45 +217,59 @@ public:bool is_first_wheel_event_with_delta { false };};// Takes note of a wheel event from the UI as it arrives, ahead of anything that may turn it away or leave it to- // the main thread.+ // the page.NotedWheelEvent note_wheel_event_from_ui(Web::MouseEvent const&, Optional<MonotonicTime> now_for_testing = {});// Takes note of a wheel event that the main thread has and the UI did not send here, as the UI's events are noted.// Such an event adds nothing to the velocity of a flick or of a stretch release.NotedWheelEvent note_wheel_event_from_main_thread(Web::MouseEvent const&, MonotonicTime now);// The UI's wheel deltas are in CSS pixels; this scales them for the scroll tree, which works in device pixels.- ContextUpdateResult handle_wheel_event(Web::MouseEvent const&, bool is_first_wheel_event_with_delta, Optional<MonotonicTime> now_for_testing = {});+ ContextUpdateResult handle_wheel_event(Web::MouseEvent const&, bool is_first_wheel_event_with_delta, WheelEventListenerGate const&, Optional<MonotonicTime> now_for_testing = {});// Routes the event like one from the UI, also in a context that is nested in another one.- ContextUpdateResult scroll_for_wheel_event_from_main_thread(Web::MouseEvent const&, bool is_first_wheel_event_with_delta, Compositing::AsyncScrollOperationTracking, MonotonicTime now);+ ContextUpdateResult scroll_for_wheel_event_from_main_thread(Web::MouseEvent const&, bool is_first_wheel_event_with_delta, WheelEventListenerGate const&, Compositing::AsyncScrollOperationTracking, MonotonicTime now);Optional<u64> wheel_gesture_id() const { return m_wheel_gesture_routing.gesture_id(); }+ bool wheel_step_was_overtaken_by_ui(Web::ScrollGesturePhase phase, u64 input_event_id) const { return m_wheel_gesture_routing.step_was_overtaken_by_ui(phase, input_event_id); }+ Optional<Web::CompositorContextId> wheel_event_listener_context() const { return m_wheel_gesture_routing.wheel_event_listener_context(); }+ void set_wheel_event_listener_context(Web::CompositorContextId context_id) { m_wheel_gesture_routing.set_wheel_event_listener_context(context_id); }+ WheelEventListenerGate wheel_event_listener_gate(Optional<u64> gesture_id) const;+ void note_page_let_wheel_gesture_through(u64 gesture_id) { m_wheel_gesture_routing.note_page_let_gesture_through(gesture_id); }+ void forget_page_let_wheel_gesture_through(u64 gesture_id) { m_wheel_gesture_routing.forget_page_let_gesture_through(gesture_id); }+ // A wheel event of the UI that this context did not scroll by is left to its page, which then answers whether it let+ // the event through.+ void note_wheel_event_left_to_the_page(Web::MouseEvent const&);+ bool take_wheel_delta_left_to_the_page(Gfx::FloatPoint delta_in_css_pixels) { return m_wheel_gesture_routing.take_delta_left_to_the_page(delta_in_css_pixels); }+ bool has_wheel_latch_for_gesture(Optional<u64> gesture_id) const { return m_wheel_gesture_routing.has_latch_for_gesture(gesture_id); }+ Optional<Web::CompositorContextId> nested_context_of_wheel_latch() const { return m_wheel_gesture_routing.nested_context_of_latch(); }+ Optional<Web::AsyncScrollNodeStableID> wheel_latched_scroller() const { return m_wheel_gesture_routing.latched_scroller(); }+ void forget_wheel_latch_of_gesture(u64 gesture_id) { m_wheel_gesture_routing.clear_latch_of_gesture(gesture_id); }+ void end_wheel_gesture_stretch(MonotonicTime now) { m_elastic_overscroll_controller.end_gesture(now); }ContextUpdateResult handle_pinch_event(Web::PinchEvent const&);bool admits_async_pinch() const { return m_wheel_gesture_routing.admits_async_pinch(); }bool may_hand_first_wheel_steps_to_nested_contexts() const;Optional<Compositing::NestedContextHit> nested_context_for_wheel_at(Gfx::FloatPoint position);ContextUpdateResult scroll_for_wheel_event_passed_on_by_nested_context(Web::MouseEvent const&, Compositing::AsyncScrollOperationTracking, MonotonicTime now);- void latch_wheel_gesture_to_nested_context(Web::CompositorContextId, Optional<Web::AsyncScrollNodeStableID> scroller, Web::MouseEvent const&);+ void latch_wheel_gesture_to_nested_context(Web::CompositorContextId, Optional<Web::AsyncScrollNodeStableID> scroller, Web::ScrollGesturePhase);+ // Where a position in the viewport of a context nested in this one lies in this context's viewport.+ Optional<Gfx::FloatPoint> position_of_nested_context_position(Web::CompositorContextId, Gfx::FloatPoint position_in_nested_context, Gfx::IntSize nested_context_viewport_size);void forget_wheel_gesture_latch() { m_wheel_gesture_routing.clear_latch(); }void clear_per_test_input_state();- FirstWheelStepRoute route_first_wheel_step_from_containing_context(Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels, Web::WheelDeltaPrecision, Compositing::NestedContextRegions);+ // The scrollers the page found around the target of a step that it let through, innermost first, go before a hit+ // test at the position of the step.+ FirstWheelStepRoute route_first_wheel_step_from_containing_context(Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels, Web::WheelDeltaPrecision, Compositing::NestedContextRegions, WheelStepAdmission, ReadonlySpan<Web::AsyncScrollNodeStableID> scroll_chain = {});// Latches the gesture to the scroller the route found, or to the one that keeps the step, and scrolls by the step.- ContextUpdateResult take_first_wheel_step_from_containing_context(FirstWheelStepRoute const&, WheelStepFromContainingContext const&, MonotonicTime now);- ContextUpdateResult take_latched_wheel_step_from_containing_context(WheelStepFromContainingContext const&, MonotonicTime now);+ ContextUpdateResult take_first_wheel_step_from_containing_context(FirstWheelStepRoute const&, WheelStep const&, MonotonicTime now);+ ContextUpdateResult take_latched_wheel_step_from_containing_context(WheelStep const&, WheelStepAdmission, MonotonicTime now);+ // The first step of a gesture that the page let through, routed from the scrollers the page found around its target,+ // innermost first, if this context knows one, and by a hit test otherwise.+ ContextUpdateResult scroll_for_first_wheel_step_the_page_let_through(WheelStep const&, ReadonlySpan<Web::AsyncScrollNodeStableID> scroll_chain, MonotonicTime now);+ // A step of a gesture that the page let through and that is latched to a scroller of this context. Empty once the+ // scroller is gone.+ Optional<ContextUpdateResult> scroll_for_latched_wheel_step_the_page_let_through(WheelStep const&, MonotonicTime now);+ // A step of a gesture that this context has moved past scrolls once along its route, latching and stretching+ // nothing.+ ContextUpdateResult scroll_for_wheel_step_overtaken_by_ui(WheelStep const&, ReadonlySpan<Web::AsyncScrollNodeStableID> scroll_chain, MonotonicTime now);Optional<Web::UniqueNodeID> document_id() const { return m_async_scroll_tree.document_id(); }- AsyncScrollResult async_scroll_by(- Web::UniqueNodeID document_id,- Gfx::FloatPoint position,- Gfx::FloatPoint delta,- Gfx::IntRect viewport_rect,- Web::WheelDeltaPrecision,- Web::ScrollGesturePhase,- Compositing::AsyncScrollOperationTracking,- Compositing::WheelStepDispatch,- // The gesture the compositor named in the mark of the wheel event.- Optional<u64> wheel_gesture_id_from_mark,- // The id the UI gave the wheel event, or 0 for a step that did not come from the UI.- u64 input_event_id,- Optional<MonotonicTime> now_for_testing = {});Optional<PendingFrame> apply_scroll_requests(ReadonlySpan<Compositing::ScrollRequest>);void cancel_smooth_scroll(Web::AsyncScrollNodeStableID);Optional<Gfx::IntRect> advance_smooth_scroll_animations(MonotonicTime now);@@ -245,7 +279,7 @@ public:// The wheel event of the next step of the fling, which is scrolled by like a wheel event from the UI.Optional<Web::MouseEvent> take_scroll_fling_step(MonotonicTime frame_time);Optional<Web::MouseEvent> end_scroll_fling();- ContextUpdateResult scroll_for_fling_step(Web::MouseEvent const&, MonotonicTime now);+ ContextUpdateResult scroll_for_fling_step(Web::MouseEvent const&, WheelEventListenerGate const&, MonotonicTime now);void end_scroll_fling_on_next_step();// Starts a fling if the gesture that the event ends was a flick. Use only on platforms that send no momentum// scroll events.@@ -377,8 +411,11 @@ private:Optional<Compositing::SpatialNodeIndex> latched_scroll_node_index {};};// The scroller the first step of a wheel gesture is routed to, which the gesture is latched to.- WheelGestureLatchAttempt hit_test_and_latch_wheel_gesture(Gfx::FloatPoint position, Gfx::FloatPoint delta, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, Optional<u64> gesture_id, Optional<Web::UniqueNodeID> expected_document_id, Compositing::WheelStepDispatch, Compositing::NestedContextRegions);- ContextUpdateResult take_wheel_step_from_containing_context(Compositing::SpatialNodeIndex, Web::InputRoutingDecision, WheelStepFromContainingContext const&, Compositing::ScrollChaining, MonotonicTime now);+ WheelGestureLatchAttempt route_and_latch_wheel_gesture(Gfx::FloatPoint position, Gfx::FloatPoint delta, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, Optional<u64> gesture_id, Compositing::WheelStepDispatch, Compositing::NestedContextRegions, ReadonlySpan<Web::AsyncScrollNodeStableID> scroll_chain);+ // The scroller the first step of a gesture goes to, as the hit test at the position finds it, or as it is found+ // from the innermost of the scrollers the page found around the target that this context knows.+ Compositing::WheelHitTestResult route_first_wheel_step(Gfx::FloatPoint position, Gfx::FloatPoint delta, Web::WheelDeltaPrecision, Compositing::WheelStepDispatch, Compositing::NestedContextRegions, ReadonlySpan<Web::AsyncScrollNodeStableID> scroll_chain);+ ContextUpdateResult take_wheel_step_from_containing_context(Compositing::SpatialNodeIndex, Web::InputRoutingDecision, WheelStep const&, Compositing::ScrollChaining, MonotonicTime now);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::SpatialNodeIndex, ScrollSnapController::SnapScrollStart&&, bool settles_gesture, MonotonicTime now);@@ -389,11 +426,12 @@ private:bool pull_elastic_overscroll_by(Compositing::AsyncScrollNode const&, Gfx::FloatPoint step_delta, Gfx::FloatPoint delta_the_scroller_did_not_scroll_by);Optional<Compositing::ScrollStateSnapshot> scroll_state_snapshot_stretched_by_elastic_overscrolls() const;NotedWheelEvent note_wheel_event(Web::MouseEvent const&, MonotonicTime now);- ContextUpdateResult scroll_for_wheel_event(Web::MouseEvent const&, bool is_first_wheel_event_with_delta, Compositing::AsyncScrollOperationTracking, MonotonicTime now);- ContextUpdateResult scroll_for_wheel_event_in_this_context(Web::MouseEvent const&, Optional<Compositing::SpatialNodeIndex> latched_scroll_node_index, Compositing::NestedContextRegions, Compositing::AsyncScrollOperationTracking, MonotonicTime now);+ ContextUpdateResult scroll_for_wheel_event(Web::MouseEvent const&, bool is_first_wheel_event_with_delta, WheelEventListenerGate const&, Compositing::AsyncScrollOperationTracking, MonotonicTime now);+ // A step of the gesture latched to the scroller, or the first step, which latches the gesture to the scroller it is+ // routed to.+ ContextUpdateResult scroll_for_wheel_step_in_this_context(WheelStep const&, Optional<Compositing::SpatialNodeIndex> latched_scroll_node_index, Compositing::NestedContextRegions, WheelStepAdmission, ReadonlySpan<Web::AsyncScrollNodeStableID> scroll_chain, MonotonicTime now);Optional<TrackedScrollOperation> tracked_scroll_operation(Compositing::AsyncScrollOperationTracking, Optional<Compositing::AsyncScrollOperationID>) const;Gfx::FloatPoint wheel_event_delta_in_device_pixels(Web::MouseEvent const&) const;- bool step_continues_touchpad_gesture_the_page_let_through(Optional<Compositing::SpatialNodeIndex> const& latched_scroll_node_index, Web::WheelDeltaPrecision, 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);void retarget_user_scroll(ActiveSmoothScrollAnimation&, Gfx::FloatPoint destination_offset, MonotonicTime now);diff --git a/Services/Compositor/WheelGestureRouting.cpp b/Services/Compositor/WheelGestureRouting.cppindex 72497b73444..e9fd4164a42 100644--- a/Services/Compositor/WheelGestureRouting.cpp+++ b/Services/Compositor/WheelGestureRouting.cpp@@ -43,11 +43,6 @@ bool WheelGestureRouting::admits_async_pinch() const&& !m_has_blocking_wheel_event_listeners;}-bool WheelGestureRouting::only_blocking_wheel_event_listeners_hold_steps_back() const-{- return first_is_one_of(m_admission, Compositing::WheelRoutingAdmission::BlockingWheelEventListeners, Compositing::WheelRoutingAdmission::StaleWheelEventListeners);-}-WheelGestureRouting::NotedWheelEvent WheelGestureRouting::note_wheel_event(Web::MouseEvent const& event, Gfx::FloatPoint position, Compositing::AsyncScrollTree const& async_scroll_tree, MonotonicTime now){auto phase = event.scroll_gesture_phase;@@ -84,6 +79,39 @@ Optional<u64> WheelGestureRouting::gesture_id() constreturn m_gesture->id;}+Optional<Web::CompositorContextId> WheelGestureRouting::wheel_event_listener_context() const+{+ if (!m_gesture.has_value())+ return {};+ return m_gesture->wheel_event_listener_context;+}++void WheelGestureRouting::set_wheel_event_listener_context(Web::CompositorContextId context_id)+{+ if (m_gesture.has_value())+ m_gesture->wheel_event_listener_context = context_id;+}++void WheelGestureRouting::note_delta_left_to_the_page(Gfx::FloatPoint delta_in_css_pixels)+{+ if (m_gesture.has_value())+ m_gesture->delta_left_to_the_page += { AK::abs(delta_in_css_pixels.x()), AK::abs(delta_in_css_pixels.y()) };+}++bool WheelGestureRouting::take_delta_left_to_the_page(Gfx::FloatPoint delta_in_css_pixels)+{+ if (!m_gesture.has_value())+ return false;+ // The page sends back the deltas it was given, which may have been summed up on the way.+ constexpr float rounding_slack = 0.01f;+ auto& delta_left = m_gesture->delta_left_to_the_page;+ Gfx::FloatPoint step { AK::abs(delta_in_css_pixels.x()), AK::abs(delta_in_css_pixels.y()) };+ if (step.x() > delta_left.x() + rounding_slack || step.y() > delta_left.y() + rounding_slack)+ return false;+ delta_left = { max(0.0f, delta_left.x() - step.x()), max(0.0f, delta_left.y() - step.y()) };+ return true;+}+void WheelGestureRouting::forget_gesture(){m_gesture.clear();@@ -191,19 +219,50 @@ void WheelGestureRouting::relatch_to(Web::AsyncScrollNodeStableID stable_node_idm_latch->stable_node_id = stable_node_id;}-void WheelGestureRouting::note_page_let_latched_gesture_through()+Optional<Web::CompositorContextId> WheelGestureRouting::nested_context_of_latch() const+{+ if (!m_latch.has_value())+ return {};+ return m_latch->nested_context_id;+}++void WheelGestureRouting::clear_latch_of_gesture(u64 gesture_id){- VERIFY(m_latch.has_value());- m_latch->wheel_event_listener_state_generation_the_page_let_the_gesture_through_at = m_wheel_event_listener_state_generation;+ if (has_latch_for_gesture(gesture_id))+ m_latch.clear();}-bool WheelGestureRouting::page_let_latched_touchpad_gesture_through(Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase) const+void WheelGestureRouting::note_page_let_gesture_through(u64 gesture_id){- if (!m_latch.has_value())- return false;- if (wheel_delta_precision != Web::WheelDeltaPrecision::Precise || scroll_gesture_phase == Web::ScrollGesturePhase::None)- return false;- return m_latch->wheel_event_listener_state_generation_the_page_let_the_gesture_through_at == m_wheel_event_listener_state_generation;+ m_gesture_the_page_let_through = GestureThePageLetThrough {+ .gesture_id = gesture_id,+ .wheel_event_listener_state_generation = m_wheel_event_listener_state_generation,+ };+}++void WheelGestureRouting::forget_page_let_gesture_through(u64 gesture_id)+{+ if (m_gesture_the_page_let_through.has_value() && m_gesture_the_page_let_through->gesture_id == gesture_id)+ m_gesture_the_page_let_through.clear();+}++bool WheelGestureRouting::page_let_gesture_through(Optional<u64> gesture_id) const+{+ return gesture_id.has_value()+ && m_gesture_the_page_let_through.has_value()+ && m_gesture_the_page_let_through->gesture_id == *gesture_id+ && m_gesture_the_page_let_through->wheel_event_listener_state_generation == m_wheel_event_listener_state_generation;+}++Optional<Web::InputRoutingDecision> WheelGestureRouting::reason_to_hold_latched_steps_back(Optional<u64> gesture_id) const+{+ if (page_let_gesture_through(gesture_id))+ return {};+ // Blocking listeners over all of the viewport hold every step back, and so do listeners that a context without a+ // current display list cannot place.+ if (first_is_one_of(m_admission, Compositing::WheelRoutingAdmission::Accepted, Compositing::WheelRoutingAdmission::NoScrollNode))+ return {};+ return Compositing::input_routing_decision_for_wheel_step_not_admitted_by(m_admission);}bool WheelGestureRouting::momentum_of_latched_gesture_can_spring_scroller_back() constdiff --git a/Services/Compositor/WheelGestureRouting.h b/Services/Compositor/WheelGestureRouting.hindex 7ecc07c63f2..2d7bb61087d 100644--- a/Services/Compositor/WheelGestureRouting.h+++ b/Services/Compositor/WheelGestureRouting.h@@ -30,7 +30,6 @@ public:Compositing::WheelRoutingAdmission admission() const { return m_admission; }bool admits_async_wheel() const { return m_admission == Compositing::WheelRoutingAdmission::Accepted; }bool admits_async_pinch() const;- bool only_blocking_wheel_event_listeners_hold_steps_back() const;struct NotedWheelEvent {// The event starts another gesture than the one before it, which lets go of the latch.@@ -45,11 +44,21 @@ public:// The id of the gesture of the wheel events this context notes. No gesture of any context in the process has the// same id, so a context nested in another one can tell the gestures of the containing context from its own.Optional<u64> gesture_id() const;+ // The context whose page dispatches the wheel events of the gesture: the innermost one under the pointer as the+ // gesture started, which may be nested in this one. Empty for this context.+ Optional<Web::CompositorContextId> wheel_event_listener_context() const;+ void set_wheel_event_listener_context(Web::CompositorContextId);+ // The UI's input of the gesture that this context left to the page. It bounds what the page of another process may+ // scroll here, and in the contexts nested here, for the gesture.+ void note_delta_left_to_the_page(Gfx::FloatPoint delta_in_css_pixels);+ bool take_delta_left_to_the_page(Gfx::FloatPoint delta_in_css_pixels);// 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 step_was_overtaken_by_ui(Web::ScrollGesturePhase, u64 input_event_id) const;bool has_latch() const { return m_latch.has_value(); }+ bool has_latch_for_gesture(Optional<u64> gesture_id) const { return m_latch.has_value() && m_latch->gesture_id == gesture_id; }+ Optional<Web::CompositorContextId> nested_context_of_latch() const;Optional<Web::AsyncScrollNodeStableID> latched_scroller() const;void set_touchpad_gesture_end(Compositing::TouchpadGestureEnd touchpad_gesture_end) { m_touchpad_gesture_end = touchpad_gesture_end; }// Whether the fingers of the gesture are on the touchpad, where the gesture lasts until they lift.@@ -71,10 +80,17 @@ public:void latch_to_nested_context(Web::CompositorContextId, Optional<Web::AsyncScrollNodeStableID> scroller, Web::ScrollGesturePhase, Optional<u64> gesture_id);void latch_keeping_steps(Web::ScrollGesturePhase, Optional<u64> gesture_id);void clear_latch() { m_latch.clear(); }+ void clear_latch_of_gesture(u64 gesture_id);void forget_gesture();void relatch_to(Web::AsyncScrollNodeStableID);- void note_page_let_latched_gesture_through();- bool page_let_latched_touchpad_gesture_through(Web::WheelDeltaPrecision, Web::ScrollGesturePhase) const;+ // This context's page dispatched a step of the gesture and did not cancel it, or canceled one.+ void note_page_let_gesture_through(u64 gesture_id);+ void forget_page_let_gesture_through(u64 gesture_id);+ // Whether the page let the gesture through, and its wheel event listeners are as they were then.+ bool page_let_gesture_through(Optional<u64> gesture_id) const;+ // Why this context's wheel event listeners hold the steps of a latched gesture back for the page, if they do. Once+ // the page let the gesture through, they only do so after they change.+ Optional<Web::InputRoutingDecision> reason_to_hold_latched_steps_back(Optional<u64> gesture_id) const;bool momentum_of_latched_gesture_can_spring_scroller_back() const;void set_momentum_of_latched_gesture_has_sprung_scroller_back(bool);@@ -94,10 +110,6 @@ 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 {};};struct NewestWheelEventIdsFromUI {@@ -112,13 +124,24 @@ private:struct Gesture {u64 id;Compositing::WheelGestureIdentity identity;+ Optional<Web::CompositorContextId> wheel_event_listener_context {};+ // Summed per axis, whatever the direction.+ Gfx::FloatPoint delta_left_to_the_page {};};// The gesture of the wheel events this context sees first: the UI's, or ones the UI never sent that the main- // thread makes. It says which gesture a step is in, whether this context or the main thread scrolls the step.+ // thread makes. It says which gesture a step is in, whether the page lets the step through before or after this+ // context scrolls by it.Optional<Gesture> m_gesture;NewestWheelEventIdsFromUI m_newest_wheel_event_ids_from_ui;bool m_gesture_had_wheel_event_with_delta { false };Optional<Latch> m_latch;+ // The gesture whose step this context's page dispatched and did not cancel, and the state of the page's wheel event+ // listeners then. The later steps of the gesture do not wait for the page for as long as the listeners stay so.+ struct GestureThePageLetThrough {+ u64 gesture_id { 0 };+ u64 wheel_event_listener_state_generation { 0 };+ };+ Optional<GestureThePageLetThrough> m_gesture_the_page_let_through;Compositing::TouchpadGestureEnd m_touchpad_gesture_end { Compositing::TouchpadGestureEnd::AfterIdleDelay };};diff --git a/Tests/Compositor/TestContextState.cpp b/Tests/Compositor/TestContextState.cppindex 56cf1cbec72..a9f239d79e8 100644--- a/Tests/Compositor/TestContextState.cpp+++ b/Tests/Compositor/TestContextState.cpp@@ -135,11 +135,11 @@ TEST_CASE(wheel_pans_the_zoomed_visual_viewport_of_a_page_without_scroll_nodes)wheel_event.wheel_delta_precision = Web::WheelDeltaPrecision::Precise;// Before the page is zoomed in, there is nothing for the wheel to pan.- EXPECT(!context.handle_wheel_event(wheel_event, false).accepted);+ EXPECT(!context.handle_wheel_event(wheel_event, false, {}).accepted);EXPECT(context.handle_pinch_event(pinch_event(1.0)).accepted);(void)context.take_pending_async_scroll_updates();- auto result = context.handle_wheel_event(wheel_event, false);+ auto result = context.handle_wheel_event(wheel_event, false, {});EXPECT(result.accepted);EXPECT(result.frame_to_present.has_value());diff --git a/Tests/LibWeb/Text/expected/async-scrolling/ui-mouse-wheel-under-a-wheel-listener-asks-only-about-the-first-tick.txt b/Tests/LibWeb/Text/expected/async-scrolling/ui-mouse-wheel-under-a-wheel-listener-asks-only-about-the-first-tick.txtnew file mode 100644index 00000000000..45f3aa1092f--- /dev/null+++ b/Tests/LibWeb/Text/expected/async-scrolling/ui-mouse-wheel-under-a-wheel-listener-asks-only-about-the-first-tick.txt@@ -0,0 +1,4 @@+cancelable ticks: true,false,false+window.scrollY after the ticks: 120+cancelable steps: true,false,false+window.scrollY after the steps: 240diff --git a/Tests/LibWeb/Text/expected/async-scrolling/ui-wheel-gesture-in-iframe-lets-go-of-the-scroller-of-the-gesture-before.txt b/Tests/LibWeb/Text/expected/async-scrolling/ui-wheel-gesture-in-iframe-lets-go-of-the-scroller-of-the-gesture-before.txtnew file mode 100644index 00000000000..4ea963a96cf--- /dev/null+++ b/Tests/LibWeb/Text/expected/async-scrolling/ui-wheel-gesture-in-iframe-lets-go-of-the-scroller-of-the-gesture-before.txt@@ -0,0 +1,3 @@+a.scrollTop after the first gesture: 40+a.scrollTop after the second gesture: 40+b.scrollTop after the second gesture: 30diff --git a/Tests/LibWeb/Text/expected/async-scrolling/ui-wheel-gesture-keeps-the-scroller-the-page-let-its-first-step-through-to.txt b/Tests/LibWeb/Text/expected/async-scrolling/ui-wheel-gesture-keeps-the-scroller-the-page-let-its-first-step-through-to.txtnew file mode 100644index 00000000000..07110df2fd1--- /dev/null+++ b/Tests/LibWeb/Text/expected/async-scrolling/ui-wheel-gesture-keeps-the-scroller-the-page-let-its-first-step-through-to.txt@@ -0,0 +1,3 @@+cancelable steps: true,false+nested.scrollTop: 80+outer.scrollTop: 0diff --git a/Tests/LibWeb/Text/expected/async-scrolling/ui-wheel-over-iframe-it-cannot-scroll-does-not-reach-the-pages-wheel-listener.txt b/Tests/LibWeb/Text/expected/async-scrolling/ui-wheel-over-iframe-it-cannot-scroll-does-not-reach-the-pages-wheel-listener.txtnew file mode 100644index 00000000000..43ba43c6c66--- /dev/null+++ b/Tests/LibWeb/Text/expected/async-scrolling/ui-wheel-over-iframe-it-cannot-scroll-does-not-reach-the-pages-wheel-listener.txt@@ -0,0 +1,6 @@+#1 compositor: nested-context-passed-step-on+#1 compositor: latched scroller=viewport+#1 compositor: forwarded-to-page+window.scrollY: 50+wheel events in the frame: 1+wheel events here: 0diff --git a/Tests/LibWeb/Text/expected/async-scrolling/ui-wheel-over-iframe-with-a-wheel-listener-asks-only-about-the-first-step.txt b/Tests/LibWeb/Text/expected/async-scrolling/ui-wheel-over-iframe-with-a-wheel-listener-asks-only-about-the-first-step.txtnew file mode 100644index 00000000000..fb960fcf016--- /dev/null+++ b/Tests/LibWeb/Text/expected/async-scrolling/ui-wheel-over-iframe-with-a-wheel-listener-asks-only-about-the-first-step.txt@@ -0,0 +1,5 @@+cancelable touchpad steps: true,false,false,false+frame scrollY after the touchpad gesture: 90+cancelable ticks: true,false,false+frame scrollY after the ticks: 210+window.scrollY: 0diff --git a/Tests/LibWeb/Text/expected/overscroll-behavior-stops-wheel-chaining-on-the-main-thread.txt b/Tests/LibWeb/Text/expected/overscroll-behavior-stops-wheel-chaining-under-a-wheel-listener.txtsimilarity index 100%rename from Tests/LibWeb/Text/expected/overscroll-behavior-stops-wheel-chaining-on-the-main-thread.txtrename to Tests/LibWeb/Text/expected/overscroll-behavior-stops-wheel-chaining-under-a-wheel-listener.txtdiff --git a/Tests/LibWeb/Text/expected/scroll-snap-wheel-step-of-a-new-gesture-during-snap-scroll.txt b/Tests/LibWeb/Text/expected/scroll-snap-wheel-step-of-a-new-gesture-during-snap-scroll.txtindex bd85b77c838..35719c830ac 100644--- a/Tests/LibWeb/Text/expected/scroll-snap-wheel-step-of-a-new-gesture-during-snap-scroll.txt+++ b/Tests/LibWeb/Text/expected/scroll-snap-wheel-step-of-a-new-gesture-during-snap-scroll.txt@@ -1,3 +1,3 @@Reversal in a nested scroller: 0, window: 0-Reversal on the root scroller: 0Handoff to the root scroller: 400, window: 100+Reversal on the root scroller: 0diff --git a/Tests/LibWeb/Text/expected/scroll-with-pinch-zoom-applied.txt b/Tests/LibWeb/Text/expected/scroll-with-pinch-zoom-applied.txtindex 32885f63cda..225a60b5e31 100644--- a/Tests/LibWeb/Text/expected/scroll-with-pinch-zoom-applied.txt+++ b/Tests/LibWeb/Text/expected/scroll-with-pinch-zoom-applied.txt@@ -1,4 +1,4 @@Initial: pageTop=0, scale=1After zoom: pageTop=33.328125, scale=1.5, offsetTop=33.328125-pageTop changed by: 100+pageTop changed by: 66.671875PASSdiff --git a/Tests/LibWeb/Text/expected/wheel-latch-drops-on-prevent-default.txt b/Tests/LibWeb/Text/expected/wheel-latch-drops-on-prevent-default.txtindex c3a55339995..33767c9f771 100644--- a/Tests/LibWeb/Text/expected/wheel-latch-drops-on-prevent-default.txt+++ b/Tests/LibWeb/Text/expected/wheel-latch-drops-on-prevent-default.txt@@ -1,3 +1,4 @@-scroller.scrollTop after the first tick: 100-window.scrollY after the cancelled tick: 0-window.scrollY after the tick following the cancelled one: 100+scroller.scrollTop after the cancelled tick: 0+scroller.scrollTop after the tick following the cancelled one: 100+window.scrollY after the last tick: 0+cancelable: true,true,falsediff --git a/Tests/LibWeb/Text/expected/wheel-latch-drops-when-latched-scroller-is-removed-by-listener.txt b/Tests/LibWeb/Text/expected/wheel-latch-drops-when-latched-scroller-is-removed-by-listener.txtindex 7372e318d71..fd17541c7d9 100644--- a/Tests/LibWeb/Text/expected/wheel-latch-drops-when-latched-scroller-is-removed-by-listener.txt+++ b/Tests/LibWeb/Text/expected/wheel-latch-drops-when-latched-scroller-is-removed-by-listener.txt@@ -1,3 +1,4 @@scroller.scrollTop after the first tick: 100scroller removed: true-window.scrollY after the second tick: 100+window.scrollY after the second tick: 0+window.scrollY after the third tick: 100diff --git a/Tests/LibWeb/Text/input/async-scrolling/ui-mouse-wheel-under-a-wheel-listener-asks-only-about-the-first-tick.html b/Tests/LibWeb/Text/input/async-scrolling/ui-mouse-wheel-under-a-wheel-listener-asks-only-about-the-first-tick.htmlnew file mode 100644index 00000000000..b11633a8d94--- /dev/null+++ b/Tests/LibWeb/Text/input/async-scrolling/ui-mouse-wheel-under-a-wheel-listener-asks-only-about-the-first-tick.html@@ -0,0 +1,32 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<style>+ body {+ margin: 0;+ height: 3000px;+ }+</style>+<script>+ promiseTest(async () => {+ const cancelable = [];+ window.addEventListener("wheel", event => cancelable.push(event.cancelable), { passive: false });+ await waitForCondition(() => internals.compositorWheelTargetAt(100, 100, 0, 40).decision === "blocking-wheel-event-listeners");++ // Mouse wheel ticks in quick succession at one spot are one gesture. The page sees its first tick before+ // anything scrolls, and lets it through, so the compositor scrolls the later ticks without asking again.+ await scrollSettled(document, async () => {+ for (let tick = 0; tick < 3; ++tick)+ await internals.wheelThroughUIProcess(100, 100, 0, 40);+ });+ println(`cancelable ticks: ${cancelable.splice(0).join(",")}`);+ println(`window.scrollY after the ticks: ${window.scrollY}`);++ // A burst of precise steps without phases, 50 CSS pixels away, is another gesture.+ await scrollSettled(document, async () => {+ for (let step = 0; step < 3; ++step)+ await internals.wheelThroughUIProcess(150, 100, 0, 40, true);+ });+ println(`cancelable steps: ${cancelable.splice(0).join(",")}`);+ println(`window.scrollY after the steps: ${window.scrollY}`);+ });+</script>diff --git a/Tests/LibWeb/Text/input/async-scrolling/ui-wheel-gesture-in-iframe-lets-go-of-the-scroller-of-the-gesture-before.html b/Tests/LibWeb/Text/input/async-scrolling/ui-wheel-gesture-in-iframe-lets-go-of-the-scroller-of-the-gesture-before.htmlnew file mode 100644index 00000000000..eb73eb361a2--- /dev/null+++ b/Tests/LibWeb/Text/input/async-scrolling/ui-wheel-gesture-in-iframe-lets-go-of-the-scroller-of-the-gesture-before.html@@ -0,0 +1,40 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<style>+ body {+ margin: 0;+ }++ iframe {+ display: block;+ width: 400px;+ height: 200px;+ border: 0;+ }+</style>+<script>+ promiseTest(async () => {+ const frame = document.createElement("iframe");+ const frameLoaded = new Promise(resolve => frame.addEventListener("load", resolve, { once: true }));+ frame.srcdoc = `<style>body { margin: 0; display: flex } .scroller { width: 150px; height: 150px; overflow: scroll } .content { height: 1000px }</style>+ <div id="a" class="scroller"><div class="content"></div></div><div id="b" class="scroller"><div class="content"></div></div>`;+ document.body.prepend(frame);+ await frameLoaded;+ const a = frame.contentDocument.getElementById("a");+ const b = frame.contentDocument.getElementById("b");+ b.addEventListener("wheel", () => { }, { passive: false });+ const routedInTheFrame = (route, decision) => route.document === frame.contentDocument && route.decision === decision;+ await waitForCondition(() => routedInTheFrame(internals.compositorWheelTargetAt(225, 75, 0, 30), "blocked-by-wheel-event-region")+ && routedInTheFrame(internals.compositorWheelTargetAt(75, 75, 0, 40), "latched"));++ // The compositor latches the gesture over #a to it.+ await scrollSettled(a, () => internals.wheelThroughUIProcess(75, 75, 0, 40, true));+ println(`a.scrollTop after the first gesture: ${a.scrollTop}`);++ // A step 150 CSS pixels away is another gesture, which the page sees first. The latch of the gesture before it+ // is no longer the gesture's, so the step scrolls #b.+ await scrollSettled(b, () => internals.wheelThroughUIProcess(225, 75, 0, 30, true));+ println(`a.scrollTop after the second gesture: ${a.scrollTop}`);+ println(`b.scrollTop after the second gesture: ${b.scrollTop}`);+ });+</script>diff --git a/Tests/LibWeb/Text/input/async-scrolling/ui-wheel-gesture-keeps-the-scroller-the-page-let-its-first-step-through-to.html b/Tests/LibWeb/Text/input/async-scrolling/ui-wheel-gesture-keeps-the-scroller-the-page-let-its-first-step-through-to.htmlnew file mode 100644index 00000000000..a24c06564a9--- /dev/null+++ b/Tests/LibWeb/Text/input/async-scrolling/ui-wheel-gesture-keeps-the-scroller-the-page-let-its-first-step-through-to.html@@ -0,0 +1,40 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<style>+ body {+ margin: 0;+ }++ #outer {+ width: 300px;+ height: 300px;+ overflow: scroll;+ }++ #nested {+ width: 100px;+ height: 100px;+ overflow: scroll;+ }++ .content {+ height: 1000px;+ }+</style>+<div id="outer"><div class="content"><div id="nested"><div class="content"></div></div></div></div>+<script>+ promiseTest(async () => {+ const cancelable = [];+ nested.addEventListener("wheel", event => cancelable.push(event.cancelable), { passive: false });+ await waitForCondition(() => internals.compositorWheelTargetAt(95, 50, 0, 40).decision === "blocked-by-wheel-event-region");++ // The page sees the first step over #nested before anything scrolls, and lets it through to #nested. The next+ // step of the gesture, 8 CSS pixels away over #outer, still scrolls #nested, and the page does not see it+ // first.+ await internals.wheelThroughUIProcess(95, 50, 0, 40, true);+ await internals.wheelThroughUIProcess(103, 50, 0, 40, true);+ println(`cancelable steps: ${cancelable.join(",")}`);+ println(`nested.scrollTop: ${nested.scrollTop}`);+ println(`outer.scrollTop: ${outer.scrollTop}`);+ });+</script>diff --git a/Tests/LibWeb/Text/input/async-scrolling/ui-wheel-over-iframe-it-cannot-scroll-does-not-reach-the-pages-wheel-listener.html b/Tests/LibWeb/Text/input/async-scrolling/ui-wheel-over-iframe-it-cannot-scroll-does-not-reach-the-pages-wheel-listener.htmlnew file mode 100644index 00000000000..0c14b6ad8cf--- /dev/null+++ b/Tests/LibWeb/Text/input/async-scrolling/ui-wheel-over-iframe-it-cannot-scroll-does-not-reach-the-pages-wheel-listener.html@@ -0,0 +1,40 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<style>+ body {+ margin: 0;+ height: 2000px;+ }++ iframe {+ display: block;+ width: 200px;+ height: 150px;+ border: 0;+ }+</style>+<script>+ promiseTest(async () => {+ const frame = document.createElement("iframe");+ const frameLoaded = new Promise(resolve => frame.addEventListener("load", resolve, { once: true }));+ frame.srcdoc = "<body></body>";+ document.body.prepend(frame);+ await frameLoaded;++ let wheelEventsHere = 0;+ window.addEventListener("wheel", () => ++wheelEventsHere, { passive: false });+ let wheelEventsInFrame = 0;+ frame.contentWindow.addEventListener("wheel", () => ++wheelEventsInFrame, { passive: true });+ await waitForCondition(() => frame.contentWindow.internals.compositorScrollState().document === frame.contentDocument+ && internals.compositorWheelTargetAt(100, 300, 0, 50).decision === "blocking-wheel-event-listeners");++ // The frame has nothing to scroll and passes the step on to this document. This document's listener never sees+ // the wheel events over the frame, so it does not hold the step back, and the compositor scrolls the page.+ internals.beginInputTrace();+ await scrollSettled(document, () => internals.wheelThroughUIProcess(100, 75, 0, 50));+ printInputTrace(internals.takeInputTrace(), { stages: ["compositor"] });+ println(`window.scrollY: ${window.scrollY}`);+ println(`wheel events in the frame: ${wheelEventsInFrame}`);+ println(`wheel events here: ${wheelEventsHere}`);+ });+</script>diff --git a/Tests/LibWeb/Text/input/async-scrolling/ui-wheel-over-iframe-with-a-wheel-listener-asks-only-about-the-first-step.html b/Tests/LibWeb/Text/input/async-scrolling/ui-wheel-over-iframe-with-a-wheel-listener-asks-only-about-the-first-step.htmlnew file mode 100644index 00000000000..e84e012b317--- /dev/null+++ b/Tests/LibWeb/Text/input/async-scrolling/ui-wheel-over-iframe-with-a-wheel-listener-asks-only-about-the-first-step.html@@ -0,0 +1,53 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<style>+ body {+ margin: 0;+ height: 2000px;+ }++ iframe {+ display: block;+ width: 200px;+ height: 150px;+ border: 0;+ }+</style>+<script>+ promiseTest(async () => {+ const frame = document.createElement("iframe");+ const frameLoaded = new Promise(resolve => frame.addEventListener("load", resolve, { once: true }));+ frame.srcdoc = "<body style='margin: 0; height: 1000px'></body>";+ document.body.prepend(frame);+ await frameLoaded;++ const cancelable = [];+ frame.contentWindow.addEventListener("wheel", event => cancelable.push(event.cancelable), { passive: false });+ // The compositor holds the first step of a gesture back for the frame's page from when it knows of the listener,+ // even while no frame shows the listener yet.+ await waitForCondition(() => {+ const route = internals.compositorWheelTargetAt(100, 75, 0, 30);+ return route.document === frame.contentDocument+ && ["blocking-wheel-event-listeners", "stale-wheel-event-listeners"].includes(route.decision);+ });++ // The frame's page sees the first step of a gesture before anything scrolls, and lets it through, so the+ // compositor scrolls the frame by the later steps without asking again.+ await scrollSettled(frame.contentDocument, async () => {+ for (let step = 0; step < 3; ++step)+ await internals.wheelThroughUIProcess(100, 75, 0, 30, true, "ongoing");+ await internals.wheelThroughUIProcess(100, 75, 0, 0, true, "ended");+ });+ println(`cancelable touchpad steps: ${cancelable.splice(0).join(",")}`);+ println(`frame scrollY after the touchpad gesture: ${frame.contentWindow.scrollY}`);++ // Mouse wheel ticks 50 CSS pixels away are another gesture, which the frame's page sees the first tick of.+ await scrollSettled(frame.contentDocument, async () => {+ for (let tick = 0; tick < 3; ++tick)+ await internals.wheelThroughUIProcess(150, 75, 0, 40);+ });+ println(`cancelable ticks: ${cancelable.splice(0).join(",")}`);+ println(`frame scrollY after the ticks: ${frame.contentWindow.scrollY}`);+ println(`window.scrollY: ${window.scrollY}`);+ });+</script>diff --git a/Tests/LibWeb/Text/input/overscroll-behavior-on-a-box-with-nothing-to-scroll.html b/Tests/LibWeb/Text/input/overscroll-behavior-on-a-box-with-nothing-to-scroll.htmlindex 0882c848d64..de4a888945c 100644--- a/Tests/LibWeb/Text/input/overscroll-behavior-on-a-box-with-nothing-to-scroll.html+++ b/Tests/LibWeb/Text/input/overscroll-behavior-on-a-box-with-nothing-to-scroll.html@@ -18,7 +18,7 @@</style><div id="box"><div></div></div><script>- // A wheel listener that may cancel the scroll keeps the scrolling of this page on the main thread.+ // A wheel listener that may cancel the scroll makes the compositor wait for the page before it scrolls a gesture.window.addEventListener("wheel", () => { }, { passive: false });promiseTest(async () => {diff --git a/Tests/LibWeb/Text/input/overscroll-behavior-stops-wheel-chaining-on-the-main-thread.html b/Tests/LibWeb/Text/input/overscroll-behavior-stops-wheel-chaining-under-a-wheel-listener.htmlsimilarity index 96%rename from Tests/LibWeb/Text/input/overscroll-behavior-stops-wheel-chaining-on-the-main-thread.htmlrename to Tests/LibWeb/Text/input/overscroll-behavior-stops-wheel-chaining-under-a-wheel-listener.htmlindex a305127dc3a..c3822db99fa 100644--- a/Tests/LibWeb/Text/input/overscroll-behavior-stops-wheel-chaining-on-the-main-thread.html+++ b/Tests/LibWeb/Text/input/overscroll-behavior-stops-wheel-chaining-under-a-wheel-listener.html@@ -18,7 +18,7 @@</style><div id="scroller"><div></div></div><script>- // A wheel listener that may cancel the scroll keeps the scrolling of this page on the main thread.+ // A wheel listener that may cancel the scroll makes the compositor wait for the page before it scrolls a gesture.window.addEventListener("wheel", () => { }, { passive: false });async function touchpadGesture(deltaX, deltaY) {diff --git a/Tests/LibWeb/Text/input/scroll-snap-new-gesture-during-snap-scroll.html b/Tests/LibWeb/Text/input/scroll-snap-new-gesture-during-snap-scroll.htmlindex 8cc5310e570..212bcfa05dc 100644--- a/Tests/LibWeb/Text/input/scroll-snap-new-gesture-during-snap-scroll.html+++ b/Tests/LibWeb/Text/input/scroll-snap-new-gesture-during-snap-scroll.html@@ -21,7 +21,7 @@promiseTest(async () => {const scroller = document.getElementById("scroller");- // A blocking wheel event listener keeps the scrolling of this gesture on the main thread.+ // A blocking wheel event listener makes the compositor wait for the page before it scrolls this gesture.scroller.addEventListener("wheel", () => {});await animationFrame();diff --git a/Tests/LibWeb/Text/input/scroll-snap-wheel-step-of-a-new-gesture-during-snap-scroll.html b/Tests/LibWeb/Text/input/scroll-snap-wheel-step-of-a-new-gesture-during-snap-scroll.htmlindex 03cade02364..d47d5113493 100644--- a/Tests/LibWeb/Text/input/scroll-snap-wheel-step-of-a-new-gesture-during-snap-scroll.html+++ b/Tests/LibWeb/Text/input/scroll-snap-wheel-step-of-a-new-gesture-during-snap-scroll.html@@ -45,8 +45,9 @@const reversalScroller = document.getElementById("reversal-scroller");const handoffScroller = document.getElementById("handoff-scroller");- // A blocking wheel event listener keeps the scrolling on the main thread. Each step is taken 30px away from the- // one before it, so it starts a new gesture while the snap scroll of the previous one is still in flight.+ // A blocking wheel event listener makes the compositor wait for the page before it scrolls. Each step is taken+ // 30px away from the one before it, so it starts a new gesture while the snap scroll of the previous one is+ // still in flight.window.addEventListener("wheel", () => {}, { passive: false });await waitForCondition(() => internals.compositorWheelTargetAt(50, 50, 0, 10).decision === "blocking-wheel-event-listeners");@@ -60,12 +61,14 @@await wheelStepsWhileMovingThePointer(50, 50, [200, -40], []);println(`Reversal in a nested scroller: ${reversalScroller.scrollTop}, window: ${window.scrollY}`);+ await wheelStepsWhileMovingThePointer(50, 250, [500, 100], [handoffScroller, document]);+ println(`Handoff to the root scroller: ${handoffScroller.scrollTop}, window: ${window.scrollY}`);++ // The compositor snaps the root scroller by the scroll snap type the frames show it, which they keep showing+ // once the root element no longer has it. This case comes last for that reason.+ await scrollSettled(document, () => window.scrollTo(0, 0));document.documentElement.style.scrollSnapType = "y mandatory";await wheelStepsWhileMovingThePointer(300, 50, [200, -40], []);println(`Reversal on the root scroller: ${window.scrollY}`);- document.documentElement.style.scrollSnapType = "";-- await wheelStepsWhileMovingThePointer(50, 250, [500, 100], [handoffScroller, document]);- println(`Handoff to the root scroller: ${handoffScroller.scrollTop}, window: ${window.scrollY}`);});</script>diff --git a/Tests/LibWeb/Text/input/scroll-with-pinch-zoom-applied.html b/Tests/LibWeb/Text/input/scroll-with-pinch-zoom-applied.htmlindex ac7d8968fcd..742f3cbfd6e 100644--- a/Tests/LibWeb/Text/input/scroll-with-pinch-zoom-applied.html+++ b/Tests/LibWeb/Text/input/scroll-with-pinch-zoom-applied.html@@ -36,12 +36,13 @@println(`pageTop changed by: ${scrolled}`);- // The scroll amount should be approximately equal to the requested delta+ // The delta is in screen pixels, which pan the zoomed visual viewport by the delta divided by the scale.// Allow small tolerance for floating point- if (Math.abs(scrolled - scrollDelta) < 1) {+ const expectedScroll = scrollDelta / vv.scale;+ if (Math.abs(scrolled - expectedScroll) < 1) {println("PASS");} else {- println(`FAIL: Expected scroll of ${scrollDelta}, got ${scrolled}`);+ println(`FAIL: Expected scroll of ${expectedScroll}, got ${scrolled}`);}done();});diff --git a/Tests/LibWeb/Text/input/visual-viewport-horizontal-scroll-hit-test.html b/Tests/LibWeb/Text/input/visual-viewport-horizontal-scroll-hit-test.htmlindex 0d2ab439d11..f94d0d05e2b 100644--- a/Tests/LibWeb/Text/input/visual-viewport-horizontal-scroll-hit-test.html+++ b/Tests/LibWeb/Text/input/visual-viewport-horizontal-scroll-hit-test.html@@ -36,8 +36,8 @@let hit = internals.hitTest(200, 150);results.push(`before scroll: ${hit.node.id}`);- // Scroll right by 400 to pan the visual viewport to the right half- internals.wheel(200, 150, 400, 0);+ // Scroll right by 800 screen pixels, which pan the visual viewport at zoom 2 by 400 to the right half+ internals.wheel(200, 150, 800, 0);await scrollOffsetStopsChanging(() => vv.offsetLeft);// Do not call println() here — DOM mutation triggers layout whichdiff --git a/Tests/LibWeb/Text/input/wheel-latch-drops-on-prevent-default.html b/Tests/LibWeb/Text/input/wheel-latch-drops-on-prevent-default.htmlindex 5f7080a1285..b87b21ee179 100644--- a/Tests/LibWeb/Text/input/wheel-latch-drops-on-prevent-default.html+++ b/Tests/LibWeb/Text/input/wheel-latch-drops-on-prevent-default.html@@ -17,23 +17,26 @@<div id="scroller"><div></div></div><script>promiseTest(async () => {- let wheelEvents = 0;+ const cancelable = [];scroller.addEventListener("wheel", event => {- if (++wheelEvents == 2)+ cancelable.push(event.cancelable);+ if (cancelable.length == 1)event.preventDefault();}, { passive: false });await animationFrame();await animationFrame();await internals.wheel(50, 50, 0, 100);- println(`scroller.scrollTop after the first tick: ${scroller.scrollTop}`);+ println(`scroller.scrollTop after the cancelled tick: ${scroller.scrollTop}`);+ // The cancelled event ended the gesture the scroller was latched for, so the page sees this tick first again,+ // and it is routed afresh.await internals.wheel(50, 50, 0, 100);- println(`window.scrollY after the cancelled tick: ${window.scrollY}`);+ println(`scroller.scrollTop after the tick following the cancelled one: ${scroller.scrollTop}`);- // The cancelled event ended the gesture the scroller was latched for, so this tick is routed afresh, and- // the scroller at its extent leaves it to the page.+ // The page let the gesture through, so this tick does not wait for it, and the scroller at its extent keeps it.await internals.wheel(50, 50, 0, 100);- println(`window.scrollY after the tick following the cancelled one: ${window.scrollY}`);+ println(`window.scrollY after the last tick: ${window.scrollY}`);+ println(`cancelable: ${cancelable.join(",")}`);});</script>diff --git a/Tests/LibWeb/Text/input/wheel-latch-drops-when-latched-scroller-is-removed-by-listener.html b/Tests/LibWeb/Text/input/wheel-latch-drops-when-latched-scroller-is-removed-by-listener.htmlindex 435e2221a05..18f684cdbe2 100644--- a/Tests/LibWeb/Text/input/wheel-latch-drops-when-latched-scroller-is-removed-by-listener.html+++ b/Tests/LibWeb/Text/input/wheel-latch-drops-when-latched-scroller-is-removed-by-listener.html@@ -31,9 +31,14 @@await internals.wheel(50, 50, 0, 100);println(`scroller.scrollTop after the first tick: ${scroller.scrollTop}`);- // The listener removes the scroller the gesture is latched to, so the tick is routed afresh.+ // The page let the gesture through, so the compositor scrolls the latched scroller by this tick before the+ // listener removes the scroller.await internals.wheel(50, 50, 0, 100);println(`scroller removed: ${!scroller.isConnected}`);println(`window.scrollY after the second tick: ${window.scrollY}`);++ // The scroller the gesture is latched to is gone, so the tick is routed afresh, to the page.+ await internals.wheel(50, 50, 0, 100);+ println(`window.scrollY after the third tick: ${window.scrollY}`);});</script>diff --git a/Tests/LibWeb/Text/input/wheel-latch-keeps-wheel-event-target.html b/Tests/LibWeb/Text/input/wheel-latch-keeps-wheel-event-target.htmlindex fd5d9a9c8df..4dae309237e 100644--- a/Tests/LibWeb/Text/input/wheel-latch-keeps-wheel-event-target.html+++ b/Tests/LibWeb/Text/input/wheel-latch-keeps-wheel-event-target.html@@ -24,7 +24,7 @@<script>promiseTest(async () => {const targets = [];- // Blocking wheel event listeners keep the scrolling of these gestures on the main thread.+ // Blocking wheel event listeners make the compositor wait for the page before it scrolls these gestures.for (const element of [a, b])element.addEventListener("wheel", event => targets.push(event.currentTarget.id), { passive: false });await animationFrame();diff --git a/Tests/LibWeb/Text/input/wheel-latch-nested-scroller-at-extent-does-not-chain-mid-gesture.html b/Tests/LibWeb/Text/input/wheel-latch-nested-scroller-at-extent-does-not-chain-mid-gesture.htmlindex c4640ec0e18..6119807d6f5 100644--- a/Tests/LibWeb/Text/input/wheel-latch-nested-scroller-at-extent-does-not-chain-mid-gesture.html+++ b/Tests/LibWeb/Text/input/wheel-latch-nested-scroller-at-extent-does-not-chain-mid-gesture.html@@ -17,7 +17,7 @@<div id="nested"><div></div></div><script>promiseTest(async () => {- // A blocking wheel event listener keeps the scrolling of these gestures on the main thread.+ // A blocking wheel event listener makes the compositor wait for the page before it scrolls these gestures.nested.addEventListener("wheel", () => {}, { passive: false });await animationFrame();await animationFrame();diff --git a/Tests/LibWeb/Text/input/wheel-latch-outer-scroller-keeps-gesture-when-nested-scroller-slides-under-cursor.html b/Tests/LibWeb/Text/input/wheel-latch-outer-scroller-keeps-gesture-when-nested-scroller-slides-under-cursor.htmlindex 7128b1e23b8..b5a78a30c6b 100644--- a/Tests/LibWeb/Text/input/wheel-latch-outer-scroller-keeps-gesture-when-nested-scroller-slides-under-cursor.html+++ b/Tests/LibWeb/Text/input/wheel-latch-outer-scroller-keeps-gesture-when-nested-scroller-slides-under-cursor.html@@ -20,7 +20,7 @@<div id="nested"><div></div></div><script>promiseTest(async () => {- // A blocking wheel event listener keeps the scrolling of these gestures on the main thread.+ // A blocking wheel event listener makes the compositor wait for the page before it scrolls these gestures.window.addEventListener("wheel", () => {}, { passive: false });await animationFrame();await animationFrame();diff --git a/Tests/LibWeb/Text/input/wheel-latch-over-iframe-keeps-iframe-at-its-extent-mid-gesture.html b/Tests/LibWeb/Text/input/wheel-latch-over-iframe-keeps-iframe-at-its-extent-mid-gesture.htmlindex aca8a4806b9..4a0fde7e0b4 100644--- a/Tests/LibWeb/Text/input/wheel-latch-over-iframe-keeps-iframe-at-its-extent-mid-gesture.html+++ b/Tests/LibWeb/Text/input/wheel-latch-over-iframe-keeps-iframe-at-its-extent-mid-gesture.html@@ -19,7 +19,7 @@iframe.srcdoc = `<style>body { margin: 0; height: 600px; } html { scrollbar-width: none; }</style>`;document.body.prepend(iframe);await iframeLoaded;- // A blocking wheel event listener keeps the scrolling of these gestures on the main thread.+ // A blocking wheel event listener makes the compositor wait for the page before it scrolls these gestures.iframe.contentWindow.addEventListener("wheel", () => {}, { passive: false });await animationFrame();await animationFrame();diff --git a/Tests/LibWeb/Text/input/wheel-latch-parent-scroller-does-not-hand-gesture-to-iframe-mid-gesture.html b/Tests/LibWeb/Text/input/wheel-latch-parent-scroller-does-not-hand-gesture-to-iframe-mid-gesture.htmlindex 1fe09deef4c..6f3d1d37ac4 100644--- a/Tests/LibWeb/Text/input/wheel-latch-parent-scroller-does-not-hand-gesture-to-iframe-mid-gesture.html+++ b/Tests/LibWeb/Text/input/wheel-latch-parent-scroller-does-not-hand-gesture-to-iframe-mid-gesture.html@@ -25,7 +25,7 @@let wheelEventsInIframe = 0;iframe.contentWindow.addEventListener("wheel", () => ++wheelEventsInIframe, { passive: false });- // A blocking wheel event listener keeps the scrolling of these gestures on the main thread.+ // A blocking wheel event listener makes the compositor wait for the page before it scrolls these gestures.window.addEventListener("wheel", () => {}, { passive: false });await animationFrame();await animationFrame();diff --git a/Tests/LibWeb/Text/input/wheel-latch-phase-less-gesture-expires-after-idle.html b/Tests/LibWeb/Text/input/wheel-latch-phase-less-gesture-expires-after-idle.htmlindex fa80fe93d8b..3931d72976a 100644--- a/Tests/LibWeb/Text/input/wheel-latch-phase-less-gesture-expires-after-idle.html+++ b/Tests/LibWeb/Text/input/wheel-latch-phase-less-gesture-expires-after-idle.html@@ -17,7 +17,7 @@<div id="nested"><div></div></div><script>promiseTest(async () => {- // A blocking wheel event listener keeps the scrolling of these gestures on the main thread.+ // A blocking wheel event listener makes the compositor wait for the page before it scrolls these gestures.nested.addEventListener("wheel", () => {}, { passive: false });await animationFrame();await animationFrame();diff --git a/Tests/LibWeb/Text/input/wheel-latch-phase-less-ticks-stay-latched-until-cursor-moves.html b/Tests/LibWeb/Text/input/wheel-latch-phase-less-ticks-stay-latched-until-cursor-moves.htmlindex 33f9add893e..bfbbe3a43b4 100644--- a/Tests/LibWeb/Text/input/wheel-latch-phase-less-ticks-stay-latched-until-cursor-moves.html+++ b/Tests/LibWeb/Text/input/wheel-latch-phase-less-ticks-stay-latched-until-cursor-moves.html@@ -17,7 +17,7 @@<div id="nested"><div></div></div><script>promiseTest(async () => {- // A blocking wheel event listener keeps the scrolling of these gestures on the main thread.+ // A blocking wheel event listener makes the compositor wait for the page before it scrolls these gestures.nested.addEventListener("wheel", () => {}, { passive: false });await animationFrame();await animationFrame();