Truly independent web browser
LibWeb: Keep the layout arena's pending lists and dirty marks plain
Aliaksandr Kalenik37d577820eac
diff --git a/Libraries/LibWeb/Rust/src/layout/commit.rs b/Libraries/LibWeb/Rust/src/layout/commit.rsindex 2904b9adcc7..85dff34bd20 100644--- a/Libraries/LibWeb/Rust/src/layout/commit.rs+++ b/Libraries/LibWeb/Rust/src/layout/commit.rs@@ -183,10 +183,10 @@ fn commit_subtree(}if !reuses_committed_subtree {paintables.arena_mut().note_subtree_committed_anew(node);- paintables.arena().forget_committed_out_of_flow_facts(node);+ paintables.arena_mut().forget_committed_out_of_flow_facts(node);}if let Some(inputs) = entry.and_then(|link| link.abspos_layout_inputs.as_ref()) {- paintables.arena().note_committed_out_of_flow_box(node, inputs);+ paintables.arena_mut().note_committed_out_of_flow_box(node, inputs);paintables.arena_mut().set_position_option_in_use(node, inputs.position_option);diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rsindex 8fde8a7fb06..b7219fbc0a5 100644--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs@@ -3521,9 +3521,9 @@ impl LayoutStageJob {.note_document_svg_root_natural_size(root_box, natural_size);}notifications.prepend_layout_messages(messages);- let arena = state.arena();- state.layout_scratch().layout_trace.hand_over_to(&arena.layout_trace);- state.layout_scratch().end_layout_pass(arena);+ let (arena, scratch) = state.arena_mut_and_layout_scratch();+ scratch.layout_trace.hand_over_to(&arena.layout_trace);+ scratch.end_layout_pass(arena);arena.reset_layout_update_flags_in_subtree(root);arena.leave_active_layout_pass();match kind {@@ -3635,15 +3635,15 @@ fn compute_root_layout(input: LayoutStageInput<'_>, should_collect_devtools_layo/// Brings the arena up to date for a stage before the stage borrows it: derives the facts its runs read, marks the/// flex and grid items of the nodes marked for layout, and drops the cached intrinsic sizes of released slots.fn prepare_layout_stage(state: &mut super::ArenaHandle, kind: LayoutStageKind, root: NodeSlotId) {- let arena = state.arena();+ let (arena, scratch) = state.arena_mut_and_layout_scratch();match kind {LayoutStageKind::Root { .. } => {// NB: The tree builder derives the facts of rebuilt subtrees. Unclassified invalidations// require deriving them for the entire tree instead.- if arena.pending_updates_escape_partial_relayout.get() {+ if arena.pending_updates_escape_partial_relayout {arena.derive_facts_in_subtree(root);arena.clear_partial_relayout_escape();- arena.pending_attached_subtree_roots.borrow_mut().clear();+ arena.pending_attached_subtree_roots.clear();} else {// NB: Top-layer updates can attach boxes without running the tree builder.arena.derive_facts_after_tree_update(&[]);@@ -3657,16 +3657,16 @@ fn prepare_layout_stage(state: &mut super::ArenaHandle, kind: LayoutStageKind, rarena.derive_facts_in_subtree(root);}}- drop_intrinsic_size_cache_entries_of_released_slots(arena, state.layout_scratch());- state.layout_scratch().apply_memo_invalidations(arena);- arena.layout_trace.hand_over_to(&state.layout_scratch().layout_trace);+ drop_intrinsic_size_cache_entries_of_released_slots(arena, scratch);+ scratch.apply_memo_invalidations(arena);+ arena.layout_trace.hand_over_to(&scratch.layout_trace);arena.begin_active_layout_pass();}/// Drops the intrinsic size cache entries of the slots the arena let go of, or whose cache epoch wrapped, since the/// last stage, before any run of this one reads a cache.fn drop_intrinsic_size_cache_entries_of_released_slots(- arena: &LayoutNodeArena,+ arena: &mut LayoutNodeArena,scratch: &super::run_state::LayoutScratch,) {let drops = arena.take_intrinsic_size_cache_drops();diff --git a/Libraries/LibWeb/Rust/src/layout/host_tables.rs b/Libraries/LibWeb/Rust/src/layout/host_tables.rsindex c0ca9d09c3b..b81b684f53b 100644--- a/Libraries/LibWeb/Rust/src/layout/host_tables.rs+++ b/Libraries/LibWeb/Rust/src/layout/host_tables.rs@@ -177,6 +177,11 @@ impl ArenaHandle {pub(crate) fn arena_mut(&mut self) -> &mut LayoutNodeArena {&mut self.arena}++ /// The arena to write, beside the layout stage's scratch, which the stage reads as it prepares and ends a pass.+ pub(crate) fn arena_mut_and_layout_scratch(&mut self) -> (&mut LayoutNodeArena, &super::run_state::LayoutScratch) {+ (&mut self.arena, &self.layout_scratch)+ }}#[cfg(test)]diff --git a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rsindex 023ce00194c..08a92d47f96 100644--- a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs+++ b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs@@ -1203,14 +1203,14 @@ pub(crate) struct LayoutNodeArena {/// Whether the document is an SVG file decoded as an image, which is fixed for its lifetime.document_is_decoded_svg: bool,/// Depth of synchronous layout passes, including their commits, on the stack.- active_layout_pass_depth: Cell<u32>,+ active_layout_pass_depth: u32,/// The viewport the last layout tree build placed, invalid once that box is freed.layout_root: NodeSlotId,/// The subtree roots the last layout tree build rebuilt, waiting for the partial relayout/// plan that follows it. A full layout pass covers every one of them, so its commit clears/// them.- pending_rebuilt_subtree_roots: RefCell<Vec<NodeSlotId>>,- pending_layout_tree_update_escaped_rebuild_roots: Cell<bool>,+ pending_rebuilt_subtree_roots: Vec<NodeSlotId>,+ pending_layout_tree_update_escaped_rebuild_roots: bool,/// Every box must be recreated by the next layout tree build; set when the tree is torn down/// or a build finds a box it cannot place among rebuilt roots, cleared by the full pass.needs_full_layout_tree_update: bool,@@ -1221,12 +1221,12 @@ pub(crate) struct LayoutNodeArena {committed_subtree_tokens: Vec<u32>,layout_tree_build_stats: FfiLayoutTreeBuildStats,pre_order_labels: Vec<Cell<u64>>,- pre_order_relabel_count: Cell<u64>,+ pre_order_relabel_count: u64,free_list: Vec<u32>,next_index: u32,live_count: u32,/// The slots whose intrinsic size cache entries the layout stage drops before its next run.- intrinsic_size_cache_drops: RefCell<Vec<u32>>,+ intrinsic_size_cache_drops: Vec<u32>,default_scroll_shift_anchors: Vec<DefaultScrollShiftAnchorSlot>,any_default_scroll_shift_anchor_ever_stored: bool,text_slots: TextSlots,@@ -1249,13 +1249,13 @@ pub(crate) struct LayoutNodeArena {// Hit testing can measure overflow and invalidate painting state while querying this list.// Reuse workspace allocations without making recording scratch part of the committed paint state.pub(crate) scrollable_overflow: crate::painting::scrollable_overflow::ScrollableOverflowState,- pub(crate) partial_relayout_boundary_roots: RefCell<super::partial_relayout::PartialRelayoutBoundaryRoots>,- nodes_with_layout_update_flags: RefCell<Vec<NodeSlotId>>,- layout_update_flag_node_indices: RefCell<HashMap<NodeSlotId, usize>>,- pub(super) pending_attached_subtree_roots: RefCell<Vec<NodeSlotId>>,+ pub(crate) partial_relayout_boundary_roots: super::partial_relayout::PartialRelayoutBoundaryRoots,+ nodes_with_layout_update_flags: Vec<NodeSlotId>,+ layout_update_flag_node_indices: HashMap<NodeSlotId, usize>,+ pub(super) pending_attached_subtree_roots: Vec<NodeSlotId>,/// Boxes whose child lists gained children since the last layout tree build, held back from/// layout invalidation until the build shows what the new children are.- pub(crate) deferred_child_list_insertion_parents: RefCell<Vec<(NodeSlotId, NodeSlotId)>>,+ pub(crate) deferred_child_list_insertion_parents: Vec<(NodeSlotId, NodeSlotId)>,/// Layout inputs for new absolutely positioned boxes that the build confined to themselves./// They stand in for the committed inputs such a box does not have yet.pub(crate) confined_abspos_layout_inputs: HashMap<NodeSlotId, AbsposLayoutInputs>,@@ -1265,12 +1265,12 @@ pub(crate) struct LayoutNodeArena {/// https://drafts.csswg.org/css-anchor-position-1/#last-successful-position-optionlast_successful_position_options: HashMap<NodeSlotId, super::abspos_inputs::PositionOptionChoice>,pub(crate) inline_boxes_lifted_out_of: HashMap<NodeSlotId, NodeSlotId>,- pub(crate) out_of_flow_positioning_contained: RefCell<HashMap<NodeSlotId, u32>>,+ pub(crate) out_of_flow_positioning_contained: HashMap<NodeSlotId, u32>,/// Attribution of pending updates for partial relayout. Invariant: every update recorded/// since the last layout pass is either attributed to a boundary in the root set above, or/// this escape bit is set. Partial relayout may only run while the bit is clear; a full/// layout pass re-derives every fact boundary qualification depends on, so it clears the bit.- pub(crate) pending_updates_escape_partial_relayout: Cell<bool>,+ pub(crate) pending_updates_escape_partial_relayout: bool,pub(crate) boxes_needing_scrollable_overflow_recalculation: RefCell<Vec<NodeSlotId>>,pub(crate) needs_full_scrollable_overflow_recalculation: Cell<bool>,text_nodes_enrolled_for_content_sync: HashSet<NodeSlotId>,@@ -1331,10 +1331,10 @@ impl LayoutNodeArena {box_presence_host: Cell::new(None),queued_box_presence: None,document_is_decoded_svg: (false),- active_layout_pass_depth: Cell::new(0),+ active_layout_pass_depth: 0,layout_root: (NodeSlotId::INVALID),- pending_rebuilt_subtree_roots: RefCell::new(Vec::new()),- pending_layout_tree_update_escaped_rebuild_roots: Cell::new(false),+ pending_rebuilt_subtree_roots: Vec::new(),+ pending_layout_tree_update_escaped_rebuild_roots: false,needs_full_layout_tree_update: (false),partial_layout_count: (0),full_layout_count: (0),@@ -1342,11 +1342,11 @@ impl LayoutNodeArena {committed_subtree_tokens: Vec::new(),layout_tree_build_stats: (FfiLayoutTreeBuildStats::default()),pre_order_labels: Vec::new(),- pre_order_relabel_count: Cell::new(0),+ pre_order_relabel_count: 0,free_list: Vec::new(),next_index: 0,live_count: 0,- intrinsic_size_cache_drops: RefCell::new(Vec::new()),+ intrinsic_size_cache_drops: Vec::new(),default_scroll_shift_anchors: Vec::new(),any_default_scroll_shift_anchor_ever_stored: false,text_slots: TextSlots::default(),@@ -1362,17 +1362,17 @@ impl LayoutNodeArena {paintable_rows: crate::painting::paintable_rows::PaintableRowStore::default(),paint_state: RefCell::new(crate::painting::paint_state::PaintState::default()),scrollable_overflow: Default::default(),- partial_relayout_boundary_roots: RefCell::default(),- nodes_with_layout_update_flags: RefCell::new(Vec::new()),- layout_update_flag_node_indices: RefCell::new(HashMap::default()),- pending_attached_subtree_roots: RefCell::new(Vec::new()),- deferred_child_list_insertion_parents: RefCell::new(Vec::new()),+ partial_relayout_boundary_roots: Default::default(),+ nodes_with_layout_update_flags: Vec::new(),+ layout_update_flag_node_indices: HashMap::default(),+ pending_attached_subtree_roots: Vec::new(),+ deferred_child_list_insertion_parents: Vec::new(),confined_abspos_layout_inputs: HashMap::default(),position_options_in_use: (HashMap::default()),last_successful_position_options: (HashMap::default()),inline_boxes_lifted_out_of: HashMap::default(),- out_of_flow_positioning_contained: RefCell::new(HashMap::default()),- pending_updates_escape_partial_relayout: Cell::new(false),+ out_of_flow_positioning_contained: HashMap::default(),+ pending_updates_escape_partial_relayout: false,boxes_needing_scrollable_overflow_recalculation: RefCell::new(Vec::new()),needs_full_scrollable_overflow_recalculation: Cell::new(false),text_nodes_enrolled_for_content_sync: HashSet::default(),@@ -1395,15 +1395,14 @@ impl LayoutNodeArena {/// Drops one node's cached intrinsic sizes outright, for the wrap of its epoch:/// entries are stamped with the epoch they were measured under, so a stamp reused/// after a full lap would match a pre-wrap entry.- pub(crate) fn drop_intrinsic_size_cache(&self, data: &NodeData) {- let (index, _) = self.slot_for_data(data);- self.intrinsic_size_cache_drops.borrow_mut().push(index);+ fn drop_intrinsic_size_cache(&mut self, node: NodeSlotId) {+ self.intrinsic_size_cache_drops.push(node.slot_index());}/// The slots whose intrinsic size cache entries must go, for the layout stage to drop before/// its next run reads any.- pub(crate) fn take_intrinsic_size_cache_drops(&self) -> Vec<u32> {- self.intrinsic_size_cache_drops.take()+ pub(crate) fn take_intrinsic_size_cache_drops(&mut self) -> Vec<u32> {+ std::mem::take(&mut self.intrinsic_size_cache_drops)}pub(crate) fn layout_commit_count(&self) -> u64 {@@ -1415,7 +1414,7 @@ impl LayoutNodeArena {}pub(crate) fn has_intrinsic_size_cache_drops(&self) -> bool {- !self.intrinsic_size_cache_drops.borrow().is_empty()+ !self.intrinsic_size_cache_drops.is_empty()}/// What an intrinsic size cache entry measured for the row `id` now is valid for.@@ -1427,12 +1426,12 @@ impl LayoutNodeArena {}}- pub(crate) fn reset_cached_intrinsic_sizes(&self, node: NodeSlotId) {+ pub(crate) fn reset_cached_intrinsic_sizes(&mut self, node: NodeSlotId) {let data = self.data(node);let bumped_epoch = data.intrinsic_cache_epoch.get().wrapping_add(1);data.intrinsic_cache_epoch.set(bumped_epoch);if bumped_epoch == 0 {- self.drop_intrinsic_size_cache(data);+ self.drop_intrinsic_size_cache(node);}}@@ -1640,8 +1639,8 @@ impl LayoutNodeArena {self.assert_node_is_unlinked_from_parent(root);if self.layout_root == root {self.layout_root = NodeSlotId::INVALID;- self.pending_rebuilt_subtree_roots.get_mut().clear();- self.pending_layout_tree_update_escaped_rebuild_roots.set(false);+ self.pending_rebuilt_subtree_roots.clear();+ self.pending_layout_tree_update_escaped_rebuild_roots = false;}// NB: The root was unlinked through remove_child(), which already noted what its subtree takes out of the// overflow index.@@ -1722,9 +1721,9 @@ impl LayoutNodeArena {self.paintable_row_freed(reset);}self.inline_boxes_lifted_out_of.remove(&id);- self.out_of_flow_positioning_contained.get_mut().remove(&id);+ self.out_of_flow_positioning_contained.remove(&id);self.pre_order_labels[index as usize].set(0);- self.partial_relayout_boundary_roots.get_mut().note_freed(id);+ self.partial_relayout_boundary_roots.note_freed(id);self.metadata_mut(index).occupied = false;self.forget_row_sharing_dom_node(id);self.unbind_row(id);@@ -1734,7 +1733,7 @@ impl LayoutNodeArena {self.style_record_pins[index as usize].set(ArenaStylePin::None);self.style_records_pinned_by_host[index as usize].set(0);- self.intrinsic_size_cache_drops.get_mut().push(index);+ self.intrinsic_size_cache_drops.push(index);if let Some(slot) = self.default_scroll_shift_anchors.get_mut(index as usize) {*slot = DefaultScrollShiftAnchorSlot::default();}@@ -2084,14 +2083,10 @@ impl LayoutNodeArena {id: NodeSlotId,style_node: Option<StyleNodeID>,) {- let mut row = id;- loop {- let next = self.next_rows_built_for_same_node[row.slot_index() as usize].get();+ let mut cursor = Some(id);+ while let Some(row) = cursor {+ cursor = self.next_row_sharing_dom_node_with(id, row);self.set_node_style_node(row, style_node);- if next.is_invalid() || next == id {- break;- }- row = next;}}@@ -2221,7 +2216,7 @@ impl LayoutNodeArena {/// Sets the row's `HasScrollOffset` flag from what it is scrolled to, as a row is stamped,/// bound or unbound, and as the offset it holds changes. The viewport's row is measured eagerly/// anyway, so it never carries the flag.- fn refresh_has_scroll_offset_flag(&self, slot: NodeSlotId) {+ fn refresh_has_scroll_offset_flag(&mut self, slot: NodeSlotId) {let has_scroll_offset = self.data(slot).kind.get() != NodeKind::Viewport&& self.row_scroll_offset(slot) != CssPixelPoint::default();self.set_node_flag(slot, NodeFlag::HasScrollOffset, has_scroll_offset);@@ -2238,7 +2233,7 @@ impl LayoutNodeArena {/// Records what the element has scrolled to, for every row built for it. A rebuild can leave/// an old row and its replacement both built for the element until the commit that retires the/// old one, and both answer for the element meanwhile.- pub(crate) fn set_element_scroll_offset(&self, element: StyleNodeID, offset: CssPixelPoint) {+ pub(crate) fn set_element_scroll_offset(&mut self, element: StyleNodeID, offset: CssPixelPoint) {let previous_offset = {let mut offsets = self.style_node_tables.element_scroll_offsets.borrow_mut();if offset == CssPixelPoint::default() {@@ -2251,16 +2246,16 @@ impl LayoutNodeArena {self.note_scroll_offsets_moved();}let bound_row = self.bound_row(element);- if !bound_row.is_invalid() {- for row in self.rows_sharing_dom_node_with(bound_row) {- self.refresh_has_scroll_offset_flag(row);- }+ let mut cursor = (!bound_row.is_invalid()).then_some(bound_row);+ while let Some(row) = cursor {+ cursor = self.next_row_sharing_dom_node_with(bound_row, row);+ self.refresh_has_scroll_offset_flag(row);}}/// Records what the pseudo-element of kind `generated_for` on `generator` has scrolled to.pub(crate) fn set_pseudo_element_scroll_offset(- &self,+ &mut self,generator: StyleNodeID,generated_for: u8,offset: CssPixelPoint,@@ -2876,7 +2871,7 @@ impl LayoutNodeArena {/// again, so the relayout of one of them does not finish as a partial relayout. A relayout of an absolutely/// positioned partial relayout boundary stays confined to it, as the box contributes nothing to ancestor layout;/// a rendered ::backdrop keeps it from being confined, as its box is the element box's sibling.- fn mark_row_for_relayout_after_style_change(&self, style_node: StyleNodeID, slot: NodeSlotId) {+ fn mark_row_for_relayout_after_style_change(&mut self, style_node: StyleNodeID, slot: NodeSlotId) {let viewport_propagation_source =self.data(slot).flags.get() & (NodeFlag::IsDocumentElement as u32 | NodeFlag::IsBody as u32) != 0;if viewport_propagation_source {@@ -3052,19 +3047,18 @@ impl LayoutNodeArena {/// values must never be replaced in that window: the pass caches decoded style and borrows/// payload pointers that a replacement would invalidate under it.pub(crate) fn layout_pass_is_running(&self) -> bool {- self.active_layout_pass_depth.get() > 0+ self.active_layout_pass_depth > 0}- pub(crate) fn begin_active_layout_pass(&self) {- self.active_layout_pass_depth- .set(self.active_layout_pass_depth.get() + 1);+ pub(crate) fn begin_active_layout_pass(&mut self) {+ self.active_layout_pass_depth += 1;}/// Leaves a pass, and answers whether it was the outermost one.- pub(crate) fn leave_active_layout_pass(&self) -> bool {- let depth = self.active_layout_pass_depth.get();+ pub(crate) fn leave_active_layout_pass(&mut self) -> bool {+ let depth = self.active_layout_pass_depth;assert!(depth > 0, "layout pass depth underflow");- self.active_layout_pass_depth.set(depth - 1);+ self.active_layout_pass_depth = depth - 1;depth == 1}@@ -3132,35 +3126,33 @@ impl LayoutNodeArena {}pub(crate) fn set_pending_rebuilt_subtree_roots(- &self,+ &mut self,roots: Vec<NodeSlotId>,layout_tree_update_escaped_rebuild_roots: bool,) {- *self.pending_rebuilt_subtree_roots.borrow_mut() = roots;- self.pending_layout_tree_update_escaped_rebuild_roots- .set(layout_tree_update_escaped_rebuild_roots);+ self.pending_rebuilt_subtree_roots = roots;+ self.pending_layout_tree_update_escaped_rebuild_roots = layout_tree_update_escaped_rebuild_roots;}- pub(crate) fn take_pending_rebuilt_subtree_roots(&self) -> (Vec<NodeSlotId>, bool) {+ pub(crate) fn take_pending_rebuilt_subtree_roots(&mut self) -> (Vec<NodeSlotId>, bool) {(- std::mem::take(&mut *self.pending_rebuilt_subtree_roots.borrow_mut()),- self.pending_layout_tree_update_escaped_rebuild_roots.replace(false),+ std::mem::take(&mut self.pending_rebuilt_subtree_roots),+ std::mem::replace(&mut self.pending_layout_tree_update_escaped_rebuild_roots, false),)}/// The DOM nodes the subtrees the last build rebuilt and left live stand for. An anonymous root stands for none.pub(crate) fn pending_rebuilt_dom_roots(&self) -> Vec<crate::painting::host::FfiNodeIdentity> {self.pending_rebuilt_subtree_roots- .borrow().iter().filter(|&&root| self.node_is_dom_backed(root)).map(|&root| crate::painting::hit_test::resolve::row_node_identity(self, root, false)).collect()}- pub(crate) fn clear_pending_rebuilt_subtree_roots(&self) {- self.pending_rebuilt_subtree_roots.borrow_mut().clear();- self.pending_layout_tree_update_escaped_rebuild_roots.set(false);+ pub(crate) fn clear_pending_rebuilt_subtree_roots(&mut self) {+ self.pending_rebuilt_subtree_roots.clear();+ self.pending_layout_tree_update_escaped_rebuild_roots = false;}pub(crate) fn note_partial_layout(&mut self) {@@ -3863,7 +3855,7 @@ impl LayoutNodeArena {NodeSlotId::INVALID}- fn derive_containing_block_establishment_flags(&self, node: NodeSlotId) {+ fn derive_containing_block_establishment_flags(&mut self, node: NodeSlotId) {let data = self.write_shape(node);let previous_flags = data.flags.get();let (absolute, fixed) = if data.kind.get() == NodeKind::InlineNode {@@ -3894,7 +3886,6 @@ impl LayoutNodeArena {let releases_contained_boxes = lost != 0&& self.out_of_flow_positioning_contained- .borrow().get(&node).is_some_and(|contained| contained & lost != 0);if !catches_escaping_boxes && !releases_contained_boxes {@@ -3911,7 +3902,7 @@ impl LayoutNodeArena {PaintRead::node_containing_block_if_live(self, node).unwrap_or(NodeSlotId::INVALID)}- fn mark_nodes_escaped_by_out_of_flow_box(&self, node: NodeSlotId, containing_block: NodeSlotId) {+ fn mark_nodes_escaped_by_out_of_flow_box(&mut self, node: NodeSlotId, containing_block: NodeSlotId) {if let Some(inline_box) = self.inline_box_lifted_out_of(node) {let mut inline_ancestor = inline_box;while !inline_ancestor.is_invalid() && self.data(inline_ancestor).kind.get() == NodeKind::InlineNode {@@ -3926,7 +3917,7 @@ impl LayoutNodeArena {}}- fn mark_nodes_escaped_by_attached_out_of_flow_box(&self, node: NodeSlotId) {+ fn mark_nodes_escaped_by_attached_out_of_flow_box(&mut self, node: NodeSlotId) {if !super::node_facts::kind_is_box(self.data(node).kind.get())|| !self.node_style_if_live(node)@@ -3938,21 +3929,21 @@ impl LayoutNodeArena {self.mark_nodes_escaped_by_out_of_flow_box(node, containing_block);}- pub(crate) fn forget_committed_out_of_flow_facts(&self, node: NodeSlotId) {+ pub(crate) fn forget_committed_out_of_flow_facts(&mut self, node: NodeSlotId) {let data = self.write_shape(node);data.set_flags(data.flags.get() & !(NodeFlag::AbsposDescendantEscapes as u32));- let mut contained = self.out_of_flow_positioning_contained.borrow_mut();+ let contained = &mut self.out_of_flow_positioning_contained;if !contained.is_empty() {contained.remove(&node);}}- pub(crate) fn note_committed_out_of_flow_box(&self, node: NodeSlotId, inputs: &AbsposLayoutInputs) {+ pub(crate) fn note_committed_out_of_flow_box(&mut self, node: NodeSlotId, inputs: &AbsposLayoutInputs) {let positioning = super::node_facts::containing_block_establishment_flag(crate::painting::style_queries::is_fixed_position(self, node),) as u32;{- let mut contained = self.out_of_flow_positioning_contained.borrow_mut();+ let contained = &mut self.out_of_flow_positioning_contained;*contained.entry(inputs.containing_block).or_default() |= positioning;if !inputs.inline_containing_block.is_invalid() {*contained.entry(inputs.inline_containing_block).or_default() |=@@ -3962,14 +3953,19 @@ impl LayoutNodeArena {self.mark_nodes_escaped_by_out_of_flow_box(node, inputs.containing_block);}- fn derive_containing_block_establishment_flags_of_children(&self, parent: NodeSlotId) {- self.for_each_node_in_layout_subtree_in_pre_order_with_pruning(parent, |node| {- if node == parent {- return true;- }- self.derive_containing_block_establishment_flags(node);- super::node_facts::has_flag(self.data(node), NodeFlag::Anonymous)- });+ fn derive_containing_block_establishment_flags_of_children(&mut self, parent: NodeSlotId) {+ let mut cursor = Some(parent);+ while let Some(node) = cursor {+ let descend_into_children = node == parent || {+ self.derive_containing_block_establishment_flags(node);+ super::node_facts::has_flag(self.data(node), NodeFlag::Anonymous)+ };+ cursor = if descend_into_children {+ self.next_node_in_layout_subtree_in_pre_order(parent, node)+ } else {+ self.next_node_after_layout_subtree_in_pre_order(parent, node)+ };+ }}pub(crate) fn hover_frame_style_records(&self) -> Vec<u64> {@@ -3984,21 +3980,20 @@ impl LayoutNodeArena {records}- pub(crate) fn refresh_style_flags(&self, slot: NodeSlotId) {+ pub(crate) fn refresh_style_flags(&mut self, slot: NodeSlotId) {let style = self.node_style_if_live(slot).expect("styled layout node");+ let has_anchor_names = !style.anchor().anchor_names.as_slice().is_empty();+ let has_preserve_3d_transform_style =+ style.transform().transform_style == crate::css::css_enums::transform_style::PRESERVE_3D;let had_preserve_3d_transform_style =super::node_facts::has_flag(self.data(slot), NodeFlag::HasPreserve3dTransformStyle);- self.set_node_flag(- slot,- NodeFlag::HasAnchorNames,- !style.anchor().anchor_names.as_slice().is_empty(),- );+ self.set_node_flag(slot, NodeFlag::HasAnchorNames, has_anchor_names);self.refresh_insets_use_anchor_functions_flag(slot);self.set_node_flag(slot, NodeFlag::HasAnimatedOpacityOrTransform, false);self.set_node_flag(slot,NodeFlag::HasPreserve3dTransformStyle,- style.transform().transform_style == crate::css::css_enums::transform_style::PRESERVE_3D,+ has_preserve_3d_transform_style,);if !self.data(slot).parent.get().is_invalid() || self.data(slot).kind.get() == NodeKind::Viewport {self.derive_containing_block_establishment_flags(slot);@@ -4032,8 +4027,8 @@ impl LayoutNodeArena {/// Marks the flex and grid items among the nodes marked for layout and their children, ahead of the layout that/// lays them out: a style change can make a box, or the children of a box, items without rebuilding them.- pub(crate) fn mark_flex_and_grid_items_of_nodes_marked_for_layout(&self) {- let nodes = self.nodes_with_layout_update_flags.borrow().clone();+ pub(crate) fn mark_flex_and_grid_items_of_nodes_marked_for_layout(&mut self) {+ let nodes = self.nodes_with_layout_update_flags.clone();for node in nodes {if !self.slot_is_live(node) {continue;@@ -4219,7 +4214,7 @@ impl LayoutNodeArena {self.enroll_node_for_replaced_content_facts_sync_if_eligible(slot);}- pub(crate) fn refresh_insets_use_anchor_functions_flag(&self, slot: NodeSlotId) {+ pub(crate) fn refresh_insets_use_anchor_functions_flag(&mut self, slot: NodeSlotId) {let insets_use_anchor_functions = self.style_payloads(slot).is_some_and(|payloads| {super::node_facts::style_insets_use_anchor_functions(ComputedValuesView::new(&payloads.groups))});@@ -4510,12 +4505,18 @@ impl LayoutNodeArena {let mut row = Some(id);std::iter::from_fn(move || {let current = row?;- let next = self.next_rows_built_for_same_node[current.slot_index() as usize].get();- row = (!next.is_invalid() && next != id).then_some(next);+ row = self.next_row_sharing_dom_node_with(id, current);Some(current)})}+ /// The row after `current` in the ring of rows built for the DOM node of `first`, or none once the ring comes+ /// back to `first`. A walk that writes each row it visits reads the next one with this before the write.+ pub(crate) fn next_row_sharing_dom_node_with(&self, first: NodeSlotId, current: NodeSlotId) -> Option<NodeSlotId> {+ let next = self.next_rows_built_for_same_node[current.slot_index() as usize].get();+ (!next.is_invalid() && next != first).then_some(next)+ }+fn forget_row_sharing_dom_node(&mut self, id: NodeSlotId) {let successor = self.next_rows_built_for_same_node[id.slot_index() as usize].replace(NodeSlotId::INVALID);if successor.is_invalid() {@@ -4545,9 +4546,8 @@ impl LayoutNodeArena {self.replace_bound_row(node, id, successor);}- pub(crate) fn set_node_flag(&self, id: NodeSlotId, flag: NodeFlag, value: bool) {- let data = self.write_shape(id);- let previous = data.flags.get();+ pub(crate) fn set_node_flag(&mut self, id: NodeSlotId, flag: NodeFlag, value: bool) {+ let previous = self.data(id).flags.get();let mut updated = previous;if value {updated |= flag as u32;@@ -4556,13 +4556,10 @@ impl LayoutNodeArena {}if value&& matches!(flag, NodeFlag::NeedsLayoutUpdate | NodeFlag::NeedsOwnGeometryUpdate)- && data.flags.get() & (NodeFlag::NeedsLayoutUpdate as u32 | NodeFlag::NeedsOwnGeometryUpdate as u32) == 0+ && previous & (NodeFlag::NeedsLayoutUpdate as u32 | NodeFlag::NeedsOwnGeometryUpdate as u32) == 0{- let mut nodes = self.nodes_with_layout_update_flags.borrow_mut();- let previous = self- .layout_update_flag_node_indices- .borrow_mut()- .insert(id, nodes.len());+ let nodes = &mut self.nodes_with_layout_update_flags;+ let previous = self.layout_update_flag_node_indices.insert(id, nodes.len());debug_assert!(previous.is_none());nodes.push(id);} else if !value@@ -4571,7 +4568,7 @@ impl LayoutNodeArena {{self.remove_layout_update_flag_node(id);}- data.set_flags(updated);+ self.write_shape(id).set_flags(updated);// A box that becomes a flex or grid item can lay out to the fragment it committed before, but orders its// painting differently, so its committed geometry no longer lets its commit be skipped.if matches!(flag, NodeFlag::IsFlexItem | NodeFlag::IsGridItem) && updated != previous {@@ -4627,13 +4624,26 @@ impl LayoutNodeArena {&self,root: NodeSlotId,current: NodeSlotId,+ ) -> Option<NodeSlotId> {+ let first_child = self+ .slot_is_live(current)+ .then(|| self.data(current).first_child.get())?;+ if !first_child.is_invalid() {+ return Some(first_child);+ }+ self.next_node_after_layout_subtree_in_pre_order(root, current)+ }++ /// The node a pre-order walk of the layout subtree under `root` visits after the subtree of `current`, for a walk+ /// that skips the children of `current`.+ pub(crate) fn next_node_after_layout_subtree_in_pre_order(+ &self,+ root: NodeSlotId,+ current: NodeSlotId,) -> Option<NodeSlotId> {let valid = |link: NodeSlotId| (!link.is_invalid()).then_some(link);let mut current = current;let mut data = self.slot_is_live(current).then(|| self.data(current))?;- if let Some(first_child) = valid(data.first_child.get()) {- return Some(first_child);- }while current != root {if let Some(next_sibling) = valid(data.next_sibling.get()) {return Some(next_sibling);@@ -4648,28 +4658,30 @@ impl LayoutNodeArena {None}- fn remove_layout_update_flag_node(&self, node: NodeSlotId) {- let mut indices = self.layout_update_flag_node_indices.borrow_mut();+ fn remove_layout_update_flag_node(&mut self, node: NodeSlotId) {+ let indices = &mut self.layout_update_flag_node_indices;let Some(index) = indices.remove(&node) else {return;};- let mut nodes = self.nodes_with_layout_update_flags.borrow_mut();+ let nodes = &mut self.nodes_with_layout_update_flags;nodes.swap_remove(index);if let Some(&moved_node) = nodes.get(index) {*indices.get_mut(&moved_node).unwrap() = index;}}- pub(crate) fn reset_layout_update_flags_in_subtree(&self, root: NodeSlotId) {+ pub(crate) fn reset_layout_update_flags_in_subtree(&mut self, root: NodeSlotId) {let flags_to_clear = NodeFlag::NeedsLayoutUpdate as u32 | NodeFlag::NeedsOwnGeometryUpdate as u32;if self.data(root).kind.get() != NodeKind::Viewport {// NB: A partial-relayout batch commits each independent boundary separately.// Scanning the document's dirty list per boundary would make cleanup quadratic.- self.for_each_node_in_layout_subtree_in_pre_order(root, |node| {+ let mut cursor = Some(root);+ while let Some(node) = cursor {let data = self.write_shape(node);data.set_flags(data.flags.get() & !flags_to_clear);self.remove_layout_update_flag_node(node);- });+ cursor = self.next_node_in_layout_subtree_in_pre_order(root, node);+ }return;}@@ -4680,10 +4692,7 @@ impl LayoutNodeArena {membership.insert(NodeSlotId::INVALID, false);let mut ancestors = Vec::new();let mut index = 0;- loop {- let Some(node) = self.nodes_with_layout_update_flags.borrow().get(index).copied() else {- break;- };+ while let Some(node) = self.nodes_with_layout_update_flags.get(index).copied() {let mut ancestor = node;while !membership.contains_key(&ancestor) {ancestors.push(ancestor);@@ -4762,16 +4771,16 @@ impl LayoutNodeArena {}/// Returns every attached subtree root the derivation visited.- pub(crate) fn derive_facts_after_tree_update(&self, rebuilt_roots: &[NodeSlotId]) -> HashSet<NodeSlotId> {+ pub(crate) fn derive_facts_after_tree_update(&mut self, rebuilt_roots: &[NodeSlotId]) -> HashSet<NodeSlotId> {// NB: Anonymous wrappers, generated content, and table fixup can attach nodes// outside the builder's reported rebuild roots. Include every attached subtree.- let mut pending = self.pending_attached_subtree_roots.borrow_mut();+ let mut pending = std::mem::take(&mut self.pending_attached_subtree_roots);let roots: HashSet<_> = pending.drain(..).chain(rebuilt_roots.iter().copied()).filter(|&root| self.slot_is_live(root)).collect();- drop(pending);+ self.pending_attached_subtree_roots = pending;for &root in &roots {let mut ancestor = self.data(root).parent.get();if ancestor.is_invalid() && self.data(root).kind.get() != NodeKind::Viewport {@@ -4795,18 +4804,20 @@ impl LayoutNodeArena {/// Derives what the nodes in the inclusive subtree of `root` take from their ancestors: whether they/// establish containing blocks, and their ancestor facts, which the pre-order walk finds already derived/// for the parent. Out-of-flow boxes in the subtree also mark the ancestors they escape.- pub(crate) fn derive_facts_in_subtree(&self, root: NodeSlotId) {- self.for_each_node_in_layout_subtree_in_pre_order(root, |node| {+ pub(crate) fn derive_facts_in_subtree(&mut self, root: NodeSlotId) {+ let mut cursor = Some(root);+ while let Some(node) = cursor {self.derive_containing_block_establishment_flags(node);self.mark_nodes_escaped_by_attached_out_of_flow_box(node);self.derive_ancestor_facts_for_node(node);self.mark_flex_or_grid_item(node);- });+ cursor = self.next_node_in_layout_subtree_in_pre_order(root, node);+ }}/// Marks `node` as a flex or grid item once its parent lays it out as one, as its parent's run would: an in-flow/// box that is not an anonymous run of collapsible whitespace. The mark is never taken back.- pub(crate) fn mark_flex_or_grid_item(&self, node: NodeSlotId) {+ pub(crate) fn mark_flex_or_grid_item(&mut self, node: NodeSlotId) {let data = self.data(node);let parent = data.parent.get();if parent.is_invalid() || !super::node_facts::kind_is_box(data.kind.get()) {@@ -4903,7 +4914,7 @@ impl LayoutNodeArena {}pub(crate) fn pre_order_relabel_count(&self) -> u64 {- self.pre_order_relabel_count.get()+ self.pre_order_relabel_count}pub(crate) fn count_nodes_in_layout_subtree(&self, root: NodeSlotId) -> u64 {@@ -4938,7 +4949,7 @@ impl LayoutNodeArena {}}- fn assign_pre_order_labels_to_inserted_subtree(&self, parent: NodeSlotId, child: NodeSlotId) {+ fn assign_pre_order_labels_to_inserted_subtree(&mut self, parent: NodeSlotId, child: NodeSlotId) {let child_data = self.data(child);let (previous_sibling, next_sibling) = { (child_data.previous_sibling.get(), child_data.next_sibling.get()) };let lower = if previous_sibling.is_invalid() {@@ -4990,7 +5001,7 @@ impl LayoutNodeArena {}fn spread_pre_order_labels_evenly_over_descendants(- &self,+ &mut self,subtree_root: NodeSlotId,lower: u64,upper: u64,@@ -5015,7 +5026,7 @@ impl LayoutNodeArena {position_in_subtree += 1;self.set_node_pre_order_label(node, lower + step * position_in_subtree);});- self.pre_order_relabel_count.set(self.pre_order_relabel_count.get() + 1);+ self.pre_order_relabel_count += 1;true}@@ -5649,7 +5660,7 @@ impl LayoutNodeArena {self.invalidate_at_and_above(node, AncestorInvalidation::ContentChange);}- pub(crate) fn insert_child(&self, parent: NodeSlotId, child: NodeSlotId, before: NodeSlotId) {+ pub(crate) fn insert_child(&mut self, parent: NodeSlotId, child: NodeSlotId, before: NodeSlotId) {assert_ne!(parent, child, "a layout node cannot become its own child");let parent_data = self.write_shape(parent);let child_data = self.write_shape(child);@@ -5713,12 +5724,12 @@ impl LayoutNodeArena {self.assign_pre_order_labels_to_inserted_subtree(parent, child);self.note_layout_subtree_attached(child);- self.pending_attached_subtree_roots.borrow_mut().push(child);+ self.pending_attached_subtree_roots.push(child);self.note_overflow_contained_boxes_may_move_with_subtree(child);self.note_structural_change_at_and_above(parent);}- pub(crate) fn remove_child(&self, parent: NodeSlotId, child: NodeSlotId) {+ pub(crate) fn remove_child(&mut self, parent: NodeSlotId, child: NodeSlotId) {if self.paintable_row_count() > 0 {self.push_enclosing_paint_order_damage(child);}@@ -7289,19 +7300,19 @@ mod tests {arena.reset_layout_update_flags_in_subtree(boundary.slot);assert_eq!(arena.data(boundary.slot).flags.get(), 0);assert_eq!(arena.data(child.slot).flags.get(), 0);- assert_eq!(arena.nodes_with_layout_update_flags.borrow().len(), (31 - index) * 2);- assert_eq!(arena.layout_update_flag_node_indices.borrow().len(), (31 - index) * 2);+ assert_eq!(arena.nodes_with_layout_update_flags.len(), (31 - index) * 2);+ assert_eq!(arena.layout_update_flag_node_indices.len(), (31 - index) * 2);// Re-enrollment after removal must not leave duplicates or stale indices.arena.set_node_flag(child.slot, NodeFlag::NeedsLayoutUpdate, true);arena.set_node_flag(child.slot, NodeFlag::NeedsLayoutUpdate, false);}- assert!(arena.nodes_with_layout_update_flags.borrow().is_empty());+ assert!(arena.nodes_with_layout_update_flags.is_empty());arena.set_node_flag(boundaries[0].0.slot, NodeFlag::NeedsLayoutUpdate, true);arena.free_subtree(viewport.slot).destroy_shells_and_invoke_callbacks(&crate::stage::MainThread::for_test());- assert!(arena.nodes_with_layout_update_flags.borrow().is_empty());- assert!(arena.layout_update_flag_node_indices.borrow().is_empty());+ assert!(arena.nodes_with_layout_update_flags.is_empty());+ assert!(arena.layout_update_flag_node_indices.is_empty());}#[test]@@ -7330,7 +7341,7 @@ mod tests {index >= 64);}- assert_eq!(arena.nodes_with_layout_update_flags.borrow().len(), 64);+ assert_eq!(arena.nodes_with_layout_update_flags.len(), 64);arena.free_subtree(viewport.slot).destroy_shells_and_invoke_callbacks(&crate::stage::MainThread::for_test());diff --git a/Libraries/LibWeb/Rust/src/layout/partial_relayout.rs b/Libraries/LibWeb/Rust/src/layout/partial_relayout.rsindex 94032f501b4..38be754dcb6 100644--- a/Libraries/LibWeb/Rust/src/layout/partial_relayout.rs+++ b/Libraries/LibWeb/Rust/src/layout/partial_relayout.rs@@ -71,7 +71,7 @@ impl LayoutNodeArena {/// anonymous siblings; otherwise a node under an anonymous parent escalates the rebuild/// to the nearest non-anonymous ancestor.pub(crate) fn classify_layout_tree_update(- &self,+ &mut self,node: NodeSlotId,reason_is_structural_boundary_self_rebuild: bool,) -> LayoutTreeUpdateClassification {@@ -208,10 +208,10 @@ impl LayoutNodeArena {)}- pub(crate) fn register_partial_relayout_boundary_root(&self, node: NodeSlotId) {+ pub(crate) fn register_partial_relayout_boundary_root(&mut self, node: NodeSlotId) {let kind = self.data(node).kind.get();assert!(node_facts::kind_is_box(kind));- let mut roots = self.partial_relayout_boundary_roots.borrow_mut();+ let mut roots = std::mem::take(&mut self.partial_relayout_boundary_roots);if roots.freed != 0 {roots.roots.retain(|candidate| self.slot_is_live(*candidate));roots.registered.retain(|candidate| self.slot_is_live(*candidate));@@ -220,26 +220,27 @@ impl LayoutNodeArena {if roots.registered.insert(node) {roots.roots.push(node);}+ self.partial_relayout_boundary_roots = roots;}/// Counts stale entries for freed nodes on purpose: the C++ side treats a nonempty/// root set as "layout is not up to date", and a freed boundary still attributes a/// pending update, exactly as a nulled-out weak pointer did.pub(crate) fn has_partial_relayout_boundary_roots(&self) -> bool {- !self.partial_relayout_boundary_roots.borrow().roots.is_empty()+ !self.partial_relayout_boundary_roots.roots.is_empty()}- pub(crate) fn take_partial_relayout_boundary_roots(&self) -> Vec<NodeSlotId> {- std::mem::take(&mut *self.partial_relayout_boundary_roots.borrow_mut()).roots+ pub(crate) fn take_partial_relayout_boundary_roots(&mut self) -> Vec<NodeSlotId> {+ std::mem::take(&mut self.partial_relayout_boundary_roots).roots}- pub(crate) fn record_partial_relayout_escape(&self) {- self.pending_updates_escape_partial_relayout.set(true);+ pub(crate) fn record_partial_relayout_escape(&mut self) {+ self.pending_updates_escape_partial_relayout = true;self.set_needs_full_scrollable_overflow_recalculation();}- pub(crate) fn clear_partial_relayout_escape(&self) {- self.pending_updates_escape_partial_relayout.set(false);+ pub(crate) fn clear_partial_relayout_escape(&mut self) {+ self.pending_updates_escape_partial_relayout = false;}pub(crate) fn node_needs_layout_update(&self, node: NodeSlotId) -> bool {@@ -249,7 +250,7 @@ impl LayoutNodeArena {/// Plans a partial relayout against the subtree roots the last layout tree build left/// pending, consuming them.pub(crate) fn plan_partial_relayout_with_pending_rebuilt_roots(- &self,+ &mut self,root: NodeSlotId,registered_root_slots: &[NodeSlotId],) -> Option<Vec<PlannedBoundary>> {@@ -274,8 +275,8 @@ impl LayoutNodeArena {) -> bool {!(root.is_invalid()|| self.needs_full_layout_tree_update()- || self.pending_updates_escape_partial_relayout.get()- || (registered_root_slots.is_empty() && self.deferred_child_list_insertion_parents.borrow().is_empty())+ || self.pending_updates_escape_partial_relayout+ || (registered_root_slots.is_empty() && self.deferred_child_list_insertion_parents.is_empty())|| self.node_needs_layout_update(root)|| facts.container_query_evaluation_is_pending|| facts.should_collect_devtools_layout_data)@@ -285,14 +286,14 @@ impl LayoutNodeArena {/// escape bit either way: a refusal here is followed by a full layout pass in the same/// update, which re-derives every fact the bit stands in for.pub(crate) fn plan_partial_relayout(- &self,+ &mut self,root: NodeSlotId,registered_root_slots: &[NodeSlotId],rebuilt_subtree_root_slots: &[NodeSlotId],layout_tree_update_escaped_rebuild_roots: bool,) -> Option<Vec<PlannedBoundary>> {- let pending_updates_escaped =- self.pending_updates_escape_partial_relayout.replace(false) || layout_tree_update_escaped_rebuild_roots;+ let pending_updates_escaped = std::mem::replace(&mut self.pending_updates_escape_partial_relayout, false)+ || layout_tree_update_escaped_rebuild_roots;if pending_updates_escaped {self.set_needs_full_scrollable_overflow_recalculation();}@@ -473,11 +474,9 @@ impl LayoutNodeArena {/// Hold back the layout invalidation of a box whose child list gained children until the/// layout tree build has attached them.- pub(crate) fn defer_child_list_insertion_layout_update(&self, parent: NodeSlotId) {+ pub(crate) fn defer_child_list_insertion_layout_update(&mut self, parent: NodeSlotId) {let grandparent = self.data(parent).parent.get();- self.deferred_child_list_insertion_parents- .borrow_mut()- .push((parent, grandparent));+ self.deferred_child_list_insertion_parents.push((parent, grandparent));}/// Invalidate what the children attached by a layout tree build reach. `attached_roots` are the@@ -493,7 +492,7 @@ impl LayoutNodeArena {attached_roots: &crate::css::style::fast_hash::FastSet<NodeSlotId>,) {self.confined_abspos_layout_inputs.clear();- let mut parents = std::mem::take(&mut *self.deferred_child_list_insertion_parents.borrow_mut());+ let mut parents = std::mem::take(&mut self.deferred_child_list_insertion_parents);parents.sort_unstable_by_key(|(parent, _)| parent.index);parents.dedup_by_key(|(parent, _)| *parent);for (parent, grandparent) in parents {@@ -664,7 +663,7 @@ impl LayoutNodeArena {/// An absolutely positioned child is leaving `parent`, which is its containing block./// Unless the removed subtree affects anchor positioning, only the cached runs that still/// describe it and the scrollable overflow it contributed to are invalidated.- pub(crate) fn note_contained_abspos_child_removal(&self, parent: NodeSlotId, child: NodeSlotId) {+ pub(crate) fn note_contained_abspos_child_removal(&mut self, parent: NodeSlotId, child: NodeSlotId) {let parent_data = self.data(parent);if !node_facts::kind_is_box(parent_data.kind.get())|| !self.paintable_rows().paintable_row_is_populated(parent)@@ -695,7 +694,7 @@ impl LayoutNodeArena {self.push_paint_damage(parent, damage);}- pub(crate) fn reset_cached_intrinsic_sizes_of_self_and_ancestors(&self, node: NodeSlotId) {+ pub(crate) fn reset_cached_intrinsic_sizes_of_self_and_ancestors(&mut self, node: NodeSlotId) {let node_kind = self.data(node).kind.get();if node_facts::kind_is_box(node_kind) {self.reset_cached_intrinsic_sizes(node);@@ -704,7 +703,7 @@ impl LayoutNodeArena {}// Reset intrinsic size caches for ancestors up to abspos or SVG root boundary.- fn reset_cached_intrinsic_sizes_of_ancestors(&self, node: NodeSlotId) {+ fn reset_cached_intrinsic_sizes_of_ancestors(&mut self, node: NodeSlotId) {let mut ancestor = self.data(node).parent.get();while !ancestor.is_invalid() {if node_facts::kind_is_box(self.data(ancestor).kind.get()) {@@ -728,7 +727,7 @@ impl LayoutNodeArena {.is_some_and(|style| style.is_absolutely_positioned())}- pub(crate) fn set_needs_layout_update(&self, node: NodeSlotId, propagate_through_ancestors: bool) {+ pub(crate) fn set_needs_layout_update(&mut self, node: NodeSlotId, propagate_through_ancestors: bool) {self.invalidate_one(node, AncestorInvalidation::ContentChange);let data = self.data(node);@@ -1049,7 +1048,7 @@ mod tests {arena.set_style_node_for_test(grandparent.slot, StyleNodeID::from_raw(7));let classification = arena.classify_layout_tree_update(child.slot, false);- assert!(!arena.pending_updates_escape_partial_relayout.get());+ assert!(!arena.pending_updates_escape_partial_relayout);assert!(!classification.marks_partial_relayout_boundary_self_only);assert_eq!(classification.escalation_target, Some(7));@@ -1057,7 +1056,7 @@ mod tests {assert_eq!(parent_classification.escalation_target, None);arena.classify_layout_tree_update(grandparent.slot, false);- assert!(arena.pending_updates_escape_partial_relayout.get());+ assert!(arena.pending_updates_escape_partial_relayout);free_node(&mut arena, &grandparent);}@@ -1090,7 +1089,7 @@ mod tests {assert!(!arena.partial_relayout_may_be_attempted(parent.slot, ®istered, facts));assert_eq!(arena.plan_partial_relayout(parent.slot, ®istered, &[], false), None);- assert!(!arena.pending_updates_escape_partial_relayout.get());+ assert!(!arena.pending_updates_escape_partial_relayout);assert!(arena.partial_relayout_may_be_attempted(parent.slot, ®istered, facts));free_node(&mut arena, &parent);}@@ -1099,7 +1098,7 @@ mod tests {fn planning_refuses_when_the_build_escaped_its_rebuild_roots() {let (mut arena, parent, registered) = arena_with_a_registered_child_root();assert_eq!(arena.plan_partial_relayout(parent.slot, ®istered, &[], true), None);- assert!(!arena.pending_updates_escape_partial_relayout.get());+ assert!(!arena.pending_updates_escape_partial_relayout);free_node(&mut arena, &parent);}diff --git a/Libraries/LibWeb/Rust/src/layout/tree_builder.rs b/Libraries/LibWeb/Rust/src/layout/tree_builder.rsindex b8db7da69e0..d1a22f416ad 100644--- a/Libraries/LibWeb/Rust/src/layout/tree_builder.rs+++ b/Libraries/LibWeb/Rust/src/layout/tree_builder.rs@@ -2390,7 +2390,7 @@ fn construct_principal_layout_node(update.state.layout_tree_update_escaped_rebuild_roots = true;let backdrop_parent = host.parent(old_backdrop);assert!(!backdrop_parent.is_invalid());- host.arena().detach_child(backdrop_parent, old_backdrop);+ host.arena_mut().detach_child(backdrop_parent, old_backdrop);host.free_subtree(old_backdrop);}}@@ -2714,7 +2714,8 @@ fn update_principal_node_after_entry();}FfiPrincipalBoxPlacement::ReplaceExisting => {- let arena = host.arena();+ let host_calls = host.host_calls();+ let arena = host.arena_mut();let old_data = arena.data(old_layout_node);let new_data = arena.data(layout_node);if node_facts::kind_is_box(old_data.kind.get())@@ -2724,8 +2725,8 @@ fn update_principal_node_after_entry(arena.set_committed_fragment_link(layout_node, link, None);}transfer_fragments_to_replacement_box(arena, old_layout_node, layout_node);- super::layout_node_arena::prepare_subtree_for_detach(host.host_calls(), arena, old_layout_node);- let old_parent = host.parent(old_layout_node);+ super::layout_node_arena::prepare_subtree_for_detach(host_calls, arena, old_layout_node);+ let old_parent = arena.data(old_layout_node).parent.get();assert!(!old_parent.is_invalid());let replaced_old_box = arena.replace_child(old_parent,@@ -3178,7 +3179,7 @@ fn stamp_pseudo_element_box_row(.make_display_contents_pseudo_element_box_inline(host_calls, slot);}if is_list_item_marker {- host.arena()+ host.arena_mut().set_node_flag(slot, NodeFlag::ListMarkerIsInside, facts.marker_position_is_inside);}host.note_style_of_built_row(slot, None);@@ -3221,7 +3222,7 @@ fn stamp_nested_list_marker_row(let marker_position_is_inside = host.style(list_item_box).is_some_and(ComputedValuesView::list_style_position_is_inside);- host.arena()+ host.arena_mut().set_node_flag(slot, NodeFlag::ListMarkerIsInside, marker_position_is_inside);host.note_style_of_built_row(slot, None);host.arena_mut().owe_image_resources(@@ -3632,8 +3633,8 @@ impl<'a> TreeBuilderHost<'a> {})}- fn set_children_are_inline(&self, node: LayoutNode, children_are_inline: bool) {- self.arena()+ fn set_children_are_inline(&mut self, node: LayoutNode, children_are_inline: bool) {+ self.arena_mut().set_node_flag(node, NodeFlag::ChildrenAreInline, children_are_inline);}@@ -3674,7 +3675,7 @@ impl<'a> TreeBuilderHost<'a> {// A media element renders the children of its shadow root, such as its controls.NodeKind::AudioBox | NodeKind::VideoBox => {let has_shadow_root = self.arena().shadow_root_of(element).is_some();- self.arena()+ self.arena_mut().set_node_flag(slot, NodeFlag::ReplacedBoxCanHaveChildren, has_shadow_root);}_ => {}@@ -3733,7 +3734,7 @@ impl<'a> TreeBuilderHost<'a> {/// metrics, giving the caret an anchor to paint at and the control its baseline. The document/// restamps it when editability changes. Under an element with a highlight pseudo-element style/// and no box of its own, the row takes that style's paint facts itself.- fn stamp_text_row_facts(&self, slot: NodeSlotId, text: StyleNodeID) {+ fn stamp_text_row_facts(&mut self, slot: NodeSlotId, text: StyleNodeID) {use crate::css::style::bridge::element_construction_fact::{IS_EDITING_HOST, IS_HTML_INPUT_ELEMENT};let is_in_user_agent_shadow_tree =self.arena().node_flags(slot) & NodeFlag::IsInUserAgentShadowTree as u32 != 0;@@ -3754,7 +3755,7 @@ impl<'a> TreeBuilderHost<'a> {});(parent_is_editing_host || is_in_text_control, parent_element)});- self.arena().set_node_flag(+ self.arena_mut().set_node_flag(slot,NodeFlag::ProducesLineBoxFragmentWhenEmpty,produces_line_box_fragment_when_empty,@@ -3831,7 +3832,7 @@ impl<'a> TreeBuilderHost<'a> {.derive_anonymous_style_record(parent_style_record, style_kind, overrides);let slot = self.arena.allocate_unbound();self.arena_mut().stamp_anonymous_box(slot, node_kind, derived);- self.arena().refresh_insets_use_anchor_functions_flag(slot);+ self.arena_mut().refresh_insets_use_anchor_functions_flag(slot);// An anonymous inline box takes its style from its parent, so it may name images too.if node_kind == NodeKind::InlineNode {self.arena_mut().owe_image_resources(@@ -3853,12 +3854,12 @@ impl<'a> TreeBuilderHost<'a> {)}- fn attach_child(&self, parent: LayoutNode, child: UnplacedLayoutNode, before: LayoutNode) {- self.arena().attach_child(parent, child, before);+ fn attach_child(&mut self, parent: LayoutNode, child: UnplacedLayoutNode, before: LayoutNode) {+ self.arena_mut().attach_child(parent, child, before);}- fn move_child(&self, child: LayoutNode, new_parent: LayoutNode, before: LayoutNode) {- self.arena().move_child(child, new_parent, before);+ fn move_child(&mut self, child: LayoutNode, new_parent: LayoutNode, before: LayoutNode) {+ self.arena_mut().move_child(child, new_parent, before);}fn free_unplaced(&mut self, node: UnplacedLayoutNode) {@@ -3939,7 +3940,7 @@ impl<'a> TreeBuilderHost<'a> {for &node in nodes {let parent = self.parent(node);assert!(!parent.is_invalid());- self.arena().detach_child(parent, node);+ self.arena_mut().detach_child(parent, node);}for &node in nodes {self.free_subtree(node);@@ -4307,7 +4308,7 @@ fn wrap_children_in_anonymous_wrapper(}fn insert_child_in_dom_order(- host: &TreeBuilderHost<'_>,+ host: &mut TreeBuilderHost<'_>,parent: LayoutNode,child: UnplacedLayoutNode,identity: StyleNodeID,@@ -4632,7 +4633,7 @@ fn create_first_letter_boxes(host: &mut TreeBuilderHost<'_>, element: StyleNodeIhost.attach_child(wrapper_slot, first_letter_slice, NodeSlotId::INVALID);host.attach_child(parent, wrapper, text_node);host.attach_child(parent, remainder_slice, text_node);- host.arena().detach_child(parent, text_node);+ host.arena_mut().detach_child(parent, text_node);host.free_subtree(text_node);}@@ -4712,7 +4713,7 @@ fn create_writing_suggestion_boxes(host: &mut TreeBuilderHost<'_>, element: Stylhost.attach_child(parent, leading_slice, text_node);host.attach_child(parent, wrapper, text_node);host.attach_child(parent, trailing_slice, text_node);- host.arena().detach_child(parent, text_node);+ host.arena_mut().detach_child(parent, text_node);host.free_subtree(text_node);}@@ -5344,7 +5345,7 @@ fn fixup_row(AnonymousStyleOverrides::default(),NodeKind::BlockContainer,);- host.arena()+ host.arena_mut().set_node_flag(cell.slot(), NodeFlag::IsMissingTableCell, true);host.attach_child(row, cell, NodeSlotId::INVALID);}diff --git a/Libraries/LibWeb/Rust/src/layout/tree_mutation.rs b/Libraries/LibWeb/Rust/src/layout/tree_mutation.rsindex 0844bc1b187..db9ded22340 100644--- a/Libraries/LibWeb/Rust/src/layout/tree_mutation.rs+++ b/Libraries/LibWeb/Rust/src/layout/tree_mutation.rs@@ -251,15 +251,15 @@ fn next_sibling_of(arena: &LayoutNodeArena, node: NodeSlotId) -> NodeSlotId {}impl LayoutNodeArena {- pub(crate) fn attach_child(&self, parent: NodeSlotId, child: UnplacedLayoutNode, before: NodeSlotId) {+ pub(crate) fn attach_child(&mut self, parent: NodeSlotId, child: UnplacedLayoutNode, before: NodeSlotId) {self.insert_child(parent, child.into_slot(), before);}- pub(crate) fn detach_child(&self, parent: NodeSlotId, child: NodeSlotId) {+ pub(crate) fn detach_child(&mut self, parent: NodeSlotId, child: NodeSlotId) {self.remove_child(parent, child);}- pub(crate) fn detach_from_parent(&self, node: NodeSlotId) -> bool {+ pub(crate) fn detach_from_parent(&mut self, node: NodeSlotId) -> bool {let parent = parent_of(self, node);if parent.is_invalid() {return false;@@ -268,7 +268,7 @@ impl LayoutNodeArena {true}- pub(crate) fn move_child(&self, child: NodeSlotId, new_parent: NodeSlotId, before: NodeSlotId) {+ pub(crate) fn move_child(&mut self, child: NodeSlotId, new_parent: NodeSlotId, before: NodeSlotId) {let old_parent = parent_of(self, child);assert!(!old_parent.is_invalid(), "moved layout node has no parent");self.remove_child(old_parent, child);@@ -276,7 +276,7 @@ impl LayoutNodeArena {}pub(crate) fn replace_child(- &self,+ &mut self,parent: NodeSlotId,old_child: NodeSlotId,new_child: UnplacedLayoutNode,diff --git a/Libraries/LibWeb/Rust/src/layout/tree_update_marks.rs b/Libraries/LibWeb/Rust/src/layout/tree_update_marks.rsindex 0c4fae4e571..3d02116c2e9 100644--- a/Libraries/LibWeb/Rust/src/layout/tree_update_marks.rs+++ b/Libraries/LibWeb/Rust/src/layout/tree_update_marks.rs@@ -303,7 +303,7 @@ impl LayoutNodeArena {/// to it, and its box is invalidated as [`Self::apply_layout_tree_update_mark`] does. What only the DOM side knows/// of, the resources an SVG element lends its references and a display: contents element's parent, is not for a/// node with a box.- pub(crate) fn mark_layout_tree_update(&self, node: Option<StyleNodeID>, mark: FfiLayoutTreeUpdateMark) {+ pub(crate) fn mark_layout_tree_update(&mut self, node: Option<StyleNodeID>, mark: FfiLayoutTreeUpdateMark) {let document = self.document_style_node();let Some(style_node) = node.or(document) else {return;@@ -357,7 +357,7 @@ impl LayoutNodeArena {/// Invalidates the box of the node `node` names, or the document's for `None`, as a layout tree update mark on it/// asks, and marks the node a rebuild of it escalates to. A node without a box has nothing to invalidate.- pub(crate) fn apply_layout_tree_update_mark(&self, node: Option<StyleNodeID>, mark: FfiLayoutTreeUpdateMark) {+ pub(crate) fn apply_layout_tree_update_mark(&mut self, node: Option<StyleNodeID>, mark: FfiLayoutTreeUpdateMark) {let row = match node {Some(node) => self.bound_row(node),None => self.bound_viewport_row(),@@ -585,7 +585,7 @@ impl FfiBoxMarks {arena.set_needs_layout_update(row, true);}if self.has_editing_facts {- let stamp = |flag: NodeFlag, value: bool| {+ let mut stamp = |flag: NodeFlag, value: bool| {let flips = (arena.node_flags(row) & flag as u32 != 0) != value;if flips {arena.set_node_flag(row, flag, value);diff --git a/Libraries/LibWeb/Rust/src/layout/update_layout.rs b/Libraries/LibWeb/Rust/src/layout/update_layout.rsindex 258703865a9..aebacabfa3b 100644--- a/Libraries/LibWeb/Rust/src/layout/update_layout.rs+++ b/Libraries/LibWeb/Rust/src/layout/update_layout.rs@@ -417,9 +417,9 @@ impl StabilizationTrace {root.is_invalid(),!root.is_invalid() && arena.node_needs_layout_update(root),arena.needs_full_layout_tree_update(),- arena.partial_relayout_boundary_roots.borrow().roots().len(),- arena.pending_updates_escape_partial_relayout.get(),- arena.deferred_child_list_insertion_parents.borrow().len(),+ arena.partial_relayout_boundary_roots.roots().len(),+ arena.pending_updates_escape_partial_relayout,+ arena.deferred_child_list_insertion_parents.len(),)});let facts_that_hold: Vec<&str> = [@@ -830,7 +830,7 @@ impl LayoutRoundJob {if self.layout == RoundLayout::PartialIfPlanned&& arena.partial_relayout_may_be_attempted(arena.layout_root(),- arena.partial_relayout_boundary_roots.borrow().roots(),+ arena.partial_relayout_boundary_roots.roots(),partial_relayout_facts,){@@ -845,7 +845,7 @@ impl LayoutRoundJob {}}- let arena = state.arena();+ let arena = state.arena_mut();// Among the boundaries are those the build registered where it invalidated what deferred child list// insertions reach.let boundaries = arena.take_partial_relayout_boundary_roots();@@ -884,7 +884,7 @@ impl LayoutRoundJob {}}// The full layout below covers every registered boundary, the build's among them.- drop(state.arena().take_partial_relayout_boundary_roots());+ drop(state.arena_mut().take_partial_relayout_boundary_roots());let layout_root = state.arena().layout_root();assert!(!layout_root.is_invalid(), "a full layout pass needs a layout root");diff --git a/Libraries/LibWeb/Rust/src/painting/scrollable_overflow.rs b/Libraries/LibWeb/Rust/src/painting/scrollable_overflow.rsindex aaf15fc8f96..0b0da73f8b7 100644--- a/Libraries/LibWeb/Rust/src/painting/scrollable_overflow.rs+++ b/Libraries/LibWeb/Rust/src/painting/scrollable_overflow.rs@@ -749,7 +749,7 @@ impl LayoutNodeArena {}}- pub(crate) fn did_commit_full_layout(&self, viewport: NodeSlotId) {+ pub(crate) fn did_commit_full_layout(&mut self, viewport: NodeSlotId) {if self.scrollable_overflow.viewport.replace(Some(viewport)) != Some(viewport) {self.scrollable_overflow.contained_boxes_dirty.set(true);self.set_needs_full_scrollable_overflow_recalculation();@@ -983,7 +983,7 @@ impl Drop for OverflowStyle {}impl LayoutNodeArena {- pub(crate) fn invalidate_overflow_after_style_change(&self, slot: NodeSlotId) {+ pub(crate) fn invalidate_overflow_after_style_change(&mut self, slot: NodeSlotId) {if !self.paintable_row_is_populated(slot) {return;}