Skip to content

Truly independent web browser

LibWeb: Hand a float without a context of its own back with its cells

Aliaksandr Kalenik69793fbac969
diff --git a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
index 23329f8eb40..785196f8145 100644
--- a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
+++ b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
@@ -3227,7 +3227,6 @@ 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 86d210487aa..4b84356f390 100644
--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
@@ -187,7 +187,7 @@ impl LaidOutBlockLevelBox {
}
/// 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.
+/// box out in, or the cells it sizes a child in ahead of the child's layout.
#[derive(Clone, Copy)]
pub(crate) struct ChildSizedHere<'sized> {
pub(crate) node: Node,
@@ -209,7 +209,7 @@ impl<'sized> ChildSizedHere<'sized> {
}
}
- /// `node`, a child kept for its run, sized in `cells` ahead of that run.
+ /// `node`, a child sized in `cells` ahead of its layout, which takes them.
pub(crate) fn ahead_of_its_run(node: Node, cells: &'sized Cell<used_values::RootInputCells>) -> Self {
Self {
node,
@@ -2164,7 +2164,6 @@ impl<'pass> BlockFormattingContext<'pass> {
participation: ParticipationInParentFormattingContext::Item,
},
marker_cells,
- None,
true,
list_item.percentage_block_insets_have_definite_basis,
);
@@ -2234,7 +2233,6 @@ impl<'pass> BlockFormattingContext<'pass> {
sized_child.node,
input,
self.metrics_of(sized_child),
- sized_child.record(),
force_independent_context_run,
block_container.percentage_block_insets_have_definite_basis,
);
@@ -4779,10 +4777,7 @@ impl<'pass> BlockFormattingContext<'pass> {
self.dimension_float_root_inline_size(sized_float, block_container, &float_input);
let (float_layout, fragment_arrival, float_box) =
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()
- .then(|| formatting_context::PlacedChild::of_laid_out_box(&float_box));
+ let placed_float = 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);
@@ -4804,11 +4799,7 @@ impl<'pass> BlockFormattingContext<'pass> {
let Some(side) = side else {
formatting_context::leave_child_unplaced(
run,
- float_handed_back_by_its_run
- .unwrap_or_else(|| {
- formatting_context::PlacedChild::of_record(self.record_of(sized_float), &self.run)
- })
- .with_fragment_facts(fragment_facts),
+ placed_float.with_fragment_facts(fragment_facts),
fragment_arrival,
);
return (
@@ -4906,8 +4897,7 @@ impl<'pass> BlockFormattingContext<'pass> {
formatting_context::place_child(
&self.run,
node,
- float_handed_back_by_its_run
- .unwrap_or_else(|| formatting_context::PlacedChild::of_record(self.record_of(sized_float), &self.run))
+ placed_float
.with_in_flow_box_insets(insets)
.with_fragment_facts(fragment_facts),
content_offset,
diff --git a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
index 88e01f4730b..706d4639ac8 100644
--- a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
@@ -3204,7 +3204,6 @@ impl<'pass> FlexFormattingContext<'pass> {
node,
input,
cells,
- None,
false,
run.percentage_block_insets_of_root_children_have_definite_basis(run.records.used_values(run.box_)),
);
diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
index f8d037f6d58..4b08cd40c36 100644
--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
@@ -2798,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
-/// `record_kept_by_parent`, the record of the call laying the child out, 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 sizes the child in
+/// them here where it needs no run of its own.
#[allow(clippy::too_many_arguments)]
pub(crate) fn layout_inside_child_with_input_cells(
run: &FormattingContextRun,
@@ -2808,7 +2808,6 @@ 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 {
@@ -2823,9 +2822,6 @@ pub(crate) fn layout_inside_child_with_input_cells(
child_input_cells.padding_top += padding_top;
child_input_cells.padding_bottom += padding_bottom;
}
- if let Some(used) = record_kept_by_parent {
- child_input_cells.apply_to_record(used);
- }
let skipped = |out_of_flow_root_used_insets| ChildLayoutOutcome::Skipped {
depends_on_percentage_block_size: run.sizing().skipped_child_depends_on_percentage_block_size(child),
out_of_flow_root_used_insets,
@@ -2841,18 +2837,12 @@ pub(crate) fn layout_inside_child_with_input_cells(
{
// OPTIMIZATION: An empty atomic block has no formatting-context body output. Size it in the
// parent run, which will also construct its fragment when placing the box.
- // NB: A child kept without a record is sized in a record of this layout's own, and handed back like a child
- // its own run laid out.
- let record_of_this_layout;
- let used = match record_kept_by_parent {
- Some(used) => used,
- None => {
- record_of_this_layout = child_input_cells.materialize_record(run.callbacks.frame);
- &record_of_this_layout
- }
- };
+ let record_of_this_layout = child_input_cells.materialize_record(run.callbacks.frame);
let committed_fragment = run.sizing().dimension_empty_atomic_root(
- sizing_context::SizedRecord::new(child, used_values::RecordInFrame::new(used, run.callbacks.frame)),
+ sizing_context::SizedRecord::new(
+ child,
+ used_values::RecordInFrame::new(&record_of_this_layout, run.callbacks.frame),
+ ),
input.available_space,
input.containing_block_constraints,
child_run_builds_fragments,
@@ -2863,15 +2853,15 @@ pub(crate) fn layout_inside_child_with_input_cells(
.filter(|fragment| {
run.fragments.is_some()
&& fragment.is_plain_box()
- && used.shows_box_of_fragment(fragment)
+ && record_of_this_layout.shows_box_of_fragment(fragment)
&& !facts.has_anchor_names()
})
.map(|fragment| fragment_tree::ChildFragmentArrival::CommittedFragment {
fragment,
reuses_subtree: false,
});
- store_derived_baselines(used, DerivedBaselines::default());
- let laid_out_box = run_records::LaidOutChildBox::sized_in_parent_run(used);
+ store_derived_baselines(&record_of_this_layout, DerivedBaselines::default());
+ let laid_out_box = run_records::LaidOutChildBox::sized_in_parent_run(&record_of_this_layout);
return ChildLayout {
outcome: skipped(None),
fragment_arrival,
@@ -2883,23 +2873,17 @@ pub(crate) fn layout_inside_child_with_input_cells(
Some(FormattingContextType::InternalReplaced | FormattingContextType::ReplacedWithChildren)
);
if !facts.can_have_children() && !creates_replaced_context {
- // NB: A child its parent's call keeps no record of is sized in a record of this layout's own, and handed back
- // like a child its own run laid out.
- let record_of_this_layout;
- let used = match record_kept_by_parent {
- Some(used) => used,
- None => {
- record_of_this_layout = child_input_cells.materialize_record(run.callbacks.frame);
- &record_of_this_layout
- }
- };
- size_skipped_independent_root(run, parent_block, child, used, &input);
+ let record_of_this_layout = child_input_cells.materialize_record(run.callbacks.frame);
+ size_skipped_independent_root(run, parent_block, child, &record_of_this_layout, &input);
let out_of_flow_root_used_insets = matches!(
input.participation,
ParticipationInParentFormattingContext::AbsolutelyPositioned(_)
)
- .then(|| used.used_insets.get());
- return ChildLayout::of_child_sized_in_parent_run(skipped(out_of_flow_root_used_insets), used);
+ .then(|| record_of_this_layout.used_insets.get());
+ return ChildLayout::of_child_sized_in_parent_run(
+ skipped(out_of_flow_root_used_insets),
+ &record_of_this_layout,
+ );
}
let ChildRunPlan {
@@ -2913,10 +2897,6 @@ pub(crate) fn layout_inside_child_with_input_cells(
force_independent_context_run,
percentage_block_insets_of_containing_block_have_definite_basis,
);
- assert!(
- record_kept_by_parent.is_none(),
- "{child:?} is handed to a run of its own by a parent that lays it out itself"
- );
let child_run_outcome = run_formatting_context(
run.fragments.as_deref(),
child_input_cells,
diff --git a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
index 1b6a7b90cdc..28143c5d4ab 100644
--- a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
@@ -4489,7 +4489,6 @@ impl<'pass> GridFormattingContext<'pass> {
item.box_,
input,
cells,
- None,
false,
run.percentage_block_insets_of_root_children_have_definite_basis(run.records.used_values(run.box_)),
);
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
index af8370b2579..3f91c1524c4 100644
--- a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
@@ -1472,7 +1472,6 @@ impl<'context> InlineFormattingContext<'context> {
node,
input,
cells,
- None,
false,
self.block_container.percentage_block_insets_have_definite_basis,
);
@@ -2039,33 +2038,16 @@ impl<'context> InlineFormattingContext<'context> {
inline_level_iterator::ItemType::FloatingElement => {
line_builder.commit_pending_margin_before_float();
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,
+ // NB: Every float is sized in cells ahead of its layout, which takes them.
+ let cells_of_float_ahead_of_its_layout = Cell::new(used_values::cells_before_sizing(
+ &self.callbacks,
item.node,
- ))
- .is_some()
- {
- cells_of_float_ahead_of_its_run = Cell::new(used_values::cells_before_sizing(
- &self.callbacks,
- item.node,
- constraints,
- ));
- block_formatting_context::ChildSizedHere::ahead_of_its_run(
- item.node,
- &cells_of_float_ahead_of_its_run,
- )
- } else {
- record_of_float_without_formatting_context_of_its_own =
- used_values::create_used_values(&self.callbacks, item.node, constraints);
- block_formatting_context::ChildSizedHere::laid_out_in(
- item.node,
- &record_of_float_without_formatting_context_of_its_own,
- )
- };
+ constraints,
+ ));
+ let sized_float = block_formatting_context::ChildSizedHere::ahead_of_its_run(
+ item.node,
+ &cells_of_float_ahead_of_its_layout,
+ );
self.clear_floating_boxes(item.node);
line_builder.set_unbreakable_run_inline_size_interrupted_by_float(
iterator.next_unbreakable_run_inline_size(self),
diff --git a/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs
index 5cc27298532..052239434db 100644
--- a/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs
@@ -2168,7 +2168,6 @@ impl<'pass> MathFormattingContext<'pass> {
child,
input,
child_cells,
- None,
true,
run.percentage_block_insets_of_root_children_have_definite_basis(run.records.used_values(run.box_)),
);
diff --git a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs
index b42fefc712a..e03a05a25bf 100644
--- a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs
@@ -2088,7 +2088,6 @@ impl<'pass> SvgFormattingContext<'pass> {
child,
child_input,
child_cells,
- None,
true,
run.percentage_block_insets_of_root_children_have_definite_basis(run.records.used_values(run.box_)),
);
diff --git a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs
index e353ba487db..4b28ed0c2a8 100644
--- a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs
@@ -2690,7 +2690,6 @@ 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(run.records.used_values(run.box_)),