Skip to content

Truly independent web browser

LibWeb: Place every child through one function

Aliaksandr Kalenik18fe2600a09b
diff --git a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
index 84afa8ff1d1..4f7158204db 100644
--- a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
+++ b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
@@ -3253,17 +3253,16 @@ impl<'pass> AbsposEngine<'pass> {
let mut placed_child = formatting_context::PlacedChild::of_laid_out_box(&laid_out_box, line_data);
placed_child.facts_decided_by_parent.used_insets = used_insets;
placed_child.facts_decided_by_parent.default_scroll_shift = default_scroll_shift;
- formatting_context::place_child_in_containing_block(
+ placed_child.abspos_layout_inputs = Some(inputs);
+ formatting_context::place_child(
run,
node,
placed_child,
- inputs.containing_block,
FfiCssPixelPoint {
x: used_offset.inline_offset,
y: used_offset.block_offset,
},
None,
- Some(inputs),
fragment_arrival,
);
used_offset.block_offset + metrics.content_block_size() + metrics.border_box_bottom(collapsed)
diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
index 8002a3acb3b..3af1156259c 100644
--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
@@ -847,34 +847,6 @@ impl<'pass> BlockFormattingContext<'pass> {
handed_over.unwrap_or_else(|| self.run.records.box_metrics_of(node).input_cells())
}
- fn place_laid_out_child(
- &self,
- node: Node,
- placed_child: formatting_context::PlacedChild,
- offset: FfiCssPixelPoint,
- fragment_arrival: Option<fragment_tree::ChildFragmentArrival>,
- ) {
- self.place_laid_out_child_on_line(node, placed_child, offset, None, fragment_arrival);
- }
-
- fn place_laid_out_child_on_line(
- &self,
- node: Node,
- placed_child: formatting_context::PlacedChild,
- offset: FfiCssPixelPoint,
- containing_line_box_fragment: Option<used_values::LineBoxFragmentCoordinate>,
- fragment_arrival: Option<fragment_tree::ChildFragmentArrival>,
- ) -> Option<fragment_tree::PlacedFragment> {
- formatting_context::place_laid_out_child(
- &self.run,
- node,
- placed_child,
- offset,
- containing_line_box_fragment,
- fragment_arrival,
- )
- }
-
fn register_contained_abspos_child(&self, node: Node, block_offset: CssPixels, coordinate_space_box: Node) {
let static_position = abspos_inputs::StaticPositionRect {
rect: geometry::LogicalRect {
@@ -2208,13 +2180,15 @@ impl<'pass> BlockFormattingContext<'pass> {
))
};
- self.place_laid_out_child(
+ formatting_context::place_child(
+ &self.run,
marker,
formatting_context::PlacedChild::of_laid_out_box(&marker_box, marker_line_data),
FfiCssPixelPoint {
x: round_css_pixels(marker_inline_offset),
y: marker_block_offset,
},
+ None,
fragment_arrival,
);
Some(
@@ -3066,7 +3040,8 @@ impl<'pass> BlockFormattingContext<'pass> {
);
let mut placed = match pending_position {
Some(position) => {
- let placed = self.place_laid_out_child_on_line(
+ let placed = formatting_context::place_child(
+ &self.run,
node,
placed_child,
position,
@@ -3261,20 +3236,23 @@ impl<'pass> BlockFormattingContext<'pass> {
entry.depends_on_percentage_block_size,
);
let insets = self.compute_inset(&self.run, node, block_container);
- formatting_context::place_reused_child(
+ formatting_context::place_child(
&self.run,
node,
- used_values::RecordInFrame::new(used, self.run.callbacks.frame).cells(),
- run_records::FactsDecidedByParent {
- used_insets: insets.used_insets.unwrap_or_default(),
- default_scroll_shift: insets.default_scroll_shift,
- ..run_records::FactsDecidedByParent::default()
- },
+ formatting_context::PlacedChild::new(fragment_tree::FragmentGeometry {
+ cells: used_values::RecordInFrame::new(used, self.run.callbacks.frame).cells(),
+ line_data: None,
+ })
+ .with_in_flow_box_insets(insets),
FfiCssPixelPoint {
x: entry.offset_from_flow_position.x,
y: entry.offset_from_flow_position.y + flow_position,
},
- fragment,
+ None,
+ Some(fragment_tree::ChildFragmentArrival::CommittedFragment {
+ fragment,
+ reuses_subtree: true,
+ }),
);
used.seal_own_metrics();
self.block_offset_of_current_block_container
@@ -4486,13 +4464,15 @@ impl<'pass> BlockFormattingContext<'pass> {
let legend_fragment_arrival = self.pending_legend_fragment_arrival.take();
let placed_legend = self.pending_legend_placed_child.take();
if let Some(legend_flow_position) = self.pending_legend_flow_position.take() {
- self.place_laid_out_child(
+ formatting_context::place_child(
+ &self.run,
legend,
placed_legend.expect("the rendered legend is laid out before the fieldset places it"),
FfiCssPixelPoint {
x: legend_flow_position.inline_offset,
y: legend_content_block_offset,
},
+ None,
legend_fragment_arrival,
);
if let Some(index) = index_of_legend_in_root_flow_children
@@ -4967,7 +4947,8 @@ impl<'pass> BlockFormattingContext<'pass> {
} else {
floating_box.percentage_basis_inline_size.unwrap_or_default() - floating_box.offset_from_edge
};
- self.place_laid_out_child(
+ formatting_context::place_child(
+ &self.run,
node,
float_handed_back_by_its_run
.unwrap_or_else(|| formatting_context::PlacedChild::of_record(self.used(node), &self.run))
@@ -4977,6 +4958,7 @@ impl<'pass> BlockFormattingContext<'pass> {
x: inline_offset,
y: content_block_offset,
},
+ None,
fragment_arrival,
);
(insets, laid_out_float_handed_back_by_its_run)
diff --git a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
index bb50504e523..711ce56f01e 100644
--- a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
@@ -3993,7 +3993,7 @@ impl<'pass> FlexFormattingContext<'pass> {
.collect();
self.resolve_baseline_aligned_items();
for (index, (fragment_arrival, placed_item)) in laid_out_items.into_iter().enumerate() {
- formatting_context::place_laid_out_child(
+ formatting_context::place_child(
&self.run,
self.flex_items[index].box_,
placed_item,
diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
index 2cc148b23e9..fb77ad76ada 100644
--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
@@ -354,6 +354,9 @@ pub(crate) struct PlacedChild {
/// The offset the relative positioning of the fragmented inline boxes a block-level child interrupts gives the
/// child's committed fragment.
pub(crate) offset_from_relatively_positioned_inline_ancestors: FfiCssPixelPoint,
+ /// For an absolutely positioned child, the inputs it was laid out with, which name the containing block it is
+ /// placed in.
+ pub(crate) abspos_layout_inputs: Option<abspos_inputs::AbsposLayoutInputs>,
}
impl PlacedChild {
@@ -363,6 +366,7 @@ impl PlacedChild {
geometry,
facts_decided_by_parent: run_records::FactsDecidedByParent::default(),
offset_from_relatively_positioned_inline_ancestors: FfiCssPixelPoint::default(),
+ abspos_layout_inputs: None,
}
}
@@ -417,50 +421,22 @@ impl PlacedChild {
}
}
+/// Places `node` at `offset` in its containing block, taking in what the layout of the box handed its placement. An
+/// absolutely positioned child is placed in the containing block its layout inputs name, and hands its link those
+/// inputs.
pub(crate) fn place_child(
run: &FormattingContextRun,
node: Node,
placed_child: PlacedChild,
offset: FfiCssPixelPoint,
containing_line_box_fragment: Option<used_values::LineBoxFragmentCoordinate>,
-) -> Option<fragment_tree::PlacedFragment> {
- place_laid_out_child(run, node, placed_child, offset, containing_line_box_fragment, None)
-}
-
-/// Places `node`, taking in what the layout of the box handed its placement.
-pub(crate) fn place_laid_out_child(
- run: &FormattingContextRun,
- node: Node,
- placed_child: PlacedChild,
- offset: FfiCssPixelPoint,
- containing_line_box_fragment: Option<used_values::LineBoxFragmentCoordinate>,
- fragment_arrival: Option<fragment_tree::ChildFragmentArrival>,
-) -> Option<fragment_tree::PlacedFragment> {
- let containing_block = run.callbacks.in_flow_containing_block(node);
- place_child_in_containing_block(
- run,
- node,
- placed_child,
- containing_block,
- offset,
- containing_line_box_fragment,
- None,
- fragment_arrival,
- )
-}
-
-/// Places `node` in `containing_block`. An absolutely positioned box hands its link the inputs it was laid out with.
-#[expect(clippy::too_many_arguments)]
-pub(crate) fn place_child_in_containing_block(
- run: &FormattingContextRun,
- node: Node,
- placed_child: PlacedChild,
- containing_block: Node,
- offset: FfiCssPixelPoint,
- containing_line_box_fragment: Option<used_values::LineBoxFragmentCoordinate>,
- abspos_layout_inputs: Option<abspos_inputs::AbsposLayoutInputs>,
fragment_arrival: Option<fragment_tree::ChildFragmentArrival>,
) -> Option<fragment_tree::PlacedFragment> {
+ let abspos_layout_inputs = placed_child.abspos_layout_inputs;
+ let containing_block = abspos_layout_inputs.map_or_else(
+ || run.callbacks.in_flow_containing_block(node),
+ |inputs| inputs.containing_block,
+ );
let records = run.records;
let callbacks = &run.callbacks;
let placement = run_records::BoxPlacement {
@@ -484,6 +460,7 @@ pub(crate) fn place_child_in_containing_block(
geometry,
facts_decided_by_parent,
offset_from_relatively_positioned_inline_ancestors,
+ ..
} = placed_child;
debug_assert!(
facts_decided_by_parent.placement.is_none(),
@@ -616,62 +593,6 @@ fn cells_kept_for_contained_abspos(
})
}
-/// Places an in-flow child whose committed subtree is reused as it is, with the committed fragment it was laid out
-/// to, and the sizes and box sides `cells_in_run_frame` its layout left it with.
-pub(crate) fn place_reused_child(
- run: &FormattingContextRun,
- node: Node,
- cells_in_run_frame: used_values::RootInputCells,
- facts_decided_by_parent: run_records::FactsDecidedByParent,
- offset: FfiCssPixelPoint,
- fragment: std::sync::Arc<fragment_tree::Fragment>,
-) {
- let records = run.records;
- let callbacks = &run.callbacks;
- let containing_block = callbacks.in_flow_containing_block(node);
- let placement = run_records::BoxPlacement {
- content_offset_in_containing_block: offset,
- containing_block,
- };
- records.place_box(node, placement);
- let fragments = run
- .fragments
- .as_deref()
- .expect("a reused subtree is placed by a run that builds fragments");
- fragments.note_placed_box(
- node,
- placement,
- cells_kept_for_contained_abspos(run, node, || cells_in_run_frame),
- );
- debug_assert!(
- facts_decided_by_parent.placement.is_none(),
- "a child is handed to placement before it is placed"
- );
- let facts_decided_by_parent = run_records::FactsDecidedByParent {
- placement: Some(placement),
- ..facts_decided_by_parent
- };
- fragments.attach_committed_fragment(
- node,
- fragment,
- true,
- (!containing_block.is_invalid()).then_some(containing_block),
- facts_decided_by_parent,
- None,
- None,
- point_add(
- offset,
- committed_offset_delta_at_placement(
- callbacks,
- node,
- facts_decided_by_parent.used_insets,
- FfiCssPixelPoint::default(),
- ),
- ),
- callbacks.frame,
- );
-}
-
/// The index of the line box that `node` is placed on. Both callers that place a box on a line name one that exists:
/// atomic inlines are placed while walking the laid-out lines, and an interrupting block gets its line before it is
/// laid out.
@@ -3692,6 +3613,7 @@ fn compute_root_layout(input: LayoutStageInput<'_>, should_collect_devtools_layo
PlacedChild::of_record(viewport_used, &entry_run),
FfiCssPixelPoint::default(),
None,
+ None,
);
first_child
} else {
@@ -3721,7 +3643,7 @@ fn compute_root_layout(input: LayoutStageInput<'_>, should_collect_devtools_layo
None,
);
let root_outcome = root_outcome.hand_box_back_to(&entry_run, root_for_layout);
- place_laid_out_child(
+ place_child(
&entry_run,
root_for_layout,
root_outcome.placed_child(),
diff --git a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
index 5539e3346c1..114a8410973 100644
--- a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
@@ -4704,7 +4704,7 @@ impl<'pass> GridFormattingContext<'pass> {
offset: FfiCssPixelPoint,
fragment_arrival: Option<fragment_tree::ChildFragmentArrival>,
) {
- formatting_context::place_laid_out_child(&self.run, item.box_, placed_item, offset, None, fragment_arrival);
+ formatting_context::place_child(&self.run, item.box_, placed_item, offset, None, fragment_arrival);
self.laid_out_items
.borrow_mut()
.get_mut(&item.box_)
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
index 61dcc371246..d027dac85e7 100644
--- a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
@@ -2228,7 +2228,7 @@ impl<'context> InlineFormattingContext<'context> {
for (node, position) in atomic_inlines_after_clamp_point {
self.hide_placed_atomic_inline_for_line_clamp(node);
let fragment_arrival = self.take_atomic_inline_fragment_arrival(node);
- formatting_context::place_laid_out_child(
+ formatting_context::place_child(
self.run,
node,
self.placed_atomic_inline(node),
@@ -2365,6 +2365,7 @@ impl<'context> InlineFormattingContext<'context> {
self.placed_entered_inline_box(node),
FfiCssPixelPoint::default(),
None,
+ None,
);
}
}
@@ -2386,7 +2387,7 @@ impl<'context> InlineFormattingContext<'context> {
let relative_insets =
self.relative_insets_of_inline_ancestors(self.callbacks.parent(fragment.layout_node));
let fragment_arrival = self.take_atomic_inline_fragment_arrival(fragment.layout_node);
- formatting_context::place_laid_out_child(
+ formatting_context::place_child(
self.run,
fragment.layout_node,
self.placed_atomic_inline(fragment.layout_node),
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
index 47b555777c0..e533a3d79bd 100644
--- a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
+++ b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
@@ -1034,6 +1034,7 @@ fn record_entered_inline_box(
formatting_context::PlacedChild::of_record(used, context.run).with_in_flow_box_insets(insets),
FfiCssPixelPoint::default(),
None,
+ None,
);
}
sides
diff --git a/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs
index 8ac08a15077..081c1c8bf7e 100644
--- a/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs
@@ -2325,7 +2325,7 @@ impl<'pass> MathFormattingContext<'pass> {
};
let fragment_arrival = self.take_fragment_arrival_of_child(child.node);
let placed_child = self.placed_child(child.node);
- formatting_context::place_laid_out_child(run, child.node, placed_child, offset, None, fragment_arrival);
+ formatting_context::place_child(run, child.node, placed_child, offset, None, fragment_arrival);
}
for fragment_arrival in self.fragment_arrivals_of_children.take() {
formatting_context::leave_child_unplaced(
diff --git a/Libraries/LibWeb/Rust/src/layout/replaced_with_children_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/replaced_with_children_formatting_context.rs
index 09f20cbb87b..a9d3dcf2aab 100644
--- a/Libraries/LibWeb/Rust/src/layout/replaced_with_children_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/replaced_with_children_formatting_context.rs
@@ -76,7 +76,7 @@ pub(super) fn layout_replaced_with_children(
wrapper,
wrapper_result.depends_on_percentage_block_size,
);
- formatting_context::place_laid_out_child(
+ formatting_context::place_child(
run,
wrapper,
wrapper_outcome.placed_child(),
diff --git a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs
index d04cfaafb4f..63ce5e20620 100644
--- a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs
@@ -1898,7 +1898,7 @@ impl<'pass> SvgFormattingContext<'pass> {
y: CssPixels,
fragment_arrival: Option<fragment_tree::ChildFragmentArrival>,
) {
- formatting_context::place_laid_out_child(
+ formatting_context::place_child(
&self.run,
node,
placed_child,
diff --git a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs
index fa495d76800..7de3de13971 100644
--- a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs
@@ -1274,6 +1274,7 @@ impl<'pass> TableFormattingContext<'pass> {
formatting_context::PlacedChild::of_record(record, &self.run).with_fragment_facts(fragment_facts),
content_offset,
None,
+ None,
);
record.seal_own_metrics();
participant_box.content_offset.set(content_offset);
@@ -3459,7 +3460,7 @@ impl<'pass> TableFormattingContext<'pass> {
.take()
.expect("a cell is laid out before it is placed")
.with_fragment_facts(self.cell_fragment_facts[cell_index]);
- formatting_context::place_laid_out_child(
+ formatting_context::place_child(
&self.run,
cell.box_,
placed_cell,