Truly independent web browser
Compositor: Let only what is under a pinch hold it back
Andreas Klingd4d1d9ebfb10
diff --git a/Libraries/LibCompositing/Scrolling/AsyncScrollTree.h b/Libraries/LibCompositing/Scrolling/AsyncScrollTree.hindex 304fc918409..73e2a31cdaa 100644--- a/Libraries/LibCompositing/Scrolling/AsyncScrollTree.h+++ b/Libraries/LibCompositing/Scrolling/AsyncScrollTree.h@@ -147,6 +147,7 @@ public:Optional<Web::CSSPixelPoint> css_scroll_offset_for_node(Compositing::SpatialNodeIndex, Compositing::ScrollStateSnapshot const&) const;Web::CSSPixelPoint css_scroll_offset_for_node(AsyncScrollNode const&, Compositing::ScrollStateSnapshot const&) const;bool blocks_wheel_event_at_position(Compositing::AccumulatedVisualContextTree const&, Gfx::FloatPoint position) const;+ bool main_thread_wheel_event_region_contains(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, NestedContextRegions = NestedContextRegions::LeaveToMainThread) const;// The nested context whose content is the topmost thing taking pointer input at the position, if any.Optional<NestedContextHit> nested_context_at(Compositing::AccumulatedVisualContextTree const&, Gfx::FloatPoint position) const;@@ -188,7 +189,6 @@ private:static bool can_scroll_node_from_offset_by_delta(AsyncScrollNode const&, Gfx::FloatPoint scroll_offset, Gfx::FloatPoint delta);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;diff --git a/Services/Compositor/CompositorState.cpp b/Services/Compositor/CompositorState.cppindex 9171535821e..ab0d3b37272 100644--- a/Services/Compositor/CompositorState.cpp+++ b/Services/Compositor/CompositorState.cpp@@ -1164,17 +1164,31 @@ void CompositorState::dispatch_scroll_fling_step(Web::CompositorContextId contexcontext.dispatch_mouse_event_to_web_content(*event);}-// A pinch over a document nested in the context is a ctrl+wheel event to that document first, which its blocking wheel-// event listeners may cancel before anything zooms. Rather than hit test contexts the pinch may be zooming, any nested-// context that would hold back a pinch of its own holds back the pinch of the context it is nested in.-bool CompositorState::nested_context_may_cancel_pinch(Web::CompositorContextId context_id) const+// A pinch is a ctrl+wheel event first, to the document under it, whose blocking wheel event listeners may cancel it+// before anything zooms. Only the documents at the position can see that event.+bool CompositorState::page_under_pinch_may_cancel_it(Web::CompositorContextId context_id, ContextState& context, Gfx::FloatPoint position){- for (auto const& context_entry : m_contexts) {- auto const& nested_context = *context_entry.value;- if (!nested_context.admits_async_pinch() && is_nested_in(context_id, nested_context))+ auto containing_context_id = context_id;+ auto* containing_context = &context;+ // A walk down the nested contexts that outlasts the number of contexts went around a loop.+ for (size_t remaining_contexts = m_contexts.size(); remaining_contexts > 0; --remaining_contexts) {+ if (containing_context->page_may_cancel_pinch_at(position))+ return true;+ auto hit = containing_context->nested_context_for_wheel_at(position);+ if (!hit.has_value())+ return false;+ // NB: Nothing is known yet of the listeners of a context that is not available.+ auto* nested_context = context_if_present(hit->child_context_id);+ if (!nested_context || nested_context->parent_context_id() != containing_context_id)+ return true;+ auto position_in_nested = position_in_nested_context(*hit, *nested_context);+ if (!position_in_nested.has_value())return true;+ containing_context_id = hit->child_context_id;+ containing_context = nested_context;+ position = *position_in_nested;}- return false;+ return true;}void CompositorState::handle_and_dispatch_pinch_event(Web::CompositorContextId context_id, Web::PinchEvent event)@@ -1188,8 +1202,9 @@ void CompositorState::handle_and_dispatch_pinch_event(Web::CompositorContextId creturn;}- // A nested document that already let the event through leaves only the zoom to do.- if (context->admits_async_pinch() && (event.wheel_event_was_dispatched || !nested_context_may_cancel_pinch(context_id)))+ // A page that already let the event through leaves only the zoom to do.+ Gfx::FloatPoint position { static_cast<float>(event.position.x().value()), static_cast<float>(event.position.y().value()) };+ if (event.wheel_event_was_dispatched || !page_under_pinch_may_cancel_it(context_id, *context, position))event.async_zoom_performed_default_action = apply_context_update_result(context_id, *context, context->handle_pinch_event(event));// The scroll updates the event produced reach WebContent ahead of the event itself on the same connection.diff --git a/Services/Compositor/CompositorState.h b/Services/Compositor/CompositorState.hindex ca98ddd806d..ba8d88d1974 100644--- a/Services/Compositor/CompositorState.h+++ b/Services/Compositor/CompositorState.h@@ -292,7 +292,7 @@ private:// without regard to where their content is or what clips it.Optional<Gfx::FloatPoint> position_in_nested_context_ignoring_clips(Web::CompositorContextId presenting_context_id, ContextState& presenting_context, ContextState& nested_context, Gfx::FloatPoint position);bool is_nested_in(Web::CompositorContextId containing_context_id, ContextState const&) const;- bool nested_context_may_cancel_pinch(Web::CompositorContextId) const;+ bool page_under_pinch_may_cancel_it(Web::CompositorContextId, ContextState&, Gfx::FloatPoint position);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 9786e208e43..877babb7631 100644--- a/Services/Compositor/ContextState.cpp+++ b/Services/Compositor/ContextState.cpp@@ -678,9 +678,7 @@ ContextState::ContextUpdateResult ContextState::handle_mouse_event_at(Web::MouseContextState::ContextUpdateResult ContextState::handle_pinch_event(Web::PinchEvent const& event){- if (!presents_to_client())- return {};- if (!m_wheel_gesture_routing.admits_async_pinch())+ if (!presents_to_client() || !m_has_async_scrolling_state)return {};if (!m_scene.visual_context_tree().has_value())return {};@@ -1735,6 +1733,16 @@ bool ContextState::may_hand_first_wheel_steps_to_nested_contexts() constreturn m_has_async_scrolling_state && m_scene.visual_viewport_scale().value_or(1.0f) == 1.0f;}+bool ContextState::page_may_cancel_pinch_at(Gfx::FloatPoint position)+{+ if (!m_has_async_scrolling_state || !m_wheel_gesture_routing.admits_async_pinch())+ return true;+ auto const& visual_context_tree = m_scene.visual_context_tree_for_compositing();+ // NB: The main thread takes the wheel events of a nested document the compositor cannot reach.+ return m_async_scroll_tree.blocks_wheel_event_at_position(visual_context_tree, position)+ || m_async_scroll_tree.main_thread_wheel_event_region_contains(visual_context_tree, position);+}+Optional<Compositing::NestedContextHit> ContextState::nested_context_for_wheel_at(Gfx::FloatPoint position){if (!m_has_async_scrolling_state)diff --git a/Services/Compositor/ContextState.h b/Services/Compositor/ContextState.hindex c062b712682..a69899a4bc7 100644--- a/Services/Compositor/ContextState.h+++ b/Services/Compositor/ContextState.h@@ -244,6 +244,8 @@ public: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(); }+ // Whether this context's page may cancel the ctrl+wheel event of a pinch at the position, or has yet to tell.+ bool page_may_cancel_pinch_at(Gfx::FloatPoint position);bool may_hand_first_wheel_steps_to_nested_contexts() const;Optional<Compositing::NestedContextHit> nested_context_for_wheel_at(Gfx::FloatPoint position);diff --git a/Services/Compositor/WheelGestureRouting.cpp b/Services/Compositor/WheelGestureRouting.cppindex b0f6e6d592b..06c8c2daa40 100644--- a/Services/Compositor/WheelGestureRouting.cpp+++ b/Services/Compositor/WheelGestureRouting.cpp@@ -34,21 +34,18 @@ void WheelGestureRouting::did_install_scrolling_state(Compositing::AsyncScrollin{m_admission = Compositing::wheel_routing_admission_for(async_scrolling_state, m_wheel_event_listener_state_generation);m_wheel_event_listener_state_generation = max(m_wheel_event_listener_state_generation, async_scrolling_state.wheel_event_listener_state_generation);- m_has_blocking_wheel_event_listeners = async_scrolling_state.has_blocking_wheel_event_listeners;}void WheelGestureRouting::invalidate_wheel_event_listener_state(u64 generation){m_wheel_event_listener_state_generation = max(m_wheel_event_listener_state_generation, generation);m_admission = Compositing::WheelRoutingAdmission::StaleWheelEventListeners;- m_has_blocking_wheel_event_listeners = true;}bool WheelGestureRouting::admits_async_pinch() const{// Pinch zoom scales the visual viewport, which a page whose viewport cannot be scrolled has too.- return first_is_one_of(m_admission, Compositing::WheelRoutingAdmission::Accepted, Compositing::WheelRoutingAdmission::NoScrollNode)- && !m_has_blocking_wheel_event_listeners;+ return first_is_one_of(m_admission, Compositing::WheelRoutingAdmission::Accepted, Compositing::WheelRoutingAdmission::NoScrollNode);}WheelGestureRouting::NotedWheelEvent WheelGestureRouting::note_wheel_event(Web::MouseEvent const& event, Gfx::FloatPoint position, Compositing::AsyncScrollTree const& async_scroll_tree, MonotonicTime now)diff --git a/Services/Compositor/WheelGestureRouting.h b/Services/Compositor/WheelGestureRouting.hindex df0c08c6145..d8d7fee5748 100644--- a/Services/Compositor/WheelGestureRouting.h+++ b/Services/Compositor/WheelGestureRouting.h@@ -118,7 +118,6 @@ private:};Compositing::WheelRoutingAdmission m_admission { Compositing::WheelRoutingAdmission::NoAsyncScrollingState };- bool m_has_blocking_wheel_event_listeners { false };u64 m_wheel_event_listener_state_generation { 0 };struct Gesture {u64 id;diff --git a/Tests/LibWeb/Text/expected/SiteIsolation/iframe/pinch-away-from-isolated-iframe-with-blocking-wheel-listener.txt b/Tests/LibWeb/Text/expected/SiteIsolation/iframe/pinch-away-from-isolated-iframe-with-blocking-wheel-listener.txtindex 9e81d140bc7..23ad22d841f 100644--- a/Tests/LibWeb/Text/expected/SiteIsolation/iframe/pinch-away-from-isolated-iframe-with-blocking-wheel-listener.txt+++ b/Tests/LibWeb/Text/expected/SiteIsolation/iframe/pinch-away-from-isolated-iframe-with-blocking-wheel-listener.txt@@ -1 +1 @@-compositor scale beside the task: 1+compositor scale beside the task: 1.5diff --git a/Tests/LibWeb/Text/expected/async-scrolling/pinch-away-from-a-blocking-wheel-listener.txt b/Tests/LibWeb/Text/expected/async-scrolling/pinch-away-from-a-blocking-wheel-listener.txtindex b2b3be08f53..fd488772f92 100644--- a/Tests/LibWeb/Text/expected/async-scrolling/pinch-away-from-a-blocking-wheel-listener.txt+++ b/Tests/LibWeb/Text/expected/async-scrolling/pinch-away-from-a-blocking-wheel-listener.txt@@ -1,2 +1,2 @@over the listener: cancelable=true compositor scale=1-away from the listener, beside the task: compositor scale=1+away from the listener, beside the task: compositor scale=1.5