diff --git a/components/style/animation.rs b/components/style/animation.rs index abcef9478a9..8ce3077f2d2 100644 --- a/components/style/animation.rs +++ b/components/style/animation.rs @@ -14,7 +14,7 @@ use keyframes::{KeyframesStep, KeyframesStepValue}; use properties::{self, CascadeFlags, ComputedValues, Importance}; use properties::animated_properties::{AnimatedProperty, TransitionProperty}; use properties::longhands::animation_direction::computed_value::single_value::T as AnimationDirection; -use properties::longhands::animation_iteration_count::computed_value::AnimationIterationCount; +use properties::longhands::animation_iteration_count::single_value::computed_value::T as AnimationIterationCount; use properties::longhands::animation_play_state::computed_value::single_value::T as AnimationPlayState; use properties::longhands::transition_timing_function::single_value::computed_value::StartEnd; use properties::longhands::transition_timing_function::single_value::computed_value::T as TransitionTimingFunction; diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhand/box.mako.rs index 27453cff48c..ea00e0dda72 100644 --- a/components/style/properties/longhand/box.mako.rs +++ b/components/style/properties/longhand/box.mako.rs @@ -831,97 +831,66 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", pub use properties::longhands::transition_timing_function::single_value::SpecifiedValue; -<%helpers:longhand name="animation-iteration-count" - need_index="True" - animatable="False", - spec="https://drafts.csswg.org/css-animations/#propdef-animation-iteration-count", - allowed_in_keyframe_block="False"> +<%helpers:vector_longhand name="animation-iteration-count" + need_index="True" + animatable="False", + spec="https://drafts.csswg.org/css-animations/#propdef-animation-iteration-count", + allowed_in_keyframe_block="False"> + use std::fmt; + use style_traits::ToCss; use values::computed::ComputedValueAsSpecified; use values::NoViewportPercentage; pub mod computed_value { - use parser::{Parse, ParserContext}; - use std::fmt; - use style_traits::ToCss; + pub use super::SpecifiedValue as T; + } - pub use self::AnimationIterationCount as SingleComputedValue; + // https://drafts.csswg.org/css-animations/#animation-iteration-count + #[derive(Debug, Clone, PartialEq)] + #[cfg_attr(feature = "servo", derive(HeapSizeOf))] + pub enum SpecifiedValue { + Number(f32), + Infinite, + } - // https://drafts.csswg.org/css-animations/#animation-iteration-count - #[derive(Debug, Clone, PartialEq)] - #[cfg_attr(feature = "servo", derive(HeapSizeOf))] - pub enum AnimationIterationCount { - Number(f32), - Infinite, - } - - impl Parse for AnimationIterationCount { - fn parse(_context: &ParserContext, input: &mut ::cssparser::Parser) -> Result { - if input.try(|input| input.expect_ident_matching("infinite")).is_ok() { - return Ok(AnimationIterationCount::Infinite) - } - - let number = try!(input.expect_number()); - if number < 0.0 { - return Err(()); - } - - Ok(AnimationIterationCount::Number(number)) + impl Parse for SpecifiedValue { + fn parse(_context: &ParserContext, input: &mut ::cssparser::Parser) -> Result { + if input.try(|input| input.expect_ident_matching("infinite")).is_ok() { + return Ok(SpecifiedValue::Infinite) } - } - impl ToCss for AnimationIterationCount { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - match *self { - AnimationIterationCount::Number(n) => write!(dest, "{}", n), - AnimationIterationCount::Infinite => dest.write_str("infinite"), - } + let number = try!(input.expect_number()); + if number < 0.0 { + return Err(()); } + + Ok(SpecifiedValue::Number(number)) } + } - #[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, value) in self.0.iter().enumerate() { - if i != 0 { - try!(dest.write_str(", ")) - } - try!(value.to_css(dest)) - } - Ok(()) + impl ToCss for SpecifiedValue { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + match *self { + SpecifiedValue::Number(n) => write!(dest, "{}", n), + SpecifiedValue::Infinite => dest.write_str("infinite"), } } } - pub use self::computed_value::AnimationIterationCount; - pub use self::computed_value::AnimationIterationCount as SingleSpecifiedValue; - pub use self::computed_value::T as SpecifiedValue; impl NoViewportPercentage for SpecifiedValue {} #[inline] - pub fn get_initial_single_value() -> AnimationIterationCount { - AnimationIterationCount::Number(1.0) + pub fn get_initial_value() -> computed_value::T { + computed_value::T::Number(1.0) } #[inline] pub fn parse(context: &ParserContext, input: &mut Parser) -> Result { - Ok(SpecifiedValue(try!(input.parse_comma_separated(|i| { - AnimationIterationCount::parse(context, i) - })))) - } - - #[inline] - pub fn get_initial_value() -> computed_value::T { - computed_value::T(vec![get_initial_single_value()]) + SpecifiedValue::parse(context, input) } impl ComputedValueAsSpecified for SpecifiedValue {} - + ${helpers.single_keyword("animation-direction", "normal reverse alternate alternate-reverse", diff --git a/components/style/properties/shorthand/box.mako.rs b/components/style/properties/shorthand/box.mako.rs index c9a9282544d..63f424f8ace 100644 --- a/components/style/properties/shorthand/box.mako.rs +++ b/components/style/properties/shorthand/box.mako.rs @@ -246,7 +246,7 @@ macro_rules! try_parse_one { animation_delay: delay.unwrap_or_else(animation_delay::single_value::get_initial_value), animation_iteration_count: - iteration_count.unwrap_or_else(animation_iteration_count::get_initial_single_value), + iteration_count.unwrap_or_else(animation_iteration_count::single_value::get_initial_value), animation_direction: direction.unwrap_or_else(animation_direction::single_value::get_initial_value), animation_fill_mode: diff --git a/tests/unit/style/parsing/animation.rs b/tests/unit/style/parsing/animation.rs index 69c33b0d43c..ed746790920 100644 --- a/tests/unit/style/parsing/animation.rs +++ b/tests/unit/style/parsing/animation.rs @@ -6,7 +6,7 @@ use cssparser::Parser; use media_queries::CSSErrorReporterTest; use parsing::parse; use style::parser::{Parse, ParserContext}; -use style::properties::longhands::animation_iteration_count::computed_value::AnimationIterationCount; +use style::properties::longhands::animation_iteration_count::single_value::computed_value::T as AnimationIterationCount; use style::stylesheets::Origin; use style_traits::ToCss;