Truly independent web browser
LibWeb+LibCompositing: Drop the enclosing scroll node of a box
Aliaksandr Kalenikbfd4997cee97
diff --git a/Libraries/LibCompositing/Rust/src/display_list/damage.rs b/Libraries/LibCompositing/Rust/src/display_list/damage.rsindex 0777447d254..05341fcf229 100644--- a/Libraries/LibCompositing/Rust/src/display_list/damage.rs+++ b/Libraries/LibCompositing/Rust/src/display_list/damage.rs@@ -2218,7 +2218,6 @@ mod tests {SpatialData::Scroll(ScrollData {state_slot: NO_SCROLL_STATE_SLOT,owner_paintable: NodeSlotId::INVALID,- registry_parent_node: VISUAL_VIEWPORT_NODE_INDEX,}),VISUAL_VIEWPORT_NODE_INDEX,);@@ -2236,7 +2235,6 @@ mod tests {SpatialData::Scroll(ScrollData {state_slot: NO_SCROLL_STATE_SLOT,owner_paintable: NodeSlotId::INVALID,- registry_parent_node: VISUAL_VIEWPORT_NODE_INDEX,}),VISUAL_VIEWPORT_NODE_INDEX,);@@ -2377,7 +2375,6 @@ mod tests {SpatialData::Scroll(ScrollData {state_slot: 1,owner_paintable: NodeSlotId::INVALID,- registry_parent_node: VISUAL_VIEWPORT_NODE_INDEX,}),VISUAL_VIEWPORT_NODE_INDEX,);@@ -2455,7 +2452,6 @@ mod tests {SpatialData::Scroll(ScrollData {state_slot: 1,owner_paintable: NodeSlotId::INVALID,- registry_parent_node: VISUAL_VIEWPORT_NODE_INDEX,}),VISUAL_VIEWPORT_NODE_INDEX,);@@ -2577,7 +2573,6 @@ mod tests {SpatialData::Scroll(ScrollData {state_slot: 1,owner_paintable: NodeSlotId::INVALID,- registry_parent_node: VISUAL_VIEWPORT_NODE_INDEX,}),VISUAL_VIEWPORT_NODE_INDEX,);diff --git a/Libraries/LibCompositing/Rust/src/display_list/replay.rs b/Libraries/LibCompositing/Rust/src/display_list/replay.rsindex 942737b6017..15b486a5981 100644--- a/Libraries/LibCompositing/Rust/src/display_list/replay.rs+++ b/Libraries/LibCompositing/Rust/src/display_list/replay.rs@@ -2166,7 +2166,6 @@ mod tests {SpatialData::Scroll(crate::visual_context::ScrollData {state_slot: crate::visual_context::scroll_state::NO_SCROLL_STATE_SLOT,owner_paintable: NodeSlotId::INVALID,- registry_parent_node: VISUAL_VIEWPORT_NODE_INDEX,}),VISUAL_VIEWPORT_NODE_INDEX,);diff --git a/Libraries/LibCompositing/Rust/src/ffi.rs b/Libraries/LibCompositing/Rust/src/ffi.rsindex a6606159adc..21fac2af08c 100644--- a/Libraries/LibCompositing/Rust/src/ffi.rs+++ b/Libraries/LibCompositing/Rust/src/ffi.rs@@ -659,7 +659,6 @@ pub unsafe extern "C" fn visual_context_tree_test_builder_append_scroll(builder:crate::visual_context::SpatialData::Scroll(crate::visual_context::ScrollData {state_slot: crate::visual_context::scroll_state::NO_SCROLL_STATE_SLOT,owner_paintable: NodeSlotId::INVALID,- registry_parent_node: SpatialNodeIndex(parent),}),SpatialNodeIndex(parent),)diff --git a/Libraries/LibCompositing/Rust/src/visual_context/mod.rs b/Libraries/LibCompositing/Rust/src/visual_context/mod.rsindex 96c64826b11..f09e3573bad 100644--- a/Libraries/LibCompositing/Rust/src/visual_context/mod.rs+++ b/Libraries/LibCompositing/Rust/src/visual_context/mod.rs@@ -152,7 +152,6 @@ pub struct MaskData {pub struct ScrollData {pub state_slot: ScrollStateSlot,pub owner_paintable: NodeSlotId,- pub registry_parent_node: SpatialNodeIndex,}// A sticky box's shift is derived when the scroll state snapshot is resolved, from the scroller's@@ -724,7 +723,6 @@ fn for_each_spatial_node_reference(visit(node.parent);}match &node.data {- SpatialData::Scroll(scroll) => visit(scroll.registry_parent_node),SpatialData::Sticky(sticky) => {visit(sticky.scroller);if let Some(parent_sticky) = sticky.parent_sticky {@@ -739,7 +737,7 @@ fn for_each_spatial_node_reference(}SpatialData::BackfaceVisibility(backface) => visit(backface.plane_root_index),SpatialData::AnchorScrollShift(shift) => visit(shift.scroll_node_index),- SpatialData::Perspective(_) | SpatialData::Dead => {}+ SpatialData::Scroll(_) | SpatialData::Perspective(_) | SpatialData::Dead => {}}}@@ -1530,7 +1528,6 @@ mod tests {SpatialData::Scroll(ScrollData {state_slot: NO_SCROLL_STATE_SLOT,owner_paintable: NodeSlotId::INVALID,- registry_parent_node: VISUAL_VIEWPORT_NODE_INDEX,}),VISUAL_VIEWPORT_NODE_INDEX,);@@ -1590,7 +1587,6 @@ mod tests {SpatialData::Scroll(ScrollData {state_slot: NO_SCROLL_STATE_SLOT,owner_paintable: NodeSlotId::INVALID,- registry_parent_node: VISUAL_VIEWPORT_NODE_INDEX,})}diff --git a/Libraries/LibCompositing/Rust/src/visual_context/queries.rs b/Libraries/LibCompositing/Rust/src/visual_context/queries.rsindex 577d50b4d12..b7cc3369c58 100644--- a/Libraries/LibCompositing/Rust/src/visual_context/queries.rs+++ b/Libraries/LibCompositing/Rust/src/visual_context/queries.rs@@ -916,7 +916,6 @@ mod tests {SpatialData::Scroll(ScrollData {state_slot: NO_SCROLL_STATE_SLOT,owner_paintable: NodeSlotId::INVALID,- registry_parent_node: VISUAL_VIEWPORT_NODE_INDEX,})}@@ -1633,10 +1632,6 @@ mod tests {registry_parent_node: map(sticky.registry_parent_node),..*sticky}),- SpatialData::Scroll(scroll) => SpatialData::Scroll(ScrollData {- registry_parent_node: map(scroll.registry_parent_node),- ..*scroll- }),other => other.clone(),}}diff --git a/Libraries/LibCompositing/Rust/src/visual_context/scroll_state.rs b/Libraries/LibCompositing/Rust/src/visual_context/scroll_state.rsindex 4df3217d9da..2df39b01ffa 100644--- a/Libraries/LibCompositing/Rust/src/visual_context/scroll_state.rs+++ b/Libraries/LibCompositing/Rust/src/visual_context/scroll_state.rs@@ -17,10 +17,9 @@ pub const NO_SCROLL_STATE_SLOT: ScrollStateSlot = usize::MAX;// Registry entry of one scroll-like node of the accumulated visual context tree, addressed by the// slot stamped into the node's payload. A scroll container's offset is kept beside the entries; a-// sticky node's entry only links it into the scroll-parent chain, which the anchor default-scroll-shift-// derivation walks and which decides the node's scroller and parent sticky. That chain follows-// containing blocks, deliberately unlike the visual context parent chain for sticky content inside-// fixed-position ancestors.+// sticky node's entry only links it to its parent, which decides the node's scroller and parent+// sticky. That link follows containing blocks, deliberately unlike the visual context parent chain+// for sticky content inside fixed-position ancestors.#[derive(Clone, Debug)]pub struct ScrollNodeState {pub paintable: NodeSlotId,@@ -30,8 +29,8 @@ pub struct ScrollNodeState {}// Registry of the scroll-like nodes of the accumulated visual context tree: the tree owns-// structure and identity, entries here carry the scroll containers' offsets and the-// containing-block-derived scroll-parent references. Rebuilt together with the tree; offsets are+// structure and identity, entries here carry the scroll containers' offsets and the sticky nodes'+// containing-block-derived parent references. Rebuilt together with the tree; offsets are// refreshed in place between rebuilds. Sticky offsets never live here: they are derived from the// tree when the snapshot is resolved.#[derive(Clone, Default)]@@ -64,17 +63,12 @@ impl ScrollState {self.states.len() - 1}- pub fn register_scroll_node(- &mut self,- node_index: SpatialNodeIndex,- paintable: NodeSlotId,- parent_slot: ScrollStateSlot,- ) -> ScrollStateSlot {+ pub fn register_scroll_node(&mut self, node_index: SpatialNodeIndex, paintable: NodeSlotId) -> ScrollStateSlot {self.append(ScrollNodeState {paintable,is_sticky: false,node_index,- parent_slot,+ parent_slot: NO_SCROLL_STATE_SLOT,})}diff --git a/Libraries/LibCompositing/Rust/src/visual_context/serialize.rs b/Libraries/LibCompositing/Rust/src/visual_context/serialize.rsindex 227a943823d..3b46b055437 100644--- a/Libraries/LibCompositing/Rust/src/visual_context/serialize.rs+++ b/Libraries/LibCompositing/Rust/src/visual_context/serialize.rs@@ -377,7 +377,6 @@ fn read_spatial_data(reader: &mut TreeByteReader<'_>) -> Option<SpatialData> {SPATIAL_KIND_SCROLL => SpatialData::Scroll(ScrollData {state_slot: NO_SCROLL_STATE_SLOT,owner_paintable: NodeSlotId::INVALID,- registry_parent_node: VISUAL_VIEWPORT_NODE_INDEX,}),SPATIAL_KIND_STICKY => {let scroller = reader.spatial_index()?;@@ -980,7 +979,6 @@ mod tests {SpatialData::Scroll(ScrollData {state_slot: NO_SCROLL_STATE_SLOT,owner_paintable: NodeSlotId::INVALID,- registry_parent_node: VISUAL_VIEWPORT_NODE_INDEX,}),VISUAL_VIEWPORT_NODE_INDEX,);@@ -1494,7 +1492,6 @@ mod tests {SpatialData::Scroll(ScrollData {state_slot: NO_SCROLL_STATE_SLOT,owner_paintable: NodeSlotId::INVALID,- registry_parent_node: VISUAL_VIEWPORT_NODE_INDEX,}),VISUAL_VIEWPORT_NODE_INDEX,);@@ -1662,7 +1659,6 @@ mod tests {SpatialData::Scroll(ScrollData {state_slot: NO_SCROLL_STATE_SLOT,owner_paintable: NodeSlotId::INVALID,- registry_parent_node: VISUAL_VIEWPORT_NODE_INDEX,}),VISUAL_VIEWPORT_NODE_INDEX,);@@ -1801,7 +1797,6 @@ mod tests {root_is_not_a_transform.spatial_nodes[0].data = SpatialData::Scroll(ScrollData {state_slot: NO_SCROLL_STATE_SLOT,owner_paintable: NodeSlotId::INVALID,- registry_parent_node: VISUAL_VIEWPORT_NODE_INDEX,});assert!(VisualContextTree::from_bytes(&encode_tree(&root_is_not_a_transform)).is_none());diff --git a/Libraries/LibWeb/Rust/src/painting/paintable_data.rs b/Libraries/LibWeb/Rust/src/painting/paintable_data.rsindex 9ccc12ffe68..a96cfd874a4 100644--- a/Libraries/LibWeb/Rust/src/painting/paintable_data.rs+++ b/Libraries/LibWeb/Rust/src/painting/paintable_data.rs@@ -52,7 +52,6 @@ pub struct PaintableData {pub establishes_stacking_context: bool,- pub enclosing_scroll_node_index: SpatialNodeIndex,pub own_scroll_node_index: SpatialNodeIndex,pub node_identity: i64,pub has_accumulated_visual_context: bool,@@ -70,7 +69,6 @@ impl Default for PaintableData {offset: used_values::FfiCssPixelPoint::default(),content_size: used_values::FfiCssPixelSize::default(),establishes_stacking_context: false,- enclosing_scroll_node_index: SpatialNodeIndex::default(),own_scroll_node_index: SpatialNodeIndex::default(),node_identity: 0,has_accumulated_visual_context: false,diff --git a/Libraries/LibWeb/Rust/src/painting/visual_context/box_build.rs b/Libraries/LibWeb/Rust/src/painting/visual_context/box_build.rsindex c5c290d190e..77baf474b95 100644--- a/Libraries/LibWeb/Rust/src/painting/visual_context/box_build.rs+++ b/Libraries/LibWeb/Rust/src/painting/visual_context/box_build.rs@@ -20,13 +20,12 @@ pub(crate) struct BoxBuildEnvironment<'a, Arena> {pub(crate) trait AnchorScrollShiftResolver {fn default_scroll_shift_anchor(&self, slot: NodeSlotId) -> NodeSlotId;- fn enclosing_scroll_node_index(&self, slot: NodeSlotId) -> SpatialNodeIndex;+ fn spatial_node_index(&self, slot: NodeSlotId) -> SpatialNodeIndex;}#[derive(Clone)]pub(crate) struct PaintableVisualContextAssignment {pub slot: NodeSlotId,- pub enclosing_scroll_node_index: SpatialNodeIndex,pub own_scroll_node_index: SpatialNodeIndex,pub node_identity: i64,pub has_accumulated_visual_context: bool,@@ -44,7 +43,6 @@ impl PaintableVisualContextAssignment {pub(crate) fn from_data(slot: NodeSlotId, data: &PaintableData, record: PaintableVisualContextRecord) -> Self {Self {slot,- enclosing_scroll_node_index: data.enclosing_scroll_node_index,own_scroll_node_index: data.own_scroll_node_index,node_identity: data.node_identity,has_accumulated_visual_context: data.has_accumulated_visual_context,@@ -70,8 +68,7 @@ impl PaintableVisualContextAssignment {Some(_) => {let data = layout_arena.paintable_data(self.slot);(- data.enclosing_scroll_node_index != self.enclosing_scroll_node_index- || data.own_scroll_node_index != self.own_scroll_node_index+ data.own_scroll_node_index != self.own_scroll_node_index|| data.node_identity != self.node_identity,data.has_flag(PaintableFlag::HasNonInvertibleCssTransform) != self.has_non_invertible_css_transform,)@@ -81,7 +78,6 @@ impl PaintableVisualContextAssignment {{let mut data = layout_arena.paintable_data_mut(self.slot);data.establishes_stacking_context = self.record.stacking_context.establishes_stacking_context;- data.enclosing_scroll_node_index = self.enclosing_scroll_node_index;data.own_scroll_node_index = self.own_scroll_node_index;data.node_identity = self.node_identity;data.has_accumulated_visual_context = self.has_accumulated_visual_context;@@ -103,36 +99,26 @@ impl PaintableVisualContextAssignment {}}-// A scroll-like node's registry parent follows containing blocks up to the viewport. A node-// that is not scroll-like ends the chain: a committed index can name a node an earlier box of-// this pass retired, and such a box contributes no scroll shift instead of a stale lookup.-fn scroll_registry_parent_node(sink: &impl VisualContextNodeSink, index: SpatialNodeIndex) -> Option<SpatialNodeIndex> {- if index == VISUAL_VIEWPORT_NODE_INDEX {- return None;- }- match &sink.spatial_node_at(index).data {- SpatialData::Scroll(scroll) => Some(scroll.registry_parent_node),- SpatialData::Sticky(sticky) => Some(sticky.registry_parent_node),- _ => None,- }-}--fn scroll_registry_chain_to_viewport(+// The scroll-like nodes that move content of the space of `index`, nearest first. A committed index+// can name a node an earlier box of this pass retired; the walk stops there, so such a box+// contributes no scroll shift instead of a stale lookup.+fn scroll_like_nodes_up_to_viewport(sink: &impl VisualContextNodeSink,index: SpatialNodeIndex,) -> Vec<SpatialNodeIndex> {- const MAX_SCROLL_REGISTRY_CHAIN_LENGTH: usize = 1024;- let mut chain = Vec::new();- let mut node = index;- while let Some(parent) = scroll_registry_parent_node(sink, node) {- debug_assert!(!chain.contains(&node), "scroll registry parents form a cycle");- if chain.len() >= MAX_SCROLL_REGISTRY_CHAIN_LENGTH {+ let mut scroll_like_nodes = Vec::new();+ let mut current = index;+ while current != VISUAL_VIEWPORT_NODE_INDEX {+ let node = sink.spatial_node_at(current);+ if !node.data.is_live() {break;}- chain.push(node);- node = parent;+ if node.data.is_scroll_like() {+ scroll_like_nodes.push(current);+ }+ current = node.parent;}- chain+ scroll_like_nodes}// https://drafts.csswg.org/css-anchor-position-1/#default-scroll-shift@@ -147,15 +133,15 @@ fn append_anchor_scroll_shift_nodes<Arena: PaintableRowsRead, Sink: VisualContexsink: &mut Sink,resolver: &dyn AnchorScrollShiftResolver,layout_node: NodeSlotId,- own_enclosing_scroll_node_index: SpatialNodeIndex,first_anchor_node: NodeSlotId,mut own_state: ContextRef,) -> ContextRef {- let enclosing_scroll_node_index = |node: NodeSlotId| {+ let own_spatial_node_before_shifts = own_state.spatial;+ let spatial_node_index = |node: NodeSlotId| {if node == layout_node {- own_enclosing_scroll_node_index+ own_spatial_node_before_shifts} else {- resolver.enclosing_scroll_node_index(node)+ resolver.spatial_node_index(node)}};let mut box_node = layout_node;@@ -179,8 +165,8 @@ fn append_anchor_scroll_shift_nodes<Arena: PaintableRowsRead, Sink: VisualContexcompensate_horizontal_scroll && box_flags & NodeFlag::CompensatesForHorizontalScroll as u32 != 0;compensate_vertical_scroll =compensate_vertical_scroll && box_flags & NodeFlag::CompensatesForVerticalScroll as u32 != 0;- let anchor_scroll_chain = scroll_registry_chain_to_viewport(sink, enclosing_scroll_node_index(anchor_node));- let base_scroll_chain = scroll_registry_chain_to_viewport(sink, enclosing_scroll_node_index(box_node));+ let anchor_scroll_chain = scroll_like_nodes_up_to_viewport(sink, spatial_node_index(anchor_node));+ let base_scroll_chain = scroll_like_nodes_up_to_viewport(sink, spatial_node_index(box_node));let shared_scroll_node = base_scroll_chain.iter().copied()@@ -267,35 +253,10 @@ pub(crate) fn build_box_visual_context_nodes<Arena: PaintableRowsRead>(stacking_context: stacking_context_facts,},);- assignment.enclosing_scroll_node_index = VISUAL_VIEWPORT_NODE_INDEX;assignment.own_scroll_node_index = VISUAL_VIEWPORT_NODE_INDEX;assignment.node_identity = 0;assignment.gathered_svg_filter_bounds = Some(svg_filter_bounds);- let mut nearest_scroll_nodes_for_descendants = if is_fixed {- NearestScrollNodeIndices {- stopping_at_fixed_position_ancestors: VISUAL_VIEWPORT_NODE_INDEX,- continuing_through_fixed_position_ancestors: inherited- .fixed_position- .nearest_scroll_nodes- .continuing_through_fixed_position_ancestors,- }- } else if is_absolute {- inherited.absolute_position.nearest_scroll_nodes- } else {- inherited.normal.nearest_scroll_nodes- };- let nearest_ancestor_scroll_node_index = if is_sticky {- nearest_scroll_nodes_for_descendants.continuing_through_fixed_position_ancestors- } else {- nearest_scroll_nodes_for_descendants.stopping_at_fixed_position_ancestors- };- if !is_fixed && !is_sticky {- assignment.enclosing_scroll_node_index = nearest_ancestor_scroll_node_index;- }-- let creates_sticky_scroll_node = is_sticky;-let inherited_chain = if is_fixed {inherited.fixed_position} else if is_absolute {@@ -305,6 +266,7 @@ pub(crate) fn build_box_visual_context_nodes<Arena: PaintableRowsRead>(// their visual parent.inherited.normal};+ let mut nearest_scroll_like_node_for_descendants = inherited_chain.nearest_scroll_like_node;// Build this element's own state from inherited state.let mut own_state = inherited_chain.with_effect(inherited.effect);@@ -313,7 +275,6 @@ pub(crate) fn build_box_visual_context_nodes<Arena: PaintableRowsRead>(sink,anchor_scroll_shift_resolver,layout_node,- assignment.enclosing_scroll_node_index,facts.default_scroll_shift_anchor,own_state,);@@ -357,13 +318,13 @@ pub(crate) fn build_box_visual_context_nodes<Arena: PaintableRowsRead>(}};}- let mut sticky_scroll_node_index = VISUAL_VIEWPORT_NODE_INDEX;- if creates_sticky_scroll_node {+ if is_sticky {// The scroll state fills in the geometry once the tree is built. The scroller is the nearest scroll node// above any enclosing sticky boxes, as the scroll state resolves it.- let (scroller, parent_sticky) = match &sink.spatial_node_at(nearest_ancestor_scroll_node_index).data {- SpatialData::Sticky(parent) => (parent.scroller, Some(nearest_ancestor_scroll_node_index)),- _ => (nearest_ancestor_scroll_node_index, None),+ let nearest_scroll_like_node = inherited_chain.nearest_scroll_like_node;+ let (scroller, parent_sticky) = match &sink.spatial_node_at(nearest_scroll_like_node).data {+ SpatialData::Sticky(parent) => (parent.scroller, Some(nearest_scroll_like_node)),+ _ => (nearest_scroll_like_node, None),};own_state = sink.append_spatial_node_under(own_state,@@ -372,15 +333,10 @@ pub(crate) fn build_box_visual_context_nodes<Arena: PaintableRowsRead>(parent_sticky,NO_SCROLL_STATE_SLOT,slot,- nearest_ancestor_scroll_node_index,+ nearest_scroll_like_node,)),);- sticky_scroll_node_index = own_state.spatial;- assignment.enclosing_scroll_node_index = sticky_scroll_node_index;- nearest_scroll_nodes_for_descendants = NearestScrollNodeIndices {- stopping_at_fixed_position_ancestors: sticky_scroll_node_index,- continuing_through_fixed_position_ancestors: sticky_scroll_node_index,- };+ nearest_scroll_like_node_for_descendants = own_state.spatial;}let transform_data = facts.transform;@@ -553,26 +509,17 @@ pub(crate) fn build_box_visual_context_nodes<Arena: PaintableRowsRead>(if paintable_geometry::has_scrollable_overflow(layout_arena, slot)|| crate::painting::chrome_geometry::keeps_scrolls_along_some_axis(layout_arena, slot){- let parent_index = if creates_sticky_scroll_node {- sticky_scroll_node_index- } else {- nearest_ancestor_scroll_node_index- };state_for_descendants = sink.append_spatial_node_under(state_for_descendants,SpatialData::Scroll(ScrollData {state_slot: NO_SCROLL_STATE_SLOT,owner_paintable: slot,- registry_parent_node: parent_index,}),);let scroll_node_index = state_for_descendants.spatial;assignment.own_scroll_node_index = scroll_node_index;assignment.node_identity = layout_arena.unique_node_ids().id(slot);- nearest_scroll_nodes_for_descendants = NearestScrollNodeIndices {- stopping_at_fixed_position_ancestors: scroll_node_index,- continuing_through_fixed_position_ancestors: scroll_node_index,- };+ nearest_scroll_like_node_for_descendants = scroll_node_index;}// A snap area is identified across relayouts and processes by its element, like a scroll node.@@ -590,7 +537,7 @@ pub(crate) fn build_box_visual_context_nodes<Arena: PaintableRowsRead>(let state_for_positioned_descendants = PositioningContext {spatial: state_for_descendants.spatial,clip: state_for_descendants.clip,- nearest_scroll_nodes: nearest_scroll_nodes_for_descendants,+ nearest_scroll_like_node: nearest_scroll_like_node_for_descendants,plane_root: plane_root_for_descendants,};if let Some(svg_viewport_transform) = super::build::svg_viewport_transform_of(layout_arena, slot) {@@ -619,7 +566,7 @@ pub(crate) fn build_box_visual_context_nodes<Arena: PaintableRowsRead>(normal: PositioningContext {spatial: state_for_descendants.spatial,clip: state_for_descendants.clip,- nearest_scroll_nodes: nearest_scroll_nodes_for_descendants,+ nearest_scroll_like_node: nearest_scroll_like_node_for_descendants,plane_root: plane_root_for_descendants,},absolute_position: state_for_absolute_position_descendants,diff --git a/Libraries/LibWeb/Rust/src/painting/visual_context/build.rs b/Libraries/LibWeb/Rust/src/painting/visual_context/build.rsindex 88be6248912..7dbf6f52145 100644--- a/Libraries/LibWeb/Rust/src/painting/visual_context/build.rs+++ b/Libraries/LibWeb/Rust/src/painting/visual_context/build.rs@@ -297,7 +297,6 @@ pub(crate) fn create_fresh_tree_with_viewport_nodes(SpatialData::Scroll(ScrollData {state_slot: NO_SCROLL_STATE_SLOT,owner_paintable: viewport,- registry_parent_node: VISUAL_VIEWPORT_NODE_INDEX,}),VISUAL_VIEWPORT_NODE_INDEX,);@@ -307,14 +306,10 @@ pub(crate) fn create_fresh_tree_with_viewport_nodes(effect: root_isolation_effect,};- let viewport_nearest_scroll_nodes = NearestScrollNodeIndices {- stopping_at_fixed_position_ancestors: viewport_scroll_node,- continuing_through_fixed_position_ancestors: viewport_scroll_node,- };let scrolled = PositioningContext {spatial: viewport_scroll_node,clip: ClipNodeIndex::NONE,- nearest_scroll_nodes: viewport_nearest_scroll_nodes,+ nearest_scroll_like_node: viewport_scroll_node,plane_root: viewport_scroll_node,};let viewport_contexts = DescendantVisualContexts {@@ -341,7 +336,6 @@ pub(crate) fn create_fresh_tree_with_viewport_nodes(stacking_context: crate::painting::stacking_context::StackingContextFacts::for_viewport(),},);- viewport_assignment.enclosing_scroll_node_index = VISUAL_VIEWPORT_NODE_INDEX;viewport_assignment.own_scroll_node_index = viewport_scroll_node;viewport_assignment.has_accumulated_visual_context = true;viewport_assignment.accumulated_visual_context = root_context;diff --git a/Libraries/LibWeb/Rust/src/painting/visual_context/dump.rs b/Libraries/LibWeb/Rust/src/painting/visual_context/dump.rsindex 67b20534c21..b36cce3b75d 100644--- a/Libraries/LibWeb/Rust/src/painting/visual_context/dump.rs+++ b/Libraries/LibWeb/Rust/src/painting/visual_context/dump.rs@@ -466,7 +466,6 @@ mod node_dump_tests {SpatialData::Scroll(ScrollData {state_slot: NO_SCROLL_STATE_SLOT,owner_paintable: NodeSlotId::INVALID,- registry_parent_node: VISUAL_VIEWPORT_NODE_INDEX,}),VISUAL_VIEWPORT_NODE_INDEX,);@@ -681,7 +680,6 @@ mod section_dump_tests {SpatialData::Scroll(ScrollData {state_slot: NO_SCROLL_STATE_SLOT,owner_paintable: NodeSlotId::INVALID,- registry_parent_node: VISUAL_VIEWPORT_NODE_INDEX,}),VISUAL_VIEWPORT_NODE_INDEX,);@@ -689,7 +687,6 @@ mod section_dump_tests {SpatialData::Scroll(ScrollData {state_slot: NO_SCROLL_STATE_SLOT,owner_paintable: NodeSlotId::INVALID,- registry_parent_node: VISUAL_VIEWPORT_NODE_INDEX,}),VISUAL_VIEWPORT_NODE_INDEX,);diff --git a/Libraries/LibWeb/Rust/src/painting/visual_context/incremental.rs b/Libraries/LibWeb/Rust/src/painting/visual_context/incremental.rsindex f772792e8ac..fc7d98711b9 100644--- a/Libraries/LibWeb/Rust/src/painting/visual_context/incremental.rs+++ b/Libraries/LibWeb/Rust/src/painting/visual_context/incremental.rs@@ -254,20 +254,20 @@ pub(crate) fn register_scroll_like_node(node_index: SpatialNodeIndex,) -> Option<RegisteredScrollLikeNode> {let index = node_index.0 as usize;- let (is_sticky, owner_paintable, registry_parent_node) = match &tree.spatial_nodes[index].data {- SpatialData::Scroll(scroll) => (false, scroll.owner_paintable, scroll.registry_parent_node),- SpatialData::Sticky(sticky) => (true, sticky.owner_paintable, sticky.registry_parent_node),+ let (owner_paintable, sticky_registry_parent_node) = match &tree.spatial_nodes[index].data {+ SpatialData::Scroll(scroll) => (scroll.owner_paintable, None),+ SpatialData::Sticky(sticky) => (sticky.owner_paintable, Some(sticky.registry_parent_node)),_ => return None,};- let parent_slot = tree.scroll_state_slot_for_node(registry_parent_node);- if is_sticky {+ if let Some(registry_parent_node) = sticky_registry_parent_node {+ let parent_slot = tree.scroll_state_slot_for_node(registry_parent_node);let slot = scroll_state.register_sticky_node(node_index, owner_paintable, parent_slot);if let SpatialData::Sticky(sticky) = &mut tree.spatial_nodes[index].data {sticky.state_slot = slot;}Some(RegisteredScrollLikeNode::Sticky)} else {- let slot = scroll_state.register_scroll_node(node_index, owner_paintable, parent_slot);+ let slot = scroll_state.register_scroll_node(node_index, owner_paintable);if let SpatialData::Scroll(scroll) = &mut tree.spatial_nodes[index].data {scroll.state_slot = slot;}@@ -372,15 +372,18 @@ impl<Arena: PaintableRowsRead> AnchorScrollShiftResolver for WalkAnchorScrollShiself.layout_arena.default_scroll_shift_anchor(slot)}- fn enclosing_scroll_node_index(&self, slot: NodeSlotId) -> SpatialNodeIndex {+ fn spatial_node_index(&self, slot: NodeSlotId) -> SpatialNodeIndex {if let Some(&index) = self.assignment_index_by_slot.get(&slot) {- return self.assignments[index].enclosing_scroll_node_index;+ return self.assignments[index].accumulated_visual_context.spatial;}// A box this pass has not rebuilt keeps the record of the tree being updated. A fresh// tree dropped every record; a box reached there before its own build is only reachable// through a malformed anchor chain and contributes no scroll shift.if self.layout_arena.paintable_visual_context_record(slot).is_some() {- self.layout_arena.paintable_data(slot).enclosing_scroll_node_index+ self.layout_arena+ .paintable_data(slot)+ .accumulated_visual_context+ .spatial} else {VISUAL_VIEWPORT_NODE_INDEX}@@ -497,7 +500,7 @@ pub(crate) fn update_visual_context_tree<Arena: PaintableRowsWrite>(scope.rebuilds_every_box() || plan.revalidate_children_of.contains(&viewport),);- // An anchor-positioned box's scroll shift nodes name its anchor's enclosing scroll node, so+ // An anchor-positioned box's scroll shift nodes name the scroll-like nodes above its anchor, so// the box is built once the stack is drained, after every anchor this pass rebuilds.let defers_anchor_positioned = layout_arena.may_have_default_scroll_shift_anchor();let mut deferred_anchor_positioned: Vec<DeferredAnchorPositionedBox> = Vec::new();diff --git a/Libraries/LibWeb/Rust/src/painting/visual_context/records.rs b/Libraries/LibWeb/Rust/src/painting/visual_context/records.rsindex e2273a4cd80..c4b13f4fd7f 100644--- a/Libraries/LibWeb/Rust/src/painting/visual_context/records.rs+++ b/Libraries/LibWeb/Rust/src/painting/visual_context/records.rs@@ -112,22 +112,15 @@ impl BoxVisualContextNodeHandles {}}-// Nearest ancestor scroll node resolved along the containing block chain, drilled down alongside-// the visual context indices. A fixed-position ancestor decouples its subtree from all outer-// scrollers, but sticky boxes must still reference a scrollport through fixed-position ancestors-// for their sticky offset computation, so both resolutions are carried.-#[derive(Clone, Copy, Debug, PartialEq, Eq)]-pub(crate) struct NearestScrollNodeIndices {- pub stopping_at_fixed_position_ancestors: SpatialNodeIndex,- pub continuing_through_fixed_position_ancestors: SpatialNodeIndex,-}--// One positioning chain; effects are shared by all three chains.+// One positioning chain; effects are shared by all three chains. The nearest scroll-like node is+// what a sticky box sticks to, resolved along the containing block chain: a fixed-position ancestor+// takes its subtree off the spatial chain of outer scrollers, but sticky boxes must still reference+// a scrollport through it for their sticky offset computation.#[derive(Clone, Copy, Debug, PartialEq, Eq)]pub(crate) struct PositioningContext {pub spatial: SpatialNodeIndex,pub clip: ClipNodeIndex,- pub nearest_scroll_nodes: NearestScrollNodeIndices,+ pub nearest_scroll_like_node: SpatialNodeIndex,pub plane_root: SpatialNodeIndex,}diff --git a/Libraries/LibWeb/Rust/src/painting/visual_context/shape.rs b/Libraries/LibWeb/Rust/src/painting/visual_context/shape.rsindex 2485cb1ad5e..e45375b0b7d 100644--- a/Libraries/LibWeb/Rust/src/painting/visual_context/shape.rs+++ b/Libraries/LibWeb/Rust/src/painting/visual_context/shape.rs@@ -10,7 +10,6 @@ use super::*;pub(crate) enum SpatialNodeShape {Scroll {parent: SpatialNodeIndex,- registry_parent_node: SpatialNodeIndex,},Sticky {parent: SpatialNodeIndex,@@ -75,10 +74,7 @@ pub(crate) struct EffectNodeShape {pub(crate) fn spatial_node_shape(node: &SpatialNode) -> SpatialNodeShape {let parent = node.parent;match &node.data {- SpatialData::Scroll(scroll) => SpatialNodeShape::Scroll {- parent,- registry_parent_node: scroll.registry_parent_node,- },+ SpatialData::Scroll(_) => SpatialNodeShape::Scroll { parent },SpatialData::Sticky(sticky) => SpatialNodeShape::Sticky {parent,registry_parent_node: sticky.registry_parent_node,diff --git a/Tests/LibWeb/Text/expected/css/anchor-scroll-shift-in-transformed-and-fixed-chains.txt b/Tests/LibWeb/Text/expected/css/anchor-scroll-shift-in-transformed-and-fixed-chains.txtnew file mode 100644index 00000000000..53f589b2a9a--- /dev/null+++ b/Tests/LibWeb/Text/expected/css/anchor-scroll-shift-in-transformed-and-fixed-chains.txt@@ -0,0 +1,6 @@+absolute, anchor in a scrolled scroller: anchor bottom 160, anchored top 160+fixed, anchor in the scrolled document: anchor bottom 160, anchored top 160+fixed and anchor in a transformed box in a scrolled scroller: anchor bottom 40, anchored top 40+fixed in a transformed box in a scrolled scroller, anchor in an inner scrolled scroller: anchor bottom 60, anchored top 60+absolute in fixed, anchor in sticky in the same fixed, scrolled document: anchor bottom 40, anchored top 40+absolute in fixed, anchor in stuck sticky in a scrolled scroller, scrolled document: anchor bottom 45, anchored top 45diff --git a/Tests/LibWeb/Text/input/css/anchor-scroll-shift-in-transformed-and-fixed-chains.html b/Tests/LibWeb/Text/input/css/anchor-scroll-shift-in-transformed-and-fixed-chains.htmlnew file mode 100644index 00000000000..32f125c8b4d--- /dev/null+++ b/Tests/LibWeb/Text/input/css/anchor-scroll-shift-in-transformed-and-fixed-chains.html@@ -0,0 +1,68 @@+<!DOCTYPE html>+<style>+ html, body { margin: 0; }+ .scroller { overflow: scroll; width: 200px; height: 100px; }+ .tall { height: 1000px; }+ .anchor { anchor-name: --anchor; width: 10px; height: 10px; }+ .anchored { position-anchor: --anchor; top: anchor(bottom); left: anchor(left); width: 10px; height: 10px; }+ .transformed { transform: translate(0, 0); height: 300px; padding-top: 80px; }+</style>+<body>+<div id="stage"></div>+<script src="../include.js"></script>+<script>+ const ANCHOR = `<div class="anchor" id="anchor"></div>`;+ const ANCHORED_ABSOLUTE = `<div class="anchored" id="anchored" style="position: absolute"></div>`;+ const ANCHORED_FIXED = `<div class="anchored" id="anchored" style="position: fixed"></div>`;++ const scenarios = [+ {+ name: "absolute, anchor in a scrolled scroller",+ html: `<div class="scroller" id="a"><div class="tall" style="padding-top: 200px">${ANCHOR}</div></div>${ANCHORED_ABSOLUTE}`,+ scroll: () => { a.scrollTop = 50; },+ },+ {+ name: "fixed, anchor in the scrolled document",+ html: `<div style="height: 3000px; padding-top: 200px">${ANCHOR}</div>${ANCHORED_FIXED}`,+ scroll: () => window.scrollTo(0, 50),+ },+ {+ name: "fixed and anchor in a transformed box in a scrolled scroller",+ html: `<div class="scroller" id="a"><div class="tall"><div class="transformed">${ANCHOR}${ANCHORED_FIXED}</div></div></div>`,+ scroll: () => { a.scrollTop = 50; },+ },+ {+ name: "fixed in a transformed box in a scrolled scroller, anchor in an inner scrolled scroller",+ html: `<div class="scroller" id="a"><div class="tall"><div class="transformed"><div class="scroller" id="b"><div class="tall" style="padding-top: 40px">${ANCHOR}</div></div>${ANCHORED_FIXED}</div></div></div>`,+ scroll: () => { a.scrollTop = 50; b.scrollTop = 20; },+ },+ {+ name: "absolute in fixed, anchor in sticky in the same fixed, scrolled document",+ html: `<div style="height: 3000px"><div style="position: fixed; top: 30px; left: 0; width: 50px; height: 60px"><div style="position: sticky; top: 0">${ANCHOR}</div>${ANCHORED_ABSOLUTE}</div></div>`,+ scroll: () => window.scrollTo(0, 50),+ },+ {+ name: "absolute in fixed, anchor in stuck sticky in a scrolled scroller, scrolled document",+ html: `<div style="height: 3000px"><div style="position: fixed; top: 30px; left: 0; width: 200px; height: 120px"><div class="scroller" id="a"><div class="tall"><div style="height: 30px"></div><div style="position: sticky; top: 5px">${ANCHOR}</div></div></div>${ANCHORED_ABSOLUTE}</div></div>`,+ scroll: () => { a.scrollTop = 80; window.scrollTo(0, 50); },+ },+ ];++ promiseTest(async () => {+ const stage = document.getElementById("stage");+ const results = [];+ for (const scenario of scenarios) {+ stage.innerHTML = scenario.html;+ await animationFrame();+ scenario.scroll();+ await animationFrame();+ await animationFrame();+ const anchorBottom = document.getElementById("anchor").getBoundingClientRect().bottom;+ const anchoredTop = document.getElementById("anchored").getBoundingClientRect().top;+ results.push(`${scenario.name}: anchor bottom ${anchorBottom}, anchored top ${anchoredTop}`);+ stage.innerHTML = "";+ window.scrollTo(0, 0);+ }+ results.forEach(line => println(line));+ });+</script>