Truly independent web browser
LibCompositing+Compositor: Hand wheel gestures over iframes to them
Aliaksandr Kalenik7a98994ae10b
diff --git a/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cpp b/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cppindex fe5abdeb45e..ea9fc3dac4e 100644--- a/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cpp+++ b/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cpp@@ -23,6 +23,8 @@ void AsyncScrollTree::set_state(AsyncScrollingState&& state)m_blocking_wheel_event_regions = move(state.blocking_wheel_event_regions);m_scroll_chaining_barriers = move(state.scroll_chaining_barriers);m_has_blocking_wheel_event_region_covering_viewport = state.has_blocking_wheel_event_region_covering_viewport;+ m_viewport_keeps_horizontal_scrolls = state.viewport_keeps_horizontal_scrolls;+ m_viewport_keeps_vertical_scrolls = state.viewport_keeps_vertical_scrolls;m_cached_wheel_hit_test_targets.clear();m_cached_main_thread_wheel_event_targets.clear();m_cached_nested_context_wheel_regions.clear();@@ -86,7 +88,9 @@ WheelHitTestResult AsyncScrollTree::hit_test_result_for_scroll_node(AsyncScrollNreturn { .outcome = WheelHitTestOutcome::BlockedByMainThreadRegion };if (can_take_step(*node))return { .outcome = WheelHitTestOutcome::FoundScrollTarget, .node_id = node->node_id, .innermost_scroll_node_id = node_id };- if (!node_chains_scroll_to_ancestors(*node, delta) || !node->parent_node_id.has_value())+ if (!node_chains_scroll_to_ancestors(*node, delta))+ return { .outcome = WheelHitTestOutcome::NoScrollTarget, .innermost_scroll_node_id = node_id, .node_keeping_the_scroll = node->node_id };+ if (!node->parent_node_id.has_value())break;node = scroll_node_for_id(*node->parent_node_id);}@@ -443,40 +447,68 @@ bool AsyncScrollTree::blocks_wheel_event_at_position(Compositing::AccumulatedVisreturn false;}-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) const+bool AsyncScrollTree::main_thread_wheel_event_region_contains(Compositing::AccumulatedVisualContextTree const& visual_context_tree, Gfx::FloatPoint position) const{- if (m_visual_context_tree_structural_epoch != visual_context_tree.structural_epoch())- return { .outcome = WheelHitTestOutcome::HitTestTargetsOfAnotherVisualContextTree };-- auto context_is_valid = [&](Compositing::ContextRef context) {- 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)- return { .outcome = WheelHitTestOutcome::BlockedByWheelEventRegion };-for (auto const& target : m_cached_main_thread_wheel_event_targets) {if (target.viewport_rect.has_value() && !target.viewport_rect->contains(position))continue;- if (!context_is_valid(target.context))+ if (!visual_context_tree.context_is_valid(target.context))continue;auto position_in_context = visual_context_tree.transform_point_for_hit_test(target.context, position, m_scroll_state_snapshot);if (position_in_context.has_value() && target.rect.contains(*position_in_context))- return { .outcome = WheelHitTestOutcome::BlockedByMainThreadRegion };+ return true;}+ return false;+}- // The main thread hands a wheel over a nested context's content to the nested navigable.- for (auto const& cached_region : m_cached_nested_context_wheel_regions) {+Optional<AsyncScrollTree::NestedContextWheelRegionHit> AsyncScrollTree::topmost_nested_context_wheel_region_at(Compositing::AccumulatedVisualContextTree const& visual_context_tree, Gfx::FloatPoint position) const+{+ for (auto const& cached_region : m_cached_nested_context_wheel_regions.in_reverse()) {auto const& region = cached_region.region;if (cached_region.viewport_rect.has_value() && !cached_region.viewport_rect->contains(position))continue;- if (!context_is_valid(region.context))+ if (!visual_context_tree.context_is_valid(region.context))continue;auto position_in_context = visual_context_tree.transform_point_for_hit_test(region.context, position, m_scroll_state_snapshot);if (position_in_context.has_value() && rounded_rect_contains_point(region.rect, region.corner_radii, *position_in_context))- return { .outcome = WheelHitTestOutcome::BlockedByMainThreadRegion };+ return NestedContextWheelRegionHit { region, *position_in_context };}+ return {};+}++Optional<NestedContextWheelHit> AsyncScrollTree::nested_context_for_wheel_at(Compositing::AccumulatedVisualContextTree const& visual_context_tree, Gfx::FloatPoint position) const+{+ if (m_visual_context_tree_structural_epoch != visual_context_tree.structural_epoch())+ return {};+ if (main_thread_wheel_event_region_contains(visual_context_tree, position))+ return {};+ auto hit = topmost_nested_context_wheel_region_at(visual_context_tree, position);+ if (!hit.has_value() || is_covered_by_hit_test_target_painted_after(hit->region.paint_order_index, visual_context_tree, position))+ return {};+ return NestedContextWheelHit {+ .child_context_id = hit->region.child_context_id,+ .position_in_content_box = hit->position_in_context - hit->region.rect.location(),+ .content_box_size = hit->region.rect.size(),+ };+}++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())+ return { .outcome = WheelHitTestOutcome::HitTestTargetsOfAnotherVisualContextTree };++ auto context_is_valid = [&](Compositing::ContextRef context) {+ 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)+ return { .outcome = WheelHitTestOutcome::BlockedByWheelEventRegion };++ if (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))return { .outcome = WheelHitTestOutcome::BlockedByWheelEventRegion };@@ -521,11 +553,11 @@ WheelHitTestResult AsyncScrollTree::hit_test_scroll_node_for_wheel(Compositing::return hit_test_result_for_scroll_node(*viewport_node_id, delta, in_flight_destination_for, scroll_nodes_behind_scroll_chaining_barriers);}-FirstWheelStepRoute AsyncScrollTree::route_first_wheel_step(WheelRoutingAdmission admission, Compositing::AccumulatedVisualContextTree const& visual_context_tree, Gfx::FloatPoint position, Gfx::FloatPoint delta) const+FirstWheelStepRoute AsyncScrollTree::route_first_wheel_step(WheelRoutingAdmission admission, Compositing::AccumulatedVisualContextTree const& visual_context_tree, Gfx::FloatPoint position, Gfx::FloatPoint delta, NestedContextRegions nested_context_regions) const{if (admission != WheelRoutingAdmission::Accepted)return { input_routing_decision_for_wheel_step_not_admitted_by(admission) };- auto scroll_target = hit_test_scroll_node_for_wheel(visual_context_tree, position, delta);+ auto scroll_target = hit_test_scroll_node_for_wheel(visual_context_tree, position, delta, {}, WheelStepDispatch::NotYetDispatched, nested_context_regions);FirstWheelStepRoute route { input_routing_decision_for_first_wheel_step(scroll_target.outcome) };if (scroll_target.node_id.has_value()) {if (auto const* node = scroll_node_for_id(*scroll_target.node_id))@@ -579,6 +611,11 @@ bool AsyncScrollTree::scroll_node_is_viewport(AsyncScrollNodeID node_id) constreturn node && node->is_viewport;}+bool AsyncScrollTree::viewport_keeps_scrolls_along_main_axis_of(Gfx::FloatPoint delta) const+{+ return delta_is_mainly_vertical(delta) ? m_viewport_keeps_vertical_scrolls : m_viewport_keeps_horizontal_scrolls;+}+Optional<Gfx::FloatPoint> AsyncScrollTree::set_scroll_offset(AsyncScrollNodeID node_id, Gfx::FloatPoint scroll_offset, Compositing::AccumulatedVisualContextTree const& visual_context_tree, Compositing::ScrollStateSnapshot& scroll_state_snapshot){auto const* node = scroll_node_for_id(node_id);diff --git a/Libraries/LibCompositing/Scrolling/AsyncScrollTree.h b/Libraries/LibCompositing/Scrolling/AsyncScrollTree.hindex 2526c547d40..83c4c22dab4 100644--- a/Libraries/LibCompositing/Scrolling/AsyncScrollTree.h+++ b/Libraries/LibCompositing/Scrolling/AsyncScrollTree.h@@ -37,6 +37,9 @@ struct WheelHitTestResult {// The scroller the wheel is over, which is where the search for `node_id` started. It is set even if neither it// nor any scroller around it can scroll by the delta.Optional<AsyncScrollNodeID> innermost_scroll_node_id {};+ // The scroller that keeps the delta from the scrollers around it, when the outcome is NoScrollTarget for that+ // reason rather than because no scroller is left to offer it to.+ Optional<AsyncScrollNodeID> node_keeping_the_scroll {};bool is_blocked_by_a_region() const{@@ -60,6 +63,24 @@ struct FirstWheelStepRouteForTesting {Optional<Web::UniqueNodeID> document_id;};+// 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.+ LeaveToMainThread,+ // The step is handed to the nested context under it, which only gets here if there is none.+ HandToNestedContext,+ // The nested context passed the step on, so it goes to whatever is under the nested context.+ Ignore,+};++// Where a wheel over the content of a nested context lands in it.+struct NestedContextWheelHit {+ Web::CompositorContextId child_context_id;+ // Relative to the origin of the nested context's content box, in the device pixels of the containing context.+ Gfx::FloatPoint position_in_content_box;+ Gfx::FloatSize content_box_size;+};+struct WheelScrollTarget {Web::AsyncScrollNodeStableID stable_node_id;Gfx::FloatPoint current_offset;@@ -127,15 +148,20 @@ public:Gfx::FloatPoint device_offset_from_css_pixels(Web::CSSPixelPoint) const;Optional<Web::CSSPixelPoint> css_scroll_offset_for_node(AsyncScrollNodeID, Compositing::ScrollStateSnapshot const&) const;bool blocks_wheel_event_at_position(Compositing::AccumulatedVisualContextTree const&, Gfx::FloatPoint position) const;- WheelHitTestResult hit_test_scroll_node_for_wheel(Compositing::AccumulatedVisualContextTree const&, Gfx::FloatPoint position, Gfx::FloatPoint delta, Function<Optional<Gfx::FloatPoint>(Web::AsyncScrollNodeStableID)> const& in_flight_destination_for = {}, WheelStepDispatch = WheelStepDispatch::NotYetDispatched) const;+ WheelHitTestResult hit_test_scroll_node_for_wheel(Compositing::AccumulatedVisualContextTree const&, Gfx::FloatPoint position, Gfx::FloatPoint delta, Function<Optional<Gfx::FloatPoint>(Web::AsyncScrollNodeStableID)> const& in_flight_destination_for = {}, WheelStepDispatch = WheelStepDispatch::NotYetDispatched, NestedContextRegions = NestedContextRegions::LeaveToMainThread) const;+ // The nested context whose content is the topmost thing taking pointer input at the position, if any.+ Optional<NestedContextWheelHit> nested_context_for_wheel_at(Compositing::AccumulatedVisualContextTree const&, Gfx::FloatPoint position) const;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// to be covered whenever that cannot be told.bool is_covered_by_hit_test_target_painted_after(u32 paint_order_index, Compositing::AccumulatedVisualContextTree const&, Gfx::FloatPoint position) const;bool scroll_node_is_viewport(AsyncScrollNodeID) const;+ // Whether the viewport keeps a scroll by the delta from the document it is nested in, whether or not it has a+ // scroll node.+ bool viewport_keeps_scrolls_along_main_axis_of(Gfx::FloatPoint delta) const;// Leaves out what only a compositor holding a gesture decides: whether a step continues a latched gesture, which// scroller fingers at its edge stretch, and whether a zoomed page pans its visual viewport.- FirstWheelStepRoute route_first_wheel_step(WheelRoutingAdmission, Compositing::AccumulatedVisualContextTree const&, Gfx::FloatPoint position, Gfx::FloatPoint delta) const;+ FirstWheelStepRoute route_first_wheel_step(WheelRoutingAdmission, Compositing::AccumulatedVisualContextTree const&, Gfx::FloatPoint position, Gfx::FloatPoint delta, NestedContextRegions = NestedContextRegions::LeaveToMainThread) const;// 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<AsyncScrollNodeID> outermost_scroll_node_wheel_scrollable_along_main_axis_of(AsyncScrollNodeID innermost_node_id, Gfx::FloatPoint delta) const;@@ -153,6 +179,12 @@ private:WheelHitTestResult hit_test_result_for_scroll_node(AsyncScrollNodeID, Gfx::FloatPoint delta, Function<Optional<Gfx::FloatPoint>(Web::AsyncScrollNodeStableID)> const& in_flight_destination_for, ReadonlySpan<AsyncScrollNodeID> scroll_nodes_behind_scroll_chaining_barriers) 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 {+ NestedContextWheelRegion const& region;+ Gfx::FloatPoint position_in_context;+ };+ Optional<NestedContextWheelRegionHit> topmost_nested_context_wheel_region_at(Compositing::AccumulatedVisualContextTree const&, Gfx::FloatPoint position) const;Optional<AsyncScrollNodeID> scrollable_ancestor_for_node(AsyncScrollNodeID, Compositing::ScrollStateSnapshot const&, Gfx::FloatPoint delta) const;Gfx::FloatPoint apply_scroll_delta_to_node(AsyncScrollNode const&, Gfx::FloatPoint delta, Compositing::ScrollStateSnapshot&);@@ -173,6 +205,8 @@ private:Optional<u64> m_visual_context_tree_structural_epoch;Compositing::ScrollStateSnapshot m_scroll_state_snapshot;bool m_has_blocking_wheel_event_region_covering_viewport { false };+ bool m_viewport_keeps_horizontal_scrolls { false };+ bool m_viewport_keeps_vertical_scrolls { false };};}diff --git a/Libraries/LibWebCommon/Page/InputRoutingDecision.h b/Libraries/LibWebCommon/Page/InputRoutingDecision.hindex 568e5b4937a..daf4b1fa433 100644--- a/Libraries/LibWebCommon/Page/InputRoutingDecision.h+++ b/Libraries/LibWebCommon/Page/InputRoutingDecision.h@@ -32,6 +32,9 @@ namespace Web {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") \diff --git a/Services/Compositor/CompositorState.cpp b/Services/Compositor/CompositorState.cppindex c78fae04e2c..04924808f3c 100644--- a/Services/Compositor/CompositorState.cpp+++ b/Services/Compositor/CompositorState.cpp@@ -578,9 +578,11 @@ void CompositorState::handle_and_dispatch_mouse_event(Web::CompositorContextId cContextState::ContextUpdateResult result;if (is_wheel_event)- result = scroll_for_wheel_step(*context, event, WheelStepOrigin::UI);+ result = scroll_for_wheel_step(context_id, *context, event, WheelStepOrigin::UI);elseresult = context->handle_mouse_event(event);+ if (result.nested_context_hand_off.has_value())+ record_routing(*result.nested_context_hand_off);if (result.routing_decision.has_value()) {dbgln_if(COMPOSITOR_DEBUG, "[Compositor] Context {} routed input event {}: {}", context_id, event.id, Web::input_routing_decision_name(*result.routing_decision));record_routing(*result.routing_decision, result.routed_scroller);@@ -611,40 +613,151 @@ void CompositorState::handle_and_dispatch_mouse_event(Web::CompositorContextId cbool CompositorState::nested_context_scrolled_since_last_frame(Web::CompositorContextId context_id) const{for (auto const& entry : m_contexts) {- auto const& context = *entry.value;- if (!context.scrolled_since_last_frame())- continue;- for (auto parent_context_id = context.parent_context_id(); parent_context_id.has_value();) {- if (*parent_context_id == context_id)- return true;- auto const* parent_context = context_if_present(*parent_context_id);- if (!parent_context)- break;- parent_context_id = parent_context->parent_context_id();- }+ if (entry.value->scrolled_since_last_frame() && is_nested_in(context_id, *entry.value))+ return true;}return false;}-ContextState::ContextUpdateResult CompositorState::scroll_for_wheel_step(ContextState& context, Web::MouseEvent const& event, WheelStepOrigin origin, Optional<MonotonicTime> fling_step_time)+bool CompositorState::is_nested_in(Web::CompositorContextId containing_context_id, ContextState const& context) const{- if (origin == WheelStepOrigin::UI)- return context.handle_wheel_event(event);+ // A walk up the parents that outlasts the number of contexts went around a loop.+ auto const* ancestor = &context;+ for (size_t remaining_ancestors = m_contexts.size(); ancestor && remaining_ancestors > 0; --remaining_ancestors) {+ auto parent_context_id = ancestor->parent_context_id();+ if (!parent_context_id.has_value())+ return false;+ if (*parent_context_id == containing_context_id)+ return true;+ ancestor = context_if_present(*parent_context_id);+ }+ return false;+}++ContextState::ContextUpdateResult CompositorState::scroll_for_wheel_step(Web::CompositorContextId context_id, ContextState& context, Web::MouseEvent const& event, WheelStepOrigin origin, Optional<MonotonicTime> fling_step_time)+{+ auto now = fling_step_time.value_or(MonotonicTime::now());+ auto result = origin == WheelStepOrigin::UI ? context.handle_wheel_event(event) : context.scroll_for_fling_step(event, now);+ 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, now);+ result = move(handed_step.result);+ presents_frame = handed_step.nested_context_presents_frame;+ }- auto result = context.scroll_for_fling_step(event, fling_step_time.value_or(MonotonicTime::now()));// If the compositor accepts a momentum step of the fling but does not scroll, the scroller is at its edge.// Alternatively, a snap scroll uses the step. The next display tick ends the fling.- if (event.scroll_gesture_phase == Web::ScrollGesturePhase::Momentum && result.accepted && !result.frame_to_present.has_value())+ if (origin == WheelStepOrigin::Fling && event.scroll_gesture_phase == Web::ScrollGesturePhase::Momentum && result.accepted && !presents_frame)context.end_scroll_fling_on_next_step();return 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, MonotonicTime now)+{+ auto step = ContextState::WheelStepFromContainingContext::for_wheel_event(event);+ // 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.+ 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> {},+ },+ .nested_context_presents_frame = nested_result.frame_to_present.has_value(),+ };+ };++ if (!nested_step.hit.has_value()) {+ auto* nested_context = context_if_present(nested_step.context_id);+ if (!nested_context || !is_nested_in(context_id, *nested_context)) {+ context.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.+ 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);+ }++ auto taking_context = nested_context_taking_first_wheel_step(context_id, *nested_step.hit, step.delta_in_css_pixels, step.wheel_delta_precision);+ if (!taking_context.has_value()) {+ auto result = context.scroll_for_wheel_event_passed_on_by_nested_context(event, now);+ result.nested_context_hand_off = Web::InputRoutingDecision::NestedContextPassedStepOn;+ return { .result = result, .nested_context_presents_frame = result.frame_to_present.has_value() };+ }++ WheelStepHandedToNestedContext handed_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, now);+ } else {+ handed_step.result = ContextState::ContextUpdateResult::declined(taking_context->route.decision);+ }+ handed_step.result.nested_context_hand_off = Web::InputRoutingDecision::HandedToNestedContext;+ return handed_step;+}++// The content box of a nested context is drawn scaled to the size of its viewport.+static Optional<Gfx::FloatPoint> position_in_nested_context(Compositing::NestedContextWheelHit const& hit, ContextState const& nested_context)+{+ auto viewport_size = nested_context.presenter().viewport_size().to_type<float>();+ if (hit.content_box_size.is_empty() || viewport_size.is_empty())+ return {};+ return Gfx::FloatPoint {+ hit.position_in_content_box.x() * viewport_size.width() / hit.content_box_size.width(),+ hit.position_in_content_box.y() * viewport_size.height() / hit.content_box_size.height(),+ };+}++Optional<CompositorState::NestedContextTakingWheelStep> CompositorState::nested_context_taking_first_wheel_step(Web::CompositorContextId context_id, Compositing::NestedContextWheelHit 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) {+ // 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 } };+ 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);+ contexts.append({ .context_id = hit.child_context_id, .context = nested_context, .position = *position, .route = route });+ if (route.kind != Kind::NestedContext)+ break;+ containing_context_id = hit.child_context_id;+ 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.+ while (contexts.last().route.kind == Kind::PassedOn) {+ contexts.take_last();+ if (contexts.is_empty())+ return {};+ 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);+ }+ return contexts.take_last();+}+void CompositorState::dispatch_scroll_fling_step(Web::CompositorContextId context_id, ContextState& context, Optional<Web::MouseEvent> event, MonotonicTime now){// Send each fling step on the same route as a wheel event from the UI.if (!event.has_value())return;- auto result = scroll_for_wheel_step(context, *event, WheelStepOrigin::Fling, now);+ auto result = scroll_for_wheel_step(context_id, context, *event, WheelStepOrigin::Fling, now);+ if (result.nested_context_hand_off.has_value())+ context.input_trace().record({ .input_event_id = event->id, .stage = Web::InputTraceStage::Compositor, .decision = *result.nested_context_hand_off });if (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);@@ -1253,7 +1366,22 @@ Optional<Compositing::FirstWheelStepRouteForTesting> CompositorState::route_firsauto* context = context_if_present(context_id);if (!context)return {};- return context->route_first_wheel_step_for_testing(position, delta_in_css_pixels);+ if (!context->presents_to_client() || !context->may_hand_first_wheel_steps_to_nested_contexts())+ return context->route_first_wheel_step_for_testing(position, delta_in_css_pixels, Compositing::NestedContextRegions::LeaveToMainThread);+ auto 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);+ 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.+ bool ids_are_of_this_process = taking_context->context && taking_context->context->is_owned_by(context->web_content_client());+ Compositing::FirstWheelStepRouteForTesting route { .route = { taking_context->route.decision }, .document_id = {} };+ if (ids_are_of_this_process) {+ route.route.scroller = taking_context->route.scroller;+ route.document_id = taking_context->context->document_id();+ }+ return route;}void CompositorState::begin_input_trace_for_testing(Web::CompositorContextId context_id)diff --git a/Services/Compositor/CompositorState.h b/Services/Compositor/CompositorState.hindex d2778f90cda..7a3beba8e13 100644--- a/Services/Compositor/CompositorState.h+++ b/Services/Compositor/CompositorState.h@@ -219,7 +219,24 @@ private:Fling,};// A fling step is scrolled at the frame time the fling synthesized it for.- ContextState::ContextUpdateResult scroll_for_wheel_step(ContextState&, Web::MouseEvent const&, WheelStepOrigin, Optional<MonotonicTime> fling_step_time = {});+ ContextState::ContextUpdateResult scroll_for_wheel_step(Web::CompositorContextId, ContextState&, Web::MouseEvent const&, WheelStepOrigin, Optional<MonotonicTime> fling_step_time = {});+ struct WheelStepHandedToNestedContext {+ // What is left for the context the step was handed from to present and report.+ ContextState::ContextUpdateResult result;+ bool nested_context_presents_frame { false };+ };+ WheelStepHandedToNestedContext hand_wheel_step_to_nested_context(Web::CompositorContextId, ContextState&, Web::MouseEvent const&, ContextState::NestedContextWheelStep const&, MonotonicTime now);+ struct NestedContextTakingWheelStep {+ Web::CompositorContextId context_id;+ // Null when the step cannot be handed to the context.+ ContextState* context { nullptr };+ 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::NestedContextWheelHit, Gfx::FloatPoint delta_in_css_pixels, Web::WheelDeltaPrecision);+ bool is_nested_in(Web::CompositorContextId containing_context_id, ContextState const&) const;void dispatch_scroll_fling_step(Web::CompositorContextId, ContextState&, Optional<Web::MouseEvent>, MonotonicTime now);void present_frame(Web::CompositorContextId, ContextState&, PendingFrame);void schedule_present_frame(Web::CompositorContextId, ContextState&, PendingFrame);diff --git a/Services/Compositor/ContextState.cpp b/Services/Compositor/ContextState.cppindex 2ce82418181..441bf08951d 100644--- a/Services/Compositor/ContextState.cpp+++ b/Services/Compositor/ContextState.cpp@@ -807,7 +807,11 @@ ContextState::AsyncScrollResult ContextState::async_scroll_by(&& first_is_one_of(scroll_gesture_phase, Web::ScrollGesturePhase::Ongoing, Web::ScrollGesturePhase::Momentum);bool only_blocking_wheel_event_listeners_hold_steps_back = m_wheel_gesture_routing.only_blocking_wheel_event_listeners_hold_steps_back();- auto latched_node_id = resolve_wheel_scroll_latch(position, scroll_gesture_phase, modifiers, now);+ auto latch = resolve_wheel_scroll_latch(position, scroll_gesture_phase, modifiers, now);+ // 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_node_id = latch.node_id;// The end of the gesture before this one may never have arrived. Whether a step of the UI starts another gesture// was decided when the UI sent it.if (!latched_node_id.has_value() && !step_came_from_ui)@@ -840,7 +844,7 @@ ContextState::AsyncScrollResult ContextState::async_scroll_by(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, modifiers, now, expected_document_id, wheel_step_dispatch_for_hit_test);+ auto latch_attempt = hit_test_and_latch_wheel_gesture(position, delta, wheel_delta_precision, scroll_gesture_phase, modifiers, now, expected_document_id, wheel_step_dispatch_for_hit_test, Compositing::NestedContextRegions::LeaveToMainThread);if (!latch_attempt.latched_node_id.has_value())return AsyncScrollResult::declined(latch_attempt.decision);latched_node_id = latch_attempt.latched_node_id;@@ -1151,12 +1155,37 @@ ContextState::ContextUpdateResult ContextState::scroll_for_wheel_event(Web::Mousreturn ContextUpdateResult::declined(Web::InputRoutingDecision::ContextNotPresenting);auto position = wheel_event_position(event);- auto delta = wheel_event_delta_in_device_pixels(event);// 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)m_elastic_overscroll_controller.end_gesture(now);- auto latched_node_id = resolve_wheel_scroll_latch(position, event.scroll_gesture_phase, event.modifiers, now);+ auto latch = resolve_wheel_scroll_latch(position, event.scroll_gesture_phase, event.modifiers, now);+ if (latch.nested_context_id.has_value())+ return { .nested_context_wheel_step = NestedContextWheelStep { .context_id = *latch.nested_context_id } };++ // 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.node_id.has_value()+ && m_wheel_gesture_routing.is_first_wheel_event_from_ui_with_delta(event.id)+ && may_hand_first_wheel_steps_to_nested_contexts();+ if (may_hand_step_to_nested_context) {+ nested_context_regions = Compositing::NestedContextRegions::HandToNestedContext;+ if (auto hit = nested_context_for_wheel_at(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.node_id, nested_context_regions, now);+}++ContextState::ContextUpdateResult ContextState::scroll_for_wheel_event_passed_on_by_nested_context(Web::MouseEvent const& event, MonotonicTime now)+{+ return scroll_for_wheel_event_in_this_context(event, {}, Compositing::NestedContextRegions::Ignore, now);+}++ContextState::ContextUpdateResult ContextState::scroll_for_wheel_event_in_this_context(Web::MouseEvent const& event, Optional<Compositing::AsyncScrollNodeID> latched_node_id, Compositing::NestedContextRegions nested_context_regions, MonotonicTime now)+{+ auto position = wheel_event_position(event);+ auto delta = wheel_event_delta_in_device_pixels(event);// 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@@ -1182,7 +1211,7 @@ ContextState::ContextUpdateResult ContextState::scroll_for_wheel_event(Web::Mous// gesture are not held back by regions the cursor moves over later.bool is_first_step_of_gesture = !latched_node_id.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);+ 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);if (initial_scroll_target.is_blocked_by_a_region())return ContextUpdateResult::declined(Compositing::input_routing_decision_for_first_wheel_step(initial_scroll_target.outcome));}@@ -1201,7 +1230,7 @@ ContextState::ContextUpdateResult ContextState::scroll_for_wheel_event(Web::Mous// 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, event.modifiers, now, {}, Compositing::WheelStepDispatch::NotYetDispatched);+ auto latch_attempt = hit_test_and_latch_wheel_gesture(position, delta.scaled(1.0f / m_scene.visual_viewport_magnification()), event.wheel_delta_precision, event.scroll_gesture_phase, event.modifiers, now, {}, Compositing::WheelStepDispatch::NotYetDispatched, nested_context_regions);latched_node_id = latch_attempt.latched_node_id;routing_decision = latch_attempt.decision;}@@ -1229,6 +1258,136 @@ ContextState::ContextUpdateResult ContextState::scroll_for_wheel_event(Web::Mous};}+bool ContextState::may_hand_first_wheel_steps_to_nested_contexts() const+{+ // A zoomed page pans its visual viewport before anything scrolls. This document's wheel event listeners never see+ // the wheel events over a document nested in it, whatever state they are in.+ return m_has_async_scrolling_state && m_scene.visual_viewport_scale().value_or(1.0f) == 1.0f;+}++Optional<Compositing::NestedContextWheelHit> ContextState::nested_context_for_wheel_at(Gfx::FloatPoint position)+{+ if (!m_has_async_scrolling_state)+ return {};+ return 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, MonotonicTime now)+{+ m_wheel_gesture_routing.latch_to_nested_context(nested_context_id, scroller, wheel_event_position(event), event.scroll_gesture_phase, event.modifiers, now);+}++ContextState::WheelStepFromContainingContext ContextState::WheelStepFromContainingContext::for_wheel_event(Web::MouseEvent const& event)+{+ 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 = {},+ .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,+ };+}++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)+{+ using Kind = FirstWheelStepRoute::Kind;+ auto admission = m_wheel_gesture_routing.admission();+ if (!m_has_async_scrolling_state || 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.+ auto const& visual_context_tree = m_scene.visual_context_tree_for_compositing();+ if (nested_context_regions == Compositing::NestedContextRegions::HandToNestedContext) {+ if (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) };++ 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 scroller_of = [&](Optional<Compositing::AsyncScrollNodeID> node_id) {+ return node_id.map([&](auto id) { return m_async_scroll_tree.scroll_node_for_id(id)->stable_node_id; });+ };+ if (scroll_target.outcome == Compositing::WheelHitTestOutcome::FoundScrollTarget)+ return { .kind = Kind::ScrollNode, .decision = Web::InputRoutingDecision::Latched, .node_id = scroll_target.node_id, .scroller = scroller_of(scroll_target.node_id) };+ if (scroll_target.outcome != Compositing::WheelHitTestOutcome::NoScrollTarget)+ return { Kind::Declined, Compositing::input_routing_decision_for_first_wheel_step(scroll_target.outcome) };++ // https://drafts.csswg.org/css-overscroll-1/#scroll-chaining-and-boundary-default-actions+ // A nested context does not stretch at its edge. It passes the step on to the document around it unless a scroller+ // keeps it, the viewport included.+ bool viewport_keeps_the_scroll = m_async_scroll_tree.viewport_keeps_scrolls_along_main_axis_of(delta);+ if (!scroll_target.node_keeping_the_scroll.has_value() && !viewport_keeps_the_scroll)+ return { Kind::PassedOn, Web::InputRoutingDecision::NestedContextPassedStepOn };+ auto node_keeping_the_scroll = scroll_target.node_keeping_the_scroll.has_value() ? scroll_target.node_keeping_the_scroll : m_async_scroll_tree.viewport_scroll_node_id();+ return { .kind = Kind::Kept, .decision = Web::InputRoutingDecision::ScrollKeptByOverscrollBehavior, .node_id = node_keeping_the_scroll, .scroller = scroller_of(node_keeping_the_scroll) };+}++ContextState::ContextUpdateResult ContextState::take_first_wheel_step_from_containing_context(FirstWheelStepRoute const& route, WheelStepFromContainingContext const& step, MonotonicTime now)+{+ VERIFY(first_is_one_of(route.kind, FirstWheelStepRoute::Kind::ScrollNode, FirstWheelStepRoute::Kind::Kept));+ if (route.kind == FirstWheelStepRoute::Kind::Kept) {+ if (route.scroller.has_value())+ m_wheel_gesture_routing.latch(*route.scroller, step.position, step.scroll_gesture_phase, step.modifiers, now);+ else+ m_wheel_gesture_routing.latch_keeping_steps(step.position, step.scroll_gesture_phase, step.modifiers, now);+ return { .accepted = true, .routing_decision = route.decision, .routed_scroller = route.scroller };+ }+ m_wheel_gesture_routing.latch(*route.scroller, step.position, step.scroll_gesture_phase, step.modifiers, now);+ return take_wheel_step_from_containing_context(*route.node_id, route.decision, step, Compositing::ScrollChaining::ToScrollableAncestors, now);+}++ContextState::ContextUpdateResult ContextState::take_latched_wheel_step_from_containing_context(WheelStepFromContainingContext const& step, 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_continued_by_containing_context(m_async_scroll_tree, m_scene.current_visual_context_tree(), step.scroll_gesture_phase, now);+ if (latch.keeps_steps)+ return { .accepted = true, .routing_decision = Web::InputRoutingDecision::ScrollKeptByOverscrollBehavior };+ if (!latch.node_id.has_value())+ return ContextUpdateResult::declined(Web::InputRoutingDecision::NestedContextUnavailable);++ if (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);+ if (!snap_at_gesture_end(now).has_value())+ return ContextUpdateResult::declined(Web::InputRoutingDecision::GestureEndWithNothingToSnap);+ return {+ .accepted = true,+ .frame_to_present = PendingFrame::repainting_changes(m_async_scrolling_viewport_rect),+ .should_request_rendering_update = true,+ .routing_decision = Web::InputRoutingDecision::SnappedAtGestureEnd,+ .routed_scroller = m_wheel_gesture_routing.latched_scroller(),+ };+ }+ return take_wheel_step_from_containing_context(*latch.node_id, Web::InputRoutingDecision::ContinuedLatch, step, Compositing::ScrollChaining::None, now);+}++ContextState::ContextUpdateResult ContextState::take_wheel_step_from_containing_context(Compositing::AsyncScrollNodeID node_id, Web::InputRoutingDecision decision, WheelStepFromContainingContext 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()));+ auto outcome = perform_wheel_scroll_of_node(node_id, delta, step.wheel_delta_precision, step.scroll_gesture_phase, Compositing::AsyncScrollOperationTracking::No, m_async_scrolling_viewport_rect, now, scroll_chaining, VisualViewportPanning::No);+ 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 = decision,+ .routed_scroller = m_wheel_gesture_routing.latched_scroller(),+ };+}+bool ContextState::wheel_step_can_stretch_elastically(Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase) const{return presents_to_client() && m_elastic_overscroll_controller.step_can_stretch(wheel_delta_precision, scroll_gesture_phase);@@ -1254,7 +1413,7 @@ Optional<Gfx::IntRect> ContextState::advance_elastic_overscroll_rebounds(Monotonreturn m_async_scrolling_viewport_rect;}-Compositing::FirstWheelStepRouteForTesting ContextState::route_first_wheel_step_for_testing(Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels)+Compositing::FirstWheelStepRouteForTesting ContextState::route_first_wheel_step_for_testing(Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels, Compositing::NestedContextRegions nested_context_regions){auto document_id = m_async_scroll_tree.document_id();if (!presents_to_client())@@ -1262,7 +1421,7 @@ Compositing::FirstWheelStepRouteForTesting ContextState::route_first_wheel_step_if (!m_scene.display_list() || !m_scene.visual_context_tree().has_value())return { { Web::InputRoutingDecision::NoAsyncScrollingState }, document_id };auto delta = delta_in_css_pixels.scaled(static_cast<float>(m_async_scroll_tree.device_pixels_per_css_pixel()) / m_scene.visual_viewport_magnification());- return { m_async_scroll_tree.route_first_wheel_step(m_wheel_gesture_routing.admission(), m_scene.visual_context_tree_for_compositing(), position, delta), document_id };+ return { m_async_scroll_tree.route_first_wheel_step(m_wheel_gesture_routing.admission(), m_scene.visual_context_tree_for_compositing(), position, delta, nested_context_regions), document_id };}String ContextState::scroll_state_for_testing(Web::AsyncScrollNodeStableID stretched_scroller) const@@ -1490,7 +1649,7 @@ void ContextState::store_pending_async_scroll_offsets(m_async_scroll_update_outbox.complete_operation(*operation_id);}-Optional<Compositing::AsyncScrollNodeID> ContextState::resolve_wheel_scroll_latch(Gfx::FloatPoint position, Web::ScrollGesturePhase scroll_gesture_phase, u32 modifiers, MonotonicTime now)+WheelGestureRouting::ResolvedLatch ContextState::resolve_wheel_scroll_latch(Gfx::FloatPoint position, Web::ScrollGesturePhase scroll_gesture_phase, u32 modifiers, MonotonicTime now){// Only a hit test takes a latch, and it needs the tree of an installed display list.if (!m_wheel_gesture_routing.has_latch())@@ -1498,12 +1657,12 @@ Optional<Compositing::AsyncScrollNodeID> ContextState::resolve_wheel_scroll_latcreturn m_wheel_gesture_routing.resolve_latch(m_async_scroll_tree, m_scene.current_visual_context_tree(), position, scroll_gesture_phase, modifiers, now);}-ContextState::WheelGestureLatchAttempt ContextState::hit_test_and_latch_wheel_gesture(Gfx::FloatPoint position, Gfx::FloatPoint delta, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, u32 modifiers, MonotonicTime now, Optional<Web::UniqueNodeID> expected_document_id, Compositing::WheelStepDispatch wheel_step_dispatch)+ContextState::WheelGestureLatchAttempt ContextState::hit_test_and_latch_wheel_gesture(Gfx::FloatPoint position, Gfx::FloatPoint delta, Web::WheelDeltaPrecision wheel_delta_precision, Web::ScrollGesturePhase scroll_gesture_phase, u32 modifiers, MonotonicTime now, Optional<Web::UniqueNodeID> expected_document_id, Compositing::WheelStepDispatch wheel_step_dispatch, Compositing::NestedContextRegions nested_context_regions){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);+ 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);if (scroll_target.is_blocked_by_a_region())return { Compositing::input_routing_decision_for_first_wheel_step(scroll_target.outcome) };diff --git a/Services/Compositor/ContextState.h b/Services/Compositor/ContextState.hindex 3b7c33b8693..951ab8b6c78 100644--- a/Services/Compositor/ContextState.h+++ b/Services/Compositor/ContextState.h@@ -71,6 +71,14 @@ public:static AsyncScrollResult declined(Web::InputRoutingDecision decision) { return { .enqueue_result = { .routing_decision = decision } }; }};+ // A wheel step that goes to a context nested in this one: the first step of a gesture over the content of the+ // nested context, or a step of a gesture latched to a context nested here.+ struct NestedContextWheelStep {+ Web::CompositorContextId context_id;+ // Where the first step lands in the content of the nested context.+ Optional<Compositing::NestedContextWheelHit> hit {};+ };+struct ContextUpdateResult {bool accepted { false };Optional<PendingFrame> frame_to_present {};@@ -79,10 +87,43 @@ public:// Why a wheel or mouse event was taken or turned away, and the scroller it was routed to.Optional<Web::InputRoutingDecision> routing_decision {};Optional<Web::AsyncScrollNodeStableID> routed_scroller {};+ // How the first step of a wheel gesture went by a nested context, ahead of `routing_decision`.+ Optional<Web::InputRoutingDecision> nested_context_hand_off {};+ // Set instead of everything else for a wheel step that a nested context is to take.+ Optional<NestedContextWheelStep> nested_context_wheel_step {};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 {+ 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 };++ static WheelStepFromContainingContext for_wheel_event(Web::MouseEvent const&);+ };++ // Where the first step of a gesture that the containing context hands in goes in this context. A nested context+ // passes a step on to the document around it unless one of its scrollers takes or keeps it.+ struct FirstWheelStepRoute {+ enum class Kind : u8 {+ Declined,+ ScrollNode,+ NestedContext,+ Kept,+ PassedOn,+ };+ Kind kind;+ Web::InputRoutingDecision decision;+ Optional<Compositing::AsyncScrollNodeID> node_id {};+ Optional<Web::AsyncScrollNodeStableID> scroller {};+ Optional<Compositing::NestedContextWheelHit> nested_context_hit {};+ };+ContextState(Web::CompositorContextId, Optional<u64> page_id, CompositorStateWebContentClient&, Compositing::OwnedCanvasSurfaces, Function<void(Gfx::IntRect)> schedule_caret_repaint = {});~ContextState();@@ -123,6 +164,18 @@ public:// the main thread.void note_wheel_event_from_ui(Web::MouseEvent const&, Optional<MonotonicTime> now_for_testing = {});ContextUpdateResult handle_pinch_event(Web::PinchEvent const&);++ bool may_hand_first_wheel_steps_to_nested_contexts() const;+ Optional<Compositing::NestedContextWheelHit> nested_context_for_wheel_at(Gfx::FloatPoint position);+ ContextUpdateResult scroll_for_wheel_event_passed_on_by_nested_context(Web::MouseEvent const&, MonotonicTime now);+ void latch_wheel_gesture_to_nested_context(Web::CompositorContextId, Optional<Web::AsyncScrollNodeStableID> scroller, Web::MouseEvent const&, MonotonicTime now);+ void forget_wheel_gesture_latch() { m_wheel_gesture_routing.clear_latch(); }++ FirstWheelStepRoute route_first_wheel_step_from_containing_context(Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels, Web::WheelDeltaPrecision, Compositing::NestedContextRegions);+ // 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);+ Optional<Web::UniqueNodeID> document_id() const { return m_async_scroll_tree.document_id(); }AsyncScrollResult async_scroll_by(Web::UniqueNodeID document_id,Gfx::FloatPoint position,@@ -158,7 +211,7 @@ public:String scroll_state_for_testing(Web::AsyncScrollNodeStableID stretched_scroller) const;Web::InputTraceRecorder& input_trace() { return m_input_trace; }// Where the first step of a wheel gesture at the position, by the delta in CSS pixels, would go.- Compositing::FirstWheelStepRouteForTesting route_first_wheel_step_for_testing(Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels);+ Compositing::FirstWheelStepRouteForTesting route_first_wheel_step_for_testing(Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels, Compositing::NestedContextRegions);bool advance_visual_animations(MonotonicTime now);bool visual_animations_need_frame();Compositing::PendingAsyncScrollUpdates take_pending_async_scroll_updates();@@ -241,13 +294,14 @@ private:Optional<Gfx::FloatPoint> delta_the_node_did_not_scroll_by;};NodeScrollByWheelDelta scroll_node_by_wheel_delta(Compositing::AsyncScrollNodeID, Gfx::FloatPoint delta, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, Compositing::AsyncScrollOperationTracking, Gfx::IntRect viewport_rect, MonotonicTime now, Compositing::ScrollChaining);- Optional<Compositing::AsyncScrollNodeID> resolve_wheel_scroll_latch(Gfx::FloatPoint position, Web::ScrollGesturePhase, u32 modifiers, MonotonicTime now);+ WheelGestureRouting::ResolvedLatch resolve_wheel_scroll_latch(Gfx::FloatPoint position, Web::ScrollGesturePhase, u32 modifiers, MonotonicTime now);struct WheelGestureLatchAttempt {Web::InputRoutingDecision decision;Optional<Compositing::AsyncScrollNodeID> latched_node_id {};};// The scroller the first step of a wheel gesture is routed to, which the gesture is latched to.- WheelGestureLatchAttempt hit_test_and_latch_wheel_gesture(Gfx::FloatPoint position, Gfx::FloatPoint delta, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, u32 modifiers, MonotonicTime now, Optional<Web::UniqueNodeID> expected_document_id, Compositing::WheelStepDispatch);+ WheelGestureLatchAttempt hit_test_and_latch_wheel_gesture(Gfx::FloatPoint position, Gfx::FloatPoint delta, Web::WheelDeltaPrecision, Web::ScrollGesturePhase, u32 modifiers, MonotonicTime now, Optional<Web::UniqueNodeID> expected_document_id, Compositing::WheelStepDispatch, Compositing::NestedContextRegions);+ ContextUpdateResult take_wheel_step_from_containing_context(Compositing::AsyncScrollNodeID, Web::InputRoutingDecision, WheelStepFromContainingContext 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::AsyncScrollNodeID, ScrollSnapController::SnapScrollStart&&, bool settles_gesture, MonotonicTime now);@@ -258,6 +312,7 @@ 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;ContextUpdateResult scroll_for_wheel_event(Web::MouseEvent const&, MonotonicTime now);+ ContextUpdateResult scroll_for_wheel_event_in_this_context(Web::MouseEvent const&, Optional<Compositing::AsyncScrollNodeID> latched_node_id, Compositing::NestedContextRegions, MonotonicTime now);Gfx::FloatPoint wheel_event_delta_in_device_pixels(Web::MouseEvent const&) const;bool step_continues_touchpad_gesture_the_page_let_through(Optional<Compositing::AsyncScrollNodeID> const& latched_node_id, Web::WheelDeltaPrecision, Web::ScrollGesturePhase) const;Optional<Gfx::FloatPoint> in_flight_wheel_destination(Web::AsyncScrollNodeStableID) const;diff --git a/Services/Compositor/WheelGestureRouting.cpp b/Services/Compositor/WheelGestureRouting.cppindex c659fe95bed..ebafe412361 100644--- a/Services/Compositor/WheelGestureRouting.cpp+++ b/Services/Compositor/WheelGestureRouting.cpp@@ -54,12 +54,18 @@ bool WheelGestureRouting::note_wheel_event_from_ui(Web::MouseEvent const& event,m_newest_wheel_event_ids_from_ui.ended = event.id;}- if (m_gesture_from_ui.has_value() && m_gesture_from_ui->is_continued_by(position, phase, event.modifiers, now, position_slop_in_device_pixels(async_scroll_tree))) {+ bool starts_gesture = !m_gesture_from_ui.has_value() || !m_gesture_from_ui->is_continued_by(position, phase, event.modifiers, now, position_slop_in_device_pixels(async_scroll_tree));+ if (starts_gesture) {+ m_gesture_from_ui = Compositing::WheelGestureIdentity::started_by(position, phase, event.modifiers, now);+ m_gesture_from_ui_had_wheel_event_with_delta = false;+ } else {m_gesture_from_ui->advance_to(phase, now);- return false;}- m_gesture_from_ui = Compositing::WheelGestureIdentity::started_by(position, phase, event.modifiers, now);- return true;+ if (!m_gesture_from_ui_had_wheel_event_with_delta && (event.wheel_delta_x != 0 || event.wheel_delta_y != 0)) {+ m_gesture_from_ui_had_wheel_event_with_delta = true;+ m_id_of_first_wheel_event_from_ui_with_delta = event.id;+ }+ return starts_gesture;}bool WheelGestureRouting::step_was_overtaken_by_ui(Web::ScrollGesturePhase phase, u64 input_event_id) const@@ -81,7 +87,7 @@ bool WheelGestureRouting::step_was_overtaken_by_ui(Web::ScrollGesturePhase phaseVERIFY_NOT_REACHED();}-Optional<Compositing::AsyncScrollNodeID> WheelGestureRouting::resolve_latch(Compositing::AsyncScrollTree const& async_scroll_tree, Compositing::AccumulatedVisualContextTree const& current_visual_context_tree, Gfx::FloatPoint position, Web::ScrollGesturePhase scroll_gesture_phase, u32 modifiers, MonotonicTime now)+WheelGestureRouting::ResolvedLatch WheelGestureRouting::resolve_latch(Compositing::AsyncScrollTree const& async_scroll_tree, Compositing::AccumulatedVisualContextTree const& current_visual_context_tree, Gfx::FloatPoint position, Web::ScrollGesturePhase scroll_gesture_phase, u32 modifiers, MonotonicTime now){if (!m_latch.has_value())return {};@@ -89,7 +95,18 @@ Optional<Compositing::AsyncScrollNodeID> WheelGestureRouting::resolve_latch(Compm_latch.clear();return {};}- auto node_id = async_scroll_tree.scroll_node_id_for_stable_id(m_latch->stable_node_id);+ return resolve_latch_continued_by_containing_context(async_scroll_tree, current_visual_context_tree, scroll_gesture_phase, now);+}++WheelGestureRouting::ResolvedLatch WheelGestureRouting::resolve_latch_continued_by_containing_context(Compositing::AsyncScrollTree const& async_scroll_tree, Compositing::AccumulatedVisualContextTree const& current_visual_context_tree, Web::ScrollGesturePhase scroll_gesture_phase, MonotonicTime now)+{+ if (!m_latch.has_value())+ return {};+ if (m_latch->nested_context_id.has_value() || !m_latch->stable_node_id.has_value()) {+ m_latch->gesture.advance_to(scroll_gesture_phase, now);+ return { .nested_context_id = m_latch->nested_context_id, .keeps_steps = !m_latch->nested_context_id.has_value() };+ }+ auto node_id = async_scroll_tree.scroll_node_id_for_stable_id(*m_latch->stable_node_id);if (!node_id.has_value()) {m_latch.clear();return {};@@ -98,7 +115,7 @@ Optional<Compositing::AsyncScrollNodeID> WheelGestureRouting::resolve_latch(Compif (!async_scroll_tree.has_wheel_hit_test_targets_for(current_visual_context_tree))return {};m_latch->gesture.advance_to(scroll_gesture_phase, now);- return node_id;+ return { .node_id = node_id };}Optional<Web::AsyncScrollNodeStableID> WheelGestureRouting::latched_scroller() const@@ -116,9 +133,26 @@ void WheelGestureRouting::latch(Web::AsyncScrollNodeStableID stable_node_id, Gfx};}+void WheelGestureRouting::latch_to_nested_context(Web::CompositorContextId nested_context_id, Optional<Web::AsyncScrollNodeStableID> scroller, Gfx::FloatPoint position, Web::ScrollGesturePhase scroll_gesture_phase, u32 modifiers, MonotonicTime now)+{+ m_latch = Latch {+ .stable_node_id = scroller,+ .gesture = Compositing::WheelGestureIdentity::started_by(position, scroll_gesture_phase, modifiers, now),+ .nested_context_id = nested_context_id,+ };+}++void WheelGestureRouting::latch_keeping_steps(Gfx::FloatPoint position, Web::ScrollGesturePhase scroll_gesture_phase, u32 modifiers, MonotonicTime now)+{+ m_latch = Latch {+ .stable_node_id = {},+ .gesture = Compositing::WheelGestureIdentity::started_by(position, scroll_gesture_phase, modifiers, now),+ };+}+void WheelGestureRouting::relatch_to(Web::AsyncScrollNodeStableID stable_node_id){- if (m_latch.has_value())+ if (m_latch.has_value() && m_latch->stable_node_id.has_value() && !m_latch->nested_context_id.has_value())m_latch->stable_node_id = stable_node_id;}diff --git a/Services/Compositor/WheelGestureRouting.h b/Services/Compositor/WheelGestureRouting.hindex f057bef1c12..2bb26411a29 100644--- a/Services/Compositor/WheelGestureRouting.h+++ b/Services/Compositor/WheelGestureRouting.h@@ -12,6 +12,7 @@#include <LibCompositing/Scrolling/AsyncScrollingState.h>#include <LibCompositing/Scrolling/WheelGestureIdentity.h>#include <LibGfx/Point.h>+#include <LibWebCommon/Page/CompositorContextId.h>#include <LibWebCommon/Page/InputEvent.h>namespace Compositing {@@ -33,17 +34,32 @@ public:// Returns whether the event starts another gesture than the one the UI was sending.bool note_wheel_event_from_ui(Web::MouseEvent const&, Gfx::FloatPoint position, Compositing::AsyncScrollTree const&, MonotonicTime now);+ // Whether the wheel event is the first step of the gesture from the UI that moves anything. A touchpad gesture can+ // start with a step that has no delta.+ bool is_first_wheel_event_from_ui_with_delta(u64 input_event_id) const { return input_event_id != 0 && input_event_id == m_id_of_first_wheel_event_from_ui_with_delta; }// 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(); }Optional<Web::AsyncScrollNodeStableID> latched_scroller() const;- // The latched scroller of the gesture the wheel event continues, in the current scroll tree, with the gesture- // advanced to the event. A latch the event does not continue, or whose scroller the current display list no- // longer has, is dropped here.- Optional<Compositing::AsyncScrollNodeID> resolve_latch(Compositing::AsyncScrollTree const&, Compositing::AccumulatedVisualContextTree const& current_visual_context_tree, Gfx::FloatPoint position, Web::ScrollGesturePhase, u32 modifiers, MonotonicTime now);+ // What a gesture is latched to: a scroller in the current scroll tree, a context nested in this one that latched the+ // gesture to a scroller of its own, or nothing that scrolls, when this context keeps the steps from the document+ // around it.+ struct ResolvedLatch {+ Optional<Compositing::AsyncScrollNodeID> node_id {};+ Optional<Web::CompositorContextId> nested_context_id {};+ bool keeps_steps { false };+ };+ // The latch of the gesture the wheel event continues, with the gesture advanced to the event. A latch the event+ // does not continue, or whose scroller the current display list no longer has, is dropped here.+ ResolvedLatch resolve_latch(Compositing::AsyncScrollTree const&, Compositing::AccumulatedVisualContextTree const& current_visual_context_tree, Gfx::FloatPoint position, Web::ScrollGesturePhase, u32 modifiers, MonotonicTime now);+ // The same for a step that the containing context hands in, which has decided that the step continues the gesture.+ ResolvedLatch resolve_latch_continued_by_containing_context(Compositing::AsyncScrollTree const&, Compositing::AccumulatedVisualContextTree const& current_visual_context_tree, Web::ScrollGesturePhase, MonotonicTime now);void latch(Web::AsyncScrollNodeStableID, Gfx::FloatPoint position, Web::ScrollGesturePhase, u32 modifiers, MonotonicTime now);+ void latch_to_nested_context(Web::CompositorContextId, Optional<Web::AsyncScrollNodeStableID> scroller, Gfx::FloatPoint position, Web::ScrollGesturePhase, u32 modifiers, MonotonicTime now);+ void latch_keeping_steps(Gfx::FloatPoint position, Web::ScrollGesturePhase, u32 modifiers, MonotonicTime now);+ void clear_latch() { m_latch.clear(); }void relatch_to(Web::AsyncScrollNodeStableID);void note_page_let_latched_gesture_through();bool page_let_latched_touchpad_gesture_through(Web::WheelDeltaPrecision, Web::ScrollGesturePhase) const;@@ -54,8 +70,10 @@ private:// The scroller the first step of a wheel gesture was routed to. Every later step of the gesture scrolls it without// hit testing, and stops at its edge rather than handing the rest of the gesture to an ancestor.struct Latch {- Web::AsyncScrollNodeStableID stable_node_id;+ // Empty for a latch that keeps the steps without a scroller.+ Optional<Web::AsyncScrollNodeStableID> stable_node_id;Compositing::WheelGestureIdentity gesture;+ Optional<Web::CompositorContextId> nested_context_id {};// 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 };@@ -77,6 +95,8 @@ private:// The touchpad gesture the UI is sending, whether this context or the main thread scrolls its steps.Optional<Compositing::WheelGestureIdentity> m_gesture_from_ui;NewestWheelEventIdsFromUI m_newest_wheel_event_ids_from_ui;+ u64 m_id_of_first_wheel_event_from_ui_with_delta { 0 };+ bool m_gesture_from_ui_had_wheel_event_with_delta { false };Optional<Latch> m_latch;};diff --git a/Tests/LibWeb/Text/expected/async-scrolling/nested-context-wheel-routing.txt b/Tests/LibWeb/Text/expected/async-scrolling/nested-context-wheel-routing.txtnew file mode 100644index 00000000000..2ff6dc689bc--- /dev/null+++ b/Tests/LibWeb/Text/expected/async-scrolling/nested-context-wheel-routing.txt@@ -0,0 +1,14 @@+main thread regions: 0+nested context regions: 5+over a frame that scrolls: latched scroller=nested viewport+over the border of a frame that scrolls: latched scroller=viewport+over a frame with nothing to scroll: latched scroller=viewport+over a frame whose root keeps its scrolls: scroll-kept-by-overscroll-behavior+over a frame that takes no pointer input: latched scroller=viewport+over a frame with a blocking wheel listener: blocking-wheel-event-listeners+over a scroller in a frame: latched scroller=div+over a scroller in a frame, upwards: no-scroll-target+over the header covering a frame: latched scroller=viewport+with a blocking wheel listener here, over a frame that scrolls: latched scroller=nested viewport+with a blocking wheel listener here, over a frame with nothing to scroll: blocking-wheel-event-listeners+once it takes pointer input, over a frame that took none: latched scroller=nested viewportdiff --git a/Tests/LibWeb/Text/expected/async-scrolling/nested-navigable-wheel-admission.txt b/Tests/LibWeb/Text/expected/async-scrolling/nested-navigable-wheel-admission.txtindex 585567b1938..cab8ff8e9ef 100644--- a/Tests/LibWeb/Text/expected/async-scrolling/nested-navigable-wheel-admission.txt+++ b/Tests/LibWeb/Text/expected/async-scrolling/nested-navigable-wheel-admission.txt@@ -1,6 +1,6 @@main thread regions: 0nested context regions: 1-over iframe: blocked-by-main-thread-region+over iframe: latched scroller=nested viewportoutside iframe: latched scroller=viewportdisplay list:AccumulatedVisualContext Tree:diff --git a/Tests/LibWeb/Text/expected/async-scrolling/ui-touchpad-gesture-over-iframe-stays-in-the-iframe.txt b/Tests/LibWeb/Text/expected/async-scrolling/ui-touchpad-gesture-over-iframe-stays-in-the-iframe.txtnew file mode 100644index 00000000000..bdc76362e70--- /dev/null+++ b/Tests/LibWeb/Text/expected/async-scrolling/ui-touchpad-gesture-over-iframe-stays-in-the-iframe.txt@@ -0,0 +1,13 @@+#1 compositor: blocked-by-main-thread-region+#1 compositor: forwarded-to-page+#2 compositor: handed-to-nested-context+#2 compositor: latched scroller=nested viewport+#2 compositor: forwarded-to-page+#3 compositor: continued-latch scroller=nested viewport+#3 compositor: forwarded-to-page+#4 compositor: continued-latch scroller=nested viewport+#4 compositor: forwarded-to-page+#5 compositor: gesture-end-with-nothing-to-snap+#5 compositor: forwarded-to-page+frame scrollY: 150+window.scrollY: 0diff --git a/Tests/LibWeb/Text/expected/async-scrolling/ui-touchpad-gesture-over-iframe-that-keeps-its-scrolls-stays-there.txt b/Tests/LibWeb/Text/expected/async-scrolling/ui-touchpad-gesture-over-iframe-that-keeps-its-scrolls-stays-there.txtnew file mode 100644index 00000000000..921110aeea6--- /dev/null+++ b/Tests/LibWeb/Text/expected/async-scrolling/ui-touchpad-gesture-over-iframe-that-keeps-its-scrolls-stays-there.txt@@ -0,0 +1,8 @@+#1 compositor: handed-to-nested-context+#1 compositor: scroll-kept-by-overscroll-behavior+#1 compositor: forwarded-to-page+#2 compositor: scroll-kept-by-overscroll-behavior+#2 compositor: forwarded-to-page+#3 compositor: scroll-kept-by-overscroll-behavior+#3 compositor: forwarded-to-page+window.scrollY: 0diff --git a/Tests/LibWeb/Text/expected/async-scrolling/ui-touchpad-gesture-over-iframe-yields-to-a-listener-added-mid-gesture.txt b/Tests/LibWeb/Text/expected/async-scrolling/ui-touchpad-gesture-over-iframe-yields-to-a-listener-added-mid-gesture.txtnew file mode 100644index 00000000000..265244dffee--- /dev/null+++ b/Tests/LibWeb/Text/expected/async-scrolling/ui-touchpad-gesture-over-iframe-yields-to-a-listener-added-mid-gesture.txt@@ -0,0 +1,7 @@+#1 compositor: handed-to-nested-context+#1 compositor: latched scroller=nested viewport+#1 compositor: forwarded-to-page+compositor scrolled a later step: false+frame scrolled by the first step: true+canceled wheel events: 2+frame scrolled by the canceled step: falsediff --git a/Tests/LibWeb/Text/expected/async-scrolling/ui-wheel-over-iframe-is-scrolled-by-the-compositor.txt b/Tests/LibWeb/Text/expected/async-scrolling/ui-wheel-over-iframe-is-scrolled-by-the-compositor.txtnew file mode 100644index 00000000000..afc8a2bc30e--- /dev/null+++ b/Tests/LibWeb/Text/expected/async-scrolling/ui-wheel-over-iframe-is-scrolled-by-the-compositor.txt@@ -0,0 +1,8 @@+#1 compositor: handed-to-nested-context+#1 compositor: latched scroller=nested viewport+#1 compositor: forwarded-to-page+frame scrollY: 50+window.scrollY: 0+wheel events in the frame: 1+cancelable wheel events in the frame: 0+wheel events here: 0diff --git a/Tests/LibWeb/Text/expected/async-scrolling/ui-wheel-over-iframe-it-cannot-scroll-scrolls-the-page.txt b/Tests/LibWeb/Text/expected/async-scrolling/ui-wheel-over-iframe-it-cannot-scroll-scrolls-the-page.txtnew file mode 100644index 00000000000..81f6888fec7--- /dev/null+++ b/Tests/LibWeb/Text/expected/async-scrolling/ui-wheel-over-iframe-it-cannot-scroll-scrolls-the-page.txt@@ -0,0 +1,12 @@+over a frame with nothing to scroll:+#1 compositor: nested-context-passed-step-on+#1 compositor: latched scroller=viewport+#1 compositor: forwarded-to-page+frame scrolled: false+window.scrollY: 50+over a frame at its edge:+#1 compositor: nested-context-passed-step-on+#1 compositor: latched scroller=viewport+#1 compositor: forwarded-to-page+frame scrolled: false+window.scrollY: 50diff --git a/Tests/LibWeb/Text/input/async-scrolling/nested-context-wheel-routing.html b/Tests/LibWeb/Text/input/async-scrolling/nested-context-wheel-routing.htmlnew file mode 100644index 00000000000..8039491d639--- /dev/null+++ b/Tests/LibWeb/Text/input/async-scrolling/nested-context-wheel-routing.html@@ -0,0 +1,78 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<style>+ body {+ margin: 0;+ height: 2000px;+ }++ iframe {+ position: absolute;+ width: 100px;+ height: 100px;+ border: 10px solid;+ }++ #covering-header {+ position: fixed;+ z-index: 1;+ left: 0;+ top: 0;+ width: 800px;+ height: 30px;+ }+</style>+<div id="covering-header"></div>+<script>+ function createFrame(left, top, srcdoc, style = "") {+ const frame = document.createElement("iframe");+ frame.style = `left: ${left}px; top: ${top}px; ${style}`;+ const frameLoaded = new Promise(resolve => frame.addEventListener("load", resolve, { once: true }));+ frame.srcdoc = srcdoc;+ document.body.append(frame);+ return { frame, frameLoaded };+ }++ function route(x, y, deltaY = 100) {+ return wheelTargetToString(internals.compositorWheelTargetAt(x, y, 0, deltaY));+ }++ promiseTest(async () => {+ const frames = [+ createFrame(0, 0, "<body style='height: 1000px'></body>"),+ createFrame(200, 0, "<body></body>"),+ createFrame(400, 0, "<style>html { overscroll-behavior: contain; }</style><body></body>"),+ createFrame(600, 0, "<body style='height: 1000px'></body>", "pointer-events: none"),+ createFrame(0, 200, "<body style='height: 1000px'><script>addEventListener('wheel', () => {}, { passive: false });<\/script></body>"),+ createFrame(200, 200, "<body style='height: 1000px'><div style='overflow: auto; height: 50px'><div style='height: 500px'></div></div></body>"),+ ];+ await Promise.all(frames.map(({ frameLoaded }) => frameLoaded));+ await waitForCondition(() => {+ const state = internals.compositorScrollState();+ return state.document === document && state.nestedContextWheelRegionCount === 5;+ });+ await waitForCondition(() => frames.every(({ frame }) => frame.contentWindow.internals.compositorScrollState().document === frame.contentDocument));++ println(`main thread regions: ${internals.compositorScrollState().mainThreadWheelEventRegionCount}`);+ println(`nested context regions: ${internals.compositorScrollState().nestedContextWheelRegionCount}`);+ println(`over a frame that scrolls: ${route(60, 80)}`);+ println(`over the border of a frame that scrolls: ${route(5, 80)}`);+ println(`over a frame with nothing to scroll: ${route(260, 80)}`);+ println(`over a frame whose root keeps its scrolls: ${route(460, 80)}`);+ println(`over a frame that takes no pointer input: ${route(660, 80)}`);+ println(`over a frame with a blocking wheel listener: ${route(60, 280)}`);+ println(`over a scroller in a frame: ${route(260, 240)}`);+ println(`over a scroller in a frame, upwards: ${route(260, 240, -100)}`);+ println(`over the header covering a frame: ${route(60, 25)}`);++ // The listeners of this document never see the wheel events over the content of a document nested in it.+ window.addEventListener("wheel", () => {}, { passive: false });+ await waitForCondition(() => internals.compositorScrollState().hasBlockingWheelEventRegionCoveringViewport);+ println(`with a blocking wheel listener here, over a frame that scrolls: ${route(60, 80)}`);+ println(`with a blocking wheel listener here, over a frame with nothing to scroll: ${route(260, 80)}`);++ frames[3].frame.style.pointerEvents = "auto";+ await waitForCondition(() => internals.compositorScrollState().nestedContextWheelRegionCount === 6);+ println(`once it takes pointer input, over a frame that took none: ${route(660, 80)}`);+ });+</script>diff --git a/Tests/LibWeb/Text/input/async-scrolling/nested-navigable-wheel-admission.html b/Tests/LibWeb/Text/input/async-scrolling/nested-navigable-wheel-admission.htmlindex 4de2e787f52..4c56dcea8e5 100644--- a/Tests/LibWeb/Text/input/async-scrolling/nested-navigable-wheel-admission.html+++ b/Tests/LibWeb/Text/input/async-scrolling/nested-navigable-wheel-admission.html@@ -35,11 +35,13 @@frame.srcdoc = "<body style='height: 1000px'></body>";document.body.prepend(frame);await frameLoaded;- // The compositor routes the wheel with the first frame that shows where the iframe is.+ // The compositor routes the wheel with the first frame that shows where the iframe is, and hands it to the+ // iframe once it holds the iframe's frame too.await waitForCondition(() => {const state = internals.compositorScrollState();return state.document === document && state.nestedContextWheelRegionCount > 0;});+ await waitForCondition(() => frame.contentWindow.internals.compositorScrollState().document === frame.contentDocument);const state = internals.compositorScrollState();const output = [diff --git a/Tests/LibWeb/Text/input/async-scrolling/ui-touchpad-gesture-over-iframe-stays-in-the-iframe.html b/Tests/LibWeb/Text/input/async-scrolling/ui-touchpad-gesture-over-iframe-stays-in-the-iframe.htmlnew file mode 100644index 00000000000..251ea135b73--- /dev/null+++ b/Tests/LibWeb/Text/input/async-scrolling/ui-touchpad-gesture-over-iframe-stays-in-the-iframe.html@@ -0,0 +1,41 @@+<!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: 300px'></body>";+ document.body.prepend(frame);+ await frameLoaded;+ await waitForCondition(() => internals.compositorWheelTargetAt(100, 75, 0, 50).document === frame.contentDocument);++ // A touchpad gesture can begin with a step that moves nothing. The gesture is latched to the frame's viewport by+ // its first step that does, and its later steps, momentum included, stay there past the frame's edge rather than+ // scrolling the page. The momentum follows the fingers without an end in between, as momentum arriving more than+ // 100 ms after an end starts another gesture.+ internals.beginInputTrace();+ await scrollSettled(frame.contentDocument, async () => {+ await internals.wheelThroughUIProcess(100, 75, 0, 0, true, "ongoing");+ await internals.wheelThroughUIProcess(100, 75, 0, 100, true, "ongoing");+ await internals.wheelThroughUIProcess(100, 75, 0, 100, true, "ongoing");+ await internals.wheelThroughUIProcess(100, 75, 0, 100, true, "momentum");+ await internals.wheelThroughUIProcess(100, 75, 0, 0, true, "ended");+ });+ printInputTrace(internals.takeInputTrace(), { stages: ["compositor"] });+ println(`frame scrollY: ${frame.contentWindow.scrollY}`);+ println(`window.scrollY: ${window.scrollY}`);+ });+</script>diff --git a/Tests/LibWeb/Text/input/async-scrolling/ui-touchpad-gesture-over-iframe-that-keeps-its-scrolls-stays-there.html b/Tests/LibWeb/Text/input/async-scrolling/ui-touchpad-gesture-over-iframe-that-keeps-its-scrolls-stays-there.htmlnew file mode 100644index 00000000000..0ddfd715764--- /dev/null+++ b/Tests/LibWeb/Text/input/async-scrolling/ui-touchpad-gesture-over-iframe-that-keeps-its-scrolls-stays-there.html@@ -0,0 +1,36 @@+<!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 = "<style>html { overscroll-behavior: contain; }</style><body></body>";+ document.body.prepend(frame);+ await frameLoaded;+ await waitForCondition(() => internals.compositorWheelTargetAt(100, 75, 0, 50).decision === "scroll-kept-by-overscroll-behavior");++ // The frame has nothing to scroll, and its root keeps the scrolls from this document. The gesture stays latched+ // to the frame for all of its steps, which scroll nothing.+ internals.beginInputTrace();+ await internals.wheelThroughUIProcess(100, 75, 0, 50, true, "ongoing");+ await internals.wheelThroughUIProcess(100, 75, 0, 50, true, "ongoing");+ await internals.wheelThroughUIProcess(100, 75, 0, 0, true, "ended");+ printInputTrace(internals.takeInputTrace(), { stages: ["compositor"] });+ await animationFrame();+ await animationFrame();+ println(`window.scrollY: ${window.scrollY}`);+ });+</script>diff --git a/Tests/LibWeb/Text/input/async-scrolling/ui-touchpad-gesture-over-iframe-yields-to-a-listener-added-mid-gesture.html b/Tests/LibWeb/Text/input/async-scrolling/ui-touchpad-gesture-over-iframe-yields-to-a-listener-added-mid-gesture.htmlnew file mode 100644index 00000000000..568df198fc5--- /dev/null+++ b/Tests/LibWeb/Text/input/async-scrolling/ui-touchpad-gesture-over-iframe-yields-to-a-listener-added-mid-gesture.html@@ -0,0 +1,48 @@+<!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;+ await waitForCondition(() => internals.compositorWheelTargetAt(100, 75, 0, 50).document === frame.contentDocument);++ // The compositor scrolls the frame by the first step of the gesture. A listener the frame then adds may cancel+ // the later steps, so the compositor leaves them to the page until a frame shows where the listener is.+ internals.beginInputTrace();+ await internals.wheelThroughUIProcess(100, 75, 0, 50, true, "ongoing");+ const scrollYBeforeListener = frame.contentWindow.scrollY;+ let canceledWheelEvents = 0;+ frame.contentWindow.addEventListener("wheel", event => {+ if (event.cancelable) {+ event.preventDefault();+ ++canceledWheelEvents;+ }+ }, { passive: false });+ await internals.wheelThroughUIProcess(100, 75, 0, 50, true, "ongoing");+ await internals.wheelThroughUIProcess(100, 75, 0, 0, true, "ended");+ // Whether the listener's state is stale or known by the later steps depends on when the frame records again.+ const trace = internals.takeInputTrace().filter(record => record.stage === "compositor");+ printInputTrace(trace.filter(record => record.id === trace[0].id));+ const compositorScrolledLaterStep = trace.some(record => record.id !== trace[0].id && record.decision === "continued-latch");+ println(`compositor scrolled a later step: ${compositorScrolledLaterStep}`);+ println(`frame scrolled by the first step: ${scrollYBeforeListener > 0}`);+ println(`canceled wheel events: ${canceledWheelEvents}`);+ println(`frame scrolled by the canceled step: ${frame.contentWindow.scrollY !== scrollYBeforeListener}`);+ });+</script>diff --git a/Tests/LibWeb/Text/input/async-scrolling/ui-wheel-over-iframe-is-scrolled-by-the-compositor.html b/Tests/LibWeb/Text/input/async-scrolling/ui-wheel-over-iframe-is-scrolled-by-the-compositor.htmlnew file mode 100644index 00000000000..14c5d9d852b--- /dev/null+++ b/Tests/LibWeb/Text/input/async-scrolling/ui-wheel-over-iframe-is-scrolled-by-the-compositor.html@@ -0,0 +1,45 @@+<!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;++ // This document's blocking listener never sees the wheel events over the iframe, so it does not hold them back.+ let wheelEventsHere = 0;+ window.addEventListener("wheel", () => ++wheelEventsHere, { passive: false });+ let wheelEventsInFrame = 0;+ let cancelableWheelEventsInFrame = 0;+ frame.contentWindow.addEventListener("wheel", event => {+ ++wheelEventsInFrame;+ if (event.cancelable)+ ++cancelableWheelEventsInFrame;+ }, { passive: true });+ await waitForCondition(() => internals.compositorWheelTargetAt(100, 75, 0, 50).document === frame.contentDocument);++ internals.beginInputTrace();+ await scrollSettled(frame.contentDocument, () => internals.wheelThroughUIProcess(100, 75, 0, 50));+ printInputTrace(internals.takeInputTrace(), { stages: ["compositor"] });+ println(`frame scrollY: ${frame.contentWindow.scrollY}`);+ println(`window.scrollY: ${window.scrollY}`);+ println(`wheel events in the frame: ${wheelEventsInFrame}`);+ println(`cancelable wheel events in the frame: ${cancelableWheelEventsInFrame}`);+ println(`wheel events here: ${wheelEventsHere}`);+ });+</script>diff --git a/Tests/LibWeb/Text/input/async-scrolling/ui-wheel-over-iframe-it-cannot-scroll-scrolls-the-page.html b/Tests/LibWeb/Text/input/async-scrolling/ui-wheel-over-iframe-it-cannot-scroll-scrolls-the-page.htmlnew file mode 100644index 00000000000..0880421e79b--- /dev/null+++ b/Tests/LibWeb/Text/input/async-scrolling/ui-wheel-over-iframe-it-cannot-scroll-scrolls-the-page.html@@ -0,0 +1,45 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<style>+ body {+ margin: 0;+ height: 2000px;+ }++ iframe {+ display: block;+ width: 200px;+ height: 150px;+ border: 0;+ }+</style>+<script>+ function createFrame(srcdoc) {+ const frame = document.createElement("iframe");+ const frameLoaded = new Promise(resolve => frame.addEventListener("load", resolve, { once: true }));+ frame.srcdoc = srcdoc;+ document.body.append(frame);+ return frameLoaded.then(() => frame);+ }++ promiseTest(async () => {+ const frameWithNothingToScroll = await createFrame("<body></body>");+ const frameAtItsEdge = await createFrame("<body style='margin: 0; height: 1000px'></body>");+ frameAtItsEdge.contentWindow.scrollTo(0, 1000);+ // A frame that cannot take a step passes it on to this document, which the compositor scrolls by it.+ for (const [name, frame, y] of [["with nothing to scroll", frameWithNothingToScroll, 75], ["at its edge", frameAtItsEdge, 225]]) {+ await waitForCondition(() => frame.contentWindow.internals.compositorScrollState().document === frame.contentDocument+ && internals.compositorWheelTargetAt(100, y, 0, 50).decision === "latched");+ const frameScrollY = frame.contentWindow.scrollY;+ internals.beginInputTrace();+ await scrollSettled(document, () => internals.wheelThroughUIProcess(100, y, 0, 50));+ println(`over a frame ${name}:`);+ printInputTrace(internals.takeInputTrace(), { stages: ["compositor"] });+ println(`frame scrolled: ${frame.contentWindow.scrollY !== frameScrollY}`);+ println(`window.scrollY: ${window.scrollY}`);+ window.scrollTo(0, 0);+ await animationFrame();+ await animationFrame();+ }+ });+</script>diff --git a/Tests/LibWeb/Text/input/include.js b/Tests/LibWeb/Text/input/include.jsindex 116f331cdc2..43c53bb009d 100644--- a/Tests/LibWeb/Text/input/include.js+++ b/Tests/LibWeb/Text/input/include.js@@ -102,7 +102,8 @@ async function scrollSettled(target, action) {}function __describeNodeOfInputHook(node, documentName = "document") {- if (node instanceof Document) return node === document ? documentName : `nested ${documentName}`;+ // A nested document comes from another realm, whose Document it is an instance of.+ if (node.nodeType === Node.DOCUMENT_NODE) return node === document ? documentName : `nested ${documentName}`;if (node.id) return `#${node.id}`;return node.nodeName.toLowerCase();}