Bug 1336668 - Add a tweak to avoid calling interpolate() if animation_type is discrete. r?emilio draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Thu, 06 Apr 2017 20:28:46 +0900
changeset 556973 22f2bc8631446735b2346c707aa3f444c518da9b
parent 556972 20b827b630d3ca5eaea52bc021809bbc8ad64c37
child 556974 56f83d5c55f685571b93deeab2b73332892b529c
push id52642
push userhikezoe@mozilla.com
push dateThu, 06 Apr 2017 11:29:16 +0000
reviewersemilio
bugs1336668
milestone55.0a1
Bug 1336668 - Add a tweak to avoid calling interpolate() if animation_type is discrete. r?emilio For discrete type of animations, we just need to return 'from' value if progress is less than 0.5 and otherwise return 'to' value. https://w3c.github.io/web-animations/#discrete-animation-type MozReview-Commit-ID: JeQY8sHjv0z
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
@@ -228,19 +228,26 @@ impl AnimatedProperty {
 
     /// Update `style` with the proper computed style corresponding to this
     /// animation at `progress`.
     pub fn update(&self, style: &mut ComputedValues, progress: f64) {
         match *self {
             % for prop in data.longhands:
                 % if prop.animatable:
                     AnimatedProperty::${prop.camel_case}(ref from, ref to) => {
-                        if let Ok(value) = from.interpolate(to, progress) {
-                            style.mutate_${prop.style_struct.ident.strip("_")}().set_${prop.ident}(value);
-                        }
+                        // https://w3c.github.io/web-animations/#discrete-animation-type
+                        % if prop.animation_type == "discrete":
+                            let value = if progress < 0.5 { *from } else { *to };
+                        % else:
+                            let value = match from.interpolate(to, progress) {
+                                Ok(value) => value,
+                                Err(()) => return,
+                            };
+                        % endif
+                        style.mutate_${prop.style_struct.ident.strip("_")}().set_${prop.ident}(value);
                     }
                 % endif
             % endfor
         }
     }
 
     /// Get an animatable value from a transition-property, an old style, and a
     /// new style.
@@ -420,17 +427,26 @@ impl AnimationValue {
 
 impl Interpolate for AnimationValue {
     fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
         match (self, other) {
             % for prop in data.longhands:
                 % if prop.animatable:
                     (&AnimationValue::${prop.camel_case}(ref from),
                      &AnimationValue::${prop.camel_case}(ref to)) => {
-                        from.interpolate(to, progress).map(AnimationValue::${prop.camel_case})
+                        // https://w3c.github.io/web-animations/#discrete-animation-type
+                        % if prop.animation_type == "discrete":
+                            if progress < 0.5 {
+                                    Ok(AnimationValue::${prop.camel_case}(*from))
+                            } else {
+                                    Ok(AnimationValue::${prop.camel_case}(*to))
+                            }
+                        % else:
+                            from.interpolate(to, progress).map(AnimationValue::${prop.camel_case})
+                        % endif
                     }
                 % endif
             % endfor
             _ => {
                 panic!("Expected interpolation of computed values of the same \
                         property, got: {:?}, {:?}", self, other);
             }
         }