| <!-- |
| // Copyright 2015 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| --> |
| <import src="timer.sky" as="AnimationTimer" /> |
| <script> |
| module.exports = class AnimationController { |
| constructor(delegate) { |
| this.delegate_ = delegate; |
| this.timer_ = new AnimationTimer(this); |
| this.begin_ = 0; |
| this.end_ = 0; |
| this.curve_ = null; |
| this.isAnimating = false; |
| Object.preventExtensions(this); |
| } |
| |
| start(options) { |
| this.begin_ = options.begin; |
| this.end_ = options.end; |
| this.curve_ = options.curve; |
| this.isAnimating = true; |
| this.timer_.start(options.duration); |
| } |
| |
| stop() { |
| this.isAnimating = false; |
| this.timer_.stop(); |
| } |
| |
| positionForTime_(t) { |
| // Explicitly finish animations at |this.end_| in case the curve isn't an |
| // exact numerical transform. |
| if (t == 1) |
| return this.end_; |
| var curvedTime = this.curve_.transform(t); |
| var begin = this.begin_; |
| return begin + (this.end_ - begin) * curvedTime; |
| } |
| |
| updateAnimation(t) { |
| this.delegate_.updateAnimation(this.positionForTime_(t)); |
| } |
| }; |
| </script> |