diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhand/box.mako.rs index 26aab0498b8..0af6c23353b 100644 --- a/components/style/properties/longhand/box.mako.rs +++ b/components/style/properties/longhand/box.mako.rs @@ -1973,3 +1973,67 @@ ${helpers.single_keyword("-moz-orient", gecko_enum_prefix="StyleOrient", spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/-moz-orient)", animatable=False)} + +<%helpers:longhand name="will-change" products="none" animatable="False" + spec="https://drafts.csswg.org/css-will-change/#will-change"> + use cssparser::serialize_identifier; + use std::fmt; + use style_traits::ToCss; + use values::HasViewportPercentage; + use values::computed::ComputedValueAsSpecified; + + impl ComputedValueAsSpecified for SpecifiedValue {} + no_viewport_percentage!(SpecifiedValue); + + pub mod computed_value { + pub use super::SpecifiedValue as T; + } + + #[derive(Debug, Clone, PartialEq)] + #[cfg_attr(feature = "servo", derive(HeapSizeOf))] + pub enum SpecifiedValue { + Auto, + AnimateableFeatures(Vec), + } + + impl ToCss for SpecifiedValue { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + match *self { + SpecifiedValue::Auto => dest.write_str("auto"), + SpecifiedValue::AnimateableFeatures(ref features) => { + let (first, rest) = features.split_first().unwrap(); + // handle head element + serialize_identifier(&*first.to_string(), dest)?; + // handle tail, precede each with a delimiter + for feature in rest { + dest.write_str(", ")?; + serialize_identifier(&*feature.to_string(), dest)?; + } + Ok(()) + } + } + } + } + + #[inline] + pub fn get_initial_value() -> computed_value::T { + computed_value::T::Auto + } + + /// auto | # + pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result { + if input.try(|input| input.expect_ident_matching("auto")).is_ok() { + Ok(computed_value::T::Auto) + } else { + input.parse_comma_separated(|i| { + let ident = i.expect_ident()?; + match_ignore_ascii_case! { &ident, + "will-change" | "none" | "all" | "auto" | + "initial" | "inherit" | "unset" | "default" => return Err(()), + _ => {}, + } + Ok((Atom::from(ident))) + }).map(SpecifiedValue::AnimateableFeatures) + } + } + diff --git a/tests/unit/style/parsing/box_.rs b/tests/unit/style/parsing/box_.rs new file mode 100644 index 00000000000..189e55d75a1 --- /dev/null +++ b/tests/unit/style/parsing/box_.rs @@ -0,0 +1,28 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +use cssparser::Parser; +use media_queries::CSSErrorReporterTest; +use parsing::parse; +use style::parser::ParserContext; +use style::stylesheets::Origin; +use style_traits::ToCss; + +#[test] +fn test_will_change() { + use style::properties::longhands::will_change; + + assert_roundtrip_with_context!(will_change::parse, "auto"); + assert_roundtrip_with_context!(will_change::parse, "scroll-position"); + assert_roundtrip_with_context!(will_change::parse, "contents"); + assert_roundtrip_with_context!(will_change::parse, "transition"); + assert_roundtrip_with_context!(will_change::parse, "opacity, transform"); + + assert!(parse(will_change::parse, "will-change").is_err()); + assert!(parse(will_change::parse, "all").is_err()); + assert!(parse(will_change::parse, "none").is_err()); + assert!(parse(will_change::parse, "contents, auto").is_err()); + assert!(parse(will_change::parse, "contents, inherit, initial").is_err()); + assert!(parse(will_change::parse, "transform scroll-position").is_err()); +} diff --git a/tests/unit/style/parsing/mod.rs b/tests/unit/style/parsing/mod.rs index e4a9ce985a3..cfa7582eeda 100644 --- a/tests/unit/style/parsing/mod.rs +++ b/tests/unit/style/parsing/mod.rs @@ -85,6 +85,7 @@ mod animation; mod background; mod basic_shape; mod border; +mod box_; mod column; mod effects; mod font;