mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Convert animation-iteration-count longhand into vector_longhand
This commit is contained in:
parent
3934f505d6
commit
227737c685
4 changed files with 38 additions and 69 deletions
|
@ -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;
|
||||
|
|
|
@ -831,33 +831,32 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
|
|||
pub use properties::longhands::transition_timing_function::single_value::SpecifiedValue;
|
||||
</%helpers:vector_longhand>
|
||||
|
||||
<%helpers:longhand name="animation-iteration-count"
|
||||
<%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 self::AnimationIterationCount as SingleComputedValue;
|
||||
pub use super::SpecifiedValue as T;
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/css-animations/#animation-iteration-count
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub enum AnimationIterationCount {
|
||||
pub enum SpecifiedValue {
|
||||
Number(f32),
|
||||
Infinite,
|
||||
}
|
||||
|
||||
impl Parse for AnimationIterationCount {
|
||||
impl Parse for SpecifiedValue {
|
||||
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)
|
||||
return Ok(SpecifiedValue::Infinite)
|
||||
}
|
||||
|
||||
let number = try!(input.expect_number());
|
||||
|
@ -865,63 +864,33 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
|
|||
return Err(());
|
||||
}
|
||||
|
||||
Ok(AnimationIterationCount::Number(number))
|
||||
Ok(SpecifiedValue::Number(number))
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for AnimationIterationCount {
|
||||
impl ToCss for SpecifiedValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
AnimationIterationCount::Number(n) => write!(dest, "{}", n),
|
||||
AnimationIterationCount::Infinite => dest.write_str("infinite"),
|
||||
SpecifiedValue::Number(n) => write!(dest, "{}", n),
|
||||
SpecifiedValue::Infinite => dest.write_str("infinite"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct T(pub Vec<AnimationIterationCount>);
|
||||
|
||||
impl ToCss for T {
|
||||
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 {}
|
||||
|
||||
#[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<SpecifiedValue, ()> {
|
||||
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:longhand>
|
||||
</%helpers:vector_longhand>
|
||||
|
||||
${helpers.single_keyword("animation-direction",
|
||||
"normal reverse alternate alternate-reverse",
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue