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

Side by Side Diff: tools/dom/templates/html/impl/impl_Window.darttemplate

Issue 12259037: Reapply remove setTimeout, take 3. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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 | « tools/dom/templates/html/dartium/impl_Window.darttemplate ('k') | 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) 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 * Executes a [callback] after the immediate execution stack has completed.
15 *
16 * This differs from using Timer.run(callback)
17 * because Timer will run in about 4-15 milliseconds, depending on browser,
18 * depending on load. [setImmediate], in contrast, makes browser-specific
19 * changes in behavior to attempt to run immediately after the current
20 * frame unwinds, causing the future to complete after all processing has
21 * completed for the current event, but before any subsequent events.
22 */
23 void setImmediate(TimeoutHandler callback) {
24 _addMicrotaskCallback(callback);
25 }
26 /**
27 * Lookup a port by its [name]. Return null if no port is
28 * registered under [name].
29 */
30 SendPortSync lookupPort(String name) {
31 var port =
32 json.parse(document.documentElement.attributes['dart-port:$name']);
33 return _deserialize(port);
34 }
35
36 /**
37 * Register a [port] on this window under the given [name]. This
38 * port may be retrieved by any isolate (or JavaScript script)
39 * running in this window.
40 */
41 void registerPort(String name, var port) {
42 var serialized = _serialize(port);
43 document.documentElement.attributes['dart-port:$name'] =
44 json.stringify(serialized);
45 }
46
47 /**
48 * Returns a Future that completes just before the window is about to repaint
49 * so the user can draw an animation frame
50 *
51 * If you need to later cancel this animation, use [requestAnimationFrame]
52 * instead.
53 *
54 * Note: The code that runs when the future completes should call
55 * [animationFrame] again for the animation to continue.
56 */
57 Future<num> get animationFrame {
58 var completer = new Completer<int>();
59 requestAnimationFrame(completer.complete);
60 return completer.future;
61 }
62
63 $if DART2JS
9 Document get document => JS('Document', '#.document', this); 64 Document get document => JS('Document', '#.document', this);
10 65
11 WindowBase _open2(url, name) => JS('Window', '#.open(#,#)', this, url, name); 66 WindowBase _open2(url, name) => JS('Window', '#.open(#,#)', this, url, name);
12 67
13 WindowBase _open3(url, name, options) => 68 WindowBase _open3(url, name, options) =>
14 JS('Window', '#.open(#,#,#)', this, url, name, options); 69 JS('Window', '#.open(#,#,#)', this, url, name, options);
15 70
16 WindowBase open(String url, String name, [String options]) { 71 WindowBase open(String url, String name, [String options]) {
17 if (options == null) { 72 if (options == null) {
18 return _DOMWindowCrossFrame._createSafe(_open2(url, name)); 73 return _DOMWindowCrossFrame._createSafe(_open2(url, name));
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 // On Firefox the code that implements 'is Location' fails to find the patch 119 // On Firefox the code that implements 'is Location' fails to find the patch
65 // stub on Object.prototype and throws an exception. 120 // stub on Object.prototype and throws an exception.
66 try { 121 try {
67 return thing is Location; 122 return thing is Location;
68 } catch (e) { 123 } catch (e) {
69 return false; 124 return false;
70 } 125 }
71 } 126 }
72 127
73 /** 128 /**
74 * Executes a [callback] after the immediate execution stack has completed. 129 * Called to draw an animation frame and then request the window to repaint
130 * after [callback] has finished (creating the animation).
75 * 131 *
76 * This will cause the callback to be executed after all processing has 132 * Use this method only if you need to later call [cancelAnimationFrame]. If
77 * completed for the current event, but before any subsequent events. 133 * not, the preferred Dart idiom is to set animation frames by calling
134 * [animationFrame], which returns a Future.
135 *
136 * 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
138 * [cancelAnimationFrame] so you can specify the particular animation to
139 * cancel.
140 *
141 * Note: The supplied [callback] needs to call [requestAnimationFrame] again
142 * for the animation to continue.
78 */ 143 */
79 void setImmediate(TimeoutHandler callback) {
80 _addMicrotaskCallback(callback);
81 }
82
83 @DomName('DOMWindow.requestAnimationFrame') 144 @DomName('DOMWindow.requestAnimationFrame')
84 int requestAnimationFrame(RequestAnimationFrameCallback callback) { 145 int requestAnimationFrame(RequestAnimationFrameCallback callback) {
85 _ensureRequestAnimationFrame(); 146 _ensureRequestAnimationFrame();
86 return _requestAnimationFrame(callback); 147 return _requestAnimationFrame(callback);
87 } 148 }
88 149
89 void cancelAnimationFrame(id) { 150 void cancelAnimationFrame(id) {
90 _ensureRequestAnimationFrame(); 151 _ensureRequestAnimationFrame();
91 _cancelAnimationFrame(id); 152 _cancelAnimationFrame(id);
92 } 153 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 */ 192 */
132 @SupportedBrowser(SupportedBrowser.CHROME, '23.0') 193 @SupportedBrowser(SupportedBrowser.CHROME, '23.0')
133 @SupportedBrowser(SupportedBrowser.FIREFOX, '15.0') 194 @SupportedBrowser(SupportedBrowser.FIREFOX, '15.0')
134 @SupportedBrowser(SupportedBrowser.IE, '10.0') 195 @SupportedBrowser(SupportedBrowser.IE, '10.0')
135 @Experimental 196 @Experimental
136 IdbFactory get indexedDB => 197 IdbFactory get indexedDB =>
137 JS('IdbFactory', 198 JS('IdbFactory',
138 '#.indexedDB || #.webkitIndexedDB || #.mozIndexedDB', 199 '#.indexedDB || #.webkitIndexedDB || #.mozIndexedDB',
139 this, this, this); 200 this, this, this);
140 201
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') 202 @DomName('Window.console')
161 Console get console => Console.safeConsole; 203 Console get console => Console.safeConsole;
162 204
163 /// Checks if _setImmediate is supported. 205 /// Checks if _setImmediate is supported.
164 static bool get _supportsSetImmediate => 206 static bool get _supportsSetImmediate =>
165 JS('bool', '!!(window.setImmediate)'); 207 JS('bool', '!!(window.setImmediate)');
166 208
167 // Set immediate implementation for IE 209 // Set immediate implementation for IE
168 void _setImmediate(void callback()) { 210 void _setImmediate(void callback()) {
169 JS('void', '#.setImmediate(#)', this, convertDartClosureToJS(callback, 0)); 211 JS('void', '#.setImmediate(#)', this, convertDartClosureToJS(callback, 0));
170 } 212 }
213 $else
214 /// Checks if _setImmediate is supported.
215 static bool get _supportsSetImmediate => false;
216
217 /// Dartium stub for IE's setImmediate.
218 void _setImmediate(void callback()) {
219 throw new UnsupportedError('setImmediate is not supported');
220 }
221 $endif
171 222
172 $!MEMBERS 223 $!MEMBERS
173 } 224 }
OLDNEW
« no previous file with comments | « tools/dom/templates/html/dartium/impl_Window.darttemplate ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698