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

Side by Side Diff: sky/framework/animation/timer.sky

Issue 942413002: Port sky-drawer to Dart (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: 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
« no previous file with comments | « sky/framework/animation/timer.dart ('k') | sky/framework/sky-drawer.sky » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 AnimationTimer {
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 new Error("Tick already scheduled.");
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
« no previous file with comments | « sky/framework/animation/timer.dart ('k') | sky/framework/sky-drawer.sky » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698