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

Side by Side Diff: client/base/AnimationScheduler.dart

Issue 8277005: Make the AnimationController class future compatible, and also change it to (Closed) Base URL: http://dart.googlecode.com/svn/trunk/dart/
Patch Set: Created 9 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 typedef void AnimationCallback(num currentTime); 5 typedef void AnimationCallback(num currentTime);
6 6
7 class CallbackData { 7 class CallbackData {
8 final AnimationCallback callback; 8 final AnimationCallback callback;
9 final num minTime; 9 final num minTime;
10 int id; 10 int id;
(...skipping 25 matching lines...) Expand all
36 static final FRAMES_PER_SECOND = 60; 36 static final FRAMES_PER_SECOND = 60;
37 static final MS_PER_FRAME = 1000 ~/ FRAMES_PER_SECOND; 37 static final MS_PER_FRAME = 1000 ~/ FRAMES_PER_SECOND;
38 static final USE_INTERVALS = false; 38 static final USE_INTERVALS = false;
39 39
40 /** List of callbacks to be executed next animation frame. */ 40 /** List of callbacks to be executed next animation frame. */
41 List<CallbackData> _callbacks; 41 List<CallbackData> _callbacks;
42 int _intervalId; 42 int _intervalId;
43 bool _isMobileSafari = false; 43 bool _isMobileSafari = false;
44 Css _safariHackCss; 44 Css _safariHackCss;
45 int _frameCount = 0; 45 int _frameCount = 0;
46 bool _webkitAnimationFrameMaybeAvailable = true; 46 bool _animationFrameMaybeAvailable = true;
47 47
48 AnimationScheduler() 48 AnimationScheduler()
49 : _callbacks = new List<CallbackData>() { 49 : _callbacks = new List<CallbackData>() {
50 if (_isMobileSafari) { 50 if (_isMobileSafari) {
51 // TODO(jacobr): find a better workaround for the issue that 3d transforms 51 // TODO(jacobr): find a better workaround for the issue that 3d transforms
52 // sometimes don't render on iOS without forcing a layout. 52 // sometimes don't render on iOS without forcing a layout.
53 final element = new Element.tag('div'); 53 final element = new Element.tag('div');
54 document.body.nodes.add(element); 54 document.body.nodes.add(element);
55 _safariHackCss = new Css(element.style); 55 _safariHackCss = new Css(element.style);
56 _safariHackCss.position = 'absolute'; 56 _safariHackCss.position = 'absolute';
(...skipping 29 matching lines...) Expand all
86 _setupInterval(); 86 _setupInterval();
87 } 87 }
88 } 88 }
89 89
90 void _setupInterval() { 90 void _setupInterval() {
91 // Assert that we never schedule multiple frames at once. 91 // Assert that we never schedule multiple frames at once.
92 assert(_intervalId === null); 92 assert(_intervalId === null);
93 if (USE_INTERVALS) { 93 if (USE_INTERVALS) {
94 _intervalId = window.setInterval(_step, MS_PER_FRAME); 94 _intervalId = window.setInterval(_step, MS_PER_FRAME);
95 } else { 95 } else {
96 if (_webkitAnimationFrameMaybeAvailable) { 96 if (_animationFrameMaybeAvailable) {
97 // First try to see if the browser supports the requestAnimationFrame AP I,
98 // and if that check fails, fall back to using WebKit/Mozilla/IE specifi c
99 // versions of the API.
97 try { 100 try {
98 // TODO(jacobr): passing in document should not be required. 101 // TODO(jacobr): passing in document should not be required.
99 _intervalId = window.webkitRequestAnimationFrame( 102 _intervalId = window.requestAnimationFrame(
Jacob 2011/10/17 18:24:57 This approach would cause multiple exceptions to b
100 (int ignored) { _step(); }, document); 103 (int ignored) { _step(); }, document);
101 // TODO(jacobr) fix this odd type error. 104 // TODO(jacobr) fix this odd type error.
102 } catch (var e) { 105 } catch (var e) {
103 _webkitAnimationFrameMaybeAvailable = false; 106 try {
107 _intervalId = window.webkitRequestAnimationFrame(
108 (int ignored) { _step(); }, document);
109 } catch (var e) {
110 try {
Jacob 2011/10/17 18:24:57 at some point, window.mozRequestAnimationFrame mig
111 _intervalId = window.mozRequestAnimationFrame(
112 (int ignored) { _step(); }, document);
113 } catch (e) {
114 try {
115 _intervalId = window.msRequestAnimationFrame(
116 (int ignored) { _step(); }, document);
117 } catch (var e) {
118 _animationFrameMaybeAvailable = false;
119 }
120 }
121 }
104 } 122 }
105 } 123 }
106 if (!_webkitAnimationFrameMaybeAvailable) { 124 if (!_animationFrameMaybeAvailable) {
107 _intervalId = window.setTimeout(() { _step(); }, MS_PER_FRAME); 125 _intervalId = window.setTimeout(() { _step(); }, MS_PER_FRAME);
108 } 126 }
109 } 127 }
110 } 128 }
111 129
112 void _step() { 130 void _step() {
113 if (_callbacks.isEmpty()) { 131 if (_callbacks.isEmpty()) {
114 // Cancel the interval on the first frame where there aren't actually 132 // Cancel the interval on the first frame where there aren't actually
115 // any available callbacks. 133 // any available callbacks.
116 assert(_intervalId != null); 134 assert(_intervalId != null);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 _frameCount++; 175 _frameCount++;
158 if (_isMobileSafari) { 176 if (_isMobileSafari) {
159 // Hack to work around an iOS bug where sometimes animations do not 177 // Hack to work around an iOS bug where sometimes animations do not
160 // render if only webkit transforms were modified. 178 // render if only webkit transforms were modified.
161 // TODO(jacobr): find a cleaner workaround. 179 // TODO(jacobr): find a cleaner workaround.
162 int offset = _frameCount % 2; 180 int offset = _frameCount % 2;
163 _safariHackCss.left = '${offset}px'; 181 _safariHackCss.left = '${offset}px';
164 } 182 }
165 } 183 }
166 } 184 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698