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

Unified Diff: sky/framework/animation/timer.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/timer.sky
diff --git a/sky/framework/animation/timer.sky b/sky/framework/animation/timer.sky
new file mode 100644
index 0000000000000000000000000000000000000000..7346a94ca4931a068abe3ba050b4b5c27b862791
--- /dev/null
+++ b/sky/framework/animation/timer.sky
@@ -0,0 +1,49 @@
+<!--
+// 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.
+-->
+<script>
+module.exports = class Timer {
esprehn 2015/01/29 19:03:57 AnimationTimer, I expected this to do setTimeout f
abarth-chromium 2015/01/29 19:16:45 Good point.
+ constructor(delegate) {
+ this.delegate_ = delegate;
+ this.startTime_ = 0;
+ this.duration_ = 0;
+ this.animationId_ = 0;
+ Object.preventExtensions(this);
+ }
+
+ start(duration) {
+ if (this.animationId_)
+ this.stop();
+ this.duration_ = duration;
+ this.scheduleTick_();
+ }
+
+ stop() {
+ cancelAnimationFrame(this.animationId_);
+ this.startTime_ = 0;
+ this.duration_ = 0;
+ this.animationId_ = 0;
+ }
+
+ scheduleTick_() {
+ if (this.animationId_)
+ throw "Tick already scheduled.";
esprehn 2015/01/29 19:03:57 new Error(...); throwing a string is bad, you don
abarth-chromium 2015/01/29 19:16:45 kk
+ this.animationId_ = requestAnimationFrame(this.tick_.bind(this));
+ }
+
+ tick_(timeStamp) {
+ this.animationId_ = 0;
+ if (!this.startTime_)
+ this.startTime_ = timeStamp;
+ var elapsedTime = timeStamp - this.startTime_;
+ var t = Math.max(0, Math.min(1, elapsedTime / this.duration_));
+ if (t < 1)
+ this.scheduleTick_();
+ else
+ this.stop();
+ this.delegate_.updateAnimation(t);
+ }
+};
+</script>

Powered by Google App Engine
This is Rietveld 408576698