From 3934f505d65cba350a96c21f282e593daf2933f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Naz=C4=B1m=20Can=20Alt=C4=B1nova?= Date: Sat, 7 Jan 2017 22:18:29 +0300 Subject: [PATCH] Convert animation-name longhand into vector_longhand --- .../style/properties/longhand/box.mako.rs | 97 +++++++------------ 1 file changed, 36 insertions(+), 61 deletions(-) diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhand/box.mako.rs index 2741c5e632d..27453cff48c 100644 --- a/components/style/properties/longhand/box.mako.rs +++ b/components/style/properties/longhand/box.mako.rs @@ -757,82 +757,57 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", pub use properties::longhands::transition_duration::single_value::{get_initial_value, parse}; -<%helpers:longhand name="animation-name" - need_index="True" - animatable="False", - allowed_in_keyframe_block="False" - spec="https://drafts.csswg.org/css-animations/#propdef-animation-name"> +<%helpers:vector_longhand name="animation-name" + allow_empty="True" + need_index="True" + animatable="False", + allowed_in_keyframe_block="False" + spec="https://drafts.csswg.org/css-animations/#propdef-animation-name"> + use Atom; + use std::fmt; + use std::ops::Deref; + use style_traits::ToCss; use values::computed::ComputedValueAsSpecified; use values::NoViewportPercentage; pub mod computed_value { - use Atom; - use parser::{Parse, ParserContext}; - use std::fmt; - use std::ops::Deref; - use style_traits::ToCss; + pub use super::SpecifiedValue as T; + } - #[derive(Clone, Debug, Hash, Eq, PartialEq)] - #[cfg_attr(feature = "servo", derive(HeapSizeOf))] - pub struct AnimationName(pub Atom); + #[derive(Clone, Debug, Hash, Eq, PartialEq)] + #[cfg_attr(feature = "servo", derive(HeapSizeOf))] + pub struct SpecifiedValue(pub Atom); - impl fmt::Display for AnimationName { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - self.0.fmt(f) - } - } - - pub use self::AnimationName as SingleComputedValue; - - impl Parse for AnimationName { - fn parse(_context: &ParserContext, input: &mut ::cssparser::Parser) -> Result { - use cssparser::Token; - Ok(match input.next() { - Ok(Token::Ident(ref value)) if value != "none" => AnimationName(Atom::from(&**value)), - Ok(Token::QuotedString(value)) => AnimationName(Atom::from(&*value)), - _ => return Err(()), - }) - } - } - - #[derive(Debug, Clone, PartialEq)] - #[cfg_attr(feature = "servo", derive(HeapSizeOf))] - pub struct T(pub Vec); - - impl ToCss for T { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - if self.0.is_empty() { - return dest.write_str("none") - } - - for (i, name) in self.0.iter().enumerate() { - if i != 0 { - try!(dest.write_str(", ")); - } - // NB: to_string() needed due to geckolib backend. - try!(dest.write_str(&*name.to_string())); - } - Ok(()) - } + impl fmt::Display for SpecifiedValue { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.0.fmt(f) } } - pub use self::computed_value::T as SpecifiedValue; + impl ToCss for SpecifiedValue { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + dest.write_str(&*self.0.to_string()) + } + } + + impl Parse for SpecifiedValue { + fn parse(_context: &ParserContext, input: &mut ::cssparser::Parser) -> Result { + use cssparser::Token; + Ok(match input.next() { + Ok(Token::Ident(ref value)) if value != "none" => SpecifiedValue(Atom::from(&**value)), + Ok(Token::QuotedString(value)) => SpecifiedValue(Atom::from(&*value)), + _ => return Err(()), + }) + } + } impl NoViewportPercentage for SpecifiedValue {} - pub use self::computed_value::SingleComputedValue as SingleSpecifiedValue; - - #[inline] - pub fn get_initial_value() -> computed_value::T { - computed_value::T(vec![]) - } pub fn parse(context: &ParserContext, input: &mut Parser) -> Result { - use std::borrow::Cow; - Ok(SpecifiedValue(try!(input.parse_comma_separated(|i| SingleSpecifiedValue::parse(context, i))))) + SpecifiedValue::parse(context, input) } impl ComputedValueAsSpecified for SpecifiedValue {} - + <%helpers:vector_longhand name="animation-duration" need_index="True"