Truly independent web browser
LibWeb: Read markers, floats and table boxes from their layout's result
Aliaksandr Kalenik1121014e6ff4
diff --git a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rsindex 430f583fbd9..3c63007a35a 100644--- a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs+++ b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs@@ -3104,6 +3104,7 @@ impl<'pass> AbsposEngine<'pass> {let formatting_context::ChildLayout {outcome,fragment_arrival,+ ..} = formatting_context::layout_inside_child(run,None,diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rsindex 16d2fcc7281..a535074ecfd 100644--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs@@ -1966,6 +1966,7 @@ impl<'pass> BlockFormattingContext<'pass> {let formatting_context::ChildLayout {outcome: marker_outcome,fragment_arrival,+ laid_out_box: marker_box,} = formatting_context::layout_inside_child_with_input_cells(run,None,@@ -1991,7 +1992,8 @@ impl<'pass> BlockFormattingContext<'pass> {}}- let marker_metrics = self.run.records.box_metrics_of(marker);+ 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();let list_item_style = self.style(list_item);@@ -2002,7 +2004,7 @@ impl<'pass> BlockFormattingContext<'pass> {list_item_used.content_inline_size.get() - 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_metrics.content_baselines().first+ && let Some(marker_first_baseline) = marker_box.baselines.first{list_item_first_baseline - marker_first_baseline} else {@@ -2027,6 +2029,8 @@ impl<'pass> BlockFormattingContext<'pass> {)}+ /// 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.fn layout_inside(&self,run: &FormattingContextRun<'pass>,@@ -2036,10 +2040,12 @@ impl<'pass> BlockFormattingContext<'pass> {) -> (Option<formatting_context::ChildLayoutResult>,Option<fragment_tree::ChildFragmentArrival>,+ run_records::LaidOutChildBox,) {let formatting_context::ChildLayout {outcome,fragment_arrival,+ laid_out_box,} = formatting_context::layout_inside_child_with_input_cells(run,Some(self),@@ -2050,14 +2056,22 @@ impl<'pass> BlockFormattingContext<'pass> {force_independent_context_run,);outcome.report_percentage_block_size_dependency_of(run, node);- match outcome {- ChildLayoutOutcome::Skipped { .. } => (None, fragment_arrival),- ChildLayoutOutcome::Created(child_layout) => (Some(child_layout), fragment_arrival),+ 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, fragment_arrival)+ (+ None,+ Some(run_records::LaidOutChildBox::sized_in_parent_run(self.used(node))),+ )}- }+ };+ (+ child_layout,+ fragment_arrival,+ laid_out_box.expect("the layout of a child with a formatting context of its own leaves its box"),+ )}fn child_layout_input(@@ -2526,10 +2540,11 @@ impl<'pass> BlockFormattingContext<'pass> {let metrics = self.child_metrics(node);(metrics.border_box_left(false), metrics.border_box_top(false))});- let (child_layout, fragment_arrival) = self.layout_inside(run, node, inside_layout_input, true);+ let (child_layout, fragment_arrival, laid_out_box) =+ self.layout_inside(run, node, inside_layout_input, true);fragment_arrival_of_child_with_own_formatting_context = fragment_arrival;if container_facts.is_table_wrapper() && style.display().is_table_inside() && child_layout.is_some() {- let table_box = self.run.records.box_metrics_of(node);+ let table_box = laid_out_box.cells;self.table_box_in_wrapper_border_box_inline_size.set(Some(table_box.border_box_inline_size(table_box.uses_collapsing_borders_model()),));@@ -4496,7 +4511,7 @@ impl<'pass> BlockFormattingContext<'pass> {input.containing_block_constraints,);self.dimension_float_root_inline_size(node, &float_input);- let (_, fragment_arrival) = self.layout_inside(run, node, float_input, false);+ let (_, fragment_arrival, float_box) = self.layout_inside(run, node, float_input, false);let containing_block_rect = self.containing_block_rect(block_container, containing_block_position_in_root);let containing_block_rect_now = containing_block_rect.translated(CssPixels::default(),@@ -4517,7 +4532,7 @@ impl<'pass> BlockFormattingContext<'pass> {formatting_context::leave_child_unplaced(run, fragment_arrival);return abspos_engine::InFlowBoxInsets::default();};- let float_box = self.run.records.box_metrics_of(node);+ let float_box = float_box.cells;let mut margin_box_ceiling = if let Some(line_builder) = line_builder.as_deref_mut() {line_builder.ceiling_for_float_to_be_inserted_here(float_box.margin_box_inline_size(false))} else {diff --git a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rsindex aa43c1bb621..be0395724be 100644--- a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs@@ -3040,6 +3040,7 @@ impl<'pass> FlexFormattingContext<'pass> {let formatting_context::ChildLayout {outcome,fragment_arrival,+ ..} = formatting_context::layout_inside_child_with_input_cells(run, None, None, node, input, cells, false);self.flex_items[index].cells = run.records.box_metrics_of(node).input_cells();outcome.report_percentage_block_size_dependency_of(run, node);diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rsindex 9cc32df1ea2..8ec655fe7e1 100644--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs@@ -2751,17 +2751,20 @@ pub(crate) fn propagate_percentage_block_size_dependency_to_containing_block(records.note_descendant_depends_on_percentage_block_size(containing_block_or_run_root_that_forwarded_the_basis);}-/// The layout of a child: its outcome, and the fragments its placement takes.+/// The layout of a child: its outcome, the fragments its placement takes, and the child's box as its layout left it,+/// unless the parent lays out the child's contents itself.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>,}impl ChildLayout {- fn without_fragments(outcome: ChildLayoutOutcome) -> Self {+ fn of_child_sized_in_parent_run(outcome: ChildLayoutOutcome, record: &UsedValues) -> Self {Self {outcome,fragment_arrival: None,+ laid_out_box: Some(run_records::LaidOutChildBox::sized_in_parent_run(record)),}}}@@ -2858,6 +2861,7 @@ pub(crate) fn layout_inside_child_with_input_cells(return ChildLayout {outcome: skipped(),fragment_arrival,+ laid_out_box: Some(run_records::LaidOutChildBox::sized_in_parent_run(used)),};}let creates_replaced_context = matches!(@@ -2865,9 +2869,9 @@ pub(crate) fn layout_inside_child_with_input_cells(Some(FormattingContextType::InternalReplaced | FormattingContextType::ReplacedWithChildren));if !facts.can_have_children() && !creates_replaced_context {- record_for_this_run();+ let used = record_for_this_run();size_skipped_independent_root(run, parent_block, child, &input);- return ChildLayout::without_fragments(skipped());+ return ChildLayout::of_child_sized_in_parent_run(skipped(), used);}let Some(ChildRunPlan {@@ -2876,17 +2880,21 @@ pub(crate) fn layout_inside_child_with_input_cells(input,}) = child_run_plan(run, child, input, force_independent_context_run)else {- record_for_this_run();+ let used = record_for_this_run();if force_independent_context_run {- return ChildLayout::without_fragments(skipped());+ return ChildLayout::of_child_sized_in_parent_run(skipped(), used);}- return ChildLayout::without_fragments(ChildLayoutOutcome::ReenterCurrent);+ return ChildLayout {+ outcome: ChildLayoutOutcome::ReenterCurrent,+ fragment_arrival: None,+ laid_out_box: 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");- let (result, fragment_arrival) = run_formatting_context(+ let child_run_outcome = run_formatting_context(run.fragments.as_deref(),child_input_cells,child,@@ -2897,11 +2905,13 @@ pub(crate) fn layout_inside_child_with_input_cells(run.callbacks,input,run.records.take_table_inline_layout(child),- )- .hand_box_back_to(run, child);+ );+ let laid_out_box = child_run_outcome.laid_out_box;+ let (result, fragment_arrival) = child_run_outcome.hand_box_back_to(run, child);ChildLayout {outcome: ChildLayoutOutcome::Created(result),fragment_arrival,+ laid_out_box: Some(laid_out_box),}}diff --git a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rsindex 3bee7188835..7cca6404dc7 100644--- a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs@@ -4422,6 +4422,7 @@ impl<'pass> GridFormattingContext<'pass> {let formatting_context::ChildLayout {outcome,fragment_arrival,+ ..} = formatting_context::layout_inside_child_with_input_cells(run,None,diff --git a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rsindex 4e3ccb50c52..ce069cb707f 100644--- a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs@@ -1423,6 +1423,7 @@ impl<'context> InlineFormattingContext<'context> {let formatting_context::ChildLayout {outcome,fragment_arrival,+ ..} = formatting_context::layout_inside_child(self.run, Some(self.parent), None, node, input, false);self.keep_atomic_inline_fragment_arrival(node, fragment_arrival);outcome.report_percentage_block_size_dependency_of(self.run, node);diff --git a/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rsindex eadda886f76..238c29f2cac 100644--- a/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs@@ -2146,6 +2146,7 @@ impl<'pass> MathFormattingContext<'pass> {let formatting_context::ChildLayout {outcome,fragment_arrival,+ ..} = formatting_context::layout_inside_child_with_input_cells(run, None, None, child, input, child_cells, true);if let Some(fragment_arrival) = fragment_arrival {self.fragment_arrivals_of_children.borrow_mut().push(fragment_arrival);diff --git a/Libraries/LibWeb/Rust/src/layout/run_records.rs b/Libraries/LibWeb/Rust/src/layout/run_records.rsindex 64b9bb40444..410eaa62e5c 100644--- a/Libraries/LibWeb/Rust/src/layout/run_records.rs+++ b/Libraries/LibWeb/Rust/src/layout/run_records.rs@@ -390,6 +390,19 @@ pub(crate) struct LaidOutChildBox {pub(crate) orthogonal_flow_baselines: Option<DerivedBaselines>,}+impl LaidOutChildBox {+ /// A child as the run of its parent left it in `record`, where that run sizes the child itself instead of handing+ /// it to a run of its own.+ pub(crate) fn sized_in_parent_run(record: &UsedValues) -> Self {+ Self {+ cells: used_values::RecordInFrame::in_its_own_frame(record).cells(),+ baselines: record.content_baselines_from_cells(),+ // NB: A box that establishes an orthogonal flow is laid out by a run of its own.+ orthogonal_flow_baselines: None,+ }+ }+}+/// What the parent of a box laid out by a run of its own keeps of it once that run returns: the box, the lines the run/// laid out in it, and the frame the box's metrics are in.#[derive(Clone)]diff --git a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rsindex 5d03c194d9c..2d83860cb45 100644--- a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs@@ -2056,6 +2056,7 @@ impl<'pass> SvgFormattingContext<'pass> {let formatting_context::ChildLayout {outcome,fragment_arrival,+ ..} = formatting_context::layout_inside_child_with_input_cells(run,None,diff --git a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rsindex a0f0614cb36..be4711b5b86 100644--- a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs@@ -2610,6 +2610,7 @@ impl<'pass> TableFormattingContext<'pass> {let formatting_context::ChildLayout {outcome,fragment_arrival,+ ..} = formatting_context::layout_inside_child_with_input_cells(run,None,