diff --git a/components/style/custom_properties.rs b/components/style/custom_properties.rs index 6d7a198e047..574031453e5 100644 --- a/components/style/custom_properties.rs +++ b/components/style/custom_properties.rs @@ -25,6 +25,7 @@ use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss}; /// /// TODO(emilio): If this becomes a bit more complex we should probably move it /// to the `media_queries` module, or something. +#[derive(Debug, MallocSizeOf)] pub struct CssEnvironment; struct EnvironmentVariable { diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs index 58c727ca416..ba1a6444d42 100644 --- a/components/style/properties/helpers/animated_properties.mako.rs +++ b/components/style/properties/helpers/animated_properties.mako.rs @@ -18,7 +18,7 @@ use num_traits::Zero; use properties::{CSSWideKeyword, PropertyDeclaration}; use properties::longhands; use properties::longhands::visibility::computed_value::T as Visibility; -use properties::{LonghandId, ShorthandId}; +use properties::LonghandId; use servo_arc::Arc; use smallvec::SmallVec; use std::{cmp, ptr}; @@ -50,6 +50,7 @@ use void::{self, Void}; #[allow(non_upper_case_globals)] impl From for TransitionProperty { fn from(property: nsCSSPropertyID) -> TransitionProperty { + use properties::ShorthandId; match property { % for prop in data.longhands: ${prop.nscsspropertyid()} => { diff --git a/components/style/servo/media_queries.rs b/components/style/servo/media_queries.rs index 98b1ec7ae6f..bae0aa3978b 100644 --- a/components/style/servo/media_queries.rs +++ b/components/style/servo/media_queries.rs @@ -6,6 +6,7 @@ use app_units::Au; use cssparser::RGBA; +use custom_properties::CssEnvironment; use euclid::{Size2D, TypedScale, TypedSize2D}; use media_queries::MediaType; use media_queries::media_feature::{AllowsRanges, ParsingRequirements}; @@ -49,6 +50,9 @@ pub struct Device { /// Whether any styles computed in the document relied on the viewport size. #[ignore_malloc_size_of = "Pure stack type"] used_viewport_units: AtomicBool, + /// The CssEnvironment object responsible of getting CSS environment + /// variables. + environment: CssEnvironment, } impl Device { @@ -66,9 +70,16 @@ impl Device { root_font_size: AtomicIsize::new(FontSize::medium().size().0 as isize), used_root_font_size: AtomicBool::new(false), used_viewport_units: AtomicBool::new(false), + environment: CssEnvironment, } } + /// Get the relevant environment to resolve `env()` functions. + #[inline] + pub fn environment(&self) -> &CssEnvironment { + &self.environment + } + /// Return the default computed values for this device. pub fn default_computed_values(&self) -> &ComputedValues { // FIXME(bz): This isn't really right, but it's no more wrong diff --git a/tests/unit/style/custom_properties.rs b/tests/unit/style/custom_properties.rs index dfb0c825627..aeefe6e19b9 100644 --- a/tests/unit/style/custom_properties.rs +++ b/tests/unit/style/custom_properties.rs @@ -4,7 +4,7 @@ use cssparser::{Parser, ParserInput}; use servo_arc::Arc; -use style::custom_properties::{Name, SpecifiedValue, CustomPropertiesMap, CustomPropertiesBuilder}; +use style::custom_properties::{Name, SpecifiedValue, CustomPropertiesMap, CustomPropertiesBuilder, CssEnvironment}; use style::properties::CustomDeclarationValue; use test::{self, Bencher}; @@ -18,7 +18,8 @@ fn cascade( (Name::from(name), SpecifiedValue::parse(&mut parser).unwrap()) }).collect::>(); - let mut builder = CustomPropertiesBuilder::new(inherited); + let env = CssEnvironment; + let mut builder = CustomPropertiesBuilder::new(inherited, &env); for &(ref name, ref val) in &values { builder.cascade(name, &CustomDeclarationValue::Value(val.clone()));