diff options
author | Oriol Brufau <obrufau@igalia.com> | 2024-09-25 01:53:04 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-25 08:53:04 +0000 |
commit | 43d92ecbcbb297906f2d7d5735eaffbefdd6cfeb (patch) | |
tree | 561538bc895577e64368601af2f325b096b2d7e3 | |
parent | ade902207fc1f941fc77fa47bff1db0375ed7220 (diff) | |
download | servo-43d92ecbcbb297906f2d7d5735eaffbefdd6cfeb.tar.gz servo-43d92ecbcbb297906f2d7d5735eaffbefdd6cfeb.zip |
Use `ContentSizes::shrink_to_fit` when possible (#33527)
And ensure that the minimum wins for malformed ContentSizes.
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
-rw-r--r-- | components/layout_2020/flexbox/layout.rs | 11 | ||||
-rw-r--r-- | components/layout_2020/sizing.rs | 8 |
2 files changed, 11 insertions, 8 deletions
diff --git a/components/layout_2020/flexbox/layout.rs b/components/layout_2020/flexbox/layout.rs index bbb333ad524..c7f7c4a86b8 100644 --- a/components/layout_2020/flexbox/layout.rs +++ b/components/layout_2020/flexbox/layout.rs @@ -1737,9 +1737,8 @@ impl FlexItem<'_> { self.content_max_size.cross, ) }); - (containing_block.inline_size - self.pbm_auto_is_zero.cross) - .min(content_contributions.max_content) - .max(content_contributions.min_content) + content_contributions + .shrink_to_fit(containing_block.inline_size - self.pbm_auto_is_zero.cross) }), // The main size of a flex item is considered to be definite if its flex basis is definite // or the flex container has a definite main size. @@ -2513,10 +2512,8 @@ impl FlexItemBox { flex_context.layout_context, &containing_block_for_children, ); - - containing_block_inline_size_minus_pbm - .min(inline_content_sizes.max_content) - .max(inline_content_sizes.min_content) + inline_content_sizes + .shrink_to_fit(containing_block_inline_size_minus_pbm) } }) .clamp_between_extremums(min_size.inline, max_size.inline); diff --git a/components/layout_2020/sizing.rs b/components/layout_2020/sizing.rs index 70c726d3c0e..abffe3548a0 100644 --- a/components/layout_2020/sizing.rs +++ b/components/layout_2020/sizing.rs @@ -92,9 +92,15 @@ impl AddAssign for ContentSizes { } impl ContentSizes { + /// Clamps the provided amount to be between the min-content and the max-content. + /// This is called "shrink-to-fit" in CSS2, and "fit-content" in CSS Sizing. /// <https://drafts.csswg.org/css2/visudet.html#shrink-to-fit-float> + /// <https://drafts.csswg.org/css-sizing/#funcdef-width-fit-content> pub fn shrink_to_fit(&self, available_size: Au) -> Au { - available_size.max(self.min_content).min(self.max_content) + // This formula is slightly different than what the spec says, + // to ensure that the minimum wins for a malformed ContentSize + // whose min_content is larger than its max_content. + available_size.min(self.max_content).max(self.min_content) } } |