Auto merge of #16640 - hiikezoe:timing-function, r=xidorn

Use FunctionKeyword for computed_value of timing function

<!-- Please describe your changes on the following line: -->
https://bugzilla.mozilla.org/show_bug.cgi?id=1358330

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #15086

<!-- Either: -->
- [X] These changes do not require tests because mozilla-central has test cases.  There might be some test cases in servo tree.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16640)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-04-28 22:49:26 -05:00 committed by GitHub
commit 93a513c06f
5 changed files with 141 additions and 43 deletions

View file

@ -339,19 +339,24 @@ impl PropertyAnimation {
/// Update the given animation at a given point of progress.
pub fn update(&self, style: &mut ComputedValues, time: f64) {
let progress = match self.timing_function {
let timing_function = match self.timing_function {
TransitionTimingFunction::Keyword(keyword) =>
keyword.to_non_keyword_value(),
other => other,
};
let progress = match timing_function {
TransitionTimingFunction::CubicBezier(p1, p2) => {
// See `WebCore::AnimationBase::solveEpsilon(double)` in WebKit.
let epsilon = 1.0 / (200.0 * (self.duration.seconds() as f64));
Bezier::new(Point2D::new(p1.x as f64, p1.y as f64),
Point2D::new(p2.x as f64, p2.y as f64)).solve(time, epsilon)
}
},
TransitionTimingFunction::Steps(steps, StartEnd::Start) => {
(time * (steps as f64)).ceil() / (steps as f64)
}
},
TransitionTimingFunction::Steps(steps, StartEnd::End) => {
(time * (steps as f64)).floor() / (steps as f64)
}
},
TransitionTimingFunction::Frames(frames) => {
// https://drafts.csswg.org/css-timing/#frames-timing-functions
let mut out = (time * (frames as f64)).floor() / ((frames - 1) as f64);
@ -367,7 +372,10 @@ impl PropertyAnimation {
out = 1.0;
}
out
}
},
TransitionTimingFunction::Keyword(_) => {
panic!("Keyword function should not appear")
},
};
self.property.update(style, progress);