diff --git a/components/style/custom_properties.rs b/components/style/custom_properties.rs index f9d3c77b1c4..d8e8913c41e 100644 --- a/components/style/custom_properties.rs +++ b/components/style/custom_properties.rs @@ -345,6 +345,7 @@ pub fn cascade<'a>(custom_properties: &mut Option { map.remove(&name); } + DeclaredValue::Unset | // Custom properties are inherited by default. DeclaredValue::Inherit => {} // The inherited value is what we already have. } } diff --git a/components/style/properties/helpers.mako.rs b/components/style/properties/helpers.mako.rs index 6225c5b63e6..5efeac958fe 100644 --- a/components/style/properties/helpers.mako.rs +++ b/components/style/properties/helpers.mako.rs @@ -245,6 +245,9 @@ % endif } DeclaredValue::WithVariables { .. } => unreachable!(), + % if not data.current_style_struct.inherited: + DeclaredValue::Unset | + % endif DeclaredValue::Initial => { // We assume that it's faster to use copy_*_from rather than // set_*(get_initial_value()); @@ -253,6 +256,9 @@ context.mutate_style().mutate_${data.current_style_struct.name_lower}() .copy_${property.ident}_from(initial_struct ${maybe_wm}); }, + % if data.current_style_struct.inherited: + DeclaredValue::Unset | + % endif DeclaredValue::Inherit => { // This is a bit slow, but this is rare so it shouldn't // matter. @@ -286,8 +292,7 @@ match input.try(|i| CSSWideKeyword::parse(context, i)) { Ok(CSSWideKeyword::InheritKeyword) => Ok(DeclaredValue::Inherit), Ok(CSSWideKeyword::InitialKeyword) => Ok(DeclaredValue::Initial), - Ok(CSSWideKeyword::UnsetKeyword) => Ok(DeclaredValue::${ - "Inherit" if data.current_style_struct.inherited else "Initial"}), + Ok(CSSWideKeyword::UnsetKeyword) => Ok(DeclaredValue::Unset), Err(()) => { input.look_for_var_functions(); let start = input.position(); @@ -383,6 +388,7 @@ use properties::{longhands, PropertyDeclaration, DeclaredValue, ShorthandId}; use std::fmt; use style_traits::ToCss; + use super::{SerializeFlags, ALL_INHERIT, ALL_INITIAL, ALL_UNSET}; pub struct Longhands { % for sub_property in shorthand.sub_properties: @@ -441,17 +447,16 @@ impl<'a> ToCss for LonghandsToSerialize<'a> { fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - let mut all_inherit = true; - let mut all_initial = true; + let mut all_flags = SerializeFlags::all(); let mut with_variables = false; % for sub_property in shorthand.sub_properties: match *self.${sub_property.ident} { - DeclaredValue::Initial => all_inherit = false, - DeclaredValue::Inherit => all_initial = false, + DeclaredValue::Initial => all_flags &= ALL_INITIAL, + DeclaredValue::Inherit => all_flags &= ALL_INHERIT, + DeclaredValue::Unset => all_flags &= ALL_UNSET, DeclaredValue::WithVariables {..} => with_variables = true, DeclaredValue::Value(..) => { - all_initial = false; - all_inherit = false; + all_flags = SerializeFlags::empty(); } } % endfor @@ -459,10 +464,12 @@ if with_variables { // We don't serialize shorthands with variables dest.write_str("") - } else if all_inherit { + } else if all_flags == ALL_INHERIT { dest.write_str("inherit") - } else if all_initial { + } else if all_flags == ALL_INITIAL { dest.write_str("initial") + } else if all_flags == ALL_UNSET { + dest.write_str("unset") } else { self.to_css_declared(dest) } diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 4929208a7b9..fbd3c611143 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -90,6 +90,14 @@ pub mod shorthands { use parser::{Parse, ParserContext}; use values::specified; + bitflags! { + flags SerializeFlags: u8 { + const ALL_INHERIT = 0b001, + const ALL_INITIAL = 0b010, + const ALL_UNSET = 0b100, + } + } + pub fn parse_four_sides(input: &mut Parser, parse_one: F) -> Result<(T, T, T, T), ()> where F: Fn(&mut Parser) -> Result, T: Clone { @@ -520,9 +528,7 @@ pub enum DeclaredValue { }, Initial, Inherit, - // There is no Unset variant here. - // The 'unset' keyword is represented as either Initial or Inherit, - // depending on whether the property is inherited. + Unset, } impl HasViewportPercentage for DeclaredValue { @@ -533,7 +539,8 @@ impl HasViewportPercentage for DeclaredValue { DeclaredValue::WithVariables { .. } => panic!("DeclaredValue::has_viewport_percentage without resolving variables!"), DeclaredValue::Initial | - DeclaredValue::Inherit => false, + DeclaredValue::Inherit | + DeclaredValue::Unset => false, } } } @@ -549,6 +556,7 @@ impl ToCss for DeclaredValue { DeclaredValue::WithVariables { .. } => Ok(()), DeclaredValue::Initial => dest.write_str("initial"), DeclaredValue::Inherit => dest.write_str("inherit"), + DeclaredValue::Unset => dest.write_str("unset"), } } } @@ -817,7 +825,7 @@ impl PropertyDeclaration { match id { PropertyId::Custom(name) => { let value = match input.try(|i| CSSWideKeyword::parse(context, i)) { - Ok(CSSWideKeyword::UnsetKeyword) | // Custom properties are alawys inherited + Ok(CSSWideKeyword::UnsetKeyword) => DeclaredValue::Unset, Ok(CSSWideKeyword::InheritKeyword) => DeclaredValue::Inherit, Ok(CSSWideKeyword::InitialKeyword) => DeclaredValue::Initial, Err(()) => match ::custom_properties::SpecifiedValue::parse(context, input) { @@ -900,8 +908,7 @@ impl PropertyDeclaration { Ok(CSSWideKeyword::UnsetKeyword) => { % for sub_property in shorthand.sub_properties: result_list.push(PropertyDeclaration::${sub_property.camel_case}( - DeclaredValue::${"Inherit" if sub_property.style_struct.inherited else "Initial"} - )); + DeclaredValue::Unset)); % endfor PropertyDeclarationParseResult::ValidOrIgnoredDeclaration }, diff --git a/components/style/properties/shorthand/border.mako.rs b/components/style/properties/shorthand/border.mako.rs index 05efc2c5303..e324e690c70 100644 --- a/components/style/properties/shorthand/border.mako.rs +++ b/components/style/properties/shorthand/border.mako.rs @@ -40,6 +40,7 @@ ${helpers.four_sides_shorthand("border-style", "border-%s-style", }, &DeclaredValue::Initial => DeclaredValue::Initial, &DeclaredValue::Inherit => DeclaredValue::Inherit, + &DeclaredValue::Unset => DeclaredValue::Unset, }; % endfor diff --git a/components/style/properties/shorthand/box.mako.rs b/components/style/properties/shorthand/box.mako.rs index e991d5787c0..08e27c0bde6 100644 --- a/components/style/properties/shorthand/box.mako.rs +++ b/components/style/properties/shorthand/box.mako.rs @@ -28,6 +28,7 @@ (&DeclaredValue::WithVariables { .. }, &DeclaredValue::WithVariables { .. }) => true, (&DeclaredValue::Initial, &DeclaredValue::Initial) => true, (&DeclaredValue::Inherit, &DeclaredValue::Inherit) => true, + (&DeclaredValue::Unset, &DeclaredValue::Unset) => true, _ => false }; @@ -331,6 +332,7 @@ macro_rules! try_parse_one { }, (&DeclaredValue::Initial, &DeclaredValue::Initial) => true, (&DeclaredValue::Inherit, &DeclaredValue::Inherit) => true, + (&DeclaredValue::Unset, &DeclaredValue::Unset) => true, (x, y) => { *x == *y }, }; diff --git a/tests/wpt/metadata/MANIFEST.json b/tests/wpt/metadata/MANIFEST.json index 54315c84a42..11844dae048 100644 --- a/tests/wpt/metadata/MANIFEST.json +++ b/tests/wpt/metadata/MANIFEST.json @@ -39677,6 +39677,12 @@ "deleted_reftests": {}, "items": { "testharness": { + "css-values/unset-value-storage.html": [ + { + "path": "css-values/unset-value-storage.html", + "url": "/css-values/unset-value-storage.html" + } + ], "cssom/CSSKeyframesRule.html": [ { "path": "cssom/CSSKeyframesRule.html", diff --git a/tests/wpt/web-platform-tests/css-values/unset-value-storage.html b/tests/wpt/web-platform-tests/css-values/unset-value-storage.html new file mode 100644 index 00000000000..9cf13b250d8 --- /dev/null +++ b/tests/wpt/web-platform-tests/css-values/unset-value-storage.html @@ -0,0 +1,23 @@ + + +Storage of "unset" value + + + + + +
+