aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout_2020/sizing.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/layout_2020/sizing.rs')
-rw-r--r--components/layout_2020/sizing.rs8
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)
}
}