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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/components/LayoutTab.java

Issue 2114513002: Fade theme color in tab switcher (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments & fix coloring invisible LayoutTab Created 4 years, 5 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: chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/components/LayoutTab.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/components/LayoutTab.java b/chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/components/LayoutTab.java
index e03bb150ecec617e61bb2a80060499997405c394..f541c80a93901d1154071525d637769b8df5a2dd 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/components/LayoutTab.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/components/LayoutTab.java
@@ -4,6 +4,8 @@
package org.chromium.chrome.browser.compositor.layouts.components;
+import static org.chromium.chrome.browser.compositor.layouts.ChromeAnimation.AnimatableAnimation.createAnimation;
+
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Color;
@@ -12,7 +14,10 @@ import android.graphics.RectF;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.compositor.layouts.ChromeAnimation;
import org.chromium.chrome.browser.tab.Tab;
+import org.chromium.chrome.browser.toolbar.ToolbarPhone;
+import org.chromium.chrome.browser.util.ColorUtils;
import org.chromium.chrome.browser.util.MathUtils;
+import org.chromium.ui.interpolators.BakedBezierInterpolator;
/**
* {@link LayoutTab} is used to keep track of a thumbnail's bitmap and position and to
@@ -40,6 +45,7 @@ public class LayoutTab implements ChromeAnimation.Animatable<LayoutTab.Property>
DECORATION_ALPHA,
TOOLBAR_Y_OFFSET,
SIDE_BORDER_SCALE,
+ TOOLBAR_COLOR,
}
public static final float ALPHA_THRESHOLD = 1.0f / 255.0f;
@@ -115,6 +121,11 @@ public class LayoutTab implements ChromeAnimation.Animatable<LayoutTab.Property>
*/
private boolean mInitFromHostCalled = false;
+ /** The animation set specific to this LayoutTab. */
+ private ChromeAnimation<ChromeAnimation.Animatable<?>> mCurrentAnimations;
+ private int mInitialThemeColor;
+ private int mFinalThemeColor;
+
// All the members bellow are initialized from the delayed initialization.
//
// Begin section --------------
@@ -208,16 +219,53 @@ public class LayoutTab implements ChromeAnimation.Animatable<LayoutTab.Property>
* @param shouldStall Whether the tab should display a desaturated thumbnail and
* wait for the content layer to load.
* @param canUseLiveTexture Whether the tab can use a live texture when being displayed.
+ * @return True if the init requires the compositor to update.
*/
- public void initFromHost(int backgroundColor, boolean shouldStall, boolean canUseLiveTexture,
+ public boolean initFromHost(int backgroundColor, boolean shouldStall, boolean canUseLiveTexture,
int toolbarBackgroundColor, int textBoxBackgroundColor, float textBoxAlpha) {
mBackgroundColor = backgroundColor;
- mToolbarBackgroundColor = toolbarBackgroundColor;
+
+ boolean needsUpdate = false;
+
+ // If the toolbar color changed, animate between the old and new colors.
+ if (mToolbarBackgroundColor != toolbarBackgroundColor && isVisible()) {
+ ChromeAnimation.Animation<ChromeAnimation.Animatable<?>> themeColorAnimation =
+ createAnimation(this, Property.TOOLBAR_COLOR, 0.0f, 1.0f,
+ ToolbarPhone.THEME_COLOR_TRANSITION_DURATION, 0, false,
+ BakedBezierInterpolator.TRANSFORM_CURVE);
+
+ mInitialThemeColor = mToolbarBackgroundColor;
+ mFinalThemeColor = toolbarBackgroundColor;
+
+ if (mCurrentAnimations != null) {
+ mCurrentAnimations.updateAndFinish();
+ }
+
+ mCurrentAnimations = new ChromeAnimation<ChromeAnimation.Animatable<?>>();
+ mCurrentAnimations.add(themeColorAnimation);
+ mCurrentAnimations.start();
+ needsUpdate = true;
+ } else {
+ // If the layout tab isn't visible, just set the toolbar color without animating.
+ mToolbarBackgroundColor = toolbarBackgroundColor;
+ }
+
mTextBoxBackgroundColor = textBoxBackgroundColor;
mTextBoxAlpha = textBoxAlpha;
mShouldStall = shouldStall;
mCanUseLiveTexture = canUseLiveTexture;
mInitFromHostCalled = true;
+
+ return needsUpdate;
+ }
+
+ /**
+ * Update any animation controlled by this object.
+ * @param time The current app time in ms.
+ * @return Whether the animations controlled by this LayoutTab are finished.
+ */
+ public boolean onUpdateAnimation(long time) {
+ return mCurrentAnimations == null ? true : mCurrentAnimations.update(time);
}
/**
@@ -774,6 +822,7 @@ public class LayoutTab implements ChromeAnimation.Animatable<LayoutTab.Property>
* @param visible True if the {@link LayoutTab} is visible and need to be drawn.
*/
public void setVisible(boolean visible) {
+ if (!visible && mCurrentAnimations != null) mCurrentAnimations.updateAndFinish();
mVisible = visible;
}
@@ -959,9 +1008,21 @@ public class LayoutTab implements ChromeAnimation.Animatable<LayoutTab.Property>
case SIDE_BORDER_SCALE:
setSideBorderScale(val);
break;
+ case TOOLBAR_COLOR:
+ if (!isVisible()) {
+ mCurrentAnimations.updateAndFinish();
+ } else {
+ mToolbarBackgroundColor = ColorUtils.getColorWithOverlay(mInitialThemeColor,
+ mFinalThemeColor, val);
+ }
+ break;
}
}
@Override
- public void onPropertyAnimationFinished(Property prop) {}
+ public void onPropertyAnimationFinished(Property prop) {
+ if (mCurrentAnimations != null && mCurrentAnimations.finished()) {
+ mCurrentAnimations = null;
+ }
+ }
}

Powered by Google App Engine
This is Rietveld 408576698