Truly independent web browser
LibWeb: Fold the paintable commit into the layout commit
Aliaksandr Kalenikd3b3410ef30b
diff --git a/Libraries/LibWeb/Rust/build.rs b/Libraries/LibWeb/Rust/build.rsindex 01c8f108db3..bb701f7206b 100644--- a/Libraries/LibWeb/Rust/build.rs+++ b/Libraries/LibWeb/Rust/build.rs@@ -3156,7 +3156,6 @@ fn main() -> Result<(), Box<dyn Error>> {manifest_dir.join("src/layout/line_box.rs"),manifest_dir.join("src/layout/line_box_fragment.rs"),manifest_dir.join("src/painting/paintable_data.rs"),- manifest_dir.join("src/painting/paintable_build.rs"),manifest_dir.join("src/painting/host/mod.rs"),manifest_dir.join("src/painting/host/visual_context.rs"),manifest_dir.join("src/painting/host/hit_test.rs"),diff --git a/Libraries/LibWeb/Rust/src/layout/commit.rs b/Libraries/LibWeb/Rust/src/layout/commit.rsindex 3b8b80e4cb1..a6aed9736a3 100644--- a/Libraries/LibWeb/Rust/src/layout/commit.rs+++ b/Libraries/LibWeb/Rust/src/layout/commit.rs@@ -6,6 +6,12 @@use super::*;use crate::css::style::tree::StyleNodeID;+use crate::layout::node_data::DomPaintFact;+use crate::painting::node_painting;+use crate::painting::paint_read::PaintRead;+use crate::painting::paintable_rows::PaintableRowReset;+use crate::painting::record::damage::PaintDamage;+use crate::painting::visual_context::dirty::VisualContextBoxDirtyKind;/// What a commit message tells the document.#[derive(Clone, Copy, Debug, PartialEq, Eq)]@@ -70,7 +76,7 @@ impl FfiCommitMessage {/// Host notifications contain no arena borrows. Dispatch them only after the/// mutation phase returns, since C++ can reenter Rust to read or update paint state.pub(crate) struct CommitNotifications {- row_resets: Vec<crate::painting::paintable_rows::PaintableRowReset>,+ row_resets: Vec<PaintableRowReset>,messages: Vec<FfiCommitMessage>,}@@ -114,6 +120,84 @@ impl CommitNotifications {}}+#[derive(Clone, Copy, Debug)]+struct PreparedPaintable {+ has_paintable_row: bool,+ row_existed_before_this_commit: bool,+ previous_offset: Option<used_values::FfiCssPixelPoint>,+}++struct ReplacedCommittedFragmentLink {+ content_size_change: Option<(used_values::FfiCssPixelSize, used_values::FfiCssPixelSize)>,+ line_root_changes: LineRootChanges,+}++#[derive(Clone, Copy, Default)]+struct LineDataChange {+ content_changed: bool,+ item_order_changed: bool,+}++#[derive(Clone, Copy, Default)]+struct LineRootChanges {+ fragment_changed: bool,+ inline_content_changed: bool,+ inline_item_order_changed: bool,+}++impl LineRootChanges {+ fn all() -> Self {+ Self {+ fragment_changed: true,+ inline_content_changed: true,+ inline_item_order_changed: true,+ }+ }++ fn any(self) -> bool {+ self.fragment_changed || self.inline_content_changed || self.inline_item_order_changed+ }+}++fn same_inline_content(left: &fragment_tree::Fragment, right: &fragment_tree::Fragment) -> bool {+ match (&left.line_data, &right.line_data) {+ (None, None) => true,+ (Some(left), Some(right)) => std::sync::Arc::ptr_eq(left, right) || left == right,+ _ => false,+ }+}++fn has_descendant_dependent_paint(arena: &LayoutNodeArena, node: NodeSlotId) -> bool {+ let kind = arena.data(node).kind.get();+ if node_painting::is_svg(kind)+ || matches!(+ kind,+ NodeKind::FieldSetBox | NodeKind::SVGSVGBox | NodeKind::SVGForeignObjectBox+ )+ {+ return true;+ }+ let Some(style) = arena.node_style_if_live(node) else {+ return true;+ };+ let display = style.display();+ if display.is_table_inside() || display.is_internal_table() || kind == NodeKind::TableWrapper {+ return true;+ }+ // A text-clipped background can collect glyphs from multiple descendant line roots.+ fn clips_text(value: &crate::css::style_value::StyleValueData) -> bool {+ use crate::css::{css_enums, style_value::StyleValueData};+ match value {+ StyleValueData::Keyword { keyword } => {+ css_enums::keyword_to_background_box(*keyword) == Some(css_enums::background_box::TEXT)+ }+ StyleValueData::ValueList { values, .. } => values.as_slice().iter().any(|value| clips_text(value.data())),+ _ => false,+ }+ }+ crate::painting::style_queries::handle_value(&style.background().background_clip).is_some_and(clips_text)+}+/// The fragment holding the links a commit meets: a box's fragment, or the top of the pass.#[derive(Clone, Copy)]struct Holder {@@ -123,7 +207,7 @@ struct Holder {fragment_index: Option<u32>,/// How many lines the box's earlier fragments hold, by which the fragment's line indices count on.line_index_offset: usize,- line_root_changes: crate::painting::paintable_build::LineRootChanges,+ line_root_changes: LineRootChanges,}impl Holder {@@ -151,7 +235,7 @@ impl Holder {struct BrokenBox<'tree> {fragments: fragment_tree::SlotFragments<'tree>,line_count: usize,- enclosing_line_root_changes: crate::painting::paintable_build::LineRootChanges,+ enclosing_line_root_changes: LineRootChanges,}/// A box a commit committed anew, with the fragments it committed before, whose links the commit clears unless it met@@ -166,8 +250,10 @@ struct RecommittedBox {/// changed. The fragment of a box whose committed link it meets again unchanged, in geometry still current, holds the/// links its subtree committed, so the walk leaves that subtree as it is.struct Commit<'arena, 'tree> {- paintables: crate::painting::paintable_build::PaintableCommit<'arena>,+ arena: &'arena mut LayoutNodeArena,messages: Vec<FfiCommitMessage>,+ row_reset_notifications: Vec<PaintableRowReset>,+ committed_navigable_container_viewports: Vec<Node>,/// The number of this commit, which tells the links it met from those it did not.number: u32,root: Node,@@ -178,16 +264,20 @@ struct Commit<'arena, 'tree> {broken_box_order: Vec<Node>,out_of_flow_boxes: Vec<(Node, std::sync::Arc<crate::layout::abspos_inputs::AbsposLayoutInputs>)>,pass_level_links: Vec<Node>,- line_roots: Vec<(Node, crate::painting::paintable_build::LineRootChanges)>,+ line_roots: Vec<(Node, LineRootChanges)>,}impl<'tree> Commit<'_, 'tree> {fn arena(&self) -> &LayoutNodeArena {- self.paintables.arena()+ self.arena}fn arena_mut(&mut self) -> &mut LayoutNodeArena {- self.paintables.arena_mut()+ self.arena+ }++ fn discard_absolute_rects_memoized_during_commit(&mut self) {+ self.arena_mut().clear_absolute_rect_memo();}fn was_met(&self, node: Node) -> bool {@@ -330,7 +420,7 @@ impl<'tree> Commit<'_, 'tree> {node,fragment_index: Some(fragment_index),line_index_offset: lines_before,- line_root_changes: crate::painting::paintable_build::LineRootChanges::all(),+ line_root_changes: LineRootChanges::all(),};for child in &link.fragment.children {self.meet(child, &children_holder);@@ -370,7 +460,7 @@ impl<'tree> Commit<'_, 'tree> {&mut self,node: Node,fragments: fragment_tree::SlotFragments<'tree>,- enclosing_line_root_changes: crate::painting::paintable_build::LineRootChanges,+ enclosing_line_root_changes: LineRootChanges,) -> Option<Holder> {let first = fragments.first().expect("a committed box has a fragment");let link_with_merged_line_index;@@ -435,9 +525,7 @@ impl<'tree> Commit<'_, 'tree> {.and_then(|previous| previous.previous_inline_content.clone())}).flatten();- let prepared = self- .paintables- .prepare_node(node, true, keeps_committed_subtree, enclosing_line_root_changes);+ let prepared = self.prepare_node(node, true, keeps_committed_subtree, enclosing_line_root_changes);self.committed_anew.push(node);if let Some(previous) = previous {self.recommitted.push(previous);@@ -457,13 +545,9 @@ impl<'tree> Commit<'_, 'tree> {|| !crate::painting::node_painting::is_svg_path(self.arena().data(node).kind.get()),"committed path-like fragment carries no computed SVG path");- let replaced = self.paintables.replace_committed_fragment_link(- node,- link,- enclosing_line_root_changes,- prepared.previous_offset,- );- self.paintables.set_box_fragments(node, &fragments);+ let replaced =+ self.replace_committed_fragment_link(node, link, enclosing_line_root_changes, prepared.previous_offset);+ self.set_box_fragments(node, &fragments);let mut line_root_changes_for_children = enclosing_line_root_changes;if fragment.line_data.is_some() {line_root_changes_for_children = replaced.line_root_changes;@@ -499,7 +583,7 @@ impl<'tree> Commit<'_, 'tree> {}).flatten();if let Some(line_data) = merged_line_data.as_ref().or(fragment.line_data.as_ref()) {- let change = self.paintables.set_line_data(+ let change = self.set_line_data(node,line_data,previous_fragmented_content,@@ -509,7 +593,7 @@ impl<'tree> Commit<'_, 'tree> {line_root_changes_for_children.inline_content_changed |= change.content_changed;line_root_changes_for_children.inline_item_order_changed |= change.item_order_changed;} else {- self.paintables.clear_line_data(node);+ self.clear_line_data(node);}self.arena_mut().gather_layout_style_snapshot_geometry(node);// NB: A link can change what orders the painting of a box that keeps its fragment, such as whether collapsed@@ -524,7 +608,7 @@ impl<'tree> Commit<'_, 'tree> {}/// Notes a box committed anew whose fragment may hold lines, whose inline boxes commit after the walk.- fn finish_box(&mut self, node: Node, line_root_changes: crate::painting::paintable_build::LineRootChanges) {+ fn finish_box(&mut self, node: Node, line_root_changes: LineRootChanges) {if self.arena().paintable_row_is_populated(node)&& self.arena()@@ -537,6 +621,445 @@ impl<'tree> Commit<'_, 'tree> {}}+ /// Clears the committed link and row of a box the commit left without them.+ fn clear_node(&mut self, node: formatting_context::Node) {+ self.arena_mut().clear_committed_fragment_link(node);+ if self.arena().paintable_rows().paintable_row_is_populated(node) {+ let reset = self+ .arena()+ .prepare_paintable_row_cleared_reset(node)+ .expect("live row for node could not be cleared");+ self.row_reset_notifications.push(reset);+ self.arena_mut().paintable_row_cleared(reset);+ }+ }++ fn prepare_node(+ &mut self,+ node: formatting_context::Node,+ has_used_values: bool,+ reuses_committed_subtree: bool,+ enclosing_line_root_changes: LineRootChanges,+ ) -> PreparedPaintable {+ let (wants_paintable, node_kind) = {+ let data = self.arena().data(node);+ let is_fragmented_inline = node_facts::node_is_fragmented_inline(data, node_facts::node_style_view(data));+ let has_dom_node = !node_facts::has_flag(data, crate::layout::node_data::NodeFlag::Anonymous);+ (+ (has_used_values || (is_fragmented_inline && has_dom_node))+ && node_painting::has_paintable(data.kind.get()),+ data.kind.get(),+ )+ };+ 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()+ .with_committed_fragment_link(node, |link| link.map(|link| link.offset))+ })+ .flatten();+ if !wants_paintable {+ self.clear_node(node);+ return PreparedPaintable {+ has_paintable_row: false,+ row_existed_before_this_commit: false,+ previous_offset: None,+ };+ }+ if node_kind == NodeKind::NavigableContainerViewport {+ self.committed_navigable_container_viewports.push(node);+ }+ if reuses_committed_subtree {+ assert!(+ row_existed_before_this_commit,+ "a kept subtree root has no committed row"+ );+ return PreparedPaintable {+ has_paintable_row: true,+ row_existed_before_this_commit: true,+ previous_offset,+ };+ }+ if !has_used_values {+ 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));+ if row_existed_before_this_commit && inline_paint_changed {+ self.arena_mut().push_paint_damage(node, PaintDamage::ALL_PRODUCERS);+ }+ if row_existed_before_this_commit && enclosing_line_root_changes.fragment_changed {+ self.arena_mut()+ .note_visual_context_box_dirty(node, VisualContextBoxDirtyKind::InlineGeometryChanged);+ }+ }+ if row_existed_before_this_commit {+ let notification = self+ .arena()+ .paintable_rows()+ .prepare_paintable_row_recommit_notification(node);+ self.row_reset_notifications.push(notification);+ }+ let arena = self.arena_mut();+ if row_existed_before_this_commit {+ arena.paintable_rows_mut().begin_paintable_row_recommit(node);+ if node_kind == NodeKind::Viewport {+ // A recommitted viewport row starts its paint state over: the scroll registry is+ // dropped here and rebuilt by the next tree update, while the host resets its+ // snapshot from the row reset notification.+ arena.paint_state_mut().visual_context.clear_scroll_state();+ }+ } else {+ arena.populate_paintable_row(node);+ if node_kind == NodeKind::Viewport {+ arena.paint_state_mut().reset_visual_context_state();+ }+ arena.note_visual_context_box_dirty(node, VisualContextBoxDirtyKind::NewRow);+ }+ PreparedPaintable {+ has_paintable_row: true,+ row_existed_before_this_commit,+ previous_offset,+ }+ }++ fn replace_committed_fragment_link(+ &mut self,+ node: formatting_context::Node,+ link: &fragment_tree::FragmentLink,+ enclosing_line_root_changes: LineRootChanges,+ previous_offset: Option<used_values::FfiCssPixelPoint>,+ ) -> ReplacedCommittedFragmentLink {+ let fragment = &link.fragment;+ let new_content_size = fragment.sides.content_size;+ let new_offset = link.offset;+ let mut content_size_change = None;+ let mut own_paint_unchanged = false;+ let mut child_placements_unchanged = false;+ let mut inline_content_unchanged = false;+ let mut inline_item_order_unchanged = false;+ let mut child_sequence_unchanged = false;+ let mut link_shows_box_the_same = true;+ let mut old_scrollable_overflow = crate::layout::fragment_overflow::FragmentScrollableOverflow::default();+ let (old_identity, old_content_size) = self.arena().with_committed_fragment_link(node, |old_link| {+ old_link.map_or((0, used_values::FfiCssPixelSize::default()), |old_link| {+ let previous = &old_link.fragment;+ old_scrollable_overflow = previous.scrollable_overflow;+ if previous.identity == fragment.identity {+ own_paint_unchanged = true;+ child_placements_unchanged = true;+ inline_content_unchanged = true;+ inline_item_order_unchanged = true;+ child_sequence_unchanged = true;+ } else {+ inline_content_unchanged = same_inline_content(fragment, previous);+ inline_item_order_unchanged = inline_content_unchanged+ || match (&fragment.line_data, &previous.line_data) {+ (Some(left), Some(right)) => left.has_same_item_order(right),+ _ => false,+ };+ own_paint_unchanged = inline_content_unchanged+ && fragment.has_same_box_properties(previous)+ && !has_descendant_dependent_paint(self.arena(), node);+ child_placements_unchanged = fragment.has_same_child_placements(previous);+ child_sequence_unchanged = fragment.has_same_child_sequence(previous);+ }+ own_paint_unchanged &= old_link.has_same_placement(link);+ link_shows_box_the_same = link.placement.shown_as == old_link.placement.shown_as;+ (old_link.fragment.identity, old_link.fragment.sides.content_size)+ })+ });+ if old_content_size != new_content_size {+ content_size_change = Some((old_content_size, new_content_size));+ }+ let committed_fragment_identity_changed = old_identity != fragment.identity;+ // Inserted, removed or reordered children change which scopes this row's plans list,+ // independently of where the children were placed.+ if !child_sequence_unchanged {+ self.arena_mut().push_paint_damage(node, PaintDamage::ORDER);+ }+ let painted_geometry_lives_in_enclosing_line_root = {+ let data = self.arena().data(node);+ node_facts::node_is_fragmented_inline(data, node_facts::node_style_view(data))+ };+ let fragment_content_changed = committed_fragment_identity_changed+ || (enclosing_line_root_changes.fragment_changed && painted_geometry_lives_in_enclosing_line_root);+ // Keep fragment identity as the conservative signal for overflow and visual contexts.+ // The fragment stays the same when only the link's margins or parent-decided facts change, but margin-box clip+ // paths, line clamp clips and overflow read those.+ let fragment_content_unchanged = link_shows_box_the_same && old_identity != 0 && !fragment_content_changed;+ let offset_unchanged = previous_offset == Some(new_offset);+ let enclosing_inline_paint_changed = painted_geometry_lives_in_enclosing_line_root+ && (enclosing_line_root_changes.inline_content_changed+ || (enclosing_line_root_changes.fragment_changed+ && has_descendant_dependent_paint(self.arena(), node)));+ // A fragmented inline's geometry is read from its line root's pieces. Comparing it with+ // the fragment's temporary offset would dirty identical inlines on every relayout; their+ // line content and box properties suffice.+ let paint_offset_unchanged = offset_unchanged || painted_geometry_lives_in_enclosing_line_root;+ // record_lines_hit_test_items() emits an EmptyEditable target only without paint+ // children. An out-of-flow child can change that eligibility without changing the+ // editor's box properties or inline content, so descendant dirtiness alone is insufficient.+ let empty_editable_children_changed = !child_placements_unchanged+ && node_painting::has_lines(self.arena(), node)+ && self+ .arena()+ .node_has_dom_paint_fact(node, DomPaintFact::EditableOrEditingHost)+ && fragment+ .line_data+ .as_ref()+ .is_none_or(|content| content.fragments.is_empty());+ let mut damage = PaintDamage::NONE;+ if !own_paint_unchanged || enclosing_inline_paint_changed || empty_editable_children_changed {+ damage |= PaintDamage::ALL_PRODUCERS;+ }+ if !inline_item_order_unchanged+ || (painted_geometry_lives_in_enclosing_line_root && enclosing_line_root_changes.inline_item_order_changed)+ {+ damage |= PaintDamage::ORDER;+ }+ if !paint_offset_unchanged {+ damage |= PaintDamage::MOVED;+ }+ self.arena_mut().push_paint_damage(node, damage);+ if !offset_unchanged {+ self.arena_mut()+ .note_visual_context_box_dirty(node, VisualContextBoxDirtyKind::MovedWithDescendants);+ }+ if !fragment_content_unchanged {+ self.arena_mut()+ .note_visual_context_box_dirty(node, VisualContextBoxDirtyKind::RecommittedInPlace);+ }+ if old_scrollable_overflow != fragment.scrollable_overflow {+ self.arena_mut().note_scrollable_overflow_change(+ node,+ old_scrollable_overflow.has_scrollable_overflow,+ fragment.scrollable_overflow.has_scrollable_overflow,+ false,+ );+ }+ self.arena_mut().note_scroll_offset_may_leave_range(node);+ // A layout pass bumps no epoch, so its geometry is laid out against the epoch the node has now.+ let epoch_of_laid_out_geometry = self.arena().data(node).fragment_cache_epoch;+ self.arena_mut()+ .set_committed_fragment_link(node, link.clone(), Some(epoch_of_laid_out_geometry));+ ReplacedCommittedFragmentLink {+ content_size_change,+ line_root_changes: LineRootChanges {+ fragment_changed: committed_fragment_identity_changed,+ inline_content_changed: !inline_content_unchanged,+ inline_item_order_changed: !inline_item_order_unchanged,+ },+ }+ }++ fn set_box_fragments(&mut self, slot: NodeSlotId, fragments: &[fragment_tree::SlotFragment<'_>]) {+ let later_fragments = fragments.get(1..).unwrap_or_default();+ let (moved, containing_block_fragment, identical, geometry_unchanged) = {+ let side = self.arena().committed_side_data(slot);+ let containing_block_fragment = fragments+ .first()+ .and_then(|fragment| fragment.containing_block_fragment)+ .unwrap_or(side.containing_block_fragment);+ let first_fragment_moved = side.containing_block_fragment != containing_block_fragment;+ let same_count = !first_fragment_moved && side.box_fragments().len() == later_fragments.len();+ let all_pairs = |same: fn(&fragment_tree::FragmentLink, &fragment_tree::FragmentLink) -> bool| {+ side.box_fragments()+ .iter()+ .zip(later_fragments)+ .all(|(committed, fragment)| {+ Some(committed.containing_block_fragment) == fragment.containing_block_fragment+ && same(fragment.link, &committed.link)+ })+ };+ (+ first_fragment_moved || !all_pairs(|link, committed| link.has_same_placement(committed)),+ containing_block_fragment,+ same_count && all_pairs(|link, committed| link.places_same_fragment_identically_to(committed)),+ same_count+ && all_pairs(|link, committed| {+ link.has_same_placement(committed)+ && link.fragment.has_same_box_properties(&committed.fragment)+ && same_inline_content(&link.fragment, &committed.fragment)+ }),+ )+ };+ let flags = [+ (+ crate::painting::paintable_data::PaintableFlag::InLaterContainingBlockFragment,+ containing_block_fragment != 0,+ ),+ (+ crate::painting::paintable_data::PaintableFlag::HasLaterBoxFragments,+ !later_fragments.is_empty(),+ ),+ ];+ let data = self.arena().live_paintable_data(slot);+ if flags.iter().any(|&(flag, value)| data.has_flag(flag) != value) {+ let arena = self.arena_mut();+ let mut paintable_rows = arena.paintable_rows_mut();+ let mut data = paintable_rows.paintable_data_mut(slot);+ for (flag, value) in flags {+ data.set_flag(flag, value);+ }+ }+ if identical {+ return;+ }+ let (later_overflow_changed, later_fragments_had_scrollable_overflow) = {+ let committed = self.arena().committed_side_data(slot).box_fragments();+ (+ committed.len() != later_fragments.len()+ || committed.iter().zip(later_fragments).any(|(committed, fragment)| {+ committed.link.fragment.scrollable_overflow != fragment.link.fragment.scrollable_overflow+ }),+ committed+ .iter()+ .any(|committed| committed.link.fragment.scrollable_overflow.has_scrollable_overflow),+ )+ };+ if later_overflow_changed {+ let later_fragments_have_scrollable_overflow = later_fragments+ .iter()+ .any(|fragment| fragment.link.fragment.scrollable_overflow.has_scrollable_overflow);+ self.arena_mut().note_scrollable_overflow_change(+ slot,+ later_fragments_had_scrollable_overflow,+ later_fragments_have_scrollable_overflow,+ false,+ );+ }+ {+ let mut side = self.arena_mut().committed_side_data_mut(slot);+ side.containing_block_fragment = containing_block_fragment;+ side.box_fragments = (!later_fragments.is_empty()).then(|| {+ std::sync::Arc::new(+ later_fragments+ .iter()+ .map(|fragment| crate::painting::paintable_data::CommittedBoxFragment {+ link: fragment.link.clone(),+ containing_block_fragment: fragment.containing_block_fragment.unwrap_or_default(),+ })+ .collect(),+ )+ });+ }+ if geometry_unchanged {+ return;+ }+ self.arena_mut()+ .push_paint_damage(slot, PaintDamage::ALL_PRODUCERS | PaintDamage::MOVED);+ self.arena_mut().note_visual_context_box_dirty(+ slot,+ if moved {+ VisualContextBoxDirtyKind::MovedWithDescendants+ } else {+ VisualContextBoxDirtyKind::RecommittedInPlace+ },+ );+ }++ fn set_line_data(+ &mut self,+ slot: NodeSlotId,+ line_data: &std::sync::Arc<crate::layout::inline_content::InlineContent>,+ previous_fragmented_content: Option<std::sync::Arc<crate::layout::inline_content::InlineContent>>,+ content_size: used_values::FfiCssPixelSize,+ ) -> LineDataChange {+ if !node_painting::has_lines(self.arena(), slot) {+ self.clear_line_data(slot);+ return LineDataChange::default();+ }+ let writing_mode = line_data.writing_mode;+ let physical_line_data;+ let line_data = if writing_mode == crate::css::css_enums::writing_mode::HORIZONTAL_TB {+ line_data+ } else {+ physical_line_data = std::sync::Arc::new(line_data.in_physical_plane(writing_mode, content_size));+ &physical_line_data+ };+ let has_pieces = !line_data.inline_box_pieces.is_empty();+ let (content_changed, item_order_changed) = previous_fragmented_content.map_or((false, false), |previous| {+ if std::sync::Arc::ptr_eq(&previous, line_data) || *previous == **line_data {+ return (false, false);+ }+ (true, !previous.has_same_item_order(line_data))+ });+ self.arena_mut().committed_side_data_mut(slot).inline_content = Some(line_data.clone());+ if item_order_changed {+ self.arena_mut().push_paint_damage(slot, PaintDamage::ORDER);+ }+ if has_pieces {+ self.arena_mut().note_line_root_needs_fragment_ownership(slot);+ }+ LineDataChange {+ content_changed,+ item_order_changed,+ }+ }++ /// Clears the inline content of a row whose new fragment has none.+ fn clear_line_data(&mut self, slot: NodeSlotId) {+ if self.arena().committed_side_data(slot).inline_content.is_some() {+ self.arena_mut().committed_side_data_mut(slot).inline_content = None;+ }+ }++ fn committed_containing_block(+ &self,+ node: formatting_context::Node,+ link: Option<&fragment_tree::FragmentLink>,+ ) -> NodeSlotId {+ match link.map(|link| link.placement.containing_block) {+ Some(containing_block) if !containing_block.is_invalid() => containing_block,+ _ => self.arena().containing_block_by_walking_ancestors(node),+ }+ }++ fn stamp_containing_block(&mut self, node: formatting_context::Node, link: Option<&fragment_tree::FragmentLink>) {+ if !self.arena().paintable_row_is_populated(node) {+ return;+ }+ let containing_block = self.committed_containing_block(node, link);+ let arena = self.arena_mut();+ let mut paintable_rows = arena.paintable_rows_mut();+ let containing_block = if paintable_rows.paintable_row_is_populated(containing_block) {+ containing_block+ } else {+ NodeSlotId::INVALID+ };+ let containing_block_changed = {+ let mut data = paintable_rows.paintable_data_mut(node);+ std::mem::replace(&mut data.containing_block, containing_block) != containing_block+ };+ if containing_block_changed {+ paintable_rows.note_visual_context_box_dirty(node, VisualContextBoxDirtyKind::ContainingBlockChanged);+ paintable_rows.push_paint_damage(node, PaintDamage::MOVED);+ }+ }++ /// Notes that the inline boxes whose pieces the line root `slot` committed anew have geometry its new inline+ /// content gives them.+ fn note_inline_boxes_of_line_root_recommitted(&mut self, slot: NodeSlotId) {+ let inline_boxes: Vec<NodeSlotId> = self+ .arena()+ .committed_side_data(slot)+ .inline_content+ .as_ref()+ .map(|content| content.inline_boxes.boxes().map(|(node, _)| node).collect())+ .unwrap_or_default();+ let arena = self.arena_mut();+ let mut paintable_rows = arena.paintable_rows_mut();+ for inline_box in inline_boxes {+ if paintable_rows.paintable_row_is_populated(inline_box)+ && node_painting::is_fragmented_inline(&paintable_rows, inline_box)+ {+ paintable_rows+ .note_visual_context_box_dirty(inline_box, VisualContextBoxDirtyKind::InlineGeometryChanged);+ }+ }+ }+/// Commits the rows of the inline boxes of the line roots this commit committed anew that have pieces but no link/// of their own, as an inline box laid out where no fragments are built has.fn commit_inline_boxes_without_links(&mut self) {@@ -566,13 +1089,11 @@ impl<'tree> Commit<'_, 'tree> {}let number = self.number;self.arena_mut().note_committed_link_holder(inline_box, root, number);- let prepared = self- .paintables- .prepare_node(inline_box, false, false, line_root_changes);+ let prepared = self.prepare_node(inline_box, false, false, line_root_changes);self.committed_anew.push(inline_box);if prepared.has_paintable_row {- self.paintables.set_box_fragments(inline_box, &[]);- self.paintables.clear_line_data(inline_box);+ self.set_box_fragments(inline_box, &[]);+ self.clear_line_data(inline_box);}self.arena_mut().gather_layout_style_snapshot_geometry(inline_box);self.arena_mut().refresh_paint_order_inputs(inline_box);@@ -654,7 +1175,7 @@ impl<'tree> Commit<'_, 'tree> {continue;}self.arena_mut().forget_committed_out_of_flow_facts(node);- self.paintables.clear_node(node);+ self.clear_node(node);self.arena_mut().gather_layout_style_snapshot_geometry(node);}}@@ -670,7 +1191,7 @@ impl<'tree> Commit<'_, 'tree> {self.commit_inline_boxes_without_links();for (root, _) in std::mem::take(&mut self.line_roots) {if self.arena().slot_is_live(root) && self.arena().paintable_row_is_populated(root) {- self.paintables.note_inline_boxes_of_line_root_recommitted(root);+ self.note_inline_boxes_of_line_root_recommitted(root);}}for node in std::mem::take(&mut self.committed_anew) {@@ -678,7 +1199,7 @@ impl<'tree> Commit<'_, 'tree> {continue;}let link = self.arena().with_committed_fragment_link(node, |link| link.cloned());- self.paintables.stamp_containing_block(node, link.as_ref());+ self.stamp_containing_block(node, link.as_ref());}for (node, inputs) in std::mem::take(&mut self.out_of_flow_boxes) {if !self.arena().slot_is_live(node)@@ -690,24 +1211,19 @@ impl<'tree> Commit<'_, 'tree> {self.arena_mut().set_position_option_in_use(node, inputs.position_option);}- let Self {- mut paintables,- mut messages,- ..- } = self;- paintables.discard_absolute_rects_memoized_during_commit();- for &viewport in paintables.committed_navigable_container_viewports() {- if let Some(style_node) = paintables.arena().commit_message_style_node(viewport) {- messages.push(FfiCommitMessage::new(+ self.discard_absolute_rects_memoized_during_commit();+ for viewport in std::mem::take(&mut self.committed_navigable_container_viewports) {+ if let Some(style_node) = self.arena().commit_message_style_node(viewport) {+ self.messages.push(FfiCommitMessage::new(style_node,FfiCommitMessageKind::NavigableContainerViewportCommitted,));}}- paintables.arena_mut().publish_layout_style_snapshot_commit();+ self.arena_mut().publish_layout_style_snapshot_commit();CommitNotifications {- row_resets: paintables.take_row_reset_notifications(),- messages,+ row_resets: self.row_reset_notifications,+ messages: self.messages,}}}@@ -739,11 +1255,12 @@ pub(crate) fn commit_replacing(arena.note_layout_commit();let number = arena.layout_commit_count() as u32;let is_full_commit = arena.data(root).kind.get() == NodeKind::Viewport;- let mut paintables = crate::painting::paintable_build::PaintableCommit::new(arena);- paintables.begin_commit();+ arena.clear_absolute_rect_memo();Commit {- paintables,+ arena,messages: Vec::new(),+ row_reset_notifications: Vec::new(),+ committed_navigable_container_viewports: Vec::new(),number,root,is_full_commit,diff --git a/Libraries/LibWeb/Rust/src/painting/mod.rs b/Libraries/LibWeb/Rust/src/painting/mod.rsindex 6cae9d10d24..ea53ed9e34c 100644--- a/Libraries/LibWeb/Rust/src/painting/mod.rs+++ b/Libraries/LibWeb/Rust/src/painting/mod.rs@@ -31,7 +31,6 @@ pub(crate) mod paint_order_plan;pub(crate) mod paint_passes;pub(crate) mod paint_read;pub mod paint_state;-pub mod paintable_build;pub mod paintable_data;pub mod paintable_geometry;pub(crate) mod paintable_rows;diff --git a/Libraries/LibWeb/Rust/src/painting/paintable_build.rs b/Libraries/LibWeb/Rust/src/painting/paintable_build.rsdeleted file mode 100644index 1dcdec24f5a..00000000000--- a/Libraries/LibWeb/Rust/src/painting/paintable_build.rs+++ /dev/null@@ -1,574 +0,0 @@-/*- * Copyright (c) 2026-present, the Ladybird developers.- *- * SPDX-License-Identifier: BSD-2-Clause- */--use crate::layout::LayoutNodeArena;-use crate::layout::node_data::{DomPaintFact, NodeKind, NodeSlotId};-use crate::layout::{formatting_context, fragment_tree, node_facts, used_values};-use crate::painting::node_painting;-use crate::painting::paint_read::PaintRead;-use crate::painting::record::damage::PaintDamage;-use crate::painting::visual_context::dirty::VisualContextBoxDirtyKind;--#[derive(Clone, Copy, Debug)]-pub(crate) struct PreparedPaintable {- pub(crate) has_paintable_row: bool,- pub(crate) row_existed_before_this_commit: bool,- pub(crate) previous_offset: Option<used_values::FfiCssPixelPoint>,-}--pub(crate) struct ReplacedCommittedFragmentLink {- pub(crate) content_size_change: Option<(used_values::FfiCssPixelSize, used_values::FfiCssPixelSize)>,- pub(crate) line_root_changes: LineRootChanges,-}--#[derive(Clone, Copy, Default)]-pub(crate) struct LineDataChange {- pub(crate) content_changed: bool,- pub(crate) item_order_changed: bool,-}--#[derive(Clone, Copy, Default)]-pub(crate) struct LineRootChanges {- pub(crate) fragment_changed: bool,- pub(crate) inline_content_changed: bool,- pub(crate) inline_item_order_changed: bool,-}--impl LineRootChanges {- pub(crate) fn all() -> Self {- Self {- fragment_changed: true,- inline_content_changed: true,- inline_item_order_changed: true,- }- }-- pub(crate) fn any(self) -> bool {- self.fragment_changed || self.inline_content_changed || self.inline_item_order_changed- }-}--fn same_inline_content(left: &fragment_tree::Fragment, right: &fragment_tree::Fragment) -> bool {- match (&left.line_data, &right.line_data) {- (None, None) => true,- (Some(left), Some(right)) => std::sync::Arc::ptr_eq(left, right) || left == right,- _ => false,- }-}--fn has_descendant_dependent_paint(arena: &LayoutNodeArena, node: NodeSlotId) -> bool {- let kind = arena.data(node).kind.get();- if node_painting::is_svg(kind)- || matches!(- kind,- NodeKind::FieldSetBox | NodeKind::SVGSVGBox | NodeKind::SVGForeignObjectBox- )- {- return true;- }- let Some(style) = arena.node_style_if_live(node) else {- return true;- };- let display = style.display();- if display.is_table_inside() || display.is_internal_table() || kind == NodeKind::TableWrapper {- return true;- }- // A text-clipped background can collect glyphs from multiple descendant line roots.- fn clips_text(value: &crate::css::style_value::StyleValueData) -> bool {- use crate::css::{css_enums, style_value::StyleValueData};- match value {- StyleValueData::Keyword { keyword } => {- css_enums::keyword_to_background_box(*keyword) == Some(css_enums::background_box::TEXT)- }- StyleValueData::ValueList { values, .. } => values.as_slice().iter().any(|value| clips_text(value.data())),- _ => false,- }- }- crate::painting::style_queries::handle_value(&style.background().background_clip).is_some_and(clips_text)-}--pub(crate) struct PaintableCommit<'a> {- arena: &'a mut LayoutNodeArena,- committed_navigable_container_viewports: Vec<NodeSlotId>,- row_reset_notifications: Vec<crate::painting::paintable_rows::PaintableRowReset>,-}--impl<'a> PaintableCommit<'a> {- pub(crate) fn new(arena: &'a mut LayoutNodeArena) -> Self {- Self {- arena,- committed_navigable_container_viewports: Vec::new(),- row_reset_notifications: Vec::new(),- }- }-- pub(crate) fn arena(&self) -> &LayoutNodeArena {- self.arena- }-- pub(crate) fn arena_mut(&mut self) -> &mut LayoutNodeArena {- self.arena- }-- pub(crate) fn discard_absolute_rects_memoized_during_commit(&mut self) {- self.arena_mut().clear_absolute_rect_memo();- }-- pub(crate) fn begin_commit(&mut self) {- self.arena_mut().clear_absolute_rect_memo();- }-- /// Clears the committed link and row of a box the commit left without them.- pub(crate) fn clear_node(&mut self, node: formatting_context::Node) {- self.arena_mut().clear_committed_fragment_link(node);- if self.arena().paintable_rows().paintable_row_is_populated(node) {- let reset = self- .arena()- .prepare_paintable_row_cleared_reset(node)- .expect("live row for node could not be cleared");- self.row_reset_notifications.push(reset);- self.arena_mut().paintable_row_cleared(reset);- }- }-- pub(crate) fn prepare_node(- &mut self,- node: formatting_context::Node,- has_used_values: bool,- reuses_committed_subtree: bool,- enclosing_line_root_changes: LineRootChanges,- ) -> PreparedPaintable {- let (wants_paintable, node_kind) = {- let data = self.arena().data(node);- let is_fragmented_inline = node_facts::node_is_fragmented_inline(data, node_facts::node_style_view(data));- let has_dom_node = !node_facts::has_flag(data, crate::layout::node_data::NodeFlag::Anonymous);- (- (has_used_values || (is_fragmented_inline && has_dom_node))- && node_painting::has_paintable(data.kind.get()),- data.kind.get(),- )- };- 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()- .with_committed_fragment_link(node, |link| link.map(|link| link.offset))- })- .flatten();- if !wants_paintable {- self.clear_node(node);- return PreparedPaintable {- has_paintable_row: false,- row_existed_before_this_commit: false,- previous_offset: None,- };- }- if node_kind == NodeKind::NavigableContainerViewport {- self.committed_navigable_container_viewports.push(node);- }- if reuses_committed_subtree {- assert!(- row_existed_before_this_commit,- "a kept subtree root has no committed row"- );- return PreparedPaintable {- has_paintable_row: true,- row_existed_before_this_commit: true,- previous_offset,- };- }- if !has_used_values {- 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));- if row_existed_before_this_commit && inline_paint_changed {- self.arena_mut().push_paint_damage(node, PaintDamage::ALL_PRODUCERS);- }- if row_existed_before_this_commit && enclosing_line_root_changes.fragment_changed {- self.arena_mut()- .note_visual_context_box_dirty(node, VisualContextBoxDirtyKind::InlineGeometryChanged);- }- }- if row_existed_before_this_commit {- let notification = self- .arena()- .paintable_rows()- .prepare_paintable_row_recommit_notification(node);- self.row_reset_notifications.push(notification);- }- let arena = self.arena_mut();- if row_existed_before_this_commit {- arena.paintable_rows_mut().begin_paintable_row_recommit(node);- if node_kind == NodeKind::Viewport {- // A recommitted viewport row starts its paint state over: the scroll registry is- // dropped here and rebuilt by the next tree update, while the host resets its- // snapshot from the row reset notification.- arena.paint_state_mut().visual_context.clear_scroll_state();- }- } else {- arena.populate_paintable_row(node);- if node_kind == NodeKind::Viewport {- arena.paint_state_mut().reset_visual_context_state();- }- arena.note_visual_context_box_dirty(node, VisualContextBoxDirtyKind::NewRow);- }- PreparedPaintable {- has_paintable_row: true,- row_existed_before_this_commit,- previous_offset,- }- }-- pub(crate) fn take_row_reset_notifications(&mut self) -> Vec<crate::painting::paintable_rows::PaintableRowReset> {- std::mem::take(&mut self.row_reset_notifications)- }-- pub(crate) fn committed_navigable_container_viewports(&self) -> &[NodeSlotId] {- &self.committed_navigable_container_viewports- }-- pub(crate) fn replace_committed_fragment_link(- &mut self,- node: formatting_context::Node,- link: &fragment_tree::FragmentLink,- enclosing_line_root_changes: LineRootChanges,- previous_offset: Option<used_values::FfiCssPixelPoint>,- ) -> ReplacedCommittedFragmentLink {- let fragment = &link.fragment;- let new_content_size = fragment.sides.content_size;- let new_offset = link.offset;- let mut content_size_change = None;- let mut own_paint_unchanged = false;- let mut child_placements_unchanged = false;- let mut inline_content_unchanged = false;- let mut inline_item_order_unchanged = false;- let mut child_sequence_unchanged = false;- let mut link_shows_box_the_same = true;- let mut old_scrollable_overflow = crate::layout::fragment_overflow::FragmentScrollableOverflow::default();- let (old_identity, old_content_size) = self.arena().with_committed_fragment_link(node, |old_link| {- old_link.map_or((0, used_values::FfiCssPixelSize::default()), |old_link| {- let previous = &old_link.fragment;- old_scrollable_overflow = previous.scrollable_overflow;- if previous.identity == fragment.identity {- own_paint_unchanged = true;- child_placements_unchanged = true;- inline_content_unchanged = true;- inline_item_order_unchanged = true;- child_sequence_unchanged = true;- } else {- inline_content_unchanged = same_inline_content(fragment, previous);- inline_item_order_unchanged = inline_content_unchanged- || match (&fragment.line_data, &previous.line_data) {- (Some(left), Some(right)) => left.has_same_item_order(right),- _ => false,- };- own_paint_unchanged = inline_content_unchanged- && fragment.has_same_box_properties(previous)- && !has_descendant_dependent_paint(self.arena(), node);- child_placements_unchanged = fragment.has_same_child_placements(previous);- child_sequence_unchanged = fragment.has_same_child_sequence(previous);- }- own_paint_unchanged &= old_link.has_same_placement(link);- link_shows_box_the_same = link.placement.shown_as == old_link.placement.shown_as;- (old_link.fragment.identity, old_link.fragment.sides.content_size)- })- });- if old_content_size != new_content_size {- content_size_change = Some((old_content_size, new_content_size));- }- let committed_fragment_identity_changed = old_identity != fragment.identity;- // Inserted, removed or reordered children change which scopes this row's plans list,- // independently of where the children were placed.- if !child_sequence_unchanged {- self.arena_mut().push_paint_damage(node, PaintDamage::ORDER);- }- let painted_geometry_lives_in_enclosing_line_root = {- let data = self.arena().data(node);- node_facts::node_is_fragmented_inline(data, node_facts::node_style_view(data))- };- let fragment_content_changed = committed_fragment_identity_changed- || (enclosing_line_root_changes.fragment_changed && painted_geometry_lives_in_enclosing_line_root);- // Keep fragment identity as the conservative signal for overflow and visual contexts.- // The fragment stays the same when only the link's margins or parent-decided facts change, but margin-box clip- // paths, line clamp clips and overflow read those.- let fragment_content_unchanged = link_shows_box_the_same && old_identity != 0 && !fragment_content_changed;- let offset_unchanged = previous_offset == Some(new_offset);- let enclosing_inline_paint_changed = painted_geometry_lives_in_enclosing_line_root- && (enclosing_line_root_changes.inline_content_changed- || (enclosing_line_root_changes.fragment_changed- && has_descendant_dependent_paint(self.arena(), node)));- // A fragmented inline's geometry is read from its line root's pieces. Comparing it with- // the fragment's temporary offset would dirty identical inlines on every relayout; their- // line content and box properties suffice.- let paint_offset_unchanged = offset_unchanged || painted_geometry_lives_in_enclosing_line_root;- // record_lines_hit_test_items() emits an EmptyEditable target only without paint- // children. An out-of-flow child can change that eligibility without changing the- // editor's box properties or inline content, so descendant dirtiness alone is insufficient.- let empty_editable_children_changed = !child_placements_unchanged- && node_painting::has_lines(self.arena(), node)- && self- .arena()- .node_has_dom_paint_fact(node, DomPaintFact::EditableOrEditingHost)- && fragment- .line_data- .as_ref()- .is_none_or(|content| content.fragments.is_empty());- let mut damage = PaintDamage::NONE;- if !own_paint_unchanged || enclosing_inline_paint_changed || empty_editable_children_changed {- damage |= PaintDamage::ALL_PRODUCERS;- }- if !inline_item_order_unchanged- || (painted_geometry_lives_in_enclosing_line_root && enclosing_line_root_changes.inline_item_order_changed)- {- damage |= PaintDamage::ORDER;- }- if !paint_offset_unchanged {- damage |= PaintDamage::MOVED;- }- self.arena_mut().push_paint_damage(node, damage);- if !offset_unchanged {- self.arena_mut()- .note_visual_context_box_dirty(node, VisualContextBoxDirtyKind::MovedWithDescendants);- }- if !fragment_content_unchanged {- self.arena_mut()- .note_visual_context_box_dirty(node, VisualContextBoxDirtyKind::RecommittedInPlace);- }- if old_scrollable_overflow != fragment.scrollable_overflow {- self.arena_mut().note_scrollable_overflow_change(- node,- old_scrollable_overflow.has_scrollable_overflow,- fragment.scrollable_overflow.has_scrollable_overflow,- false,- );- }- self.arena_mut().note_scroll_offset_may_leave_range(node);- // A layout pass bumps no epoch, so its geometry is laid out against the epoch the node has now.- let epoch_of_laid_out_geometry = self.arena().data(node).fragment_cache_epoch;- self.arena_mut()- .set_committed_fragment_link(node, link.clone(), Some(epoch_of_laid_out_geometry));- ReplacedCommittedFragmentLink {- content_size_change,- line_root_changes: LineRootChanges {- fragment_changed: committed_fragment_identity_changed,- inline_content_changed: !inline_content_unchanged,- inline_item_order_changed: !inline_item_order_unchanged,- },- }- }-- pub(crate) fn set_box_fragments(&mut self, slot: NodeSlotId, fragments: &[fragment_tree::SlotFragment<'_>]) {- let later_fragments = fragments.get(1..).unwrap_or_default();- let (moved, containing_block_fragment, identical, geometry_unchanged) = {- let side = self.arena().committed_side_data(slot);- let containing_block_fragment = fragments- .first()- .and_then(|fragment| fragment.containing_block_fragment)- .unwrap_or(side.containing_block_fragment);- let first_fragment_moved = side.containing_block_fragment != containing_block_fragment;- let same_count = !first_fragment_moved && side.box_fragments().len() == later_fragments.len();- let all_pairs = |same: fn(&fragment_tree::FragmentLink, &fragment_tree::FragmentLink) -> bool| {- side.box_fragments()- .iter()- .zip(later_fragments)- .all(|(committed, fragment)| {- Some(committed.containing_block_fragment) == fragment.containing_block_fragment- && same(fragment.link, &committed.link)- })- };- (- first_fragment_moved || !all_pairs(|link, committed| link.has_same_placement(committed)),- containing_block_fragment,- same_count && all_pairs(|link, committed| link.places_same_fragment_identically_to(committed)),- same_count- && all_pairs(|link, committed| {- link.has_same_placement(committed)- && link.fragment.has_same_box_properties(&committed.fragment)- && same_inline_content(&link.fragment, &committed.fragment)- }),- )- };- let flags = [- (- crate::painting::paintable_data::PaintableFlag::InLaterContainingBlockFragment,- containing_block_fragment != 0,- ),- (- crate::painting::paintable_data::PaintableFlag::HasLaterBoxFragments,- !later_fragments.is_empty(),- ),- ];- let data = self.arena().live_paintable_data(slot);- if flags.iter().any(|&(flag, value)| data.has_flag(flag) != value) {- let arena = self.arena_mut();- let mut paintable_rows = arena.paintable_rows_mut();- let mut data = paintable_rows.paintable_data_mut(slot);- for (flag, value) in flags {- data.set_flag(flag, value);- }- }- if identical {- return;- }- let (later_overflow_changed, later_fragments_had_scrollable_overflow) = {- let committed = self.arena().committed_side_data(slot).box_fragments();- (- committed.len() != later_fragments.len()- || committed.iter().zip(later_fragments).any(|(committed, fragment)| {- committed.link.fragment.scrollable_overflow != fragment.link.fragment.scrollable_overflow- }),- committed- .iter()- .any(|committed| committed.link.fragment.scrollable_overflow.has_scrollable_overflow),- )- };- if later_overflow_changed {- let later_fragments_have_scrollable_overflow = later_fragments- .iter()- .any(|fragment| fragment.link.fragment.scrollable_overflow.has_scrollable_overflow);- self.arena_mut().note_scrollable_overflow_change(- slot,- later_fragments_had_scrollable_overflow,- later_fragments_have_scrollable_overflow,- false,- );- }- {- let mut side = self.arena_mut().committed_side_data_mut(slot);- side.containing_block_fragment = containing_block_fragment;- side.box_fragments = (!later_fragments.is_empty()).then(|| {- std::sync::Arc::new(- later_fragments- .iter()- .map(|fragment| crate::painting::paintable_data::CommittedBoxFragment {- link: fragment.link.clone(),- containing_block_fragment: fragment.containing_block_fragment.unwrap_or_default(),- })- .collect(),- )- });- }- if geometry_unchanged {- return;- }- self.arena_mut()- .push_paint_damage(slot, PaintDamage::ALL_PRODUCERS | PaintDamage::MOVED);- self.arena_mut().note_visual_context_box_dirty(- slot,- if moved {- VisualContextBoxDirtyKind::MovedWithDescendants- } else {- VisualContextBoxDirtyKind::RecommittedInPlace- },- );- }-- pub(crate) fn set_line_data(- &mut self,- slot: NodeSlotId,- line_data: &std::sync::Arc<crate::layout::inline_content::InlineContent>,- previous_fragmented_content: Option<std::sync::Arc<crate::layout::inline_content::InlineContent>>,- content_size: used_values::FfiCssPixelSize,- ) -> LineDataChange {- if !node_painting::has_lines(self.arena(), slot) {- self.clear_line_data(slot);- return LineDataChange::default();- }- let writing_mode = line_data.writing_mode;- let physical_line_data;- let line_data = if writing_mode == crate::css::css_enums::writing_mode::HORIZONTAL_TB {- line_data- } else {- physical_line_data = std::sync::Arc::new(line_data.in_physical_plane(writing_mode, content_size));- &physical_line_data- };- let has_pieces = !line_data.inline_box_pieces.is_empty();- let (content_changed, item_order_changed) = previous_fragmented_content.map_or((false, false), |previous| {- if std::sync::Arc::ptr_eq(&previous, line_data) || *previous == **line_data {- return (false, false);- }- (true, !previous.has_same_item_order(line_data))- });- self.arena_mut().committed_side_data_mut(slot).inline_content = Some(line_data.clone());- if item_order_changed {- self.arena_mut().push_paint_damage(slot, PaintDamage::ORDER);- }- if has_pieces {- self.arena_mut().note_line_root_needs_fragment_ownership(slot);- }- LineDataChange {- content_changed,- item_order_changed,- }- }-- /// Clears the inline content of a row whose new fragment has none.- pub(crate) fn clear_line_data(&mut self, slot: NodeSlotId) {- if self.arena().committed_side_data(slot).inline_content.is_some() {- self.arena_mut().committed_side_data_mut(slot).inline_content = None;- }- }-- fn committed_containing_block(- &self,- node: formatting_context::Node,- link: Option<&fragment_tree::FragmentLink>,- ) -> NodeSlotId {- match link.map(|link| link.placement.containing_block) {- Some(containing_block) if !containing_block.is_invalid() => containing_block,- _ => self.arena().containing_block_by_walking_ancestors(node),- }- }-- pub(crate) fn stamp_containing_block(- &mut self,- node: formatting_context::Node,- link: Option<&fragment_tree::FragmentLink>,- ) {- if !self.arena().paintable_row_is_populated(node) {- return;- }- let containing_block = self.committed_containing_block(node, link);- let arena = self.arena_mut();- let mut paintable_rows = arena.paintable_rows_mut();- let containing_block = if paintable_rows.paintable_row_is_populated(containing_block) {- containing_block- } else {- NodeSlotId::INVALID- };- let containing_block_changed = {- let mut data = paintable_rows.paintable_data_mut(node);- std::mem::replace(&mut data.containing_block, containing_block) != containing_block- };- if containing_block_changed {- paintable_rows.note_visual_context_box_dirty(node, VisualContextBoxDirtyKind::ContainingBlockChanged);- paintable_rows.push_paint_damage(node, PaintDamage::MOVED);- }- }-- /// Notes that the inline boxes whose pieces the line root `slot` committed anew have geometry its new inline- /// content gives them.- pub(crate) fn note_inline_boxes_of_line_root_recommitted(&mut self, slot: NodeSlotId) {- let inline_boxes: Vec<NodeSlotId> = self- .arena()- .committed_side_data(slot)- .inline_content- .as_ref()- .map(|content| content.inline_boxes.boxes().map(|(node, _)| node).collect())- .unwrap_or_default();- let arena = self.arena_mut();- let mut paintable_rows = arena.paintable_rows_mut();- for inline_box in inline_boxes {- if paintable_rows.paintable_row_is_populated(inline_box)- && node_painting::is_fragmented_inline(&paintable_rows, inline_box)- {- paintable_rows- .note_visual_context_box_dirty(inline_box, VisualContextBoxDirtyKind::InlineGeometryChanged);- }- }- }-}