Bug 1278485 - Part 2: ComputedTimingFunction::GetValue ensures 0 or 1 on both edges. r?birtles
MozReview-Commit-ID: ABkcUhhZdbZ
--- 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>