Truly independent web browser
LibWeb: Report a child's percentage dependency from its caller
Aliaksandr Kalenik734e1565c0d8
diff --git a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rsindex 18a2a9003ad..441be3302e8 100644--- a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs+++ b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs@@ -3111,7 +3111,7 @@ impl<'pass> AbsposEngine<'pass> {assert!(!self.facts(node).is_svg_box());let (available_space, constraints) = out_of_flow_root_space(inputs);- match formatting_context::layout_inside_child(+ let outcome = formatting_context::layout_inside_child(run,None,None,@@ -3122,8 +3122,10 @@ impl<'pass> AbsposEngine<'pass> {ParticipationInParentFormattingContext::AbsolutelyPositioned(inputs),),false,- ) {- ChildLayoutOutcome::Created(_) | ChildLayoutOutcome::Skipped => {}+ );+ outcome.report_percentage_block_size_dependency_of(run, node);+ match outcome {+ ChildLayoutOutcome::Created(_) | ChildLayoutOutcome::Skipped { .. } => {}ChildLayoutOutcome::ReenterCurrent => {unreachable!("abspos child with contents did not establish a formatting context")}diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rsindex 191997725d2..920c04530be 100644--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs@@ -1745,7 +1745,7 @@ impl<'pass> BlockFormattingContext<'pass> {inline_size: AvailableSize::definite(max_content_inline_size),block_size: AvailableSize::Indefinite,};- match formatting_context::layout_inside_child(+ let marker_outcome = formatting_context::layout_inside_child(run,None,None,@@ -1760,8 +1760,10 @@ impl<'pass> BlockFormattingContext<'pass> {participation: ParticipationInParentFormattingContext::Item,},true,- ) {- ChildLayoutOutcome::Created(_) | ChildLayoutOutcome::Skipped => {}+ );+ 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")}@@ -1804,9 +1806,11 @@ impl<'pass> BlockFormattingContext<'pass> {input: LayoutInput,force_independent_context_run: bool,) -> Option<formatting_context::ChildLayoutResult> {- match formatting_context::layout_inside_child(run, Some(self), None, node, input, force_independent_context_run)- {- ChildLayoutOutcome::Skipped => None,+ let outcome =+ formatting_context::layout_inside_child(run, Some(self), None, node, input, force_independent_context_run);+ outcome.report_percentage_block_size_dependency_of(run, node);+ match outcome {+ ChildLayoutOutcome::Skipped { .. } => None,ChildLayoutOutcome::Created(child_layout) => Some(child_layout),ChildLayoutOutcome::ReenterCurrent => {self.run(run, input);diff --git a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rsindex 3296a1f08b0..2a0c2752e07 100644--- a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs@@ -2980,15 +2980,16 @@ impl<'pass> FlexFormattingContext<'pass> {self.item_used(index),self.available_space_for_items.unwrap().space,);- self.flex_items[index].content_baselines =- match formatting_context::layout_inside_child(run, None, None, node, input, false) {- ChildLayoutOutcome::Created(result) => result.baselines,- ChildLayoutOutcome::ReenterCurrent => {- self.run(run, input);- self.item_used(index).content_baselines_from_cells()- }- ChildLayoutOutcome::Skipped => self.item_used(index).content_baselines_from_cells(),- };+ let outcome = formatting_context::layout_inside_child(run, None, None, node, input, false);+ 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);+ self.item_used(index).content_baselines_from_cells()+ }+ ChildLayoutOutcome::Skipped { .. } => self.item_used(index).content_baselines_from_cells(),+ };let container_inline_size = self.container_used().content_inline_size.get();let container_block_size = self.container_used().content_block_size.get();diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rsindex 7cf533bac55..4805afb1bcc 100644--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs@@ -1068,11 +1068,36 @@ pub(crate) struct RunOutputs {}pub(crate) enum ChildLayoutOutcome {- Skipped,+ Skipped { depends_on_percentage_block_size: bool },Created(ChildLayoutResult),ReenterCurrent,}+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,+ Self::ReenterCurrent => false,+ }+ }++ /// 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.records,+ &run.callbacks,+ child,+ self.child_depends_on_percentage_block_size(),+ );+ }+}+#[derive(Clone, Copy, Debug, PartialEq, Eq)]pub(crate) enum SizingAxis {Inline,@@ -2640,13 +2665,8 @@ pub(crate) fn layout_inside_child(used.padding_top.set(used.padding_top.get() + padding_top);used.padding_bottom.set(used.padding_bottom.get() + padding_bottom);}- let note_skipped_child_dependency = || {- propagate_percentage_block_size_dependency_to_containing_block(- run.records,- &run.callbacks,- child,- run.sizing().skipped_child_depends_on_percentage_block_size(child),- );+ let skipped = || ChildLayoutOutcome::Skipped {+ depends_on_percentage_block_size: run.sizing().skipped_child_depends_on_percentage_block_size(child),};if !force_independent_context_run&& !facts.node_has_size_containment()@@ -2678,8 +2698,7 @@ pub(crate) fn layout_inside_child(fragments.hold_committed_fragment_of_empty_box(used, fragment);}store_derived_baselines(used, DerivedBaselines::default());- note_skipped_child_dependency();- return ChildLayoutOutcome::Skipped;+ return skipped();}let creates_replaced_context = matches!(formatting_context_type_created_by_box(facts),@@ -2687,8 +2706,7 @@ pub(crate) fn layout_inside_child();if !facts.can_have_children() && !creates_replaced_context {size_skipped_independent_root(run, parent_block, child, &input);- note_skipped_child_dependency();- return ChildLayoutOutcome::Skipped;+ return skipped();}let Some(ChildRunPlan {@@ -2698,8 +2716,7 @@ pub(crate) fn layout_inside_child(}) = child_run_plan(run, child, input, force_independent_context_run)else {if force_independent_context_run {- note_skipped_child_dependency();- return ChildLayoutOutcome::Skipped;+ return skipped();}return ChildLayoutOutcome::ReenterCurrent;};@@ -2717,12 +2734,6 @@ pub(crate) fn layout_inside_child(input,run.records.take_table_inline_layout(child),);- propagate_percentage_block_size_dependency_to_containing_block(- run.records,- &run.callbacks,- child,- result.depends_on_percentage_block_size,- );ChildLayoutOutcome::Created(result)}diff --git a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rsindex c2b355d7d2a..e1dd5f6d597 100644--- a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs@@ -4380,8 +4380,10 @@ impl<'pass> GridFormattingContext<'pass> {// grid area in both axes for the table's percentage resolution.input.containing_block_constraints.percentage_basis_inline_size = Some(inline_basis);}- match formatting_context::layout_inside_child(run, None, Some(self), item.box_, input, false) {- ChildLayoutOutcome::Created(_) | ChildLayoutOutcome::Skipped => {}+ let outcome = formatting_context::layout_inside_child(run, None, Some(self), item.box_, input, false);+ outcome.report_percentage_block_size_dependency_of(run, item.box_);+ match outcome {+ ChildLayoutOutcome::Created(_) | ChildLayoutOutcome::Skipped { .. } => {}ChildLayoutOutcome::ReenterCurrent => {self.run(run, input);}diff --git a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rsindex 98f81af77ed..b7b6349f702 100644--- a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs@@ -1283,13 +1283,15 @@ impl<'context> InlineFormattingContext<'context> {self.input.containing_block_constraints,ParticipationInParentFormattingContext::AtomicInline,);- match formatting_context::layout_inside_child(self.run, Some(self.parent), None, node, input, false) {+ let outcome = formatting_context::layout_inside_child(self.run, Some(self.parent), None, node, input, false);+ outcome.report_percentage_block_size_dependency_of(self.run, node);+ match outcome {ChildLayoutOutcome::Created(result) => result.baselines,ChildLayoutOutcome::ReenterCurrent => {self.parent.run(self.run, input);self.used(node).content_baselines_from_cells()}- ChildLayoutOutcome::Skipped => self.used(node).content_baselines_from_cells(),+ ChildLayoutOutcome::Skipped { .. } => self.used(node).content_baselines_from_cells(),}}diff --git a/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rsindex b498e2ebc6c..f3738af4ff7 100644--- a/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs@@ -2133,9 +2133,13 @@ impl<'pass> MathFormattingContext<'pass> {);input.sizing.math_stretch_size_constraint = stretch_size_constraint;let used = run.records.used_values(child);- let baselines = match formatting_context::layout_inside_child(run, None, None, child, input, true) {+ let outcome = formatting_context::layout_inside_child(run, None, None, child, input, true);+ outcome.report_percentage_block_size_dependency_of(run, child);+ let baselines = match outcome {ChildLayoutOutcome::Created(result) => result.baselines,- ChildLayoutOutcome::ReenterCurrent | ChildLayoutOutcome::Skipped => used.content_baselines_from_cells(),+ ChildLayoutOutcome::ReenterCurrent | ChildLayoutOutcome::Skipped { .. } => {+ used.content_baselines_from_cells()+ }};let collapsed = used.uses_collapsing_borders_model.get();let block_size = used.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.rsindex 9590dc0d98b..3f9d1697995 100644--- a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs@@ -2032,9 +2032,11 @@ impl<'pass> SvgFormattingContext<'pass> {},..self.nested_layout_input()};- match formatting_context::layout_inside_child(run, None, None, child, child_input, true) {+ let outcome = formatting_context::layout_inside_child(run, None, None, child, child_input, true);+ outcome.report_percentage_block_size_dependency_of(run, child);+ match outcome {ChildLayoutOutcome::Created(_) => {}- ChildLayoutOutcome::Skipped | ChildLayoutOutcome::ReenterCurrent => {+ ChildLayoutOutcome::Skipped { .. } | ChildLayoutOutcome::ReenterCurrent => {panic!("SVG foreign object did not create an independent formatting context")}};diff --git a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rsindex 85a4361642b..bd20dcf27e3 100644--- a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs@@ -2580,13 +2580,15 @@ impl<'pass> TableFormattingContext<'pass> {},participation: ParticipationInParentFormattingContext::Item,};- match formatting_context::layout_inside_child(run, None, None, cell.box_, layout_input, false) {+ let outcome = formatting_context::layout_inside_child(run, None, None, cell.box_, layout_input, false);+ outcome.report_percentage_block_size_dependency_of(run, cell.box_);+ match outcome {ChildLayoutOutcome::Created(result) => result.baselines,ChildLayoutOutcome::ReenterCurrent => {self.run(run, layout_input, None);self.used_values(cell.box_).content_baselines_from_cells()}- ChildLayoutOutcome::Skipped => self.used_values(cell.box_).content_baselines_from_cells(),+ ChildLayoutOutcome::Skipped { .. } => self.used_values(cell.box_).content_baselines_from_cells(),}}