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 <obrufau@igalia.com>
This commit is contained in:
Oriol Brufau 2025-09-19 22:17:56 +02:00 committed by GitHub
parent 994d767ae5
commit 0de0f741b6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 54 additions and 14 deletions

View file

@ -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<T: Deref<Target = ComputedValues>> taffy::CoreStyle for TaffyStyloStyle<T>
#[inline]
fn inset(&self) -> taffy::Rect<taffy::LengthPercentageAuto> {
// 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),