| 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; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 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, |
| 29 * this approach yields superior performance to calling setTimeout directly as | 29 * this approach yields superior performance to calling setTimeout directly as |
| 30 * all pieces of the UI will animate at the same time resulting in fewer | 30 * all pieces of the UI will animate at the same time resulting in fewer |
| 31 * layouts. | 31 * layouts. |
| 32 */ | 32 */ |
| 33 // TODO(jacobr): use window.requestAnimationFrame when it is available and | 33 // TODO(jacobr): use window.requestAnimationFrame when it is available and |
| 34 // 60fps for the current browser. | 34 // 60fps for the current browser. |
| 35 class AnimationScheduler { | 35 class AnimationScheduler { |
| 36 static final FRAMES_PER_SECOND = 60; | 36 static final int FRAMES_PER_SECOND = 60; |
| 37 static final MS_PER_FRAME = 1000 ~/ FRAMES_PER_SECOND; | 37 static final int MS_PER_FRAME = 1000 ~/ FRAMES_PER_SECOND; |
| 38 static final USE_INTERVALS = false; | 38 static final bool 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 _webkitAnimationFrameMaybeAvailable = true; |
| 47 | 47 |
| 48 AnimationScheduler() | 48 AnimationScheduler() |
| (...skipping 108 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 _safariHackCss.left = '${offset}px'; | 163 _safariHackCss.left = '${offset}px'; |
| 164 } | 164 } |
| 165 } | 165 } |
| 166 } | 166 } |
| OLD | NEW |