Brian Slesinsky has uploaded a new change for review.

  https://gwt-review.googlesource.com/1780


Change subject: Stop using prefixed API's in AnimationScheduler by default. Firefox and Safari will use the Timer-based implementation. For Chrome we can use requestAnimationFrame because it's unprefixed starting in Chrome 24.
......................................................................

Stop using prefixed API's in AnimationScheduler by default.
Firefox and Safari will use the Timer-based implementation. For Chrome
we can use requestAnimationFrame because it's unprefixed starting in
Chrome 24.

Since Chrome and Safari are in the same permutation, a future version of Safari that adds the unprefixed API will automatically pick up requestAnimationFrame
once it's unprefixed. I attempted to avoid depending on any details of the
JavaScript API (it's mostly based on the Mozilla implementation) but can't
predict what the final standard will be, so it still seems risky. Perhaps we
should test specifically for Chrome?

Keep in mind that some apps built with GWT 2.5.1 will be around for a long time.

(Not tested yet.)

Change-Id: I3011dceab489871a5864eed1ece47ec850d82425
---
M user/src/com/google/gwt/animation/Animation.gwt.xml
M user/src/com/google/gwt/animation/client/AnimationSchedulerImplMozilla.java
A user/src/com/google/gwt/animation/client/AnimationSchedulerImplNative.java
M user/src/com/google/gwt/animation/client/AnimationSchedulerImplWebkit.java
4 files changed, 97 insertions(+), 2 deletions(-)



diff --git a/user/src/com/google/gwt/animation/Animation.gwt.xml b/user/src/com/google/gwt/animation/Animation.gwt.xml
index bc2a47c..8e1f752 100644
--- a/user/src/com/google/gwt/animation/Animation.gwt.xml
+++ b/user/src/com/google/gwt/animation/Animation.gwt.xml
@@ -29,14 +29,31 @@
   </replace-with>

   <!-- Implementation based on mozRequestAnimationFrame -->
+  <!-- Disabled by default because it uses a prefixed API. -->
+<!--
<replace-with class="com.google.gwt.animation.client.AnimationSchedulerImplMozilla"> <when-type-is class="com.google.gwt.animation.client.AnimationScheduler"/>
     <when-property-is name="user.agent" value="gecko1_8"/>
   </replace-with>
+-->

   <!-- Implementation based on webkitRequestAnimationFrame -->
+  <!-- Disabled by default because it uses a prefixed API. -->
+<!--
<replace-with class="com.google.gwt.animation.client.AnimationSchedulerImplWebkit"> <when-type-is class="com.google.gwt.animation.client.AnimationScheduler"/>
     <when-property-is name="user.agent" value="safari"/>
   </replace-with>
+-->
+
+    <!--
+ Implementation based on requestAnimationFrame. Note: as of January 2013 this is + only available for Chrome 24 and above. Safari will fall back to the Timer-based
+     implementation, but this may change in a future Safari release.
+     -->
+ <replace-with class="com.google.gwt.animation.client.AnimationSchedulerImplNative"> + <when-type-is class="com.google.gwt.animation.client.AnimationScheduler"/>
+      <when-property-is name="user.agent" value="gecko1_8"/>
+      <when-property-is name="user.agent" value="safari"/>
+  </replace-with>
 </module>
diff --git a/user/src/com/google/gwt/animation/client/AnimationSchedulerImplMozilla.java b/user/src/com/google/gwt/animation/client/AnimationSchedulerImplMozilla.java
index 157a53e..2f7d0c9 100644
--- a/user/src/com/google/gwt/animation/client/AnimationSchedulerImplMozilla.java +++ b/user/src/com/google/gwt/animation/client/AnimationSchedulerImplMozilla.java
@@ -18,7 +18,7 @@
 import com.google.gwt.dom.client.Element;

 /**
- * Implementation using <code>mozRequestAnimationFrame</code>.
+ * Implementation using <code>mozRequestAnimationFrame</code>. Not currently used by default.
  *
  * @see <a
* href="https://developer.mozilla.org/en/DOM/window.mozRequestAnimationFrame";> diff --git a/user/src/com/google/gwt/animation/client/AnimationSchedulerImplNative.java b/user/src/com/google/gwt/animation/client/AnimationSchedulerImplNative.java
new file mode 100644
index 0000000..d0c4f8f
--- /dev/null
+++ b/user/src/com/google/gwt/animation/client/AnimationSchedulerImplNative.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.animation.client;
+
+import com.google.gwt.dom.client.Element;
+
+/**
+ * An implementation using the unprefixed <code>requestAnimationFrame</code>. + * Since browser support is in flux, assumes as little as possible about the + * JavaScript API. In particular, we only pass in the callback and don't look
+ * at the return value. Also, the callback doesn't look at any parameters.
+ *
+ * <p>(This API was unprefixed in Chrome 24, despite not being standardized yet.)
+ *
+ * @see <a
+ * href="http://www.w3.org/TR/animation-timing/";>Timing control for script-based animations</a>
+ */
+class AnimationSchedulerImplNative extends AnimationSchedulerImpl {
+
+  /**
+   * A handle that remembers whether it was cancelled..
+   */
+  private class AnimationHandleImpl extends AnimationHandle {
+    @SuppressWarnings("unused")
+    private boolean cancelled;
+
+    @Override
+    public void cancel() {
+      cancelled = true;
+    }
+  }
+
+  @Override
+ public AnimationHandle requestAnimationFrame(AnimationCallback callback, Element element) {
+    AnimationHandleImpl handle = new AnimationHandleImpl();
+    requestAnimationFrameImpl(callback, handle);
+    return handle;
+  }
+
+  @Override
+  protected native boolean isNativelySupported() /*-{
+    return !!($wnd.requestAnimationFrame);
+  }-*/;
+
+  /**
+   * Request an animation frame. To avoid depending on a request ID, we
+ * create a JavaScriptObject and add an expando named "cancelled" to indicate + * that the request was cancelled. The callback wrapper checks the expando before
+   * executing the user callback.
+   *
+   * @param callback the user callback to execute
+   * @param handle the handle object
+   */
+  private native void requestAnimationFrameImpl(AnimationCallback callback,
+ AnimationHandleImpl handle) /*-{
+    var wrapper = $entry(function() {
+ if (!hand...@com.google.gwt.animation.client.AnimationSchedulerImplNative.AnimationHandleImpl::cancelled) {
+        // Ignore any time parameter that we were called with.
+ var now = @com.google.gwt.core.client.Duration::currentTimeMillis()(); + callba...@com.google.gwt.animation.client.AnimationScheduler.AnimationCallback::execute(D)(now);
+      }
+    });
+    $wnd.requestAnimationFrame(wrapper);
+  }-*/;
+}
diff --git a/user/src/com/google/gwt/animation/client/AnimationSchedulerImplWebkit.java b/user/src/com/google/gwt/animation/client/AnimationSchedulerImplWebkit.java
index ed02124..7b60173 100644
--- a/user/src/com/google/gwt/animation/client/AnimationSchedulerImplWebkit.java +++ b/user/src/com/google/gwt/animation/client/AnimationSchedulerImplWebkit.java
@@ -19,7 +19,7 @@

 /**
  * Implementation using <code>webkitRequestAnimationFrame</code> and
- * <code>webkitCancelRequestAnimationFrame</code>.
+ * <code>webkitCancelRequestAnimationFrame</code>. Not currently used by default.
  *
  * @see <a
* href="http://www.chromium.org/developers/web-platform-status#TOC-requestAnimationFrame";>

--
To view, visit https://gwt-review.googlesource.com/1780
To unsubscribe, visit https://gwt-review.googlesource.com/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3011dceab489871a5864eed1ece47ec850d82425
Gerrit-PatchSet: 1
Gerrit-Project: gwt
Gerrit-Branch: master
Gerrit-Owner: Brian Slesinsky <skybr...@google.com>

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to