diff options
author | Oriol Brufau <obrufau@igalia.com> | 2024-12-18 23:21:47 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-18 22:21:47 +0000 |
commit | ab270f3d52de28f76975e99b3f5bf871a8a9961b (patch) | |
tree | 4c6bd011e0445e3b0030c69a5d79a1e9d926068f /components | |
parent | 017b12a627820e8de834fbdda68f650629dddaee (diff) | |
download | servo-ab270f3d52de28f76975e99b3f5bf871a8a9961b.tar.gz servo-ab270f3d52de28f76975e99b3f5bf871a8a9961b.zip |
layout: Never stretch indefinite intrinsic keywords other than `auto` (#34672)
Consider:
```html
<div style="position: relative; width: 50px; height: 50px; border: solid; margin: 5px">
<div style="position: absolute; top: 0; bottom: 0; height: max-content">
<canvas width="25" height="25" style="background: cyan; height: 100%"></canvas>
</div>
</div>
```
In order to determine the inline min/max-content sizes, we need a
tentative block size as the input, which only takes extrinsic values
into account.
In this case `height: max-content` is intrinsic, so we were treating it
as `height: initial`, which would behave as a definite `height: stretch`.
Therefore, the canvas was able to resolve its percentage.
However, it seems weird to treat an explicitly intrinsic keyword in an
extrinsic way, and Blink doesn't do it. So now we treat the tentative
block size as indefinite, therefore the percentage behaves as auto.
This adds a new test, we were previously failing 6 subtests, now only 3.
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Diffstat (limited to 'components')
-rw-r--r-- | components/layout_2020/geom.rs | 2 | ||||
-rw-r--r-- | components/layout_2020/positioned.rs | 11 |
2 files changed, 7 insertions, 6 deletions
diff --git a/components/layout_2020/geom.rs b/components/layout_2020/geom.rs index f065baad12a..1684e0304a3 100644 --- a/components/layout_2020/geom.rs +++ b/components/layout_2020/geom.rs @@ -627,7 +627,7 @@ impl ToLogicalWithContainingBlock<LogicalRect<Au>> for PhysicalRect<Au> { /// The possible values accepted by the sizing properties. /// <https://drafts.csswg.org/css-sizing/#sizing-properties> -#[derive(Clone, PartialEq)] +#[derive(Clone, Debug, PartialEq)] pub(crate) enum Size<T> { /// Represents an `auto` value for the preferred and minimum size properties, /// or `none` for the maximum size properties. diff --git a/components/layout_2020/positioned.rs b/components/layout_2020/positioned.rs index ecb65af97cc..9841f9b6c86 100644 --- a/components/layout_2020/positioned.rs +++ b/components/layout_2020/positioned.rs @@ -799,7 +799,6 @@ impl<'a> AbsoluteAxisSolver<'a> { // A LazyCell will only invoke it once if needed, and then reuse the result. let content_size = get_content_size.map(LazyCell::new); let solve_size = |initial_behavior, stretch_size: Au| -> SizeConstraint { - let initial_is_stretch = initial_behavior == Size::Stretch; let stretch_size = stretch_size.max(Au::zero()); if let Some(ref content_size) = content_size { let preferred_size = Some(self.computed_size.resolve( @@ -816,10 +815,12 @@ impl<'a> AbsoluteAxisSolver<'a> { .resolve_non_initial(stretch_size, content_size); SizeConstraint::new(preferred_size, min_size, max_size) } else { - let preferred_size = self - .computed_size - .maybe_resolve_extrinsic(Some(stretch_size)) - .or(initial_is_stretch.then_some(stretch_size)); + let preferred_size = if self.computed_size.is_initial() { + initial_behavior + } else { + self.computed_size + } + .maybe_resolve_extrinsic(Some(stretch_size)); let min_size = self .computed_min_size .maybe_resolve_extrinsic(Some(stretch_size)) |