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

Side by Side 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, 10 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 unified diff | Download patch
OLDNEW
(Empty)
1 <!--
2 // Copyright 2015 The Chromium Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 -->
6 <script>
7 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.
8 constructor(delegate) {
9 this.delegate_ = delegate;
10 this.startTime_ = 0;
11 this.duration_ = 0;
12 this.animationId_ = 0;
13 Object.preventExtensions(this);
14 }
15
16 start(duration) {
17 if (this.animationId_)
18 this.stop();
19 this.duration_ = duration;
20 this.scheduleTick_();
21 }
22
23 stop() {
24 cancelAnimationFrame(this.animationId_);
25 this.startTime_ = 0;
26 this.duration_ = 0;
27 this.animationId_ = 0;
28 }
29
30 scheduleTick_() {
31 if (this.animationId_)
32 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
33 this.animationId_ = requestAnimationFrame(this.tick_.bind(this));
34 }
35
36 tick_(timeStamp) {
37 this.animationId_ = 0;
38 if (!this.startTime_)
39 this.startTime_ = timeStamp;
40 var elapsedTime = timeStamp - this.startTime_;
41 var t = Math.max(0, Math.min(1, elapsedTime / this.duration_));
42 if (t < 1)
43 this.scheduleTick_();
44 else
45 this.stop();
46 this.delegate_.updateAnimation(t);
47 }
48 };
49 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698