Bug 1278485 - Part 2: ComputedTimingFunction::GetValue ensures 0 or 1 on both edges. r?birtles draft
authorHiroyuki Ikezoe <hiikezoe@mozilla-japan.org>
Tue, 12 Jul 2016 16:33:45 +0900
changeset 386577 b6d0803523c3768a627ea79da135f5686e347f36
parent 386576 47b1ce3baac443d75d4fc1a0a33c0e7b3d07b0f8
child 386578 d06cf2309cc55b9085ae22741b6213490d3d4b42
push id22748
push userhiikezoe@mozilla-japan.org
push dateTue, 12 Jul 2016 10:30:30 +0000
reviewersbirtles
bugs1278485
milestone50.0a1
Bug 1278485 - Part 2: ComputedTimingFunction::GetValue ensures 0 or 1 on both edges. r?birtles MozReview-Commit-ID: ABkcUhhZdbZ
dom/animation/ComputedTimingFunction.cpp
dom/animation/test/mozilla/file_cubic_bezier_limits.html
--- a/dom/animation/ComputedTimingFunction.cpp
+++ b/dom/animation/ComputedTimingFunction.cpp
@@ -67,16 +67,24 @@ ComputedTimingFunction::GetValue(
     // Check for a linear curve.
     // (GetSplineValue(), below, also checks this but doesn't work when
     // aPortion is outside the range [0.0, 1.0]).
     if (mTimingFunction.X1() == mTimingFunction.Y1() &&
         mTimingFunction.X2() == mTimingFunction.Y2()) {
       return aPortion;
     }
 
+    // Ensure that we return 0 or 1 on both edges.
+    if (aPortion == 0.0) {
+      return 0.0;
+    }
+    if (aPortion == 1.0) {
+      return 1.0;
+    }
+
     // For negative values, try to extrapolate with tangent (p1 - p0) or,
     // if p1 is coincident with p0, with (p2 - p0).
     if (aPortion < 0.0) {
       if (mTimingFunction.X1() > 0.0) {
         return aPortion * mTimingFunction.Y1() / mTimingFunction.X1();
       } else if (mTimingFunction.Y1() == 0 && mTimingFunction.X2() > 0.0) {
         return aPortion * mTimingFunction.Y2() / mTimingFunction.X2();
       }
--- a/dom/animation/test/mozilla/file_cubic_bezier_limits.html
+++ b/dom/animation/test/mozilla/file_cubic_bezier_limits.html
@@ -130,12 +130,38 @@ test(function(t) {
   flushComputedStyle(div);
   div.style.marginLeft = '0px';
   assert_equals(div.getAnimations()[0].effect.getKeyframes()[0].easing,
     'cubic-bezier(0, 0, 0, ' + -max_float + ')',
     'y2 control point for CSS transition on lower boundary');
 
 }, 'Clamp y1 and y2 control point out of boundaries for CSS transition' );
 
+test(function(t) {
+  var div = addDiv(t);
+  var anim = div.animate({ }, { duration: 100 * MS_PER_SEC, fill: 'forwards' });
+
+  anim.pause();
+  // The positive steepest function on both edges.
+  anim.effect.timing.easing = 'cubic-bezier(0, 1e+39, 0, 1e+39)';
+  assert_equals(anim.effect.getComputedTiming().progress, 0.0,
+    'progress on lower edge for the highest value of y1 and y2 control points');
+
+  anim.finish();
+  assert_equals(anim.effect.getComputedTiming().progress, 1.0,
+    'progress on upper edge for the highest value of y1 and y2 control points');
+
+  // The negative steepest function on both edges.
+  anim.effect.timing.easing = 'cubic-bezier(0, -1e+39, 0, -1e+39)';
+  anim.currentTime = 0;
+  assert_equals(anim.effect.getComputedTiming().progress, 0.0,
+    'progress on lower edge for the lowest value of y1 and y2 control points');
+
+  anim.finish();
+  assert_equals(anim.effect.getComputedTiming().progress, 1.0,
+    'progress on lower edge for the lowest value of y1 and y2 control points');
+
+}, 'Calculated values on both edges');
+
 done();
 
 </script>
 </body>