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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/toolbar/ToolbarPhone.java

Issue 2228823003: When possible, draw the toolbar shadow with the compositor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 4 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/toolbar/ToolbarPhone.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/toolbar/ToolbarPhone.java b/chrome/android/java/src/org/chromium/chrome/browser/toolbar/ToolbarPhone.java
index 1ac2662a235c7496a27b722ece61466d6f738d17..735bbee18c4b5a56bdc301f379fdf34c8c115ba0 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/toolbar/ToolbarPhone.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/toolbar/ToolbarPhone.java
@@ -122,6 +122,7 @@ public class ToolbarPhone extends ToolbarLayout
private TextView mUrlBar;
private View mUrlActionContainer;
private ImageView mToolbarShadow;
+ private boolean mUrlHasFocus;
private final int mProgressBackBackgroundColorWhite;
@@ -132,6 +133,7 @@ public class ToolbarPhone extends ToolbarLayout
private final Set<View> mBrowsingModeViews = new HashSet<>();
@ViewDebug.ExportedProperty(category = "chrome")
private int mTabSwitcherState;
+ private boolean mIsCompositorReady;
// This determines whether or not the toolbar draws as expected (false) or whether it always
// draws as if it's showing the non-tabswitcher, non-animating toolbar. This is used in grabbing
@@ -173,6 +175,8 @@ public class ToolbarPhone extends ToolbarLayout
@ViewDebug.ExportedProperty(category = "chrome")
private float mUrlFocusChangePercent;
+ private float mToolbarShadowAlpha;
+
/**
* The degree to which the omnibox has expanded to full width, either because it is getting
* focused or the NTP search box is being scrolled up. Note that in the latter case, the actual
@@ -265,6 +269,7 @@ public class ToolbarPhone extends ToolbarLayout
private NewTabPage mVisibleNewTabPage;
private float mPreTextureCaptureAlpha = 1f;
+ private int mPreTextureCaptureVisibility;
private boolean mIsOverlayTabStackDrawableLight;
// The following are some properties used during animation. We use explicit property classes
@@ -280,6 +285,7 @@ public class ToolbarPhone extends ToolbarLayout
@Override
public void set(ToolbarPhone object, Float value) {
setUrlFocusChangePercent(value);
+ setToolbarShadowAlpha(value);
}
};
@@ -877,12 +883,12 @@ public class ToolbarPhone extends ToolbarLayout
private void resetNtpAnimationValues() {
mLocationBarBackgroundNtpOffset.setEmpty();
mLocationBar.setTranslationY(0);
+
if (!mUrlFocusChangeInProgress) {
mToolbarButtonsContainer.setTranslationY(0);
mReturnButton.setTranslationY(0);
mHomeButton.setTranslationY(0);
}
- mToolbarShadow.setAlpha(1f);
mLocationBar.setAlpha(1);
mForceDrawLocationBarBackground = false;
mLocationBarBackgroundAlpha = 255;
@@ -905,7 +911,6 @@ public class ToolbarPhone extends ToolbarLayout
if (mTabSwitcherState == TAB_SWITCHER || mTabSwitcherState == ENTERING_TAB_SWITCHER) return;
setAncestorsShouldClipChildren(mUrlExpansionPercent == 0f);
- mToolbarShadow.setAlpha(0f);
NewTabPage ntp = getToolbarDataProvider().getNewTabPageForCurrentTab();
ntp.getSearchBoxBounds(mNtpSearchBoxBounds, mNtpSearchBoxTranslation);
@@ -1437,10 +1442,12 @@ public class ToolbarPhone extends ToolbarLayout
assert mTextureCaptureMode != textureMode;
mTextureCaptureMode = textureMode;
if (mTextureCaptureMode) {
- mToolbarShadow.setVisibility(VISIBLE);
+ mPreTextureCaptureVisibility = mToolbarShadow.getVisibility();
+ mToolbarShadow.setVisibility(INVISIBLE);
mPreTextureCaptureAlpha = getAlpha();
setAlpha(1);
} else {
+ mToolbarShadow.setVisibility(mPreTextureCaptureVisibility);
setAlpha(mPreTextureCaptureAlpha);
updateShadowVisibility();
mPreTextureCaptureAlpha = 1f;
@@ -1763,6 +1770,7 @@ public class ToolbarPhone extends ToolbarLayout
triggerUrlFocusAnimation(hasFocus);
TransitionDrawable shadowDrawable = (TransitionDrawable) mToolbarShadow.getDrawable();
+
if (hasFocus) {
dismissTabSwitcherCallout();
shadowDrawable.startTransition(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS);
@@ -1809,6 +1817,7 @@ public class ToolbarPhone extends ToolbarLayout
public void onAnimationEnd(Animator animation) {
if (mCanceled) return;
+ mUrlHasFocus = hasFocus;
if (!hasFocus) {
mDisableLocationBarRelayout = false;
mLayoutLocationBarInFocusedMode = false;
@@ -1816,6 +1825,7 @@ public class ToolbarPhone extends ToolbarLayout
}
mLocationBar.finishUrlFocusChange(hasFocus);
mUrlFocusChangeInProgress = false;
+ updateShadowVisibility();
}
});
mUrlFocusLayoutAnimator.start();
@@ -1882,6 +1892,8 @@ public class ToolbarPhone extends ToolbarLayout
mHasCheckedIfTabSwitcherCalloutIsNecessary = true;
showTabSwitcherCalloutIfNecessary();
}
+
+ updateShadowVisibility();
}
private static boolean isVisualStateValidForBrandColorTransition(VisualState state) {
@@ -1991,13 +2003,54 @@ public class ToolbarPhone extends ToolbarLayout
return ntp != null && ntp.isLocationBarShownInNTP();
}
+ /**
+ * @return True if the Android version of the toolbar shadow is needed.
+ */
+ private boolean needsAndroidToolbarShadow() {
+ // Reasons to draw the Android toolbar shadow:
+ // 1. Web page is using a native view except in the case of the NTP.
+ // 2. Omnibox is focused and there are suggestions under it.
+ if (!mIsCompositorReady || getToolbarDataProvider() == null
+ || getToolbarDataProvider().getTab() == null) {
+ return true;
+ }
+ Tab tab = getToolbarDataProvider().getTab();
+
+ // If the shadow is not needed, this is definitely the NTP. There are other shadows that
+ // will show in place of the normal toolbar shadow.
+ if (tab.getNativePage() != null && !tab.getNativePage().needsToolbarShadow()) return false;
+
+ // Check if the current tab uses a native android View instead of a WebContents.
+ boolean usesNativeView = tab.isNativePage() || tab.isShowingSadTab();
+
+ return mTabSwitcherState == STATIC_TAB && (mUrlHasFocus || usesNativeView);
+ }
+
private void updateShadowVisibility() {
- boolean shouldDrawShadow = mTabSwitcherState == STATIC_TAB;
- int shadowVisibility = shouldDrawShadow ? View.VISIBLE : View.INVISIBLE;
+ if (needsAndroidToolbarShadow()) {
+ mToolbarShadow.setAlpha(1.0f);
+ } else {
+ mToolbarShadow.setAlpha(0.0f);
+ }
+ }
- if (mToolbarShadow.getVisibility() != shadowVisibility) {
- mToolbarShadow.setVisibility(shadowVisibility);
+ /**
+ * Set the toolbar shadow's alpha during animation.
+ * @param alpha The alpha that the toolbar shadow should have.
+ */
+ private void setToolbarShadowAlpha(float value) {
+ boolean isNativePage = false;
+ if (getToolbarDataProvider() != null && getToolbarDataProvider().getTab() != null) {
+ isNativePage = getToolbarDataProvider().getTab().isNativePage();
}
+
+ // If the toolbar shadow is always supposed be showing, don't fade it. Check if the page
+ // is native because the shadow might be showing becuase of the omnibox.
+ if (needsAndroidToolbarShadow() && isNativePage) {
+ mToolbarShadow.setAlpha(1.0f);
+ return;
+ }
+ mToolbarShadow.setAlpha(Math.min(value, 1.0f));
}
private VisualState computeVisualState(boolean isInTabSwitcherMode) {
@@ -2268,5 +2321,12 @@ public class ToolbarPhone extends ToolbarLayout
mFullscreenCalloutToken);
}
}
+
+ @Override
+ public void onFirstCompositorFrame() {
+ if (mIsCompositorReady) return;
+ mIsCompositorReady = true;
+ updateShadowVisibility();
+ }
}

Powered by Google App Engine
This is Rietveld 408576698