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

Unified Diff: sdk/lib/html/dartium/html_dartium.dart

Issue 2039963003: Add zone task support for request-anim. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 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:
Download patch
Index: sdk/lib/html/dartium/html_dartium.dart
diff --git a/sdk/lib/html/dartium/html_dartium.dart b/sdk/lib/html/dartium/html_dartium.dart
index 26fc739abe27c89b3e3d6c1eafcdde3ba3454f36..b3300761e306a1a597d3485c127108009570c54c 100644
--- a/sdk/lib/html/dartium/html_dartium.dart
+++ b/sdk/lib/html/dartium/html_dartium.dart
@@ -39131,6 +39131,77 @@ class WheelEvent extends MouseEvent {
// BSD-style license that can be found in the LICENSE file.
+typedef void RemoveFrameRequestMapping(int id);
+
+/**
+ * The task object representing animation-frame requests.
+ *
+ * For historical reasons, [Window.requestAnimationFrame] returns an integer
+ * to users. However, zone-tasks must be unique objects, and an integer thus
+ * doesn't work. The [Window] class thus keeps a mapping from the id to the
+ * corresponding task object. All zone related operations work on this task
+ * object, whereas users of [Window.requestAnimationFrame] only see the integer
+ * id.
+ *
+ * Since this mapping takes space, it must be removed as soon as the animation-
+ * frame task triggered. The default-implementations do this automatically, but
+ * intercepted implementations of `requestAnimationFrame` must ensure to
+ * call the [AnimationFrameRequestSpecification.removeMapping] function that is
+ * provided in the task specification.
+ */
+abstract class AnimationFrameTask {
+ /** The id that is returned to users. */
+ int get id;
+
+ /** The function that is invoked when the user cancels the request. */
+ void cancel(Window window);
+
+ /** The zone in which the task should run (and cancel). */
+ Zone get zone;
+}
+
+class _AnimationFrameTask implements AnimationFrameTask {
+ final int id;
+ final Zone zone;
+ final FrameRequestCallback _callback;
+
+ _AnimationFrameTask(this.id, this.zone, this._callback);
+
+ void cancel(Window window) {
+ window._cancelAnimationFrame(this.id);
+ }
+}
+
+/**
+ * The task specification for an animation-frame request.
+ *
+ * The task specification of animation-frame requests include a `removeMapping`
+ * function. This function must be called by the created task before it
+ * runs the frame-request callback.
+ */
+class AnimationFrameRequestSpecification implements TaskSpecification {
+ final Window window;
+ /**
+ * The callback that should be executed when the animation-frame is ready.
+ *
+ * Note that the callback hasn't been registered in any zone yet.
+ */
+ final FrameRequestCallback callback;
+
+ /**
+ * The function that should be invoked by the task before running [callback].
+ *
+ * See [AnimationFrame].
+ */
+ final RemoveFrameRequestMapping removeMapping;
+
+ AnimationFrameRequestSpecification(
+ this.window, this.callback, this.removeMapping);
+
+ String get name => "dart.html.request-animation-frame";
+ bool get isOneShot => true;
+}
+
@DocsEditable()
/**
* Top-level container for the current browser tab or window.
@@ -39185,9 +39256,7 @@ class Window extends EventTarget implements WindowEventHandlers, WindowBase, Glo
*/
Future<num> get animationFrame {
var completer = new Completer<num>.sync();
- requestAnimationFrame((time) {
- completer.complete(time);
- });
+ requestAnimationFrame(completer.complete);
return completer.future;
}

Powered by Google App Engine
This is Rietveld 408576698