Truly independent web browser
LibCompositing+Compositor: Read offsets of walked scroll nodes directly
Aliaksandr Kalenik0230b4769aae
diff --git a/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cpp b/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cppindex 23ab497a9d6..56a9f4dd3b9 100644--- a/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cpp+++ b/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cpp@@ -388,6 +388,11 @@ Optional<Web::CSSPixelPoint> AsyncScrollTree::css_scroll_offset_for_node(Composireturn scroll_offset_for_node(scroll_node_index, scroll_state_snapshot).map([&](auto device_offset) { return css_pixels_from_device_offset(device_offset); });}+Web::CSSPixelPoint AsyncScrollTree::css_scroll_offset_for_node(AsyncScrollNode const& node, Compositing::ScrollStateSnapshot const& scroll_state_snapshot) const+{+ return css_pixels_from_device_offset(scroll_offset_for_node(node, scroll_state_snapshot));+}+Optional<Compositing::SpatialNodeIndex> AsyncScrollTree::viewport_scroll_node_index() const{for (auto const& node : m_scroll_nodes) {diff --git a/Libraries/LibCompositing/Scrolling/AsyncScrollTree.h b/Libraries/LibCompositing/Scrolling/AsyncScrollTree.hindex 9599dbb2864..304fc918409 100644--- a/Libraries/LibCompositing/Scrolling/AsyncScrollTree.h+++ b/Libraries/LibCompositing/Scrolling/AsyncScrollTree.h@@ -131,6 +131,7 @@ public:void rebuild_wheel_hit_test_targets(RefPtr<Compositing::DisplayList const> const&, Compositing::AccumulatedVisualContextTree const*, Compositing::ScrollStateSnapshot const&);Optional<Gfx::FloatPoint> scroll_offset_for_node(Compositing::SpatialNodeIndex, Compositing::ScrollStateSnapshot const&) const;+ static Gfx::FloatPoint scroll_offset_for_node(AsyncScrollNode const&, Compositing::ScrollStateSnapshot const&);Optional<Web::UniqueNodeID> document_id() const { return m_document_id; }Optional<Compositing::SpatialNodeIndex> viewport_scroll_node_index() const;Optional<Compositing::SpatialNodeIndex> scroll_node_index_for_stable_id(Web::AsyncScrollNodeStableID) const;@@ -144,6 +145,7 @@ public:Web::CSSPixelPoint css_pixels_from_device_offset(Gfx::FloatPoint) const;Gfx::FloatPoint device_offset_from_css_pixels(Web::CSSPixelPoint) const;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;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.@@ -182,7 +184,6 @@ public:private:static Gfx::FloatPoint clamp_scroll_offset_to_node(AsyncScrollNode const&, Gfx::FloatPoint);- static Gfx::FloatPoint scroll_offset_for_node(AsyncScrollNode const&, Compositing::ScrollStateSnapshot const&);static bool can_scroll_node_by_delta(AsyncScrollNode const&, Compositing::ScrollStateSnapshot const&, Gfx::FloatPoint);static bool can_scroll_node_from_offset_by_delta(AsyncScrollNode const&, Gfx::FloatPoint scroll_offset, Gfx::FloatPoint delta);diff --git a/Services/Compositor/ContextState.cpp b/Services/Compositor/ContextState.cppindex 26d94476e5b..5d55751abeb 100644--- a/Services/Compositor/ContextState.cpp+++ b/Services/Compositor/ContextState.cpp@@ -1984,10 +1984,8 @@ Vector<Web::CompositorScrollOffset> ContextState::scroll_offsets() constauto scroll_nodes = m_async_scroll_tree.scroll_nodes();Vector<Web::CompositorScrollOffset> scroll_offsets;scroll_offsets.ensure_capacity(scroll_nodes.size());- for (auto const& node : scroll_nodes) {- if (auto offset = m_async_scroll_tree.css_scroll_offset_for_node(node.scroll_node_index, m_scroll_state_snapshot); offset.has_value())- scroll_offsets.unchecked_append({ node.stable_node_id, *offset });- }+ for (auto const& node : scroll_nodes)+ scroll_offsets.unchecked_append({ node.stable_node_id, m_async_scroll_tree.css_scroll_offset_for_node(node, m_scroll_state_snapshot) });return scroll_offsets;}@@ -2160,10 +2158,8 @@ HashMap<Web::AsyncScrollNodeStableID, Gfx::FloatPoint> ContextState::scroll_offsHashMap<Web::AsyncScrollNodeStableID, Gfx::FloatPoint> scroll_offsets;if (!m_has_async_scrolling_state)return scroll_offsets;- for (auto const& node : m_async_scroll_tree.scroll_nodes()) {- if (auto offset = m_async_scroll_tree.scroll_offset_for_node(node.scroll_node_index, m_scroll_state_snapshot); offset.has_value())- scroll_offsets.set(node.stable_node_id, offset.value());- }+ for (auto const& node : m_async_scroll_tree.scroll_nodes())+ scroll_offsets.set(node.stable_node_id, m_async_scroll_tree.scroll_offset_for_node(node, m_scroll_state_snapshot));return scroll_offsets;}@@ -2183,7 +2179,7 @@ Optional<Gfx::FloatPoint> ContextState::keep_scroll_offsets_of_known_nodes(HashMm_scroll_nodes_seeded_by_last_frame.set(node.stable_node_id);continue;}- if (m_async_scroll_tree.scroll_offset_for_node(node.scroll_node_index, m_scroll_state_snapshot) != known_scroll_offset)+ if (m_async_scroll_tree.scroll_offset_for_node(node, m_scroll_state_snapshot) != known_scroll_offset.value())m_scroll_offsets_differ_from_last_frame = true;auto kept_scroll_offset = m_async_scroll_tree.set_scroll_offset_leaving_sticky_offsets_unresolved(node, known_scroll_offset.value(), m_scroll_state_snapshot);kept_any_scroll_offset = true;