Truly independent web browser
LibWeb: Remove automatic content inline sizes from layout runs
Aliaksandr Kalenik0ffa72c00b91
diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rsindex 85c99d890ef..0bcefd90f34 100644--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs@@ -205,9 +205,6 @@ pub(crate) struct FloatingBox {// Offset from left/right edge to the left content edge of `box`.offset_from_edge: CssPixels,- // Top margin edge of `box`.- top_margin_edge: CssPixels,-// Bottom margin edge of `box`.bottom_margin_edge: CssPixels,@@ -4172,9 +4169,6 @@ impl<'pass> BlockFormattingContext<'pass> {box_: node,side,offset_from_edge: placement.offset_from_edge,- top_margin_edge: content_block_offset- - self.used(node).margin_top.get()- - self.used(node).border_box_top(false),bottom_margin_edge: content_block_offset+ self.used(node).content_block_size.get()+ self.used(node).margin_box_bottom(false),@@ -4240,6 +4234,10 @@ impl<'pass> BlockFormattingContext<'pass> {available_space_for_children: AvailableSpace,) {assert!(self.facts(block_container).children_are_inline());+ debug_assert!(+ self.used(block_container).has_definite_inline_size(),+ "lines are laid out in a block container of definite inline size"+ );let inline_input = self.child_layout_input(block_container, input, available_space_for_children);let mut context = inline_formatting_context::InlineFormattingContext::new_with_rust_parent(run,@@ -4249,56 +4247,6 @@ impl<'pass> BlockFormattingContext<'pass> {self,);context.run();- let automatic_inline_size = context.automatic_content_inline_size;- let automatic_block_size = context.automatic_content_block_size;- if !self.used(block_container).has_definite_inline_size() {- // NOTE: min-width or max-width for boxes with inline children can only be applied after inside layout- // is done and the inline size of the box content is known- let mut used_inline_size = automatic_inline_size;- // https://www.w3.org/TR/css-sizing-3/#sizing-values- // Percentages are resolved against the appropriate inline or block size of the containing block.- let containing_inline_size = input.containing_block_constraints.inline_basis();- let available_inline_size = AvailableSize::definite(containing_inline_size);- let sizing = self.sizing();- let style = self.style(block_container);- // https://drafts.csswg.org/css-values-5/#calc-size- // For the purpose of sizing (including for intrinsic size contributions), calc-size() resolves to the- // result of its calc-size calculation.- if style.width().is_auto() {- used_inline_size = sizing.resolve_calc_size(- block_container,- SizingAxis::Inline,- style.width(),- used_inline_size,- input.containing_block_constraints.percentage_basis_inline_size,- );- }- if !sizing.should_treat_max_inline_size_as_none(- block_container,- input.available_space.inline_size,- input.containing_block_constraints,- ) {- let maximum = sizing.calculate_inner_inline_size(- block_container,- available_inline_size,- style.max_width(),- input.containing_block_constraints,- );- used_inline_size = used_inline_size.min(maximum);- }- if !crate::layout::sizing_context::is_plain_auto(style.min_width()) {- let minimum = sizing.calculate_inner_inline_size(- block_container,- available_inline_size,- style.min_width(),- input.containing_block_constraints,- );- used_inline_size = used_inline_size.max(minimum);- }- let used = self.used(block_container);- used.set_content_inline_size(used_inline_size);- used.set_content_block_size(automatic_block_size);- }}pub(crate) fn compute_automatic_block_size_for_block_level_element(@@ -4449,126 +4397,12 @@ impl<'pass> BlockFormattingContext<'pass> {CssPixels::default()}- pub(crate) fn greatest_child_inline_size_including_floats(&self, node: Node) -> CssPixels {- // Similar to the former C++ greatest_child_inline_size() helper.- // but this one takes floats into account!- let mut max_inline_size = CssPixels::default();-- // https://drafts.csswg.org/css2/#floats- // A line box is next to a float when there exists a vertical position that satisfies all of these- // four conditions: (a) at or below the top of the line box, (b) at or above the bottom of the line- // box, (c) below the top margin edge of the float, and (d) above the bottom margin edge of the float.- let line_box_is_next_to_float = |block_start: CssPixels, block_end: CssPixels, floating_box: &FloatingBox| {- block_start < floating_box.bottom_margin_edge && block_end > floating_box.top_margin_edge- };- let inline_size_to_make_room_for_float_margin_box = |floating_box: &FloatingBox| {- let used = self.used(floating_box.box_);- if floating_box.side == FloatSide::Left {- floating_box.offset_from_edge- + used.content_inline_size.get()- + used.margin_right.get()- + used.border_box_right(false)- } else {- floating_box.offset_from_edge + used.margin_left.get() + used.border_box_left(false)- }- };-- let floats = self.floats.borrow();- // https://drafts.csswg.org/css-sizing-3/#intrinsic-contribution- // A box’s min-content contribution/max-content contribution in each axis is the size of the- // content box of a hypothetical width/auto-sized float that contains only that box- //- // Only direct floats participate here. Descendant floats contribute through their containing block's- // own min-content contribution, not as if they belonged to this box's hypothetical float.- for candidate in floats.iter().filter(|floating_box| {- self.containing_block(floating_box.box_) == node- && !self.used(floating_box.box_).is_invisible_for_line_clamp.get()- }) {- let mut inline_space = inline_formatting_context::SpaceUsedByFloats::default();- for direct_float in floats.iter().filter(|floating_box| {- self.containing_block(floating_box.box_) == node- && !self.used(floating_box.box_).is_invisible_for_line_clamp.get()- }) {- if line_box_is_next_to_float(candidate.top_margin_edge, candidate.bottom_margin_edge, direct_float) {- let inline_size = inline_size_to_make_room_for_float_margin_box(direct_float);- if direct_float.side == FloatSide::Left {- inline_space.left = inline_space.left.max(inline_size);- } else {- inline_space.right = inline_space.right.max(inline_size);- }- }- }- max_inline_size = max_inline_size.max(inline_space.left + inline_space.right);- }-- let facts = self.facts(node);- if facts.children_are_inline() {- if let Some(data) = self.used(node).line_data_ref() {- for line in data.lines() {- let mut inline_size_here = line.horizontal_extent;- let line_block_start = line.physical_vertical_end() - line.physical_vertical_extent();- let line_block_end = line.physical_vertical_end();- let mut extra_left = CssPixels::default();- for left_float in floats.iter().filter(|floating_box| {- floating_box.side == FloatSide::Left- && self.containing_block(floating_box.box_) == node- && !self.used(floating_box.box_).is_invisible_for_line_clamp.get()- }) {- // NOTE: Floats directly affect the automatic size of their containing block, but only indirectly anything above in the tree.- if line_box_is_next_to_float(line_block_start, line_block_end, left_float) {- extra_left = extra_left.max(inline_size_to_make_room_for_float_margin_box(left_float));- }- }- let mut extra_right = CssPixels::default();- for right_float in floats.iter().filter(|floating_box| {- floating_box.side == FloatSide::Right- && self.containing_block(floating_box.box_) == node- && !self.used(floating_box.box_).is_invisible_for_line_clamp.get()- }) {- // NOTE: Floats directly affect the automatic size of their containing block, but only indirectly anything above in the tree.- if line_box_is_next_to_float(line_block_start, line_block_end, right_float) {- extra_right = extra_right.max(inline_size_to_make_room_for_float_margin_box(right_float));- }- }- inline_size_here += extra_left + extra_right;- max_inline_size = max_inline_size.max(inline_size_here);- }- }- } else {- drop(floats);- for child in self.laid_out_children(node) {- if !self.facts(child).is_flow_layout_participant() {- continue;- }- if let Some(used) = self.run.records.used_values_if_owned(child) {- if used.is_invisible_for_line_clamp.get() {- continue;- }- max_inline_size = max_inline_size.max(used.margin_box_inline_size(false));- }- }- }- max_inline_size- }-- pub(crate) fn automatic_content_inline_size(&self) -> CssPixels {- let root_facts = self.facts(self.run.box_);- if root_facts.children_are_inline() {- return self.used(self.run.box_).content_inline_size.get();- }- if root_facts.is_table_wrapper() {- let mut stack: Vec<Node> = self.run.callbacks.children_rev(self.run.box_).collect();- while let Some(node) = stack.pop() {- let facts = self.facts(node);- if facts.is_box() && self.style(node).display().is_table_inside() {- let used = self.used(node);- return used.border_box_inline_size(used.uses_collapsing_borders_model.get());- }- stack.extend(self.run.callbacks.children_rev(node));- }- unreachable!("a table wrapper contains its table box");+ pub(crate) fn table_wrapper_content_inline_size(&self) -> Option<CssPixels> {+ if !self.facts(self.run.box_).is_table_wrapper() {+ return None;}- self.greatest_child_inline_size_including_floats(self.run.box_)+ let table_used = self.used(self.sizing().table_box_inside_wrapper(self.run.box_));+ Some(table_used.border_box_inline_size(table_used.uses_collapsing_borders_model.get()))}fn resolve_automatic_line_clamp_block_size(&self, input: LayoutInput) -> Option<CssPixels> {diff --git a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rsindex 7bddffcf6d1..f4777f154dd 100644--- a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs@@ -3948,10 +3948,6 @@ impl<'pass> FlexFormattingContext<'pass> {self.derived_baselines_of_root_box}- pub(super) fn automatic_content_inline_size(&self) -> CssPixels {- self.container_used().content_inline_size.get()- }-pub(super) fn automatic_content_block_size(&self) -> CssPixels {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 54e1aea73ce..f91c53cf13f 100644--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs@@ -969,10 +969,11 @@ pub struct BorderData {#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]pub(crate) struct ChildLayoutResult {- pub automatic_content_inline_size: CssPixels,pub automatic_content_block_size: CssPixels,pub automatic_line_clamp_max_lines: Option<usize>,pub baselines: DerivedBaselines,+ /// For a table wrapper, the inline size its table box gives it.+ pub table_wrapper_content_inline_size: Option<CssPixels>,pub table_box_in_wrapper_border_box_block_size: Option<CssPixels>,/// For a box with a preferred aspect ratio, the block size of its laid out content.pub content_block_size_for_aspect_ratio_minimum: Option<CssPixels>,@@ -1700,11 +1701,8 @@ fn in_flow_children_margin_box_block_extent(fn finalize_block_level_root(run: &FormattingContextRun, input: &LayoutInput, body_result: &ChildLayoutResult) {let node = run.box_;- let facts = NodeFacts::new(&run.callbacks, node);- if facts.is_table_wrapper() {- run.records- .used_values(node)- .set_content_inline_size(body_result.automatic_content_inline_size);+ if let Some(inline_size) = body_result.table_wrapper_content_inline_size {+ run.records.used_values(node).set_content_inline_size(inline_size);}let style = StyleValues::for_node(&run.callbacks, node);if !style.display().is_table_inside() && input.sizing.forced_content_block_size.is_none() {@@ -1726,10 +1724,8 @@ fn finalize_block_level_root(run: &FormattingContextRun, input: &LayoutInput, bofn finalize_float_root(run: &FormattingContextRun, input: &LayoutInput, body_result: &ChildLayoutResult) {let node = run.box_;- if NodeFacts::new(&run.callbacks, node).is_table_wrapper() {- run.records- .used_values(node)- .set_content_inline_size(body_result.automatic_content_inline_size);+ if let Some(inline_size) = body_result.table_wrapper_content_inline_size {+ run.records.used_values(node).set_content_inline_size(inline_size);}run.sizing().resolve_used_block_size_if_treated_as_auto(node,@@ -2127,10 +2123,10 @@ fn execute_formatting_context_run(FormattingContextImplementation::Block(context) => {context.run(body_run, body_input);let mut result = ChildLayoutResult {- automatic_content_inline_size: context.automatic_content_inline_size(),automatic_content_block_size: context.automatic_content_block_size(),automatic_line_clamp_max_lines: context.automatic_line_clamp_max_lines(),baselines: context.derived_baselines_of_root_box(),+ table_wrapper_content_inline_size: context.table_wrapper_content_inline_size(),table_box_in_wrapper_border_box_block_size: context.table_box_in_wrapper_border_box_block_size(),..ChildLayoutResult::default()@@ -2149,7 +2145,6 @@ fn execute_formatting_context_run(let baselines = context.derived_baselines_of_root_box();store_derived_baselines(run.records.used_values(run.box_), baselines);ChildLayoutResult {- automatic_content_inline_size: context.automatic_content_inline_size(),automatic_content_block_size: context.automatic_content_block_size(),baselines,..ChildLayoutResult::default()@@ -2160,7 +2155,6 @@ fn execute_formatting_context_run(let baselines = context.derived_baselines_of_root_box();store_derived_baselines(run.records.used_values(run.box_), baselines);ChildLayoutResult {- automatic_content_inline_size: context.automatic_content_inline_size(),automatic_content_block_size: context.automatic_content_block_size(),baselines,..ChildLayoutResult::default()@@ -2171,7 +2165,6 @@ fn execute_formatting_context_run(let baselines = context.derived_baselines_of_root_box();store_derived_baselines(run.records.used_values(run.box_), baselines);ChildLayoutResult {- automatic_content_inline_size: context.automatic_content_inline_size(),automatic_content_block_size: context.automatic_content_block_size,baselines,..ChildLayoutResult::default()@@ -2186,7 +2179,6 @@ fn execute_formatting_context_run(let baselines = context.derived_baselines_of_root_box();store_derived_baselines(run.records.used_values(run.box_), baselines);ChildLayoutResult {- automatic_content_inline_size: context.automatic_content_inline_size(),automatic_content_block_size: context.automatic_content_block_size(),baselines,..ChildLayoutResult::default()@@ -2220,17 +2212,11 @@ fn execute_formatting_context_run(// effects:// 1. The intrinsic sizes of the size containment box are determined as if the element had no content, following// the same logic as when sizing as if empty.- result.automatic_content_inline_size = explicit_intrinsic_inner_inline_size(&containment_facts);result.automatic_content_block_size = if style.contain_intrinsic_height_has_length() {CssPixels::nearest_value_for(style.contain_intrinsic_height_px())} else {CssPixels::default()};- } else if lays_out_own_content && containment_facts.node_has_inline_size_containment() {- // https://drafts.csswg.org/css-contain-2/#containment-inline-size- // "This means the inline-axis intrinsic sizes of the principal box are determined as if the element had- // no content."- result.automatic_content_inline_size = explicit_intrinsic_inner_inline_size(&containment_facts);}if containment_facts.has_preferred_aspect_ratio() {@@ -2507,7 +2493,11 @@ fn leave_own_frame(} else if used.orthogonal_flow_baselines().is_some() {used.rare_data_mut().orthogonal_flow_baselines = None;}- result.automatic_content_inline_size = result.automatic_content_block_size;+ // NB: The inline size of a table wrapper in its parent's frame is the block size of its content in its own+ // frame.+ if result.table_wrapper_content_inline_size.is_some() {+ result.table_wrapper_content_inline_size = Some(result.automatic_content_block_size);+ }result.automatic_content_block_size = content_inline_size;result.baselines = DerivedBaselines::default();result.content_block_size_for_aspect_ratio_minimum = None;diff --git a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rsindex 6d798599b3e..16f135fb99d 100644--- a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs@@ -4911,10 +4911,6 @@ impl<'pass> GridFormattingContext<'pass> {self.derived_baselines_of_root_box}- pub(crate) fn automatic_content_inline_size(&self) -> CssPixels {- self.container_used().content_inline_size.get()- }-pub(crate) fn automatic_content_block_size(&self) -> CssPixels {self.automatic_content_block_size}diff --git a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rsindex 832b3bc0872..58c4b6c7245 100644--- a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs@@ -974,8 +974,6 @@ pub(crate) struct InlineFormattingContext<'context> {pub(crate) parent: &'context block_formatting_context::BlockFormattingContext<'context>,pub(crate) containing_used_values: &'context UsedValues,pub(crate) fragmented_inlines_in_pre_order: Vec<Node>,- pub(crate) automatic_content_inline_size: CssPixels,- pub(crate) automatic_content_block_size: CssPixels,pub(crate) current_line_start: Cell<fragmentation::LinePosition>,inline_boxes_continued_from_previous_fragment: Vec<Node>,inline_boxes_continued_in_next_fragment: RefCell<Vec<Node>>,@@ -1000,8 +998,6 @@ impl<'context> InlineFormattingContext<'context> {parent,containing_used_values,fragmented_inlines_in_pre_order: Vec::new(),- automatic_content_inline_size: CssPixels::default(),- automatic_content_block_size: CssPixels::default(),current_line_start: Cell::new(fragmentation::LinePosition::default()),inline_boxes_continued_from_previous_fragment: Vec::new(),inline_boxes_continued_in_next_fragment: RefCell::new(Vec::new()),@@ -2189,22 +2185,6 @@ impl<'context> InlineFormattingContext<'context> {self.compute_inline_box_pieces();self.fold_inline_ancestor_relative_insets_into_line_data();}- self.automatic_content_block_size = {- let data = self.line_data();- let lines = &data.line_boxes;- if lines.iter().any(|line| line.has_block_level_box) {- lines- .last()- .map_or(CssPixels::default(), |line| line.physical_vertical_end())- } else {- lines- .iter()- .fold(CssPixels::default(), |sum, line| sum + line.physical_vertical_extent())- }- };- self.automatic_content_inline_size = self- .parent- .greatest_child_inline_size_including_floats(self.containing_block);let baselines = formatting_context::derive_baselines(self.run.records, &self.callbacks, self.containing_block);if self.containing_block == self.parent.root_box() {self.parent.record_derived_baselines_of_root_box(baselines);diff --git a/Libraries/LibWeb/Rust/src/layout/intrinsic_sizing.rs b/Libraries/LibWeb/Rust/src/layout/intrinsic_sizing.rsindex 8567af25fc2..dba6563c86a 100644--- a/Libraries/LibWeb/Rust/src/layout/intrinsic_sizing.rs+++ b/Libraries/LibWeb/Rust/src/layout/intrinsic_sizing.rs@@ -772,7 +772,7 @@ pub(super) fn content_sizes_of_math(ParticipationInParentFormattingContext::Root,);let result = formatting_context::run_root_without_parent_fragments(callbacks, node, scope.root(), input);- let size = result.automatic_content_inline_size;+ let size = scope.root().content_inline_size.get();let observes_percentage_inline_basis = scope.enter(callbacks, |run| {run.sizing().measurement_root_observes_percentage_inline_basis(node)});diff --git a/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rsindex f54735458f0..ed6fb8aad13 100644--- a/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/math_formatting_context.rs@@ -1422,7 +1422,6 @@ pub(super) fn layout_operator(run: &FormattingContextRun<'_>, input: &LayoutInpuif sizing_context::is_plain_auto(context.style(operator).width()) {used.content_inline_size.set(inline_size);}- result.automatic_content_inline_size = inline_size;result.automatic_content_block_size = ascent + descent;result.baselines = DerivedBaselines {inline_alignment: None,@@ -2245,6 +2244,10 @@ impl<'pass> MathFormattingContext<'pass> {_ => false,};let content_box_is_known = root_used.has_definite_inline_size();+ // NB: A MathML box measured for its content inline sizes takes the inline size of its math content.+ if !content_box_is_known {+ root_used.set_content_inline_size(content.inline_size);+ }let is_rtl = root_style.direction() == direction::RTL;let mut math_content_line_left = CssPixels::default();if content_box_is_known {@@ -2606,10 +2609,6 @@ impl<'pass> MathFormattingContext<'pass> {self.derived_baselines_of_root_box}- pub(super) fn automatic_content_inline_size(&self) -> CssPixels {- self.content.inline_size- }-pub(super) fn automatic_content_block_size(&self) -> CssPixels {self.content.ascent + self.content.descent}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 fac3db13905..4d1c49bfb20 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@@ -77,7 +77,6 @@ pub(super) fn layout_replaced_with_children(formatting_context::place_child(run, wrapper, used_values::FfiCssPixelPoint::default(), None);formatting_context::ChildLayoutResult {- automatic_content_inline_size: content_inline_size,automatic_content_block_size: wrapper_result.automatic_content_block_size,baselines: formatting_context::DerivedBaselines::default(),..formatting_context::ChildLayoutResult::default()diff --git a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rsindex f31b409448f..017ee3d9201 100644--- a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs@@ -3449,9 +3449,4 @@ impl<'pass> TableFormattingContext<'pass> {pub(super) fn derived_baselines_of_root_box(&self) -> DerivedBaselines {self.derived_baselines_of_root_box.get()}-- pub(super) fn automatic_content_inline_size(&self) -> CssPixels {- let used = self.used_values(self.run.box_);- used.content_inline_size.get()- }}