layout: Generalize ContainingBlock's block size to a SizeConstraint (#34946)

It used to be an `AuOrAuto`, turning it into a `SizeConstraint` allows
passing the information about the min and max constraints when the
containing block doesn't have a definite block size.

This will be useful for table layout.

Note that in most cases we were already constructing the containing
block from a `SizeConstraint`, but we were calling `to_auto_or()` to
turn it into an `AuOrAuto`.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
Oriol Brufau 2025-01-13 02:25:33 -08:00 committed by GitHub
parent de780dcde4
commit f66cd172d6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 71 additions and 69 deletions

View file

@ -145,7 +145,7 @@ impl BlockLevelBox {
let available_inline_size =
containing_block.size.inline - pbm.padding_border_sums.inline - margin.inline_sum();
let available_block_size = containing_block.size.block.non_auto().map(|block_size| {
let available_block_size = containing_block.size.block.to_definite().map(|block_size| {
Au::zero().max(block_size - pbm.padding_border_sums.block - margin.block_sum())
});
@ -174,7 +174,7 @@ impl BlockLevelBox {
let containing_block_for_children = ContainingBlock {
size: ContainingBlockSize {
inline: inline_size,
block: tentative_block_size.to_auto_or(),
block: tentative_block_size,
},
style,
};
@ -269,7 +269,7 @@ impl OutsideMarker {
let containing_block_for_children = ContainingBlock {
size: ContainingBlockSize {
inline: content_sizes.sizes.max_content,
block: AuOrAuto::auto(),
block: SizeConstraint::default(),
},
style: &self.marker_style,
};
@ -1202,7 +1202,7 @@ impl IndependentNonReplacedContents {
let available_block_size = containing_block
.size
.block
.non_auto()
.to_definite()
.map(|block_size| Au::zero().max(block_size - pbm_sums.block_sum()));
let (preferred_block_size, min_block_size, max_block_size) = content_box_sizes
.block
@ -1265,7 +1265,7 @@ impl IndependentNonReplacedContents {
&ContainingBlock {
size: ContainingBlockSize {
inline: inline_size,
block: tentative_block_size.to_auto_or(),
block: tentative_block_size,
},
style,
},
@ -1335,7 +1335,7 @@ impl IndependentNonReplacedContents {
&ContainingBlock {
size: ContainingBlockSize {
inline: proposed_inline_size,
block: tentative_block_size.to_auto_or(),
block: tentative_block_size,
},
style,
},
@ -1662,7 +1662,7 @@ fn solve_containing_block_padding_and_border_for_in_flow_box<'a>(
let available_block_size = containing_block
.size
.block
.non_auto()
.to_definite()
.map(|block_size| Au::zero().max(block_size - pbm_sums.block_sum()));
// https://drafts.csswg.org/css2/#the-height-property
@ -1698,7 +1698,7 @@ fn solve_containing_block_padding_and_border_for_in_flow_box<'a>(
let containing_block_for_children = ContainingBlock {
size: ContainingBlockSize {
inline: inline_size,
block: tentative_block_size.to_auto_or(),
block: tentative_block_size,
},
style,
};
@ -2102,7 +2102,7 @@ fn block_size_is_zero_or_intrinsic(size: &StyleSize, containing_block: &Containi
StyleSize::LengthPercentage(ref lp) => {
// TODO: Should this resolve definite percentages? Blink does it, Gecko and WebKit don't.
lp.is_definitely_zero() ||
(lp.0.has_percentage() && containing_block.size.block.is_auto())
(lp.0.has_percentage() && !containing_block.size.block.is_definite())
},
StyleSize::AnchorSizeFunction(_) => unreachable!("anchor-size() should be disabled"),
}
@ -2171,7 +2171,7 @@ impl IndependentFormattingContext {
let available_block_size = containing_block
.size
.block
.non_auto()
.to_definite()
.map(|block_size| (block_size - pbm_sums.block_sum()).max(Au::zero()));
let tentative_block_size = content_box_sizes_and_pbm
.content_box_sizes
@ -2198,7 +2198,7 @@ impl IndependentFormattingContext {
let containing_block_for_children = ContainingBlock {
size: ContainingBlockSize {
inline: inline_size,
block: tentative_block_size.to_auto_or(),
block: tentative_block_size,
},
style: self.style(),
};