layout: Implement the fit-content() sizing function (#36056)

Spec: https://drafts.csswg.org/css-sizing-3/#funcdef-width-fit-content

It's similar to the `fit-content` keyword but, instead of clamping the
stretch size between `min-content` and `max-content`, it clamps the
provided argument.

So now that we support `fit-content`, it's quite straightforward to add.
It's just not completely clear what should happen when the argument has
a cyclic percentage, so this may need some further adjustments depending
on the outcome of https://github.com/w3c/csswg-drafts/issues/11805

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
Oriol Brufau 2025-03-23 15:26:44 +01:00 committed by GitHub
parent 3a356ffb74
commit 8c2ac88ad0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
33 changed files with 100 additions and 192 deletions

View file

@ -2144,9 +2144,11 @@ impl<'container> PlacementState<'container> {
fn block_size_is_zero_or_intrinsic(size: &StyleSize, containing_block: &ContainingBlock) -> bool {
match size {
StyleSize::Auto | StyleSize::MinContent | StyleSize::MaxContent | StyleSize::FitContent => {
true
},
StyleSize::Auto |
StyleSize::MinContent |
StyleSize::MaxContent |
StyleSize::FitContent |
StyleSize::FitContentFunction(_) => true,
StyleSize::Stretch => {
// TODO: Should this return true when the containing block has a definite size of 0px?
!containing_block.size.block.is_definite()