Bug 1326131 - Make AnimationValue::from_declaration return computed CSS variable. r?manishearth draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Wed, 05 Apr 2017 06:39:39 +0900
changeset 555784 8a6713b455e8aba31135ba217a41886c73046e35
parent 555725 b043233ec04f06768d59dcdfb9e928142280f3cc
child 622707 2b4b66061a025b671b368abb38cf9e3e38b34706
push id52348
push userhikezoe@mozilla.com
push dateTue, 04 Apr 2017 21:40:13 +0000
reviewersmanishearth
bugs1326131
milestone55.0a1
Bug 1326131 - Make AnimationValue::from_declaration return computed CSS variable. r?manishearth In Gecko, we resolve CSS variables when we generate keyframes for each animations (i.e. when we create script animations, when we create/update CSS animations). AnimationValue::from_declaration is only called in both cases. MozReview-Commit-ID: 8pAj876JYxL
servo/components/style/properties/helpers/animated_properties.mako.rs
--- a/servo/components/style/properties/helpers/animated_properties.mako.rs
+++ b/servo/components/style/properties/helpers/animated_properties.mako.rs
@@ -296,17 +296,20 @@ impl AnimationValue {
                     }
                 % endif
             % endfor
         }
     }
 
     /// Construct an AnimationValue from a property declaration
     pub fn from_declaration(decl: &PropertyDeclaration, context: &Context, initial: &ComputedValues) -> Option<Self> {
+        use error_reporting::StdoutErrorReporter;
         use properties::LonghandId;
+        use properties::DeclaredValue;
+
         match *decl {
             % for prop in data.longhands:
             % if prop.animatable:
             PropertyDeclaration::${prop.camel_case}(ref val) => {
                 Some(AnimationValue::${prop.camel_case}(val.to_computed_value(context)))
             },
             % endif
             % endfor
@@ -339,20 +342,51 @@ impl AnimationValue {
                     % endif
                     % endfor
                     % for prop in data.longhands:
                     % if not prop.animatable:
                     LonghandId::${prop.camel_case} => None,
                     % endif
                     % endfor
                 }
-            }
-            PropertyDeclaration::WithVariables(_, _) => {
-                // https://bugzilla.mozilla.org/show_bug.cgi?id=1326131
-                unimplemented!()
+            },
+            PropertyDeclaration::WithVariables(id, ref variables) => {
+                let custom_props = context.style().custom_properties();
+                let reporter = StdoutErrorReporter;
+                match id {
+                    % for prop in data.longhands:
+                    % if prop.animatable:
+                    LonghandId::${prop.camel_case} => {
+                        let mut result = None;
+                        ::properties::substitute_variables_${prop.ident}_slow(
+                            &variables.css,
+                            variables.first_token_type,
+                            &variables.url_data,
+                            variables.from_shorthand,
+                            &custom_props,
+                            |v| {
+                                let declaration = match *v {
+                                    DeclaredValue::Value(value) => {
+                                        PropertyDeclaration::${prop.camel_case}(value.clone())
+                                    },
+                                    DeclaredValue::CSSWideKeyword(keyword) => {
+                                        PropertyDeclaration::CSSWideKeyword(id, keyword)
+                                    },
+                                    DeclaredValue::WithVariables(_) => unreachable!(),
+                                };
+                                result = AnimationValue::from_declaration(&declaration, context, initial);
+                            },
+                            &reporter);
+                        result
+                    },
+                    % else:
+                    LonghandId::${prop.camel_case} => None,
+                    % endif
+                    % endfor
+                }
             },
             _ => None // non animatable properties will get included because of shorthands. ignore.
         }
     }
 }
 
 impl Interpolate for AnimationValue {
     fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {