Truly independent web browser
LibWeb: Read inline box geometry from the line root's inline content
Aliaksandr Kalenike500f81d63da
diff --git a/Libraries/LibWeb/Rust/src/layout/commit.rs b/Libraries/LibWeb/Rust/src/layout/commit.rsindex 15c8d93fc4a..4f7bae2dd82 100644--- a/Libraries/LibWeb/Rust/src/layout/commit.rs+++ b/Libraries/LibWeb/Rust/src/layout/commit.rs@@ -208,7 +208,7 @@ fn commit_subtree(enclosing_line_root_changes,);- let mut has_pending_inline_box_geometry = false;+ let mut has_recommitted_inline_box_pieces = false;let mut line_root_changes_for_children = enclosing_line_root_changes;if let Some(link) = entry&& prepared.has_paintable_row@@ -254,7 +254,7 @@ fn commit_subtree(.flatten();if let Some(line_data) = merged_line_data.as_ref().or(fragment.line_data.as_ref()) {let change = paintables.set_line_data(node, line_data, previous_fragmented_content);- has_pending_inline_box_geometry = change.has_pieces;+ has_recommitted_inline_box_pieces = change.has_pieces;line_root_changes_for_children.fragment_changed |= change.content_changed;line_root_changes_for_children.inline_content_changed |= change.content_changed;line_root_changes_for_children.inline_item_order_changed |= change.item_order_changed;@@ -289,11 +289,9 @@ fn commit_subtree(child = next;}- if has_pending_inline_box_geometry {- // Inline box geometry unites this block's piece rects with the box- // models of its descendant inline paintables, which exist only now- // that the whole subtree has committed.- paintables.assign_inline_box_geometry(node);+ if has_recommitted_inline_box_pieces {+ // NB: The rows of this block's inline boxes exist only now that its whole subtree has committed.+ paintables.note_inline_boxes_of_line_root_recommitted(node);}}diff --git a/Libraries/LibWeb/Rust/src/layout/inline_content.rs b/Libraries/LibWeb/Rust/src/layout/inline_content.rsindex 4dc4bc31f26..25fdea00f1d 100644--- a/Libraries/LibWeb/Rust/src/layout/inline_content.rs+++ b/Libraries/LibWeb/Rust/src/layout/inline_content.rs@@ -27,6 +27,76 @@ pub struct InlineContent {pub elided_content_rects: Vec<(u32, used_values::FfiCssPixelRect)>,/// The writing mode whose frame the lines were laid out in.pub writing_mode: u8,+ /// The pieces of each inline box, by box.+ pub inline_boxes: InlineBoxIndex,+}++/// The indices of each inline box's pieces in its line root's content, in line order, which painting and geometry+/// queries look up by box.+#[derive(Clone, Default, PartialEq)]+pub struct InlineBoxIndex {+ /// Sorted by box.+ boxes: Vec<InlineBoxPieces>,+ piece_indices: Vec<u32>,+}++#[derive(Clone, Copy, PartialEq)]+struct InlineBoxPieces {+ node: NodeSlotId,+ first: u32,+ count: u32,+}++fn inline_box_order(node: NodeSlotId) -> (u32, u8) {+ (node.slot_index(), node.generation())+}++impl InlineBoxIndex {+ fn of(pieces: &[InlineBoxPieceRecord]) -> Self {+ let mut pieces_by_box: Vec<(NodeSlotId, u32)> = pieces+ .iter()+ .enumerate()+ .filter(|(_, piece)| !piece.node.is_invalid())+ .map(|(index, piece)| (piece.node, index as u32))+ .collect();+ pieces_by_box.sort_unstable_by_key(|&(node, index)| (inline_box_order(node), index));+ let mut index = Self {+ boxes: Vec::new(),+ piece_indices: Vec::with_capacity(pieces_by_box.len()),+ };+ for (node, piece_index) in pieces_by_box {+ match index.boxes.last_mut() {+ Some(pieces) if pieces.node == node => pieces.count += 1,+ _ => index.boxes.push(InlineBoxPieces {+ node,+ first: index.piece_indices.len() as u32,+ count: 1,+ }),+ }+ index.piece_indices.push(piece_index);+ }+ index+ }++ /// The indices of the pieces of `node`, in line order.+ pub(crate) fn piece_indices_of(&self, node: NodeSlotId) -> &[u32] {+ self.boxes+ .binary_search_by_key(&inline_box_order(node), |pieces| inline_box_order(pieces.node))+ .map_or(&[], |position| {+ let pieces = self.boxes[position];+ &self.piece_indices[pieces.first as usize..(pieces.first + pieces.count) as usize]+ })+ }++ /// Each inline box with pieces, with the indices of its pieces in line order.+ pub(crate) fn boxes(&self) -> impl Iterator<Item = (NodeSlotId, &[u32])> {+ self.boxes.iter().map(|pieces| {+ (+ pieces.node,+ &self.piece_indices[pieces.first as usize..(pieces.first + pieces.count) as usize],+ )+ })+ }}#[derive(Clone, Copy, Debug, PartialEq, Eq)]@@ -205,6 +275,7 @@ impl InlineContent {let mut content = Self {lines,fragments,+ inline_boxes: InlineBoxIndex::of(&pieces),inline_box_pieces: pieces,items: Vec::new(),lines_after_clamp_point_rect: data.lines_after_clamp_point_rect,@@ -275,9 +346,15 @@ impl InlineContent {combined.append_translated(content, interleaves, *box_fragment, *offset);}combined.drop_repeated_placeholder_pieces();+ combined.index_inline_boxes();std::sync::Arc::new(combined)}+ /// Indexes the pieces of each inline box again, after they were renumbered or given to other boxes.+ pub(crate) fn index_inline_boxes(&mut self) {+ self.inline_boxes = InlineBoxIndex::of(&self.inline_box_pieces);+ }+fn drop_repeated_placeholder_pieces(&mut self) {let is_placeholder =|piece: &InlineBoxPieceRecord| piece.is_geometry_only_placeholder && piece.fragment_count == 0;@@ -550,3 +627,39 @@ impl FragmentRecord {super::geometry::to_physical(self.writing_mode, self.inline_length, self.block_length).1}}++#[cfg(test)]+mod tests {+ use super::*;++ fn piece_of(node: NodeSlotId, line_index: u32) -> InlineBoxPieceRecord {+ InlineBoxPieceRecord {+ node,+ line_index,+ ..InlineBoxPieceRecord::default()+ }+ }++ #[test]+ fn the_inline_box_index_lists_each_box_with_its_pieces_in_line_order() {+ let outer = NodeSlotId::new(7, 1);+ let inner = NodeSlotId::new(3, 2);+ let pieces = [+ piece_of(outer, 0),+ piece_of(inner, 0),+ piece_of(NodeSlotId::INVALID, 0),+ piece_of(outer, 1),+ piece_of(inner, 1),+ piece_of(outer, 2),+ ];+ let index = InlineBoxIndex::of(&pieces);+ assert_eq!(index.piece_indices_of(outer), &[0, 3, 5]);+ assert_eq!(index.piece_indices_of(inner), &[1, 4]);+ assert!(index.piece_indices_of(NodeSlotId::new(3, 1)).is_empty());+ assert!(index.piece_indices_of(NodeSlotId::INVALID).is_empty());+ assert_eq!(+ index.boxes().map(|(node, _)| node).collect::<Vec<_>>(),+ vec![inner, outer]+ );+ }+}diff --git a/Libraries/LibWeb/Rust/src/painting/client_rects.rs b/Libraries/LibWeb/Rust/src/painting/client_rects.rsindex 7c023eed4ed..d5294355643 100644--- a/Libraries/LibWeb/Rust/src/painting/client_rects.rs+++ b/Libraries/LibWeb/Rust/src/painting/client_rects.rs@@ -68,7 +68,7 @@ fn for_each_inline_piece_border_box_rect(};let root_positions = paintable_geometry::LineRootPositions::new(arena, root);let root_side = arena.committed_side_data(root);- with_inline_pieces(arena, inline_paintable, |piece, _| {+ with_inline_pieces(arena, inline_paintable, |piece| {if piece.is_geometry_only_placeholder {return true;}diff --git a/Libraries/LibWeb/Rust/src/painting/dump.rs b/Libraries/LibWeb/Rust/src/painting/dump.rsindex dbb8396b690..88b0d6f1e8d 100644--- a/Libraries/LibWeb/Rust/src/painting/dump.rs+++ b/Libraries/LibWeb/Rust/src/painting/dump.rs@@ -179,7 +179,7 @@ pub(crate) fn dump_inline_piece_fragments(return;};let root_side = layout_arena.committed_side_data(root);- for piece_index in layout_arena.committed_side_data(inline_paintable).piece_indices() {+ for piece_index in root_side.inline_box_piece_indices(inline_paintable) {let piece = &root_side.inline_box_pieces()[*piece_index as usize];let mut fragment_index_within_piece = 0usize;for fragment_index in piece.first_fragment_index..piece.first_fragment_index + piece.fragment_count {diff --git a/Libraries/LibWeb/Rust/src/painting/ffi.rs b/Libraries/LibWeb/Rust/src/painting/ffi.rsindex ddb64dee700..58de9bc1eba 100644--- a/Libraries/LibWeb/Rust/src/painting/ffi.rs+++ b/Libraries/LibWeb/Rust/src/painting/ffi.rs@@ -827,7 +827,7 @@ pub extern "C" fn render_state_inline_paintable_has_content_pieces() -> bool {read_arena(host, node_read(), inline_paintable, |arena, inline_paintable| {let mut has_content = false;- with_inline_pieces(&arena.paintable_rows(), inline_paintable, |piece, _| {+ with_inline_pieces(&arena.paintable_rows(), inline_paintable, |piece| {if !piece.is_geometry_only_placeholder {has_content = true;return false;@@ -864,7 +864,7 @@ pub extern "C" fn render_state_inline_paintable_first_piece_position(};let border_widths = crate::painting::paintable_geometry::committed_border(arena, inline_paintable);let padding_widths = crate::painting::paintable_geometry::committed_padding(arena, inline_paintable);- with_inline_pieces(&paintable_rows, inline_paintable, |piece, _data| {+ with_inline_pieces(&paintable_rows, inline_paintable, |piece| {let border_rect = CssPixelRect::from(piece.border_box_rect);let rect = if piece.is_geometry_only_placeholder {border_rectdiff --git a/Libraries/LibWeb/Rust/src/painting/inline_box_geometry.rs b/Libraries/LibWeb/Rust/src/painting/inline_box_geometry.rsnew file mode 100644index 00000000000..72bd76ad603--- /dev/null+++ b/Libraries/LibWeb/Rust/src/painting/inline_box_geometry.rs@@ -0,0 +1,99 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++//! The geometry of an inline box broken into pieces on its line root's lines, which the line root's committed inline+//! content holds.++use crate::css::css_pixels::{CssPixelPoint, CssPixelRect};+use crate::layout::node_data::NodeSlotId;+use crate::painting::paint_read::GeometryRead;+use crate::painting::paintable_geometry;++/// The rects an inline box's pieces unite to, relative to the content box of its line root's fragment that holds the+/// box.+pub(crate) struct InlineBoxUnions {+ pub(crate) content: CssPixelRect,+ pub(crate) padding: CssPixelRect,+ pub(crate) border: CssPixelRect,+}++fn unite(target: &mut Option<CssPixelRect>, rect: CssPixelRect) {+ let Some(current) = target else {+ *target = Some(rect);+ return;+ };+ if rect.is_empty() {+ return;+ }+ if current.is_empty() {+ *current = rect;+ } else {+ current.unite(rect);+ }+}++/// The unions of the pieces of the inline box `inline_box`, or None where it has no line root or no pieces.+pub(crate) fn unions(arena: &impl GeometryRead, inline_box: NodeSlotId) -> Option<InlineBoxUnions> {+ let root = arena.inline_pieces_root(inline_box)?;+ let root_positions = (paintable_geometry::fragment_count(arena, root) > 1)+ .then(|| paintable_geometry::LineRootPositions::new(arena, root));+ let origin = root_positions+ .as_ref()+ .map(|positions| positions.of_fragment(arena.committed_side_data(inline_box).containing_block_fragment));+ let padding_widths = paintable_geometry::committed_padding(arena, inline_box);+ let border_widths = paintable_geometry::committed_border(arena, inline_box);+ let side = arena.committed_side_data(root);+ let mut content_union = None;+ let mut padding_union = None;+ let mut border_union = None;+ for piece_index in side.inline_box_piece_indices(inline_box) {+ let piece = side.inline_box_pieces()[*piece_index as usize];+ let root_fragment_offset =+ root_positions+ .as_ref()+ .zip(origin)+ .map_or_else(CssPixelPoint::default, |(positions, origin)| {+ let location = positions.of_line(side.lines(), piece.line_index as usize);+ CssPixelPoint {+ x: location.x - origin.x,+ y: location.y - origin.y,+ }+ });+ let border_rect = CssPixelRect::from(piece.border_box_rect).translated_by(root_fragment_offset);+ if piece.is_geometry_only_placeholder {+ let padding_rect = border_rect.inflated(+ padding_widths.top,+ padding_widths.right,+ padding_widths.bottom,+ padding_widths.left,+ );+ unite(&mut content_union, border_rect);+ unite(+ &mut border_union,+ padding_rect.inflated(+ border_widths.top,+ border_widths.right,+ border_widths.bottom,+ border_widths.left,+ ),+ );+ unite(&mut padding_union, padding_rect);+ continue;+ }+ let padding_rect = piece.shrunken_by_present_edges(border_rect, border_widths);+ unite(+ &mut content_union,+ piece.shrunken_by_present_edges(padding_rect, padding_widths),+ );+ unite(&mut padding_union, padding_rect);+ unite(&mut border_union, border_rect);+ }+ Some(InlineBoxUnions {+ content: content_union?,+ padding: padding_union.expect("padding union set alongside content union"),+ border: border_union.expect("border union set alongside content union"),+ })+}diff --git a/Libraries/LibWeb/Rust/src/painting/mod.rs b/Libraries/LibWeb/Rust/src/painting/mod.rsindex c738e8263b9..8ede6284b76 100644--- a/Libraries/LibWeb/Rust/src/painting/mod.rs+++ b/Libraries/LibWeb/Rust/src/painting/mod.rs@@ -21,6 +21,7 @@ pub mod hit_test;pub mod host;pub(crate) mod image_content;pub(crate) mod image_map_areas;+pub(crate) mod inline_box_geometry;pub(crate) mod intersection_observer;pub(crate) mod layer_image_paint_facts;pub mod layout_tree_dump;diff --git a/Libraries/LibWeb/Rust/src/painting/paintable_build.rs b/Libraries/LibWeb/Rust/src/painting/paintable_build.rsindex 58208035e03..430448f0d03 100644--- a/Libraries/LibWeb/Rust/src/painting/paintable_build.rs+++ b/Libraries/LibWeb/Rust/src/painting/paintable_build.rs@@ -4,7 +4,7 @@* SPDX-License-Identifier: BSD-2-Clause*/-use crate::css::css_pixels::{CssPixelPoint, CssPixelRect};+use crate::css::css_pixels::CssPixelRect;use crate::layout::LayoutNodeArena;use crate::layout::node_data::{DomPaintFact, NodeKind, NodeSlotId};use crate::layout::{formatting_context, fragment_tree, node_facts, used_values};@@ -310,9 +310,9 @@ impl<'a> PaintableCommit<'a> {&& (enclosing_line_root_changes.inline_content_changed|| (enclosing_line_root_changes.fragment_changed&& has_descendant_dependent_paint(self.arena(), node)));- // Fragmented inline offsets are finalized from the line root's pieces after this- // commit. Comparing that final offset with the fragment's temporary one would dirty- // identical inlines on every relayout; their line content and box properties suffice.+ // 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@@ -557,123 +557,25 @@ impl<'a> PaintableCommit<'a> {}}- pub(crate) fn assign_inline_box_geometry(&mut self, slot: NodeSlotId) {+ /// 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();- let mut piece_indices_by_node: Vec<(NodeSlotId, Vec<u32>)> = Vec::new();- for (piece_index, piece) in paintable_rows- .committed_side_data(slot)- .inline_box_pieces()- .iter()- .enumerate()- {- if piece.node.is_invalid() {- continue;- }- match piece_indices_by_node.iter_mut().find(|(node, _)| *node == piece.node) {- Some((_, indices)) => indices.push(piece_index as u32),- None => piece_indices_by_node.push((piece.node, vec![piece_index as u32])),- }- }- let root_positions = (crate::painting::paintable_geometry::fragment_count(&paintable_rows, slot) > 1)- .then(|| crate::painting::paintable_geometry::LineRootPositions::new(&paintable_rows, slot));- for (piece_node, piece_indices) in piece_indices_by_node {- if !paintable_rows.paintable_row_is_populated(piece_node)- || !node_painting::is_fragmented_inline(&paintable_rows, piece_node)+ for inline_box in inline_boxes {+ if paintable_rows.paintable_row_is_populated(inline_box)+ && node_painting::is_fragmented_inline(&paintable_rows, inline_box){- continue;- }- let origin = root_positions.as_ref().map(|positions| {- positions.of_fragment(paintable_rows.committed_side_data(piece_node).containing_block_fragment)- });- let padding_widths = crate::painting::paintable_geometry::committed_padding(&paintable_rows, piece_node);- let border_widths = crate::painting::paintable_geometry::committed_border(&paintable_rows, piece_node);- let mut content_union: Option<CssPixelRect> = None;- let mut padding_union: Option<CssPixelRect> = None;- let mut border_union: Option<CssPixelRect> = None;- let unite = |target: &mut Option<CssPixelRect>, rect: CssPixelRect| {- let Some(current) = target else {- *target = Some(rect);- return;- };- if rect.is_empty() {- return;- }- if current.is_empty() {- *current = rect;- } else {- current.unite(rect);- }- };- for piece_index in &piece_indices {- let (piece, root_fragment_offset) = {- let side = paintable_rows.committed_side_data(slot);- let piece = side.inline_box_pieces()[*piece_index as usize];- let offset = root_positions.as_ref().zip(origin).map_or_else(- CssPixelPoint::default,- |(positions, origin)| {- let location = positions.of_line(side.lines(), piece.line_index as usize);- CssPixelPoint {- x: location.x - origin.x,- y: location.y - origin.y,- }- },- );- (piece, offset)- };- let border_rect = CssPixelRect::from(piece.border_box_rect).translated_by(root_fragment_offset);- if piece.is_geometry_only_placeholder {- let content_rect = border_rect;- let padding_rect = content_rect.inflated(- padding_widths.top,- padding_widths.right,- padding_widths.bottom,- padding_widths.left,- );- let border_rect = padding_rect.inflated(- border_widths.top,- border_widths.right,- border_widths.bottom,- border_widths.left,- );- unite(&mut content_union, content_rect);- unite(&mut padding_union, padding_rect);- unite(&mut border_union, border_rect);- continue;- }- let padding_rect = piece.shrunken_by_present_edges(border_rect, border_widths);- let content_rect = piece.shrunken_by_present_edges(padding_rect, padding_widths);- unite(&mut content_union, content_rect);- unite(&mut padding_union, padding_rect);- unite(&mut border_union, border_rect);- }- let Some(content_union) = content_union else {- continue;- };- let padding_union = padding_union.expect("padding union set alongside content union");- let border_union = border_union.expect("border union set alongside content union");- let inline_geometry_changed = {- let mut data = paintable_rows.paintable_data_mut(piece_node);- let new_offset = content_union.location().into();- let new_content_size = content_union.size().into();- let new_padding_box_union = padding_union.translated(-content_union.x, -content_union.y).into();- let new_border_box_union = border_union.translated(-content_union.x, -content_union.y).into();- let inline_geometry_changed = data.offset != new_offset- || data.content_size != new_content_size- || data.local_padding_box_union != new_padding_box_union- || data.local_border_box_union != new_border_box_union;- data.offset = new_offset;- data.content_size = new_content_size;- data.local_padding_box_union = new_padding_box_union;- data.local_border_box_union = new_border_box_union;- inline_geometry_changed- };- if inline_geometry_changed {paintable_rows- .note_visual_context_box_dirty(piece_node, VisualContextBoxDirtyKind::InlineGeometryChanged);+ .note_visual_context_box_dirty(inline_box, VisualContextBoxDirtyKind::InlineGeometryChanged);}- // This box has at most one piece per line, so its piece indices are ordered by line.- paintable_rows.committed_side_data_mut(piece_node).piece_indices = Some(piece_indices.into());}}}diff --git a/Libraries/LibWeb/Rust/src/painting/paintable_data.rs b/Libraries/LibWeb/Rust/src/painting/paintable_data.rsindex a778f97009f..a2aadc6ceef 100644--- a/Libraries/LibWeb/Rust/src/painting/paintable_data.rs+++ b/Libraries/LibWeb/Rust/src/painting/paintable_data.rs@@ -49,8 +49,6 @@ pub struct PaintableData {pub offset: used_values::FfiCssPixelPoint,pub content_size: used_values::FfiCssPixelSize,- pub local_padding_box_union: used_values::FfiCssPixelRect,- pub local_border_box_union: used_values::FfiCssPixelRect,pub establishes_stacking_context: bool,@@ -71,8 +69,6 @@ impl Default for PaintableData {flags: 0,offset: used_values::FfiCssPixelPoint::default(),content_size: used_values::FfiCssPixelSize::default(),- local_padding_box_union: used_values::FfiCssPixelRect::default(),- local_border_box_union: used_values::FfiCssPixelRect::default(),establishes_stacking_context: false,enclosing_scroll_node_index: SpatialNodeIndex::default(),own_scroll_node_index: SpatialNodeIndex::default(),@@ -206,14 +202,12 @@ pub(crate) struct CommittedBoxFragment {pub(crate) containing_block_fragment: u32,}-/// What a row committed beside its geometry that painting reads with it: its inline content, the-/// pieces an inline box has in its line root's content, its measured scrollable overflow, and what-/// paint preparation adds for the recording. Shared records are held by `Arc`, so copying a row+/// What a row committed beside its geometry that painting reads with it: its inline content, its+/// measured scrollable overflow, and what paint preparation adds for the recording. Shared records are held by `Arc`, so copying a row/// copies reference counts.#[derive(Clone, Default)]pub(crate) struct CommittedSideData {pub(crate) inline_content: Option<std::sync::Arc<crate::layout::inline_content::InlineContent>>,- pub(crate) piece_indices: Option<std::sync::Arc<[u32]>>,pub(crate) overflow_valid_across_recommits: bool,pub(crate) overflow_relative_to_padding_box: FfiOverflowData,/// The bounds of the SVG filter the box references, as the visual context update resolved@@ -237,7 +231,6 @@ impl PartialEq for CommittedSideData {&& self.overflow_relative_to_padding_box == other.overflow_relative_to_padding_box&& self.svg_filter_bounds == other.svg_filter_bounds&& self.order_inputs == other.order_inputs- && same_payload(self.piece_indices.as_ref(), other.piece_indices.as_ref(), |a, b| a == b)&& same_payload(self.fragment_ownership.as_ref(),other.fragment_ownership.as_ref(),@@ -264,18 +257,12 @@ impl CommittedSideData {pub(crate) fn clear_committed_records(&mut self) {self.inline_content = None;- self.piece_indices = None;}pub(crate) fn box_fragments(&self) -> &[CommittedBoxFragment] {self.box_fragments.as_deref().map_or(&[], Vec::as_slice)}- /// The indices of an inline box's pieces in its line root's inline content.- pub(crate) fn piece_indices(&self) -> &[u32] {- self.piece_indices.as_deref().unwrap_or_default()- }-pub(crate) fn lines(&self) -> &[crate::layout::inline_content::LineRecord] {self.inline_content.as_ref().map_or(&[], |content| &content.lines)}@@ -297,4 +284,10 @@ impl CommittedSideData {.as_ref().map_or(&[], |content| &content.inline_box_pieces)}+ /// For a line root, the indices of the pieces of the inline box `node` among its inline box pieces, in line order.+ pub(crate) fn inline_box_piece_indices(&self, node: NodeSlotId) -> &[u32] {+ self.inline_content+ .as_ref()+ .map_or(&[], |content| content.inline_boxes.piece_indices_of(node))+ }}diff --git a/Libraries/LibWeb/Rust/src/painting/paintable_geometry.rs b/Libraries/LibWeb/Rust/src/painting/paintable_geometry.rsindex 78e94f6f198..541b754504f 100644--- a/Libraries/LibWeb/Rust/src/painting/paintable_geometry.rs+++ b/Libraries/LibWeb/Rust/src/painting/paintable_geometry.rs@@ -50,10 +50,13 @@ fn link_content_rect(link: &crate::layout::fragment_tree::FragmentLink) -> CssPi}pub(crate) fn committed_offset(arena: &impl GeometryRead, slot: NodeSlotId) -> used_values::FfiCssPixelPoint {- let data = arena.paintable_data(slot);- if node_painting::is_fragmented_inline(arena, slot) {- return data.offset;+ // NB: An inline box without pieces keeps the geometry its link gives it.+ if node_painting::is_fragmented_inline(arena, slot)+ && let Some(unions) = crate::painting::inline_box_geometry::unions(arena, slot)+ {+ return unions.content.location().into();}+ let data = arena.paintable_data(slot);let frame = data.frame();if !frame.is_physical() {let containing_block = data.containing_block;@@ -71,10 +74,12 @@ pub(crate) fn committed_offset(arena: &impl GeometryRead, slot: NodeSlotId) -> u}pub(crate) fn committed_content_size(arena: &impl GeometryRead, slot: NodeSlotId) -> used_values::FfiCssPixelSize {- let data = arena.paintable_data(slot);- if node_painting::is_fragmented_inline(arena, slot) {- return data.content_size;+ if node_painting::is_fragmented_inline(arena, slot)+ && let Some(unions) = crate::painting::inline_box_geometry::unions(arena, slot)+ {+ return unions.content.size().into();}+ let data = arena.paintable_data(slot);let frame = data.frame();arena.with_committed_fragment_link(slot, |link| {link.map_or_else(used_values::FfiCssPixelSize::default, |link| {@@ -621,11 +626,26 @@ pub(crate) fn absolute_padding_box_rect(arena: &impl GeometryRead, slot: NodeSlorect}+/// A union of the pieces of the inline box `slot`, placed where its content union lies at `absolute_content_rect`.+fn inline_box_union_at(+ arena: &impl GeometryRead,+ slot: NodeSlotId,+ absolute_content_rect: CssPixelRect,+ union: impl FnOnce(&crate::painting::inline_box_geometry::InlineBoxUnions) -> CssPixelRect,+) -> CssPixelRect {+ let Some(unions) = crate::painting::inline_box_geometry::unions(arena, slot) else {+ return CssPixelRect::from_location_and_size(absolute_content_rect.location(), Default::default());+ };+ union(&unions).translated(+ absolute_content_rect.x - unions.content.x,+ absolute_content_rect.y - unions.content.y,+ )+}+pub(crate) fn first_fragment_padding_box_rect(arena: &impl GeometryRead, slot: NodeSlotId) -> CssPixelRect {let absolute = absolute_rect(arena, slot);if node_painting::is_fragmented_inline(arena, slot) {- return CssPixelRect::from(arena.paintable_data(slot).local_padding_box_union)- .translated_by(absolute.location());+ return inline_box_union_at(arena, slot, absolute, |unions| unions.padding);}let padding = committed_padding(arena, slot);let content_size = committed_content_size(arena, slot);@@ -685,8 +705,7 @@ pub(crate) fn absolute_border_box_rects_of_fragments(pub(crate) fn first_fragment_border_box_rect(arena: &impl GeometryRead, slot: NodeSlotId) -> CssPixelRect {if node_painting::is_fragmented_inline(arena, slot) {- return CssPixelRect::from(arena.paintable_data(slot).local_border_box_union)- .translated_by(absolute_rect(arena, slot).location());+ return inline_box_union_at(arena, slot, absolute_rect(arena, slot), |unions| unions.border);}let padded = first_fragment_padding_box_rect(arena, slot);let border = committed_border_box_edges(arena, slot);diff --git a/Libraries/LibWeb/Rust/src/painting/paintable_rows.rs b/Libraries/LibWeb/Rust/src/painting/paintable_rows.rsindex 5d390b7cf54..c5c99f0df83 100644--- a/Libraries/LibWeb/Rust/src/painting/paintable_rows.rs+++ b/Libraries/LibWeb/Rust/src/painting/paintable_rows.rs@@ -70,24 +70,16 @@ mod tests {let side_data = CommittedSideData {inline_content: Some(Arc::new(InlineContent::default())),- piece_indices: Some(Arc::from([1, 2])),..Default::default()};assert!(side_data == side_data.clone());let equal_records = CommittedSideData {inline_content: Some(Arc::new(InlineContent::default())),- piece_indices: Some(Arc::from([1, 2])),..Default::default()};assert!(side_data == equal_records);- let other_pieces = CommittedSideData {- piece_indices: Some(Arc::from([1])),- ..side_data.clone()- };- assert!(side_data != other_pieces);-let without_content = CommittedSideData {inline_content: None,..side_data.clone()@@ -101,6 +93,31 @@ mod tests {assert!(side_data != measured);}+ /// Places the single piece of the inline box `node` on a line of a new line root, at the padding box `rect`.+ fn give_inline_box_a_piece(+ arena: &mut LayoutNodeArena,+ node: NodeSlotId,+ rect: crate::css::css_pixels::CssPixelRect,+ ) {+ use crate::layout::inline_content::{InlineBoxPieceRecord, InlineContent};+ use crate::layout::node_data::NodeKind;++ let root = arena.allocate_for_test().slot;+ arena.write_shape(root).set_kind(NodeKind::BlockContainer);+ arena.populate_paintable_row(root);+ arena.paintable_rows_mut().paintable_data_mut(node).containing_block = root;+ let mut content = InlineContent {+ inline_box_pieces: vec![InlineBoxPieceRecord {+ node,+ border_box_rect: rect.into(),+ ..InlineBoxPieceRecord::default()+ }],+ ..InlineContent::default()+ };+ content.index_inline_boxes();+ arena.committed_side_data_mut(root).inline_content = Some(Arc::new(content));+ }+#[test]fn overflow_queries_do_not_measure_ordinary_inline_fragments() {use crate::css::css_pixels::{CssPixelRect, CssPixels};@@ -118,10 +135,7 @@ mod tests {CssPixels::from_integer(100),CssPixels::from_integer(80),);- arena- .paintable_rows_mut()- .paintable_data_mut(node)- .local_padding_box_union = rect.into();+ give_inline_box_a_piece(&mut arena, node, rect);arena.measure_scrollable_overflow();let rows = arena.paintable_rows();@@ -147,10 +161,7 @@ mod tests {CssPixels::from_integer(100),CssPixels::from_integer(80),);- arena- .paintable_rows_mut()- .paintable_data_mut(node)- .local_padding_box_union = rect.into();+ give_inline_box_a_piece(&mut arena, node, rect);arena.measure_scrollable_overflow();assert_eq!(paintable_geometry::scrollable_overflow_rect(&arena.paintable_rows(), node),@@ -183,10 +194,7 @@ mod tests {CssPixels::from_integer(100),CssPixels::from_integer(80),);- arena- .paintable_rows_mut()- .paintable_data_mut(node)- .local_padding_box_union = rect.into();+ give_inline_box_a_piece(&mut arena, node, rect);{let mut committed = arena.committed_side_data_mut(node);committed.overflow_relative_to_padding_box = FfiOverflowData {@@ -536,8 +544,6 @@ wherelet mut data = self.paintable_data_mut(id);data.offset = used_values::FfiCssPixelPoint::default();data.content_size = used_values::FfiCssPixelSize::default();- data.local_padding_box_union = used_values::FfiCssPixelRect::default();- data.local_border_box_union = used_values::FfiCssPixelRect::default();}// The row's damage is deliberately kept; the commit diff pushes what actually changed.let filter = {@@ -1248,6 +1254,7 @@ impl LayoutNodeArena {piece.node = new_node;}}+ content.index_inline_boxes();}pub(crate) fn push_propagated_text_decoration_damage(&mut self, root: NodeSlotId) {@@ -1292,16 +1299,15 @@ impl LayoutNodeArena {pub(crate) fn with_inline_pieces(arena: &impl GeometryRead,inline_paintable: NodeSlotId,- mut callback: impl FnMut(&InlineBoxPieceRecord, &PaintableData) -> bool,+ mut callback: impl FnMut(&InlineBoxPieceRecord) -> bool,) {let Some(root) = arena.inline_pieces_root(inline_paintable) else {return;};- let data = arena.paintable_data(inline_paintable);let root_side = arena.committed_side_data(root);- for piece_index in arena.committed_side_data(inline_paintable).piece_indices() {+ for piece_index in root_side.inline_box_piece_indices(inline_paintable) {let piece = &root_side.inline_box_pieces()[*piece_index as usize];- if !callback(piece, data) {+ if !callback(piece) {return;}}diff --git a/Libraries/LibWeb/Rust/src/painting/published_frame.rs b/Libraries/LibWeb/Rust/src/painting/published_frame.rsindex 0fb565c7430..0ca25cd33d1 100644--- a/Libraries/LibWeb/Rust/src/painting/published_frame.rs+++ b/Libraries/LibWeb/Rust/src/painting/published_frame.rs@@ -279,13 +279,13 @@ mod tests {link.inset_left = CssPixels::from_integer(10);arena.set_committed_fragment_link(node, link.clone(), None);arena.paintable_rows_mut().paintable_data_mut(node).offset.x = CssPixels::from_integer(10).into();- arena.committed_side_data_mut(node).piece_indices = Some([0].into());+ arena.committed_side_data_mut(node).inline_content = Some(Default::default());let published = arena.publish_rows();link.inset_left = CssPixels::from_integer(20);arena.set_committed_fragment_link(node, link, None);arena.paintable_rows_mut().paintable_data_mut(node).offset.x = CssPixels::from_integer(20).into();- arena.committed_side_data_mut(node).piece_indices = None;+ arena.committed_side_data_mut(node).inline_content = None;assert_eq!(published.paintable_data(node).offset.x,@@ -295,7 +295,7 @@ mod tests {published.with_committed_fragment_link(node, |link| link.map(|link| link.inset_left)),Some(CssPixels::from_integer(10)));- assert_eq!(published.committed_side_data(node).piece_indices(), [0]);+ assert!(published.committed_side_data(node).inline_content.is_some());assert_eq!(arena.live_paintable_data(node).offset.x,CssPixels::from_integer(20).into()@@ -304,7 +304,7 @@ mod tests {arena.with_committed_fragment_link(node, |link| link.map(|link| link.inset_left)),Some(CssPixels::from_integer(20)));- assert!(arena.committed_side_data(node).piece_indices().is_empty());+ assert!(arena.committed_side_data(node).inline_content.is_none());}fn derived_facts<'a>(row: Option<impl PaintRow<'a>>) -> Option<[bool; 5]> {diff --git a/Libraries/LibWeb/Rust/src/painting/record/hit_test_items.rs b/Libraries/LibWeb/Rust/src/painting/record/hit_test_items.rsindex acea527cda8..13b4db95149 100644--- a/Libraries/LibWeb/Rust/src/painting/record/hit_test_items.rs+++ b/Libraries/LibWeb/Rust/src/painting/record/hit_test_items.rs@@ -375,8 +375,8 @@ impl<'a, O: Observer> PaintRecorder<'a, O> {fn inline_has_content(&self, paintable: NodeSlotId) -> bool {let has_content_pieces = self.inline_root(paintable).is_some_and(|root| {self.source- .committed_side_data(paintable)- .piece_indices()+ .committed_side_data(root)+ .inline_box_piece_indices(paintable).iter().any(|piece_index| !self.piece_of(root, *piece_index).is_geometry_only_placeholder)});@@ -390,8 +390,8 @@ impl<'a, O: Observer> PaintRecorder<'a, O> {let root_positions = self.line_root_positions(root);let layout_arena = self.source;let context = self.data(paintable).accumulated_visual_context;- for piece_index in layout_arena.committed_side_data(paintable).piece_indices() {- let side = layout_arena.committed_side_data(root);+ let side = layout_arena.committed_side_data(root);+ for piece_index in side.inline_box_piece_indices(paintable) {let piece = &side.inline_box_pieces()[*piece_index as usize];if piece.is_geometry_only_placeholder {continue;diff --git a/Libraries/LibWeb/Rust/src/painting/record/paint/background.rs b/Libraries/LibWeb/Rust/src/painting/record/paint/background.rsindex 4c18aee0e13..961e6745c60 100644--- a/Libraries/LibWeb/Rust/src/painting/record/paint/background.rs+++ b/Libraries/LibWeb/Rust/src/painting/record/paint/background.rs@@ -1058,8 +1058,8 @@ fn append_text_clip_paths<O: Observer>(recorder: &mut PaintRecorder<'_, O>, pain&& node_painting::has_lines(recorder.source, root){let layout_arena = recorder.source;- for piece_index in layout_arena.committed_side_data(paintable).piece_indices() {- let side = layout_arena.committed_side_data(root);+ let side = layout_arena.committed_side_data(root);+ for piece_index in side.inline_box_piece_indices(paintable) {let piece = &side.inline_box_pieces()[*piece_index as usize];for fragment_index in piece.first_fragment_index..piece.first_fragment_index + piece.fragment_count {append_fragment(recorder, root, fragment_index as usize);diff --git a/Libraries/LibWeb/Rust/src/painting/record/paint/inline_box.rs b/Libraries/LibWeb/Rust/src/painting/record/paint/inline_box.rsindex 167b6ee63c9..826b6305e5b 100644--- a/Libraries/LibWeb/Rust/src/painting/record/paint/inline_box.rs+++ b/Libraries/LibWeb/Rust/src/painting/record/paint/inline_box.rs@@ -23,13 +23,7 @@ pub(crate) fn paint<O: Observer>(recorder: &mut PaintRecorder<'_, O>, paintable:if matches!(phase, PaintPhase::Background | PaintPhase::Border) && !recorder.is_recording_svg_resource_content() {return;}- let arena = recorder.source;- paint_pieces(- recorder,- paintable,- phase,- arena.committed_side_data(paintable).piece_indices(),- );+ paint_pieces(recorder, paintable, phase, None);}pub(crate) fn paint_piece<O: Observer>(recorder: &mut PaintRecorder<'_, O>, root: NodeSlotId, index: u32) {@@ -44,7 +38,7 @@ pub(crate) fn paint_piece<O: Observer>(recorder: &mut PaintRecorder<'_, O>, root}let context = recorder.context_for_phase(paintable, phase);recorder.recorder.set_accumulated_visual_context(context);- paint_pieces(recorder, paintable, phase, &[index]);+ paint_pieces(recorder, paintable, phase, Some(&[index]));}recorder.recorder.set_accumulated_visual_context(Default::default());}@@ -53,7 +47,7 @@ fn paint_pieces<O: Observer>(recorder: &mut PaintRecorder<'_, O>,paintable: NodeSlotId,phase: PaintPhase,- piece_indices: &[u32],+ only_piece_indices: Option<&[u32]>,) {let root = {let block = recorder.data(paintable).containing_block;@@ -72,6 +66,7 @@ fn paint_pieces<O: Observer>(root_positions.of_line(side.lines(), piece.line_index as usize)};let root_pieces = &side.inline_box_pieces();+ let piece_indices = only_piece_indices.unwrap_or_else(|| side.inline_box_piece_indices(paintable));let facts = recorder.base_paint_facts(paintable);if phase == PaintPhase::Background && facts.is_visible {