Skip to content

Truly independent web browser

LibCompositing+Compositor: Resolve sticky offsets once per install

Aliaksandr Kalenikcf88d7d9582f
diff --git a/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cpp b/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cpp
index 65d6f5f0c84..23ab497a9d6 100644
--- a/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cpp
+++ b/Libraries/LibCompositing/Scrolling/AsyncScrollTree.cpp
@@ -631,10 +631,16 @@ Optional<Gfx::FloatPoint> AsyncScrollTree::set_scroll_offset(Compositing::Spatia
if (!node)
return {};
- auto new_scroll_offset = clamp_scroll_offset_to_node(*node, scroll_offset);
- scroll_state_snapshot.set_device_offset_for_index(node->scroll_node_index, { -new_scroll_offset.x(), -new_scroll_offset.y() });
+ auto new_scroll_offset = set_scroll_offset_leaving_sticky_offsets_unresolved(*node, scroll_offset, scroll_state_snapshot);
Compositing::resolve_sticky_offsets(visual_context_tree, scroll_state_snapshot);
return new_scroll_offset;
}
+Gfx::FloatPoint AsyncScrollTree::set_scroll_offset_leaving_sticky_offsets_unresolved(AsyncScrollNode const& node, Gfx::FloatPoint scroll_offset, Compositing::ScrollStateSnapshot& scroll_state_snapshot)
+{
+ auto new_scroll_offset = clamp_scroll_offset_to_node(node, scroll_offset);
+ scroll_state_snapshot.set_device_offset_for_index(node.scroll_node_index, { -new_scroll_offset.x(), -new_scroll_offset.y() });
+ return new_scroll_offset;
+}
+
}
diff --git a/Libraries/LibCompositing/Scrolling/AsyncScrollTree.h b/Libraries/LibCompositing/Scrolling/AsyncScrollTree.h
index 6741761fd25..9599dbb2864 100644
--- a/Libraries/LibCompositing/Scrolling/AsyncScrollTree.h
+++ b/Libraries/LibCompositing/Scrolling/AsyncScrollTree.h
@@ -178,6 +178,7 @@ public:
Optional<AsyncScrollOffset> apply_scroll_delta(Compositing::SpatialNodeIndex, Gfx::FloatPoint delta, Compositing::AccumulatedVisualContextTree const&, Compositing::ScrollStateSnapshot&, ScrollChaining);
Optional<WheelScrollTarget> select_wheel_scroll_target(Compositing::SpatialNodeIndex, Gfx::FloatPoint delta, Compositing::ScrollStateSnapshot const&, Function<Optional<Gfx::FloatPoint>(Web::AsyncScrollNodeStableID)> const& in_flight_destination_for, ScrollChaining scroll_chaining) const;
Optional<Gfx::FloatPoint> set_scroll_offset(Compositing::SpatialNodeIndex, Gfx::FloatPoint, Compositing::AccumulatedVisualContextTree const&, Compositing::ScrollStateSnapshot&);
+ Gfx::FloatPoint set_scroll_offset_leaving_sticky_offsets_unresolved(AsyncScrollNode const&, Gfx::FloatPoint, Compositing::ScrollStateSnapshot&);
private:
static Gfx::FloatPoint clamp_scroll_offset_to_node(AsyncScrollNode const&, Gfx::FloatPoint);
diff --git a/Services/Compositor/ContextState.cpp b/Services/Compositor/ContextState.cpp
index 5b8ba52d8db..26d94476e5b 100644
--- a/Services/Compositor/ContextState.cpp
+++ b/Services/Compositor/ContextState.cpp
@@ -2174,6 +2174,7 @@ Optional<Gfx::FloatPoint> ContextState::keep_scroll_offsets_of_known_nodes(HashM
{
Optional<Gfx::FloatPoint> viewport_scroll_offset;
Vector<Compositing::AsyncScrollOffset> clamped_scroll_offsets;
+ bool kept_any_scroll_offset = false;
m_scroll_offsets_differ_from_last_frame = false;
m_scroll_nodes_seeded_by_last_frame.clear();
for (auto const& node : m_async_scroll_tree.scroll_nodes()) {
@@ -2184,17 +2185,16 @@ Optional<Gfx::FloatPoint> ContextState::keep_scroll_offsets_of_known_nodes(HashM
}
if (m_async_scroll_tree.scroll_offset_for_node(node.scroll_node_index, m_scroll_state_snapshot) != known_scroll_offset)
m_scroll_offsets_differ_from_last_frame = true;
- auto kept_scroll_offset = m_async_scroll_tree.set_scroll_offset(node.scroll_node_index, known_scroll_offset.value(), m_scene.current_visual_context_tree(), m_scroll_state_snapshot);
- if (!kept_scroll_offset.has_value())
- continue;
+ 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;
if (node.is_viewport)
viewport_scroll_offset = kept_scroll_offset;
// A box whose scroll range shrank past its offset is told where it ended up.
- if (kept_scroll_offset.value() != known_scroll_offset.value()) {
+ if (kept_scroll_offset != known_scroll_offset.value()) {
clamped_scroll_offsets.append({
.stable_node_id = node.stable_node_id,
- .compositor_scroll_offset = kept_scroll_offset.value(),
- .unadopted_scroll_delta = kept_scroll_offset.value() - known_scroll_offset.value(),
+ .compositor_scroll_offset = kept_scroll_offset,
+ .unadopted_scroll_delta = kept_scroll_offset - known_scroll_offset.value(),
.last_relative_scroll_delta = {},
.visual_viewport_scale = {},
.applied_scroll_request_id = 0,
@@ -2202,6 +2202,9 @@ Optional<Gfx::FloatPoint> ContextState::keep_scroll_offsets_of_known_nodes(HashM
});
}
}
+ // Resolving sticky offsets walks the whole visual context tree, so it runs once, after every offset is kept.
+ if (kept_any_scroll_offset)
+ Compositing::resolve_sticky_offsets(m_scene.current_visual_context_tree(), m_scroll_state_snapshot);
if (!clamped_scroll_offsets.is_empty())
store_pending_async_scroll_offsets(clamped_scroll_offsets);
return viewport_scroll_offset;