Skip to content

Truly independent web browser

LibWeb: Merge the two item content block size adoption directives

Aliaksandr Kalenik44eb97ec0db1
diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
index b1599c17f46..aad02dca151 100644
--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
@@ -2345,7 +2345,7 @@ impl<'pass> BlockFormattingContext<'pass> {
available_space: inner_available_space,
containing_block_constraints: marker_constraints,
sizing: RootSizingDirectives {
- adopt_automatic_content_block_size: true,
+ content_block_size_after_run: geometry::ContentBlockSizeAfterRun::Automatic,
..RootSizingDirectives::default()
},
participation: ParticipationInParentFormattingContext::Item,
diff --git a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
index d476b75b578..52dabcfb1f6 100644
--- a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
+++ b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
@@ -290,8 +290,7 @@ fn sizing_directives_match_ignoring_unobserved(
block_parent_resolved_content_inline_size,
table_cell_intrinsic_block_padding,
table_box_content_block_offset_in_wrapper,
- adopt_automatic_content_block_size,
- content_block_size_after_inside_layout,
+ content_block_size_after_run,
flex_self_block_size_resolution_space,
outer_float_intrusion_before_list_item_children,
treat_block_axis_percentage_insets_as_auto_beyond_root,
@@ -303,8 +302,7 @@ fn sizing_directives_match_ignoring_unobserved(
&& block_parent_resolved_content_inline_size == b.block_parent_resolved_content_inline_size
&& table_cell_intrinsic_block_padding == b.table_cell_intrinsic_block_padding
&& table_box_content_block_offset_in_wrapper == b.table_box_content_block_offset_in_wrapper
- && ((adopt_automatic_content_block_size == b.adopt_automatic_content_block_size
- && content_block_size_after_inside_layout == b.content_block_size_after_inside_layout)
+ && (content_block_size_after_run == b.content_block_size_after_run
|| content_block_size_adopted_after_run_unobserved)
&& outer_float_intrusion_before_list_item_children == b.outer_float_intrusion_before_list_item_children
&& treat_block_axis_percentage_insets_as_auto_beyond_root
@@ -1493,9 +1491,8 @@ mod tests {
let stored = key_of(item_input.clone());
let mut adopting_input = item_input;
- adopting_input.sizing.adopt_automatic_content_block_size = true;
- adopting_input.sizing.content_block_size_after_inside_layout =
- geometry::PackedOptionalCssPixels::from(Some(px(40)));
+ adopting_input.sizing.content_block_size_after_run =
+ geometry::ContentBlockSizeAfterRun::GrownFromAspectRatioBlockSize(px(40));
let probe = key_of(adopting_input);
assert!(!stored.matches(&probe, RunInputsTheStoredRunNeverObserved::default()));
diff --git a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
index b6855cdf12f..d01d38def3a 100644
--- a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
@@ -3248,9 +3248,10 @@ impl<'pass> FlexFormattingContext<'pass> {
&& self.flex_item_details[index]
.cross_size_transferred_through_aspect_ratio
.is_some()
+ && let Some(cross_size) = self.flex_items[index].cross_size
{
- input.sizing.content_block_size_after_inside_layout =
- geometry::PackedOptionalCssPixels::from(self.flex_items[index].cross_size);
+ input.sizing.content_block_size_after_run =
+ geometry::ContentBlockSizeAfterRun::GrownFromAspectRatioBlockSize(cross_size);
}
input
}
diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
index 9597bcebd8b..ec9e98f73dd 100644
--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
@@ -3425,10 +3425,11 @@ pub(super) fn content_block_size_adopted_after_run(
if input.participation != ParticipationInParentFormattingContext::Item {
return None;
}
- input.sizing.content_block_size_after_inside_layout.get().or(input
- .sizing
- .adopt_automatic_content_block_size
- .then_some(automatic_content_block_size))
+ match input.sizing.content_block_size_after_run {
+ geometry::ContentBlockSizeAfterRun::HandedOver => None,
+ geometry::ContentBlockSizeAfterRun::Automatic => Some(automatic_content_block_size),
+ geometry::ContentBlockSizeAfterRun::GrownFromAspectRatioBlockSize(block_size) => Some(block_size),
+ }
}
fn child_layout_from_outputs(
diff --git a/Libraries/LibWeb/Rust/src/layout/geometry.rs b/Libraries/LibWeb/Rust/src/layout/geometry.rs
index a764817d735..eb27afb2108 100644
--- a/Libraries/LibWeb/Rust/src/layout/geometry.rs
+++ b/Libraries/LibWeb/Rust/src/layout/geometry.rs
@@ -367,10 +367,7 @@ pub(crate) struct RootSizingDirectives {
// content box sits in the wrapper, so rows and row groups (whose containing block is the
// wrapper) can be placed in wrapper coordinates.
pub(crate) table_box_content_block_offset_in_wrapper: PackedOptionalCssPixels,
- pub(crate) adopt_automatic_content_block_size: bool,
- // Input-only: a flex item lays out its content against the block size transferred through its aspect ratio, then
- // takes this block size, which the automatic minimum size grew to fit the content.
- pub(crate) content_block_size_after_inside_layout: PackedOptionalCssPixels,
+ pub(crate) content_block_size_after_run: ContentBlockSizeAfterRun,
pub(crate) flex_self_block_size_resolution_space: Option<AvailableSpace>,
pub(crate) outer_float_intrusion_before_list_item_children: inline_formatting_context::SpaceUsedByFloats,
pub(crate) treat_block_axis_percentage_insets_as_auto_beyond_root: bool,
@@ -380,6 +377,19 @@ pub(crate) struct RootSizingDirectives {
pub(crate) math_stretch_size_constraint: Option<MathStretchSizeConstraint>,
}
+/// The content block size the root of an item's run takes once its contents are laid out.
+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
+pub(crate) enum ContentBlockSizeAfterRun {
+ /// The one its container handed it.
+ #[default]
+ HandedOver,
+ /// Its automatic content block size.
+ Automatic,
+ /// A flex or grid item lays out its content against the block size transferred through its aspect ratio, then
+ /// takes this block size, which the automatic minimum size grew to fit the content.
+ GrownFromAspectRatioBlockSize(CssPixels),
+}
+
/// The size that MathML layout asks the core operator of an embellished operator to stretch to cover.
// https://w3c.github.io/mathml-core/#box-model
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
diff --git a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
index c14fee8dfb8..fd22de9e77e 100644
--- a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
@@ -4878,8 +4878,8 @@ impl<'pass> GridFormattingContext<'pass> {
if let Some(transferred) = item.block_size_transferred_through_aspect_ratio {
// NB: The content is laid out against the block size transferred through the aspect ratio, and the item
// grows to its used block size afterwards.
- sizing.content_block_size_after_inside_layout =
- geometry::PackedOptionalCssPixels::from(Some(cells.content_block_size));
+ sizing.content_block_size_after_run =
+ geometry::ContentBlockSizeAfterRun::GrownFromAspectRatioBlockSize(cells.content_block_size);
cells.set_content_block_size(transferred);
}
self.update_cells_of(item, |item_cells| *item_cells = cells);
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.rs
index bc72ca9c9e5..57ad70b6e73 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
@@ -53,7 +53,7 @@ pub(super) fn layout_replaced_with_children(
available_space: child_available_space,
containing_block_constraints: wrapper_constraints,
sizing: geometry::RootSizingDirectives {
- adopt_automatic_content_block_size: true,
+ content_block_size_after_run: geometry::ContentBlockSizeAfterRun::Automatic,
..geometry::RootSizingDirectives::default()
},
participation: geometry::ParticipationInParentFormattingContext::Item,
diff --git a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs
index 22fc0c75926..9aa15c4fba0 100644
--- a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs
@@ -2828,7 +2828,11 @@ impl<'pass> TableFormattingContext<'pass> {
available_space: input,
containing_block_constraints: ContainingBlockConstraints::default(),
sizing: RootSizingDirectives {
- adopt_automatic_content_block_size,
+ content_block_size_after_run: if adopt_automatic_content_block_size {
+ geometry::ContentBlockSizeAfterRun::Automatic
+ } else {
+ geometry::ContentBlockSizeAfterRun::HandedOver
+ },
table_cell_intrinsic_block_padding: intrinsic_block_padding,
..RootSizingDirectives::default()
},
@@ -2946,7 +2950,11 @@ impl<'pass> TableFormattingContext<'pass> {
available_space: inner,
containing_block_constraints: ContainingBlockConstraints::default(),
sizing: RootSizingDirectives {
- adopt_automatic_content_block_size,
+ content_block_size_after_run: if adopt_automatic_content_block_size {
+ geometry::ContentBlockSizeAfterRun::Automatic
+ } else {
+ geometry::ContentBlockSizeAfterRun::HandedOver
+ },
..RootSizingDirectives::default()
},
participation: ParticipationInParentFormattingContext::Item,