Skip to content

Truly independent web browser

LibWeb: Install styles and stamp rows through a mutable layout arena

Aliaksandr Kalenik40d235cb67d6
diff --git a/Libraries/LibWeb/Rust/src/layout/commit.rs b/Libraries/LibWeb/Rust/src/layout/commit.rs
index 5136c488cd1..c90c0a9902d 100644
--- a/Libraries/LibWeb/Rust/src/layout/commit.rs
+++ b/Libraries/LibWeb/Rust/src/layout/commit.rs
@@ -182,7 +182,7 @@ fn commit_subtree(
);
}
if !reuses_committed_subtree {
- paintables.arena().note_subtree_committed_anew(node);
+ paintables.arena_mut().note_subtree_committed_anew(node);
paintables.arena().forget_committed_out_of_flow_facts(node);
}
if let Some(inputs) = entry.and_then(|link| link.abspos_layout_inputs.as_ref()) {
diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
index 25fbf0e03b2..8fde8a7fb06 100644
--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
@@ -3414,12 +3414,12 @@ pub(crate) fn lay_out_root(
assert!(!root.is_invalid());
// The style rewrites enroll the affected boxes' text children for content sync, so the sync
// follows them, and both precede the pass, which caches decoded style.
- let arena = state.arena();
+ let facts = viewport_propagation::viewport_propagation_facts(state.arena());
viewport_propagation::propagate_root_styles_to_viewport(
super::tree_mutation::HostCalls(work),
- arena,
+ state.arena_mut(),
root,
- &viewport_propagation::viewport_propagation_facts(arena),
+ &facts,
);
super::layout_node_arena::sync_enrolled_content_for_layout(state.arena_mut());
LayoutStageJob {
diff --git a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs
index 4214b3641c1..ceeb3624da5 100644
--- a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs
+++ b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs
@@ -1218,7 +1218,7 @@ pub(crate) struct LayoutNodeArena {
full_layout_count: u64,
/// How many layouts were committed, full and partial.
layout_commit_count: u64,
- committed_subtree_tokens: RefCell<Vec<u32>>,
+ committed_subtree_tokens: Vec<u32>,
layout_tree_build_stats: FfiLayoutTreeBuildStats,
pre_order_labels: Vec<Cell<u64>>,
pre_order_relabel_count: Cell<u64>,
@@ -1233,7 +1233,7 @@ pub(crate) struct LayoutNodeArena {
pub(super) searchable_text: Option<Vec<super::text_queries::MappedText>>,
replaced_content_facts: Vec<ReplacedContentFactsSlot>,
/// The layout kind of each row built for a MathML element, from its tag name.
- math_layout_kinds: RefCell<HashMap<NodeSlotId, super::math_formatting_context::MathLayoutKind>>,
+ math_layout_kinds: HashMap<NodeSlotId, super::math_formatting_context::MathLayoutKind>,
replaced_paint_facts: Arc<crate::painting::replaced_paint_facts::ReplacedPaintFactsTable>,
layer_image_paint_facts: Arc<crate::painting::layer_image_paint_facts::LayerImagePaintFactsTable>,
svg_paint_resources: crate::painting::svg_paint_resources::SvgPaintResources,
@@ -1264,7 +1264,7 @@ pub(crate) struct LayoutNodeArena {
position_options_in_use: HashMap<NodeSlotId, super::abspos_inputs::PositionOptionChoice>,
/// https://drafts.csswg.org/css-anchor-position-1/#last-successful-position-option
last_successful_position_options: HashMap<NodeSlotId, super::abspos_inputs::PositionOptionChoice>,
- pub(crate) inline_boxes_lifted_out_of: RefCell<HashMap<NodeSlotId, NodeSlotId>>,
+ pub(crate) inline_boxes_lifted_out_of: HashMap<NodeSlotId, NodeSlotId>,
pub(crate) out_of_flow_positioning_contained: RefCell<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
@@ -1273,7 +1273,7 @@ pub(crate) struct LayoutNodeArena {
pub(crate) pending_updates_escape_partial_relayout: Cell<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: RefCell<HashSet<NodeSlotId>>,
+ text_nodes_enrolled_for_content_sync: HashSet<NodeSlotId>,
/// The scroll containers a running tree build gave a style, which may be where scroll
/// snapping happens once the build is over.
built_scroll_containers: RefCell<Vec<NodeSlotId>>,
@@ -1286,7 +1286,7 @@ pub(crate) struct LayoutNodeArena {
may_have_auto_content_visibility: Cell<bool>,
/// Whether a row has ever been given a style with a scroll snap type.
may_have_scroll_snap_areas: Cell<bool>,
- nodes_enrolled_for_replaced_content_facts_sync: RefCell<Vec<NodeSlotId>>,
+ nodes_enrolled_for_replaced_content_facts_sync: Vec<NodeSlotId>,
/// The natural size of the image each image box that owns its image's provider shows
/// (`content: url(...)`), as the provider publishes it: zero while the image is not available.
/// Such a box shows an image of its own rather than its element's.
@@ -1339,7 +1339,7 @@ impl LayoutNodeArena {
partial_layout_count: (0),
full_layout_count: (0),
layout_commit_count: 0,
- committed_subtree_tokens: RefCell::new(Vec::new()),
+ committed_subtree_tokens: Vec::new(),
layout_tree_build_stats: (FfiLayoutTreeBuildStats::default()),
pre_order_labels: Vec::new(),
pre_order_relabel_count: Cell::new(0),
@@ -1352,7 +1352,7 @@ impl LayoutNodeArena {
text_slots: TextSlots::default(),
searchable_text: None,
replaced_content_facts: Vec::new(),
- math_layout_kinds: RefCell::default(),
+ math_layout_kinds: Default::default(),
replaced_paint_facts: Default::default(),
layer_image_paint_facts: Default::default(),
svg_paint_resources: crate::painting::svg_paint_resources::SvgPaintResources::default(),
@@ -1370,18 +1370,18 @@ impl LayoutNodeArena {
confined_abspos_layout_inputs: HashMap::default(),
position_options_in_use: (HashMap::default()),
last_successful_position_options: (HashMap::default()),
- inline_boxes_lifted_out_of: RefCell::new(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),
boxes_needing_scrollable_overflow_recalculation: RefCell::new(Vec::new()),
needs_full_scrollable_overflow_recalculation: Cell::new(false),
- text_nodes_enrolled_for_content_sync: RefCell::new(HashSet::default()),
+ text_nodes_enrolled_for_content_sync: HashSet::default(),
built_scroll_containers: RefCell::default(),
image_resources_owed_to_host: RefCell::default(),
owned_image_providers: Default::default(),
may_have_auto_content_visibility: Cell::new(false),
may_have_scroll_snap_areas: Cell::new(false),
- nodes_enrolled_for_replaced_content_facts_sync: RefCell::new(Vec::new()),
+ nodes_enrolled_for_replaced_content_facts_sync: Vec::new(),
owned_image_natural_sizes: HashMap::default(),
document_svg_root_natural_size: None,
handed_over_document_svg_root_natural_size: (None),
@@ -1470,14 +1470,13 @@ impl LayoutNodeArena {
/// entry that found its fragments committed whether they still are.
pub(crate) fn committed_subtree_token(&self, id: NodeSlotId) -> u32 {
self.committed_subtree_tokens
- .borrow()
.get(id.slot_index() as usize)
.copied()
.unwrap_or_default()
}
- pub(crate) fn note_subtree_committed_anew(&self, id: NodeSlotId) {
- let mut tokens = self.committed_subtree_tokens.borrow_mut();
+ pub(crate) fn note_subtree_committed_anew(&mut self, id: NodeSlotId) {
+ let tokens = &mut self.committed_subtree_tokens;
let index = id.slot_index() as usize;
if tokens.len() <= index {
tokens.resize(index + 1, 0);
@@ -1486,7 +1485,7 @@ impl LayoutNodeArena {
}
/// Notes that the subtrees of `id` and its ancestors were committed anew.
- pub(crate) fn note_subtrees_of_self_and_ancestors_committed_anew(&self, id: NodeSlotId) {
+ pub(crate) fn note_subtrees_of_self_and_ancestors_committed_anew(&mut self, id: NodeSlotId) {
let mut node = id;
while !node.is_invalid() && self.slot_is_live(node) {
self.note_subtree_committed_anew(node);
@@ -1506,7 +1505,7 @@ impl LayoutNodeArena {
}
#[cfg(test)]
- pub(crate) fn bind_shell(&self, slot: NodeSlotId, construction_facts: super::node_data::NodeConstructionFacts) {
+ pub(crate) fn bind_shell(&mut self, slot: NodeSlotId, construction_facts: super::node_data::NodeConstructionFacts) {
assert!(
self.slot_is_live(slot),
"layout node arena bound a shell to a dead slot"
@@ -1538,7 +1537,7 @@ impl LayoutNodeArena {
/// Derives the replaced content facts of every enrolled node from what its element, or the
/// image provider the node owns, published, and lets go of the nodes that died.
fn sync_enrolled_replaced_content_facts(&mut self) {
- let mut enrolled_nodes = std::mem::take(self.nodes_enrolled_for_replaced_content_facts_sync.get_mut());
+ let mut enrolled_nodes = std::mem::take(&mut self.nodes_enrolled_for_replaced_content_facts_sync);
enrolled_nodes.retain(|&node| self.slot_is_live(node));
for &node in &enrolled_nodes {
// A box waiting for the provider it owns shows no image yet, as the provider says while
@@ -1566,10 +1565,10 @@ impl LayoutNodeArena {
self.bump_fragment_cache_epoch_of_self_and_ancestors(node);
}
}
- *self.nodes_enrolled_for_replaced_content_facts_sync.get_mut() = enrolled_nodes;
+ self.nodes_enrolled_for_replaced_content_facts_sync = enrolled_nodes;
}
- pub(crate) fn enroll_node_for_replaced_content_facts_sync_if_eligible(&self, node: NodeSlotId) {
+ pub(crate) fn enroll_node_for_replaced_content_facts_sync_if_eligible(&mut self, node: NodeSlotId) {
let data = self.data(node);
// The pass negotiates an <svg> root's natural size itself.
if !super::node_facts::node_may_have_replaced_content_facts_including_size_containment(data)
@@ -1577,7 +1576,7 @@ impl LayoutNodeArena {
{
return;
}
- let mut enrolled_nodes = self.nodes_enrolled_for_replaced_content_facts_sync.borrow_mut();
+ let enrolled_nodes = &mut self.nodes_enrolled_for_replaced_content_facts_sync;
if !enrolled_nodes.contains(&node) {
enrolled_nodes.push(node);
}
@@ -1722,7 +1721,7 @@ impl LayoutNodeArena {
if let Some(reset) = paintable_row_reset {
self.paintable_row_freed(reset);
}
- self.inline_boxes_lifted_out_of.get_mut().remove(&id);
+ self.inline_boxes_lifted_out_of.remove(&id);
self.out_of_flow_positioning_contained.get_mut().remove(&id);
self.pre_order_labels[index as usize].set(0);
self.partial_relayout_boundary_roots.get_mut().note_freed(id);
@@ -1741,7 +1740,7 @@ impl LayoutNodeArena {
}
self.paintable_rows.reset_committed_fragment_link_slot(index);
self.text_slots.reset(index as usize);
- self.text_nodes_enrolled_for_content_sync.get_mut().remove(&id);
+ self.text_nodes_enrolled_for_content_sync.remove(&id);
if let Some(slot) = self.replaced_content_facts.get_mut(index as usize) {
*slot = ReplacedContentFactsSlot::default();
}
@@ -1749,7 +1748,7 @@ impl LayoutNodeArena {
self.owned_image_providers.remove(&id);
self.memo_invalidations.get_mut().note_slot_freed(index);
self.remove_layout_update_flag_node(id);
- self.math_layout_kinds.get_mut().remove(&id);
+ self.math_layout_kinds.remove(&id);
if self.replaced_paint_facts.contains_key(&id) {
Arc::make_mut(&mut self.replaced_paint_facts).remove(&id);
}
@@ -2372,7 +2371,7 @@ impl LayoutNodeArena {
}
}
- pub(crate) fn set_node_style(&self, id: NodeSlotId, style_record: u64, payloads: StylePayloadsRef) -> bool {
+ pub(crate) fn set_node_style(&mut self, id: NodeSlotId, style_record: u64, payloads: StylePayloadsRef) -> bool {
self.write_shape(id).set_style(payloads);
self.note_row_style(id);
self.set_node_flag(id, NodeFlag::FollowsPrincipalStyle, false);
@@ -2392,7 +2391,7 @@ impl LayoutNodeArena {
/// layout inputs, this also drops the layout cached for `previous_payloads`, the style the box showed. `None`
/// keeps that layout.
pub(crate) fn install_style_record(
- &self,
+ &mut self,
slot: NodeSlotId,
style_record: u64,
payloads: StylePayloadsRef,
@@ -2437,7 +2436,7 @@ impl LayoutNodeArena {
/// the relayout the move asks for. Answers the rows it applied, by element, or why it applied none: a row's box is
/// one the host styles in a way of its own. The host installs the rows on the elements once the frame has landed.
pub(crate) fn apply_flight_style_rows(
- &self,
+ &mut self,
host_calls: HostCalls<'_>,
rows: Vec<FlightStyleRow>,
) -> Result<Vec<FlightStyleRow>, Decline> {
@@ -2575,7 +2574,7 @@ impl LayoutNodeArena {
/// which [`Self::takes_hover_row`] took, as the host's install of the row does: the style, the styles the box's
/// anonymous descendants inherit, and the relayout, the visual contexts and the repaint the move asks for.
pub(crate) fn install_hover_row(
- &self,
+ &mut self,
host_calls: HostCalls<'_>,
row: &crate::css::style::bridge::FfiStyleDelta,
generated_for: u8,
@@ -2728,7 +2727,7 @@ impl LayoutNodeArena {
/// [`Self::takes_sample`]). Answers the host's style where the box held it, or nothing where it held a sample
/// already, which `sample` replaces.
pub(crate) fn install_sample(
- &self,
+ &mut self,
row: NodeSlotId,
sample: DerivedStyleRecord,
kind: SampleKind,
@@ -2746,7 +2745,7 @@ impl LayoutNodeArena {
/// the box held it, or nothing where it held a sample already, which `sample` replaces. The box lays out again as
/// `relayout` decides.
pub(crate) fn install_sample_beside_anonymous_boxes(
- &self,
+ &mut self,
row: NodeSlotId,
sample: DerivedStyleRecord,
relayout: StyleRelayout,
@@ -2801,7 +2800,7 @@ impl LayoutNodeArena {
/// Gives `row` back the style the host installed for it, which a clock tick took to show a sample in its place. The
/// box lays out again as `relayout` decides.
- pub(crate) fn restore_host_style(&self, row: NodeSlotId, host_style: HostStyle, relayout: StyleRelayout) {
+ pub(crate) fn restore_host_style(&mut self, row: NodeSlotId, host_style: HostStyle, relayout: StyleRelayout) {
let index = row.slot_index() as usize;
assert!(
self.style_record_pins[index].get() == ArenaStylePin::Sampled,
@@ -2832,7 +2831,7 @@ impl LayoutNodeArena {
/// box does, laying the box out again as `relayout` decides. A move whose damage only repaints, such as one of
/// `color`, lays out nothing again.
fn show_style(
- &self,
+ &mut self,
row: NodeSlotId,
style_node: Option<StyleNodeID>,
style: DerivedStyleRecord,
@@ -3644,7 +3643,7 @@ impl LayoutNodeArena {
}
pub(crate) fn update_layout_style(
- &self,
+ &mut self,
host_calls: HostCalls<'_>,
node: NodeSlotId,
update: impl FnOnce(&mut LayoutStyle),
@@ -3663,11 +3662,15 @@ impl LayoutNodeArena {
}
}
- pub(crate) fn reset_table_box_style_used_by_wrapper(&self, host_calls: HostCalls<'_>, node: NodeSlotId) {
+ pub(crate) fn reset_table_box_style_used_by_wrapper(&mut self, host_calls: HostCalls<'_>, node: NodeSlotId) {
self.update_layout_style(host_calls, node, LayoutStyle::reset_table_properties);
}
- pub(crate) fn make_display_contents_pseudo_element_box_inline(&self, host_calls: HostCalls<'_>, node: NodeSlotId) {
+ pub(crate) fn make_display_contents_pseudo_element_box_inline(
+ &mut self,
+ host_calls: HostCalls<'_>,
+ node: NodeSlotId,
+ ) {
self.update_layout_style(host_calls, node, |style| {
style.set_display(crate::layout::FfiDisplay::outside_and_inside(
crate::css::css_enums::display_outside::INLINE,
@@ -3686,7 +3689,7 @@ impl LayoutNodeArena {
.is_some_and(|payloads| ComputedValuesView::new(&payloads.groups).display().is_contents())
}
- pub(crate) fn reinherit_anonymous_descendants(&self, host_calls: HostCalls<'_>, node: NodeSlotId) {
+ pub(crate) fn reinherit_anonymous_descendants(&mut self, host_calls: HostCalls<'_>, node: NodeSlotId) {
if self.node_style_record(node) == 0 {
return;
}
@@ -3711,7 +3714,12 @@ impl LayoutNodeArena {
self.reinherit_anonymous_children(host_calls, node, self.node_style_record(node));
}
- fn reinherit_anonymous_children(&self, host_calls: HostCalls<'_>, parent: NodeSlotId, parent_style_record: u64) {
+ fn reinherit_anonymous_children(
+ &mut self,
+ host_calls: HostCalls<'_>,
+ parent: NodeSlotId,
+ parent_style_record: u64,
+ ) {
let mut child = self.data(parent).first_child.get();
while !child.is_invalid() {
let next_sibling = self.data(child).next_sibling.get();
@@ -3763,7 +3771,7 @@ impl LayoutNodeArena {
}
pub(crate) fn apply_reinherited_style_record(
- &self,
+ &mut self,
host_calls: HostCalls<'_>,
slot: NodeSlotId,
derived: DerivedStyleRecord,
@@ -3794,7 +3802,7 @@ impl LayoutNodeArena {
let establishes_containing_block =
super::node_facts::containing_block_establishment_flag(search.is_fixed_position);
let looks_for_inline_containing_block = !search.is_fixed_position;
- let has_lifted_boxes = !self.inline_boxes_lifted_out_of.borrow().is_empty();
+ let has_lifted_boxes = !self.inline_boxes_lifted_out_of.is_empty();
let mut node = search.frontier;
while node != limit {
let ancestor = self.data(node).parent.get();
@@ -4030,15 +4038,15 @@ impl LayoutNodeArena {
}
}
- pub(crate) fn enroll_text_node_for_content_sync(&self, node: NodeSlotId) {
- self.text_nodes_enrolled_for_content_sync.borrow_mut().insert(node);
+ pub(crate) fn enroll_text_node_for_content_sync(&mut self, node: NodeSlotId) {
+ self.text_nodes_enrolled_for_content_sync.insert(node);
}
/// Stamps a row the build allocated for a DOM node, with the facts the style mirror publishes
/// under the node's identity. The document names no identity of its own, and its row is
/// recognized by its kind. The layout node made for the row answers for the paint facts the row
/// is built with, which are not published.
- pub(crate) fn stamp_dom_row(&self, slot: NodeSlotId, kind: NodeKind, style_node: Option<StyleNodeID>) {
+ pub(crate) fn stamp_dom_row(&mut self, slot: NodeSlotId, kind: NodeKind, style_node: Option<StyleNodeID>) {
let data = self.write_shape(slot);
assert_eq!(
data.kind.get(),
@@ -4053,7 +4061,7 @@ impl LayoutNodeArena {
let math_layout_kind =
super::math_formatting_context::MathLayoutKind::from_construction_facts(construction_facts);
if math_layout_kind != super::math_formatting_context::MathLayoutKind::NotMathML {
- self.math_layout_kinds.borrow_mut().insert(slot, math_layout_kind);
+ self.math_layout_kinds.insert(slot, math_layout_kind);
}
if let Some(style_node) = style_node {
self.stamp_dom_paint_facts(slot, style_node);
@@ -4078,7 +4086,7 @@ impl LayoutNodeArena {
/// Gives a row stamped for an element the style record the element published, the one
/// [`Self::element_box_style_record`] names, as a layout node built from the element's record
/// gave it.
- pub(crate) fn stamp_published_style(&self, slot: NodeSlotId, record: u64) {
+ pub(crate) fn stamp_published_style(&mut self, slot: NodeSlotId, record: u64) {
let published = self.with_style_engine(|engine| DerivedStyleRecord::pin(engine, record));
self.stamp_published_style_record(slot, published);
}
@@ -4087,7 +4095,7 @@ impl LayoutNodeArena {
/// takes another. The node hands the row its next record through the row's layout node, which
/// is made when first asked for and reads the row's style as it is made, so the record must
/// outlive a publication that replaces it before then.
- fn stamp_published_style_record(&self, slot: NodeSlotId, published: DerivedStyleRecord) {
+ fn stamp_published_style_record(&mut self, slot: NodeSlotId, published: DerivedStyleRecord) {
if self.set_node_style(slot, published.record, published.payloads) {
self.refresh_style_flags(slot);
}
@@ -4115,7 +4123,7 @@ impl LayoutNodeArena {
/// the element published for the pseudo-element. The row stands for no DOM node, so it is
/// anonymous; it carries its generator and the pseudo-element it is generated for.
pub(crate) fn stamp_pseudo_element_row(
- &self,
+ &mut self,
slot: NodeSlotId,
kind: NodeKind,
generator: StyleNodeID,
@@ -4184,7 +4192,7 @@ impl LayoutNodeArena {
self.refresh_has_scroll_offset_flag(slot);
}
- pub(crate) fn stamp_anonymous_box(&self, slot: NodeSlotId, kind: NodeKind, derived: DerivedStyleRecord) {
+ pub(crate) fn stamp_anonymous_box(&mut self, slot: NodeSlotId, kind: NodeKind, derived: DerivedStyleRecord) {
let data = self.write_shape(slot);
assert_eq!(
data.kind.get(),
@@ -4283,7 +4291,7 @@ impl LayoutNodeArena {
}
}
- pub(crate) fn replace_arena_pinned_style_record(&self, slot: NodeSlotId, derived: DerivedStyleRecord) {
+ pub(crate) fn replace_arena_pinned_style_record(&mut self, slot: NodeSlotId, derived: DerivedStyleRecord) {
let previously_pinned =
self.style_record_pins[slot.slot_index() as usize].replace(ArenaStylePin::Derived) != ArenaStylePin::None;
assert!(derived.record != 0 && !derived.payloads.is_null());
@@ -5212,7 +5220,7 @@ impl LayoutNodeArena {
link
}
- pub(crate) fn clear_committed_fragment_link(&self, id: NodeSlotId) {
+ pub(crate) fn clear_committed_fragment_link(&mut self, id: NodeSlotId) {
// Cached runs may reuse the committed paintable subtree without replaying its fragments.
// Once that subtree is cleared, a later layout must rebuild it instead.
self.memo_invalidations
@@ -5321,32 +5329,23 @@ impl LayoutNodeArena {
self.enroll_text_node_for_content_sync(id);
}
- pub(super) fn finish_text_content_sync(&self, id: NodeSlotId) {
- self.text_nodes_enrolled_for_content_sync.borrow_mut().remove(&id);
+ pub(super) fn finish_text_content_sync(&mut self, id: NodeSlotId) {
+ self.text_nodes_enrolled_for_content_sync.remove(&id);
}
pub(super) fn pending_text_nodes_for_content_sync(&self) -> Vec<NodeSlotId> {
- self.text_nodes_enrolled_for_content_sync
- .borrow()
- .iter()
- .copied()
- .collect()
+ self.text_nodes_enrolled_for_content_sync.iter().copied().collect()
}
/// The text rows that wait for their text to be rendered again, by slot index.
pub(super) fn text_rows_awaiting_sync(&self) -> Box<[NodeSlotId]> {
- let mut rows: Box<[NodeSlotId]> = self
- .text_nodes_enrolled_for_content_sync
- .borrow()
- .iter()
- .copied()
- .collect();
+ let mut rows: Box<[NodeSlotId]> = self.text_nodes_enrolled_for_content_sync.iter().copied().collect();
rows.sort_unstable_by_key(|row| row.index);
rows
}
pub(super) fn text_content_needs_sync(&self, id: NodeSlotId) -> bool {
- self.text_nodes_enrolled_for_content_sync.borrow().contains(&id)
+ self.text_nodes_enrolled_for_content_sync.contains(&id)
|| !self
.text_content(id)
.is_some_and(|content| content.rendering_key.is_some())
@@ -5403,7 +5402,6 @@ impl LayoutNodeArena {
/// The layout algorithm the MathML element a row is built for selects by its tag name.
pub(crate) fn math_layout_kind(&self, id: NodeSlotId) -> super::math_formatting_context::MathLayoutKind {
self.math_layout_kinds
- .borrow()
.get(&id)
.copied()
.unwrap_or(super::math_formatting_context::MathLayoutKind::NotMathML)
@@ -5749,8 +5747,8 @@ impl LayoutNodeArena {
Some(self.data(id))
}
- pub(crate) fn note_inline_box_lifted_out_of(&self, node: NodeSlotId, inline_box: Option<NodeSlotId>) {
- let mut lifted = self.inline_boxes_lifted_out_of.borrow_mut();
+ pub(crate) fn note_inline_box_lifted_out_of(&mut self, node: NodeSlotId, inline_box: Option<NodeSlotId>) {
+ let lifted = &mut self.inline_boxes_lifted_out_of;
match inline_box {
Some(inline_box) => {
lifted.insert(node, inline_box);
@@ -5763,7 +5761,6 @@ impl LayoutNodeArena {
pub(crate) fn inline_box_lifted_out_of(&self, node: NodeSlotId) -> Option<NodeSlotId> {
self.inline_boxes_lifted_out_of
- .borrow()
.get(&node)
.copied()
.filter(|&inline_box| self.slot_is_live(inline_box))
@@ -5818,14 +5815,18 @@ impl LayoutNodeArena {
}
}
- pub(crate) fn enroll_text_children_for_content_sync(&self, parent: NodeSlotId) {
+ pub(crate) fn enroll_text_children_for_content_sync(&mut self, parent: NodeSlotId) {
let mut child = self.data(parent).first_child.get();
while !child.is_invalid() {
let data = self.data(child);
- if crate::layout::node_facts::kind_is_text(data.kind.get()) {
+ let (is_text, next_sibling) = (
+ crate::layout::node_facts::kind_is_text(data.kind.get()),
+ data.next_sibling.get(),
+ );
+ if is_text {
self.enroll_text_node_for_content_sync(child);
}
- child = data.next_sibling.get();
+ child = next_sibling;
}
}
diff --git a/Libraries/LibWeb/Rust/src/layout/rendered_text.rs b/Libraries/LibWeb/Rust/src/layout/rendered_text.rs
index 24a940404a8..99ef6681641 100644
--- a/Libraries/LibWeb/Rust/src/layout/rendered_text.rs
+++ b/Libraries/LibWeb/Rust/src/layout/rendered_text.rs
@@ -113,32 +113,43 @@ fn transform_uses_locale(transform: u8) -> bool {
/// Enrolls the text under `root` whose casing or loose line breaking depends on its language, and answers whether there was
/// any. This only enrolls text; source views are requested after DOM language invalidation completes.
-pub(crate) fn enroll_text_after_language_change(arena: &LayoutNodeArena, root: NodeSlotId) -> bool {
- let mut changed = false;
- let mut enroll = |node| {
+pub(crate) fn enroll_text_after_language_change(arena: &mut LayoutNodeArena, root: NodeSlotId) -> bool {
+ let depends_on_language = |arena: &LayoutNodeArena, node: NodeSlotId| {
if !super::node_facts::kind_is_text(arena.data(node).kind.get()) {
- return;
+ return false;
}
let parent = arena.data(node).parent.get();
- if !parent.is_invalid()
+ !parent.is_invalid()
&& arena.style_payloads(parent).is_some_and(|style| {
let values = ComputedValuesView::new(&style.groups);
transform_uses_locale(values.inherited_text().text_transform)
|| values.line_break() == crate::css::css_enums::line_break::LOOSE
})
- {
- arena.enroll_text_node_for_content_sync(node);
- changed = true;
- }
};
- if super::node_facts::kind_is_text(arena.data(root).kind.get()) {
- for &node in arena.text_fragments(root).as_slice() {
- enroll(node);
+ let mut enrolled = Vec::new();
+ {
+ let arena: &LayoutNodeArena = arena;
+ if super::node_facts::kind_is_text(arena.data(root).kind.get()) {
+ enrolled.extend(
+ arena
+ .text_fragments(root)
+ .as_slice()
+ .iter()
+ .copied()
+ .filter(|&node| depends_on_language(arena, node)),
+ );
+ } else {
+ arena.for_each_node_in_layout_subtree_in_pre_order(root, |node| {
+ if depends_on_language(arena, node) {
+ enrolled.push(node);
+ }
+ });
}
- } else {
- arena.for_each_node_in_layout_subtree_in_pre_order(root, enroll);
}
- changed
+ for &node in &enrolled {
+ arena.enroll_text_node_for_content_sync(node);
+ }
+ !enrolled.is_empty()
}
#[derive(Clone)]
diff --git a/Libraries/LibWeb/Rust/src/layout/tree_builder.rs b/Libraries/LibWeb/Rust/src/layout/tree_builder.rs
index 06f58862e95..d790f61bf4d 100644
--- a/Libraries/LibWeb/Rust/src/layout/tree_builder.rs
+++ b/Libraries/LibWeb/Rust/src/layout/tree_builder.rs
@@ -148,7 +148,7 @@ pub enum FfiElementLayoutKind {
fn apply_replaced_display_adjustment(
host_calls: HostCalls<'_>,
- arena: &LayoutNodeArena,
+ arena: &mut LayoutNodeArena,
node: NodeSlotId,
adjustment: FfiReplacedElementDisplayAdjustment,
) {
@@ -1413,8 +1413,9 @@ impl TreeBuildJob {
.expect("the document element's box publishes its style during the build")
.misc_reset()
.scrollbar_width;
- host.arena()
- .update_layout_style(host.host_calls(), document_layout_node, |style| {
+ let host_calls = host.host_calls();
+ host.arena_mut()
+ .update_layout_style(host_calls, document_layout_node, |style| {
style.set_scrollbar_width(scrollbar_width);
});
}
@@ -2620,7 +2621,7 @@ fn update_principal_node_after_entry(
}
let adjustment = replaced_element_display_adjustment(host, layout_node);
if adjustment != FfiReplacedElementDisplayAdjustment::None {
- apply_replaced_display_adjustment(host.host_calls(), host.arena(), layout_node, adjustment);
+ apply_replaced_display_adjustment(host.host_calls(), host.arena_mut(), layout_node, adjustment);
}
let old_layout_node = update.old_layout_node;
@@ -3169,11 +3170,12 @@ fn stamp_pseudo_element_box_row(
.and_then(node_kind_for_display)?,
};
let slot = host.arena.allocate_unbound();
- host.arena()
+ host.arena_mut()
.stamp_pseudo_element_row(slot, kind, generator, generated_for);
if decision == FfiPseudoElementDecision::Contents {
- host.arena()
- .make_display_contents_pseudo_element_box_inline(host.host_calls(), slot);
+ let host_calls = host.host_calls();
+ host.arena_mut()
+ .make_display_contents_pseudo_element_box_inline(host_calls, slot);
}
if is_list_item_marker {
host.arena()
@@ -3212,7 +3214,7 @@ fn stamp_nested_list_marker_row(
LayoutStyle::from_record(engine, record).intern(engine)
});
let slot = host.arena.allocate_unbound();
- host.arena()
+ host.arena_mut()
.stamp_anonymous_box(slot, NodeKind::ListItemMarkerBox, derived);
host.arena()
.set_node_generated_for(slot, generated_for_of(pseudo_element), Some(generator));
@@ -3271,7 +3273,7 @@ fn create_generated_content_item(
),
);
let slot = host.arena.allocate_unbound();
- host.arena().stamp_anonymous_box(slot, NodeKind::ImageBox, derived);
+ host.arena_mut().stamp_anonymous_box(slot, NodeKind::ImageBox, derived);
host.arena()
.set_node_generated_for(slot, generated_for_of(pseudo_element), Some(generator));
host.arena_mut().owe_image_resources(
@@ -3335,7 +3337,7 @@ fn create_pseudo_element(
if decision == FfiPseudoElementDecision::ContentReplacement {
let adjustment = replaced_element_display_adjustment(host, layout_node);
if adjustment != FfiReplacedElementDisplayAdjustment::None {
- apply_replaced_display_adjustment(host.host_calls(), host.arena(), layout_node, adjustment);
+ apply_replaced_display_adjustment(host.host_calls(), host.arena_mut(), layout_node, adjustment);
}
}
@@ -3651,7 +3653,7 @@ impl<'a> TreeBuilderHost<'a> {
/// record the element published. A fieldset and a media element adjust their box as it is built.
fn create_element_box(&mut self, element: StyleNodeID, kind: NodeKind, record: u64) -> NodeSlotId {
let slot = self.stamp_dom_box(kind, Some(element));
- self.arena().stamp_published_style(slot, record);
+ self.arena_mut().stamp_published_style(slot, record);
match kind {
// https://html.spec.whatwg.org/multipage/rendering.html#the-fieldset-and-legend-elements
// If the computed outer display type is inline, the fieldset is expected to behave as inline-block.
@@ -3659,7 +3661,8 @@ impl<'a> TreeBuilderHost<'a> {
NodeKind::FieldSetBox => {
let display = self.style(slot).map(|style| style.display());
if let Some(display) = display.filter(FfiDisplay::is_flow_inside) {
- self.arena().update_layout_style(self.host_calls(), slot, |style| {
+ let host_calls = self.host_calls();
+ self.arena_mut().update_layout_style(host_calls, slot, |style| {
style.set_display(FfiDisplay::outside_and_inside(
display.outside,
crate::css::css_enums::display_inside::FLOW_ROOT,
@@ -3693,7 +3696,7 @@ impl<'a> TreeBuilderHost<'a> {
/// row.
fn stamp_dom_box(&mut self, kind: NodeKind, style_node: Option<StyleNodeID>) -> NodeSlotId {
let slot = self.arena.allocate_unbound();
- self.arena().stamp_dom_row(slot, kind, style_node);
+ self.arena_mut().stamp_dom_row(slot, kind, style_node);
self.arena().take_over_rows_of_bound_node(slot);
slot
}
@@ -3794,8 +3797,9 @@ impl<'a> TreeBuilderHost<'a> {
.arena()
.with_style_store(|engine| engine.element_unique_node_id(document));
self.arena().unique_node_ids().publish(slot, unique_node_id);
- self.arena()
- .apply_reinherited_style_record(self.host_calls(), slot, document_style);
+ let host_calls = self.host_calls();
+ self.arena_mut()
+ .apply_reinherited_style_record(host_calls, slot, document_style);
self.arena().note_built_scroll_container(slot);
slot
}
@@ -3826,7 +3830,7 @@ impl<'a> TreeBuilderHost<'a> {
.arena()
.derive_anonymous_style_record(parent_style_record, style_kind, overrides);
let slot = self.arena.allocate_unbound();
- self.arena().stamp_anonymous_box(slot, node_kind, derived);
+ self.arena_mut().stamp_anonymous_box(slot, node_kind, derived);
self.arena().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 {
@@ -4382,12 +4386,10 @@ fn insert_node_into_inline_or_block_ancestor(
} else {
insertion_parent_for_block_node(host, state, nearest_insertion_ancestor, node_slot, mode, identity)
};
- host.arena().note_inline_box_lifted_out_of(
- node_slot,
- (insertion_point != nearest_insertion_ancestor
- && host.data(nearest_insertion_ancestor).kind.get() == NodeKind::InlineNode)
- .then_some(nearest_insertion_ancestor),
- );
+ let lifted_out_of = (insertion_point != nearest_insertion_ancestor
+ && host.data(nearest_insertion_ancestor).kind.get() == NodeKind::InlineNode)
+ .then_some(nearest_insertion_ancestor);
+ host.arena_mut().note_inline_box_lifted_out_of(node_slot, lifted_out_of);
// Insertion parents can be above the subtree being rebuilt in place: inline ancestors are
// skipped, and out-of-flow boxes can join a trailing anonymous sibling. InDomOrder is selected
@@ -4561,7 +4563,8 @@ fn create_first_letter_boxes(host: &mut TreeBuilderHost<'_>, element: StyleNodeI
let text = host.arena().node_style_node(text_node);
let remainder_slice = host.stamp_dom_box(NodeKind::TextNode, text);
let first_letter_slice = host.arena.allocate_unbound();
- host.arena().stamp_dom_row(first_letter_slice, NodeKind::TextNode, text);
+ host.arena_mut()
+ .stamp_dom_row(first_letter_slice, NodeKind::TextNode, text);
host.arena()
.note_rows_share_dom_node(remainder_slice, first_letter_slice);
(first_letter_slice, remainder_slice)
@@ -4609,7 +4612,7 @@ fn create_first_letter_boxes(host: &mut TreeBuilderHost<'_>, element: StyleNodeI
}
let wrapper_slot = host.arena.allocate_unbound();
- host.arena()
+ host.arena_mut()
.stamp_pseudo_element_row(wrapper_slot, wrapper_kind, element, GENERATED_FOR_FIRST_LETTER);
host.note_style_of_built_row(wrapper_slot, None);
host.arena_mut().owe_image_resources(
@@ -4683,7 +4686,7 @@ fn create_writing_suggestion_boxes(host: &mut TreeBuilderHost<'_>, element: Styl
// becoming the row the node is bound to.
let trailing_slice = host.stamp_dom_box(NodeKind::TextNode, Some(suggestion.text));
let leading_slice = host.arena.allocate_unbound();
- host.arena()
+ host.arena_mut()
.stamp_dom_row(leading_slice, NodeKind::TextNode, Some(suggestion.text));
host.arena().note_rows_share_dom_node(trailing_slice, leading_slice);
for slice in [leading_slice, trailing_slice] {
@@ -4882,13 +4885,13 @@ fn wrap_fieldset_contents_if_needed(host: &mut TreeBuilderHost<'_>, layout_node:
overflow_y: style.box_values().overflow_y,
columns_from_parent: true,
};
- host.arena()
- .update_layout_style(host.host_calls(), layout_node, |style| {
- style.set_overflow(
- crate::css::css_enums::overflow::VISIBLE,
- crate::css::css_enums::overflow::VISIBLE,
- );
- });
+ let host_calls = host.host_calls();
+ host.arena_mut().update_layout_style(host_calls, layout_node, |style| {
+ style.set_overflow(
+ crate::css::css_enums::overflow::VISIBLE,
+ crate::css::css_enums::overflow::VISIBLE,
+ );
+ });
let wrapper = host.create_anonymous_box(
layout_node,
AnonymousStyleKind::FieldsetContentWrapper,
@@ -5294,8 +5297,9 @@ fn generate_missing_parents(host: &mut TreeBuilderHost<'_>, root: LayoutNode) ->
AnonymousStyleOverrides::default(),
NodeKind::TableWrapper,
);
- host.arena()
- .reset_table_box_style_used_by_wrapper(host.host_calls(), table_root);
+ let host_calls = host.host_calls();
+ host.arena_mut()
+ .reset_table_box_style_used_by_wrapper(host_calls, table_root);
let wrapper_slot = wrapper.slot();
host.move_child(table_root, wrapper_slot, NodeSlotId::INVALID);
host.attach_child(parent, wrapper, nearest_sibling);
diff --git a/Libraries/LibWeb/Rust/src/layout/viewport_propagation.rs b/Libraries/LibWeb/Rust/src/layout/viewport_propagation.rs
index 48b6d5ae608..3bde053266b 100644
--- a/Libraries/LibWeb/Rust/src/layout/viewport_propagation.rs
+++ b/Libraries/LibWeb/Rust/src/layout/viewport_propagation.rs
@@ -303,20 +303,21 @@ pub(crate) fn decide_viewport_propagation(facts: &ViewportPropagationFacts) -> O
/// layout pass's style borrows.
pub(crate) fn propagate_root_styles_to_viewport(
host_calls: crate::layout::tree_mutation::HostCalls<'_>,
- arena: &LayoutNodeArena,
+ arena: &mut LayoutNodeArena,
viewport: NodeSlotId,
facts: &ViewportPropagationFacts,
) {
assert!(!viewport.is_invalid());
- let apply_overflow = |node: NodeSlotId, (x, y): (u8, u8)| {
+ let apply_overflow = |arena: &mut LayoutNodeArena, node: NodeSlotId, (x, y): (u8, u8)| {
arena.update_layout_style(host_calls, node, |style| style.set_overflow(x, y));
};
- let apply_writing_mode_and_direction = |node: NodeSlotId, writing_mode: u8, direction: u8| {
- arena.update_layout_style(host_calls, node, |style| {
- style.set_writing_mode_and_direction(writing_mode, direction);
- });
- };
- let apply_viewport_overscroll_behavior = |(x, y): (u8, u8)| {
+ let apply_writing_mode_and_direction =
+ |arena: &mut LayoutNodeArena, node: NodeSlotId, writing_mode: u8, direction: u8| {
+ arena.update_layout_style(host_calls, node, |style| {
+ style.set_writing_mode_and_direction(writing_mode, direction);
+ });
+ };
+ let apply_viewport_overscroll_behavior = |arena: &mut LayoutNodeArena, (x, y): (u8, u8)| {
let mut changed = false;
arena.update_layout_style(host_calls, viewport, |style| {
style.set_overscroll_behavior(x, y);
@@ -330,22 +331,22 @@ pub(crate) fn propagate_root_styles_to_viewport(
};
let Some(styles) = decide_viewport_propagation(facts) else {
- apply_overflow(viewport, (overflow::AUTO, overflow::AUTO));
- apply_viewport_overscroll_behavior((overscroll_behavior::AUTO, overscroll_behavior::AUTO));
+ apply_overflow(arena, viewport, (overflow::AUTO, overflow::AUTO));
+ apply_viewport_overscroll_behavior(arena, (overscroll_behavior::AUTO, overscroll_behavior::AUTO));
return;
};
let root = facts.root_layout_node;
- apply_writing_mode_and_direction(root, styles.writing_mode, styles.direction);
+ apply_writing_mode_and_direction(arena, root, styles.writing_mode, styles.direction);
// https://drafts.csswg.org/css-writing-modes-4/#icb
// The principal writing mode is propagated to the initial containing block and to the
// viewport, thereby affecting the layout of the root element and the scrolling direction of
// the viewport.
- apply_writing_mode_and_direction(viewport, styles.writing_mode, styles.direction);
- apply_overflow(viewport, styles.viewport_overflow);
- apply_viewport_overscroll_behavior(styles.viewport_overscroll_behavior);
- apply_overflow(root, styles.root_overflow);
+ apply_writing_mode_and_direction(arena, viewport, styles.writing_mode, styles.direction);
+ apply_overflow(arena, viewport, styles.viewport_overflow);
+ apply_viewport_overscroll_behavior(arena, styles.viewport_overscroll_behavior);
+ apply_overflow(arena, root, styles.root_overflow);
if let Some(body_overflow) = styles.body_overflow {
- apply_overflow(facts.body_layout_node, body_overflow);
+ apply_overflow(arena, facts.body_layout_node, body_overflow);
}
}
diff --git a/Libraries/LibWeb/Rust/src/painting/paintable_build.rs b/Libraries/LibWeb/Rust/src/painting/paintable_build.rs
index dd0384f6944..8f5c9e7e82b 100644
--- a/Libraries/LibWeb/Rust/src/painting/paintable_build.rs
+++ b/Libraries/LibWeb/Rust/src/painting/paintable_build.rs
@@ -134,7 +134,7 @@ impl<'a> PaintableCommit<'a> {
let row_existed_before_this_commit = self.arena().paintable_rows().paintable_row_is_populated(node);
let previous_offset = row_existed_before_this_commit.then(|| self.arena().live_paintable_data(node).offset);
if !wants_paintable {
- self.arena().clear_committed_fragment_link(node);
+ self.arena_mut().clear_committed_fragment_link(node);
if row_existed_before_this_commit {
let reset = {
let arena = self.arena();
@@ -166,7 +166,7 @@ impl<'a> PaintableCommit<'a> {
};
}
if !has_used_values {
- self.arena().clear_committed_fragment_link(node);
+ self.arena_mut().clear_committed_fragment_link(node);
// Fragmented inlines get their painted pieces from the enclosing line root.
let inline_paint_changed = enclosing_line_root_changes.inline_content_changed
|| (enclosing_line_root_changes.fragment_changed && has_descendant_dependent_paint(self.arena(), node));
diff --git a/Libraries/LibWeb/Rust/src/render_state.rs b/Libraries/LibWeb/Rust/src/render_state.rs
index ec83b34fe89..09a3c5bada8 100644
--- a/Libraries/LibWeb/Rust/src/render_state.rs
+++ b/Libraries/LibWeb/Rust/src/render_state.rs
@@ -237,7 +237,7 @@ impl RenderState {
};
// What applying the rows owes the host, the host's install of the rows makes good again.
let work = OwedHostWork::default();
- let Ok(applied) = self.arena.arena().apply_flight_style_rows(HostCalls(&work), rows) else {
+ let Ok(applied) = self.arena.arena_mut().apply_flight_style_rows(HostCalls(&work), rows) else {
return (Vec::new(), None);
};
(applied, self.run_round(round, work))
diff --git a/Libraries/LibWeb/Rust/src/render_state/clock.rs b/Libraries/LibWeb/Rust/src/render_state/clock.rs
index 6b7e5fa63ce..21e88fbf51b 100644
--- a/Libraries/LibWeb/Rust/src/render_state/clock.rs
+++ b/Libraries/LibWeb/Rust/src/render_state/clock.rs
@@ -884,7 +884,7 @@ impl Lane {
continue;
}
};
- let arena = state.arena.arena();
+ let arena = state.arena.arena_mut();
if let Some(host_style) = arena.install_sample(row, restyled, crate::layout::SampleKind::Animation)? {
self.ticked.push((row, host_style));
}
@@ -907,7 +907,13 @@ impl Lane {
if rebuilds.len() > 1 {
let resampled: SmallVec<[StyleNodeID; 8]> = self.resampled_elements().collect();
let (ticked, restyles) = (&mut self.ticked, &mut self.restyles_built_again);
- restore_samples_for_build(state.arena.arena(), ticked, Some(&resampled), restyles, |_, _| true)?;
+ restore_samples_for_build(
+ state.arena.arena_mut(),
+ ticked,
+ Some(&resampled),
+ restyles,
+ |_, _, _| true,
+ )?;
self.samples_restored = true;
}
for (node, rebuild) in rebuilds {
@@ -950,7 +956,7 @@ impl Lane {
let in_place = !parent_row.is_invalid() && build_keeps_box(arena, parent, CHILD_LIST_INSERTION);
if in_place {
// The anonymous boxes the build makes in the parent's box inherit what it shows.
- restore_samples_for_build(arena, ticked, Some(&resampled), restyles, |row, host_style| {
+ restore_samples_for_build(arena, ticked, Some(&resampled), restyles, |arena, row, host_style| {
nearest_element_box(arena, row) == Some(parent_row)
&& arena.shows_other_inherited_style_than(row, host_style.record())
})?;
@@ -963,7 +969,9 @@ impl Lane {
if in_place {
// The boxes the build takes away show nothing more.
let row = arena.bound_row(node);
- restore_samples_for_build(arena, ticked, None, restyles, |inner, _| box_holds(arena, row, inner))?;
+ restore_samples_for_build(arena, ticked, None, restyles, |arena, inner, _| {
+ box_holds(arena, row, inner)
+ })?;
arena.mark_layout_tree_update(Some(node), style_change_mark(0));
}
in_place
@@ -1000,15 +1008,24 @@ fn nearest_element_box(arena: &LayoutNodeArena, row: NodeSlotId) -> Option<NodeS
/// another, the record a size query decided for it, goes in `restyles` with that record, which the box the build makes
/// for it shows again. An anonymous box that shows such a record only the host builds.
fn restore_samples_for_build(
- arena: &LayoutNodeArena,
+ arena: &mut LayoutNodeArena,
ticked: &mut Vec<(NodeSlotId, HostStyle)>,
resampled: Option<&[StyleNodeID]>,
restyles: &mut Vec<(StyleNodeID, u64)>,
- holds: impl Fn(NodeSlotId, &HostStyle) -> bool,
+ holds: impl Fn(&LayoutNodeArena, NodeSlotId, &HostStyle) -> bool,
) -> Result<(), Park> {
+ let held: SmallVec<[bool; 16]> = ticked
+ .iter()
+ .map(|(row, host_style)| holds(arena, *row, host_style))
+ .collect();
if let Some(resampled) = resampled {
let mut kept_restyles: SmallVec<[(StyleNodeID, u64); 4]> = SmallVec::new();
- for (row, _) in ticked.iter().filter(|(row, host_style)| holds(*row, host_style)) {
+ for (row, _) in ticked
+ .iter()
+ .zip(&held)
+ .filter(|(_, held)| **held)
+ .map(|(ticked, _)| ticked)
+ {
let element = nearest_element_box(arena, *row).and_then(|box_| arena.dom_node_style_node(box_));
if element.is_some_and(|element| resampled.contains(&element)) {
continue;
@@ -1025,7 +1042,8 @@ fn restore_samples_for_build(
});
restyles.extend(kept_restyles);
}
- for (row, host_style) in ticked.extract_if(.., |(row, host_style)| holds(*row, host_style)) {
+ let mut held = held.into_iter();
+ for (row, host_style) in ticked.extract_if(.., |_| held.next().expect("each ticked row was asked once")) {
arena.restore_host_style(row, host_style, crate::layout::StyleRelayout::ByLayoutAffectingGroups);
arena.push_paint_damage_for_repaint(row, PaintDamage::ALL_PRODUCERS);
}
@@ -1046,7 +1064,7 @@ fn mark_region_for_tree_build(
use crate::css::style::bridge::element_adjustment_fact::{
IS_DOCUMENT_ELEMENT, IS_HTML_BODY_ELEMENT, RENDERED_IN_TOP_LAYER,
};
- let arena = state.arena.arena();
+ let arena = state.arena.arena_mut();
let row = arena.bound_row(root);
let parent = match row.is_invalid() {
true => NodeSlotId::INVALID,
@@ -1059,7 +1077,7 @@ fn mark_region_for_tree_build(
{
return Err(Park("a rebuilt box the host places"));
}
- restore_samples_for_build(arena, ticked, Some(resampled), restyles, |inner, _| {
+ restore_samples_for_build(arena, ticked, Some(resampled), restyles, |arena, inner, _| {
box_holds(arena, row, inner)
})?;
arena.mark_layout_tree_update(Some(root), style_change_mark(0));
@@ -1338,7 +1356,7 @@ impl Lane {
let mut owed = Vec::new();
let built = self.plan.round.build(&mut state.arena, &mut owed);
let restyles = std::mem::take(&mut self.restyles_built_again);
- let arena = state.arena.arena();
+ let arena = state.arena.arena_mut();
let mut shown = Ok(());
for (element, record) in restyles {
let row = arena.bound_row(element);
diff --git a/Libraries/LibWeb/Rust/src/render_state/clock/effects.rs b/Libraries/LibWeb/Rust/src/render_state/clock/effects.rs
index 053c225d44e..0218241eda1 100644
--- a/Libraries/LibWeb/Rust/src/render_state/clock/effects.rs
+++ b/Libraries/LibWeb/Rust/src/render_state/clock/effects.rs
@@ -450,7 +450,7 @@ impl Lane {
let damage = node.map_or(0, |node| {
engine.element_record_damage(node, false, shown, sample.record)
}) | engine.sampled_properties_damage(shown, sample.record, properties);
- let arena = state.arena.arena();
+ let arena = state.arena.arena_mut();
let host_style = arena.install_sample_beside_anonymous_boxes(row, sample, StyleRelayout::ByDamage(damage));
// The box shows what the sample of transitions the hover started animates of what the compositor animates, in
// place of the compositor. The compositor runs the host's animations as the ticks sample them, and on once the
@@ -804,7 +804,7 @@ impl Lane {
let damage = state
.engine_mut()
.sampled_properties_damage(shown, host_style.record(), properties);
- let arena = state.arena.arena();
+ let arena = state.arena.arena_mut();
arena.restore_host_style(row, host_style, StyleRelayout::ByDamage(damage));
arena.note_style_visual_context_moves(row, damage);
arena.push_paint_damage_for_repaint(row, PaintDamage::ALL_PRODUCERS);
diff --git a/Libraries/LibWeb/Rust/src/render_state/clock/hover.rs b/Libraries/LibWeb/Rust/src/render_state/clock/hover.rs
index 4895f9b047e..3ef5d9dd7ac 100644
--- a/Libraries/LibWeb/Rust/src/render_state/clock/hover.rs
+++ b/Libraries/LibWeb/Rust/src/render_state/clock/hover.rs
@@ -945,7 +945,7 @@ impl Lane {
}
let installs = state.engine_mut().install_hover_wave(&wave);
made.installed |= !settles_back;
- let arena = state.arena.arena();
+ let arena = state.arena.arena_mut();
let work = OwedHostWork::default();
// The installs cannot call the host, which never hears of the boxes of the lane's fork they touched.
arena.queue_box_presence();