mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
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>
This commit is contained in:
parent
ade902207f
commit
43d92ecbcb
2 changed files with 11 additions and 8 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue