Refactor computation of preferred aspect ratios (#34416)

* Refactor computation of preferred aspect ratios

Computing min/max-content sizes required a ContainingBlock in order to
resolve the padding and border when determining the preferred aspect
ratio. However, all callers already knew the padding and border, so they
can compute the ratio themselves, and pass it directly instead of
the ContainingBlock.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>

* Put preferred aspect ratio into ConstraintSpace

Signed-off-by: Oriol Brufau <obrufau@igalia.com>

---------

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
Oriol Brufau 2024-11-29 12:40:52 +01:00 committed by GitHub
parent 16da1c2721
commit 19a7e95a6a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 133 additions and 113 deletions

View file

@ -235,10 +235,13 @@ impl OutsideMarker {
sequential_layout_state: Option<&mut SequentialLayoutState>,
collapsible_with_parent_start_margin: Option<CollapsibleWithParentStartMargin>,
) -> Fragment {
let content_sizes = self.block_container.inline_content_sizes(
layout_context,
&ConstraintSpace::new_for_style(&self.marker_style),
let constraint_space = ConstraintSpace::new_for_style_and_ratio(
&self.marker_style,
None, /* TODO: support preferred aspect ratios on non-replaced boxes */
);
let content_sizes = self
.block_container
.inline_content_sizes(layout_context, &constraint_space);
let containing_block_for_children = ContainingBlock {
inline_size: content_sizes.sizes.max_content,
block_size: AuOrAuto::auto(),
@ -394,7 +397,8 @@ fn calculate_inline_content_size_for_block_level_boxes(
style,
containing_block,
&LogicalVec2::zero(),
false, /* auto_block_size_stretches_to_containing_block */
false, /* auto_block_size_stretches_to_containing_block */
|_| None, /* TODO: support preferred aspect ratios on non-replaced boxes */
|constraint_space| {
contents.inline_content_sizes(layout_context, constraint_space)
},
@ -2054,7 +2058,11 @@ impl IndependentFormattingContext {
SizeConstraint::new(preferred_block_size, min_block_size, max_block_size);
let content_size = LazyCell::new(|| {
let constraint_space = ConstraintSpace::new(tentative_block_size, writing_mode);
let constraint_space = ConstraintSpace::new(
tentative_block_size,
writing_mode,
non_replaced.preferred_aspect_ratio(),
);
non_replaced
.inline_content_sizes(layout_context, &constraint_space)
.sizes