| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 part of $LIBRARYNAME; | 5 part of $LIBRARYNAME; |
| 6 | 6 |
| 7 $if DART2JS | 7 $if DART2JS |
| 8 $(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS native "@*DOMWindow" { | 8 $(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS native "@*DOMWindow" { |
| 9 $else | 9 $else |
| 10 $(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { | 10 $(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { |
| 11 $endif | 11 $endif |
| 12 | 12 |
| 13 /** | 13 /** |
| 14 * Executes a [callback] after the immediate execution stack has completed. | 14 * Executes a [callback] after the immediate execution stack has completed. |
| 15 * | 15 * |
| 16 * This differs from using Timer.run(callback) | 16 * This differs from using Timer.run(callback) |
| 17 * because Timer will run in about 4-15 milliseconds, depending on browser, | 17 * because Timer will run in about 4-15 milliseconds, depending on browser, |
| 18 * depending on load. [setImmediate], in contrast, makes browser-specific | 18 * depending on load. [setImmediate], in contrast, makes browser-specific |
| 19 * changes in behavior to attempt to run immediately after the current | 19 * changes in behavior to attempt to run immediately after the current |
| 20 * frame unwinds, causing the future to complete after all processing has | 20 * frame unwinds, causing the future to complete after all processing has |
| 21 * completed for the current event, but before any subsequent events. | 21 * completed for the current event, but before any subsequent events. |
| 22 */ | 22 */ |
| 23 void setImmediate(TimeoutHandler callback) { | 23 void setImmediate(TimeoutHandler callback) { |
| 24 _addMicrotaskCallback(callback); | 24 _addMicrotaskCallback(callback); |
| 25 } | 25 } |
| 26 /** | 26 /** |
| 27 * Lookup a port by its [name]. Return null if no port is | 27 * Lookup a port by its [name]. Return null if no port is |
| 28 * registered under [name]. | 28 * registered under [name]. |
| 29 */ | 29 */ |
| 30 SendPortSync lookupPort(String name) { | 30 SendPortSync lookupPort(String name) { |
| 31 var port = | 31 var portStr = document.documentElement.attributes['dart-port:$name']; |
| 32 json.parse(document.documentElement.attributes['dart-port:$name']); | 32 if (portStr == null) { |
| 33 return null; |
| 34 } |
| 35 var port = json.parse(portStr); |
| 33 return _deserialize(port); | 36 return _deserialize(port); |
| 34 } | 37 } |
| 35 | 38 |
| 36 /** | 39 /** |
| 37 * Register a [port] on this window under the given [name]. This | 40 * Register a [port] on this window under the given [name]. This |
| 38 * port may be retrieved by any isolate (or JavaScript script) | 41 * port may be retrieved by any isolate (or JavaScript script) |
| 39 * running in this window. | 42 * running in this window. |
| 40 */ | 43 */ |
| 41 void registerPort(String name, var port) { | 44 void registerPort(String name, var port) { |
| 42 var serialized = _serialize(port); | 45 var serialized = _serialize(port); |
| 43 document.documentElement.attributes['dart-port:$name'] = | 46 document.documentElement.attributes['dart-port:$name'] = |
| 44 json.stringify(serialized); | 47 json.stringify(serialized); |
| 45 } | 48 } |
| 46 | 49 |
| 47 /** | 50 /** |
| 48 * Returns a Future that completes just before the window is about to repaint | 51 * Returns a Future that completes just before the window is about to repaint |
| 49 * so the user can draw an animation frame | 52 * so the user can draw an animation frame |
| 50 * | 53 * |
| 51 * If you need to later cancel this animation, use [requestAnimationFrame] | 54 * If you need to later cancel this animation, use [requestAnimationFrame] |
| 52 * instead. | 55 * instead. |
| 53 * | 56 * |
| 54 * Note: The code that runs when the future completes should call | 57 * Note: The code that runs when the future completes should call |
| 55 * [animationFrame] again for the animation to continue. | 58 * [animationFrame] again for the animation to continue. |
| 56 */ | 59 */ |
| 57 Future<num> get animationFrame { | 60 Future<num> get animationFrame { |
| 58 var completer = new Completer<int>(); | 61 var completer = new Completer<int>(); |
| 59 requestAnimationFrame(completer.complete); | 62 requestAnimationFrame(completer.complete); |
| 60 return completer.future; | 63 return completer.future; |
| 61 } | 64 } |
| 62 | 65 |
| 63 $if DART2JS | 66 $if DART2JS |
| 64 Document get document => JS('Document', '#.document', this); | 67 Document get document => JS('Document', '#.document', this); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 // stub on Object.prototype and throws an exception. | 123 // stub on Object.prototype and throws an exception. |
| 121 try { | 124 try { |
| 122 return thing is Location; | 125 return thing is Location; |
| 123 } catch (e) { | 126 } catch (e) { |
| 124 return false; | 127 return false; |
| 125 } | 128 } |
| 126 } | 129 } |
| 127 | 130 |
| 128 /** | 131 /** |
| 129 * Called to draw an animation frame and then request the window to repaint | 132 * Called to draw an animation frame and then request the window to repaint |
| 130 * after [callback] has finished (creating the animation). | 133 * after [callback] has finished (creating the animation). |
| 131 * | 134 * |
| 132 * Use this method only if you need to later call [cancelAnimationFrame]. If | 135 * Use this method only if you need to later call [cancelAnimationFrame]. If |
| 133 * not, the preferred Dart idiom is to set animation frames by calling | 136 * not, the preferred Dart idiom is to set animation frames by calling |
| 134 * [animationFrame], which returns a Future. | 137 * [animationFrame], which returns a Future. |
| 135 * | 138 * |
| 136 * Returns a non-zero valued integer to represent the request id for this | 139 * Returns a non-zero valued integer to represent the request id for this |
| 137 * request. This value only needs to be saved if you intend to call | 140 * request. This value only needs to be saved if you intend to call |
| 138 * [cancelAnimationFrame] so you can specify the particular animation to | 141 * [cancelAnimationFrame] so you can specify the particular animation to |
| 139 * cancel. | 142 * cancel. |
| 140 * | 143 * |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 static bool get _supportsSetImmediate => false; | 218 static bool get _supportsSetImmediate => false; |
| 216 | 219 |
| 217 /// Dartium stub for IE's setImmediate. | 220 /// Dartium stub for IE's setImmediate. |
| 218 void _setImmediate(void callback()) { | 221 void _setImmediate(void callback()) { |
| 219 throw new UnsupportedError('setImmediate is not supported'); | 222 throw new UnsupportedError('setImmediate is not supported'); |
| 220 } | 223 } |
| 221 $endif | 224 $endif |
| 222 | 225 |
| 223 $!MEMBERS | 226 $!MEMBERS |
| 224 } | 227 } |
| OLD | NEW |