diff --git a/components/style/animation.rs b/components/style/animation.rs index 9c79aaf5a4e..c9fd2ee5e5b 100644 --- a/components/style/animation.rs +++ b/components/style/animation.rs @@ -12,9 +12,9 @@ use euclid::point::Point2D; use keyframes::{KeyframesStep, KeyframesStepValue}; use properties::{self, CascadeFlags, ComputedValues, Importance}; use properties::animated_properties::{AnimatedProperty, TransitionProperty}; -use properties::longhands::animation_direction::computed_value::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_play_state::computed_value::AnimationPlayState; +use properties::longhands::animation_play_state::computed_value::single_value::T as AnimationPlayState; use properties::longhands::transition_timing_function::computed_value::StartEnd; use properties::longhands::transition_timing_function::computed_value::TransitionTimingFunction; use std::sync::Arc; @@ -425,7 +425,7 @@ pub fn maybe_start_animations(context: &SharedStyleContext, continue } - if let Some(ref anim) = context.stylist.animations().get(&name) { + if let Some(ref anim) = context.stylist.animations().get(&name.0) { debug!("maybe_start_animations: animation {} found", name); // If this animation doesn't have any keyframe, we can just continue @@ -461,7 +461,7 @@ pub fn maybe_start_animations(context: &SharedStyleContext, new_animations_sender - .send(Animation::Keyframes(node, name.clone(), KeyframesAnimationState { + .send(Animation::Keyframes(node, name.0.clone(), KeyframesAnimationState { started_at: animation_start, duration: duration as f64, delay: delay as f64, @@ -540,7 +540,7 @@ pub fn update_style_for_animation(context: &SharedStyleContext, let maybe_index = style.get_box() .animation_name_iter() - .position(|animation_name| *name == animation_name); + .position(|animation_name| *name == animation_name.0); let index = match maybe_index { Some(index) => index, diff --git a/components/style/properties/helpers.mako.rs b/components/style/properties/helpers.mako.rs index b4e4d59cbed..ff83fcbf105 100644 --- a/components/style/properties/helpers.mako.rs +++ b/components/style/properties/helpers.mako.rs @@ -53,7 +53,7 @@ <%def name="vector_longhand(name, gecko_only=False, allow_empty=False, **kwargs)"> <%call expr="longhand(name, **kwargs)"> - % if product == "gecko" or not gecko_only: + % if not gecko_only: use std::fmt; use values::HasViewportPercentage; use style_traits::ToCss; @@ -75,6 +75,7 @@ } pub mod computed_value { pub use super::single_value::computed_value as single_value; + pub use self::single_value::T as SingleComputedValue; #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] pub struct T(pub Vec); @@ -123,6 +124,7 @@ Ok(()) } } + pub fn get_initial_value() -> computed_value::T { % if allow_empty: computed_value::T(vec![]) @@ -130,6 +132,7 @@ computed_value::T(vec![single_value::get_initial_value()]) % endif } + pub fn parse(context: &ParserContext, input: &mut Parser) -> Result { % if allow_empty: if input.try(|input| input.expect_ident_matching("none")).is_ok() { @@ -145,6 +148,9 @@ }).map(SpecifiedValue) % endif } + + pub use self::single_value::computed_value::T as SingleSpecifiedValue; + impl ToComputedValue for SpecifiedValue { type ComputedValue = computed_value::T; diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhand/box.mako.rs index 41ab2e5909c..677397a3e64 100644 --- a/components/style/properties/longhand/box.mako.rs +++ b/components/style/properties/longhand/box.mako.rs @@ -350,8 +350,8 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", impl ComputedValueAsSpecified for SpecifiedValue {} #[inline] - pub fn parse_one(input: &mut Parser) -> Result { - Time::parse(input) + pub fn get_initial_single_value() -> Time { + Time(0.0) } #[inline] @@ -359,13 +359,8 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", computed_value::T(vec![get_initial_single_value()]) } - #[inline] - pub fn get_initial_single_value() -> Time { - Time(0.0) - } - pub fn parse(_: &ParserContext, input: &mut Parser) -> Result { - Ok(SpecifiedValue(try!(input.parse_comma_separated(parse_one)))) + Ok(SpecifiedValue(try!(input.parse_comma_separated(Time::parse)))) } @@ -421,8 +416,10 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", pub mod computed_value { use euclid::point::Point2D; + use parser::Parse; use std::fmt; use style_traits::ToCss; + use values::specified; use values::computed::ComputedValueAsSpecified; pub use self::TransitionTimingFunction as SingleComputedValue; @@ -434,6 +431,58 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", Steps(u32, StartEnd), } + impl Parse for TransitionTimingFunction { + fn parse(input: &mut ::cssparser::Parser) -> Result { + if let Ok(function_name) = input.try(|input| input.expect_function()) { + return match_ignore_ascii_case! { function_name, + "cubic-bezier" => { + let (mut p1x, mut p1y, mut p2x, mut p2y) = (0.0, 0.0, 0.0, 0.0); + try!(input.parse_nested_block(|input| { + p1x = try!(specified::parse_number(input)); + try!(input.expect_comma()); + p1y = try!(specified::parse_number(input)); + try!(input.expect_comma()); + p2x = try!(specified::parse_number(input)); + try!(input.expect_comma()); + p2y = try!(specified::parse_number(input)); + Ok(()) + })); + let (p1, p2) = (Point2D::new(p1x, p1y), Point2D::new(p2x, p2y)); + Ok(TransitionTimingFunction::CubicBezier(p1, p2)) + }, + "steps" => { + let (mut step_count, mut start_end) = (0, StartEnd::End); + try!(input.parse_nested_block(|input| { + step_count = try!(specified::parse_integer(input)); + if input.try(|input| input.expect_comma()).is_ok() { + start_end = try!(match_ignore_ascii_case! { + try!(input.expect_ident()), + "start" => Ok(StartEnd::Start), + "end" => Ok(StartEnd::End), + _ => Err(()) + }); + } + Ok(()) + })); + Ok(TransitionTimingFunction::Steps(step_count as u32, start_end)) + }, + _ => Err(()) + } + } + match_ignore_ascii_case! { + try!(input.expect_ident()), + "ease" => Ok(super::ease()), + "linear" => Ok(super::linear()), + "ease-in" => Ok(super::ease_in()), + "ease-out" => Ok(super::ease_out()), + "ease-in-out" => Ok(super::ease_in_out()), + "step-start" => Ok(super::STEP_START), + "step-end" => Ok(super::STEP_END), + _ => Err(()) + } + } + } + impl ToCss for TransitionTimingFunction { fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match *self { @@ -500,68 +549,18 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", impl ComputedValueAsSpecified for SpecifiedValue {} - #[inline] - pub fn get_initial_value() -> computed_value::T { - computed_value::T(vec![get_initial_single_value()]) - } - #[inline] pub fn get_initial_single_value() -> TransitionTimingFunction { ease() } - pub fn parse_one(input: &mut Parser) -> Result { - if let Ok(function_name) = input.try(|input| input.expect_function()) { - return match_ignore_ascii_case! { function_name, - "cubic-bezier" => { - let (mut p1x, mut p1y, mut p2x, mut p2y) = (0.0, 0.0, 0.0, 0.0); - try!(input.parse_nested_block(|input| { - p1x = try!(specified::parse_number(input)); - try!(input.expect_comma()); - p1y = try!(specified::parse_number(input)); - try!(input.expect_comma()); - p2x = try!(specified::parse_number(input)); - try!(input.expect_comma()); - p2y = try!(specified::parse_number(input)); - Ok(()) - })); - let (p1, p2) = (Point2D::new(p1x, p1y), Point2D::new(p2x, p2y)); - Ok(TransitionTimingFunction::CubicBezier(p1, p2)) - }, - "steps" => { - let (mut step_count, mut start_end) = (0, computed_value::StartEnd::End); - try!(input.parse_nested_block(|input| { - step_count = try!(specified::parse_integer(input)); - if input.try(|input| input.expect_comma()).is_ok() { - start_end = try!(match_ignore_ascii_case! { - try!(input.expect_ident()), - "start" => Ok(computed_value::StartEnd::Start), - "end" => Ok(computed_value::StartEnd::End), - _ => Err(()) - }); - } - Ok(()) - })); - Ok(TransitionTimingFunction::Steps(step_count as u32, start_end)) - }, - _ => Err(()) - } - } - match_ignore_ascii_case! { - try!(input.expect_ident()), - "ease" => Ok(ease()), - "linear" => Ok(linear()), - "ease-in" => Ok(ease_in()), - "ease-out" => Ok(ease_out()), - "ease-in-out" => Ok(ease_in_out()), - "step-start" => Ok(STEP_START), - "step-end" => Ok(STEP_END), - _ => Err(()) - } + #[inline] + pub fn get_initial_value() -> computed_value::T { + computed_value::T(vec![get_initial_single_value()]) } pub fn parse(_: &ParserContext, input: &mut Parser) -> Result { - Ok(SpecifiedValue(try!(input.parse_comma_separated(parse_one)))) + Ok(SpecifiedValue(try!(input.parse_comma_separated(TransitionTimingFunction::parse)))) } @@ -607,12 +606,6 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", computed_value::T(Vec::new()) } - - #[inline] - pub fn parse_one(input: &mut Parser) -> Result { - SingleSpecifiedValue::parse(input) - } - pub fn parse(_: &ParserContext, input: &mut Parser) -> Result { Ok(SpecifiedValue(try!(input.parse_comma_separated(SingleSpecifiedValue::parse)))) } @@ -627,9 +620,8 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", need_index="True" animatable="False"> pub use properties::longhands::transition_duration::{SingleSpecifiedValue, SpecifiedValue}; - pub use properties::longhands::transition_duration::{computed_value}; - pub use properties::longhands::transition_duration::{get_initial_single_value}; - pub use properties::longhands::transition_duration::{get_initial_value, parse, parse_one}; + pub use properties::longhands::transition_duration::computed_value; + pub use properties::longhands::transition_duration::{get_initial_value, get_initial_single_value, parse}; <%helpers:longhand name="animation-name" @@ -640,15 +632,38 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", use values::NoViewportPercentage; pub mod computed_value { - use std::fmt; use Atom; + use parser::Parse; + use std::fmt; + use std::ops::Deref; use style_traits::ToCss; - pub use Atom as SingleComputedValue; + #[derive(Clone, Debug, Hash, Eq, PartialEq)] + #[cfg_attr(feature = "servo", derive(HeapSizeOf))] + pub struct AnimationName(pub Atom); + + impl fmt::Display for AnimationName { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.0.fmt(f) + } + } + + pub use self::AnimationName as SingleComputedValue; + + impl Parse for AnimationName { + fn parse(input: &mut ::cssparser::Parser) -> Result { + use cssparser::Token; + Ok(match input.next() { + Ok(Token::Ident(ref value)) if value != "none" => AnimationName(Atom::from(&**value)), + Ok(Token::QuotedString(value)) => AnimationName(Atom::from(&*value)), + _ => return Err(()), + }) + } + } #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] - pub struct T(pub Vec); + pub struct T(pub Vec); impl ToCss for T { fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { @@ -670,18 +685,7 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", pub use self::computed_value::T as SpecifiedValue; impl NoViewportPercentage for SpecifiedValue {} - pub use Atom as SingleSpecifiedValue; - - #[inline] - pub fn parse_one(input: &mut Parser) -> Result { - use cssparser::Token; - - Ok(match input.next() { - Ok(Token::Ident(ref value)) if value != "none" => Atom::from(&**value), - Ok(Token::QuotedString(value)) => Atom::from(&*value), - _ => return Err(()), - }) - } + pub use self::computed_value::SingleComputedValue as SingleSpecifiedValue; #[inline] pub fn get_initial_value() -> computed_value::T { @@ -690,7 +694,7 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", pub fn parse(_: &ParserContext, input: &mut Parser) -> Result { use std::borrow::Cow; - Ok(SpecifiedValue(try!(input.parse_comma_separated(parse_one)))) + Ok(SpecifiedValue(try!(input.parse_comma_separated(SingleSpecifiedValue::parse)))) } impl ComputedValueAsSpecified for SpecifiedValue {} @@ -701,8 +705,7 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", animatable="False", allowed_in_keyframe_block="False"> pub use super::transition_duration::computed_value; - pub use super::transition_duration::{get_initial_value, get_initial_single_value}; - pub use super::transition_duration::{parse, parse_one}; + pub use super::transition_duration::{get_initial_value, get_initial_single_value, parse}; pub use super::transition_duration::SpecifiedValue; pub use super::transition_duration::SingleSpecifiedValue; @@ -712,8 +715,7 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", animatable="False", allowed_in_keyframe_block="False"> pub use super::transition_timing_function::computed_value; - pub use super::transition_timing_function::{get_initial_value, get_initial_single_value}; - pub use super::transition_timing_function::{parse, parse_one}; + pub use super::transition_timing_function::{get_initial_value, get_initial_single_value, parse}; pub use super::transition_timing_function::SpecifiedValue; pub use super::transition_timing_function::SingleSpecifiedValue; @@ -726,6 +728,7 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", use values::NoViewportPercentage; pub mod computed_value { + use parser::Parse; use std::fmt; use style_traits::ToCss; @@ -738,6 +741,21 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", Infinite, } + impl Parse for AnimationIterationCount { + fn parse(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_integer()); + if number < 0 { + return Err(()); + } + + Ok(AnimationIterationCount::Number(number as u32)) + } + } + impl ToCss for AnimationIterationCount { fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match *self { @@ -777,22 +795,9 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", AnimationIterationCount::Number(1) } - 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)))) + Ok(SpecifiedValue(try!(input.parse_comma_separated(AnimationIterationCount::parse)))) } #[inline] @@ -803,34 +808,36 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", impl ComputedValueAsSpecified for SpecifiedValue {} -${helpers.keyword_list("animation-direction", - "normal reverse alternate alternate-reverse", - need_index=True, - animatable=False, - allowed_in_keyframe_block=False)} +${helpers.single_keyword("animation-direction", + "normal reverse alternate alternate-reverse", + need_index=True, + animatable=False, + vector=True, + allowed_in_keyframe_block=False)} // animation-play-state is the exception to the rule for allowed_in_keyframe_block: // https://drafts.csswg.org/css-animations/#keyframes -${helpers.keyword_list("animation-play-state", - "running paused", - need_clone=True, - need_index=True, - animatable=False, - allowed_in_keyframe_block=True)} +${helpers.single_keyword("animation-play-state", + "running paused", + need_clone=True, + need_index=True, + animatable=False, + vector=True, + allowed_in_keyframe_block=True)} -${helpers.keyword_list("animation-fill-mode", - "none forwards backwards both", - need_index=True, - animatable=False, - allowed_in_keyframe_block=False)} +${helpers.single_keyword("animation-fill-mode", + "none forwards backwards both", + need_index=True, + animatable=False, + vector=True, + allowed_in_keyframe_block=False)} <%helpers:longhand name="animation-delay" need_index="True" animatable="False", allowed_in_keyframe_block="False"> pub use super::transition_duration::computed_value; - pub use super::transition_duration::{get_initial_value, get_initial_single_value}; - pub use super::transition_duration::{parse, parse_one}; + pub use super::transition_duration::{get_initial_value, get_initial_single_value, parse}; pub use super::transition_duration::SpecifiedValue; pub use super::transition_duration::SingleSpecifiedValue; diff --git a/components/style/properties/shorthand/box.mako.rs b/components/style/properties/shorthand/box.mako.rs index 2465a91ae8a..87321e69587 100644 --- a/components/style/properties/shorthand/box.mako.rs +++ b/components/style/properties/shorthand/box.mako.rs @@ -53,7 +53,7 @@ macro_rules! try_parse_one { ($input: expr, $var: ident, $prop_module: ident) => { if $var.is_none() { - if let Ok(value) = $input.try($prop_module::parse_one) { + if let Ok(value) = $input.try($prop_module::computed_value::SingleComputedValue::parse) { $var = Some(value); continue; } @@ -65,6 +65,7 @@ macro_rules! try_parse_one { sub_properties="transition-property transition-duration transition-timing-function transition-delay"> + use parser::Parse; use properties::longhands::{transition_delay, transition_duration, transition_property}; use properties::longhands::{transition_timing_function}; @@ -94,8 +95,7 @@ macro_rules! try_parse_one { transition_duration: duration.unwrap_or_else(transition_duration::get_initial_single_value), transition_timing_function: - timing_function.unwrap_or_else( - transition_timing_function::get_initial_single_value), + timing_function.unwrap_or_else(transition_timing_function::get_initial_single_value), transition_delay: delay.unwrap_or_else(transition_delay::get_initial_single_value), }) @@ -154,6 +154,7 @@ macro_rules! try_parse_one { animation-iteration-count animation-direction animation-fill-mode animation-play-state" allowed_in_keyframe_block="False"> + use parser::Parse; use properties::longhands::{animation_name, animation_duration, animation_timing_function}; use properties::longhands::{animation_delay, animation_iteration_count, animation_direction}; use properties::longhands::{animation_fill_mode, animation_play_state}; @@ -210,11 +211,11 @@ macro_rules! try_parse_one { animation_iteration_count: iteration_count.unwrap_or_else(animation_iteration_count::get_initial_single_value), animation_direction: - direction.unwrap_or_else(animation_direction::get_initial_single_value), + direction.unwrap_or_else(animation_direction::single_value::get_initial_value), animation_fill_mode: - fill_mode.unwrap_or_else(animation_fill_mode::get_initial_single_value), + fill_mode.unwrap_or_else(animation_fill_mode::single_value::get_initial_value), animation_play_state: - play_state.unwrap_or_else(animation_play_state::get_initial_single_value), + play_state.unwrap_or_else(animation_play_state::single_value::get_initial_value), }) } else { Err(())