Chromium Code Reviews| 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 $(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS native "@*DOMWindow" { | 8 $(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS native "@*DOMWindow" { |
| 9 $else | |
| 10 $(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { | |
| 11 $endif | |
| 8 | 12 |
| 13 /** | |
| 14 * Returns a Future that will complete when the immediate execution stack has | |
| 15 * completed. | |
| 16 * | |
| 17 * This differs from using Timer(const Duration(milliseconds: 0), callback) | |
|
floitsch
2013/02/13 10:03:07
Timer.run
Emily Fortuna
2013/02/13 20:19:44
Done.
| |
| 18 * because Timer will run in about 4-15 milliseconds, depending on browser, | |
| 19 * depending on load. [immediate], in contrast, performs makes | |
| 20 * browser-specific changes to attempt to run immediately after the current | |
| 21 * frame unwinds, causing the future to complete after all processing has | |
| 22 * completed for the current event, but before any subsequent events. | |
| 23 */ | |
| 24 Future get immediate { | |
|
blois
2013/02/13 03:09:24
Question for Florian-
What is the plan for Future.
floitsch
2013/02/13 10:03:07
Current plan is to have a top-level "defer" in dar
| |
| 25 var completer = new Completer<int>(); | |
| 26 _addMicrotaskCallback(() { completer.complete(); }); | |
| 27 return completer.future; | |
| 28 } | |
| 29 /** | |
| 30 * Lookup a port by its [name]. Return null if no port is | |
| 31 * registered under [name]. | |
| 32 */ | |
| 33 SendPortSync lookupPort(String name) { | |
| 34 var port = | |
| 35 json.parse(document.documentElement.attributes['dart-port:$name']); | |
| 36 return _deserialize(port); | |
| 37 } | |
| 38 | |
| 39 /** | |
| 40 * Register a [port] on this window under the given [name]. This | |
| 41 * port may be retrieved by any isolate (or JavaScript script) | |
| 42 * running in this window. | |
| 43 */ | |
| 44 void registerPort(String name, var port) { | |
| 45 var serialized = _serialize(port); | |
| 46 document.documentElement.attributes['dart-port:$name'] = | |
| 47 json.stringify(serialized); | |
| 48 } | |
| 49 | |
| 50 /** | |
| 51 * Returns a Future that completes just before the window is about to repaint | |
| 52 * so the user can draw an animation frame | |
| 53 * | |
| 54 * If you need to later cancel this animation, use [requestAnimationFrame] | |
| 55 * instead. | |
| 56 * | |
| 57 * Note: The code that runs when the future completes should call | |
| 58 * [animationFrame] again for the animation to continue. | |
| 59 */ | |
| 60 Future<int> get animationFrame { | |
|
blois
2013/02/13 03:09:24
I believe this needs to be num, as it can be fract
Emily Fortuna
2013/02/13 20:19:44
You're right. I was reading the MDN docs, in which
| |
| 61 var completer = new Completer<int>(); | |
| 62 requestAnimationFrame((scheduledTime) {completer.complete(scheduledTime);}); | |
|
floitsch
2013/02/13 10:03:07
requestAnimationFrame(completer.complete);
(unles
Emily Fortuna
2013/02/13 20:19:44
Done.
| |
| 63 return completer.future; | |
| 64 } | |
| 65 | |
| 66 $if DART2JS | |
| 9 Document get document => JS('Document', '#.document', this); | 67 Document get document => JS('Document', '#.document', this); |
| 10 | 68 |
| 11 WindowBase _open2(url, name) => JS('Window', '#.open(#,#)', this, url, name); | 69 WindowBase _open2(url, name) => JS('Window', '#.open(#,#)', this, url, name); |
| 12 | 70 |
| 13 WindowBase _open3(url, name, options) => | 71 WindowBase _open3(url, name, options) => |
| 14 JS('Window', '#.open(#,#,#)', this, url, name, options); | 72 JS('Window', '#.open(#,#,#)', this, url, name, options); |
| 15 | 73 |
| 16 WindowBase open(String url, String name, [String options]) { | 74 WindowBase open(String url, String name, [String options]) { |
| 17 if (options == null) { | 75 if (options == null) { |
| 18 return _DOMWindowCrossFrame._createSafe(_open2(url, name)); | 76 return _DOMWindowCrossFrame._createSafe(_open2(url, name)); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 // On Firefox the code that implements 'is Location' fails to find the patch | 122 // On Firefox the code that implements 'is Location' fails to find the patch |
| 65 // stub on Object.prototype and throws an exception. | 123 // stub on Object.prototype and throws an exception. |
| 66 try { | 124 try { |
| 67 return thing is Location; | 125 return thing is Location; |
| 68 } catch (e) { | 126 } catch (e) { |
| 69 return false; | 127 return false; |
| 70 } | 128 } |
| 71 } | 129 } |
| 72 | 130 |
| 73 /** | 131 /** |
| 74 * Executes a [callback] after the immediate execution stack has completed. | 132 * Called to draw an animation frame and then request the window to repaint |
| 133 * after [callback] has finished (creating the animation). | |
| 75 * | 134 * |
| 76 * This will cause the callback to be executed after all processing has | 135 * Use this method only if you need to later call [cancelAnimationFrame]. If |
| 77 * completed for the current event, but before any subsequent events. | 136 * not, the preferred Dart idiom is to set animation frames by calling |
| 137 * [animationFrame], which returns a Future. | |
| 138 * | |
| 139 * Returns a non-zero valued integer to represent the request id for this | |
| 140 * request. This value only needs to be saved if you intend to call | |
| 141 * [cancelAnimationFrame] so you can specify the particular animation to | |
| 142 * cancel. | |
| 143 * | |
| 144 * Note: The supplied [callback] needs to call [requestAnimationFrame] again | |
| 145 * for the animation to continue. | |
| 78 */ | 146 */ |
| 79 void setImmediate(TimeoutHandler callback) { | |
| 80 _addMicrotaskCallback(callback); | |
| 81 } | |
| 82 | |
| 83 @DomName('DOMWindow.requestAnimationFrame') | 147 @DomName('DOMWindow.requestAnimationFrame') |
| 84 int requestAnimationFrame(RequestAnimationFrameCallback callback) { | 148 int requestAnimationFrame(RequestAnimationFrameCallback callback) { |
| 85 _ensureRequestAnimationFrame(); | 149 _ensureRequestAnimationFrame(); |
| 86 return _requestAnimationFrame(callback); | 150 return _requestAnimationFrame(callback); |
| 87 } | 151 } |
| 88 | 152 |
| 89 void cancelAnimationFrame(id) { | 153 void cancelAnimationFrame(id) { |
| 90 _ensureRequestAnimationFrame(); | 154 _ensureRequestAnimationFrame(); |
| 91 _cancelAnimationFrame(id); | 155 _cancelAnimationFrame(id); |
| 92 } | 156 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 */ | 195 */ |
| 132 @SupportedBrowser(SupportedBrowser.CHROME, '23.0') | 196 @SupportedBrowser(SupportedBrowser.CHROME, '23.0') |
| 133 @SupportedBrowser(SupportedBrowser.FIREFOX, '15.0') | 197 @SupportedBrowser(SupportedBrowser.FIREFOX, '15.0') |
| 134 @SupportedBrowser(SupportedBrowser.IE, '10.0') | 198 @SupportedBrowser(SupportedBrowser.IE, '10.0') |
| 135 @Experimental | 199 @Experimental |
| 136 IdbFactory get indexedDB => | 200 IdbFactory get indexedDB => |
| 137 JS('IdbFactory', | 201 JS('IdbFactory', |
| 138 '#.indexedDB || #.webkitIndexedDB || #.mozIndexedDB', | 202 '#.indexedDB || #.webkitIndexedDB || #.mozIndexedDB', |
| 139 this, this, this); | 203 this, this, this); |
| 140 | 204 |
| 141 /** | |
| 142 * Lookup a port by its [name]. Return null if no port is | |
| 143 * registered under [name]. | |
| 144 */ | |
| 145 SendPortSync lookupPort(String name) { | |
| 146 var port = json.parse(document.documentElement.attributes['dart-port:$name'] ); | |
| 147 return _deserialize(port); | |
| 148 } | |
| 149 | |
| 150 /** | |
| 151 * Register a [port] on this window under the given [name]. This | |
| 152 * port may be retrieved by any isolate (or JavaScript script) | |
| 153 * running in this window. | |
| 154 */ | |
| 155 void registerPort(String name, var port) { | |
| 156 var serialized = _serialize(port); | |
| 157 document.documentElement.attributes['dart-port:$name'] = json.stringify(seri alized); | |
| 158 } | |
| 159 | |
| 160 @DomName('Window.console') | 205 @DomName('Window.console') |
| 161 Console get console => Console.safeConsole; | 206 Console get console => Console.safeConsole; |
| 162 | 207 |
| 163 /// Checks if _setImmediate is supported. | 208 /// Checks if _setImmediate is supported. |
| 164 static bool get _supportsSetImmediate => | 209 static bool get _supportsSetImmediate => |
| 165 JS('bool', '!!(window.setImmediate)'); | 210 JS('bool', '!!(window.setImmediate)'); |
| 166 | 211 |
| 167 // Set immediate implementation for IE | 212 // Set immediate implementation for IE |
| 168 void _setImmediate(void callback()) { | 213 void _setImmediate(void callback()) { |
| 169 JS('void', '#.setImmediate(#)', this, convertDartClosureToJS(callback, 0)); | 214 JS('void', '#.setImmediate(#)', this, convertDartClosureToJS(callback, 0)); |
| 170 } | 215 } |
| 216 $else | |
| 217 /// Checks if _setImmediate is supported. | |
| 218 static bool get _supportsSetImmediate => false; | |
| 219 | |
| 220 /// Dartium stub for IE's setImmediate. | |
| 221 void _setImmediate(void callback()) { | |
| 222 throw new UnsupportedError('setImmediate is not supported'); | |
| 223 } | |
| 224 $endif | |
| 171 | 225 |
| 172 $!MEMBERS | 226 $!MEMBERS |
| 173 } | 227 } |
| OLD | NEW |