Treat indefinite percentages as auto offsets in relative positioning (#31484)

* Treat indefinite percentages as auto offsets in relative positioning

Instead of just resolving the percentages against zero.
The spec is not clear (https://github.com/w3c/csswg-drafts/issues/9353),
but this way we match Gecko, Blink and WebKit.

* Update test expectations
This commit is contained in:
Oriol Brufau 2024-03-04 09:09:33 +01:00 committed by GitHub
parent 3e6b92df13
commit a977729a9e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 11 additions and 12 deletions

View file

@ -875,17 +875,22 @@ pub(crate) fn relative_adjustement(
style: &ComputedValues, style: &ComputedValues,
containing_block: &ContainingBlock, containing_block: &ContainingBlock,
) -> LogicalVec2<Length> { ) -> LogicalVec2<Length> {
// "If the height of the containing block is not specified explicitly (i.e., // It's not completely clear what to do with indefinite percentages
// it depends on content height), and this element is not absolutely // (https://github.com/w3c/csswg-drafts/issues/9353), so we match
// positioned, the value computes to 'auto'."" // other browsers and treat them as 'auto' offsets.
// https://www.w3.org/TR/CSS2/visudet.html#the-height-property
let cbis = containing_block.inline_size; let cbis = containing_block.inline_size;
let cbbs = containing_block.block_size.auto_is(Au::zero); let cbbs = containing_block.block_size;
let box_offsets = style let box_offsets = style
.box_offsets(containing_block) .box_offsets(containing_block)
.map_inline_and_block_axes( .map_inline_and_block_axes(
|v| v.percentage_relative_to(cbis.into()), |v| v.percentage_relative_to(cbis.into()),
|v| v.percentage_relative_to(cbbs.into()), |v| match cbbs.non_auto() {
Some(cbbs) => v.percentage_relative_to(cbbs.into()),
None => match v.non_auto().and_then(|v| v.to_length()) {
Some(v) => LengthOrAuto::LengthPercentage(v),
None => LengthOrAuto::Auto,
},
},
); );
fn adjust(start: LengthOrAuto, end: LengthOrAuto) -> Length { fn adjust(start: LengthOrAuto, end: LengthOrAuto) -> Length {
match (start, end) { match (start, end) {

View file

@ -1,2 +0,0 @@
[position-relative-007.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[calc-offsets-relative-bottom-1.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[calc-offsets-relative-top-1.html]
expected: FAIL