style: Fix style attribute important and revert-layer behavior

By modeling it as a separate layer that behaves somewhat specially.

See https://github.com/w3c/csswg-drafts/issues/6872.

The remaining revert-layer tests that we fail are because either we
don't implement a feature (like @property) or because it's used in
keyframes (where revert is a bit unspecified and we have existing
issues with it).

Differential Revision: https://phabricator.services.mozilla.com/D133373
This commit is contained in:
Emilio Cobos Álvarez 2023-06-06 17:28:49 +02:00 committed by Oriol Brufau
parent 5c0f044d39
commit 50510715a2
5 changed files with 67 additions and 31 deletions

View file

@ -28,9 +28,25 @@ pub struct LayerOrder(u16);
impl LayerOrder {
/// The order of the root layer.
pub const fn root() -> Self {
Self(std::u16::MAX - 1)
}
/// The order of the style attribute layer.
pub const fn style_attribute() -> Self {
Self(std::u16::MAX)
}
/// Returns whether this layer is for the style attribute, which behaves
/// differently in terms of !important, see
/// https://github.com/w3c/csswg-drafts/issues/6872
///
/// (This is a bit silly, mind-you, but it's needed so that revert-layer
/// behaves correctly).
#[inline]
pub fn is_style_attribute_layer(&self) -> bool {
*self == Self::style_attribute()
}
/// The first cascade layer order.
pub const fn first() -> Self {
Self(0)
@ -39,7 +55,7 @@ impl LayerOrder {
/// Increment the cascade layer order.
#[inline]
pub fn inc(&mut self) {
if self.0 != std::u16::MAX {
if self.0 != std::u16::MAX - 1 {
self.0 += 1;
}
}