Chromium Code Reviews| 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 174da7e48d5c33041a5bae601eb19f65280b9270..94e9709d415527072fd1c89907a0c2b9aae2b9d9 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 |
| @@ -25,6 +25,7 @@ import android.graphics.drawable.Drawable; |
| import android.graphics.drawable.TransitionDrawable; |
| import android.os.Build; |
| import android.os.SystemClock; |
| +import android.support.v4.view.animation.FastOutSlowInInterpolator; |
| import android.text.TextUtils; |
| import android.util.AttributeSet; |
| import android.util.Property; |
| @@ -36,6 +37,7 @@ import android.view.View.OnLongClickListener; |
| import android.view.ViewDebug; |
| import android.view.ViewGroup; |
| import android.view.WindowManager; |
| +import android.view.animation.Interpolator; |
| import android.view.animation.LinearInterpolator; |
| import android.widget.FrameLayout; |
| import android.widget.ImageView; |
| @@ -92,11 +94,12 @@ public class ToolbarPhone extends ToolbarLayout |
| private static final float UNINITIALIZED_PERCENT = -1f; |
| - private static final String TAG = "ToolbarPhone"; |
| - |
| static final int LOCATION_BAR_TRANSPARENT_BACKGROUND_ALPHA = 51; |
| - private LocationBarPhone mPhoneLocationBar; |
| + private static final Interpolator NTP_SEARCH_BOX_EXPANSION_INTERPOLATOR = |
| + new FastOutSlowInInterpolator(); |
| + |
| + private LocationBarPhone mLocationBar; |
|
mcwilliams
2016/07/12 16:20:47
Possibly add a doc as to what the location bar is?
Bernhard Bauer
2016/07/12 16:54:38
Done.
|
| private ViewGroup mToolbarButtonsContainer; |
| private ImageView mToggleTabStackButton; |
| @@ -104,7 +107,7 @@ public class ToolbarPhone extends ToolbarLayout |
| private TintedImageButton mReturnButton; |
| private TintedImageButton mHomeButton; |
| private TextView mUrlBar; |
| - private View mUrlActionsContainer; |
| + private View mUrlActionContainer; |
| private ImageView mToolbarShadow; |
| private final int mProgressBackBackgroundColorWhite; |
| @@ -174,12 +177,13 @@ public class ToolbarPhone extends ToolbarLayout |
| private int mUnfocusedLocationBarLayoutLeft; |
| private boolean mUnfocusedLocationBarUsesTransparentBg; |
| - private int mUrlBackgroundAlpha = 255; |
| + private int mLocationBarBackgroundAlpha = 255; |
| private float mNtpSearchBoxScrollPercent = UNINITIALIZED_PERCENT; |
| private ColorDrawable mToolbarBackground; |
| - // The omnibox background (white with a shadow). |
| + /** The omnibox background (white with a shadow). */ |
| private Drawable mLocationBarBackground; |
| + |
| private boolean mForceDrawLocationBarBackground; |
| private TabSwitcherDrawable mTabSwitcherButtonDrawable; |
| private TabSwitcherDrawable mTabSwitcherButtonDrawableLight; |
| @@ -187,16 +191,30 @@ public class ToolbarPhone extends ToolbarLayout |
| private final int mLightModeDefaultColor; |
| private final int mDarkModeDefaultColor; |
| - private final Rect mUrlViewportBounds = new Rect(); |
| - private final Rect mUrlBackgroundPadding = new Rect(); |
| + /** The boundaries of the omnibox, without the NTP-specific offset applied. */ |
| + private final Rect mLocationBarBackgroundBounds = new Rect(); |
| + |
| + private final Rect mLocationBarBackgroundPadding = new Rect(); |
| private final Rect mBackgroundOverlayBounds = new Rect(); |
| - private final Rect mLocationBarBackgroundOffset = new Rect(); |
| - private final Rect mNtpSearchBoxOriginalBounds = new Rect(); |
| - private final Rect mNtpSearchBoxTransformedBounds = new Rect(); |
| + /** Offset applied to the bounds of the omnibox if we are showing a New Tab Page. */ |
| + private final Rect mLocationBarBackgroundNtpOffset = new Rect(); |
| + |
| + /** |
| + * Offsets applied to the <i>contents</i> of the omnibox if we are showing a New Tab Page. |
| + * This can be different from {@link #mLocationBarBackgroundNtpOffset} due to the fact that we |
| + * extend the omnibox horizontally beyond the screen boundaries when focused, to hide its |
| + * rounded corners. |
| + */ |
| + private float mLocationBarNtpOffsetLeft; |
| + private float mLocationBarNtpOffsetRight; |
| + |
| + private final Rect mNtpSearchBoxBounds = new Rect(); |
| + private final Point mNtpSearchBoxTranslation = new Point(); |
| - private final int mLocationBarInsets; |
| private final int mToolbarSidePadding; |
| + private final int mLocationBarVerticalMargin; |
| + private final int mLocationBarBackgroundCornerRadius; |
| private ValueAnimator mBrandColorTransitionAnimation; |
| private boolean mBrandColorTransitionActive; |
| @@ -277,9 +295,10 @@ public class ToolbarPhone extends ToolbarLayout |
| super(context, attrs); |
| mToolbarSidePadding = getResources().getDimensionPixelOffset( |
| R.dimen.toolbar_edge_padding); |
| - // Insets used for the PhoneLocatioBar background drawable. |
| - mLocationBarInsets = getResources().getDimensionPixelSize(R.dimen.location_bar_margin_top) |
| - + getResources().getDimensionPixelSize(R.dimen.location_bar_margin_bottom); |
| + mLocationBarVerticalMargin = |
| + getResources().getDimensionPixelOffset(R.dimen.location_bar_vertical_margin); |
| + mLocationBarBackgroundCornerRadius = |
|
mcwilliams
2016/07/12 16:20:47
Do we need Background in the name here?
Bernhard Bauer
2016/07/12 16:54:38
I've tried to name all members that are relevant f
|
| + getResources().getDimensionPixelOffset(R.dimen.location_bar_corner_radius); |
| mProgressBackBackgroundColorWhite = ApiCompatibilityUtils.getColor(getResources(), |
| R.color.progress_bar_background_white); |
| mLightModeDefaultColor = |
| @@ -291,7 +310,7 @@ public class ToolbarPhone extends ToolbarLayout |
| @Override |
| public void onFinishInflate() { |
| super.onFinishInflate(); |
| - mPhoneLocationBar = (LocationBarPhone) findViewById(R.id.location_bar); |
| + mLocationBar = (LocationBarPhone) findViewById(R.id.location_bar); |
| mToolbarButtonsContainer = (ViewGroup) findViewById(R.id.toolbar_buttons); |
| @@ -300,20 +319,20 @@ public class ToolbarPhone extends ToolbarLayout |
| mUrlBar = (TextView) findViewById(R.id.url_bar); |
| - mUrlActionsContainer = findViewById(R.id.url_action_container); |
| + mUrlActionContainer = findViewById(R.id.url_action_container); |
| - mBrowsingModeViews.add(mPhoneLocationBar); |
| + mBrowsingModeViews.add(mLocationBar); |
| mToolbarBackground = new ColorDrawable(getToolbarColorForVisualState(VisualState.NORMAL)); |
| mTabSwitcherAnimationBgOverlay = |
| new ColorDrawable(getToolbarColorForVisualState(VisualState.NORMAL)); |
| mLocationBarBackground = |
| - ApiCompatibilityUtils.getDrawable(getResources(), R.drawable.inset_textbox); |
| - mLocationBarBackground.getPadding(mUrlBackgroundPadding); |
| - mPhoneLocationBar.setPadding( |
| - mUrlBackgroundPadding.left, mUrlBackgroundPadding.top, |
| - mUrlBackgroundPadding.right, mUrlBackgroundPadding.bottom); |
| + ApiCompatibilityUtils.getDrawable(getResources(), R.drawable.textbox); |
| + mLocationBarBackground.getPadding(mLocationBarBackgroundPadding); |
| + mLocationBar.setPadding(mLocationBarBackgroundPadding.left, |
| + mLocationBarBackgroundPadding.top, mLocationBarBackgroundPadding.right, |
| + mLocationBarBackgroundPadding.bottom); |
| setLayoutTransition(null); |
| @@ -451,7 +470,7 @@ public class ToolbarPhone extends ToolbarLayout |
| }); |
| onHomeButtonUpdate(HomepageManager.isHomepageEnabled(getContext())); |
| - updateVisualsForToolbarState(mIsInTabSwitcherMode); |
| + updateVisualsForToolbarState(); |
| } |
| @Override |
| @@ -521,8 +540,8 @@ public class ToolbarPhone extends ToolbarLayout |
| private void updateUnfocusedLocationBarLayoutParams() { |
| boolean hasVisibleViewPriorToUrlBar = false; |
| - for (int i = 0; i < mPhoneLocationBar.getChildCount(); i++) { |
| - View child = mPhoneLocationBar.getChildAt(i); |
| + for (int i = 0; i < mLocationBar.getChildCount(); i++) { |
| + View child = mLocationBar.getChildAt(i); |
| if (child == mUrlBar) break; |
| if (child.getVisibility() != GONE) { |
| hasVisibleViewPriorToUrlBar = true; |
| @@ -534,11 +553,11 @@ public class ToolbarPhone extends ToolbarLayout |
| if (!hasVisibleViewPriorToUrlBar) leftViewBounds += mToolbarSidePadding; |
| int rightViewBounds = getViewBoundsRightOfLocationBar(mVisualState); |
| - if (!mPhoneLocationBar.hasVisibleViewsAfterUrlBarWhenUnfocused()) { |
| + if (!mLocationBar.hasVisibleViewsAfterUrlBarWhenUnfocused()) { |
| // Add spacing between the end of the URL and the edge of the omnibox drawable. |
| // This only applies if there is no end aligned view that should be visible |
| // while the omnibox is unfocused. |
| - if (ApiCompatibilityUtils.isLayoutRtl(mPhoneLocationBar)) { |
| + if (ApiCompatibilityUtils.isLayoutRtl(mLocationBar)) { |
| leftViewBounds += mToolbarSidePadding; |
| } else { |
| rightViewBounds -= mToolbarSidePadding; |
| @@ -585,15 +604,15 @@ public class ToolbarPhone extends ToolbarLayout |
| if (mLayoutLocationBarInFocusedMode || mVisualState == VisualState.NEW_TAB_NORMAL) { |
| int priorVisibleWidth = 0; |
| - for (int i = 0; i < mPhoneLocationBar.getChildCount(); i++) { |
| - View child = mPhoneLocationBar.getChildAt(i); |
| - if (child == mPhoneLocationBar.getFirstViewVisibleWhenFocused()) break; |
| + for (int i = 0; i < mLocationBar.getChildCount(); i++) { |
| + View child = mLocationBar.getChildAt(i); |
| + if (child == mLocationBar.getFirstViewVisibleWhenFocused()) break; |
| if (child.getVisibility() == GONE) continue; |
| priorVisibleWidth += child.getMeasuredWidth(); |
| } |
| width = containerWidth - (2 * mToolbarSidePadding) + priorVisibleWidth; |
| - if (ApiCompatibilityUtils.isLayoutRtl(mPhoneLocationBar)) { |
| + if (ApiCompatibilityUtils.isLayoutRtl(mLocationBar)) { |
| leftMargin = mToolbarSidePadding; |
| } else { |
| leftMargin = -priorVisibleWidth + mToolbarSidePadding; |
| @@ -688,8 +707,8 @@ public class ToolbarPhone extends ToolbarLayout |
| } |
| if (mLocationBarBackground != null |
| - && (mPhoneLocationBar.getVisibility() == VISIBLE || mTextureCaptureMode)) { |
| - updateUrlViewportBounds(mUrlViewportBounds, mVisualState, false); |
| + && (mLocationBar.getVisibility() == VISIBLE || mTextureCaptureMode)) { |
| + updateLocationBarBackgroundBounds(mLocationBarBackgroundBounds, mVisualState); |
| } |
| if (mTextureCaptureMode) { |
| @@ -743,32 +762,26 @@ public class ToolbarPhone extends ToolbarLayout |
| } |
| /** |
| - * Calculate the bounds for UrlViewport and set them to out rect. |
| + * Calculate the bounds for the location bar background and set them to the out param |
| + * {@code rect}. |
| */ |
| - private void updateUrlViewportBounds(Rect out, VisualState visualState, |
| - boolean ignoreTranslationY) { |
| - // Calculate the visible boundaries of the left and right most child views |
| - // of the location bar. |
| - int leftViewPosition = (int) MathUtils.interpolate( |
| - getViewBoundsLeftOfLocationBar(visualState), 0f, mUrlExpansionPercent) |
| - - mUrlBackgroundPadding.left; |
| - int rightViewPosition = (int) MathUtils.interpolate( |
| - getViewBoundsRightOfLocationBar(visualState), getWidth(), mUrlExpansionPercent) |
| - + mUrlBackgroundPadding.right; |
| - |
| + private void updateLocationBarBackgroundBounds(Rect out, VisualState visualState) { |
| + // Calculate the visible boundaries of the left and right most child views of the |
| + // location bar. |
| + float expansion = visualState == VisualState.NEW_TAB_NORMAL ? 1 : mUrlExpansionPercent; |
| // The bounds are set by the following: |
| // - The left most visible location bar child view. |
| // - The top of the viewport is aligned with the top of the location bar. |
| // - The right most visible location bar child view. |
| // - The bottom of the viewport is aligned with the bottom of the location bar. |
| // Additional padding can be applied for use during animations. |
| - float yOffset = ignoreTranslationY ? mPhoneLocationBar.getTop() : mPhoneLocationBar.getY(); |
| - |
| - out.set(leftViewPosition, |
| - (int) (yOffset - (mUrlBackgroundPadding.top * mUrlExpansionPercent)), |
| - rightViewPosition, |
| - (int) (yOffset + MathUtils.interpolate(mPhoneLocationBar.getMeasuredHeight(), |
| - getHeight() + mUrlBackgroundPadding.bottom, mUrlExpansionPercent))); |
| + int verticalMargin = (int) MathUtils.interpolate(mLocationBarVerticalMargin, 0, expansion); |
| + out.set((int) MathUtils.interpolate(getViewBoundsLeftOfLocationBar(visualState), |
| + -mLocationBarBackgroundCornerRadius, expansion), |
| + mLocationBar.getTop() + verticalMargin, |
| + (int) MathUtils.interpolate(getViewBoundsRightOfLocationBar(visualState), |
| + getWidth() + mLocationBarBackgroundCornerRadius, expansion), |
| + mLocationBar.getBottom() - verticalMargin); |
| } |
| /** |
| @@ -793,30 +806,54 @@ public class ToolbarPhone extends ToolbarLayout |
| return; |
| } |
| - mLocationBarBackgroundOffset.setEmpty(); |
| - |
| - FrameLayout.LayoutParams locationBarLayoutParams = |
| - getFrameLayoutParams(mPhoneLocationBar); |
| + FrameLayout.LayoutParams locationBarLayoutParams = getFrameLayoutParams(mLocationBar); |
| int currentLeftMargin = locationBarLayoutParams.leftMargin; |
| int currentWidth = locationBarLayoutParams.width; |
| - float inversePercent = 1f - mUrlExpansionPercent; |
| float locationBarTranslationX = mUnfocusedLocationBarLayoutLeft - currentLeftMargin; |
| - boolean isLocationBarRtl = ApiCompatibilityUtils.isLayoutRtl(mPhoneLocationBar); |
| + boolean isLocationBarRtl = ApiCompatibilityUtils.isLayoutRtl(mLocationBar); |
| if (isLocationBarRtl) { |
| locationBarTranslationX += mUnfocusedLocationBarLayoutWidth - currentWidth; |
| } |
| - locationBarTranslationX *= inversePercent; |
| + locationBarTranslationX *= 1f - mUrlExpansionPercent; |
| - mPhoneLocationBar.setTranslationX(locationBarTranslationX); |
| + mLocationBarBackgroundNtpOffset.setEmpty(); |
| + mLocationBarNtpOffsetLeft = 0; |
| + mLocationBarNtpOffsetRight = 0; |
| + |
| + Tab currentTab = getToolbarDataProvider().getTab(); |
| + if (currentTab != null) { |
| + NewTabPage ntp = getToolbarDataProvider().getNewTabPageForCurrentTab(); |
| + // Explicitly use the focus change percentage here because it applies scroll |
| + // compensation that only applies during focus animations. |
| + if (ntp != null && mUrlFocusChangeInProgress) { |
| + ntp.setUrlFocusChangeAnimationPercent(mUrlFocusChangePercent); |
| + } |
| + |
| + if (isLocationBarShownInNTP()) { |
| + updateNtpTransitionAnimation(); |
| + } else { |
| + // Reset these values in case we transitioned to a different page during the |
| + // transition. |
| + resetNtpAnimationValues(); |
| + } |
| + } |
| + |
| + // Get the padding straight from the location bar instead of |
| + // |mLocationBarBackgroundPadding|, because it might be different in incognito mode. |
| + mLocationBar.setTranslationX(locationBarTranslationX + mLocationBarNtpOffsetLeft |
| + + mLocationBar.getPaddingLeft()); |
| // Negate the location bar translation to keep the URL action container in the same |
| // place during the focus expansion. |
| + float urlActionsTranslationX = 0; |
| if (!isLocationBarRtl || ApiCompatibilityUtils.isLayoutRtl(this)) { |
| - mUrlActionsContainer.setTranslationX(-locationBarTranslationX); |
| + urlActionsTranslationX = -locationBarTranslationX; |
| } |
| + mUrlActionContainer.setTranslationX( |
| + urlActionsTranslationX + mLocationBarNtpOffsetRight - mLocationBarNtpOffsetLeft); |
| - mPhoneLocationBar.setUrlFocusChangePercent(mUrlExpansionPercent); |
| + mLocationBar.setUrlFocusChangePercent(mUrlExpansionPercent); |
| // Ensure the buttons are invisible after focusing the omnibox to prevent them from |
| // accepting click events. |
| @@ -831,45 +868,26 @@ public class ToolbarPhone extends ToolbarLayout |
| // Force an invalidation of the location bar to properly handle the clipping of the URL |
| // bar text as a result of the url action container translations. |
| - mPhoneLocationBar.invalidate(); |
| + mLocationBar.invalidate(); |
| invalidate(); |
| - |
| - Tab currentTab = getToolbarDataProvider().getTab(); |
| - if (currentTab == null) return; |
| - |
| - NewTabPage ntp = getToolbarDataProvider().getNewTabPageForCurrentTab(); |
| - // Explicitly use the focus change percentage here because it applies scroll compensation |
| - // that only applies during focus animations. |
| - if (ntp != null && mUrlFocusChangeInProgress) { |
| - ntp.setUrlFocusChangeAnimationPercent(mUrlFocusChangePercent); |
| - } |
| - |
| - if (!isLocationBarShownInNTP()) { |
| - // Reset these values in case we transitioned to a different page during the |
| - // transition. |
| - resetNtpAnimationValues(); |
| - return; |
| - } |
| - |
| - updateNtpTransitionAnimation(); |
| } |
|
mcwilliams
2016/07/12 16:20:47
Documentation
Bernhard Bauer
2016/07/12 16:54:38
Done.
|
| private void resetNtpAnimationValues() { |
| - mLocationBarBackgroundOffset.setEmpty(); |
| - mPhoneLocationBar.setTranslationY(0); |
| + mLocationBarBackgroundNtpOffset.setEmpty(); |
| + mLocationBar.setTranslationY(0); |
| if (!mUrlFocusChangeInProgress) { |
| mToolbarButtonsContainer.setTranslationY(0); |
| mReturnButton.setTranslationY(0); |
| mHomeButton.setTranslationY(0); |
| } |
| mToolbarShadow.setAlpha(1f); |
| - mPhoneLocationBar.setAlpha(1); |
| + mLocationBar.setAlpha(1); |
| mForceDrawLocationBarBackground = false; |
| - mUrlBackgroundAlpha = isIncognito() |
| - || (mUnfocusedLocationBarUsesTransparentBg |
| - && !mUrlFocusChangeInProgress |
| - && !mPhoneLocationBar.hasFocus()) |
| - ? LOCATION_BAR_TRANSPARENT_BACKGROUND_ALPHA : 255; |
| + mLocationBarBackgroundAlpha = |
| + isIncognito() || (mUnfocusedLocationBarUsesTransparentBg |
| + && !mUrlFocusChangeInProgress && !mLocationBar.hasFocus()) |
| + ? LOCATION_BAR_TRANSPARENT_BACKGROUND_ALPHA |
| + : 255; |
| setAncestorsShouldClipChildren(true); |
| mNtpSearchBoxScrollPercent = UNINITIALIZED_PERCENT; |
| updateUrlExpansionPercent(); |
| @@ -878,66 +896,58 @@ public class ToolbarPhone extends ToolbarLayout |
| private void updateNtpTransitionAnimation() { |
| if (mIsInTabSwitcherMode) return; |
| - NewTabPage ntp = getToolbarDataProvider().getNewTabPageForCurrentTab(); |
| - |
| setAncestorsShouldClipChildren(mUrlExpansionPercent == 0f); |
| mToolbarShadow.setAlpha(0f); |
| - float growthPercent = 0f; |
| - if (ntp.isCardsUiEnabled() || mUrlExpansionPercent == 0f || mUrlExpansionPercent == 1f) { |
| - growthPercent = 1f - mUrlExpansionPercent; |
| - } else { |
| - // During the transition from search box to omnibox, keep the omnibox drawing |
| - // at the same size of the search box for first 40% of the scroll transition. |
| - growthPercent = mUrlExpansionPercent <= 0.4f |
| - ? 1f : Math.min(1f, (1f - mUrlExpansionPercent) * 1.66667f); |
| - } |
| - |
| - int paddingTop = mPhoneLocationBar.getPaddingTop(); |
| - int paddingBottom = mPhoneLocationBar.getPaddingBottom(); |
| - |
| - ntp.getSearchBoxBounds(mNtpSearchBoxOriginalBounds, mNtpSearchBoxTransformedBounds); |
| - float halfHeightDifference = (mNtpSearchBoxTransformedBounds.height() |
| - - (mPhoneLocationBar.getMeasuredHeight() - paddingTop - paddingBottom |
| - + mLocationBarInsets)) / 2f; |
| - mPhoneLocationBar.setTranslationY(growthPercent == 0f ? 0 : Math.max(0, |
| - (mNtpSearchBoxTransformedBounds.top - mPhoneLocationBar.getTop() |
| - + halfHeightDifference))); |
| + NewTabPage ntp = getToolbarDataProvider().getNewTabPageForCurrentTab(); |
| + ntp.getSearchBoxBounds(mNtpSearchBoxBounds, mNtpSearchBoxTranslation); |
| + int locationBarTranslationY = |
| + Math.max(0, (mNtpSearchBoxBounds.top - mLocationBar.getTop())); |
| + mLocationBar.setTranslationY(locationBarTranslationY); |
| if (!mUrlFocusChangeInProgress) { |
| setButtonsTranslationY(); |
| } |
| - mLocationBarBackgroundOffset.set( |
| - (int) ((mNtpSearchBoxTransformedBounds.left - mUrlViewportBounds.left |
| - - mPhoneLocationBar.getPaddingLeft()) * growthPercent), |
| - (int) ((-halfHeightDifference - paddingTop) * growthPercent), |
| - (int) ((mNtpSearchBoxTransformedBounds.right - mUrlViewportBounds.right |
| - + mPhoneLocationBar.getPaddingRight()) * growthPercent), |
| - (int) ((halfHeightDifference - paddingBottom + mLocationBarInsets) |
| - * growthPercent)); |
| - |
| - // The transparency of the location bar is dependent on how different its size is |
| - // from the final value. This is based on how much growth is applied between the |
| - // desired size of the location bar to its drawn size. The location bar then only |
| - // starts becoming opaque once the growth is at least half done. |
| - if (growthPercent >= 0.5f) { |
| - mPhoneLocationBar.setAlpha(0); |
| + // Linearly interpolate between the bounds of the search box on the NTP and the omnibox |
| + // background bounds. |shrinkage| is the scaling factor for the offset -- if it's 1, we are |
| + // shrinking the omnibox down to the size of the search box. |
| + float shrinkage; |
| + if (ntp.isCardsUiEnabled()) { |
| + shrinkage = 1f |
| + - NTP_SEARCH_BOX_EXPANSION_INTERPOLATOR.getInterpolation(mUrlExpansionPercent); |
| } else { |
| - mPhoneLocationBar.setAlpha(1f - growthPercent * 2); |
| + // During the transition from middle of the NTP to the top, keep the omnibox drawing |
| + // at the same size of the search box for first 40% of the scroll transition. |
| + shrinkage = Math.min(1f, (1f - mUrlExpansionPercent) * 1.66667f); |
| } |
| - // Go from a transparent url background to a fully opaque one in the first 40% of the |
| - // scroll transition. |
| - mUrlBackgroundAlpha = |
| - mUrlExpansionPercent >= 0.4f ? 255 : (int) ((mUrlExpansionPercent * 2.5f) * 255); |
| - if (mUrlExpansionPercent == 1f) mUrlBackgroundAlpha = 255; |
| - mForceDrawLocationBarBackground = mUrlExpansionPercent != 0f; |
| + int leftBoundDifference = mNtpSearchBoxBounds.left - mLocationBarBackgroundBounds.left; |
| + int rightBoundDifference = mNtpSearchBoxBounds.right - mLocationBarBackgroundBounds.right; |
| + mLocationBarBackgroundNtpOffset.set( |
| + (int) Math.round(leftBoundDifference * shrinkage), |
| + locationBarTranslationY, |
| + (int) Math.round(rightBoundDifference * shrinkage), |
| + locationBarTranslationY); |
| + |
| + // The omnibox background bounds are outset by |mLocationBarBackgroundCornerRadius| in the |
| + // fully expanded state (and only there!) to hide the rounded corners, so undo that before |
| + // applying the shrinkage factor. |
| + mLocationBarNtpOffsetLeft = |
| + (leftBoundDifference - mLocationBarBackgroundCornerRadius) * shrinkage; |
| + mLocationBarNtpOffsetRight = |
| + (rightBoundDifference + mLocationBarBackgroundCornerRadius) * shrinkage; |
| + |
| + mLocationBarBackgroundAlpha = mUrlExpansionPercent > 0f ? 255 : 0; |
| + mForceDrawLocationBarBackground = mLocationBarBackgroundAlpha > 0; |
| + float relativeAlpha = mLocationBarBackgroundAlpha / 255f; |
| + mLocationBar.setAlpha(relativeAlpha); |
| + |
| + // The search box on the NTP is visible if our omnibox is invisible, and vice-versa. |
| + ntp.setSearchBoxAlpha(1f - relativeAlpha); |
| } |
| private void setButtonsTranslationY() { |
| - float searchBoxTranslationY = |
| - mNtpSearchBoxTransformedBounds.top - mNtpSearchBoxOriginalBounds.top; |
| - searchBoxTranslationY = Math.min(searchBoxTranslationY, 0); |
| + int searchBoxTranslationY = Math.min(mNtpSearchBoxTranslation.y, 0); |
| mToolbarButtonsContainer.setTranslationY(searchBoxTranslationY); |
| mReturnButton.setTranslationY(searchBoxTranslationY); |
| mHomeButton.setTranslationY(searchBoxTranslationY); |
| @@ -994,13 +1004,13 @@ public class ToolbarPhone extends ToolbarLayout |
| } |
| // Draw the location/URL bar. |
| - previousAlpha = mPhoneLocationBar.getAlpha(); |
| - mPhoneLocationBar.setAlpha(previousAlpha * floatAlpha); |
| + previousAlpha = mLocationBar.getAlpha(); |
| + mLocationBar.setAlpha(previousAlpha * floatAlpha); |
| // If the location bar is now fully transparent, do not bother drawing it. |
| - if (mPhoneLocationBar.getAlpha() != 0) { |
| - drawChild(canvas, mPhoneLocationBar, SystemClock.uptimeMillis()); |
| + if (mLocationBar.getAlpha() != 0) { |
| + drawChild(canvas, mLocationBar, SystemClock.uptimeMillis()); |
| } |
| - mPhoneLocationBar.setAlpha(previousAlpha); |
| + mLocationBar.setAlpha(previousAlpha); |
| // Draw the tab stack button and associated text. |
| translateCanvasToView(this, mToolbarButtonsContainer, canvas); |
| @@ -1092,14 +1102,18 @@ public class ToolbarPhone extends ToolbarLayout |
| @Override |
| protected boolean drawChild(Canvas canvas, View child, long drawingTime) { |
| - if (child == mPhoneLocationBar) return drawLocationBar(canvas, drawingTime); |
| + if (child == mLocationBar) return drawLocationBar(canvas, drawingTime); |
| boolean clipped = false; |
| if (mLocationBarBackground != null |
| && ((!mIsInTabSwitcherMode && !mTabSwitcherModeViews.contains(child)) |
| || (mIsInTabSwitcherMode && mBrowsingModeViews.contains(child)))) { |
| canvas.save(); |
| - if (mUrlExpansionPercent != 0f && mUrlViewportBounds.top < child.getBottom()) { |
| + |
| + int translationY = (int) mLocationBar.getTranslationY(); |
| + int clipTop = mLocationBarBackgroundBounds.top - mLocationBarBackgroundPadding.top |
| + + translationY; |
| + if (mUrlExpansionPercent != 0f && clipTop < child.getBottom()) { |
| // For other child views, use the inverse clipping of the URL viewport. |
| // Only necessary during animations. |
| // Hardware mode does not support unioned clip regions, so clip using the |
| @@ -1108,24 +1122,24 @@ public class ToolbarPhone extends ToolbarLayout |
| boolean isLeft = (child == mNewTabButton || child == mReturnButton |
| || child == mHomeButton) ^ LocalizationUtils.isLayoutRtl(); |
| - int clipTop = mUrlViewportBounds.top; |
| - int clipBottom = mUrlViewportBounds.bottom; |
| + int clipBottom = mLocationBarBackgroundBounds.bottom |
| + + mLocationBarBackgroundPadding.bottom + translationY; |
| boolean verticalClip = false; |
| - if (mPhoneLocationBar.getTranslationY() > 0f) { |
| + if (translationY > 0f) { |
| clipTop = child.getTop(); |
| - clipBottom = mUrlViewportBounds.top; |
| + clipBottom = clipTop; |
| verticalClip = true; |
| } |
| if (isLeft) { |
| - canvas.clipRect( |
| - 0, clipTop, |
| - verticalClip ? child.getMeasuredWidth() : mUrlViewportBounds.left, |
| - clipBottom); |
| + int clipRight = verticalClip ? child.getMeasuredWidth() |
| + : mLocationBarBackgroundBounds.left |
| + - mLocationBarBackgroundPadding.left; |
| + canvas.clipRect(0, clipTop, clipRight, clipBottom); |
| } else { |
| - canvas.clipRect( |
| - verticalClip ? 0 : mUrlViewportBounds.right, |
| - clipTop, getMeasuredWidth(), clipBottom); |
| + int clipLeft = verticalClip ? 0 : mLocationBarBackgroundBounds.right |
| + + mLocationBarBackgroundPadding.right; |
| + canvas.clipRect(clipLeft, clipTop, getMeasuredWidth(), clipBottom); |
| } |
| } |
| clipped = true; |
| @@ -1145,7 +1159,7 @@ public class ToolbarPhone extends ToolbarLayout |
| // Fade out/in the location bar towards the beginning of the animations to avoid |
| // large jumps of stark white. |
| backgroundAlpha = |
| - (int) (Math.pow(mPhoneLocationBar.getAlpha(), 3) * mUrlBackgroundAlpha); |
| + (int) (Math.pow(mLocationBar.getAlpha(), 3) * mLocationBarBackgroundAlpha); |
| } else if (getToolbarDataProvider().isUsingBrandColor() |
| && !mBrandColorTransitionActive) { |
| backgroundAlpha = mUnfocusedLocationBarUsesTransparentBg |
| @@ -1153,28 +1167,32 @@ public class ToolbarPhone extends ToolbarLayout |
| 255, mUrlExpansionPercent)) |
| : 255; |
| } else { |
| - backgroundAlpha = mUrlBackgroundAlpha; |
| + backgroundAlpha = mLocationBarBackgroundAlpha; |
| } |
| mLocationBarBackground.setAlpha(backgroundAlpha); |
| - if ((mPhoneLocationBar.getAlpha() > 0 || mForceDrawLocationBarBackground) |
| + if ((mLocationBar.getAlpha() > 0 || mForceDrawLocationBarBackground) |
| && !mTextureCaptureMode) { |
| - mLocationBarBackground.setBounds( |
| - mUrlViewportBounds.left + mLocationBarBackgroundOffset.left, |
| - mUrlViewportBounds.top + mLocationBarBackgroundOffset.top, |
| - mUrlViewportBounds.right + mLocationBarBackgroundOffset.right, |
| - mUrlViewportBounds.bottom + mLocationBarBackgroundOffset.bottom); |
| + mLocationBarBackground.setBounds(mLocationBarBackgroundBounds.left |
| + + mLocationBarBackgroundNtpOffset.left |
| + - mLocationBarBackgroundPadding.left, |
| + mLocationBarBackgroundBounds.top + mLocationBarBackgroundNtpOffset.top |
| + - mLocationBarBackgroundPadding.top, |
| + mLocationBarBackgroundBounds.right + mLocationBarBackgroundNtpOffset.right |
| + + mLocationBarBackgroundPadding.right, |
| + mLocationBarBackgroundBounds.bottom + mLocationBarBackgroundNtpOffset.bottom |
| + + mLocationBarBackgroundPadding.bottom); |
| mLocationBarBackground.draw(canvas); |
| } |
| - float locationBarClipLeft = mUrlViewportBounds.left |
| - + mPhoneLocationBar.getPaddingLeft() + mLocationBarBackgroundOffset.left; |
| - float locationBarClipRight = mUrlViewportBounds.right |
| - - mPhoneLocationBar.getPaddingRight() + mLocationBarBackgroundOffset.right; |
| - float locationBarClipTop = mUrlViewportBounds.top + mPhoneLocationBar.getPaddingTop() |
| - + mLocationBarBackgroundOffset.top; |
| - float locationBarClipBottom = mUrlViewportBounds.bottom |
| - - mPhoneLocationBar.getPaddingBottom() + mLocationBarBackgroundOffset.bottom; |
| + float locationBarClipLeft = |
| + mLocationBarBackgroundBounds.left + mLocationBarBackgroundNtpOffset.left; |
| + float locationBarClipRight = |
| + mLocationBarBackgroundBounds.right + mLocationBarBackgroundNtpOffset.right; |
| + float locationBarClipTop = |
| + mLocationBarBackgroundBounds.top + mLocationBarBackgroundNtpOffset.top; |
| + float locationBarClipBottom = |
| + mLocationBarBackgroundBounds.bottom + mLocationBarBackgroundNtpOffset.bottom; |
| // When unexpanded, the location bar's visible content boundaries are inset from the |
| // viewport used to draw the background. During expansion transitions, compensation |
| @@ -1198,7 +1216,7 @@ public class ToolbarPhone extends ToolbarLayout |
| clipped = true; |
| } |
| - boolean retVal = super.drawChild(canvas, mPhoneLocationBar, drawingTime); |
| + boolean retVal = super.drawChild(canvas, mLocationBar, drawingTime); |
| if (clipped) canvas.restore(); |
| return retVal; |
| @@ -1295,23 +1313,17 @@ public class ToolbarPhone extends ToolbarLayout |
| // The Android framework calls onAnimationEnd() on listeners before Animator#isRunning() |
| // returns false. Sometimes this causes the progress bar visibility to be set incorrectly. |
| // Update the visibility now that animations are set to null. (see crbug.com/606419) |
| - updateProgressBarVisibility(mIsInTabSwitcherMode); |
| + updateProgressBarVisibility(); |
| } |
| @Override |
| public void getLocationBarContentRect(Rect outRect) { |
| - mLocationBarBackground.getPadding(outRect); |
| - int paddingLeft = outRect.left; |
| - int paddingTop = outRect.top; |
| - int paddingRight = outRect.right; |
| - int paddingBottom = outRect.bottom; |
| - |
| - updateUrlViewportBounds(outRect, VisualState.NORMAL, true); |
| + updateLocationBarBackgroundBounds(outRect, VisualState.NORMAL); |
| - outRect.set(outRect.left + paddingLeft, |
| - outRect.top + paddingTop, |
| - outRect.right - paddingRight, |
| - outRect.bottom - paddingBottom); |
| + outRect.set(outRect.left + mLocationBarBackgroundPadding.left, |
| + outRect.top + mLocationBarBackgroundPadding.top, |
| + outRect.right - mLocationBarBackgroundPadding.right, |
| + outRect.bottom - mLocationBarBackgroundPadding.bottom); |
| } |
| @Override |
| @@ -1376,7 +1388,7 @@ public class ToolbarPhone extends ToolbarLayout |
| exitAnimation.addListener(new AnimatorListenerAdapter() { |
| @Override |
| public void onAnimationEnd(Animator animation) { |
| - updateViewsForTabSwitcherMode(mIsInTabSwitcherMode); |
| + updateViewsForTabSwitcherMode(); |
| } |
| }); |
| @@ -1391,7 +1403,7 @@ public class ToolbarPhone extends ToolbarLayout |
| exitAnimation.addListener(new AnimatorListenerAdapter() { |
| @Override |
| public void onAnimationStart(Animator animation) { |
| - updateViewsForTabSwitcherMode(mIsInTabSwitcherMode); |
| + updateViewsForTabSwitcherMode(); |
| // On older builds, force an update to ensure the new visuals are used |
| // when bringing in the toolbar. crbug.com/404571 |
| if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN) { |
| @@ -1402,8 +1414,8 @@ public class ToolbarPhone extends ToolbarLayout |
| @Override |
| public void onAnimationEnd(Animator animation) { |
| mDelayedTabSwitcherModeAnimation = null; |
| - updateShadowVisibility(mIsInTabSwitcherMode); |
| - updateViewsForTabSwitcherMode(mIsInTabSwitcherMode); |
| + updateShadowVisibility(); |
| + updateViewsForTabSwitcherMode(); |
| } |
| }); |
| @@ -1420,7 +1432,7 @@ public class ToolbarPhone extends ToolbarLayout |
| setAlpha(1); |
| } else { |
| setAlpha(mPreTextureCaptureAlpha); |
| - updateShadowVisibility(mIsInTabSwitcherMode); |
| + updateShadowVisibility(); |
| mPreTextureCaptureAlpha = 1f; |
| } |
| } |
| @@ -1432,9 +1444,9 @@ public class ToolbarPhone extends ToolbarLayout |
| && mDelayedTabSwitcherModeAnimation.isRunning()); |
| } |
| - private void updateViewsForTabSwitcherMode(boolean isInTabSwitcherMode) { |
| - int tabSwitcherViewsVisibility = isInTabSwitcherMode ? VISIBLE : INVISIBLE; |
| - int browsingViewsVisibility = isInTabSwitcherMode ? INVISIBLE : VISIBLE; |
| + private void updateViewsForTabSwitcherMode() { |
| + int tabSwitcherViewsVisibility = mIsInTabSwitcherMode ? VISIBLE : INVISIBLE; |
| + int browsingViewsVisibility = mIsInTabSwitcherMode ? INVISIBLE : VISIBLE; |
| for (View view : mTabSwitcherModeViews) { |
| view.setVisibility(tabSwitcherViewsVisibility); |
| @@ -1443,27 +1455,28 @@ public class ToolbarPhone extends ToolbarLayout |
| view.setVisibility(browsingViewsVisibility); |
| } |
| if (mShowMenuBadge) { |
| - setMenuButtonContentDescription(!isInTabSwitcherMode); |
| + setMenuButtonContentDescription(!mIsInTabSwitcherMode); |
| } |
| - updateProgressBarVisibility(isInTabSwitcherMode); |
| - updateVisualsForToolbarState(isInTabSwitcherMode); |
| + updateProgressBarVisibility(); |
| + updateVisualsForToolbarState(); |
| } |
| - private void updateProgressBarVisibility(boolean isInTabSwitcherMode) { |
| + private void updateProgressBarVisibility() { |
| getProgressBar().setVisibility( |
| - isInTabSwitcherMode || isTabSwitcherAnimationRunning() ? INVISIBLE : VISIBLE); |
| + mIsInTabSwitcherMode || isTabSwitcherAnimationRunning() ? INVISIBLE : VISIBLE); |
| } |
| @Override |
| protected void setContentAttached(boolean attached) { |
| - updateVisualsForToolbarState(mIsInTabSwitcherMode); |
| + updateVisualsForToolbarState(); |
| } |
| @Override |
| protected void setTabSwitcherMode( |
| boolean inTabSwitcherMode, boolean showToolbar, boolean delayAnimation) { |
| if (mIsInTabSwitcherMode == inTabSwitcherMode) return; |
| + mIsInTabSwitcherMode = inTabSwitcherMode; |
| finishAnimations(); |
| @@ -1480,7 +1493,7 @@ public class ToolbarPhone extends ToolbarLayout |
| updateUrlExpansionAnimation(); |
| } |
| mNewTabButton.setEnabled(true); |
| - updateViewsForTabSwitcherMode(true); |
| + updateViewsForTabSwitcherMode(); |
| mTabSwitcherModeAnimation = createEnterTabSwitcherModeAnimation(); |
| } else { |
| if (!mDelayingTabSwitcherAnimation) { |
| @@ -1490,7 +1503,6 @@ public class ToolbarPhone extends ToolbarLayout |
| } |
| mAnimateNormalToolbar = showToolbar; |
| - mIsInTabSwitcherMode = inTabSwitcherMode; |
| if (mTabSwitcherModeAnimation != null) mTabSwitcherModeAnimation.start(); |
| if (SysUtils.isLowEndDevice()) finishAnimations(); |
| @@ -1507,7 +1519,7 @@ public class ToolbarPhone extends ToolbarLayout |
| if (!mAnimateNormalToolbar) { |
| finishAnimations(); |
| - updateVisualsForToolbarState(mIsInTabSwitcherMode); |
| + updateVisualsForToolbarState(); |
| } |
| if (mDelayingTabSwitcherAnimation) { |
| @@ -1515,11 +1527,11 @@ public class ToolbarPhone extends ToolbarLayout |
| mDelayedTabSwitcherModeAnimation = createPostExitTabSwitcherAnimation(); |
| mDelayedTabSwitcherModeAnimation.start(); |
| } else { |
| - updateViewsForTabSwitcherMode(mIsInTabSwitcherMode); |
| + updateViewsForTabSwitcherMode(); |
| } |
| } |
| - private void updateOverlayDrawables(boolean isInTabSwitcherMode) { |
| + private void updateOverlayDrawables() { |
| if (!isNativeLibraryReady()) return; |
| VisualState overlayState = computeVisualState(false); |
| @@ -1539,7 +1551,7 @@ public class ToolbarPhone extends ToolbarLayout |
| setTabSwitcherAnimationMenuDrawable(); |
| setUseLightDrawablesForTextureCapture(); |
| - if (!isInTabSwitcherMode && !mTextureCaptureMode && mLayoutUpdateHost != null) { |
| + if (!mIsInTabSwitcherMode && !mTextureCaptureMode && mLayoutUpdateHost != null) { |
| // Request a layout update to trigger a texture capture if the tint color is changing |
| // and we're not already in texture capture mode. This is necessary if the tab switcher |
| // is entered immediately after a change to the tint color without any user interactions |
| @@ -1605,9 +1617,9 @@ public class ToolbarPhone extends ToolbarLayout |
| animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE); |
| animators.add(animator); |
| - for (int i = 0; i < mPhoneLocationBar.getChildCount(); i++) { |
| - View childView = mPhoneLocationBar.getChildAt(i); |
| - if (childView == mPhoneLocationBar.getFirstViewVisibleWhenFocused()) break; |
| + for (int i = 0; i < mLocationBar.getChildCount(); i++) { |
| + View childView = mLocationBar.getChildAt(i); |
| + if (childView == mLocationBar.getFirstViewVisibleWhenFocused()) break; |
| animator = ObjectAnimator.ofFloat(childView, ALPHA, 0); |
| animator.setDuration(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS); |
| animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE); |
| @@ -1676,9 +1688,9 @@ public class ToolbarPhone extends ToolbarLayout |
| animators.add(animator); |
| } |
| - for (int i = 0; i < mPhoneLocationBar.getChildCount(); i++) { |
| - View childView = mPhoneLocationBar.getChildAt(i); |
| - if (childView == mPhoneLocationBar.getFirstViewVisibleWhenFocused()) break; |
| + for (int i = 0; i < mLocationBar.getChildCount(); i++) { |
| + View childView = mLocationBar.getChildAt(i); |
| + if (childView == mLocationBar.getFirstViewVisibleWhenFocused()) break; |
| animator = ObjectAnimator.ofFloat(childView, ALPHA, 1); |
| animator.setStartDelay(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS); |
| animator.setDuration(URL_CLEAR_FOCUS_MENU_DELAY_MS); |
| @@ -1691,7 +1703,7 @@ public class ToolbarPhone extends ToolbarLayout |
| // The call to getLayout() can return null briefly during text changes, but as it |
| // is only needed for RTL calculations, we proceed if the location bar is showing |
| // LTR content. |
| - boolean isLocationBarRtl = ApiCompatibilityUtils.isLayoutRtl(mPhoneLocationBar); |
| + boolean isLocationBarRtl = ApiCompatibilityUtils.isLayoutRtl(mLocationBar); |
| if (!isLocationBarRtl || mUrlBar.getLayout() != null) { |
| int urlBarStartScrollX = 0; |
| if (isLocationBarRtl) { |
| @@ -1704,10 +1716,8 @@ public class ToolbarPhone extends ToolbarLayout |
| // back to page URLs (despite it continually calling setScrollX with the same |
| // number). |
| if (mUrlBar.getScrollX() != urlBarStartScrollX) { |
| - animator = ObjectAnimator.ofInt( |
| - mUrlBar, |
| - buildUrlScrollProperty(mPhoneLocationBar, isLocationBarRtl), |
| - urlBarStartScrollX); |
| + animator = ObjectAnimator.ofInt(mUrlBar, |
| + buildUrlScrollProperty(mLocationBar, isLocationBarRtl), urlBarStartScrollX); |
| animator.setDuration(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS); |
| animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE); |
| animators.add(animator); |
| @@ -1783,7 +1793,7 @@ public class ToolbarPhone extends ToolbarLayout |
| mLayoutLocationBarInFocusedMode = false; |
| requestLayout(); |
| } |
| - mPhoneLocationBar.finishUrlFocusChange(hasFocus); |
| + mLocationBar.finishUrlFocusChange(hasFocus); |
| mUrlFocusChangeInProgress = false; |
| } |
| }); |
| @@ -1796,7 +1806,7 @@ public class ToolbarPhone extends ToolbarLayout |
| // allows the menu to translate off the screen on scroll to match the tabbed behavior. |
| if (mVisualState == VisualState.NEW_TAB_NORMAL) return true; |
| - return !mPhoneLocationBar.showMenuButtonInOmnibox() && super.shouldShowMenuButton(); |
| + return !mLocationBar.showMenuButtonInOmnibox() && super.shouldShowMenuButton(); |
| } |
| @Override |
| @@ -1836,14 +1846,14 @@ public class ToolbarPhone extends ToolbarLayout |
| protected void onTabContentViewChanged() { |
| super.onTabContentViewChanged(); |
| updateNtpAnimationState(); |
| - updateVisualsForToolbarState(mIsInTabSwitcherMode); |
| + updateVisualsForToolbarState(); |
| } |
| @Override |
| protected void onTabOrModelChanged() { |
| super.onTabOrModelChanged(); |
| updateNtpAnimationState(); |
| - updateVisualsForToolbarState(mIsInTabSwitcherMode); |
| + updateVisualsForToolbarState(); |
| if (mHasCheckedIfTabSwitcherCalloutIsNecessary) { |
| dismissTabSwitcherCallout(); |
| @@ -1869,7 +1879,7 @@ public class ToolbarPhone extends ToolbarLayout |
| if (initialColor == finalColor) return; |
| boolean shouldUseOpaque = ColorUtils.shouldUseOpaqueTextboxBackground(finalColor); |
| - final int initialAlpha = mUrlBackgroundAlpha; |
| + final int initialAlpha = mLocationBarBackgroundAlpha; |
| final int finalAlpha = |
| shouldUseOpaque ? 255 : LOCATION_BAR_TRANSPARENT_BACKGROUND_ALPHA; |
| final boolean shouldAnimateAlpha = initialAlpha != finalAlpha; |
| @@ -1881,7 +1891,7 @@ public class ToolbarPhone extends ToolbarLayout |
| public void onAnimationUpdate(ValueAnimator animation) { |
| float fraction = animation.getAnimatedFraction(); |
| if (shouldAnimateAlpha) { |
| - mUrlBackgroundAlpha = |
| + mLocationBarBackgroundAlpha = |
| (int) (MathUtils.interpolate(initialAlpha, finalAlpha, fraction)); |
| } |
| updateToolbarBackground( |
| @@ -1892,7 +1902,7 @@ public class ToolbarPhone extends ToolbarLayout |
| @Override |
| public void onAnimationEnd(Animator animation) { |
| mBrandColorTransitionActive = false; |
| - updateVisualsForToolbarState(mIsInTabSwitcherMode); |
| + updateVisualsForToolbarState(); |
| } |
| }); |
| mBrandColorTransitionAnimation.start(); |
| @@ -1938,7 +1948,7 @@ public class ToolbarPhone extends ToolbarLayout |
| post(new Runnable() { |
| @Override |
| public void run() { |
| - updateVisualsForToolbarState(mIsInTabSwitcherMode); |
| + updateVisualsForToolbarState(); |
| updateNtpAnimationState(); |
| } |
| }); |
| @@ -1960,8 +1970,8 @@ public class ToolbarPhone extends ToolbarLayout |
| return ntp != null && ntp.isLocationBarShownInNTP(); |
| } |
| - private void updateShadowVisibility(boolean isInTabSwitcherMode) { |
| - boolean shouldDrawShadow = !isInTabSwitcherMode && !isTabSwitcherAnimationRunning(); |
| + private void updateShadowVisibility() { |
| + boolean shouldDrawShadow = !mIsInTabSwitcherMode && !isTabSwitcherAnimationRunning(); |
| int shadowVisibility = shouldDrawShadow ? View.VISIBLE : View.INVISIBLE; |
| if (mToolbarShadow.getVisibility() != shadowVisibility) { |
| @@ -1978,10 +1988,10 @@ public class ToolbarPhone extends ToolbarLayout |
| return VisualState.NORMAL; |
| } |
| - private void updateVisualsForToolbarState(boolean isInTabSwitcherMode) { |
| + private void updateVisualsForToolbarState() { |
| final boolean isIncognito = isIncognito(); |
| - VisualState newVisualState = computeVisualState(isInTabSwitcherMode); |
| + VisualState newVisualState = computeVisualState(mIsInTabSwitcherMode); |
| // If we are navigating to or from a brand color, allow the transition animation |
| // to run to completion as it will handle the triggering this path again and committing |
| @@ -2026,8 +2036,9 @@ public class ToolbarPhone extends ToolbarLayout |
| mVisualState = newVisualState; |
| - updateOverlayDrawables(isInTabSwitcherMode); |
| - updateShadowVisibility(isInTabSwitcherMode); |
| + updateOverlayDrawables(); |
| + updateShadowVisibility(); |
| + updateUrlExpansionAnimation(); |
| if (!visualStateChanged) { |
| if (mVisualState == VisualState.NEW_TAB_NORMAL) { |
| updateNtpTransitionAnimation(); |
| @@ -2037,26 +2048,27 @@ public class ToolbarPhone extends ToolbarLayout |
| mUseLightToolbarDrawables = false; |
| mUnfocusedLocationBarUsesTransparentBg = false; |
| - mUrlBackgroundAlpha = 255; |
| + mLocationBarBackgroundAlpha = 255; |
| updateToolbarBackground(mVisualState); |
| getProgressBar().setThemeColor(themeColorForProgressBar, isIncognito()); |
| - if (isInTabSwitcherMode) { |
| + if (mIsInTabSwitcherMode) { |
| mUseLightToolbarDrawables = true; |
| - mUrlBackgroundAlpha = LOCATION_BAR_TRANSPARENT_BACKGROUND_ALPHA; |
| + mLocationBarBackgroundAlpha = LOCATION_BAR_TRANSPARENT_BACKGROUND_ALPHA; |
| getProgressBar().setBackgroundColor(mProgressBackBackgroundColorWhite); |
| getProgressBar().setForegroundColor(ApiCompatibilityUtils.getColor(getResources(), |
| R.color.progress_bar_foreground_white)); |
| } else if (isIncognito()) { |
| mUseLightToolbarDrawables = true; |
| - mUrlBackgroundAlpha = LOCATION_BAR_TRANSPARENT_BACKGROUND_ALPHA; |
| + mLocationBarBackgroundAlpha = LOCATION_BAR_TRANSPARENT_BACKGROUND_ALPHA; |
| } else if (mVisualState == VisualState.BRAND_COLOR) { |
| mUseLightToolbarDrawables = |
| ColorUtils.shouldUseLightForegroundOnBackground(currentPrimaryColor); |
| mUnfocusedLocationBarUsesTransparentBg = |
| !ColorUtils.shouldUseOpaqueTextboxBackground(currentPrimaryColor); |
| - mUrlBackgroundAlpha = mUnfocusedLocationBarUsesTransparentBg |
| - ? LOCATION_BAR_TRANSPARENT_BACKGROUND_ALPHA : 255; |
| + mLocationBarBackgroundAlpha = mUnfocusedLocationBarUsesTransparentBg |
| + ? LOCATION_BAR_TRANSPARENT_BACKGROUND_ALPHA |
| + : 255; |
| } |
| if (mToggleTabStackButton != null) { |
| @@ -2071,7 +2083,7 @@ public class ToolbarPhone extends ToolbarLayout |
| if (shouldShowMenuButton()) { |
| mMenuButton.setTint(mUseLightToolbarDrawables ? mLightModeTint : mDarkModeTint); |
| - if (mShowMenuBadge && !isInTabSwitcherMode) { |
| + if (mShowMenuBadge && !mIsInTabSwitcherMode) { |
| setAppMenuUpdateBadgeDrawable(mUseLightToolbarDrawables); |
| } |
| } |
| @@ -2079,25 +2091,25 @@ public class ToolbarPhone extends ToolbarLayout |
| if (isReturnButtonVisible()) mReturnButton.setTint(tint); |
| if (mIsHomeButtonEnabled) mHomeButton.setTint(tint); |
| - mPhoneLocationBar.updateVisualsForState(); |
| + mLocationBar.updateVisualsForState(); |
| // Remove the side padding for incognito to ensure the badge icon aligns correctly with the |
| // background of the location bar. |
| if (isIncognito) { |
| - mPhoneLocationBar.setPadding( |
| - 0, mUrlBackgroundPadding.top, 0, mUrlBackgroundPadding.bottom); |
| + mLocationBar.setPadding( |
| + 0, mLocationBarBackgroundPadding.top, 0, mLocationBarBackgroundPadding.bottom); |
| } else { |
| - mPhoneLocationBar.setPadding( |
| - mUrlBackgroundPadding.left, mUrlBackgroundPadding.top, |
| - mUrlBackgroundPadding.right, mUrlBackgroundPadding.bottom); |
| + mLocationBar.setPadding(mLocationBarBackgroundPadding.left, |
| + mLocationBarBackgroundPadding.top, mLocationBarBackgroundPadding.right, |
| + mLocationBarBackgroundPadding.bottom); |
| } |
| // We update the alpha before comparing the visual state as we need to change |
| // its value when entering and exiting TabSwitcher mode. |
| - if (isLocationBarShownInNTP() && !isInTabSwitcherMode) { |
| + if (isLocationBarShownInNTP() && !mIsInTabSwitcherMode) { |
| updateNtpTransitionAnimation(); |
| } |
| - if (isInTabSwitcherMode) mNewTabButton.setIsIncognito(isIncognito); |
| + if (mIsInTabSwitcherMode) mNewTabButton.setIsIncognito(isIncognito); |
| CharSequence newTabContentDescription = getResources().getText( |
| isIncognito ? R.string.accessibility_toolbar_btn_new_incognito_tab : |
| @@ -2112,7 +2124,7 @@ public class ToolbarPhone extends ToolbarLayout |
| @Override |
| public LocationBar getLocationBar() { |
| - return mPhoneLocationBar; |
| + return mLocationBar; |
| } |
| @Override |
| @@ -2136,7 +2148,7 @@ public class ToolbarPhone extends ToolbarLayout |
| setAppMenuUpdateBadgeToVisible(true); |
| } |
| - mPhoneLocationBar.showAppMenuUpdateBadge(true); |
| + mLocationBar.showAppMenuUpdateBadge(true); |
| } |
| @Override |
| @@ -2149,7 +2161,7 @@ public class ToolbarPhone extends ToolbarLayout |
| mTabSwitcherAnimationMenuBadgeLightDrawable = null; |
| } |
| - mPhoneLocationBar.removeAppMenuUpdateBadge(animate); |
| + mLocationBar.removeAppMenuUpdateBadge(animate); |
| } |
| private void setTabSwitcherAnimationMenuDrawable() { |