From 0de0f741b62b6cb04e3dfa8fd1cf7e263f145108 Mon Sep 17 00:00:00 2001 From: Oriol Brufau Date: Fri, 19 Sep 2025 22:17:56 +0200 Subject: [PATCH] layout: Ignore insets in Taffy for static and sticky positionings (#39401) Taffy treats static and sticky positionings as relative. So the inset properties shifted the element in the relpos way, which was no good. It's better to just treat them as `auto` instead. Testing: 3 existing tests pass, and adding a new one. Fixes: #39399 Signed-off-by: Oriol Brufau --- .../layout/taffy/stylo_taffy/wrapper.rs | 14 ++++++++++ tests/wpt/meta/MANIFEST.json | 13 +++++++++ ...nment-sticky-positioned-items-002.html.ini | 6 ----- ...nment-sticky-positioned-items-002.html.ini | 6 ----- .../sticky/position-sticky-grid.html.ini | 2 -- .../css/css-position/position-static-001.html | 27 +++++++++++++++++++ 6 files changed, 54 insertions(+), 14 deletions(-) delete mode 100644 tests/wpt/meta/css/css-grid/alignment/grid-column-axis-alignment-sticky-positioned-items-002.html.ini delete mode 100644 tests/wpt/meta/css/css-grid/alignment/grid-row-axis-alignment-sticky-positioned-items-002.html.ini delete mode 100644 tests/wpt/meta/css/css-position/sticky/position-sticky-grid.html.ini create mode 100644 tests/wpt/tests/css/css-position/position-static-001.html diff --git a/components/layout/taffy/stylo_taffy/wrapper.rs b/components/layout/taffy/stylo_taffy/wrapper.rs index 01410c7c074..a0fe4fb6e63 100644 --- a/components/layout/taffy/stylo_taffy/wrapper.rs +++ b/components/layout/taffy/stylo_taffy/wrapper.rs @@ -10,6 +10,7 @@ use style::values::computed::{GridTemplateAreas, LengthPercentage}; use style::values::generics::grid::{TrackListValue, TrackRepeat, TrackSize}; use style::values::specified::position::NamedArea; use style::{Atom, OwnedSlice}; +use taffy::prelude::TaffyAuto; use super::{convert, stylo}; @@ -73,6 +74,19 @@ impl> taffy::CoreStyle for TaffyStyloStyle #[inline] fn inset(&self) -> taffy::Rect { + // Taffy doesn't support static nor sticky positionings, they are treated + // as relative. As a workaround, ignore the insets. + if matches!( + self.style.get_box().position, + stylo::Position::Static | stylo::Position::Sticky + ) { + return taffy::Rect { + left: taffy::LengthPercentageAuto::AUTO, + right: taffy::LengthPercentageAuto::AUTO, + top: taffy::LengthPercentageAuto::AUTO, + bottom: taffy::LengthPercentageAuto::AUTO, + }; + } let position_styles = self.style.get_position(); taffy::Rect { left: convert::inset(&position_styles.left), diff --git a/tests/wpt/meta/MANIFEST.json b/tests/wpt/meta/MANIFEST.json index e65ff27179f..7903ca7500f 100644 --- a/tests/wpt/meta/MANIFEST.json +++ b/tests/wpt/meta/MANIFEST.json @@ -237547,6 +237547,19 @@ {} ] ], + "position-static-001.html": [ + "38647cbb0feb64a50cf176379cbdcd8c4f189812", + [ + null, + [ + [ + "/css/reference/ref-filled-green-200px-square.html", + "==" + ] + ], + {} + ] + ], "replaced-object-backdrop.html": [ "b9d2cb599bd4610aaa9161fbf7fd7f8a35e89b8b", [ diff --git a/tests/wpt/meta/css/css-grid/alignment/grid-column-axis-alignment-sticky-positioned-items-002.html.ini b/tests/wpt/meta/css/css-grid/alignment/grid-column-axis-alignment-sticky-positioned-items-002.html.ini deleted file mode 100644 index 10eb51fdf1f..00000000000 --- a/tests/wpt/meta/css/css-grid/alignment/grid-column-axis-alignment-sticky-positioned-items-002.html.ini +++ /dev/null @@ -1,6 +0,0 @@ -[grid-column-axis-alignment-sticky-positioned-items-002.html] - [.grid 1] - expected: FAIL - - [.grid 2] - expected: FAIL diff --git a/tests/wpt/meta/css/css-grid/alignment/grid-row-axis-alignment-sticky-positioned-items-002.html.ini b/tests/wpt/meta/css/css-grid/alignment/grid-row-axis-alignment-sticky-positioned-items-002.html.ini deleted file mode 100644 index 85e518e5b54..00000000000 --- a/tests/wpt/meta/css/css-grid/alignment/grid-row-axis-alignment-sticky-positioned-items-002.html.ini +++ /dev/null @@ -1,6 +0,0 @@ -[grid-row-axis-alignment-sticky-positioned-items-002.html] - [.grid 1] - expected: FAIL - - [.grid 2] - expected: FAIL diff --git a/tests/wpt/meta/css/css-position/sticky/position-sticky-grid.html.ini b/tests/wpt/meta/css/css-position/sticky/position-sticky-grid.html.ini deleted file mode 100644 index 9a86e2d8c1f..00000000000 --- a/tests/wpt/meta/css/css-position/sticky/position-sticky-grid.html.ini +++ /dev/null @@ -1,2 +0,0 @@ -[position-sticky-grid.html] - expected: FAIL diff --git a/tests/wpt/tests/css/css-position/position-static-001.html b/tests/wpt/tests/css/css-position/position-static-001.html new file mode 100644 index 00000000000..38647cbb0fe --- /dev/null +++ b/tests/wpt/tests/css/css-position/position-static-001.html @@ -0,0 +1,27 @@ + + + + + + + + + +

Test passes if there is a filled green square and no red.

+
+
+