Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor box longhands #14913

Merged
merged 7 commits into from Jan 8, 2017

Convert animation-iteration-count longhand into vector_longhand

  • Loading branch information
canova committed Jan 8, 2017
commit 227737c685565fab580198afd4fedd20ccb48691
@@ -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,97 +831,66 @@ ${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"
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 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 AnimationIterationCount {
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)
}
pub use super::SpecifiedValue as T;
}

let number = try!(input.expect_number());
if number < 0.0 {
return Err(());
}
// 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,
}

Ok(AnimationIterationCount::Number(number))
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(SpecifiedValue::Infinite)
}
}

impl ToCss for AnimationIterationCount {
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"),
}
let number = try!(input.expect_number());
if number < 0.0 {
return Err(());
}
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct T(pub Vec<AnimationIterationCount>);
Ok(SpecifiedValue::Number(number))
}
}

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(())
impl ToCss for SpecifiedValue {
fn to_css<W>(&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<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;

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.