Index: ui/android/java/src/org/chromium/ui/base/WindowAndroid.java |
diff --git a/ui/android/java/src/org/chromium/ui/base/WindowAndroid.java b/ui/android/java/src/org/chromium/ui/base/WindowAndroid.java |
index 8f1c58f67ffcf8a7829660e24877662fa70bdd59..0e84cf4ef74d39befa2d5aa3f980d097d91529b0 100644 |
--- a/ui/android/java/src/org/chromium/ui/base/WindowAndroid.java |
+++ b/ui/android/java/src/org/chromium/ui/base/WindowAndroid.java |
@@ -4,6 +4,8 @@ |
package org.chromium.ui.base; |
+import android.animation.Animator; |
+import android.animation.AnimatorListenerAdapter; |
import android.annotation.SuppressLint; |
import android.app.Activity; |
import android.app.PendingIntent; |
@@ -13,6 +15,7 @@ import android.content.Intent; |
import android.os.Bundle; |
import android.util.Log; |
import android.util.SparseArray; |
+import android.view.View; |
import android.widget.Toast; |
import org.chromium.base.CalledByNative; |
@@ -21,6 +24,7 @@ import org.chromium.ui.VSyncMonitor; |
import java.lang.ref.WeakReference; |
import java.util.HashMap; |
+import java.util.HashSet; |
/** |
* The window base class that has the minimum functionality. |
@@ -47,6 +51,10 @@ public class WindowAndroid { |
// the Android lint warning "UseSparseArrays". |
protected HashMap<Integer, String> mIntentErrors; |
+ // We track all animations over content and provide a drawing placeholder for them. |
+ private HashSet<Animator> mAnimationsOverContent = new HashSet<Animator>(); |
+ private View mAnimationPlaceholderView; |
+ |
private final VSyncMonitor.Listener mVSyncListener = new VSyncMonitor.Listener() { |
@Override |
public void onVSync(VSyncMonitor monitor, long vsyncTimeMicros) { |
@@ -289,6 +297,56 @@ public class WindowAndroid { |
return mNativeWindowAndroid; |
} |
+ /** |
+ * Set the animation placeholder view, which we set to 'draw' during animations, such that |
+ * animations aren't clipped by the SurfaceView 'hole'. This can be the SurfaceView itself |
+ * or a view directly on top of it. This could be extended to many views if we ever need it. |
+ */ |
+ public void setAnimationPlaceholderView(View view) { |
+ mAnimationPlaceholderView = view; |
+ } |
+ |
+ /** |
+ * Start a post-layout animation on top of web content. |
+ * |
+ * By default, Android optimizes what it shows on top of SurfaceViews (saves power). |
+ * Effectively, layouts determine what gets drawn and post-layout animations outside |
+ * of this area may be 'clipped'. Using this method to start such animations will |
+ * ensure that nothing is clipped during the animation, and restore the optimal |
+ * state when the animation ends. |
+ */ |
+ public void startAnimationOverContent(Animator animation) { |
+ // We may not need an animation placeholder (eg. Webview doesn't use SurfaceView) |
+ if (mAnimationPlaceholderView == null) |
+ return; |
+ if (animation.isStarted()) throw new IllegalArgumentException("Already started."); |
+ boolean added = mAnimationsOverContent.add(animation); |
+ if (!added) throw new IllegalArgumentException("Already Added."); |
+ |
+ // We start the animation in this method to help guarantee that we never get stuck in this |
+ // state or leak objects into the set. Starting the animation here should guarantee that we |
+ // get an onAnimationEnd callback, and remove this animation. |
+ animation.start(); |
+ |
+ // When the first animation starts, make the placeholder 'draw' itself. |
+ if (mAnimationPlaceholderView.willNotDraw()) { |
+ mAnimationPlaceholderView.setWillNotDraw(false); |
+ } |
+ |
+ // When the last animation ends, remove the placeholder view, |
+ // returning to the default optimized state. |
+ animation.addListener(new AnimatorListenerAdapter() { |
+ @Override |
+ public void onAnimationEnd(Animator animation) { |
+ animation.removeListener(this); |
+ mAnimationsOverContent.remove(animation); |
+ if (mAnimationsOverContent.isEmpty()) { |
+ mAnimationPlaceholderView.setWillNotDraw(true); |
+ } |
+ } |
+ }); |
+ } |
+ |
private native long nativeInit(); |
private native void nativeOnVSync(long nativeWindowAndroid, |
long vsyncTimeMicros, |