Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(576)

Unified Diff: sky/framework/animation/controller.sky

Issue 886723002: Add sky-drawer to the framework (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: nit Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sky/framework/animation/controller.sky
diff --git a/sky/framework/animation/controller.sky b/sky/framework/animation/controller.sky
new file mode 100644
index 0000000000000000000000000000000000000000..752a3f4070462399f5d3f8d209ec05346cdd30e3
--- /dev/null
+++ b/sky/framework/animation/controller.sky
@@ -0,0 +1,46 @@
+<!--
+// 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="Timer" />
+<script>
+module.exports = class Controller {
esprehn 2015/01/29 19:03:57 AnimationController ? It'll print nicer in the con
abarth-chromium 2015/01/29 19:16:45 Sure!
+ constructor(delegate) {
+ this.delegate_ = delegate;
+ this.timer_ = new Timer(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>

Powered by Google App Engine
This is Rietveld 408576698