From 818bc6d4a23184b83de9551996d3585d2db33062 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 17 Jun 2016 05:25:50 +0200 Subject: [PATCH] style: parse the remaining animation longhands. --- .../dom/webidls/CSSStyleDeclaration.webidl | 8 +++ components/style/properties/data.py | 2 +- components/style/properties/helpers.mako.rs | 63 ++++++++++++++++++- .../style/properties/longhand/box.mako.rs | 18 ++++++ ports/geckolib/properties.mako.rs | 6 ++ 5 files changed, 94 insertions(+), 3 deletions(-) diff --git a/components/script/dom/webidls/CSSStyleDeclaration.webidl b/components/script/dom/webidls/CSSStyleDeclaration.webidl index 84f9c821aad..8d587b9760a 100644 --- a/components/script/dom/webidls/CSSStyleDeclaration.webidl +++ b/components/script/dom/webidls/CSSStyleDeclaration.webidl @@ -336,4 +336,12 @@ partial interface CSSStyleDeclaration { [SetterThrows, TreatNullAs=EmptyString] attribute DOMString animationTimingFunction; [SetterThrows, TreatNullAs=EmptyString] attribute DOMString animation-iteration-count; [SetterThrows, TreatNullAs=EmptyString] attribute DOMString animationIterationCount; + [SetterThrows, TreatNullAs=EmptyString] attribute DOMString animation-direction; + [SetterThrows, TreatNullAs=EmptyString] attribute DOMString animationDirection; + [SetterThrows, TreatNullAs=EmptyString] attribute DOMString animation-play-state; + [SetterThrows, TreatNullAs=EmptyString] attribute DOMString animationPlayState; + [SetterThrows, TreatNullAs=EmptyString] attribute DOMString animation-fill-mode; + [SetterThrows, TreatNullAs=EmptyString] attribute DOMString animationFillMode; + [SetterThrows, TreatNullAs=EmptyString] attribute DOMString animation-delay; + [SetterThrows, TreatNullAs=EmptyString] attribute DOMString animationDelay; }; diff --git a/components/style/properties/data.py b/components/style/properties/data.py index 0ac35003ff9..4b2cc717407 100644 --- a/components/style/properties/data.py +++ b/components/style/properties/data.py @@ -13,7 +13,7 @@ def to_rust_ident(name): def to_camel_case(ident): - return re.sub("_([a-z])", lambda m: m.group(1).upper(), ident.strip("_").capitalize()) + return re.sub("(^|_|-)([a-z])", lambda m: m.group(2).upper(), ident.strip("_").strip("-")) class Keyword(object): diff --git a/components/style/properties/helpers.mako.rs b/components/style/properties/helpers.mako.rs index 86961c89192..b704ef9784b 100644 --- a/components/style/properties/helpers.mako.rs +++ b/components/style/properties/helpers.mako.rs @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -<%! from data import Keyword, to_rust_ident %> +<%! from data import Keyword, to_rust_ident, to_camel_case %> <%def name="longhand(name, **kwargs)"> <%call expr="raw_longhand(name, **kwargs)"> @@ -181,9 +181,11 @@ % endfor } } - #[inline] pub fn get_initial_value() -> computed_value::T { + #[inline] + pub fn get_initial_value() -> computed_value::T { computed_value::T::${to_rust_ident(values.split()[0])} } + #[inline] pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result { computed_value::T::parse(input) @@ -191,6 +193,63 @@ +<%def name="keyword_list(name, values, **kwargs)"> + <% + keyword_kwargs = {a: kwargs.pop(a, None) for a in [ + 'gecko_constant_prefix', 'extra_gecko_values', 'extra_servo_values' + ]} + %> + <%call expr="longhand(name, keyword=Keyword(name, values, **keyword_kwargs), **kwargs)"> + use values::computed::ComputedValueAsSpecified; + pub use self::computed_value::T as SpecifiedValue; + pub mod computed_value { + use cssparser::ToCss; + use std::fmt; + + #[derive(Debug, Clone, PartialEq, HeapSizeOf)] + pub struct T(pub Vec<${to_camel_case(name)}>); + + impl ToCss for T { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + debug_assert!(!self.0.is_empty(), "Always parses at least one"); + + for (index, item) in self.0.iter().enumerate() { + if index != 0 { + try!(dest.write_str(", ")); + } + + try!(item.to_css(dest)); + } + + Ok(()) + } + } + + define_css_keyword_enum! { ${to_camel_case(name)}: + % for value in data.longhands_by_name[name].keyword.values_for(product): + "${value}" => ${to_rust_ident(value)}, + % endfor + } + } + + #[inline] + pub fn get_initial_value() -> computed_value::T { + computed_value::T(vec![ + computed_value::${to_camel_case(name)}::${to_rust_ident(values.split()[0])} + ]) + } + + #[inline] + pub fn parse(_context: &ParserContext, input: &mut Parser) + -> Result { + Ok(SpecifiedValue(try!( + input.parse_comma_separated(computed_value::${to_camel_case(name)}::parse)))) + } + + impl ComputedValueAsSpecified for SpecifiedValue {} + + + <%def name="shorthand(name, sub_properties, experimental=False, **kwargs)"> <% shorthand = data.declare_shorthand(name, sub_properties.split(), experimental=experimental, diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhand/box.mako.rs index 6786436c0dd..26014ee77b1 100644 --- a/components/style/properties/longhand/box.mako.rs +++ b/components/style/properties/longhand/box.mako.rs @@ -949,6 +949,24 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", need_clone= impl ComputedValueAsSpecified for SpecifiedValue {} +${helpers.keyword_list("animation-direction", + "normal reverse alternate alternate-reverse", + experimental=True)} + +${helpers.keyword_list("animation-play-state", + "running paused", + experimental=True)} + +${helpers.keyword_list("animation-fill-mode", + "none forwards backwards both", + experimental=True)} + +<%helpers:longhand name="animation-delay" experimental="True"> + pub use super::transition_duration::computed_value; + pub use super::transition_duration::{parse, get_initial_value}; + pub use super::transition_duration::SpecifiedValue; + + // CSSOM View Module // https://www.w3.org/TR/cssom-view-1/ ${helpers.single_keyword("scroll-behavior", diff --git a/ports/geckolib/properties.mako.rs b/ports/geckolib/properties.mako.rs index 7a3f79e6748..79b200d0f1b 100644 --- a/ports/geckolib/properties.mako.rs +++ b/ports/geckolib/properties.mako.rs @@ -389,6 +389,12 @@ impl Debug for ${style_struct.gecko_struct_name} { force_stub += ["list-style-type", "text-overflow"] # These are booleans. force_stub += ["page-break-after", "page-break-before"] + # In a nsTArray, have to be done manually, but probably not too much work + # (the "filling them", not the "making them work") + force_stub += ["animation-name", "animation-duration", + "animation-timing-function", "animation-iteration-count", + "animation-direction", "animation-play-state", + "animation-fill-mode", "animation-delay"] # Types used with predefined_type()-defined properties that we can auto-generate. predefined_types = {