From d972b078228686c9d9f6d906ad6f46d792154a9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 24 Oct 2017 15:56:24 +0200 Subject: [PATCH] style: Move animation-name outside of mako. --- .../style/properties/longhand/box.mako.rs | 83 +++---------------- components/style/values/computed/box.rs | 2 + components/style/values/computed/mod.rs | 2 +- components/style/values/specified/box.rs | 47 ++++++++++- components/style/values/specified/mod.rs | 2 +- 5 files changed, 62 insertions(+), 74 deletions(-) diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhand/box.mako.rs index c73ad963bdc..721a428e064 100644 --- a/components/style/properties/longhand/box.mako.rs +++ b/components/style/properties/longhand/box.mako.rs @@ -444,78 +444,19 @@ ${helpers.predefined_type("transition-delay", extra_prefixes="moz webkit", spec="https://drafts.csswg.org/css-transitions/#propdef-transition-delay")} -<%helpers:vector_longhand name="animation-name" - need_index="True" - animation_value_type="none", - extra_prefixes="moz webkit" - allowed_in_keyframe_block="False" - spec="https://drafts.csswg.org/css-animations/#propdef-animation-name"> - use Atom; - use std::fmt; - use style_traits::ToCss; - use values::KeyframesName; - pub mod computed_value { - pub use super::SpecifiedValue as T; - } - - #[derive(Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToComputedValue)] - pub struct SpecifiedValue(pub Option); - - impl SpecifiedValue { - /// As an Atom - pub fn as_atom(&self) -> Option< &Atom> { - self.0.as_ref().map(|n| n.as_atom()) - } - } - - #[inline] - pub fn get_initial_value() -> computed_value::T { - get_initial_specified_value() - } - - #[inline] - pub fn get_initial_specified_value() -> SpecifiedValue { - SpecifiedValue(None) - } - - impl fmt::Display for SpecifiedValue { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - self.to_css(f) - } - } - - impl ToCss for SpecifiedValue { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - if let Some(ref name) = self.0 { - name.to_css(dest) - } else { - dest.write_str("none") - } - } - } - - impl Parse for SpecifiedValue { - fn parse<'i, 't>( - context: &ParserContext, - input: &mut ::cssparser::Parser<'i, 't> - ) -> Result> { - if let Ok(name) = input.try(|input| KeyframesName::parse(context, input)) { - Ok(SpecifiedValue(Some(name))) - } else { - input.expect_ident_matching("none").map(|_| SpecifiedValue(None)).map_err(|e| e.into()) - } - } - } - - pub fn parse<'i, 't>( - context: &ParserContext, - input: &mut Parser<'i, 't>, - ) -> Result> { - SpecifiedValue::parse(context, input) - } - - +${helpers.predefined_type( + "animation-name", + "AnimationName", + "computed::AnimationName::none()", + initial_specified_value="specified::AnimationName::none()", + vector=True, + need_index=True, + animation_value_type="none", + extra_prefixes="moz webkit", + allowed_in_keyframe_block=False, + spec="https://drafts.csswg.org/css-animations/#propdef-animation-name", +)} ${helpers.predefined_type("animation-duration", "Time", diff --git a/components/style/values/computed/box.rs b/components/style/values/computed/box.rs index 5aee430d266..85534f1813e 100644 --- a/components/style/values/computed/box.rs +++ b/components/style/values/computed/box.rs @@ -9,6 +9,8 @@ use values::computed::length::LengthOrPercentage; use values::generics::box_::AnimationIterationCount as GenericAnimationIterationCount; use values::generics::box_::VerticalAlign as GenericVerticalAlign; +pub use values::specified::box_::AnimationName; + /// A computed value for the `vertical-align` property. pub type VerticalAlign = GenericVerticalAlign; diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index 078cf280ae3..c5bbf3fff27 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -36,7 +36,7 @@ pub use self::angle::Angle; pub use self::background::BackgroundSize; pub use self::border::{BorderImageSlice, BorderImageWidth, BorderImageSideWidth}; pub use self::border::{BorderRadius, BorderCornerRadius, BorderSpacing}; -pub use self::box_::{AnimationIterationCount, VerticalAlign}; +pub use self::box_::{AnimationIterationCount, AnimationName, VerticalAlign}; pub use self::color::{Color, ColorPropertyValue, RGBAColor}; pub use self::effects::{BoxShadow, Filter, SimpleShadow}; pub use self::flex::FlexBasis; diff --git a/components/style/values/specified/box.rs b/components/style/values/specified/box.rs index d7a42865284..4abf55f3878 100644 --- a/components/style/values/specified/box.rs +++ b/components/style/values/specified/box.rs @@ -4,9 +4,12 @@ //! Specified types for box properties. +use Atom; use cssparser::Parser; use parser::{Parse, ParserContext}; -use style_traits::ParseError; +use std::fmt; +use style_traits::{ParseError, ToCss}; +use values::KeyframesName; use values::generics::box_::AnimationIterationCount as GenericAnimationIterationCount; use values::generics::box_::VerticalAlign as GenericVerticalAlign; use values::specified::{AllowQuirks, Number}; @@ -65,3 +68,45 @@ impl AnimationIterationCount { GenericAnimationIterationCount::Number(Number::new(1.0)) } } + +/// A value for the `animation-name` property. +#[derive(Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToComputedValue)] +pub struct AnimationName(pub Option); + +impl AnimationName { + /// Get the name of the animation as an `Atom`. + pub fn as_atom(&self) -> Option<&Atom> { + self.0.as_ref().map(|n| n.as_atom()) + } + + /// Returns the `none` value. + pub fn none() -> Self { + AnimationName(None) + } +} + +impl ToCss for AnimationName { + fn to_css(&self, dest: &mut W) -> fmt::Result + where + W: fmt::Write, + { + match self.0 { + Some(ref name) => name.to_css(dest), + None => dest.write_str("none"), + } + } +} + +impl Parse for AnimationName { + fn parse<'i, 't>( + context: &ParserContext, + input: &mut Parser<'i, 't> + ) -> Result> { + if let Ok(name) = input.try(|input| KeyframesName::parse(context, input)) { + return Ok(AnimationName(Some(name))); + } + + input.expect_ident_matching("none")?; + Ok(AnimationName(None)) + } +} diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index ef79d05e4da..0ddccfe014a 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -30,7 +30,7 @@ pub use self::align::{AlignItems, AlignJustifyContent, AlignJustifySelf, Justify pub use self::background::BackgroundSize; pub use self::border::{BorderCornerRadius, BorderImageSlice, BorderImageWidth}; pub use self::border::{BorderImageSideWidth, BorderRadius, BorderSideWidth, BorderSpacing}; -pub use self::box_::{AnimationIterationCount, VerticalAlign}; +pub use self::box_::{AnimationIterationCount, AnimationName, VerticalAlign}; pub use self::color::{Color, ColorPropertyValue, RGBAColor}; pub use self::effects::{BoxShadow, Filter, SimpleShadow}; pub use self::flex::FlexBasis;