Convert animation-iteration-count longhand into vector_longhand

This commit is contained in:
Nazım Can Altınova 2017-01-07 22:30:37 +03:00
parent 3934f505d6
commit 227737c685
4 changed files with 38 additions and 69 deletions

View file

@ -14,7 +14,7 @@ use keyframes::{KeyframesStep, KeyframesStepValue};
use properties::{self, CascadeFlags, ComputedValues, Importance}; use properties::{self, CascadeFlags, ComputedValues, Importance};
use properties::animated_properties::{AnimatedProperty, TransitionProperty}; use properties::animated_properties::{AnimatedProperty, TransitionProperty};
use properties::longhands::animation_direction::computed_value::single_value::T as AnimationDirection; 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::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::StartEnd;
use properties::longhands::transition_timing_function::single_value::computed_value::T as TransitionTimingFunction; use properties::longhands::transition_timing_function::single_value::computed_value::T as TransitionTimingFunction;

View file

@ -831,97 +831,66 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
pub use properties::longhands::transition_timing_function::single_value::SpecifiedValue; pub use properties::longhands::transition_timing_function::single_value::SpecifiedValue;
</%helpers:vector_longhand> </%helpers:vector_longhand>
<%helpers:longhand name="animation-iteration-count" <%helpers:vector_longhand name="animation-iteration-count"
need_index="True" need_index="True"
animatable="False", animatable="False",
spec="https://drafts.csswg.org/css-animations/#propdef-animation-iteration-count", spec="https://drafts.csswg.org/css-animations/#propdef-animation-iteration-count",
allowed_in_keyframe_block="False"> allowed_in_keyframe_block="False">
use std::fmt;
use style_traits::ToCss;
use values::computed::ComputedValueAsSpecified; use values::computed::ComputedValueAsSpecified;
use values::NoViewportPercentage; use values::NoViewportPercentage;
pub mod computed_value { pub mod computed_value {
use parser::{Parse, ParserContext}; pub use super::SpecifiedValue as T;
use std::fmt; }
use style_traits::ToCss;
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 impl Parse for SpecifiedValue {
#[derive(Debug, Clone, PartialEq)] fn parse(_context: &ParserContext, input: &mut ::cssparser::Parser) -> Result<Self, ()> {
#[cfg_attr(feature = "servo", derive(HeapSizeOf))] if input.try(|input| input.expect_ident_matching("infinite")).is_ok() {
pub enum AnimationIterationCount { return Ok(SpecifiedValue::Infinite)
Number(f32),
Infinite,
}
impl Parse for AnimationIterationCount {
fn parse(_context: &ParserContext, input: &mut ::cssparser::Parser) -> Result<Self, ()> {
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 ToCss for AnimationIterationCount { let number = try!(input.expect_number());
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { if number < 0.0 {
match *self { return Err(());
AnimationIterationCount::Number(n) => write!(dest, "{}", n),
AnimationIterationCount::Infinite => dest.write_str("infinite"),
}
} }
Ok(SpecifiedValue::Number(number))
} }
}
#[derive(Debug, Clone, PartialEq)] impl ToCss for SpecifiedValue {
#[cfg_attr(feature = "servo", derive(HeapSizeOf))] fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
pub struct T(pub Vec<AnimationIterationCount>); match *self {
SpecifiedValue::Number(n) => write!(dest, "{}", n),
impl ToCss for T { SpecifiedValue::Infinite => dest.write_str("infinite"),
fn to_css<W>(&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::AnimationIterationCount as SingleSpecifiedValue;
pub use self::computed_value::T as SpecifiedValue;
impl NoViewportPercentage for SpecifiedValue {} impl NoViewportPercentage for SpecifiedValue {}
#[inline] #[inline]
pub fn get_initial_single_value() -> AnimationIterationCount { pub fn get_initial_value() -> computed_value::T {
AnimationIterationCount::Number(1.0) computed_value::T::Number(1.0)
} }
#[inline] #[inline]
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> { pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
Ok(SpecifiedValue(try!(input.parse_comma_separated(|i| { SpecifiedValue::parse(context, input)
AnimationIterationCount::parse(context, i)
}))))
}
#[inline]
pub fn get_initial_value() -> computed_value::T {
computed_value::T(vec![get_initial_single_value()])
} }
impl ComputedValueAsSpecified for SpecifiedValue {} impl ComputedValueAsSpecified for SpecifiedValue {}
</%helpers:longhand> </%helpers:vector_longhand>
${helpers.single_keyword("animation-direction", ${helpers.single_keyword("animation-direction",
"normal reverse alternate alternate-reverse", "normal reverse alternate alternate-reverse",

View file

@ -246,7 +246,7 @@ macro_rules! try_parse_one {
animation_delay: animation_delay:
delay.unwrap_or_else(animation_delay::single_value::get_initial_value), delay.unwrap_or_else(animation_delay::single_value::get_initial_value),
animation_iteration_count: 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: animation_direction:
direction.unwrap_or_else(animation_direction::single_value::get_initial_value), direction.unwrap_or_else(animation_direction::single_value::get_initial_value),
animation_fill_mode: animation_fill_mode:

View file

@ -6,7 +6,7 @@ use cssparser::Parser;
use media_queries::CSSErrorReporterTest; use media_queries::CSSErrorReporterTest;
use parsing::parse; use parsing::parse;
use style::parser::{Parse, ParserContext}; 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::stylesheets::Origin;
use style_traits::ToCss; use style_traits::ToCss;