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 /components/layout_2020/sizing.rs | |
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>
Diffstat (limited to 'components/layout_2020/sizing.rs')
-rw-r--r-- | components/layout_2020/sizing.rs | 8 |
1 files changed, 7 insertions, 1 deletions
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) } } |