style: Remove DeclaredValue.

I think it used to be the case that all PropertyDeclaration variants had a
DeclaredValueOwned<T> inside. But that's no longer the case, so this abstraction
seems less useful now.

Differential Revision: https://phabricator.services.mozilla.com/D5978
This commit is contained in:
Emilio Cobos Álvarez 2018-09-17 04:47:02 +00:00
parent 4cd0f492f4
commit 5cafac5d10
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
5 changed files with 36 additions and 59 deletions

View file

@ -10,7 +10,7 @@ use Atom;
use cssparser::{Delimiter, Parser, ParserInput, SourcePosition, Token, TokenSerializationType}; use cssparser::{Delimiter, Parser, ParserInput, SourcePosition, Token, TokenSerializationType};
use hash::map::Entry; use hash::map::Entry;
use precomputed_hash::PrecomputedHash; use precomputed_hash::PrecomputedHash;
use properties::{CSSWideKeyword, DeclaredValue}; use properties::{CSSWideKeyword, CustomDeclarationValue};
use selector_map::{PrecomputedHashMap, PrecomputedHashSet}; use selector_map::{PrecomputedHashMap, PrecomputedHashSet};
use selectors::parser::SelectorParseErrorKind; use selectors::parser::SelectorParseErrorKind;
use servo_arc::Arc; use servo_arc::Arc;
@ -519,14 +519,14 @@ impl<'a> CustomPropertiesBuilder<'a> {
pub fn cascade( pub fn cascade(
&mut self, &mut self,
name: &'a Name, name: &'a Name,
specified_value: DeclaredValue<'a, Arc<SpecifiedValue>>, specified_value: &CustomDeclarationValue,
) { ) {
let was_already_present = !self.seen.insert(name); let was_already_present = !self.seen.insert(name);
if was_already_present { if was_already_present {
return; return;
} }
if !self.value_may_affect_style(name, &specified_value) { if !self.value_may_affect_style(name, specified_value) {
return; return;
} }
@ -538,12 +538,12 @@ impl<'a> CustomPropertiesBuilder<'a> {
} }
let map = self.custom_properties.as_mut().unwrap(); let map = self.custom_properties.as_mut().unwrap();
match specified_value { match *specified_value {
DeclaredValue::Value(ref specified_value) => { CustomDeclarationValue::Value(ref unparsed_value) => {
self.may_have_cycles |= !specified_value.references.is_empty(); self.may_have_cycles |= !unparsed_value.references.is_empty();
map.insert(name.clone(), (*specified_value).clone()); map.insert(name.clone(), (*unparsed_value).clone());
}, },
DeclaredValue::CSSWideKeyword(keyword) => match keyword { CustomDeclarationValue::CSSWideKeyword(keyword) => match keyword {
CSSWideKeyword::Initial => { CSSWideKeyword::Initial => {
map.remove(name); map.remove(name);
}, },
@ -556,11 +556,11 @@ impl<'a> CustomPropertiesBuilder<'a> {
fn value_may_affect_style( fn value_may_affect_style(
&self, &self,
name: &Name, name: &Name,
value: &DeclaredValue<Arc<SpecifiedValue>>, value: &CustomDeclarationValue,
) -> bool { ) -> bool {
match *value { match *value {
DeclaredValue::CSSWideKeyword(CSSWideKeyword::Unset) | CustomDeclarationValue::CSSWideKeyword(CSSWideKeyword::Unset) |
DeclaredValue::CSSWideKeyword(CSSWideKeyword::Inherit) => { CustomDeclarationValue::CSSWideKeyword(CSSWideKeyword::Inherit) => {
// Custom properties are inherited by default. So // Custom properties are inherited by default. So
// explicit 'inherit' or 'unset' means we can just use // explicit 'inherit' or 'unset' means we can just use
// any existing value in the inherited CustomPropertiesMap. // 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))); .or_else(|| self.inherited.and_then(|m| m.get(name)));
match (existing_value, value) { 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 // The initial value of a custom property is the same as it
// not existing in the map. // not existing in the map.
return false; 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 // Don't bother overwriting an existing inherited value with
// the same specified value. // the same specified value.
if existing_value == specified_value { if existing_value == specified_value {

View file

@ -246,7 +246,7 @@ where
for (declaration, _cascade_level) in iter_declarations() { for (declaration, _cascade_level) in iter_declarations() {
if let PropertyDeclaration::Custom(ref declaration) = *declaration { if let PropertyDeclaration::Custom(ref declaration) = *declaration {
builder.cascade(&declaration.name, declaration.value.borrow()); builder.cascade(&declaration.name, &declaration.value);
} }
} }

View file

@ -849,7 +849,7 @@ impl PropertyDeclarationBlock {
for declaration in self.normal_declaration_iter() { for declaration in self.normal_declaration_iter() {
if let PropertyDeclaration::Custom(ref declaration) = *declaration { if let PropertyDeclaration::Custom(ref declaration) = *declaration {
builder.cascade(&declaration.name, declaration.value.borrow()); builder.cascade(&declaration.name, &declaration.value);
} }
} }

View file

@ -289,7 +289,7 @@
#[allow(unused_imports)] #[allow(unused_imports)]
use properties::longhands; use properties::longhands;
#[allow(unused_imports)] #[allow(unused_imports)]
use properties::{DeclaredValue, LonghandId, LonghandIdSet}; use properties::{LonghandId, LonghandIdSet};
#[allow(unused_imports)] #[allow(unused_imports)]
use properties::{CSSWideKeyword, ComputedValues, PropertyDeclaration}; use properties::{CSSWideKeyword, ComputedValues, PropertyDeclaration};
#[allow(unused_imports)] #[allow(unused_imports)]

View file

@ -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<T> {
/// A known specified value from the stylesheet.
Value(T),
/// An CSS-wide keyword.
CSSWideKeyword(CSSWideKeyword),
}
impl<T> DeclaredValueOwned<T> {
/// Creates a dependent DeclaredValue from this DeclaredValueOwned.
fn borrow(&self) -> DeclaredValue<T> {
match *self {
DeclaredValueOwned::Value(ref v) => DeclaredValue::Value(v),
DeclaredValueOwned::CSSWideKeyword(v) => DeclaredValue::CSSWideKeyword(v),
}
}
}
/// An unparsed property value that contains `var()` functions. /// An unparsed property value that contains `var()` functions.
#[derive(Debug, Eq, PartialEq)] #[derive(Debug, Eq, PartialEq)]
pub struct UnparsedValue { pub struct UnparsedValue {
@ -1929,6 +1896,16 @@ pub struct VariableDeclaration {
value: Arc<UnparsedValue>, value: Arc<UnparsedValue>,
} }
/// 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. /// A custom property declaration with the property name and the declared value.
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))] #[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
#[derive(Clone, PartialEq, ToCss)] #[derive(Clone, PartialEq, ToCss)]
@ -1938,7 +1915,7 @@ pub struct CustomDeclaration {
pub name: ::custom_properties::Name, pub name: ::custom_properties::Name,
/// The value of the custom property. /// The value of the custom property.
#[cfg_attr(feature = "gecko", ignore_malloc_size_of = "XXX: how to handle this?")] #[cfg_attr(feature = "gecko", ignore_malloc_size_of = "XXX: how to handle this?")]
pub value: DeclaredValueOwned<Arc<::custom_properties::SpecifiedValue>>, pub value: CustomDeclarationValue,
} }
impl fmt::Debug for PropertyDeclaration { impl fmt::Debug for PropertyDeclaration {
@ -2120,13 +2097,13 @@ impl PropertyDeclaration {
/// This is the case of custom properties and values that contain /// This is the case of custom properties and values that contain
/// unsubstituted variables. /// unsubstituted variables.
pub fn value_is_unparsed(&self) -> bool { pub fn value_is_unparsed(&self) -> bool {
match *self { match *self {
PropertyDeclaration::WithVariables(..) => true, PropertyDeclaration::WithVariables(..) => true,
PropertyDeclaration::Custom(ref declaration) => { PropertyDeclaration::Custom(ref declaration) => {
!matches!(declaration.value.borrow(), DeclaredValue::CSSWideKeyword(..)) matches!(declaration.value, CustomDeclarationValue::Value(..))
} }
_ => false, _ => false,
} }
} }
/// Returns true if this property declaration is for one of the animatable /// Returns true if this property declaration is for one of the animatable
@ -2171,9 +2148,9 @@ impl PropertyDeclaration {
// before adding skip_whitespace here. // before adding skip_whitespace here.
// This probably affects some test results. // This probably affects some test results.
let value = match input.try(CSSWideKeyword::parse) { let value = match input.try(CSSWideKeyword::parse) {
Ok(keyword) => DeclaredValueOwned::CSSWideKeyword(keyword), Ok(keyword) => CustomDeclarationValue::CSSWideKeyword(keyword),
Err(()) => match ::custom_properties::SpecifiedValue::parse(input) { Err(()) => match ::custom_properties::SpecifiedValue::parse(input) {
Ok(value) => DeclaredValueOwned::Value(value), Ok(value) => CustomDeclarationValue::Value(value),
Err(e) => return Err(StyleParseErrorKind::new_invalid( Err(e) => return Err(StyleParseErrorKind::new_invalid(
format!("--{}", property_name), format!("--{}", property_name),
e, e,