diff --git a/components/style/custom_properties.rs b/components/style/custom_properties.rs index 6ed6b6f3288..331d2a74342 100644 --- a/components/style/custom_properties.rs +++ b/components/style/custom_properties.rs @@ -10,7 +10,7 @@ use Atom; use cssparser::{Delimiter, Parser, ParserInput, SourcePosition, Token, TokenSerializationType}; use hash::map::Entry; use precomputed_hash::PrecomputedHash; -use properties::{CSSWideKeyword, DeclaredValue}; +use properties::{CSSWideKeyword, CustomDeclarationValue}; use selector_map::{PrecomputedHashMap, PrecomputedHashSet}; use selectors::parser::SelectorParseErrorKind; use servo_arc::Arc; @@ -519,14 +519,14 @@ impl<'a> CustomPropertiesBuilder<'a> { pub fn cascade( &mut self, name: &'a Name, - specified_value: DeclaredValue<'a, Arc>, + specified_value: &CustomDeclarationValue, ) { let was_already_present = !self.seen.insert(name); if was_already_present { return; } - if !self.value_may_affect_style(name, &specified_value) { + if !self.value_may_affect_style(name, specified_value) { return; } @@ -538,12 +538,12 @@ impl<'a> CustomPropertiesBuilder<'a> { } let map = self.custom_properties.as_mut().unwrap(); - match specified_value { - DeclaredValue::Value(ref specified_value) => { - self.may_have_cycles |= !specified_value.references.is_empty(); - map.insert(name.clone(), (*specified_value).clone()); + match *specified_value { + CustomDeclarationValue::Value(ref unparsed_value) => { + self.may_have_cycles |= !unparsed_value.references.is_empty(); + map.insert(name.clone(), (*unparsed_value).clone()); }, - DeclaredValue::CSSWideKeyword(keyword) => match keyword { + CustomDeclarationValue::CSSWideKeyword(keyword) => match keyword { CSSWideKeyword::Initial => { map.remove(name); }, @@ -556,11 +556,11 @@ impl<'a> CustomPropertiesBuilder<'a> { fn value_may_affect_style( &self, name: &Name, - value: &DeclaredValue>, + value: &CustomDeclarationValue, ) -> bool { match *value { - DeclaredValue::CSSWideKeyword(CSSWideKeyword::Unset) | - DeclaredValue::CSSWideKeyword(CSSWideKeyword::Inherit) => { + CustomDeclarationValue::CSSWideKeyword(CSSWideKeyword::Unset) | + CustomDeclarationValue::CSSWideKeyword(CSSWideKeyword::Inherit) => { // Custom properties are inherited by default. So // explicit 'inherit' or 'unset' means we can just use // any existing value in the inherited CustomPropertiesMap. @@ -576,12 +576,12 @@ impl<'a> CustomPropertiesBuilder<'a> { .or_else(|| self.inherited.and_then(|m| m.get(name))); match (existing_value, value) { - (None, &DeclaredValue::CSSWideKeyword(CSSWideKeyword::Initial)) => { + (None, &CustomDeclarationValue::CSSWideKeyword(CSSWideKeyword::Initial)) => { // The initial value of a custom property is the same as it // not existing in the map. return false; }, - (Some(existing_value), &DeclaredValue::Value(specified_value)) => { + (Some(existing_value), &CustomDeclarationValue::Value(ref specified_value)) => { // Don't bother overwriting an existing inherited value with // the same specified value. if existing_value == specified_value { diff --git a/components/style/properties/cascade.rs b/components/style/properties/cascade.rs index 41e308e3a83..cb8a4ae7c39 100644 --- a/components/style/properties/cascade.rs +++ b/components/style/properties/cascade.rs @@ -246,7 +246,7 @@ where for (declaration, _cascade_level) in iter_declarations() { if let PropertyDeclaration::Custom(ref declaration) = *declaration { - builder.cascade(&declaration.name, declaration.value.borrow()); + builder.cascade(&declaration.name, &declaration.value); } } diff --git a/components/style/properties/declaration_block.rs b/components/style/properties/declaration_block.rs index 56aa2fde4f4..aa8e93bd9c7 100644 --- a/components/style/properties/declaration_block.rs +++ b/components/style/properties/declaration_block.rs @@ -849,7 +849,7 @@ impl PropertyDeclarationBlock { for declaration in self.normal_declaration_iter() { if let PropertyDeclaration::Custom(ref declaration) = *declaration { - builder.cascade(&declaration.name, declaration.value.borrow()); + builder.cascade(&declaration.name, &declaration.value); } } diff --git a/components/style/properties/helpers.mako.rs b/components/style/properties/helpers.mako.rs index c1f4fc9d450..5b04e0dc02e 100644 --- a/components/style/properties/helpers.mako.rs +++ b/components/style/properties/helpers.mako.rs @@ -289,7 +289,7 @@ #[allow(unused_imports)] use properties::longhands; #[allow(unused_imports)] - use properties::{DeclaredValue, LonghandId, LonghandIdSet}; + use properties::{LonghandId, LonghandIdSet}; #[allow(unused_imports)] use properties::{CSSWideKeyword, ComputedValues, PropertyDeclaration}; #[allow(unused_imports)] diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 40d2d52541e..c78bd863438 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -1438,39 +1438,6 @@ impl ShorthandId { } } -/// Servo's representation of a declared value for a given `T`, which is the -/// declared value for that property. -#[derive(Clone, Debug, Eq, PartialEq)] -pub enum DeclaredValue<'a, T: 'a> { - /// A known specified value from the stylesheet. - Value(&'a T), - /// An CSS-wide keyword. - CSSWideKeyword(CSSWideKeyword), -} - -/// A variant of DeclaredValue that owns its data. This separation exists so -/// that PropertyDeclaration can avoid embedding a DeclaredValue (and its -/// extra discriminant word) and synthesize dependent DeclaredValues for -/// PropertyDeclaration instances as needed. -#[cfg_attr(feature = "gecko", derive(MallocSizeOf))] -#[derive(Clone, Debug, Eq, PartialEq, ToCss)] -pub enum DeclaredValueOwned { - /// A known specified value from the stylesheet. - Value(T), - /// An CSS-wide keyword. - CSSWideKeyword(CSSWideKeyword), -} - -impl DeclaredValueOwned { - /// Creates a dependent DeclaredValue from this DeclaredValueOwned. - fn borrow(&self) -> DeclaredValue { - match *self { - DeclaredValueOwned::Value(ref v) => DeclaredValue::Value(v), - DeclaredValueOwned::CSSWideKeyword(v) => DeclaredValue::CSSWideKeyword(v), - } - } -} - /// An unparsed property value that contains `var()` functions. #[derive(Debug, Eq, PartialEq)] pub struct UnparsedValue { @@ -1929,6 +1896,16 @@ pub struct VariableDeclaration { value: Arc, } +/// A custom property declaration value is either an unparsed value or a CSS +/// wide-keyword. +#[derive(Clone, PartialEq, ToCss)] +pub enum CustomDeclarationValue { + /// A value. + Value(Arc<::custom_properties::SpecifiedValue>), + /// A wide keyword. + CSSWideKeyword(CSSWideKeyword), +} + /// A custom property declaration with the property name and the declared value. #[cfg_attr(feature = "gecko", derive(MallocSizeOf))] #[derive(Clone, PartialEq, ToCss)] @@ -1938,7 +1915,7 @@ pub struct CustomDeclaration { pub name: ::custom_properties::Name, /// The value of the custom property. #[cfg_attr(feature = "gecko", ignore_malloc_size_of = "XXX: how to handle this?")] - pub value: DeclaredValueOwned>, + pub value: CustomDeclarationValue, } impl fmt::Debug for PropertyDeclaration { @@ -2120,13 +2097,13 @@ impl PropertyDeclaration { /// This is the case of custom properties and values that contain /// unsubstituted variables. pub fn value_is_unparsed(&self) -> bool { - match *self { - PropertyDeclaration::WithVariables(..) => true, - PropertyDeclaration::Custom(ref declaration) => { - !matches!(declaration.value.borrow(), DeclaredValue::CSSWideKeyword(..)) - } - _ => false, - } + match *self { + PropertyDeclaration::WithVariables(..) => true, + PropertyDeclaration::Custom(ref declaration) => { + matches!(declaration.value, CustomDeclarationValue::Value(..)) + } + _ => false, + } } /// Returns true if this property declaration is for one of the animatable @@ -2171,9 +2148,9 @@ impl PropertyDeclaration { // before adding skip_whitespace here. // This probably affects some test results. let value = match input.try(CSSWideKeyword::parse) { - Ok(keyword) => DeclaredValueOwned::CSSWideKeyword(keyword), + Ok(keyword) => CustomDeclarationValue::CSSWideKeyword(keyword), Err(()) => match ::custom_properties::SpecifiedValue::parse(input) { - Ok(value) => DeclaredValueOwned::Value(value), + Ok(value) => CustomDeclarationValue::Value(value), Err(e) => return Err(StyleParseErrorKind::new_invalid( format!("--{}", property_name), e,