Truly independent web browser
LibWeb: Hand a child's run the input cells its parent sized
Aliaksandr Kalenik45e35b3151fa
diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rsindex 4c1ff4de806..2e2c269dd8a 100644--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs@@ -1708,7 +1708,7 @@ impl<'pass> BlockFormattingContext<'pass> {((marker_line_height - marker_block_size) / 2).max(CssPixels::default())}- fn create_marker_used_values(&self, list_item: Node, marker: Node) {+ fn create_marker_used_values(&self, list_item: Node, marker: Node) -> used_values::RootInputCells {let list_item_used = self.used(list_item);let marker_constraints = ContainingBlockConstraints {percentage_basis_inline_size: list_item_used@@ -1719,7 +1719,7 @@ impl<'pass> BlockFormattingContext<'pass> {.then(|| list_item_used.content_block_size.get()),..ContainingBlockConstraints::default()};- self.create_used_values(marker, marker_constraints);+ used_values::RootInputCells::capture(self.create_used_values(marker, marker_constraints))}fn layout_list_item_marker(@@ -1743,7 +1743,7 @@ impl<'pass> BlockFormattingContext<'pass> {if marker_facts.is_floating() || marker_facts.is_absolutely_positioned() {return;}- self.create_marker_used_values(list_item, marker);+ let mut marker_cells = self.create_marker_used_values(list_item, marker);let marker_style = self.style(marker);let marker_constraints = ContainingBlockConstraints {percentage_basis_inline_size: Some(self.used(list_item).content_inline_size.get()),@@ -1752,9 +1752,7 @@ impl<'pass> BlockFormattingContext<'pass> {let max_content_inline_size = self.sizing().calculate_max_content_inline_size(marker, marker_constraints);- let marker_used = self.used(marker);- marker_used.set_content_inline_size(max_content_inline_size);- marker_used.has_definite_inline_size.set(true);+ marker_cells.set_content_inline_size(max_content_inline_size);let inner_available_space = AvailableSpace {inline_size: AvailableSize::definite(max_content_inline_size),block_size: AvailableSize::Indefinite,@@ -1762,7 +1760,7 @@ impl<'pass> BlockFormattingContext<'pass> {let formatting_context::ChildLayout {outcome: marker_outcome,fragment_arrival,- } = formatting_context::layout_inside_child(+ } = formatting_context::layout_inside_child_with_input_cells(run,None,None,@@ -1776,6 +1774,7 @@ impl<'pass> BlockFormattingContext<'pass> {},participation: ParticipationInParentFormattingContext::Item,},+ marker_cells,true,);marker_outcome.report_percentage_block_size_dependency_of(run, marker);diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rsindex 7f975abfb19..e7f0c4d9ff2 100644--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs@@ -123,14 +123,14 @@ pub(crate) fn run_root_without_parent_fragments();let fc_type = independent_formatting_context_type(node, &callbacks);let root_containing_block = callbacks.containing_block_for_child_run(node, &input.participation);- let root_used = root_cells.materialize_record();let ChildRunOutcome {result,+ laid_out_box,fragment_arrival,- ..} = run_formatting_context(None,- &root_used,+ None,+ root_cells,node,root_containing_block,None,@@ -146,7 +146,7 @@ pub(crate) fn run_root_without_parent_fragments();RootLaidOutWithoutParentFragments {result,- root_cells_left_by_run: used_values::RootInputCells::capture(&root_used),+ root_cells_left_by_run: laid_out_box.cells,}}@@ -1922,9 +1922,12 @@ pub(crate) struct ChildRunOutcome {}#[expect(clippy::too_many_arguments)]+/// Runs the formatting context of `box_` with the input cells `root_cells` its parent sized it in. A parent that still+/// keeps a record of the box hands it as `parent_used`, which takes the cells and what the run hands back.pub(super) fn run_formatting_context(parent_fragments: Option<&fragment_tree::RunFragmentBuilder>,- parent_used: &UsedValues,+ parent_used: Option<&UsedValues>,+ root_cells: used_values::RootInputCells,box_: Node,root_containing_block: Node,parent_grid: Option<&grid_formatting_context::GridFormattingContext>,@@ -1934,7 +1937,9 @@ pub(super) fn run_formatting_context(input: LayoutInput,table_inline_layout: Option<table_formatting_context::TableInlineLayout>,) -> ChildRunOutcome {- let root_cells = used_values::RootInputCells::capture(parent_used);+ if let Some(parent_used) = parent_used {+ root_cells.apply_to_record(parent_used);+ }let builds_fragments = run_builds_fragments(&input, parent_fragments.is_some());assert!(parent_fragments.is_none() || builds_fragments,@@ -2106,7 +2111,7 @@ pub(super) fn run_formatting_context(#[expect(clippy::too_many_arguments)]fn reuse_committed_subtree_as_it_is(parent_fragments: Option<&fragment_tree::RunFragmentBuilder>,- root_used: &UsedValues,+ root_used: Option<&UsedValues>,box_: Node,input: &LayoutInput,root_cells: used_values::RootInputCells,@@ -2119,6 +2124,7 @@ fn reuse_committed_subtree_as_it_is(std::sync::Arc<fragment_tree::Fragment>,)> {parent_fragments?;+ let root_used = root_used.expect("a parent that builds fragments keeps a record of its child");let entry = &*hit.entry;if !hit.reuses_committed_subtree|| !cache_key.has_no_table_cell_intrinsic_block_padding()@@ -2890,7 +2896,8 @@ pub(crate) fn layout_inside_child_with_input_cells(fragment_arrival,} = run_formatting_context(run.fragments.as_deref(),- used,+ Some(used),+ used_values::RootInputCells::capture(used),child,root_containing_block,parent_grid,@@ -3231,7 +3238,7 @@ pub(super) fn run_reads_content_block_size_adopted_after_it(fn absorb_run_outputs(callbacks: &LayoutPass<'_>,parent_fragments: Option<&fragment_tree::RunFragmentBuilder>,- parent_used: &UsedValues,+ parent_used: Option<&UsedValues>,child: Node,input: &LayoutInput,root_cells: used_values::RootInputCells,@@ -3249,7 +3256,9 @@ fn absorb_run_outputs(let content_block_size_adopted_after_run =content_block_size_adopted_after_run(input, result.automatic_content_block_size);let laid_out_box = root_outcome.laid_out_child_box(root_cells, &result, content_block_size_adopted_after_run);- root_outcome.apply_to_record(parent_used, content_block_size_adopted_after_run);+ if let Some(parent_used) = parent_used {+ root_outcome.apply_to_record(parent_used, content_block_size_adopted_after_run);+ }let fragment_arrival = parent_fragments.and(root).map(|root| {debug_assert!(root.node == child, "a child run returned a root for a different box");fragment_tree::ChildFragmentArrival::RunRoot {@@ -3529,7 +3538,8 @@ fn compute_root_layout(input: LayoutStageInput<'_>, should_collect_devtools_layolet fc_type = independent_formatting_context_type(root_for_layout, &callbacks);let root_outcome = run_formatting_context(Some(&entry_fragments),- root_for_layout_used,+ Some(root_for_layout_used),+ used_values::RootInputCells::capture(root_for_layout_used),root_for_layout,callbacks.in_flow_containing_block(root_for_layout),None,@@ -3681,7 +3691,8 @@ fn layout_subtree_with_frozen_root_geometry(run: &FormattingContextRun<'_>) {.expect("partial relayout root must establish an independent formatting context");let root_outcome = run_formatting_context(Some(fragments),- root_used,+ Some(root_used),+ used_values::RootInputCells::capture(root_used),root,callbacks.in_flow_containing_block(root),None,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 0662be89bfc..e7dbfb3170e 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@@ -41,10 +41,11 @@ pub(super) fn layout_replaced_with_children(let wrapper_constraints = run.sizing().constraints_for_child_context(run.box_, layout_input.containing_block_constraints);- let wrapper_state = run+ let wrapper_record = run.records.create_used_values(&run.callbacks, wrapper, wrapper_constraints);- wrapper_state.set_content_inline_size(content_inline_size);+ let mut wrapper_cells = used_values::RootInputCells::capture(wrapper_record);+ wrapper_cells.set_content_inline_size(content_inline_size);let formatting_context::ChildRunOutcome {result: wrapper_result,@@ -52,7 +53,8 @@ pub(super) fn layout_replaced_with_children(..} = formatting_context::run_formatting_context(run.fragments.as_deref(),- wrapper_state,+ Some(wrapper_record),+ wrapper_cells,wrapper,run.callbacks.in_flow_containing_block(wrapper),None,diff --git a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rsindex 6b42c809d8a..7ca18a7843e 100644--- a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs@@ -2030,7 +2030,7 @@ impl<'pass> SvgFormattingContext<'pass> {if self.svg_attributes(child).is_fit_to_view_box {self.layout_nested_viewport(run, child);} else if kind == NodeKind::SVGForeignObjectBox {- let child_used_pointer = self.create_used_values(child);+ let mut child_cells = used_values::RootInputCells::capture(self.create_used_values(child));let style = self.style(child);let rect = SvgCssPixelRect {x: style.x().to_px(self.viewport_width),@@ -2038,21 +2038,28 @@ impl<'pass> SvgFormattingContext<'pass> {width: style.width().to_px(self.viewport_width),height: style.height().to_px(self.viewport_height),};- let child_used = child_used_pointer;- child_used.set_content_inline_size(rect.width);- child_used.set_content_block_size(rect.height);+ child_cells.set_content_inline_size(rect.width);+ child_cells.set_content_block_size(rect.height);let child_input = LayoutInput {available_space: AvailableSpace {- inline_size: AvailableSize::definite(child_used.content_inline_size.get()),- block_size: AvailableSize::definite(child_used.content_block_size.get()),+ inline_size: AvailableSize::definite(child_cells.content_inline_size),+ block_size: AvailableSize::definite(child_cells.content_block_size),},..self.nested_layout_input()};let formatting_context::ChildLayout {outcome,fragment_arrival,- } = formatting_context::layout_inside_child(run, None, None, child, child_input, true);+ } = formatting_context::layout_inside_child_with_input_cells(+ run,+ None,+ None,+ child,+ child_input,+ child_cells,+ true,+ );outcome.report_percentage_block_size_dependency_of(run, child);match outcome {ChildLayoutOutcome::Created(_) => {}@@ -2352,23 +2359,23 @@ impl<'pass> SvgFormattingContext<'pass> {} else {let parent = self.parent(resource);assert!(!parent.is_invalid());- let parent_used = self.used_values(parent);+ let parent_metrics = run.records.box_metrics_of(parent);(CssPixels::nearest_value_for(- attributes.pattern_width.value as f64 * parent_used.content_inline_size.get().to_double(),+ attributes.pattern_width.value as f64 * parent_metrics.content_inline_size().to_double(),),CssPixels::nearest_value_for(- attributes.pattern_height.value as f64 * parent_used.content_block_size.get().to_double(),+ attributes.pattern_height.value as f64 * parent_metrics.content_block_size().to_double(),),)}} else if attributes.content_units == SVG_UNITS_OBJECT_BOUNDING_BOX {let parent = self.parent(resource);assert!(!parent.is_invalid());- let parent_used = self.used_values(parent);+ let parent_metrics = run.records.box_metrics_of(parent);(- parent_used.content_inline_size.get(),- parent_used.content_block_size.get(),+ parent_metrics.content_inline_size(),+ parent_metrics.content_block_size(),)} else {(self.viewport_width, self.viewport_height)