Skip to content

Truly independent web browser

LibWeb: Stop re-entering a parent's layout for a child without a context

Aliaksandr Kalenik6d61794706af
diff --git a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
index 15269e40ef0..3e68fe9844a 100644
--- a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
+++ b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
@@ -3197,12 +3197,8 @@ impl<'pass> AbsposEngine<'pass> {
.out_of_flow_root_used_insets
.expect("the run of an absolutely positioned box gives it used insets"),
ChildLayoutOutcome::Skipped { .. } => self.records.used_insets_of(node),
- ChildLayoutOutcome::ReenterCurrent => {
- unreachable!("abspos child with contents did not establish a formatting context")
- }
};
- let laid_out_box = laid_out_box.expect("the layout of an absolutely positioned box leaves its box");
let metrics = laid_out_box.cells;
let collapsed = metrics.uses_collapsing_borders_model();
let static_offset = aligned_static_offset(
diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
index d069553e48b..d9964ebd7e9 100644
--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
@@ -2151,14 +2151,7 @@ impl<'pass> BlockFormattingContext<'pass> {
list_item.percentage_block_insets_have_definite_basis,
);
marker_outcome.report_percentage_block_size_dependency_of(run, marker);
- match marker_outcome {
- ChildLayoutOutcome::Created(_) | ChildLayoutOutcome::Skipped { .. } => {}
- ChildLayoutOutcome::ReenterCurrent => {
- unreachable!("marker inside layout did not establish a formatting context")
- }
- }
- let marker_box = marker_box.expect("a marker's layout leaves its box to the list item");
let marker_metrics = marker_box.cells;
let marker_block_size = marker_metrics.content_block_size();
let marker_inline_size = marker_metrics.content_inline_size();
@@ -2230,23 +2223,11 @@ impl<'pass> BlockFormattingContext<'pass> {
block_container.percentage_block_insets_have_definite_basis,
);
outcome.report_percentage_block_size_dependency_of(run, node);
- let (child_layout, laid_out_box) = match outcome {
- ChildLayoutOutcome::Skipped { .. } => (None, laid_out_box),
- ChildLayoutOutcome::Created(child_layout) => (Some(child_layout), laid_out_box),
- ChildLayoutOutcome::ReenterCurrent => {
- self.run(run, input);
- (
- None,
- Some(run_records::LaidOutChildBox::sized_in_parent_run(self.used(node))),
- )
- }
+ let child_layout = match outcome {
+ ChildLayoutOutcome::Skipped { .. } => None,
+ ChildLayoutOutcome::Created(child_layout) => Some(child_layout),
};
- (
- child_layout,
- fragment_arrival,
- laid_out_box.expect("the layout of a child with a formatting context of its own leaves its box"),
- line_data,
- )
+ (child_layout, fragment_arrival, laid_out_box, line_data)
}
fn child_layout_input(
diff --git a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
index 026c85c07e3..aa508ae35ab 100644
--- a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
@@ -3053,7 +3053,7 @@ impl<'pass> FlexFormattingContext<'pass> {
input,
false,
self.run.percentage_block_insets_of_root_children_have_definite_basis(),
- )?;
+ );
debug_assert_eq!(plan.fc_type, formatting_context::FormattingContextType::Block);
Some(formatting_context::ChildRunShape {
node,
@@ -3103,27 +3103,14 @@ impl<'pass> FlexFormattingContext<'pass> {
false,
run.percentage_block_insets_of_root_children_have_definite_basis(),
);
- self.flex_items[index].cells = match &laid_out_box {
- Some(laid_out_box) => laid_out_box.cells,
- // NB: The item was laid out by this flex container's run, in the record it keeps.
- None => run.records.box_metrics_of(node).cells(),
- };
- self.flex_items[index].orthogonal_flow_baselines =
- laid_out_box.and_then(|laid_out_box| laid_out_box.orthogonal_flow_baselines);
+ 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::ReenterCurrent => {
- self.run(run, input);
- run.records.box_metrics_of(node).content_baselines()
- }
- ChildLayoutOutcome::Skipped { .. } => laid_out_box.expect("a skipped item leaves its box").baselines,
- };
- let placed_item = match laid_out_box {
- Some(laid_out_box) => formatting_context::PlacedChild::of_laid_out_box(&laid_out_box, line_data),
- // NB: The item was laid out by this flex container's run, in the record it keeps.
- None => formatting_context::PlacedChild::of_record(run.records.used_values(node), run),
+ ChildLayoutOutcome::Skipped { .. } => laid_out_box.baselines,
};
+ let placed_item = formatting_context::PlacedChild::of_laid_out_box(&laid_out_box, line_data);
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.rs
index f71bb48cd49..2e18c92933f 100644
--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
@@ -1167,7 +1167,6 @@ pub(crate) struct RunOutputs {
pub(crate) enum ChildLayoutOutcome {
Skipped { depends_on_percentage_block_size: bool },
Created(ChildLayoutResult),
- ReenterCurrent,
}
impl ChildLayoutOutcome {
@@ -1179,7 +1178,6 @@ impl ChildLayoutOutcome {
depends_on_percentage_block_size,
} => *depends_on_percentage_block_size,
Self::Created(result) => result.depends_on_percentage_block_size,
- Self::ReenterCurrent => false,
}
}
@@ -2857,7 +2855,7 @@ pub(crate) fn propagate_percentage_block_size_dependency_to_containing_block(
pub(crate) struct ChildLayout {
pub(crate) outcome: ChildLayoutOutcome,
pub(crate) fragment_arrival: Option<fragment_tree::ChildFragmentArrival>,
- pub(crate) laid_out_box: Option<run_records::LaidOutChildBox>,
+ 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>>,
}
@@ -2867,7 +2865,7 @@ impl ChildLayout {
Self {
outcome,
fragment_arrival: None,
- laid_out_box: Some(run_records::LaidOutChildBox::sized_in_parent_run(record)),
+ laid_out_box: run_records::LaidOutChildBox::sized_in_parent_run(record),
line_data: None,
}
}
@@ -2960,7 +2958,7 @@ pub(crate) fn layout_inside_child_with_input_cells(
return ChildLayout {
outcome: skipped(),
fragment_arrival,
- laid_out_box: Some(laid_out_box),
+ laid_out_box,
line_data: None,
};
}
@@ -2981,29 +2979,17 @@ pub(crate) fn layout_inside_child_with_input_cells(
return ChildLayout::of_child_sized_in_parent_run(skipped(), used);
}
- let Some(ChildRunPlan {
+ let ChildRunPlan {
fc_type,
root_containing_block,
input,
- }) = child_run_plan(
+ } = child_run_plan(
run,
child,
input,
force_independent_context_run,
percentage_block_insets_of_containing_block_have_definite_basis,
- )
- else {
- let used = record_for_this_run();
- if force_independent_context_run {
- return ChildLayout::of_child_sized_in_parent_run(skipped(), used);
- }
- return ChildLayout {
- outcome: ChildLayoutOutcome::ReenterCurrent,
- fragment_arrival: None,
- laid_out_box: None,
- line_data: None,
- };
- };
+ );
assert!(
record_kept_by_parent.is_none(),
"{child:?} is handed to a run of its own by a parent that lays it out itself"
@@ -3029,7 +3015,7 @@ pub(crate) fn layout_inside_child_with_input_cells(
ChildLayout {
outcome: ChildLayoutOutcome::Created(result),
fragment_arrival,
- laid_out_box: Some(laid_out_box),
+ laid_out_box,
line_data,
}
}
@@ -3058,7 +3044,7 @@ pub(crate) fn table_cell_run_shape_ahead_of_its_intrinsic_block_padding(
cell: Node,
cell_input_cells: used_values::RootInputCells,
mut input: LayoutInput,
-) -> Option<ChildRunShape> {
+) -> ChildRunShape {
debug_assert!(matches!(
input.participation,
ParticipationInParentFormattingContext::Item
@@ -3071,14 +3057,14 @@ pub(crate) fn table_cell_run_shape_ahead_of_its_intrinsic_block_padding(
input,
false,
run.percentage_block_insets_of_root_children_have_definite_basis(),
- )?;
- Some(ChildRunShape {
+ );
+ ChildRunShape {
node: cell,
fc_type: plan.fc_type,
input: plan.input,
root_cells: cell_input_cells,
root_containing_block: plan.root_containing_block,
- })
+ }
}
#[derive(Clone, Copy, Debug, PartialEq)]
@@ -3154,10 +3140,14 @@ pub(crate) fn child_run_plan(
mut input: LayoutInput,
force_independent_context_run: bool,
percentage_block_insets_of_containing_block_have_definite_basis: bool,
-) -> Option<ChildRunPlan> {
- let fc_type = formatting_context_type_created_by_box(NodeFacts::new(&run.callbacks, child)).or_else(|| {
- force_independent_context_run.then(|| independent_formatting_context_type(child, &run.callbacks))
- })?;
+) -> ChildRunPlan {
+ let fc_type = formatting_context_type_created_by_box(NodeFacts::new(&run.callbacks, child)).unwrap_or_else(|| {
+ assert!(
+ force_independent_context_run,
+ "{child:?} is handed to a run of its own without a formatting context of its own"
+ );
+ independent_formatting_context_type(child, &run.callbacks)
+ });
let root_containing_block = run
.callbacks
.containing_block_for_child_run(child, &input.participation);
@@ -3166,11 +3156,11 @@ pub(crate) fn child_run_plan(
input.sizing.treat_block_axis_percentage_insets_as_auto_beyond_root = child_facts.is_anonymous()
&& !child_facts.is_table_cell()
&& !percentage_block_insets_of_containing_block_have_definite_basis;
- Some(ChildRunPlan {
+ ChildRunPlan {
fc_type,
root_containing_block,
input,
- })
+ }
}
pub(crate) fn lay_out_measurement_root_for_its_result(
diff --git a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
index 1b58044f8ad..91703034bbd 100644
--- a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
@@ -1165,8 +1165,7 @@ impl formatting_context::ChildRunShapes for GridFormattingContext<'_> {
{
return None;
}
- self.item_run_shape(item)
- .filter(|shape| shape.lays_out_at(inline_size, constraints))
+ Some(self.item_run_shape(item)).filter(|shape| shape.lays_out_at(inline_size, constraints))
}
}
@@ -4387,7 +4386,7 @@ impl<'pass> GridFormattingContext<'pass> {
Some(index)
}
- fn item_run_shape(&self, item: GridItem) -> Option<formatting_context::ChildRunShape> {
+ fn item_run_shape(&self, item: GridItem) -> formatting_context::ChildRunShape {
let mut cells = self.cells_of(item);
self.prepare_item_cells(item, &mut cells, ItemRowArea::NotYetSized);
let input = self.item_layout_input(item, &cells, ItemRowArea::NotYetSized);
@@ -4397,14 +4396,14 @@ impl<'pass> GridFormattingContext<'pass> {
input,
false,
self.run.percentage_block_insets_of_root_children_have_definite_basis(),
- )?;
- Some(formatting_context::ChildRunShape {
+ );
+ formatting_context::ChildRunShape {
node: item.box_,
fc_type: plan.fc_type,
input: plan.input,
root_cells: cells,
root_containing_block: plan.root_containing_block,
- })
+ }
}
fn layout_items(&mut self, run: &FormattingContextRun<'pass>) {
@@ -4472,38 +4471,17 @@ impl<'pass> GridFormattingContext<'pass> {
false,
run.percentage_block_insets_of_root_children_have_definite_basis(),
);
- let laid_out_cells = match &laid_out_box {
- Some(laid_out_box) => laid_out_box.cells,
- // NB: The item was laid out by this grid container's run, in the record it keeps.
- None => run.records.box_metrics_of(item.box_).cells(),
- };
- self.update_cells_of(item, |item_cells| *item_cells = laid_out_cells);
+ self.update_cells_of(item, |item_cells| *item_cells = laid_out_box.cells);
outcome.report_percentage_block_size_dependency_of(run, item.box_);
- match outcome {
- ChildLayoutOutcome::Created(_) | ChildLayoutOutcome::Skipped { .. } => {}
- ChildLayoutOutcome::ReenterCurrent => {
- self.run(run, input);
- }
- };
- let laid_out_item = match &laid_out_box {
- Some(laid_out_box) => LaidOutGridItem {
+ self.laid_out_items.borrow_mut().insert(
+ item.box_,
+ LaidOutGridItem {
content_baselines: laid_out_box.baselines,
orthogonal_flow_baselines: laid_out_box.orthogonal_flow_baselines,
content_offset: None,
},
- None => LaidOutGridItem {
- content_baselines: run.records.box_metrics_of(item.box_).content_baselines(),
- // NB: A box that establishes an orthogonal flow is laid out by a run of its own.
- orthogonal_flow_baselines: None,
- content_offset: None,
- },
- };
- self.laid_out_items.borrow_mut().insert(item.box_, laid_out_item);
- let placed_item = match laid_out_box {
- Some(laid_out_box) => formatting_context::PlacedChild::of_laid_out_box(&laid_out_box, line_data),
- // NB: The item was laid out by this grid container's run, in the record it keeps.
- None => formatting_context::PlacedChild::of_record(run.records.used_values(item.box_), run),
- };
+ );
+ let placed_item = formatting_context::PlacedChild::of_laid_out_box(&laid_out_box, line_data);
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.rs
index ab8e41978f8..cac166024eb 100644
--- a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
@@ -1502,33 +1502,13 @@ impl<'context> InlineFormattingContext<'context> {
outcome.report_percentage_block_size_dependency_of(self.run, node);
let baselines = match outcome {
ChildLayoutOutcome::Created(result) => result.baselines,
- ChildLayoutOutcome::ReenterCurrent => {
- self.parent.run(self.run, input);
- self.box_metrics(node).content_baselines()
- }
- ChildLayoutOutcome::Skipped { .. } => {
- laid_out_box
- .as_ref()
- .expect("a skipped atomic inline leaves its box")
- .baselines
- }
- };
- 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),
- laid_out_box.cells,
- ),
- // NB: The box was laid out by this context's parent flow, in the record it keeps here.
- None => {
- let record = self.run.records.used_values(node);
- (
- formatting_context::PlacedChild::of_record(record, self.run),
- used_values::RootInputCells::capture(record),
- )
- }
+ ChildLayoutOutcome::Skipped { .. } => laid_out_box.baselines,
};
- self.keep_placed_atomic_inline(node, placed_child);
- (baselines, laid_out_cells)
+ self.keep_placed_atomic_inline(
+ node,
+ formatting_context::PlacedChild::of_laid_out_box(&laid_out_box, line_data),
+ );
+ (baselines, laid_out_box.cells)
}
/// Lays out `node`, an atomic inline-level box on a line that starts out with the cells `cells`, and returns the
diff --git a/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs
index 081c1c8bf7e..0d3d12d8685 100644
--- a/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs
@@ -2175,7 +2175,6 @@ impl<'pass> MathFormattingContext<'pass> {
if let Some(fragment_arrival) = fragment_arrival {
self.fragment_arrivals_of_children.borrow_mut().push(fragment_arrival);
}
- let laid_out_box = laid_out_box.expect("the layout of a math child leaves its box");
self.placed_children.borrow_mut().insert(
child,
formatting_context::PlacedChild::of_laid_out_box(&laid_out_box, line_data),
@@ -2184,7 +2183,7 @@ impl<'pass> MathFormattingContext<'pass> {
let metrics = laid_out_box.cells;
let baselines = match outcome {
ChildLayoutOutcome::Created(result) => result.baselines,
- ChildLayoutOutcome::ReenterCurrent | ChildLayoutOutcome::Skipped { .. } => laid_out_box.baselines,
+ ChildLayoutOutcome::Skipped { .. } => laid_out_box.baselines,
};
let collapsed = metrics.uses_collapsing_borders_model();
let block_size = metrics.margin_box_block_size(collapsed);
diff --git a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs
index 63ce5e20620..bc75f8b51ee 100644
--- a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs
@@ -2098,14 +2098,10 @@ impl<'pass> SvgFormattingContext<'pass> {
run.percentage_block_insets_of_root_children_have_definite_basis(),
);
outcome.report_percentage_block_size_dependency_of(run, child);
- match outcome {
- ChildLayoutOutcome::Created(_) => {}
- ChildLayoutOutcome::Skipped { .. } | ChildLayoutOutcome::ReenterCurrent => {
- panic!("SVG foreign object did not create an independent formatting context")
- }
- };
-
- let laid_out_box = laid_out_box.expect("a foreign object's child is laid out by a run of its own");
+ assert!(
+ matches!(outcome, ChildLayoutOutcome::Created(_)),
+ "SVG foreign object did not create an independent formatting context"
+ );
// Masks and clips may use this offset for objectBoundingBox units.
self.place_laid_out_child(
child,
diff --git a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs
index 839730b1bb8..76de1f3f23e 100644
--- a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs
@@ -2724,30 +2724,17 @@ impl<'pass> TableFormattingContext<'pass> {
// 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(),
);
- self.cell_box_cells[cell_index] = match &laid_out_box {
- Some(laid_out_box) => laid_out_box.cells,
- // NB: The cell was laid out by this table's run, in the record it keeps.
- None => run.records.box_metrics_of(cell.box_).cells(),
- };
- // NB: A cell this table lays out in the record it keeps hands nothing back.
- self.content_baselines_of_handed_back_cells[cell_index] =
- laid_out_box.as_ref().map(|laid_out_box| laid_out_box.baselines);
+ 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::ReenterCurrent => {
- self.run(run, layout_input, None);
- run.records.box_metrics_of(cell.box_).content_baselines()
- }
- ChildLayoutOutcome::Skipped { .. } => {
- laid_out_box.as_ref().expect("a skipped cell leaves its box").baselines
- }
+ ChildLayoutOutcome::Skipped { .. } => laid_out_box.baselines,
};
- self.placed_cells[cell_index] = Some(match laid_out_box {
- Some(laid_out_box) => formatting_context::PlacedChild::of_laid_out_box(&laid_out_box, line_data),
- // NB: The cell was laid out by this table's run, in the record it keeps.
- None => formatting_context::PlacedChild::of_record(run.records.used_values(cell.box_), run),
- });
+ self.placed_cells[cell_index] = Some(formatting_context::PlacedChild::of_laid_out_box(
+ &laid_out_box,
+ line_data,
+ ));
(baselines, fragment_arrival)
}
@@ -2847,7 +2834,7 @@ impl<'pass> TableFormattingContext<'pass> {
},
participation: ParticipationInParentFormattingContext::Item,
},
- )?;
+ );
let result = formatting_context::lay_out_shape_for_its_result(run.callbacks, shape);
Some(TableCellMeasurement {
automatic_content_block_size: result.automatic_content_block_size,