Skip to content

Truly independent web browser

LibWeb: Carry an atomic inline's cells through its layout

Aliaksandr Kalenik0bbbaf0d582d
diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
index 8dc0b0fa481..8c581aa3b75 100644
--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
@@ -2974,29 +2974,6 @@ impl ChildLayout {
}
}
-#[allow(clippy::too_many_arguments)]
-pub(crate) fn layout_inside_child(
- run: &FormattingContextRun,
- parent_block: Option<&block_formatting_context::BlockFormattingContext>,
- parent_grid: Option<&grid_formatting_context::GridFormattingContext>,
- child: Node,
- input: LayoutInput,
- force_independent_context_run: bool,
- percentage_block_insets_of_containing_block_have_definite_basis: bool,
-) -> ChildLayout {
- let child_input_cells = run.records.box_metrics_of(child).input_cells();
- layout_inside_child_with_input_cells(
- run,
- parent_block,
- parent_grid,
- child,
- input,
- child_input_cells,
- force_independent_context_run,
- percentage_block_insets_of_containing_block_have_definite_basis,
- )
-}
-
/// Lays out `child` with the input cells its parent sized it to: hands them to the child's run, or gives them to the
/// child's record where the parent lays the child out itself.
#[allow(clippy::too_many_arguments)]
@@ -3150,9 +3127,9 @@ pub(crate) fn leave_child_unplaced(
}
}
-/// The run a table cell's committing run will be (see layout_inside_child), but for the intrinsic block padding that
-/// its table hands it once rows are sized. Laid out ahead of that padding, its outputs stay in the run cache, and the
-/// committing run replays them unless they show that the run observed the root's block padding (see
+/// The run a table cell's committing run will be (see layout_inside_child_with_input_cells), but for the intrinsic
+/// block padding that its table hands it once rows are sized. Laid out ahead of that padding, its outputs stay in the
+/// run cache, and the committing run replays them unless they show that the run observed the root's block padding (see
/// fc_run_cache::run_observes_root_block_padding).
pub(crate) fn table_cell_run_shape_ahead_of_its_intrinsic_block_padding(
run: &FormattingContextRun,
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
index 3fdc11ffd6e..7af239e4ce0 100644
--- a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
@@ -1317,15 +1317,15 @@ impl<'context> InlineFormattingContext<'context> {
}
/// Starts holding `node`, an atomic inline-level box: kept for its run where it has a formatting context of its
- /// own, or with a record where this context lays it out itself.
- pub(crate) fn hold_atomic_inline(&self, node: Node) {
+ /// own, or with a record where this context lays it out itself. Returns the cells the box starts out with.
+ pub(crate) fn hold_atomic_inline(&self, node: Node) -> used_values::RootInputCells {
let constraints = self.input.containing_block_constraints;
if formatting_context::formatting_context_type_created_by_box(self.facts(node)).is_some() {
self.run
.records
- .keep_child_for_its_run(&self.callbacks, node, constraints);
+ .keep_child_for_its_run(&self.callbacks, node, constraints)
} else {
- self.create_used_values(node, constraints);
+ used_values::RecordInFrame::in_its_own_frame(self.create_used_values(node, constraints)).cells()
}
}
@@ -1472,7 +1472,14 @@ impl<'context> InlineFormattingContext<'context> {
next.map(|next| next - containing_block_offset_in_root)
}
- fn layout_inside(&self, node: Node, available_space: AvailableSpace) -> DerivedBaselines {
+ /// Lays out the contents of `node`, which starts out with the cells `cells`, and returns the baselines of its
+ /// contents and the cells its layout left it with.
+ fn layout_inside(
+ &self,
+ node: Node,
+ available_space: AvailableSpace,
+ cells: used_values::RootInputCells,
+ ) -> (DerivedBaselines, used_values::RootInputCells) {
let input = LayoutInput::new(
available_space,
self.input.containing_block_constraints,
@@ -1483,12 +1490,13 @@ impl<'context> InlineFormattingContext<'context> {
fragment_arrival,
laid_out_box,
line_data,
- } = formatting_context::layout_inside_child(
+ } = formatting_context::layout_inside_child_with_input_cells(
self.run,
Some(self.parent),
None,
node,
input,
+ cells,
false,
self.block_container.percentage_block_insets_have_definite_basis,
);
@@ -1502,31 +1510,44 @@ impl<'context> InlineFormattingContext<'context> {
}
ChildLayoutOutcome::Skipped { .. } => self.box_metrics(node).content_baselines(),
};
- let placed_child = match laid_out_box {
- Some(laid_out_box) => {
- formatting_context::PlacedChild::of_laid_out_box(&laid_out_box, line_data, self.callbacks.frame)
- }
+ let (placed_child, laid_out_cells) = match laid_out_box {
+ Some(laid_out_box) => (
+ formatting_context::PlacedChild::of_laid_out_box(&laid_out_box, line_data, self.callbacks.frame),
+ laid_out_box.cells,
+ ),
// NB: The box was laid out by this context's parent flow, in the record it keeps here.
- None => formatting_context::PlacedChild::of_record(self.run.records.used_values(node), self.run),
+ None => {
+ let record = self.run.records.used_values(node);
+ (
+ formatting_context::PlacedChild::of_record(record, self.run),
+ used_values::RecordInFrame::in_its_own_frame(record).cells(),
+ )
+ }
};
self.keep_placed_atomic_inline(node, placed_child);
- baselines
+ (baselines, laid_out_cells)
}
- pub(crate) fn dimension_box_on_line(&self, node: Node) -> DerivedBaselines {
+ /// Lays out `node`, an atomic inline-level box on a line that starts out with the cells `cells`, and returns the
+ /// baselines of its contents and the cells its layout left it with.
+ pub(crate) fn dimension_box_on_line(
+ &self,
+ node: Node,
+ cells: used_values::RootInputCells,
+ ) -> (DerivedBaselines, used_values::RootInputCells) {
let available_space = self.input.available_space;
let facts = self.facts(node);
// Any fragmented inline box should have generated line box fragments already.
if facts.is_fragmented_inline() {
- return DerivedBaselines::default();
+ return (DerivedBaselines::default(), cells);
}
- let content_baselines = self.layout_inside(node, available_space);
+ let (content_baselines, laid_out_cells) = self.layout_inside(node, available_space, cells);
debug_assert!(
- self.box_metrics(node).has_definite_inline_size(),
+ laid_out_cells.has_definite_inline_size(),
"atomic inline-level run left its root's inline size unresolved"
);
- content_baselines
+ (content_baselines, laid_out_cells)
}
#[inline]
@@ -1981,9 +2002,9 @@ impl<'context> InlineFormattingContext<'context> {
line_builder.prepare_to_append_inline_content();
if shares_items && !self.laid_out_atomic_inline(item.node) {
// NB: The box is laid out again in this run, and keeps the content baselines it had.
- self.hold_atomic_inline(item.node);
- self.dimension_box_on_line(item.node);
- item.box_cells = Some(Box::new(self.box_metrics(item.node).input_cells()));
+ let cells = self.hold_atomic_inline(item.node);
+ let (_, laid_out_cells) = self.dimension_box_on_line(item.node, cells);
+ item.box_cells = Some(Box::new(laid_out_cells));
}
let insets = self.compute_inset(item.node);
self.update_placed_atomic_inline(item.node, |placed_child| {
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
index a10677490d6..674542735db 100644
--- a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
+++ b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
@@ -983,11 +983,13 @@ impl<'iterator, 'context> InlineLevelIteratorGenerator<'iterator, 'context> {
if self.atomic_sizing == AtomicInlineSizing::Contributions {
self.size_item_by_outer_inline_contributions(&mut item);
} else {
- if self.box_model_node_stack.last().copied() != Some(node) {
- self.context().hold_atomic_inline(node);
- }
- item.content_baselines = self.context_mut().dimension_box_on_line(node);
- let box_cells = self.context().box_metrics(node).input_cells();
+ let cells = if self.box_model_node_stack.last().copied() != Some(node) {
+ self.context().hold_atomic_inline(node)
+ } else {
+ self.context().box_metrics(node).input_cells()
+ };
+ let (content_baselines, box_cells) = self.context_mut().dimension_box_on_line(node, cells);
+ item.content_baselines = content_baselines;
item.inline_size = box_cells.content_inline_size;
item.padding_start = box_cells.padding_left;
item.padding_end = box_cells.padding_right;