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

Unified Diff: tools/dom/templates/html/impl/impl_Window.darttemplate

Issue 12218131: Combine window.setTimeout/setInterval with Timer and Timer.repeating. Also (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 side-by-side diff with in-line comments
Download patch
Index: tools/dom/templates/html/impl/impl_Window.darttemplate
diff --git a/tools/dom/templates/html/dart2js/impl_Window.darttemplate b/tools/dom/templates/html/impl/impl_Window.darttemplate
similarity index 68%
rename from tools/dom/templates/html/dart2js/impl_Window.darttemplate
rename to tools/dom/templates/html/impl/impl_Window.darttemplate
index 1f74f224a8997af2b79797e2b8ad335c20438d9f..d16ca6736e5ba6d7fb6ea6dcc5e66b5274111ddc 100644
--- a/tools/dom/templates/html/dart2js/impl_Window.darttemplate
+++ b/tools/dom/templates/html/impl/impl_Window.darttemplate
@@ -4,8 +4,66 @@
part of $LIBRARYNAME;
+$if DART2JS
$(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS native "@*DOMWindow" {
+$else
+$(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC {
+$endif
+ /**
+ * Returns a Future that will complete when the immediate execution stack has
+ * completed.
+ *
+ * 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.
+ * because Timer will run in about 4-15 milliseconds, depending on browser,
+ * depending on load. [immediate], in contrast, performs makes
+ * browser-specific changes to attempt to run immediately after the current
+ * frame unwinds, causing the future to complete after all processing has
+ * completed for the current event, but before any subsequent events.
+ */
+ 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
+ var completer = new Completer<int>();
+ _addMicrotaskCallback(() { completer.complete(); });
+ return completer.future;
+ }
+ /**
+ * Lookup a port by its [name]. Return null if no port is
+ * registered under [name].
+ */
+ SendPortSync lookupPort(String name) {
+ var port =
+ json.parse(document.documentElement.attributes['dart-port:$name']);
+ return _deserialize(port);
+ }
+
+ /**
+ * Register a [port] on this window under the given [name]. This
+ * port may be retrieved by any isolate (or JavaScript script)
+ * running in this window.
+ */
+ void registerPort(String name, var port) {
+ var serialized = _serialize(port);
+ document.documentElement.attributes['dart-port:$name'] =
+ json.stringify(serialized);
+ }
+
+ /**
+ * Returns a Future that completes just before the window is about to repaint
+ * so the user can draw an animation frame
+ *
+ * If you need to later cancel this animation, use [requestAnimationFrame]
+ * instead.
+ *
+ * Note: The code that runs when the future completes should call
+ * [animationFrame] again for the animation to continue.
+ */
+ 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
+ var completer = new Completer<int>();
+ 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.
+ return completer.future;
+ }
+
+$if DART2JS
Document get document => JS('Document', '#.document', this);
WindowBase _open2(url, name) => JS('Window', '#.open(#,#)', this, url, name);
@@ -71,15 +129,21 @@ $(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS native "@*DOMWindow" {
}
/**
- * Executes a [callback] after the immediate execution stack has completed.
+ * Called to draw an animation frame and then request the window to repaint
+ * after [callback] has finished (creating the animation).
*
- * This will cause the callback to be executed after all processing has
- * completed for the current event, but before any subsequent events.
+ * Use this method only if you need to later call [cancelAnimationFrame]. If
+ * not, the preferred Dart idiom is to set animation frames by calling
+ * [animationFrame], which returns a Future.
+ *
+ * Returns a non-zero valued integer to represent the request id for this
+ * request. This value only needs to be saved if you intend to call
+ * [cancelAnimationFrame] so you can specify the particular animation to
+ * cancel.
+ *
+ * Note: The supplied [callback] needs to call [requestAnimationFrame] again
+ * for the animation to continue.
*/
- void setImmediate(TimeoutHandler callback) {
- _addMicrotaskCallback(callback);
- }
-
@DomName('DOMWindow.requestAnimationFrame')
int requestAnimationFrame(RequestAnimationFrameCallback callback) {
_ensureRequestAnimationFrame();
@@ -138,25 +202,6 @@ $(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS native "@*DOMWindow" {
'#.indexedDB || #.webkitIndexedDB || #.mozIndexedDB',
this, this, this);
- /**
- * Lookup a port by its [name]. Return null if no port is
- * registered under [name].
- */
- SendPortSync lookupPort(String name) {
- var port = json.parse(document.documentElement.attributes['dart-port:$name']);
- return _deserialize(port);
- }
-
- /**
- * Register a [port] on this window under the given [name]. This
- * port may be retrieved by any isolate (or JavaScript script)
- * running in this window.
- */
- void registerPort(String name, var port) {
- var serialized = _serialize(port);
- document.documentElement.attributes['dart-port:$name'] = json.stringify(serialized);
- }
-
@DomName('Window.console')
Console get console => Console.safeConsole;
@@ -168,6 +213,15 @@ $(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS native "@*DOMWindow" {
void _setImmediate(void callback()) {
JS('void', '#.setImmediate(#)', this, convertDartClosureToJS(callback, 0));
}
+$else
+ /// Checks if _setImmediate is supported.
+ static bool get _supportsSetImmediate => false;
+
+ /// Dartium stub for IE's setImmediate.
+ void _setImmediate(void callback()) {
+ throw new UnsupportedError('setImmediate is not supported');
+ }
+$endif
$!MEMBERS
}
« tools/dom/scripts/htmlrenamer.py ('K') | « 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