Truly independent web browser
LibWeb: Size a skipped child nothing reads by node in a local record
Aliaksandr Kalenik5267ef150d9d
diff --git a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rsindex 99c8df8b1a4..009588dd4c1 100644--- a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs@@ -3117,7 +3117,7 @@ impl<'pass> FlexFormattingContext<'pass> {self.run(run, input);run.records.box_metrics_of(node).content_baselines()}- ChildLayoutOutcome::Skipped { .. } => 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) => {diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rsindex 19abfcbb6c0..2ac6e874bd4 100644--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs@@ -2089,6 +2089,19 @@ fn size_skipped_root_in_parent_scope(}}+/// Whether size_skipped_independent_root() sizes a child that participates in its parent's formatting context as+/// `participation`, which it does in the record its parent holds for the child.+fn parent_sizes_skipped_root_in_its_record(participation: &ParticipationInParentFormattingContext) -> bool {+ match participation {+ ParticipationInParentFormattingContext::BlockLevel+ | ParticipationInParentFormattingContext::Float { .. }+ | ParticipationInParentFormattingContext::AbsolutelyPositioned(_) => true,+ ParticipationInParentFormattingContext::AtomicInline+ | ParticipationInParentFormattingContext::Item+ | ParticipationInParentFormattingContext::Root => false,+ }+}+fn size_skipped_independent_root(run: &FormattingContextRun,parent_block: Option<&block_formatting_context::BlockFormattingContext>,@@ -3025,7 +3038,16 @@ 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.- let used = record_for_this_run();+ // 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 committed_fragment = run.sizing().dimension_empty_atomic_root(sizing_context::SizedRecord::new(child, used_values::RecordInFrame::new(used, run.callbacks.frame)),input.available_space,@@ -3046,10 +3068,14 @@ pub(crate) fn layout_inside_child_with_input_cells(reuses_subtree: false,});store_derived_baselines(used, DerivedBaselines::default());+ let laid_out_box = run_records::LaidOutChildBox::sized_in_parent_run(used);+ if record_kept_by_parent.is_none() {+ run.records.note_child_handed_back(child);+ }return ChildLayout {outcome: skipped(),fragment_arrival,- laid_out_box: Some(run_records::LaidOutChildBox::sized_in_parent_run(used)),+ laid_out_box: Some(laid_out_box),line_data: None,};}@@ -3058,6 +3084,13 @@ pub(crate) fn layout_inside_child_with_input_cells(Some(FormattingContextType::InternalReplaced | FormattingContextType::ReplacedWithChildren));if !facts.can_have_children() && !creates_replaced_context {+ if record_kept_by_parent.is_none() && !parent_sizes_skipped_root_in_its_record(&input.participation) {+ // NB: A child kept without a record that nothing sizes further keeps the cells it was handed, in a record+ // of this layout's own, and is handed back like a child its own run laid out.+ let record_of_this_layout = child_input_cells.materialize_record(run.callbacks.frame);+ run.records.note_child_handed_back(child);+ 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);return ChildLayout::of_child_sized_in_parent_run(skipped(), used);diff --git a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rsindex 746742425e9..067578cfeed 100644--- a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs@@ -1509,7 +1509,12 @@ impl<'context> InlineFormattingContext<'context> {self.parent.run(self.run, input);self.box_metrics(node).content_baselines()}- ChildLayoutOutcome::Skipped { .. } => 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) => (diff --git a/Libraries/LibWeb/Rust/src/layout/run_records.rs b/Libraries/LibWeb/Rust/src/layout/run_records.rsindex 17cfa0aab2e..359806a2d8e 100644--- a/Libraries/LibWeb/Rust/src/layout/run_records.rs+++ b/Libraries/LibWeb/Rust/src/layout/run_records.rs@@ -823,7 +823,7 @@ impl<'arena> RunRecords<'arena> {#[track_caller]fn panic_for_child_read_after_its_run_handed_it_back(&self, node: Node) -> ! {panic!(- "the run rooted at slot {} reads slot {}, which its parent keeps once its run handed it back (read at {})",+ "the run rooted at slot {} reads slot {}, which its parent keeps once its layout handed it back (read at {})",self.root.slot_index(),node.slot_index(),std::panic::Location::caller(),diff --git a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rsindex 0920c6340da..dcccb35fac8 100644--- a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs@@ -2686,10 +2686,9 @@ impl<'pass> TableFormattingContext<'pass> {// NB: The cell was laid out by this table's run, in the record it keeps.None => run.records.box_metrics_of(cell.box_).input_cells(),};- if matches!(outcome, ChildLayoutOutcome::Created(_)) {- self.content_baselines_of_handed_back_cells[cell_index] =- laid_out_box.as_ref().map(|laid_out_box| laid_out_box.baselines);- }+ // 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);outcome.report_percentage_block_size_dependency_of(run, cell.box_);let baselines = match outcome {ChildLayoutOutcome::Created(result) => result.baselines,@@ -2697,7 +2696,9 @@ impl<'pass> TableFormattingContext<'pass> {self.run(run, layout_input, None);run.records.box_metrics_of(cell.box_).content_baselines()}- ChildLayoutOutcome::Skipped { .. } => run.records.box_metrics_of(cell.box_).content_baselines(),+ ChildLayoutOutcome::Skipped { .. } => {+ laid_out_box.as_ref().expect("a skipped cell leaves its box").baselines+ }};self.placed_cells[cell_index] = Some(match laid_out_box {Some(laid_out_box) => {