Fix animationFrameRequest for dartium.
Review URL: https://codereview.chromium.org/2124863002 .
diff --git a/sdk/lib/html/dart2js/html_dart2js.dart b/sdk/lib/html/dart2js/html_dart2js.dart
index e5eae90..c9cd5cb 100644
--- a/sdk/lib/html/dart2js/html_dart2js.dart
+++ b/sdk/lib/html/dart2js/html_dart2js.dart
@@ -34880,6 +34880,7 @@
JS('void', '#.location = #', this, value);
}
+
/**
* Called to draw an animation frame and then request the window to repaint
* after [callback] has finished (creating the animation).
@@ -34933,6 +34934,7 @@
* * [Window.cancelAnimationFrame](https://developer.mozilla.org/en-US/docs/Web/API/Window.cancelAnimationFrame)
* from MDN.
*/
+ @DomName('Window.cancelAnimationFrame')
void cancelAnimationFrame(int id) {
_ensureRequestAnimationFrame();
var task = AnimationFrameTask._tasks.remove(id);
@@ -34995,7 +34997,6 @@
@DomName('Window.console')
Console get console => Console._safeConsole;
-
/**
* Access a sandboxed file system of the specified `size`. If `persistent` is
* true, the application will request permission from the user to create
diff --git a/sdk/lib/html/dartium/html_dartium.dart b/sdk/lib/html/dartium/html_dartium.dart
index 35b620a..5c43505 100644
--- a/sdk/lib/html/dartium/html_dartium.dart
+++ b/sdk/lib/html/dartium/html_dartium.dart
@@ -39464,6 +39464,7 @@
return completer.future;
}
+
/**
* Called to draw an animation frame and then request the window to repaint
* after [callback] has finished (creating the animation).
@@ -39482,9 +39483,53 @@
*/
@DomName('Window.requestAnimationFrame')
int requestAnimationFrame(FrameRequestCallback callback) {
- return _requestAnimationFrame(_wrapZone(callback));
+ if (identical(Zone.current, Zone.ROOT)) {
+ return _requestAnimationFrame(callback);
+ }
+ var spec = new AnimationFrameRequestSpecification(this, callback);
+ var task = Zone.current.createTask/*<AnimationFrameTask>*/(
+ _createAnimationFrameTask, spec);
+ AnimationFrameTask._tasks[task.id] = task;
+ return task.id;
}
+ static _AnimationFrameTask _createAnimationFrameTask(
+ AnimationFrameRequestSpecification spec, Zone zone) {
+ var task;
+ var id = spec.window._requestAnimationFrame((num time) {
+ AnimationFrameTask.removeMapping(task.id);
+ zone.runTask(_runAnimationFrame, task, time);
+ });
+ var callback = zone.registerUnaryCallback(spec.callback);
+ task = new _AnimationFrameTask(id, zone, callback);
+ return task;
+ }
+
+ static void _runAnimationFrame(_AnimationFrameTask task, num time) {
+ task._callback(time);
+ }
+
+ /**
+ * Cancels an animation frame request.
+ *
+ * ## Other resources
+ *
+ * * [Window.cancelAnimationFrame](https://developer.mozilla.org/en-US/docs/Web/API/Window.cancelAnimationFrame)
+ * from MDN.
+ */
+ @DomName('Window.cancelAnimationFrame')
+ void cancelAnimationFrame(int id) {
+ _ensureRequestAnimationFrame();
+ var task = AnimationFrameTask._tasks.remove(id);
+ if (task == null) {
+ // Assume that the animation frame request wasn't intercepted by a zone.
+ _cancelAnimationFrame(id);
+ return;
+ }
+ task.cancel(this);
+ }
+
+
/**
* Access a sandboxed file system of the specified `size`. If `persistent` is
* true, the application will request permission from the user to create
@@ -40251,7 +40296,7 @@
@DomName('Window.cancelAnimationFrame')
@DocsEditable()
- void cancelAnimationFrame(int handle) => _blink.BlinkWindow.instance.cancelAnimationFrame_Callback_1_(this, handle);
+ void _cancelAnimationFrame(int handle) => _blink.BlinkWindow.instance.cancelAnimationFrame_Callback_1_(this, handle);
@DomName('Window.close')
@DocsEditable()
diff --git a/tools/dom/scripts/htmlrenamer.py b/tools/dom/scripts/htmlrenamer.py
index 7ec0685..3d3c410 100644
--- a/tools/dom/scripts/htmlrenamer.py
+++ b/tools/dom/scripts/htmlrenamer.py
@@ -402,6 +402,7 @@
'WindowTimers.setTimeout',
'Window.moveTo',
'Window.requestAnimationFrame',
+ 'Window.cancelAnimationFrame',
'Window.setInterval',
'Window.setTimeout',
diff --git a/tools/dom/templates/html/impl/impl_Window.darttemplate b/tools/dom/templates/html/impl/impl_Window.darttemplate
index fe4db3d..9563abb 100644
--- a/tools/dom/templates/html/impl/impl_Window.darttemplate
+++ b/tools/dom/templates/html/impl/impl_Window.darttemplate
@@ -187,6 +187,8 @@
JS('void', '#.location = #', this, value);
}
+$endif
+
/**
* Called to draw an animation frame and then request the window to repaint
* after [callback] has finished (creating the animation).
@@ -205,7 +207,9 @@
*/
@DomName('Window.requestAnimationFrame')
int requestAnimationFrame(FrameRequestCallback callback) {
+$if DART2JS
_ensureRequestAnimationFrame();
+$endif
if (identical(Zone.current, Zone.ROOT)) {
return _requestAnimationFrame(callback);
}
@@ -240,6 +244,7 @@
* * [Window.cancelAnimationFrame](https://developer.mozilla.org/en-US/docs/Web/API/Window.cancelAnimationFrame)
* from MDN.
*/
+ @DomName('Window.cancelAnimationFrame')
void cancelAnimationFrame(int id) {
_ensureRequestAnimationFrame();
var task = AnimationFrameTask._tasks.remove(id);
@@ -251,6 +256,7 @@
task.cancel(this);
}
+$if DART2JS
@JSName('requestAnimationFrame')
int _requestAnimationFrame(FrameRequestCallback callback) native;
@@ -301,28 +307,6 @@
/// The debugging console for this window.
@DomName('Window.console')
Console get console => Console._safeConsole;
-
-$else
- /**
- * Called to draw an animation frame and then request the window to repaint
- * after [callback] has finished (creating the animation).
- *
- * 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.
- */
- @DomName('Window.requestAnimationFrame')
- int requestAnimationFrame(FrameRequestCallback callback) {
- return _requestAnimationFrame(_wrapZone(callback));
- }
$endif
/**