diff --git a/components/style/custom_properties.rs b/components/style/custom_properties.rs index fcd319a290c..9edeb7a04e3 100644 --- a/components/style/custom_properties.rs +++ b/components/style/custom_properties.rs @@ -361,7 +361,7 @@ pub fn cascade<'a>(custom_properties: &mut Option unreachable!(), + DeclaredValue::WithVariables(_) => unreachable!(), DeclaredValue::Initial => { map.remove(&name); } diff --git a/components/style/properties/helpers.mako.rs b/components/style/properties/helpers.mako.rs index fa6ccbd862b..30c6873a8a2 100644 --- a/components/style/properties/helpers.mako.rs +++ b/components/style/properties/helpers.mako.rs @@ -196,7 +196,7 @@ % if not property.derived_from: use cssparser::Parser; use parser::{Parse, ParserContext, ParserContextExtraData}; - use properties::{CSSWideKeyword, DeclaredValue, ShorthandId}; + use properties::{CSSWideKeyword, DeclaredValue, UnparsedValue, ShorthandId}; % endif use values::{Auto, Either, None_, Normal}; use cascade_info::CascadeInfo; @@ -259,7 +259,7 @@ .set_${property.ident}(computed ${maybe_wm}); % endif } - DeclaredValue::WithVariables { .. } => unreachable!(), + DeclaredValue::WithVariables(_) => unreachable!(), % if not data.current_style_struct.inherited: DeclaredValue::Unset | % endif @@ -324,12 +324,12 @@ input.reset(start); let (first_token_type, css) = try!( ::custom_properties::parse_non_custom_with_var(input)); - return Ok(DeclaredValue::WithVariables { + return Ok(DeclaredValue::WithVariables(Box::new(UnparsedValue { css: css.into_owned(), first_token_type: first_token_type, base_url: context.base_url.clone(), from_shorthand: None, - }) + }))) } specified } @@ -421,7 +421,8 @@ #[allow(unused_imports)] use cssparser::Parser; use parser::ParserContext; - use properties::{longhands, PropertyDeclaration, DeclaredValue, ShorthandId}; + use properties::{DeclaredValue, PropertyDeclaration, UnparsedValue}; + use properties::{ShorthandId, longhands}; use properties::declaration_block::Importance; use std::fmt; use style_traits::ToCss; @@ -504,7 +505,7 @@ DeclaredValue::Initial => all_flags &= ALL_INITIAL, DeclaredValue::Inherit => all_flags &= ALL_INHERIT, DeclaredValue::Unset => all_flags &= ALL_UNSET, - DeclaredValue::WithVariables {..} => with_variables = true, + DeclaredValue::WithVariables(_) => with_variables = true, DeclaredValue::Value(..) => { all_flags = SerializeFlags::empty(); } @@ -560,12 +561,12 @@ ::custom_properties::parse_non_custom_with_var(input)); % for sub_property in shorthand.sub_properties: declarations.push((PropertyDeclaration::${sub_property.camel_case}( - DeclaredValue::WithVariables { + DeclaredValue::WithVariables(Box::new(UnparsedValue { css: css.clone().into_owned(), first_token_type: first_token_type, base_url: context.base_url.clone(), from_shorthand: Some(ShorthandId::${shorthand.camel_case}), - } + })) ), Importance::Normal)); % endfor Ok(()) diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs index af0079a7f33..35fb529c851 100644 --- a/components/style/properties/helpers/animated_properties.mako.rs +++ b/components/style/properties/helpers/animated_properties.mako.rs @@ -297,7 +297,7 @@ impl AnimationValue { PropertyDeclaration::${prop.camel_case}(ref val) => { let computed = match *val { // https://bugzilla.mozilla.org/show_bug.cgi?id=1326131 - DeclaredValue::WithVariables{..} => unimplemented!(), + DeclaredValue::WithVariables(_) => unimplemented!(), DeclaredValue::Value(ref val) => val.to_computed_value(context), % if not prop.style_struct.inherited: DeclaredValue::Unset | diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 6440deab04b..3f014d3368f 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -260,17 +260,15 @@ mod property_bit_field { where F: FnOnce(&DeclaredValue) % endif { - if let DeclaredValue::WithVariables { - ref css, first_token_type, ref base_url, from_shorthand - } = *value { + if let DeclaredValue::WithVariables(ref with_variables) = *value { // FIXME(heycam): A ParserContextExtraData should be built from data // stored in the WithVariables, in case variable expansion results in // a url() value. let extra_data = ParserContextExtraData::default(); - substitute_variables_${property.ident}_slow(css, - first_token_type, - base_url, - from_shorthand, + substitute_variables_${property.ident}_slow(&with_variables.css, + with_variables.first_token_type, + &with_variables.base_url, + with_variables.from_shorthand, custom_properties, f, error_reporter, @@ -614,17 +612,8 @@ impl ShorthandId { pub enum DeclaredValue { /// A known specified value from the stylesheet. Value(T), - /// A value that contained any css variables. - WithVariables { - /// The css serialization for this value. - css: String, - /// The first token type for this serialization. - first_token_type: TokenSerializationType, - /// The base url. - base_url: ServoUrl, - /// The shorthand this came from. - from_shorthand: Option, - }, + /// An unparsed value that contains `var()` functions. + WithVariables(Box), /// The `initial` keyword. Initial, /// The `inherit` keyword. @@ -633,11 +622,25 @@ pub enum DeclaredValue { Unset, } +/// An unparsed property value that contains `var()` functions. +#[derive(Clone, PartialEq, Eq, Debug)] +#[cfg_attr(feature = "servo", derive(HeapSizeOf))] +pub struct UnparsedValue { + /// The css serialization for this value. + css: String, + /// The first token type for this serialization. + first_token_type: TokenSerializationType, + /// The base url. + base_url: ServoUrl, + /// The shorthand this came from. + from_shorthand: Option, +} + impl HasViewportPercentage for DeclaredValue { fn has_viewport_percentage(&self) -> bool { match *self { DeclaredValue::Value(ref v) => v.has_viewport_percentage(), - DeclaredValue::WithVariables { .. } => { + DeclaredValue::WithVariables(_) => { panic!("DeclaredValue::has_viewport_percentage without \ resolving variables!") }, @@ -654,11 +657,13 @@ impl ToCss for DeclaredValue { { match *self { DeclaredValue::Value(ref inner) => inner.to_css(dest), - DeclaredValue::WithVariables { ref css, from_shorthand: None, .. } => { - dest.write_str(css) - } - // https://drafts.csswg.org/css-variables/#variables-in-shorthands - DeclaredValue::WithVariables { .. } => Ok(()), + DeclaredValue::WithVariables(ref with_variables) => { + // https://drafts.csswg.org/css-variables/#variables-in-shorthands + if with_variables.from_shorthand.is_none() { + dest.write_str(&*with_variables.css)? + } + Ok(()) + }, DeclaredValue::Initial => dest.write_str("initial"), DeclaredValue::Inherit => dest.write_str("inherit"), DeclaredValue::Unset => dest.write_str("unset"), @@ -959,9 +964,12 @@ impl PropertyDeclaration { match *self { % for property in data.longhands: PropertyDeclaration::${property.camel_case}(ref value) => match *value { - DeclaredValue::WithVariables { ref css, from_shorthand: Some(s), .. } - if s == shorthand => { - Some(&**css) + DeclaredValue::WithVariables(ref with_variables) => { + if let Some(s) = with_variables.from_shorthand { + if s == shorthand { + Some(&*with_variables.css) + } else { None } + } else { None } } _ => None }, @@ -976,12 +984,12 @@ impl PropertyDeclaration { match *self { % for property in data.longhands: PropertyDeclaration::${property.camel_case}(ref value) => match *value { - DeclaredValue::WithVariables { .. } => true, + DeclaredValue::WithVariables(_) => true, _ => false, }, % endfor PropertyDeclaration::Custom(_, ref value) => match *value { - DeclaredValue::WithVariables { .. } => true, + DeclaredValue::WithVariables(_) => true, _ => false, } } @@ -997,7 +1005,7 @@ impl PropertyDeclaration { match *self { % for property in data.longhands: PropertyDeclaration::${property.camel_case}(ref value) => { - matches!(*value, DeclaredValue::WithVariables { .. }) + matches!(*value, DeclaredValue::WithVariables(_)) }, % endfor PropertyDeclaration::Custom(..) => true diff --git a/components/style/properties/shorthand/box.mako.rs b/components/style/properties/shorthand/box.mako.rs index 207aefc6c5c..f28e3b0371c 100644 --- a/components/style/properties/shorthand/box.mako.rs +++ b/components/style/properties/shorthand/box.mako.rs @@ -22,7 +22,7 @@ (&DeclaredValue::Value(ref x_value), &DeclaredValue::Value(ref y_container)) => { *x_value == y_container.0 }, - (&DeclaredValue::WithVariables { .. }, &DeclaredValue::WithVariables { .. }) => true, + (&DeclaredValue::WithVariables(_), &DeclaredValue::WithVariables(_)) => true, (&DeclaredValue::Initial, &DeclaredValue::Initial) => true, (&DeclaredValue::Inherit, &DeclaredValue::Inherit) => true, (&DeclaredValue::Unset, &DeclaredValue::Unset) => true, @@ -43,8 +43,8 @@ (&DeclaredValue::Value(ref x_value), &DeclaredValue::Value(ref y_container)) => { *x_value == y_container.0 }, - (_, &DeclaredValue::WithVariables { .. }) | - (&DeclaredValue::WithVariables { .. }, _) => { + (_, &DeclaredValue::WithVariables(_)) | + (&DeclaredValue::WithVariables(_), _) => { // We don't serialize shorthands with variables return dest.write_str(""); }, diff --git a/tests/unit/style/size_of.rs b/tests/unit/style/size_of.rs index 86f43fa7b51..fb001763be4 100644 --- a/tests/unit/style/size_of.rs +++ b/tests/unit/style/size_of.rs @@ -7,7 +7,7 @@ use style::properties::{PropertyDeclaration, specified_value_sizes}; #[test] fn size_of_property_declaration() { - let old = 72; + let old = 48; let new = size_of::(); if new < old { panic!("Your changes have decreased the stack size of PropertyDeclaration enum from {} to {}. \