Truly independent web browser
LibWeb: Carry whether percentage block insets have a definite basis
Aliaksandr Kalenik96cdad4074b4
diff --git a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rsindex 1222a298294..9b48600c405 100644--- a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs+++ b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs@@ -3138,6 +3138,10 @@ impl<'pass> AbsposEngine<'pass> {ParticipationInParentFormattingContext::AbsolutelyPositioned(inputs),),false,+ // https://drafts.csswg.org/css-sizing-3/#definite+ // "Additionally, the size of the containing block of an absolutely positioned element is always definite+ // with respect to that element."+ true,);outcome.report_percentage_block_size_dependency_of(run, node);let mut used_insets = match outcome {@@ -3732,8 +3736,7 @@ impl<'pass> AbsposEngine<'pass> {node: Node,containing_block: &impl BoxMetricCells,percentage_basis: geometry::LogicalSize,- formatting_context_root: Node,- treat_block_axis_percentage_insets_as_auto_beyond_root: bool,+ percentage_block_insets_have_definite_basis: bool,) -> InFlowBoxInsets {// Most boxes are neither relatively positioned nor carry anchor()// insets, and both facts come straight from the node's style payload.@@ -3791,13 +3794,7 @@ impl<'pass> AbsposEngine<'pass> {let treat_block_axis_percentage_insets_as_auto = (style.inset_top().contains_percentage()|| style.inset_bottom().contains_percentage())- && !formatting_context::resolve_block_axis_percentage_inset_basis_is_definite(- self.records,- &self.callbacks,- self.callbacks.in_flow_containing_block(node),- formatting_context_root,- treat_block_axis_percentage_insets_as_auto_beyond_root,- );+ && !percentage_block_insets_have_definite_basis;fn block_axis_inset_value(value: style_values::InsetValue<'_>,treat_percentage_as_auto: bool,@@ -3857,19 +3854,20 @@ pub(crate) struct InFlowBoxInsets {}/// Resolves the insets of `node`, an in-flow box whose containing block has the metrics `containing_block`, with-/// percentages against `percentage_basis`.+/// percentages against `percentage_basis`, where block-axis percentages resolve against a definite block size if+/// `percentage_block_insets_have_definite_basis`.pub(crate) fn compute_inset_native(run: &FormattingContextRun<'_>,node: Node,containing_block: &impl BoxMetricCells,percentage_basis: geometry::LogicalSize,+ percentage_block_insets_have_definite_basis: bool,) -> InFlowBoxInsets {AbsposEngine::for_run(run).compute_inset(node,containing_block,percentage_basis,- run.box_,- run.treat_block_axis_percentage_insets_as_auto_beyond_root,+ percentage_block_insets_have_definite_basis,)}diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rsindex 57dfe5662e9..116393418c7 100644--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs@@ -99,6 +99,41 @@ pub(crate) struct InterruptedInlineContent {pub(crate) struct BlockContainer<'pass> {pub(crate) node: Node,pub(crate) used: &'pass UsedValues,+ /// Whether the block-axis percentage insets of the boxes laid out in the container resolve against a definite+ /// block size.+ pub(crate) percentage_block_insets_have_definite_basis: bool,+}++impl<'pass> BlockContainer<'pass> {+ /// The run's root, as the block container of the boxes laid out in it.+ pub(crate) fn root_of(run: &FormattingContextRun<'pass>) -> Self {+ Self {+ node: run.box_,+ used: run.records.used_values(run.box_),+ percentage_block_insets_have_definite_basis: run+ .percentage_block_insets_of_root_children_have_definite_basis(),+ }+ }++ /// `node`, laid out in `used` in `containing_block`, as the block container of the boxes laid out in it.+ fn laid_out_in(+ callbacks: &LayoutPass<'_>,+ node: Node,+ used: &'pass UsedValues,+ containing_block: BlockContainer<'_>,+ ) -> Self {+ Self {+ node,+ used,+ percentage_block_insets_have_definite_basis:+ formatting_context::percentage_block_insets_have_definite_basis_in(+ callbacks,+ node,+ || used.has_definite_block_size(),+ containing_block.percentage_block_insets_have_definite_basis,+ ),+ }+ }}/// What the layout of a block-level box the parent flow holds leaves for its outcome.@@ -666,10 +701,7 @@ impl<'pass> BlockFormattingContext<'pass> {/// The run's root, as the block container of the boxes laid out in it.fn root_block_container(&self) -> BlockContainer<'pass> {- BlockContainer {- node: self.run.box_,- used: self.used(self.run.box_),- }+ BlockContainer::root_of(&self.run)}fn next_sibling(&self, node: Node) -> Node {@@ -895,6 +927,7 @@ impl<'pass> BlockFormattingContext<'pass> {inline_size: block_container_used.content_inline_size.get(),block_size: block_container_used.content_block_size.get(),},+ block_container.percentage_block_insets_have_definite_basis,);run.records.keep_in_flow_box_insets(node, insets);insets@@ -2017,6 +2050,7 @@ impl<'pass> BlockFormattingContext<'pass> {},marker_cells,true,+ list_item.percentage_block_insets_have_definite_basis,);marker_outcome.report_percentage_block_size_dependency_of(run, marker);match marker_outcome {@@ -2071,6 +2105,7 @@ impl<'pass> BlockFormattingContext<'pass> {&self,run: &FormattingContextRun<'pass>,node: Node,+ block_container: BlockContainer<'pass>,input: LayoutInput,force_independent_context_run: bool,) -> (@@ -2092,6 +2127,7 @@ impl<'pass> BlockFormattingContext<'pass> {input,self.hand_over_child_cells(node),force_independent_context_run,+ 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 {@@ -2591,7 +2627,7 @@ impl<'pass> BlockFormattingContext<'pass> {(metrics.border_box_left(false), metrics.border_box_top(false))});let (child_layout, fragment_arrival, laid_out_box, line_data) =- self.layout_inside(run, node, inside_layout_input, true);+ self.layout_inside(run, node, block_container, inside_layout_input, true);fragment_arrival_of_child_with_own_formatting_context = fragment_arrival;if child_layout.is_some() {child_handed_back_by_its_run = Some(formatting_context::PlacedChild::of_laid_out_box(@@ -2648,10 +2684,8 @@ impl<'pass> BlockFormattingContext<'pass> {y: containing_block_position_in_root.y + content_block_offset,};self.incoming_container_token.replace(continuation.clone());- let node_as_block_container = BlockContainer {- node,- used: self.used(node),- };+ let node_as_block_container =+ BlockContainer::laid_out_in(&self.run.callbacks, node, self.used(node), block_container);let children_summary = if facts.children_are_inline() {self.layout_inline_children(run,@@ -2828,10 +2862,7 @@ impl<'pass> BlockFormattingContext<'pass> {.first;let marker_border_box_block_end = self.layout_list_item_marker(run,- BlockContainer {- node,- used: self.used(node),- },+ BlockContainer::laid_out_in(&self.run.callbacks, node, self.used(node), block_container),inline_space_used_before_children_formatted,list_item_first_baseline,);@@ -4612,7 +4643,7 @@ impl<'pass> BlockFormattingContext<'pass> {);self.dimension_float_root_inline_size(node, block_container, &float_input);let (float_layout, fragment_arrival, float_box, float_line_data) =- self.layout_inside(run, node, float_input, false);+ self.layout_inside(run, node, 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, float_line_data, self.run.callbacks.frame)diff --git a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rsindex 8c5ea10d730..db8653a0ce8 100644--- a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs@@ -3004,7 +3004,13 @@ impl<'pass> FlexFormattingContext<'pass> {let mut cells = self.flex_items[index].cells;self.size_item_cells_for_its_run(index, &mut cells, main_size, cross_size);let input = self.item_layout_input(index, &cells, space_for_items);- let plan = formatting_context::child_run_plan(&self.run, node, input, false)?;+ let plan = formatting_context::child_run_plan(+ &self.run,+ node,+ 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,@@ -3044,7 +3050,16 @@ impl<'pass> FlexFormattingContext<'pass> {fragment_arrival,laid_out_box,line_data,- } = formatting_context::layout_inside_child_with_input_cells(run, None, None, node, input, cells, false);+ } = formatting_context::layout_inside_child_with_input_cells(+ run,+ None,+ None,+ node,+ input,+ cells,+ false,+ run.percentage_block_insets_of_root_children_have_definite_basis(),+ );self.flex_items[index].cells = run.records.box_metrics_of(node).input_cells();outcome.report_percentage_block_size_dependency_of(run, node);self.flex_items[index].content_baselines = match outcome {@@ -3072,6 +3087,7 @@ impl<'pass> FlexFormattingContext<'pass> {inline_size: container_used.content_inline_size.get(),block_size: container_used.content_block_size.get(),},+ run.percentage_block_insets_of_root_children_have_definite_basis(),);run.records.keep_in_flow_box_insets(node, insets);(fragment_arrival, placed_item.with_in_flow_box_insets(insets))diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rsindex ef87de6cca0..3d1db88e5e4 100644--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs@@ -1439,6 +1439,17 @@ impl<'pass> FormattingContextRun<'pass> {sizing_context::SizingContext::new(self.records, self.callbacks)}+ /// Whether the block-axis percentage insets of the boxes whose containing block is the run's root resolve against a+ /// definite block size.+ pub(crate) fn percentage_block_insets_of_root_children_have_definite_basis(&self) -> bool {+ percentage_block_insets_have_definite_basis_in(+ &self.callbacks,+ self.box_,+ || self.records.used_values(self.box_).has_definite_block_size(),+ !self.treat_block_axis_percentage_insets_as_auto_beyond_root,+ )+ }+/// The record of the run's root, read in the frame this run lays out in.#[track_caller]pub(crate) fn root_record(&self) -> used_values::RecordInFrame<'pass> {@@ -2902,6 +2913,7 @@ impl ChildLayout {}}+#[allow(clippy::too_many_arguments)]pub(crate) fn layout_inside_child(run: &FormattingContextRun,parent_block: Option<&block_formatting_context::BlockFormattingContext>,@@ -2909,6 +2921,7 @@ pub(crate) fn layout_inside_child(child: Node,input: LayoutInput,force_independent_context_run: bool,+ percentage_block_insets_of_containing_block_have_definite_basis: bool,) -> ChildLayout {let child_input_cells = run.records.box_metrics_of(child).input_cells();layout_inside_child_with_input_cells(@@ -2919,11 +2932,13 @@ pub(crate) fn layout_inside_child(input,child_input_cells,force_independent_context_run,+ percentage_block_insets_of_containing_block_have_definite_basis,)}/// Lays out `child` with the input cells its parent sized it to: hands them to the child's run, or gives them to the/// child's record where the parent lays the child out itself.+#[allow(clippy::too_many_arguments)]pub(crate) fn layout_inside_child_with_input_cells(run: &FormattingContextRun,parent_block: Option<&block_formatting_context::BlockFormattingContext>,@@ -2932,6 +2947,7 @@ pub(crate) fn layout_inside_child_with_input_cells(input: LayoutInput,mut child_input_cells: used_values::RootInputCells,force_independent_context_run: bool,+ percentage_block_insets_of_containing_block_have_definite_basis: bool,) -> ChildLayout {let facts = NodeFacts::new(&run.callbacks, child);let child_run_builds_fragments = run_builds_fragments(&input, run.fragments.is_some());@@ -3012,7 +3028,13 @@ pub(crate) fn layout_inside_child_with_input_cells(fc_type,root_containing_block,input,- }) = child_run_plan(run, child, input, force_independent_context_run)+ }) = 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 {@@ -3082,7 +3104,14 @@ pub(crate) fn table_cell_run_shape_ahead_of_its_intrinsic_block_padding(ParticipationInParentFormattingContext::Item));input.sizing.table_cell_intrinsic_block_padding = Some((CssPixels::default(), CssPixels::default()));- let plan = child_run_plan(run, cell, input, false)?;+ // NB: A table cell is a containing block of its own to the percentage block insets of its descendants.+ let plan = child_run_plan(+ run,+ cell,+ input,+ false,+ run.percentage_block_insets_of_root_children_have_definite_basis(),+ )?;Some(ChildRunShape {node: cell,fc_type: plan.fc_type,@@ -3162,11 +3191,15 @@ pub(crate) struct ChildRunPlan {pub(crate) input: LayoutInput,}+/// How `child` is laid out by a run of its own, where the block-axis percentage insets of the boxes in the child's+/// containing block resolve against a definite block size if+/// `percentage_block_insets_of_containing_block_have_definite_basis`.pub(crate) fn child_run_plan(run: &FormattingContextRun,child: Node,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))@@ -3174,21 +3207,11 @@ pub(crate) fn child_run_plan(let root_containing_block = run.callbacks.containing_block_for_child_run(child, &input.participation);- // https://drafts.csswg.org/css-sizing-3/#definite- // "Additionally, the size of the containing block of an absolutely positioned element is always definite with- // respect to that element."- // NB: That containing block may also have been laid out by a run other than this one, which holds no record of it.- input.sizing.treat_block_axis_percentage_insets_as_auto_beyond_root = match input.participation {- ParticipationInParentFormattingContext::AbsolutelyPositioned(_) => false,- _ => treat_block_axis_percentage_insets_as_auto_beyond_anonymous_child_root(- run.records,- &run.callbacks,- child,- root_containing_block,- run.box_,- run.treat_block_axis_percentage_insets_as_auto_beyond_root,- ),- };+ // NB: Percentages see through an anonymous root to the block size of its containing block.+ let child_facts = NodeFacts::new(&run.callbacks, child);+ 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 {fc_type,root_containing_block,@@ -3421,46 +3444,20 @@ pub(super) fn independent_formatting_context_type(box_: Node, callbacks: &LayoutFormattingContextType::Block}-pub(crate) fn resolve_block_axis_percentage_inset_basis_is_definite(- records: &RunRecords,+/// Whether the block-axis percentage insets of the boxes whose containing block is `containing_block` resolve against a+/// definite block size: whether the box has a definite block size, or, where it is an anonymous box percentages see+/// through, whether `basis_beyond_it_is_definite`.+pub(crate) fn percentage_block_insets_have_definite_basis_in(callbacks: &LayoutPass<'_>,containing_block: Node,- formatting_context_root: Node,- treat_block_axis_percentage_insets_as_auto_beyond_root: bool,+ containing_block_has_definite_block_size: impl FnOnce() -> bool,+ basis_beyond_it_is_definite: bool,) -> bool {- let mut candidate = containing_block;- while !candidate.is_invalid() {- let facts = NodeFacts::new(callbacks, candidate);- if !facts.is_anonymous() || facts.is_table_cell() {- return records.used_values(candidate).has_definite_block_size();- }- if candidate == formatting_context_root {- return !treat_block_axis_percentage_insets_as_auto_beyond_root;- }- candidate = callbacks.in_flow_containing_block(candidate);+ let facts = NodeFacts::new(callbacks, containing_block);+ if !facts.is_anonymous() || facts.is_table_cell() {+ return containing_block_has_definite_block_size();}- true-}--pub(crate) fn treat_block_axis_percentage_insets_as_auto_beyond_anonymous_child_root(- records: &RunRecords,- callbacks: &LayoutPass<'_>,- child_root: Node,- child_root_containing_block: Node,- formatting_context_root: Node,- treat_block_axis_percentage_insets_as_auto_beyond_root: bool,-) -> bool {- let child_root_facts = NodeFacts::new(callbacks, child_root);- if !child_root_facts.is_anonymous() || child_root_facts.is_table_cell() {- return false;- }- !resolve_block_axis_percentage_inset_basis_is_definite(- records,- callbacks,- child_root_containing_block,- formatting_context_root,- treat_block_axis_percentage_insets_as_auto_beyond_root,- )+ basis_beyond_it_is_definite}/// Lays the document out from its viewport over the arena and layout scratch of `state`:diff --git a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rsindex e0e622f150c..e8ee83cd80f 100644--- a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs@@ -4362,7 +4362,13 @@ impl<'pass> GridFormattingContext<'pass> {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);- let plan = formatting_context::child_run_plan(&self.run, item.box_, input, false)?;+ let plan = formatting_context::child_run_plan(+ &self.run,+ item.box_,+ input,+ false,+ self.run.percentage_block_insets_of_root_children_have_definite_basis(),+ )?;Some(formatting_context::ChildRunShape {node: item.box_,fc_type: plan.fc_type,@@ -4435,6 +4441,7 @@ impl<'pass> GridFormattingContext<'pass> {input,cells,false,+ run.percentage_block_insets_of_root_children_have_definite_basis(),);let handed_back = run.records.box_metrics_of(item.box_).input_cells();self.update_cells_of(item, |item_cells| *item_cells = handed_back);@@ -4458,7 +4465,13 @@ impl<'pass> GridFormattingContext<'pass> {};// Resolve relative-position insets before placement seals the// item's committed metrics.- let insets = abspos_engine::compute_inset_native(run, item.box_, self.container_used(), area.size);+ let insets = abspos_engine::compute_inset_native(+ run,+ item.box_,+ self.container_used(),+ area.size,+ run.percentage_block_insets_of_root_children_have_definite_basis(),+ );run.records.keep_in_flow_box_insets(item.box_, insets);let placed_item = placed_item.with_in_flow_box_insets(insets);if self.item_participates_in_row_baseline_alignment(item)diff --git a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rsindex b84370ce892..9e50f564b1e 100644--- a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs@@ -1395,6 +1395,7 @@ impl<'context> InlineFormattingContext<'context> {inline_size: used.content_inline_size.get(),block_size: used.content_block_size.get(),},+ self.block_container.percentage_block_insets_have_definite_basis,);self.run.records.keep_in_flow_box_insets(node, insets);insets@@ -1482,7 +1483,15 @@ impl<'context> InlineFormattingContext<'context> {fragment_arrival,laid_out_box,line_data,- } = formatting_context::layout_inside_child(self.run, Some(self.parent), None, node, input, false);+ } = formatting_context::layout_inside_child(+ self.run,+ Some(self.parent),+ None,+ node,+ input,+ 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 = match outcome {diff --git a/Libraries/LibWeb/Rust/src/layout/intrinsic_sizing.rs b/Libraries/LibWeb/Rust/src/layout/intrinsic_sizing.rsindex 0120b945548..084f237a400 100644--- a/Libraries/LibWeb/Rust/src/layout/intrinsic_sizing.rs+++ b/Libraries/LibWeb/Rust/src/layout/intrinsic_sizing.rs@@ -137,10 +137,7 @@ pub(super) fn content_sizes_of_inline_content(let parent = block_formatting_context::BlockFormattingContext::new(run, None);let mut context = inline_formatting_context::InlineFormattingContext::new_with_rust_parent(run,- block_formatting_context::BlockContainer {- node: run.box_,- used: run.records.used_values(run.box_),- },+ block_formatting_context::BlockContainer::root_of(run),input,FfiCssPixelPoint::default(),run.callbacks,diff --git a/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rsindex 3d66d9c737c..c305a589f82 100644--- a/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs@@ -2160,7 +2160,16 @@ impl<'pass> MathFormattingContext<'pass> {fragment_arrival,laid_out_box,line_data,- } = formatting_context::layout_inside_child_with_input_cells(run, None, None, child, input, child_cells, true);+ } = formatting_context::layout_inside_child_with_input_cells(+ run,+ None,+ None,+ child,+ input,+ child_cells,+ true,+ run.percentage_block_insets_of_root_children_have_definite_basis(),+ );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/svg_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rsindex 5ddbd63b04f..5b2dbad793c 100644--- a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs@@ -2076,6 +2076,7 @@ impl<'pass> SvgFormattingContext<'pass> {child_input,child_cells,true,+ run.percentage_block_insets_of_root_children_have_definite_basis(),);outcome.report_percentage_block_size_dependency_of(run, child);match outcome {diff --git a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rsindex 60051bc8252..174efdb323e 100644--- a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs@@ -2652,6 +2652,8 @@ impl<'pass> TableFormattingContext<'pass> {layout_input,self.cell_box_cells[cell_index],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(),);self.cell_box_cells[cell_index] = run.records.box_metrics_of(cell.box_).input_cells();outcome.report_percentage_block_size_dependency_of(run, cell.box_);