diff --git a/components/script/dom/webidls/CSSStyleDeclaration.webidl b/components/script/dom/webidls/CSSStyleDeclaration.webidl index 62baec54423..84f9c821aad 100644 --- a/components/script/dom/webidls/CSSStyleDeclaration.webidl +++ b/components/script/dom/webidls/CSSStyleDeclaration.webidl @@ -334,4 +334,6 @@ partial interface CSSStyleDeclaration { [SetterThrows, TreatNullAs=EmptyString] attribute DOMString animationDuration; [SetterThrows, TreatNullAs=EmptyString] attribute DOMString animation-timing-function; [SetterThrows, TreatNullAs=EmptyString] attribute DOMString animationTimingFunction; + [SetterThrows, TreatNullAs=EmptyString] attribute DOMString animation-iteration-count; + [SetterThrows, TreatNullAs=EmptyString] attribute DOMString animationIterationCount; }; diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhand/box.mako.rs index 3a61b987eeb..6786436c0dd 100644 --- a/components/style/properties/longhand/box.mako.rs +++ b/components/style/properties/longhand/box.mako.rs @@ -270,6 +270,7 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", need_clone= // TODO(pcwalton): Multiple transitions. <%helpers:longhand name="transition-duration"> + use values::computed::ComputedValueAsSpecified; use values::specified::Time; pub use self::computed_value::T as SpecifiedValue; @@ -286,15 +287,6 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", need_clone= #[cfg_attr(feature = "servo", derive(HeapSizeOf))] pub struct T(pub Vec); - impl ToComputedValue for T { - type ComputedValue = T; - - #[inline] - fn to_computed_value(&self, _: &Cx) -> T { - (*self).clone() - } - } - impl ToCss for T { fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { if self.0.is_empty() { @@ -311,6 +303,8 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", need_clone= } } + impl ComputedValueAsSpecified for SpecifiedValue {} + #[inline] pub fn parse_one(input: &mut Parser) -> Result { Time::parse(input) @@ -886,6 +880,75 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", need_clone= pub use super::transition_timing_function::SpecifiedValue; +<%helpers:longhand name="animation-iteration-count" experimental="True"> + use values::computed::ComputedValueAsSpecified; + + pub mod computed_value { + use cssparser::ToCss; + use std::fmt; + + #[derive(Debug, Clone, PartialEq, HeapSizeOf)] + pub enum AnimationIterationCount { + Number(u32), + 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"), + } + } + } + + #[derive(Debug, Clone, PartialEq, 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(()) + } + } + } + + pub use self::computed_value::AnimationIterationCount; + pub use self::computed_value::T as SpecifiedValue; + + pub fn parse_one(input: &mut Parser) -> Result { + if input.try(|input| input.expect_ident_matching("infinite")).is_ok() { + Ok(AnimationIterationCount::Infinite) + } else { + let number = try!(input.expect_integer()); + if number < 0 { + return Err(()); + } + Ok(AnimationIterationCount::Number(number as u32)) + } + } + + + #[inline] + pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result { + Ok(SpecifiedValue(try!(input.parse_comma_separated(parse_one)))) + } + + pub fn get_initial_value() -> computed_value::T { + computed_value::T(vec![AnimationIterationCount::Number(1)]) + } + + impl ComputedValueAsSpecified for SpecifiedValue {} + + // CSSOM View Module // https://www.w3.org/TR/cssom-view-1/ ${helpers.single_keyword("scroll-behavior",