Skip to content

Truly independent web browser

LibWeb: Hand a box sized by its parent the record or cells its call owns

Aliaksandr Kalenik7ce46d6e7082
diff --git a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
index 15151684739..fb962a8f368 100644
--- a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
+++ b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
@@ -3179,6 +3179,7 @@ impl<'pass> AbsposEngine<'pass> {
ParticipationInParentFormattingContext::AbsolutelyPositioned(inputs),
),
cells,
+ None,
false,
// https://drafts.csswg.org/css-sizing-3/#definite
// "Additionally, the size of the containing block of an absolutely positioned element is always definite
diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
index 7f2692c7b02..aa79f2c4fc4 100644
--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
@@ -158,29 +158,42 @@ impl LaidOutBlockLevelBox {
}
}
-/// A box a block formatting context sizes, with the record the context lays the box out in where the layout of the box
-/// owns that record. The context sizes any other box in cells of its own ahead of the box's run, or in the record the
-/// run keeps for the box.
+/// A box a block formatting context sizes, in what the call laying the box out owns: the record the context lays the
+/// box out in, or the cells it sizes a child in ahead of the child's run.
#[derive(Clone, Copy)]
-pub(crate) struct ChildSizedHere<'record> {
+pub(crate) struct ChildSizedHere<'sized> {
pub(crate) node: Node,
- record_its_layout_owns: Option<&'record UsedValues>,
+ sized_in: SizedIn<'sized>,
}
-impl<'record> ChildSizedHere<'record> {
- /// `node`, sized ahead of its run or in the record the run keeps for it.
- pub(crate) fn kept_by_its_run(node: Node) -> Self {
+#[derive(Clone, Copy)]
+enum SizedIn<'sized> {
+ Record(&'sized UsedValues),
+ CellsAheadOfItsRun(&'sized Cell<used_values::RootInputCells>),
+}
+
+impl<'sized> ChildSizedHere<'sized> {
+ /// `node`, laid out in `record`, which its layout owns.
+ pub(crate) fn laid_out_in(node: Node, record: &'sized UsedValues) -> Self {
Self {
node,
- record_its_layout_owns: None,
+ sized_in: SizedIn::Record(record),
}
}
- /// `node`, laid out in `record`, which its layout owns.
- fn laid_out_in(node: Node, record: &'record UsedValues) -> Self {
+ /// `node`, a child kept for its run, sized in `cells` ahead of that run.
+ pub(crate) fn ahead_of_its_run(node: Node, cells: &'sized Cell<used_values::RootInputCells>) -> Self {
Self {
node,
- record_its_layout_owns: Some(record),
+ sized_in: SizedIn::CellsAheadOfItsRun(cells),
+ }
+ }
+
+ /// The record the box is laid out in, if the context lays it out itself.
+ fn record(self) -> Option<&'sized UsedValues> {
+ match self.sized_in {
+ SizedIn::Record(record) => Some(record),
+ SizedIn::CellsAheadOfItsRun(_) => None,
}
}
}
@@ -484,9 +497,6 @@ enum BreakMode {
// https://www.w3.org/TR/css-display/#block-formatting-context
pub(crate) struct BlockFormattingContext<'pass> {
run: FormattingContextRun<'pass>,
- /// The input cells of the children that establish formatting contexts of their own, as this block formatting
- /// context sizes them until it hands each to its run.
- cells_of_children_sized_ahead_of_their_runs: RefCell<HashMap<Node, used_values::RootInputCells>>,
/// The lines the stored run of the root laid out, which inline layout of the root's own lines may reuse a prefix of.
pub(super) previous_line_data: Option<std::sync::Arc<inline_content::InlineContent>>,
block_offset_of_current_block_container: Cell<Option<CssPixels>>,
@@ -613,7 +623,6 @@ impl<'pass> BlockFormattingContext<'pass> {
is_line_clamp_container && computed_continue == continue_value::_WEBKIT_LEGACY;
Self {
run: run.clone(),
- cells_of_children_sized_ahead_of_their_runs: RefCell::new(HashMap::default()),
previous_line_data,
block_offset_of_current_block_container: Cell::new(None),
pending_legend_flow_position: Cell::new(None),
@@ -768,96 +777,40 @@ impl<'pass> BlockFormattingContext<'pass> {
sizing_context::SizingContext::new(self.run.records, self.run.callbacks)
}
- /// Keeps `node`, a child with a formatting context of its own, for its run, and sizes it in cells of this block
- /// formatting context, starting out from the cells it was kept with, until it is handed to its run.
- pub(crate) fn keep_child_for_its_run_and_size_it_ahead(&self, node: Node, constraints: ContainingBlockConstraints) {
- let cells = self
- .run
- .records
- .keep_child_for_its_run(&self.run.callbacks, node, constraints);
- self.cells_of_children_sized_ahead_of_their_runs
- .borrow_mut()
- .insert(node, cells);
- }
-
- fn cells_of_child_sized_ahead_of_its_run(&self, node: Node) -> Option<used_values::RootInputCells> {
- let cells = self.cells_of_children_sized_ahead_of_their_runs.borrow();
- if cells.is_empty() {
- return None;
- }
- cells.get(&node).copied()
- }
-
- /// The sizes, size constraints and box sides of `node`, a box this block formatting context sizes: from the cells it
- /// sizes a child in ahead of its run, or as this run holds the box otherwise.
- fn child_metrics(&self, node: Node) -> used_values::RootInputCells {
- match self.cells_of_child_sized_ahead_of_its_run(node) {
- Some(cells) => cells,
- None => self.run.records.box_metrics_of(node).cells(),
- }
- }
-
/// The sizes, size constraints and box sides of `child`, a box this block formatting context sizes.
fn metrics_of(&self, child: ChildSizedHere<'_>) -> used_values::RootInputCells {
- match child.record_its_layout_owns {
- Some(record) => used_values::RootInputCells::capture(record),
- None => self.child_metrics(child.node),
+ match child.sized_in {
+ SizedIn::Record(record) => used_values::RootInputCells::capture(record),
+ SizedIn::CellsAheadOfItsRun(cells) => cells.get(),
}
}
fn update_cells_of(&self, child: ChildSizedHere<'_>, update: impl FnOnce(&mut used_values::RootInputCells)) {
- let Some(record) = child.record_its_layout_owns else {
- return self.update_child_cells(child.node, update);
- };
- let mut cells = used_values::RootInputCells::capture(record);
+ let mut cells = self.metrics_of(child);
update(&mut cells);
- cells.apply_to_record(record);
+ match child.sized_in {
+ SizedIn::Record(record) => cells.apply_to_record(record),
+ SizedIn::CellsAheadOfItsRun(cells_ahead) => cells_ahead.set(cells),
+ }
}
/// The record `child` is laid out in, a box this block formatting context lays out in a record.
#[track_caller]
- fn record_of<'record>(&self, child: ChildSizedHere<'record>) -> &'record UsedValues
- where
- 'pass: 'record,
- {
- child.record_its_layout_owns.unwrap_or_else(|| self.used(child.node))
+ fn record_of<'record>(&self, child: ChildSizedHere<'record>) -> &'record UsedValues {
+ child
+ .record()
+ .unwrap_or_else(|| panic!("{:?} is sized ahead of its run, not laid out here", child.node))
}
/// `child`, a box this block formatting context lays out in a record, as a box its sizing steps size there.
#[track_caller]
- fn sized_record_of<'record>(&self, child: ChildSizedHere<'record>) -> sizing_context::SizedRecord<'record>
- where
- 'pass: 'record,
- {
+ fn sized_record_of<'record>(&self, child: ChildSizedHere<'record>) -> sizing_context::SizedRecord<'record> {
sizing_context::SizedRecord::new(
child.node,
used_values::RecordInFrame::new(self.record_of(child), self.run.callbacks.frame),
)
}
- fn update_child_cells(&self, node: Node, update: impl FnOnce(&mut used_values::RootInputCells)) {
- {
- let mut cells = self.cells_of_children_sized_ahead_of_their_runs.borrow_mut();
- if let Some(child_cells) = cells.get_mut(&node) {
- update(child_cells);
- return;
- }
- }
- let used = self.used(node);
- let mut cells = used_values::RootInputCells::capture(used);
- update(&mut cells);
- cells.apply_to_record(used);
- }
-
- /// The cells `node` is handed to its run with.
- fn hand_over_child_cells(&self, node: Node) -> used_values::RootInputCells {
- let handed_over = self
- .cells_of_children_sized_ahead_of_their_runs
- .borrow_mut()
- .remove(&node);
- handed_over.unwrap_or_else(|| self.run.records.box_metrics_of(node).cells())
- }
-
fn register_contained_abspos_child(&self, node: Node, block_offset: CssPixels, coordinate_space_box: Node) {
let static_position = abspos_inputs::StaticPositionRect {
rect: geometry::LogicalRect {
@@ -2157,6 +2110,7 @@ impl<'pass> BlockFormattingContext<'pass> {
participation: ParticipationInParentFormattingContext::Item,
},
marker_cells,
+ None,
true,
list_item.percentage_block_insets_have_definite_basis,
);
@@ -2206,7 +2160,7 @@ impl<'pass> BlockFormattingContext<'pass> {
fn layout_inside(
&self,
run: &FormattingContextRun<'pass>,
- node: Node,
+ sized_child: ChildSizedHere<'_>,
block_container: BlockContainer<'pass>,
input: LayoutInput,
force_independent_context_run: bool,
@@ -2223,13 +2177,14 @@ impl<'pass> BlockFormattingContext<'pass> {
run,
Some(self),
None,
- node,
+ sized_child.node,
input,
- self.hand_over_child_cells(node),
+ self.metrics_of(sized_child),
+ sized_child.record(),
force_independent_context_run,
block_container.percentage_block_insets_have_definite_basis,
);
- outcome.report_percentage_block_size_dependency_of(run, node);
+ outcome.report_percentage_block_size_dependency_of(run, sized_child.node);
let child_layout = match outcome {
ChildLayoutOutcome::Skipped { .. } => None,
ChildLayoutOutcome::Created(child_layout) => Some(child_layout),
@@ -2361,10 +2316,15 @@ impl<'pass> BlockFormattingContext<'pass> {
let block_container_inline_size = block_container.used.content_inline_size.get();
// NB: A child with a formatting context of its own is sized in cells of this block formatting context, which its
// run takes. A box without one is laid out in a record of this call.
+ let cells_of_child_ahead_of_its_run;
let record_of_box_without_formatting_context_of_its_own;
let sized_child = if formatting_context::formatting_context_type_created_by_box(facts).is_some() {
- self.keep_child_for_its_run_and_size_it_ahead(node, input.containing_block_constraints);
- ChildSizedHere::kept_by_its_run(node)
+ cells_of_child_ahead_of_its_run = Cell::new(self.run.records.keep_child_for_its_run(
+ &self.run.callbacks,
+ node,
+ input.containing_block_constraints,
+ ));
+ ChildSizedHere::ahead_of_its_run(node, &cells_of_child_ahead_of_its_run)
} else {
record_of_box_without_formatting_context_of_its_own =
used_values::create_used_values(&self.run.callbacks, node, input.containing_block_constraints);
@@ -2429,7 +2389,7 @@ impl<'pass> BlockFormattingContext<'pass> {
let margin_top = self.margin_state.borrow().pending_margin_for_next_box();
let (_, float_handed_back_by_its_run) = self.layout_floating_box(
run,
- node,
+ sized_child,
block_container,
input,
containing_block_position_in_root,
@@ -2736,7 +2696,7 @@ impl<'pass> BlockFormattingContext<'pass> {
(metrics.border_box_left(false), metrics.border_box_top(false))
});
let (child_layout, fragment_arrival, laid_out_box) =
- self.layout_inside(run, node, block_container, inside_layout_input, true);
+ self.layout_inside(run, sized_child, 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"
@@ -3016,7 +2976,7 @@ impl<'pass> BlockFormattingContext<'pass> {
containing_line_box_fragment,
fragment_arrival_of_child_with_own_formatting_context,
);
- if let Some(record) = sized_child.record_its_layout_owns {
+ if let Some(record) = sized_child.record() {
record.seal_own_metrics();
}
placed
@@ -3095,7 +3055,7 @@ impl<'pass> BlockFormattingContext<'pass> {
fn laid_out_box_in_record_its_layout_owns(child: ChildSizedHere<'_>) -> run_records::LaidOutChildBox {
run_records::LaidOutChildBox::sized_in_parent_run(
child
- .record_its_layout_owns
+ .record()
.expect("a box laid out in this flow is laid out in a record its layout owns"),
)
}
@@ -4052,7 +4012,7 @@ impl<'pass> BlockFormattingContext<'pass> {
&& !style.min_height().is_intrinsic_sizing_constraint())
.then(|| {
sizing.calculate_inner_block_size(
- sizing_context::SizedBox::new(root, &self.child_metrics(root)),
+ sizing_context::SizedBox::new(root, self.used(root)),
own_size_space,
style.min_height(),
constraints,
@@ -4063,7 +4023,7 @@ impl<'pass> BlockFormattingContext<'pass> {
&& !style.max_height().is_intrinsic_sizing_constraint())
.then(|| {
let maximum = sizing.calculate_inner_block_size(
- sizing_context::SizedBox::new(root, &self.child_metrics(root)),
+ sizing_context::SizedBox::new(root, self.used(root)),
own_size_space,
style.max_height(),
constraints,
@@ -4650,17 +4610,18 @@ impl<'pass> BlockFormattingContext<'pass> {
/// Resolves the block size of a float that has no run of its own, sized at the inline size its block formatting
/// context gave it, where that follows without laying out its contents.
- pub(crate) fn resolve_float_root_block_size_in_parent(&self, node: Node, input: &LayoutInput) {
+ pub(crate) fn resolve_float_root_block_size_in_parent(&self, sized_float: ChildSizedHere<'_>, input: &LayoutInput) {
+ let node = sized_float.node;
let available_space = input.available_space;
self.resolve_used_block_size_if_not_treated_as_auto(
- ChildSizedHere::kept_by_its_run(node),
+ sized_float,
available_space,
input.containing_block_constraints,
);
- let block_size_is_definite_from_aspect_ratio = self.used(node).has_definite_inline_size()
+ let block_size_is_definite_from_aspect_ratio = self.metrics_of(sized_float).has_definite_inline_size()
&& self.facts(node).has_preferred_aspect_ratio()
&& self.sizing().box_is_sized_as_replaced_element(
- sizing_context::SizedBox::new(node, &self.child_metrics(node)),
+ sizing_context::SizedBox::new(node, &self.metrics_of(sized_float)),
available_space,
input.containing_block_constraints,
);
@@ -4669,7 +4630,7 @@ impl<'pass> BlockFormattingContext<'pass> {
|| self.style(node).display().is_flex_inside()
{
self.resolve_used_block_size_if_treated_as_auto(
- ChildSizedHere::kept_by_its_run(node),
+ sized_float,
available_space,
input.containing_block_constraints,
None,
@@ -4682,13 +4643,13 @@ impl<'pass> BlockFormattingContext<'pass> {
/// before.
pub(crate) fn dimension_float_root_inline_size(
&self,
- node: Node,
+ sized_float: ChildSizedHere<'_>,
block_container: BlockContainer<'pass>,
input: &LayoutInput,
) {
let available_space = input.available_space;
let block_container_inline_size = block_container.used.content_inline_size.get();
- self.resolve_vertical_box_model_metrics(ChildSizedHere::kept_by_its_run(node), block_container_inline_size);
+ self.resolve_vertical_box_model_metrics(sized_float, block_container_inline_size);
let ParticipationInParentFormattingContext::Float {
containing_block_position_in_bfc_root,
} = input.participation
@@ -4701,7 +4662,7 @@ impl<'pass> BlockFormattingContext<'pass> {
self.block_offset_adjustment_from_pending_ancestor_block_start_margins(block_container.node),
);
self.compute_inline_size(
- ChildSizedHere::kept_by_its_run(node),
+ sized_float,
available_space,
input.containing_block_constraints,
FfiCssPixelPoint {
@@ -4717,7 +4678,7 @@ impl<'pass> BlockFormattingContext<'pass> {
pub(crate) fn layout_floating_box(
&self,
run: &FormattingContextRun<'pass>,
- node: Node,
+ sized_float: ChildSizedHere<'_>,
block_container: BlockContainer<'pass>,
input: LayoutInput,
containing_block_position_in_root: FfiCssPixelPoint,
@@ -4725,6 +4686,7 @@ impl<'pass> BlockFormattingContext<'pass> {
mut line_builder: Option<&mut line_builder::LineBuilder<'_, '_>>,
fragment_facts: run_records::FragmentFactsDecidedByParent,
) -> (abspos_engine::InFlowBoxInsets, Option<run_records::LaidOutChildBox>) {
+ let node = sized_float.node;
let available_space = input.available_space;
assert!(self.facts(node).is_floating());
let mut float_input = LayoutInput {
@@ -4740,13 +4702,13 @@ impl<'pass> BlockFormattingContext<'pass> {
float_input.sizing.flex_self_block_size_resolution_space =
formatting_context::flex_self_block_size_resolution_space(
&self.sizing(),
- sizing_context::SizedBox::new(node, &self.child_metrics(node)),
+ sizing_context::SizedBox::new(node, &self.metrics_of(sized_float)),
available_space,
input.containing_block_constraints,
);
- self.dimension_float_root_inline_size(node, block_container, &float_input);
+ self.dimension_float_root_inline_size(sized_float, block_container, &float_input);
let (float_layout, fragment_arrival, float_box) =
- self.layout_inside(run, node, block_container, float_input, false);
+ self.layout_inside(run, sized_float, 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()
@@ -4773,7 +4735,9 @@ impl<'pass> BlockFormattingContext<'pass> {
formatting_context::leave_child_unplaced(
run,
float_handed_back_by_its_run
- .unwrap_or_else(|| formatting_context::PlacedChild::of_record(self.used(node), &self.run))
+ .unwrap_or_else(|| {
+ formatting_context::PlacedChild::of_record(self.record_of(sized_float), &self.run)
+ })
.with_fragment_facts(fragment_facts),
fragment_arrival,
);
@@ -4868,7 +4832,7 @@ impl<'pass> BlockFormattingContext<'pass> {
&self.run,
node,
float_handed_back_by_its_run
- .unwrap_or_else(|| formatting_context::PlacedChild::of_record(self.used(node), &self.run))
+ .unwrap_or_else(|| formatting_context::PlacedChild::of_record(self.record_of(sized_float), &self.run))
.with_in_flow_box_insets(insets)
.with_fragment_facts(fragment_facts),
FfiCssPixelPoint {
diff --git a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
index 24b4f9eae79..027d56cd67c 100644
--- a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
@@ -3099,6 +3099,7 @@ impl<'pass> FlexFormattingContext<'pass> {
node,
input,
cells,
+ None,
false,
run.percentage_block_insets_of_root_children_have_definite_basis(),
);
diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
index 6610a3224a3..951a32b4c2c 100644
--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
@@ -1928,14 +1928,16 @@ fn size_skipped_independent_root(
run: &FormattingContextRun,
parent_block: Option<&block_formatting_context::BlockFormattingContext>,
child: Node,
+ record: &UsedValues,
input: &LayoutInput,
) {
match input.participation {
ParticipationInParentFormattingContext::Float { .. } => {
let parent = parent_block.expect("a float requires an enclosing block formatting context");
- parent.resolve_float_root_block_size_in_parent(child, input);
+ let sized_float = block_formatting_context::ChildSizedHere::laid_out_in(child, record);
+ parent.resolve_float_root_block_size_in_parent(sized_float, input);
parent.resolve_used_block_size_if_treated_as_auto(
- block_formatting_context::ChildSizedHere::kept_by_its_run(child),
+ sized_float,
input.available_space,
input.containing_block_constraints,
None,
@@ -2796,8 +2798,8 @@ impl ChildLayout {
}
}
-/// 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.
+/// Lays out `child` with the input cells its parent sized it to: hands them to the child's run, or gives them to
+/// `record_kept_by_parent`, the record of the call laying the child out, where the parent lays the child out itself.
#[allow(clippy::too_many_arguments)]
pub(crate) fn layout_inside_child_with_input_cells(
run: &FormattingContextRun,
@@ -2806,6 +2808,7 @@ pub(crate) fn layout_inside_child_with_input_cells(
child: Node,
input: LayoutInput,
mut child_input_cells: used_values::RootInputCells,
+ record_kept_by_parent: Option<&UsedValues>,
force_independent_context_run: bool,
percentage_block_insets_of_containing_block_have_definite_basis: bool,
) -> ChildLayout {
@@ -2820,11 +2823,9 @@ pub(crate) fn layout_inside_child_with_input_cells(
child_input_cells.padding_top += padding_top;
child_input_cells.padding_bottom += padding_bottom;
}
- let record_kept_by_parent = (!run.records.keeps_child_without_record(child)).then(|| {
- let used = run.records.used_values(child);
+ if let Some(used) = record_kept_by_parent {
child_input_cells.apply_to_record(used);
- used
- });
+ }
// NB: A child kept without a record that this run lays out itself gets a record of the cells it was handed.
let record_for_this_run = || {
record_kept_by_parent.unwrap_or_else(|| {
@@ -2899,7 +2900,7 @@ pub(crate) fn layout_inside_child_with_input_cells(
return ChildLayout::of_child_sized_in_parent_run(skipped(), &record_of_this_layout);
}
let used = record_for_this_run();
- size_skipped_independent_root(run, parent_block, child, &input);
+ size_skipped_independent_root(run, parent_block, child, used, &input);
return ChildLayout::of_child_sized_in_parent_run(skipped(), used);
}
diff --git a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
index 6fdc308b6a0..a1972783938 100644
--- a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
@@ -4467,6 +4467,7 @@ impl<'pass> GridFormattingContext<'pass> {
item.box_,
input,
cells,
+ None,
false,
run.percentage_block_insets_of_root_children_have_definite_basis(),
);
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
index 2c7d7df8063..265a713c3c5 100644
--- a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
@@ -1237,14 +1237,6 @@ impl<'context> InlineFormattingContext<'context> {
/// The sizes, box sides and baselines of `node`, a box this context lays out or one it keeps for a run of its own
/// that has not laid it out yet.
#[track_caller]
- pub(crate) fn create_used_values(
- &self,
- node: Node,
- constraints: ContainingBlockConstraints,
- ) -> &'context UsedValues {
- self.run.records.create_used_values(&self.callbacks, node, constraints)
- }
-
/// Keeps the sizes and box sides `sides` and the used insets `insets` this context resolved for `node`, an inline
/// box it entered.
pub(crate) fn keep_entered_inline_box(
@@ -1485,6 +1477,7 @@ impl<'context> InlineFormattingContext<'context> {
node,
input,
cells,
+ None,
false,
self.block_container.percentage_block_insets_have_definite_basis,
);
@@ -2040,19 +2033,35 @@ impl<'context> InlineFormattingContext<'context> {
}
inline_level_iterator::ItemType::FloatingElement => {
line_builder.commit_pending_margin_before_float();
- if formatting_context::formatting_context_type_created_by_box(NodeFacts::new(
+ let constraints = self.input.containing_block_constraints;
+ // NB: A float with a formatting context of its own is sized ahead of its run, and any other is
+ // laid out in a record of this call.
+ let cells_of_float_ahead_of_its_run;
+ let record_of_float_without_formatting_context_of_its_own;
+ let sized_float = if formatting_context::formatting_context_type_created_by_box(NodeFacts::new(
&self.run.callbacks,
item.node,
))
.is_some()
{
- self.parent.keep_child_for_its_run_and_size_it_ahead(
+ cells_of_float_ahead_of_its_run = Cell::new(self.run.records.keep_child_for_its_run(
+ &self.callbacks,
item.node,
- self.input.containing_block_constraints,
- );
+ constraints,
+ ));
+ block_formatting_context::ChildSizedHere::ahead_of_its_run(
+ item.node,
+ &cells_of_float_ahead_of_its_run,
+ )
} else {
- self.create_used_values(item.node, self.input.containing_block_constraints);
- }
+ record_of_float_without_formatting_context_of_its_own =
+ used_values::create_used_values(&self.callbacks, item.node, constraints);
+ self.run.records.keep_box_laid_out_in_record_its_layout_owns(item.node);
+ block_formatting_context::ChildSizedHere::laid_out_in(
+ item.node,
+ &record_of_float_without_formatting_context_of_its_own,
+ )
+ };
if state_at_clamp_point.is_some() {
self.run.records.hide_for_line_clamp(item.node);
}
@@ -2062,7 +2071,7 @@ impl<'context> InlineFormattingContext<'context> {
);
let (insets, _) = self.parent.layout_floating_box(
self.run,
- item.node,
+ sized_float,
self.block_container,
self.input,
self.containing_block_position_in_bfc_root,
diff --git a/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs
index 4b9b9b18238..c3c3d7e862d 100644
--- a/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs
@@ -2168,6 +2168,7 @@ impl<'pass> MathFormattingContext<'pass> {
child,
input,
child_cells,
+ None,
true,
run.percentage_block_insets_of_root_children_have_definite_basis(),
);
diff --git a/Libraries/LibWeb/Rust/src/layout/run_records.rs b/Libraries/LibWeb/Rust/src/layout/run_records.rs
index 40ffb2da5e1..02ccf866e2f 100644
--- a/Libraries/LibWeb/Rust/src/layout/run_records.rs
+++ b/Libraries/LibWeb/Rust/src/layout/run_records.rs
@@ -582,20 +582,6 @@ impl<'arena> RunRecords<'arena> {
);
}
- /// Whether this run keeps `child` without a record, for runs of its own: before the first of them returns, or once
- /// the last one handed it back.
- pub(crate) fn keeps_child_without_record(&self, child: Node) -> bool {
- if self.is_root_with_record(child) {
- return false;
- }
- self.held_boxes.borrow().get(&child).is_some_and(|kept| {
- !matches!(
- kept.holding,
- KeptBoxHolding::LaidOutByThisRun { .. } | KeptBoxHolding::LaidOutInRecordItsLayoutOwns
- )
- })
- }
-
/// Gives `child`, a box this run keeps without a record, a record with the cells `cells`, for this run to lay the
/// box out itself.
#[track_caller]
diff --git a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs
index c090a538266..7986c15759b 100644
--- a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs
@@ -2093,6 +2093,7 @@ impl<'pass> SvgFormattingContext<'pass> {
child,
child_input,
child_cells,
+ None,
true,
run.percentage_block_insets_of_root_children_have_definite_basis(),
);
diff --git a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs
index fd5f66381d3..d63ddc2a182 100644
--- a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs
@@ -2701,6 +2701,7 @@ impl<'pass> TableFormattingContext<'pass> {
cell.box_,
layout_input,
self.cell_box_cells[cell_index],
+ None,
false,
// NB: A table cell is a containing block of its own to the percentage block insets of its descendants.
run.percentage_block_insets_of_root_children_have_definite_basis(),