aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout_2020/flexbox
diff options
context:
space:
mode:
authorOriol Brufau <obrufau@igalia.com>2025-03-10 21:38:44 +0100
committerGitHub <noreply@github.com>2025-03-10 20:38:44 +0000
commit0419a7818dc051aef9f0bb9022ee89aaa4183b99 (patch)
tree8652dfc8474431e0c2d283702df6749e32dd0dc9 /components/layout_2020/flexbox
parenta5cf04c479007f101cb31ff2d99fe5c8562da6bb (diff)
downloadservo-0419a7818dc051aef9f0bb9022ee89aaa4183b99.tar.gz
servo-0419a7818dc051aef9f0bb9022ee89aaa4183b99.zip
layout: Remove `calculate_hypothetical_cross_size()` (#35821)
One of the callers was only used for an assert, and it was passing an inline size argument to a parameter expecting a block size, so it wasn't making much sense anyways. Just inline the code into the other caller, and for consistency remove the assert for replaced elements too. Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Diffstat (limited to 'components/layout_2020/flexbox')
-rw-r--r--components/layout_2020/flexbox/layout.rs57
1 files changed, 23 insertions, 34 deletions
diff --git a/components/layout_2020/flexbox/layout.rs b/components/layout_2020/flexbox/layout.rs
index 81364d10487..08cacc14934 100644
--- a/components/layout_2020/flexbox/layout.rs
+++ b/components/layout_2020/flexbox/layout.rs
@@ -2021,7 +2021,6 @@ impl FlexItem<'_> {
Size::FitContent.into(),
flex_axis.vec2_to_flow_relative(self.pbm_auto_is_zero),
);
- let hypothetical_cross_size = flex_axis.vec2_to_flex_relative(size).cross;
if let Some(non_stretch_layout_result) = non_stretch_layout_result {
if non_stretch_layout_result
@@ -2030,14 +2029,11 @@ impl FlexItem<'_> {
size,
)
{
- assert_eq!(
- non_stretch_layout_result.hypothetical_cross_size,
- hypothetical_cross_size
- );
return None;
}
}
+ let hypothetical_cross_size = flex_axis.vec2_to_flex_relative(size).cross;
let fragments = replaced.make_fragments(
flex_context.layout_context,
item_style,
@@ -2061,28 +2057,6 @@ impl FlexItem<'_> {
})
},
IndependentFormattingContextContents::NonReplaced(non_replaced) => {
- let calculate_hypothetical_cross_size = |content_block_size: Au| {
- if !cross_axis_is_item_block_axis {
- return inline_size;
- }
- // This means that an auto size with stretch alignment will behave different than
- // a stretch size. That's not what the spec says, but matches other browsers.
- // To be discussed in https://github.com/w3c/csswg-drafts/issues/11784.
- let stretch_size = containing_block
- .size
- .block
- .to_definite()
- .map(|size| Au::zero().max(size - self.pbm_auto_is_zero.cross));
- self.content_cross_sizes.resolve(
- Direction::Block,
- Size::FitContent,
- Au::zero(),
- stretch_size,
- || content_block_size.into(),
- self.is_table(),
- )
- };
-
let item_as_containing_block = ContainingBlock {
size: ContainingBlockSize {
inline: inline_size,
@@ -2095,12 +2069,6 @@ impl FlexItem<'_> {
if non_stretch_layout_result
.compatible_with_containing_block_size(&item_as_containing_block)
{
- assert_eq!(
- non_stretch_layout_result.hypothetical_cross_size,
- calculate_hypothetical_cross_size(
- non_stretch_layout_result.content_size.inline,
- )
- );
return None;
}
}
@@ -2135,6 +2103,27 @@ impl FlexItem<'_> {
FragmentFlags::SIZE_DEPENDS_ON_BLOCK_CONSTRAINTS_AND_CAN_BE_CHILD_OF_FLEX_ITEM))
});
+ let hypothetical_cross_size = if cross_axis_is_item_block_axis {
+ // This means that an auto size with stretch alignment will behave different than
+ // a stretch size. That's not what the spec says, but matches other browsers.
+ // To be discussed in https://github.com/w3c/csswg-drafts/issues/11784.
+ let stretch_size = containing_block
+ .size
+ .block
+ .to_definite()
+ .map(|size| Au::zero().max(size - self.pbm_auto_is_zero.cross));
+ self.content_cross_sizes.resolve(
+ Direction::Block,
+ Size::FitContent,
+ Au::zero(),
+ stretch_size,
+ || content_block_size.into(),
+ self.is_table(),
+ )
+ } else {
+ inline_size
+ };
+
let item_writing_mode_is_orthogonal_to_container_writing_mode =
flex_context.config.writing_mode.is_horizontal() !=
item_style.writing_mode.is_horizontal();
@@ -2161,7 +2150,7 @@ impl FlexItem<'_> {
};
Some(FlexItemLayoutResult {
- hypothetical_cross_size: calculate_hypothetical_cross_size(content_block_size),
+ hypothetical_cross_size,
fragments,
positioning_context,
baseline_relative_to_margin_box,