OLD | NEW |
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; |
11 | 11 |
12 static int _nextId; | 12 static int _nextId; |
13 | 13 |
14 bool ready(num time) => minTime === null || minTime <= time; | 14 bool ready(num time) => minTime == null || minTime <= time; |
15 | 15 |
16 CallbackData(this.callback, this.minTime) { | 16 CallbackData(this.callback, this.minTime) { |
17 // TODO(jacobr): static init needs cleanup, see http://b/4161827 | 17 // TODO(jacobr): static init needs cleanup, see http://b/4161827 |
18 if (_nextId === null) { | 18 if (_nextId == null) { |
19 _nextId = 1; | 19 _nextId = 1; |
20 } | 20 } |
21 id = _nextId++; | 21 id = _nextId++; |
22 } | 22 } |
23 } | 23 } |
24 | 24 |
25 /** | 25 /** |
26 * Animation scheduler implementing the functionality provided by | 26 * Animation scheduler implementing the functionality provided by |
27 * [:window.requestAnimationFrame:] for platforms that do not support it | 27 * [:window.requestAnimationFrame:] for platforms that do not support it |
28 * or support it badly. When multiple UI components are animating at once, | 28 * or support it badly. When multiple UI components are animating at once, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 int requestAnimationFrame(AnimationCallback callback, | 75 int requestAnimationFrame(AnimationCallback callback, |
76 [Element element = null, | 76 [Element element = null, |
77 num minTime = null]) { | 77 num minTime = null]) { |
78 final callbackData = new CallbackData(callback, minTime); | 78 final callbackData = new CallbackData(callback, minTime); |
79 _requestAnimationFrameHelper(callbackData); | 79 _requestAnimationFrameHelper(callbackData); |
80 return callbackData.id; | 80 return callbackData.id; |
81 } | 81 } |
82 | 82 |
83 void _requestAnimationFrameHelper(CallbackData callbackData) { | 83 void _requestAnimationFrameHelper(CallbackData callbackData) { |
84 _callbacks.add(callbackData); | 84 _callbacks.add(callbackData); |
85 if (_intervalId === null) { | 85 if (_intervalId == null) { |
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 (_webkitAnimationFrameMaybeAvailable) { |
97 try { | 97 try { |
98 // TODO(jacobr): passing in document should not be required. | 98 // TODO(jacobr): passing in document should not be required. |
99 _intervalId = window.webkitRequestAnimationFrame( | 99 _intervalId = window.webkitRequestAnimationFrame( |
100 (int ignored) { _step(); }); | 100 (int ignored) { _step(); }); |
101 // TODO(jacobr) fix this odd type error. | 101 // TODO(jacobr) fix this odd type error. |
102 } catch (e) { | 102 } catch (e) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 _frameCount++; | 157 _frameCount++; |
158 if (_isMobileSafari) { | 158 if (_isMobileSafari) { |
159 // Hack to work around an iOS bug where sometimes animations do not | 159 // Hack to work around an iOS bug where sometimes animations do not |
160 // render if only webkit transforms were modified. | 160 // render if only webkit transforms were modified. |
161 // TODO(jacobr): find a cleaner workaround. | 161 // TODO(jacobr): find a cleaner workaround. |
162 int offset = _frameCount % 2; | 162 int offset = _frameCount % 2; |
163 _safariHackStyle.left = '${offset}px'; | 163 _safariHackStyle.left = '${offset}px'; |
164 } | 164 } |
165 } | 165 } |
166 } | 166 } |
OLD | NEW |