Truly independent web browser
LibWeb: Hand a child's lines back inside its laid out box
Aliaksandr Kalenikdd5030555138
diff --git a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rsindex 3e68fe9844a..822665288e0 100644--- a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs+++ b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs@@ -3173,7 +3173,6 @@ impl<'pass> AbsposEngine<'pass> {outcome,fragment_arrival,laid_out_box,- line_data,} = formatting_context::layout_inside_child_with_input_cells(run,None,@@ -3246,7 +3245,7 @@ impl<'pass> AbsposEngine<'pass> {}}self.records.set_used_insets(node, used_insets);- let mut placed_child = formatting_context::PlacedChild::of_laid_out_box(&laid_out_box, line_data);+ let mut placed_child = formatting_context::PlacedChild::of_laid_out_box(&laid_out_box);placed_child.facts_decided_by_parent.used_insets = used_insets;placed_child.facts_decided_by_parent.default_scroll_shift = default_scroll_shift;placed_child.abspos_layout_inputs = Some(inputs);diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rsindex 3223abad657..7f2692c7b02 100644--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs@@ -2142,7 +2142,6 @@ impl<'pass> BlockFormattingContext<'pass> {outcome: marker_outcome,fragment_arrival,laid_out_box: marker_box,- line_data: marker_line_data,} = formatting_context::layout_inside_child_with_input_cells(run,None,@@ -2187,7 +2186,7 @@ impl<'pass> BlockFormattingContext<'pass> {formatting_context::place_child(&self.run,marker,- formatting_context::PlacedChild::of_laid_out_box(&marker_box, marker_line_data),+ formatting_context::PlacedChild::of_laid_out_box(&marker_box),FfiCssPixelPoint {x: round_css_pixels(marker_inline_offset),y: marker_block_offset,@@ -2203,8 +2202,7 @@ impl<'pass> BlockFormattingContext<'pass> {}/// Lays out the contents of `node`, a child with a formatting context of its own, and returns its result where a- /// run of its own laid it out, the fragments its placement takes, the child's box as its layout left it, and the- /// lines that layout laid out in it.+ /// run of its own laid it out, the fragments its placement takes, and the child's box as its layout left it.fn layout_inside(&self,run: &FormattingContextRun<'pass>,@@ -2216,13 +2214,11 @@ impl<'pass> BlockFormattingContext<'pass> {Option<formatting_context::ChildLayoutResult>,Option<fragment_tree::ChildFragmentArrival>,run_records::LaidOutChildBox,- Option<std::sync::Arc<inline_content::InlineContent>>,) {let formatting_context::ChildLayout {outcome,fragment_arrival,laid_out_box,- line_data,} = formatting_context::layout_inside_child_with_input_cells(run,Some(self),@@ -2238,7 +2234,7 @@ impl<'pass> BlockFormattingContext<'pass> {ChildLayoutOutcome::Skipped { .. } => None,ChildLayoutOutcome::Created(child_layout) => Some(child_layout),};- (child_layout, fragment_arrival, laid_out_box, line_data)+ (child_layout, fragment_arrival, laid_out_box)}fn child_layout_input(@@ -2739,20 +2735,17 @@ impl<'pass> BlockFormattingContext<'pass> {let metrics = self.metrics_of(sized_child);(metrics.border_box_left(false), metrics.border_box_top(false))});- let (child_layout, fragment_arrival, laid_out_box, line_data) =+ let (child_layout, fragment_arrival, laid_out_box) =self.layout_inside(run, node, block_container, inside_layout_input, true);assert!(child_layout.is_some(),"a block-level box with a formatting context of its own is laid out by its run");fragment_arrival_of_child_with_own_formatting_context = fragment_arrival;- child_handed_back_by_its_run = Some(formatting_context::PlacedChild::of_laid_out_box(- &laid_out_box,- line_data,- ));+ child_handed_back_by_its_run = Some(formatting_context::PlacedChild::of_laid_out_box(&laid_out_box));+ let table_box = laid_out_box.cells;laid_out_box_handed_back_by_its_run = Some(laid_out_box);if container_facts.is_table_wrapper() && style.display().is_table_inside() {- let table_box = laid_out_box.cells;self.table_box_in_wrapper_border_box_inline_size.set(Some(table_box.border_box_inline_size(table_box.uses_collapsing_borders_model()),));@@ -4752,12 +4745,13 @@ impl<'pass> BlockFormattingContext<'pass> {input.containing_block_constraints,);self.dimension_float_root_inline_size(node, block_container, &float_input);- let (float_layout, fragment_arrival, float_box, float_line_data) =+ let (float_layout, fragment_arrival, float_box) =self.layout_inside(run, node, block_container, float_input, false);// NB: A float its own run laid out is placed as that run handed it back, and any other with its record here.let float_handed_back_by_its_run = float_layout.is_some()- .then(|| formatting_context::PlacedChild::of_laid_out_box(&float_box, float_line_data));+ .then(|| formatting_context::PlacedChild::of_laid_out_box(&float_box));+ let float_box_cells = float_box.cells;let laid_out_float_handed_back_by_its_run = float_layout.is_some().then_some(float_box);let containing_block_rect = self.containing_block_rect(block_container, containing_block_position_in_root);let containing_block_rect_now = containing_block_rect.translated(@@ -4788,7 +4782,7 @@ impl<'pass> BlockFormattingContext<'pass> {laid_out_float_handed_back_by_its_run,);};- let float_box = float_box.cells;+ let float_box = float_box_cells;let mut margin_box_ceiling = if let Some(line_builder) = line_builder.as_deref_mut() {line_builder.ceiling_for_float_to_be_inserted_here(float_box.margin_box_inline_size(false))} else {diff --git a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rsindex aa508ae35ab..24b4f9eae79 100644--- a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs@@ -3092,7 +3092,6 @@ impl<'pass> FlexFormattingContext<'pass> {outcome,fragment_arrival,laid_out_box,- line_data,} = formatting_context::layout_inside_child_with_input_cells(run,None,@@ -3106,11 +3105,8 @@ impl<'pass> FlexFormattingContext<'pass> {self.flex_items[index].cells = laid_out_box.cells;self.flex_items[index].orthogonal_flow_baselines = laid_out_box.orthogonal_flow_baselines;outcome.report_percentage_block_size_dependency_of(run, node);- self.flex_items[index].content_baselines = match outcome {- ChildLayoutOutcome::Created(result) => result.baselines,- ChildLayoutOutcome::Skipped { .. } => laid_out_box.baselines,- };- let placed_item = formatting_context::PlacedChild::of_laid_out_box(&laid_out_box, line_data);+ self.flex_items[index].content_baselines = laid_out_box.baselines;+ let placed_item = formatting_context::PlacedChild::of_laid_out_box(&laid_out_box);let container_used = self.container_used();let insets = abspos_engine::compute_inset_native(diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rsindex bd472a31f77..960b56b8595 100644--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs@@ -370,15 +370,11 @@ impl PlacedChild {}}- /// A child whose run handed back the box `laid_out` with the lines `line_data`, before its parent decided anything- /// about it.- pub(crate) fn of_laid_out_box(- laid_out: &run_records::LaidOutChildBox,- line_data: Option<std::sync::Arc<inline_content::InlineContent>>,- ) -> Self {+ /// A child whose run handed back the box `laid_out`, before its parent decided anything about it.+ pub(crate) fn of_laid_out_box(laid_out: &run_records::LaidOutChildBox) -> Self {Self::new(fragment_tree::FragmentGeometry {cells: laid_out.cells,- line_data,+ line_data: laid_out.line_data.clone(),})}@@ -1103,6 +1099,7 @@ impl RunRootOutcome {cells,baselines: result.baselines,orthogonal_flow_baselines: result.orthogonal_flow_baselines,+ line_data: self.line_data.clone(),}}}@@ -1974,7 +1971,6 @@ fn body_input_with_inner_available_space(run: &FormattingContextRun, input: &Laypub(crate) struct ChildRunOutcome {pub(crate) result: ChildLayoutResult,pub(crate) laid_out_box: run_records::LaidOutChildBox,- pub(crate) line_data: Option<std::sync::Arc<inline_content::InlineContent>>,pub(crate) fragment_arrival: Option<fragment_tree::ChildFragmentArrival>,}@@ -1988,7 +1984,7 @@ impl ChildRunOutcome {/// What placing the child takes of the box its run handed back.pub(crate) fn placed_child(&self) -> PlacedChild {- PlacedChild::of_laid_out_box(&self.laid_out_box, self.line_data.clone())+ PlacedChild::of_laid_out_box(&self.laid_out_box)}}@@ -2181,7 +2177,7 @@ fn reuse_committed_subtree_as_it_is();let geometry = fragment_tree::FragmentGeometry {cells: laid_out_box.cells,- line_data: entry.outputs.root_outcome.line_data.clone(),+ line_data: laid_out_box.line_data.clone(),};if !geometry.shows_box_of_fragment(&fragment) {return None;@@ -2196,7 +2192,6 @@ fn reuse_committed_subtree_as_it_is(Some(ChildRunOutcome {result: entry.outputs.result,laid_out_box,- line_data: geometry.line_data,fragment_arrival: Some(fragment_tree::ChildFragmentArrival::CommittedFragment {fragment,reuses_subtree: true,@@ -2789,8 +2784,6 @@ pub(crate) struct ChildLayout {pub(crate) outcome: ChildLayoutOutcome,pub(crate) fragment_arrival: Option<fragment_tree::ChildFragmentArrival>,pub(crate) laid_out_box: run_records::LaidOutChildBox,- /// The lines a run of the child's own laid out in it.- pub(crate) line_data: Option<std::sync::Arc<inline_content::InlineContent>>,}impl ChildLayout {@@ -2799,7 +2792,6 @@ impl ChildLayout {outcome,fragment_arrival: None,laid_out_box: run_records::LaidOutChildBox::sized_in_parent_run(record),- line_data: None,}}}@@ -2892,7 +2884,6 @@ pub(crate) fn layout_inside_child_with_input_cells(outcome: skipped(),fragment_arrival,laid_out_box,- line_data: None,};}let creates_replaced_context = matches!(@@ -2942,14 +2933,12 @@ pub(crate) fn layout_inside_child_with_input_cells(let ChildRunOutcome {result,laid_out_box,- line_data,fragment_arrival,} = child_run_outcome.hand_box_back_to(run, child);ChildLayout {outcome: ChildLayoutOutcome::Created(result),fragment_arrival,laid_out_box,- line_data,}}@@ -3293,7 +3282,6 @@ fn child_run_outcome_from_outputs(let content_block_size_adopted_after_run =content_block_size_adopted_after_run(input, result.automatic_content_block_size);let laid_out_box = root_outcome.laid_out_child_box(root_cells, &result, content_block_size_adopted_after_run);- let line_data = root_outcome.line_data;let fragment_arrival = parent_fragments.and(root).map(|root| {debug_assert!(root.node == child, "a child run returned a root for a different box");fragment_tree::ChildFragmentArrival::RunRoot {@@ -3304,7 +3292,6 @@ fn child_run_outcome_from_outputs(ChildRunOutcome {result,laid_out_box,- line_data,fragment_arrival,}}@@ -3722,13 +3709,12 @@ fn layout_subtree_with_frozen_root_geometry(run: &FormattingContextRun<'_>) {);let ChildRunOutcome {laid_out_box: root_box,- line_data: root_line_data,fragment_arrival,..} = root_outcome.hand_box_back_to(run, root);let root_geometry = fragment_tree::FragmentGeometry {cells: root_box.cells,- line_data: root_line_data,+ line_data: root_box.line_data,};let facts_decided_by_parent = committed_root.facts_decided_by_parent;let placement = facts_decided_by_parentdiff --git a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rsindex 91703034bbd..6fdc308b6a0 100644--- a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs@@ -4460,7 +4460,6 @@ impl<'pass> GridFormattingContext<'pass> {outcome,fragment_arrival,laid_out_box,- line_data,} = formatting_context::layout_inside_child_with_input_cells(run,None,@@ -4481,7 +4480,7 @@ impl<'pass> GridFormattingContext<'pass> {content_offset: None,},);- let placed_item = formatting_context::PlacedChild::of_laid_out_box(&laid_out_box, line_data);+ let placed_item = formatting_context::PlacedChild::of_laid_out_box(&laid_out_box);let offset = FfiCssPixelPoint {x: area.offset.inline_offset + self.item_margin_box_start(item, Axis::Column),y: area.offset.block_offset + self.item_margin_box_start(item, Axis::Row),diff --git a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rsindex e5f022a723b..2c7d7df8063 100644--- a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs@@ -1478,7 +1478,6 @@ impl<'context> InlineFormattingContext<'context> {outcome,fragment_arrival,laid_out_box,- line_data,} = formatting_context::layout_inside_child_with_input_cells(self.run,Some(self.parent),@@ -1491,14 +1490,8 @@ impl<'context> InlineFormattingContext<'context> {);self.keep_atomic_inline_fragment_arrival(node, fragment_arrival);outcome.report_percentage_block_size_dependency_of(self.run, node);- let baselines = match outcome {- ChildLayoutOutcome::Created(result) => result.baselines,- ChildLayoutOutcome::Skipped { .. } => laid_out_box.baselines,- };- self.keep_placed_atomic_inline(- node,- formatting_context::PlacedChild::of_laid_out_box(&laid_out_box, line_data),- );+ let baselines = laid_out_box.baselines;+ self.keep_placed_atomic_inline(node, formatting_context::PlacedChild::of_laid_out_box(&laid_out_box));(baselines, laid_out_box.cells)}diff --git a/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rsindex 0d3d12d8685..4b9b9b18238 100644--- a/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs@@ -2161,7 +2161,6 @@ impl<'pass> MathFormattingContext<'pass> {outcome,fragment_arrival,laid_out_box,- line_data,} = formatting_context::layout_inside_child_with_input_cells(run,None,@@ -2175,16 +2174,12 @@ impl<'pass> MathFormattingContext<'pass> {if let Some(fragment_arrival) = fragment_arrival {self.fragment_arrivals_of_children.borrow_mut().push(fragment_arrival);}- self.placed_children.borrow_mut().insert(- child,- formatting_context::PlacedChild::of_laid_out_box(&laid_out_box, line_data),- );+ self.placed_children+ .borrow_mut()+ .insert(child, formatting_context::PlacedChild::of_laid_out_box(&laid_out_box));outcome.report_percentage_block_size_dependency_of(run, child);let metrics = laid_out_box.cells;- let baselines = match outcome {- ChildLayoutOutcome::Created(result) => result.baselines,- ChildLayoutOutcome::Skipped { .. } => laid_out_box.baselines,- };+ let baselines = laid_out_box.baselines;let collapsed = metrics.uses_collapsing_borders_model();let block_size = metrics.margin_box_block_size(collapsed);// NB: A box without a baseline is aligned by its line-under margin edge.diff --git a/Libraries/LibWeb/Rust/src/layout/run_records.rs b/Libraries/LibWeb/Rust/src/layout/run_records.rsindex 41ec9c8d2c2..40ffb2da5e1 100644--- a/Libraries/LibWeb/Rust/src/layout/run_records.rs+++ b/Libraries/LibWeb/Rust/src/layout/run_records.rs@@ -321,24 +321,26 @@ pub(crate) struct FactsDecidedByParent {}/// What the parent of a box laid out by a run of its own keeps of the box once that run returns: its sizes, size-/// constraints and box sides in the parent's frame, and its baselines.-#[derive(Clone, Copy, Debug, PartialEq, Eq)]+/// constraints and box sides in the parent's frame, its baselines, and the lines the run laid out in it.+#[derive(Clone)]pub(crate) struct LaidOutChildBox {pub(crate) cells: used_values::RootInputCells,pub(crate) baselines: DerivedBaselines,/// For a box that establishes an orthogonal flow, its baselines along the horizontal axis of the parent's frame.pub(crate) orthogonal_flow_baselines: Option<DerivedBaselines>,+ pub(crate) line_data: Option<std::sync::Arc<inline_content::InlineContent>>,}impl LaidOutChildBox {/// A child as the run of its parent left it in `record`, where that run sizes the child itself instead of handing- /// it to a run of its own.+ /// it to a run of its own. The record keeps any lines the parent's run laid out in it.pub(crate) fn sized_in_parent_run(record: &UsedValues) -> Self {Self {cells: used_values::RootInputCells::capture(record),baselines: record.content_baselines_from_cells(),// NB: A box that establishes an orthogonal flow is laid out by a run of its own.orthogonal_flow_baselines: None,+ line_data: None,}}}diff --git a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rsindex bc75f8b51ee..c090a538266 100644--- a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs@@ -2086,7 +2086,6 @@ impl<'pass> SvgFormattingContext<'pass> {outcome,fragment_arrival,laid_out_box,- line_data,} = formatting_context::layout_inside_child_with_input_cells(run,None,@@ -2105,7 +2104,7 @@ impl<'pass> SvgFormattingContext<'pass> {// Masks and clips may use this offset for objectBoundingBox units.self.place_laid_out_child(child,- formatting_context::PlacedChild::of_laid_out_box(&laid_out_box, line_data),+ formatting_context::PlacedChild::of_laid_out_box(&laid_out_box),rect.x,rect.y,fragment_arrival,diff --git a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rsindex 76de1f3f23e..8fa3f44d545 100644--- a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs@@ -2712,7 +2712,6 @@ impl<'pass> TableFormattingContext<'pass> {outcome,fragment_arrival,laid_out_box,- line_data,} = formatting_context::layout_inside_child_with_input_cells(run,None,@@ -2727,14 +2726,8 @@ impl<'pass> TableFormattingContext<'pass> {self.cell_box_cells[cell_index] = laid_out_box.cells;self.content_baselines_of_handed_back_cells[cell_index] = Some(laid_out_box.baselines);outcome.report_percentage_block_size_dependency_of(run, cell.box_);- let baselines = match outcome {- ChildLayoutOutcome::Created(result) => result.baselines,- ChildLayoutOutcome::Skipped { .. } => laid_out_box.baselines,- };- self.placed_cells[cell_index] = Some(formatting_context::PlacedChild::of_laid_out_box(- &laid_out_box,- line_data,- ));+ let baselines = laid_out_box.baselines;+ self.placed_cells[cell_index] = Some(formatting_context::PlacedChild::of_laid_out_box(&laid_out_box));(baselines, fragment_arrival)}@@ -3301,8 +3294,9 @@ impl<'pass> TableFormattingContext<'pass> {cells: *cell_box,baselines: measurement.baselines,orthogonal_flow_baselines: None,+ line_data: None,};- self.placed_cells[cell_index] = Some(formatting_context::PlacedChild::of_laid_out_box(&laid_out, None));+ self.placed_cells[cell_index] = Some(formatting_context::PlacedChild::of_laid_out_box(&laid_out));self.content_baselines_of_handed_back_cells[cell_index] = Some(laid_out.baselines);run.records.note_child_handed_back(cell.box_);formatting_context::propagate_percentage_block_size_dependency_to_containing_block(