Truly independent web browser
LibWeb: Hand parents their children's layouts as LayoutResults
Aliaksandr Kalenikf7482f2fddc0
diff --git a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rsindex f37d59cfb64..866311c622c 100644--- a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs+++ b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs@@ -2636,11 +2636,7 @@ impl<'pass> AbsposEngine<'pass> {let (available_space, constraints) = out_of_flow_root_space(&inputs);let inputs = std::sync::Arc::new(inputs);- let formatting_context::ChildLayout {- outcome,- fragment_arrival,- laid_out_box,- } = formatting_context::layout_inside_child_with_input_cells(+ let laid_out = formatting_context::layout_inside_child_with_input_cells(run,None,None,@@ -2658,19 +2654,12 @@ impl<'pass> AbsposEngine<'pass> {// with respect to that element."true,);- outcome.report_percentage_block_size_dependency_of(run, node);- let mut used_insets = match outcome {- ChildLayoutOutcome::Created(result) => result- .out_of_flow_root_used_insets- .expect("the run of an absolutely positioned box gives it used insets"),- ChildLayoutOutcome::Skipped {- out_of_flow_root_used_insets,- ..- } => out_of_flow_root_used_insets- .expect("the layout of a skipped absolutely positioned box gives it used insets"),- };-- let metrics = laid_out_box.cells;+ laid_out.report_percentage_block_size_dependency_of(run, node);+ let mut used_insets = laid_out+ .out_of_flow_root_used_insets()+ .expect("the layout of an absolutely positioned box gives it used insets");++ let metrics = laid_out.cells();let collapsed = metrics.uses_collapsing_borders_model();let static_offset = aligned_static_offset(inputs.static_position_rect,@@ -2716,7 +2705,7 @@ impl<'pass> AbsposEngine<'pass> {used_insets.bottom = style.inset_bottom().to_px(containing_block_size.block_size);}}- let mut placed_child = formatting_context::PlacedChild::of_laid_out_box(&laid_out_box);+ let mut placed_child = laid_out.placed_child();placed_child.facts_decided_by_parent.used_insets = used_insets;placed_child.facts_decided_by_parent.default_scroll_shift = default_scroll_shift;placed_child.abspos_layout_inputs = Some(inputs);@@ -2729,7 +2718,7 @@ impl<'pass> AbsposEngine<'pass> {y: used_offset.block_offset,},None,- fragment_arrival,+ laid_out.into_fragment_arrival(run),);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.rsindex 6b695aeb7fc..f32502c2925 100644--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs@@ -150,6 +150,22 @@ impl BlockContainer {}}+/// A box as its layout left it, in the cells this flow keeps of it, with the baselines of its contents.+#[derive(Clone, Copy)]+pub(crate) struct LaidOutBox {+ pub(crate) cells: used_values::RootInputCells,+ pub(crate) baselines: DerivedBaselines,+}++impl LaidOutBox {+ fn of_layout(layout: &formatting_context::ChildLayout) -> Self {+ Self {+ cells: layout.cells(),+ baselines: layout.baselines(),+ }+ }+}+/// What the layout of a block-level box the parent flow holds leaves for its outcome.struct LaidOutBlockLevelBox {broken_inside: Option<BrokenInside>,@@ -157,7 +173,7 @@ struct LaidOutBlockLevelBox {collapses_through: bool,/// The box as its layout left it: as a run of its own handed it back, or as this flow laid it out in cells its/// layout owns.- laid_out_box: run_state::LaidOutChildBox,+ laid_out_box: LaidOutBox,/// What this flow decided the box's fragment shows of it.fragment_facts: run_state::FragmentFactsDecidedByParent,/// The offset of the content box in the containing block, where this flow placed the box.@@ -170,10 +186,7 @@ struct LaidOutBlockLevelBox {impl LaidOutBlockLevelBox {/// A box laid out as `laid_out_box` with `fragment_facts`, which neither broke inside nor let margins collapse/// through it, and which this flow did not place.- fn of_box(- laid_out_box: run_state::LaidOutChildBox,- fragment_facts: run_state::FragmentFactsDecidedByParent,- ) -> Self {+ fn of_box(laid_out_box: LaidOutBox, fragment_facts: run_state::FragmentFactsDecidedByParent) -> Self {Self {broken_inside: None,has_unbreakable_lines: false,@@ -209,7 +222,7 @@ struct UnplacedBlockLevelBox {fragment_arrival_of_child_with_own_formatting_context: Option<fragment_tree::RunRootFragment>,summary_of_children_laid_out_in_this_flow: Option<ChildrenSummary>,baselines_of_contents_laid_out_in_this_flow: Option<DerivedBaselines>,- laid_out_box_handed_back_by_its_run: Option<run_state::LaidOutChildBox>,+ laid_out_box_handed_back_by_its_run: Option<LaidOutBox>,own_top_margin_group_of_contents: Option<TopMarginGroup>,depends_on_percentage_block_size: bool,has_unbreakable_lines: bool,@@ -233,7 +246,7 @@ pub(crate) struct FloatLaidOutAheadOfItsPosition {node: Node,placed_float: formatting_context::PlacedChild,pub(crate) cells: used_values::RootInputCells,- laid_out_float_handed_back_by_its_run: Option<run_state::LaidOutChildBox>,+ laid_out_float_handed_back_by_its_run: Option<LaidOutBox>,fragment_arrival: Option<fragment_tree::RunRootFragment>,}@@ -992,16 +1005,15 @@ impl OutsideMarkerLine {/// An outside marker laid out before the contents of its list item, which is placed once they are laid out.struct LaidOutOutsideMarker {marker: Node,- laid_out_box: run_state::LaidOutChildBox,- fragment_arrival: Option<fragment_tree::RunRootFragment>,+ layout: formatting_context::ChildLayout,}impl LaidOutOutsideMarker {fn line(&self) -> Option<OutsideMarkerLine> {- let baseline = self.laid_out_box.baselines.first?;+ let baseline = self.layout.baselines().first?;Some(OutsideMarkerLine {ascent: baseline,- descent: self.laid_out_box.cells.content_block_size() - baseline,+ descent: self.layout.cells().content_block_size() - baseline,})}}@@ -3044,11 +3056,7 @@ impl<'pass> BlockFormattingContext<'pass> {inline_size: AvailableSize::definite(max_content_inline_size),block_size: AvailableSize::Indefinite,};- let formatting_context::ChildLayout {- outcome: marker_outcome,- fragment_arrival,- laid_out_box: marker_box,- } = formatting_context::layout_inside_child_with_input_cells(+ let layout = formatting_context::layout_inside_child_with_input_cells(run,None,None,@@ -3067,12 +3075,8 @@ impl<'pass> BlockFormattingContext<'pass> {true,list_item.percentage_block_insets_have_definite_basis,);- marker_outcome.report_percentage_block_size_dependency_of(run, marker);- Some(LaidOutOutsideMarker {- marker,- laid_out_box: marker_box,- fragment_arrival,- })+ layout.report_percentage_block_size_dependency_of(run, marker);+ Some(LaidOutOutsideMarker { marker, layout })}/// Places the outside `marker` of `list_item`, and returns the block end of the marker's border box in the list@@ -3085,13 +3089,9 @@ impl<'pass> BlockFormattingContext<'pass> {list_item_first_baseline: Option<CssPixels>,) -> CssPixels {let marker_line = marker.line();- let LaidOutOutsideMarker {- marker,- laid_out_box: marker_box,- fragment_arrival,- } = marker;+ let LaidOutOutsideMarker { marker, layout } = marker;let marker_style = self.style(marker);- let marker_metrics = marker_box.cells;+ let marker_metrics = layout.cells();let marker_block_size = marker_metrics.content_block_size();let marker_inline_size = marker_metrics.content_inline_size();let list_item_style = self.style(list_item.node);@@ -3110,7 +3110,7 @@ impl<'pass> BlockFormattingContext<'pass> {- inline_space_used_before_list_item_elements_formatted.right};let marker_block_offset = if let Some(list_item_first_baseline) = list_item_first_baseline- && let Some(marker_first_baseline) = marker_box.baselines.first+ && let Some(marker_first_baseline) = layout.baselines().first{list_item_first_baseline - marker_first_baseline} else if let Some(marker_line) = marker_line {@@ -3126,21 +3126,20 @@ impl<'pass> BlockFormattingContext<'pass> {formatting_context::place_child(&self.run,marker,- formatting_context::PlacedChild::of_laid_out_box(&marker_box),+ layout.placed_child(),FfiCssPixelPoint {x: round_css_pixels(marker_inline_offset),y: marker_block_offset,},None,- fragment_arrival,+ layout.into_fragment_arrival(&self.run),);marker_block_offset+ marker_block_size+ marker_metrics.border_box_bottom(marker_metrics.uses_collapsing_borders_model())}- /// Lays out the contents of `node`, a child with a formatting context of its own, and returns its result where a- /// run of its own laid it out, the fragments its placement takes, and the child's box as its layout left it.+ /// Lays out the contents of `node`, a child with a formatting context of its own, and returns its layout.fn layout_inside(&self,run: &FormattingContextRun<'pass>,@@ -3148,16 +3147,8 @@ impl<'pass> BlockFormattingContext<'pass> {block_container: BlockContainer,input: LayoutInput,force_independent_context_run: bool,- ) -> (- Option<formatting_context::ChildLayoutResult>,- Option<fragment_tree::RunRootFragment>,- run_state::LaidOutChildBox,- ) {- let formatting_context::ChildLayout {- outcome,- fragment_arrival,- laid_out_box,- } = formatting_context::layout_inside_child_with_input_cells(+ ) -> formatting_context::ChildLayout {+ let layout = formatting_context::layout_inside_child_with_input_cells(run,Some(self),None,@@ -3168,12 +3159,8 @@ impl<'pass> BlockFormattingContext<'pass> {force_independent_context_run,block_container.percentage_block_insets_have_definite_basis,);- 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),- };- (child_layout, fragment_arrival, laid_out_box)+ layout.report_percentage_block_size_dependency_of(run, sized_child.node);+ layout}fn child_layout_input(@@ -3761,14 +3748,14 @@ impl<'pass> BlockFormattingContext<'pass> {let metrics = self.metrics_of(sized_child);(metrics.border_box_left(false), metrics.border_box_top(false))});- let (child_layout, fragment_arrival, laid_out_box) =- self.layout_inside(run, sized_child, block_container, inside_layout_input, true);+ let layout = self.layout_inside(run, sized_child, block_container, inside_layout_input, true);assert!(- child_layout.is_some(),+ layout.result().is_some(),"a block-level box with a formatting context of its own is laid out by its run");- fragment_arrival_of_child_with_own_formatting_context = fragment_arrival;- child_handed_back_by_its_run = Some(formatting_context::PlacedChild::of_laid_out_box(&laid_out_box));+ let laid_out_box = LaidOutBox::of_layout(&layout);+ child_handed_back_by_its_run = Some(layout.placed_child());+ fragment_arrival_of_child_with_own_formatting_context = layout.into_fragment_arrival(run);let table_box = laid_out_box.cells;laid_out_box_handed_back_by_its_run = Some(laid_out_box);if container_facts.is_table_wrapper() && style.display().is_table_inside() {@@ -4282,17 +4269,14 @@ impl<'pass> BlockFormattingContext<'pass> {}/// The box `child` as this flow laid it out in cells its layout owns, with the `baselines` of its contents.- fn laid_out_box_of_box_laid_out_here(- child: ChildSizedHere<'_>,- baselines: DerivedBaselines,- ) -> run_state::LaidOutChildBox {- run_state::LaidOutChildBox::sized_here(- child+ fn laid_out_box_of_box_laid_out_here(child: ChildSizedHere<'_>, baselines: DerivedBaselines) -> LaidOutBox {+ LaidOutBox {+ cells: child.cells_laid_out_here().expect("a box laid out in this flow is laid out in cells its layout owns").get(),baselines,- )+ }}/// Whether the layout of an in-flow child can be stored and reused by `InFlowBlockKey`, and where its position in@@ -6699,7 +6683,7 @@ impl<'pass> BlockFormattingContext<'pass> {fragment_facts: run_state::FragmentFactsDecidedByParent,) -> (abspos_engine::InFlowBoxInsets,- Option<run_state::LaidOutChildBox>,+ Option<LaidOutBox>,Option<FfiCssPixelPoint>,) {let laid_out_float = self.lay_out_float_ahead_of_its_position(@@ -6771,14 +6755,13 @@ impl<'pass> BlockFormattingContext<'pass> {let node = sized_float.node;let float_input =self.size_float_for_its_run(sized_float, block_container, &input, containing_block_position_in_root);- let (float_layout, fragment_arrival, float_box) =- self.layout_inside(run, sized_float, block_container, float_input, false);+ let layout = self.layout_inside(run, sized_float, block_container, float_input, false);FloatLaidOutAheadOfItsPosition {node,- placed_float: formatting_context::PlacedChild::of_laid_out_box(&float_box),- cells: float_box.cells,- laid_out_float_handed_back_by_its_run: float_layout.is_some().then_some(float_box),- fragment_arrival,+ placed_float: layout.placed_child(),+ cells: layout.cells(),+ laid_out_float_handed_back_by_its_run: layout.result().is_some().then(|| LaidOutBox::of_layout(&layout)),+ fragment_arrival: layout.into_fragment_arrival(run),}}@@ -6796,7 +6779,7 @@ impl<'pass> BlockFormattingContext<'pass> {fragment_facts: run_state::FragmentFactsDecidedByParent,) -> (abspos_engine::InFlowBoxInsets,- Option<run_state::LaidOutChildBox>,+ Option<LaidOutBox>,Option<FfiCssPixelPoint>,) {let FloatLaidOutAheadOfItsPosition {diff --git a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rsindex 9af025d7d75..cf2581e7f80 100644--- a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs+++ b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs@@ -456,7 +456,7 @@ pub(crate) struct FcRunCacheValidity {/// The result of a completed run, which stands for any run with a matching key, whether or not the stored run's own/// result was committed. Its fragments are those it produced; where they are what the box committed, a hit keeps the/// committed subtree instead of replaying them.-pub(super) struct FcRunCacheEntry {+pub(crate) struct FcRunCacheEntry {key: LayoutRequest,validity: FcRunCacheValidity,pub(super) result: formatting_context::LayoutResult,diff --git a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rsindex 2d1a8bbda0f..b06d3dccf9b 100644--- a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs@@ -3361,16 +3361,12 @@ impl<'pass> FlexFormattingContext<'pass> {laid_out: formatting_context::ChildLayout,) -> (Option<fragment_tree::RunRootFragment>, formatting_context::PlacedChild) {let node = self.flex_items[index].box_;- let formatting_context::ChildLayout {- outcome,- fragment_arrival,- laid_out_box,- } = laid_out;- self.flex_item_details[index].cells = laid_out_box.cells;- self.flex_item_details[index].orthogonal_flow_baselines = laid_out_box.orthogonal_flow_baselines;- outcome.report_percentage_block_size_dependency_of(run, node);- self.flex_item_details[index].content_baselines = laid_out_box.baselines;- let placed_item = formatting_context::PlacedChild::of_taken_laid_out_box(laid_out_box);+ self.flex_item_details[index].cells = laid_out.cells();+ self.flex_item_details[index].orthogonal_flow_baselines = laid_out.orthogonal_flow_baselines();+ laid_out.report_percentage_block_size_dependency_of(run, node);+ self.flex_item_details[index].content_baselines = laid_out.baselines();+ let placed_item = laid_out.placed_child();+ let fragment_arrival = laid_out.into_fragment_arrival(run);let container = &self.container_cells;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.rsindex cacf11243a0..482d1f3cb4e 100644--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs@@ -160,21 +160,12 @@ pub(crate) fn run_root_without_parent_fragments(},false,);- let ChildLayout {- outcome: ChildLayoutOutcome::Created(result),- laid_out_box,- fragment_arrival,- } = run_formatting_context(pass, request, RunSideInputs::default())- else {+ let ChildLayout::Laid(layout) = run_formatting_context(pass, request, RunSideInputs::default()) else {unreachable!("a run creates its root's result");};- debug_assert!(- fragment_arrival.is_none(),- "a run without parent fragments hands its placement nothing"- );RootLaidOutWithoutParentFragments {- result,- root_cells_left_by_run: laid_out_box.cells,+ result: layout.outcome,+ root_cells_left_by_run: layout.cells(),}}@@ -388,18 +379,15 @@ impl PlacedChild {}}- /// A child whose run handed back the box `laid_out`, before its parent decided anything about it.- pub(crate) fn of_laid_out_box(laid_out: &run_state::LaidOutChildBox) -> Self {- Self::new(fragment_tree::FragmentGeometry {- cells: laid_out.cells,- line_data: laid_out.line_data.clone(),- })- }-- pub(crate) fn of_taken_laid_out_box(laid_out: run_state::LaidOutChildBox) -> Self {+ /// A child laid out as `layout` shows it, with the lines its run laid out in it, before its parent decided anything+ /// about it.+ pub(crate) fn of_layout(layout: &ChildLayout) -> Self {Self::new(fragment_tree::FragmentGeometry {- cells: laid_out.cells,- line_data: laid_out.line_data,+ cells: layout.cells(),+ line_data: match layout {+ ChildLayout::SizedInParentRun { .. } => None,+ ChildLayout::Laid(layout) => layout.line_data().cloned(),+ },})}@@ -1091,7 +1079,7 @@ impl LayoutResult {/// The result of a run its parent takes in: the run's own, which the run cache stored or not, or that of a stored run/// the probe took in place of running.-pub(super) enum LayoutResultHandle {+pub(crate) enum LayoutResultHandle {Owned(LayoutResult),/// The run's own result, which the run cache stored.Stored(std::sync::Arc<fc_run_cache::FcRunCacheEntry>),@@ -1112,20 +1100,11 @@ impl LayoutResultHandle {}}- /// The root's fragment, where `takes_fragment`, and the residue of the run, which the run's parent takes in.- fn into_fragment_and_residue(- self,- takes_fragment: bool,- ) -> (- Option<fragment_tree::RunRootFragment>,- Option<Box<run_state::RunResidue>>,- ) {+ /// What the run found out besides its result, which the run that takes in its result receives.+ fn take_residue(&mut self) -> Option<Box<run_state::RunResidue>> {match self {- Self::Owned(result) => (result.fragment.filter(|_| takes_fragment), result.residue),- Self::Stored(entry) | Self::Reused { entry, .. } => (- entry.result.fragment.as_ref().filter(|_| takes_fragment).cloned(),- entry.result.residue.clone(),- ),+ Self::Owned(result) => result.residue.take(),+ Self::Stored(entry) | Self::Reused { entry, .. } => entry.result.residue.clone(),}}}@@ -1141,40 +1120,6 @@ impl std::ops::Deref for LayoutResultHandle {}}-pub(crate) enum ChildLayoutOutcome {- Skipped {- depends_on_percentage_block_size: bool,- /// For an absolutely positioned child, the used values of its inset properties.- out_of_flow_root_used_insets: Option<run_state::UsedInsets>,- },- Created(ChildLayoutResult),-}--impl ChildLayoutOutcome {- /// Whether the laid out child depends on the block size its percentages resolve against, which the box containing- /// it hears of.- pub(crate) fn child_depends_on_percentage_block_size(&self) -> bool {- match self {- Self::Skipped {- depends_on_percentage_block_size,- ..- } => *depends_on_percentage_block_size,- Self::Created(result) => result.depends_on_percentage_block_size,- }- }-- /// Notes for the box containing `child` whether `child`, laid out with this outcome, depends on the block size its- /// percentages resolve against.- pub(crate) fn report_percentage_block_size_dependency_of(&self, run: &FormattingContextRun, child: Node) {- propagate_percentage_block_size_dependency_to_containing_block(- run.state,- &run.pass,- child,- self.child_depends_on_percentage_block_size(),- );- }-}-#[derive(Clone, Copy, Debug, PartialEq, Eq)]pub(crate) enum SizingAxis {Inline,@@ -3052,28 +2997,112 @@ pub(crate) fn propagate_percentage_block_size_dependency_to_containing_block(state.note_descendant_depends_on_percentage_block_size(box_resolving_the_dependency);}-/// The layout of a child: its outcome, the root fragment its placement takes, and the child's box as its layout left-/// it, unless the parent lays out the child's contents itself.+/// What the run of a parent knows of a child it sized itself, besides the child's cells.+#[derive(Clone, Copy, Debug)]+pub(crate) struct SkippedChild {+ pub(crate) depends_on_percentage_block_size: bool,+ /// For an absolutely positioned child, the used values of its inset properties.+ pub(crate) out_of_flow_root_used_insets: Option<run_state::UsedInsets>,+}++/// The layout of a child its parent takes in: the cells the parent's own run sized it in, or the result of the child's+/// own run, whose root fragment the child's placement takes.#[must_use]-pub(crate) struct ChildLayout {- pub(crate) outcome: ChildLayoutOutcome,- pub(crate) fragment_arrival: Option<fragment_tree::RunRootFragment>,- pub(crate) laid_out_box: run_state::LaidOutChildBox,+pub(crate) enum ChildLayout {+ SizedInParentRun {+ cells: used_values::RootInputCells,+ skipped: SkippedChild,+ },+ Laid(LayoutResultHandle),}impl ChildLayout {- /// What placing the child takes of the box its layout handed back.- pub(crate) fn placed_child(&self) -> PlacedChild {- PlacedChild::of_laid_out_box(&self.laid_out_box)+ /// The result of the child's run, where a run of its own laid it out.+ pub(crate) fn result(&self) -> Option<&ChildLayoutResult> {+ match self {+ Self::SizedInParentRun { .. } => None,+ Self::Laid(layout) => Some(&layout.outcome),+ }}- fn of_child_sized_in_parent_run(outcome: ChildLayoutOutcome, cells: used_values::RootInputCells) -> Self {- Self {- outcome,- fragment_arrival: None,- laid_out_box: run_state::LaidOutChildBox::sized_here(cells, DerivedBaselines::default()),+ /// The child's cells as its parent keeps them, in the parent's frame.+ pub(crate) fn cells(&self) -> used_values::RootInputCells {+ match self {+ Self::SizedInParentRun { cells, .. } => *cells,+ Self::Laid(layout) => layout.cells(),+ }+ }++ /// The baselines of the child's contents, which the parent's run lays out none of where it sizes the child itself.+ pub(crate) fn baselines(&self) -> DerivedBaselines {+ self.result()+ .map_or_else(DerivedBaselines::default, |result| result.baselines)+ }++ /// For a child that establishes an orthogonal flow, its baselines along the horizontal axis of the parent's frame.+ pub(crate) fn orthogonal_flow_baselines(&self) -> Option<DerivedBaselines> {+ self.result()?.orthogonal_flow_baselines+ }++ /// For an absolutely positioned child, the used values of its inset properties.+ pub(crate) fn out_of_flow_root_used_insets(&self) -> Option<run_state::UsedInsets> {+ match self {+ Self::SizedInParentRun { skipped, .. } => skipped.out_of_flow_root_used_insets,+ Self::Laid(layout) => layout.outcome.out_of_flow_root_used_insets,+ }+ }++ /// Whether the child depends on the block size its percentages resolve against, which the box containing it hears+ /// of.+ pub(crate) fn child_depends_on_percentage_block_size(&self) -> bool {+ match self {+ Self::SizedInParentRun { skipped, .. } => skipped.depends_on_percentage_block_size,+ Self::Laid(layout) => layout.outcome.depends_on_percentage_block_size,}}++ /// Notes for the box containing `child`, laid out as this, whether `child` depends on the block size its+ /// percentages resolve against.+ pub(crate) fn report_percentage_block_size_dependency_of(&self, run: &FormattingContextRun, child: Node) {+ propagate_percentage_block_size_dependency_to_containing_block(+ run.state,+ &run.pass,+ child,+ self.child_depends_on_percentage_block_size(),+ );+ }++ /// What placing the child takes of its layout.+ pub(crate) fn placed_child(&self) -> PlacedChild {+ PlacedChild::of_layout(self)+ }++ /// The root fragment of the child's run that the child's placement in `run` takes, where `run` builds fragments. A+ /// stored run's fragment can show the box as it was committed since through another fragment, which it then is.+ pub(crate) fn into_fragment_arrival(self, run: &FormattingContextRun) -> Option<fragment_tree::RunRootFragment> {+ let takes_fragment = run.fragments.is_some();+ let (root, reuses_stored_run) = match self {+ Self::SizedInParentRun { .. } => return None,+ Self::Laid(LayoutResultHandle::Owned(result)) => (result.fragment.filter(|_| takes_fragment), false),+ Self::Laid(LayoutResultHandle::Stored(entry)) => (+ entry.result.fragment.as_ref().filter(|_| takes_fragment).cloned(),+ false,+ ),+ Self::Laid(LayoutResultHandle::Reused { entry, .. }) => {+ (entry.result.fragment.as_ref().filter(|_| takes_fragment).cloned(), true)+ }+ };+ root.map(|root| {+ let fragment = reuses_stored_run+ .then(|| fragment_tree::previously_committed_fragment_matching(&run.pass, &root.fragment))+ .flatten()+ .unwrap_or(root.fragment);+ fragment_tree::RunRootFragment {+ fragment,+ payloads_past_run: root.payloads_past_run,+ }+ })+ }}/// Lays out `child` with the input cells its parent sized it to: hands them to the child's run, with the inline layout@@ -3094,9 +3123,12 @@ pub(crate) fn layout_inside_child_with_input_cells(let facts = NodeFacts::new(&run.pass, child);let created_fc_type = formatting_context_type_created_by_box(facts);let child_run_builds_fragments = RunMode::of(&input, run.mode.builds_fragments(), false).builds_fragments();- 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,+ let sized_in_parent_run = |cells, out_of_flow_root_used_insets| ChildLayout::SizedInParentRun {+ cells,+ skipped: SkippedChild {+ depends_on_percentage_block_size: run.sizing().skipped_child_depends_on_percentage_block_size(child),+ out_of_flow_root_used_insets,+ },};if is_empty_atomic_block_sized_in_parent_run(run,@@ -3115,16 +3147,13 @@ pub(crate) fn layout_inside_child_with_input_cells(input.containing_block_constraints,child_run_builds_fragments,);- return ChildLayout::of_child_sized_in_parent_run(skipped(None), cells_of_this_layout.get());+ return sized_in_parent_run(cells_of_this_layout.get(), None);}if is_childless_box_sized_in_parent_run(facts, created_fc_type) {let cells_of_this_layout = Cell::new(child_input_cells);let out_of_flow_root_used_insets =size_skipped_independent_root(run, parent_block, child, &cells_of_this_layout, &input);- return ChildLayout::of_child_sized_in_parent_run(- skipped(out_of_flow_root_used_insets),- cells_of_this_layout.get(),- );+ return sized_in_parent_run(cells_of_this_layout.get(), out_of_flow_root_used_insets);}let plan = child_run_plan(@@ -3478,11 +3507,9 @@ pub(crate) fn lay_out_measurement_root_for_its_result(}pub(crate) fn lay_out_shape_for_its_result(pass: LayoutPass<'_>, shape: ChildRunShape) -> ChildLayoutResult {- let layout = layout(pass, &RunRequest::of_shape(shape), RunSideInputs::default());- let outcome = layout.outcome;- let (_, residue) = layout.into_fragment_and_residue(false);- pass.receive_residue(residue);- outcome+ let mut layout = layout(pass, &RunRequest::of_shape(shape), RunSideInputs::default());+ pass.receive_residue(layout.take_residue());+ layout.outcome}// NB: An item that establishes an orthogonal flow sizes itself along its container's block axis, so its run owns its@@ -3520,38 +3547,21 @@ pub(super) fn content_block_size_run_leaves_root_whose_cells_its_parent_owns(})}-fn child_layout_from_outputs(pass: &LayoutPass<'_>, request: &RunRequest, layout: LayoutResultHandle) -> ChildLayout {- let child = request.node;- let outputs_are_stored_ones = matches!(layout, LayoutResultHandle::Reused { .. });- let result = layout.outcome;- let laid_out_box = run_state::LaidOutChildBox {- cells: layout.cells(),- baselines: result.baselines,- orthogonal_flow_baselines: result.orthogonal_flow_baselines,- line_data: layout.line_data().cloned(),- };- let (root, residue) = layout.into_fragment_and_residue(request.caller.collects_fragments());- pass.receive_residue(residue);- let fragment_arrival = root.map(|root| {- debug_assert!(- root.fragment.node == child,- "a child run returned a root for a different box"- );- // NB: A stored run's fragment can show the box as it was committed since through another fragment.- let fragment = outputs_are_stored_ones- .then(|| fragment_tree::previously_committed_fragment_matching(pass, &root.fragment))- .flatten()- .unwrap_or(root.fragment);- fragment_tree::RunRootFragment {- fragment,- payloads_past_run: root.payloads_past_run,- }- });- ChildLayout {- outcome: ChildLayoutOutcome::Created(result),- laid_out_box,- fragment_arrival,- }+/// The layout of the child of the run `request` asked for, whose parent hears at once of what the run found out.+fn child_layout_from_outputs(+ pass: &LayoutPass<'_>,+ request: &RunRequest,+ mut layout: LayoutResultHandle,+) -> ChildLayout {+ debug_assert!(+ layout+ .fragment+ .as_ref()+ .is_none_or(|root| root.fragment.node == request.node),+ "a child run returned a root for a different box"+ );+ pass.receive_residue(layout.take_residue());+ ChildLayout::Laid(layout)}pub(super) fn independent_formatting_context_type(box_: Node, pass: &LayoutPass<'_>) -> FormattingContextType {@@ -3823,14 +3833,14 @@ fn compute_root_layout(input: LayoutStageInput<'_>, should_collect_devtools_layo},should_collect_devtools_layout_data,);- let root_outcome = run_formatting_context(pass, request, RunSideInputs::default());+ let root_layout = run_formatting_context(pass, request, RunSideInputs::default());place_child(&entry_run,root_for_layout,- root_outcome.placed_child(),+ root_layout.placed_child(),FfiCssPixelPoint::default(),None,- root_outcome.fragment_arrival,+ root_layout.into_fragment_arrival(&entry_run),);finish_entry_pass(entry_run_state,@@ -3983,21 +3993,14 @@ fn layout_subtree_with_frozen_root_geometry(run: &FormattingContextRun<'_>) {},run.collects_devtools_layout_data(),);- let root_outcome = run_formatting_context(*pass, request, RunSideInputs::default());- let ChildLayout {- laid_out_box: root_box,- fragment_arrival,- ..- } = root_outcome;+ let root_layout = run_formatting_context(*pass, request, RunSideInputs::default());assert_eq!(- sizes_and_box_sides(root_box.cells),+ sizes_and_box_sides(root_layout.cells()),sizes_and_box_sides(root_cells),"the run of {root:?} changed the committed geometry of its root");- let root_geometry = fragment_tree::FragmentGeometry {- cells: root_box.cells,- line_data: root_box.line_data,- };+ let root_geometry = root_layout.placed_child().geometry;+ let fragment_arrival = root_layout.into_fragment_arrival(run);let facts_decided_by_parent = run_state::FactsDecidedByParent::of_committed_link(&committed_root_link,pass.frame,diff --git a/Libraries/LibWeb/Rust/src/layout/frameset_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/frameset_formatting_context.rsindex 562894ba19b..090cd4bb4ff 100644--- a/Libraries/LibWeb/Rust/src/layout/frameset_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/frameset_formatting_context.rs@@ -225,7 +225,7 @@ fn layout_frameset_child(outcome.placed_child(),offset,None,- outcome.fragment_arrival,+ outcome.into_fragment_arrival(run),);}diff --git a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rsindex 4060232df7a..535cedb70c8 100644--- a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs@@ -4912,19 +4912,15 @@ impl<'pass> GridFormattingContext<'pass> {}}};- let formatting_context::ChildLayout {- outcome,- fragment_arrival,- laid_out_box,- } = laid_out;- self.update_cells_of(item, |item_cells| *item_cells = laid_out_box.cells);- outcome.report_percentage_block_size_dependency_of(run, item.box_);+ self.update_cells_of(item, |item_cells| *item_cells = laid_out.cells());+ laid_out.report_percentage_block_size_dependency_of(run, item.box_);self.collected_item(item).laid_out.set(Some(LaidOutGridItem {- content_baselines: laid_out_box.baselines,- orthogonal_flow_baselines: laid_out_box.orthogonal_flow_baselines,+ content_baselines: laid_out.baselines(),+ orthogonal_flow_baselines: laid_out.orthogonal_flow_baselines(),content_offset: None,}));- let placed_item = formatting_context::PlacedChild::of_taken_laid_out_box(laid_out_box);+ let placed_item = laid_out.placed_child();+ let fragment_arrival = laid_out.into_fragment_arrival(run);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.rsindex 4a5d23417f0..51715b0d8dd 100644--- a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs@@ -1467,11 +1467,7 @@ impl<'context> InlineFormattingContext<'context> {self.input.containing_block_constraints,ParticipationInParentFormattingContext::AtomicInline,);- let formatting_context::ChildLayout {- outcome,- fragment_arrival,- laid_out_box,- } = formatting_context::layout_inside_child_with_input_cells(+ let laid_out = formatting_context::layout_inside_child_with_input_cells(self.run,Some(self.parent),None,@@ -1482,11 +1478,12 @@ impl<'context> InlineFormattingContext<'context> {false,self.block_container.percentage_block_insets_have_definite_basis,);- self.keep_atomic_inline_fragment_arrival(node, fragment_arrival);- outcome.report_percentage_block_size_dependency_of(self.run, node);- let baselines = laid_out_box.baselines;- self.keep_placed_atomic_inline(node, formatting_context::PlacedChild::of_laid_out_box(&laid_out_box));- (baselines, laid_out_box.cells)+ laid_out.report_percentage_block_size_dependency_of(self.run, node);+ let baselines = laid_out.baselines();+ let cells = laid_out.cells();+ self.keep_placed_atomic_inline(node, laid_out.placed_child());+ self.keep_atomic_inline_fragment_arrival(node, laid_out.into_fragment_arrival(self.run));+ (baselines, cells)}/// Lays out `node`, an atomic inline-level box on a line that starts out with the cells `cells`, and returns thediff --git a/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rsindex b90cc344cf2..20026f5dd2f 100644--- a/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs@@ -2199,11 +2199,7 @@ impl<'pass> MathFormattingContext<'pass> {ParticipationInParentFormattingContext::AtomicInline,);input.sizing.math_stretch_size_constraint = stretch_size_constraint;- let formatting_context::ChildLayout {- outcome,- fragment_arrival,- laid_out_box,- } = formatting_context::layout_inside_child_with_input_cells(+ let laid_out = formatting_context::layout_inside_child_with_input_cells(run,None,None,@@ -2214,15 +2210,13 @@ impl<'pass> MathFormattingContext<'pass> {true,run.percentage_block_insets_of_root_children_have_definite_basis(&self.root_cells),);- if let Some(fragment_arrival) = fragment_arrival {+ laid_out.report_percentage_block_size_dependency_of(run, child);+ let metrics = laid_out.cells();+ let baselines = laid_out.baselines();+ self.placed_children.borrow_mut().insert(child, laid_out.placed_child());+ if let Some(fragment_arrival) = laid_out.into_fragment_arrival(run) {self.fragment_arrivals_of_children.borrow_mut().push(fragment_arrival);}- self.placed_children- .borrow_mut()- .insert(child, formatting_context::PlacedChild::of_laid_out_box(&laid_out_box));- outcome.report_percentage_block_size_dependency_of(run, child);- let metrics = laid_out_box.cells;- let baselines = laid_out_box.baselines;let collapsed = metrics.uses_collapsing_borders_model();let block_size = metrics.margin_box_block_size(collapsed);// NB: A box without a baseline is aligned by its line-under margin edge.diff --git a/Libraries/LibWeb/Rust/src/layout/mod.rs b/Libraries/LibWeb/Rust/src/layout/mod.rsindex 783fd600a9c..397da7faaeb 100644--- a/Libraries/LibWeb/Rust/src/layout/mod.rs+++ b/Libraries/LibWeb/Rust/src/layout/mod.rs@@ -94,8 +94,7 @@ use crate::layout::node_data::NodeSlotId;pub(crate) use abspos_inputs::AbsposAxisAlignment;pub(crate) use box_alignment::AxisEdge;pub(crate) use formatting_context::{- ChildLayoutOutcome, DerivedBaselines, FfiLayoutHostCallbacks, FormattingContextRun, Node, SizingAxis,- SizingProperty,+ DerivedBaselines, FfiLayoutHostCallbacks, FormattingContextRun, Node, SizingAxis, SizingProperty,};pub(crate) use fragment_tree::FragmentLink;pub(crate) use geometry::{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.rsindex 436364fba39..eedcbed68db 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@@ -74,22 +74,15 @@ fn layout_replaced_with_children(formatting_context::RunRequest::of_child(run, wrapper, plan, wrapper_cells),formatting_context::RunSideInputs::default(),);- let formatting_context::ChildLayoutOutcome::Created(wrapper_result) = wrapper_outcome.outcome else {- unreachable!("a run creates its root's result");- };- formatting_context::propagate_percentage_block_size_dependency_to_containing_block(- run.state,- &run.pass,- wrapper,- wrapper_result.depends_on_percentage_block_size,- );+ let wrapper_result = *wrapper_outcome.result().expect("a run creates its root's result");+ wrapper_outcome.report_percentage_block_size_dependency_of(run, wrapper);formatting_context::place_child(run,wrapper,wrapper_outcome.placed_child(),used_values::FfiCssPixelPoint::default(),None,- wrapper_outcome.fragment_arrival,+ wrapper_outcome.into_fragment_arrival(run),);formatting_context::ChildLayoutResult {diff --git a/Libraries/LibWeb/Rust/src/layout/run_state.rs b/Libraries/LibWeb/Rust/src/layout/run_state.rsindex 08616fb9efa..82cfa3724ea 100644--- a/Libraries/LibWeb/Rust/src/layout/run_state.rs+++ b/Libraries/LibWeb/Rust/src/layout/run_state.rs@@ -279,31 +279,6 @@ impl FactsDecidedByParent {}}-/// What the parent of a box laid out by a run of its own keeps of the box once that run returns: its sizes, size-/// constraints and box sides in the parent's frame, its baselines, and the lines the run laid out in it.-#[derive(Clone)]-pub(crate) struct LaidOutChildBox {- pub(crate) cells: used_values::RootInputCells,- pub(crate) baselines: DerivedBaselines,- /// For a box that establishes an orthogonal flow, its baselines along the horizontal axis of the parent's frame.- pub(crate) orthogonal_flow_baselines: Option<DerivedBaselines>,- pub(crate) line_data: Option<std::sync::Arc<inline_content::InlineContent>>,-}--impl LaidOutChildBox {- /// A child as the run of its parent left it in `cells`, with the `baselines` of its contents, where that run- /// sizes the child itself instead of handing it to a run of its own.- pub(crate) fn sized_here(cells: used_values::RootInputCells, baselines: DerivedBaselines) -> Self {- Self {- cells,- baselines,- // NB: A box that establishes an orthogonal flow is laid out by a run of its own.- orthogonal_flow_baselines: None,- line_data: None,- }- }-}-/// The used values of a box's inset properties.#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]pub(crate) struct UsedInsets {diff --git a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rsindex 7cb0fcb21f9..6648aabdfa7 100644--- a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs@@ -2109,11 +2109,7 @@ impl<'pass> SvgFormattingContext<'pass> {},..self.nested_layout_input()};- let formatting_context::ChildLayout {- outcome,- fragment_arrival,- laid_out_box,- } = formatting_context::layout_inside_child_with_input_cells(+ let laid_out = formatting_context::layout_inside_child_with_input_cells(run,None,None,@@ -2124,27 +2120,28 @@ impl<'pass> SvgFormattingContext<'pass> {true,self.percentage_block_insets_of_run_root_children_have_definite_basis,);- outcome.report_percentage_block_size_dependency_of(run, child);+ laid_out.report_percentage_block_size_dependency_of(run, child);assert!(- matches!(outcome, ChildLayoutOutcome::Created(_)),+ laid_out.result().is_some(),"SVG foreign object did not create an independent formatting context");+ let cells = laid_out.cells();// Masks and clips may use this offset for objectBoundingBox units.self.place_laid_out_child(child,- formatting_context::PlacedChild::of_laid_out_box(&laid_out_box),+ laid_out.placed_child(),rect.x,rect.y,- fragment_arrival,+ laid_out.into_fragment_arrival(run),);if let Some(mask) = self.first_child_of_kind(child, NodeKind::SVGMaskBox) {- self.layout_mask_or_clip(run, mask, &laid_out_box.cells);+ self.layout_mask_or_clip(run, mask, &cells);}if let Some(clip) = self.first_child_of_kind(child, NodeKind::SVGClipBox) {- self.layout_mask_or_clip(run, clip, &laid_out_box.cells);+ self.layout_mask_or_clip(run, clip, &cells);}return Some(LaidOutSvgElement {- cells: laid_out_box.cells,+ cells,content_offset: FfiCssPixelPoint { x: rect.x, y: rect.y },});} else if kind_is_svg_graphics_box(kind) {diff --git a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rsindex 6207d08265b..dd39a205c08 100644--- a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs@@ -2926,11 +2926,7 @@ impl<'pass> TableFormattingContext<'pass> {participation: ParticipationInParentFormattingContext::Item,};let cell = self.cells[cell_index];- let formatting_context::ChildLayout {- outcome,- fragment_arrival,- laid_out_box,- } = formatting_context::layout_inside_child_with_input_cells(+ let laid_out = formatting_context::layout_inside_child_with_input_cells(run,None,None,@@ -2942,12 +2938,12 @@ 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.table_box_cells),);- 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 = laid_out_box.baselines;- self.placed_cells[cell_index] = Some(formatting_context::PlacedChild::of_laid_out_box(&laid_out_box));- (baselines, fragment_arrival)+ self.cell_box_cells[cell_index] = laid_out.cells();+ let baselines = laid_out.baselines();+ self.content_baselines_of_handed_back_cells[cell_index] = Some(baselines);+ laid_out.report_percentage_block_size_dependency_of(run, cell.box_);+ self.placed_cells[cell_index] = Some(laid_out.placed_child());+ (baselines, laid_out.into_fragment_arrival(run))}fn keep_fragment_arrival_of_cell(@@ -3530,14 +3526,12 @@ impl<'pass> TableFormattingContext<'pass> {let cell_box = &mut self.cell_box_cells[cell_index];cell_box.padding_top += intrinsic_block_padding.0;cell_box.padding_bottom += intrinsic_block_padding.1;- let laid_out = run_state::LaidOutChildBox {- cells: *cell_box,- baselines: measurement.baselines,- orthogonal_flow_baselines: None,- line_data: None,- };- self.placed_cells[cell_index] = Some(formatting_context::PlacedChild::of_laid_out_box(&laid_out));- self.content_baselines_of_handed_back_cells[cell_index] = Some(laid_out.baselines);+ self.placed_cells[cell_index] =+ Some(formatting_context::PlacedChild::new(fragment_tree::FragmentGeometry {+ cells: *cell_box,+ line_data: None,+ }));+ self.content_baselines_of_handed_back_cells[cell_index] = Some(measurement.baselines);formatting_context::propagate_percentage_block_size_dependency_to_containing_block(run.state,&run.pass,