Commit 7a676cfc authored by bauerb's avatar bauerb Committed by Commit bot

Use only toolbar to transition from fakebox to real omnibox.

Previously, we would fade out the fakebox and fade in the real omnibox during
the scroll transition, which created discrepancies. With this change, the
toolbar omnibox does the full transition. The search box on the NTP is still
kept, both to get the starting point of the transition, and for the tablet
toolbar, where the omnibox stays at the top, so there are two boxes.

Because the two boxes now have to match, their dimensions and padding are
slightly updated. The height is 56dp, and the padding on the sides is 12dp.

Also, in the focused state the omnibox now has 1dp bleed at the sides,
which moves the rounded corners out of view.

The remaining changes are not user-visible:
* Opacity of the fakebox is now driven by the toolbar. This lets us centralize
  the logic (the toolbar can decide its own opacity and the opacity of the
  fakebox) and use different behavior on tablets, where the fakebox will simply
  fade out as before.
* Rename variables to (hopefully) make them more consistent / self-explanatory.
* |mLocationBarBackgroundBounds| (formerly |mUrlViewportBounds|) more accurately
  reflects the visible omnibox bounds in the absence of the NTP / when the NTP
  is scrolled so that the omnibox is at the top. To do that, we no longer
  include the Y translation we apply to position it where the fakebox is (it's
  instead applied to the |mLocationBarBackgroundNtpOffset|), and we always use
  an expansion value of 1 if the current tab is an NTP.
* Remove the |inset_textbox| drawable -- it was the same as |textbox|, but with
  a margin added at the top and bottom (but *not* left or right). Since we
  calculate the omnibox bounds manually anyway, this allows us to account for
  the omnibox padding in the same way in either dimension.
* Remove the |isInTabSwitcherMode| parameter from some methods in favor of using
  the member variable.

BUG=605054,625108,618955,616728,612520

Review-Url: https://codereview.chromium.org/2134663002
Cr-Commit-Position: refs/heads/master@{#408885}
parent 78c093f7
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2015 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<inset
xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/textbox"
android:insetTop="@dimen/location_bar_margin_top"
android:insetBottom="@dimen/location_bar_margin_bottom"/>
\ No newline at end of file
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
android:layout_marginStart="16dp" android:layout_marginStart="16dp"
android:layout_marginEnd="16dp" android:layout_marginEnd="16dp"
android:layout_marginTop="26dp" android:layout_marginTop="26dp"
android:layout_marginBottom="27dp" /> android:layout_marginBottom="23dp" />
<!-- Search box --> <!-- Search box -->
<LinearLayout <LinearLayout
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
android:layout_height="48dp" android:layout_height="48dp"
android:layout_marginStart="12dp" android:layout_marginStart="12dp"
android:layout_marginEnd="12dp" android:layout_marginEnd="12dp"
android:layout_marginTop="3dp" android:layout_marginTop="7dp"
android:layout_marginBottom="8dp" android:layout_marginBottom="8dp"
android:gravity="center_vertical" android:gravity="center_vertical"
android:background="@drawable/bg_ntp_search_box" android:background="@drawable/bg_ntp_search_box"
......
...@@ -220,14 +220,13 @@ ...@@ -220,14 +220,13 @@
<dimen name="toolbar_progress_bar_height">2dp</dimen> <dimen name="toolbar_progress_bar_height">2dp</dimen>
<dimen name="toolbar_button_width">48dp</dimen> <dimen name="toolbar_button_width">48dp</dimen>
<dimen name="location_bar_margin_top">5dp</dimen>
<dimen name="location_bar_margin_bottom">5dp</dimen>
<dimen name="toolbar_edge_padding">8dp</dimen> <dimen name="toolbar_edge_padding">8dp</dimen>
<dimen name="location_bar_vertical_margin">8dp</dimen>
<dimen name="location_bar_url_text_size">16sp</dimen> <dimen name="location_bar_url_text_size">16sp</dimen>
<dimen name="location_bar_incognito_badge_padding">7dp</dimen> <dimen name="location_bar_incognito_badge_padding">7dp</dimen>
<dimen name="location_bar_icon_width">32dp</dimen>
<dimen name="location_bar_corner_radius">1dp</dimen>
<dimen name="location_bar_icon_width">36dp</dimen>
<dimen name="tablet_toolbar_start_padding">4dp</dimen> <dimen name="tablet_toolbar_start_padding">4dp</dimen>
<dimen name="tablet_toolbar_start_padding_no_buttons">6dp</dimen> <dimen name="tablet_toolbar_start_padding_no_buttons">6dp</dimen>
<dimen name="tablet_toolbar_end_padding">6dp</dimen> <dimen name="tablet_toolbar_end_padding">6dp</dimen>
...@@ -269,8 +268,8 @@ ...@@ -269,8 +268,8 @@
<dimen name="ntp_search_box_material_margin_left">10dp</dimen> <dimen name="ntp_search_box_material_margin_left">10dp</dimen>
<dimen name="ntp_search_box_material_margin_right">10dp</dimen> <dimen name="ntp_search_box_material_margin_right">10dp</dimen>
<dimen name="ntp_search_box_material_margin_top">0dp</dimen> <dimen name="ntp_search_box_material_margin_top">0dp</dimen>
<dimen name="ntp_search_box_material_margin_bottom">5dp</dimen> <dimen name="ntp_search_box_material_margin_bottom">1dp</dimen>
<dimen name="ntp_search_box_material_height">54dp</dimen> <dimen name="ntp_search_box_material_height">62dp</dimen>
<dimen name="ntp_search_box_material_extra_width">4dp</dimen> <dimen name="ntp_search_box_material_extra_width">4dp</dimen>
<dimen name="ntp_search_box_material_padding_top">3dp</dimen> <dimen name="ntp_search_box_material_padding_top">3dp</dimen>
<dimen name="ntp_search_box_material_padding_bottom">3dp</dimen> <dimen name="ntp_search_box_material_padding_bottom">3dp</dimen>
......
...@@ -8,6 +8,7 @@ import android.annotation.TargetApi; ...@@ -8,6 +8,7 @@ import android.annotation.TargetApi;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Point;
import android.graphics.Rect; import android.graphics.Rect;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
...@@ -671,16 +672,30 @@ public class NewTabPage ...@@ -671,16 +672,30 @@ public class NewTabPage
/** /**
* Get the bounds of the search box in relation to the top level NewTabPage view. * Get the bounds of the search box in relation to the top level NewTabPage view.
* *
* @param originalBounds The bounding region of the search box without external transforms * @param bounds The current drawing location of the search box.
* applied. The delta between this and the transformed bounds determines * @param translation The translation applied to the search box by the parent view hierarchy up
* the amount of scroll applied to this view. * to the NewTabPage view.
* @param transformedBounds The bounding region of the search box including any transforms
* applied by the parent view hierarchy up to the NewTabPage view.
* This more accurately reflects the current drawing location of the
* search box.
*/ */
public void getSearchBoxBounds(Rect originalBounds, Rect transformedBounds) { public void getSearchBoxBounds(Rect bounds, Point translation) {
mNewTabPageView.getSearchBoxBounds(originalBounds, transformedBounds); mNewTabPageView.getSearchBoxBounds(bounds, translation);
}
/**
* Updates the opacity of the search box when scrolling.
*
* @param alpha opacity (alpha) value to use.
*/
public void setSearchBoxAlpha(float alpha) {
mNewTabPageView.setSearchBoxAlpha(alpha);
}
/**
* Updates the opacity of the search provider logo when scrolling.
*
* @param alpha opacity (alpha) value to use.
*/
public void setSearchProviderLogoAlpha(float alpha) {
mNewTabPageView.setSearchProviderLogoAlpha(alpha);
} }
/** /**
......
...@@ -12,6 +12,7 @@ import android.graphics.Bitmap; ...@@ -12,6 +12,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Point;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
import android.support.v4.graphics.drawable.RoundedBitmapDrawable; import android.support.v4.graphics.drawable.RoundedBitmapDrawable;
...@@ -405,37 +406,49 @@ public class NewTabPageView extends FrameLayout ...@@ -405,37 +406,49 @@ public class NewTabPageView extends FrameLayout
private void updateSearchBoxOnScroll() { private void updateSearchBoxOnScroll() {
if (mDisableUrlFocusChangeAnimations) return; if (mDisableUrlFocusChangeAnimations) return;
float toolbarTransitionPercentage; if (mSearchBoxScrollListener != null) {
mSearchBoxScrollListener.onNtpScrollChanged(getToolbarTransitionPercentage());
}
}
/**
* Calculates the percentage (between 0 and 1) of the transition from the search box to the
* omnibox at the top of the New Tab Page, which is determined by the amount of scrolling and
* the position of the search box.
*
* @return the transition percentage
*/
private float getToolbarTransitionPercentage() {
// During startup the view may not be fully initialized, so we only calculate the current // During startup the view may not be fully initialized, so we only calculate the current
// percentage if some basic view properties are sane. // percentage if some basic view properties (height of the containing view, position of the
if (getWrapperView().getHeight() == 0 || mSearchBoxView.getTop() == 0) { // search box) are sane.
toolbarTransitionPercentage = 0f; if (getWrapperView().getHeight() == 0) return 0f;
} else if (!mUseCardsUi) {
toolbarTransitionPercentage =
MathUtils.clamp(getVerticalScroll() / (float) mSearchBoxView.getTop(), 0f, 1f);
} else {
if (!mRecyclerView.isFirstItemVisible()) {
// getVerticalScroll is valid only for the RecyclerView if the first item is
// visible. Luckily, if the first item is not visible, we know the toolbar
// transition should be 100%.
toolbarTransitionPercentage = 1f;
} else {
final int scrollY = getVerticalScroll();
final int top = mSearchBoxView.getTop(); // Relative to mNewTabPageLayout.
final int transitionLength = getResources()
.getDimensionPixelSize(R.dimen.ntp_search_box_transition_length);
// |scrollY - top| gives the distance the search bar is from the top of the screen. int searchBoxTop = mSearchBoxView.getTop();
toolbarTransitionPercentage = MathUtils.clamp( if (searchBoxTop == 0) return 0f;
(scrollY - top + transitionLength) / (float) transitionLength, 0f, 1f);
// For all other calculations, add the search box padding, because it defines where the
// visible "border" of the search box is.
searchBoxTop += mSearchBoxView.getPaddingTop();
if (!mUseCardsUi) {
return MathUtils.clamp(getVerticalScroll() / (float) searchBoxTop, 0f, 1f);
} }
if (!mRecyclerView.isFirstItemVisible()) {
// getVerticalScroll is valid only for the RecyclerView if the first item is
// visible. If the first item is not visible, we know the toolbar transition
// should be 100%.
return 1f;
} }
updateVisualsForToolbarTransition(toolbarTransitionPercentage); final int scrollY = getVerticalScroll();
final float transitionLength =
getResources().getDimension(R.dimen.ntp_search_box_transition_length);
if (mSearchBoxScrollListener != null) { // |scrollY - searchBoxTop| gives the distance the search bar is from the top of the screen.
mSearchBoxScrollListener.onNtpScrollChanged(toolbarTransitionPercentage); return MathUtils.clamp(
} (scrollY - searchBoxTop + transitionLength) / transitionLength, 0f, 1f);
} }
private ViewGroup getWrapperView() { private ViewGroup getWrapperView() {
...@@ -673,55 +686,52 @@ public class NewTabPageView extends FrameLayout ...@@ -673,55 +686,52 @@ public class NewTabPageView extends FrameLayout
int scrollOffset = mUseCardsUi ? 0 : mScrollView.getScrollY(); int scrollOffset = mUseCardsUi ? 0 : mScrollView.getScrollY();
mNewTabPageLayout.setTranslationY(percent * (-mMostVisitedLayout.getTop() + scrollOffset mNewTabPageLayout.setTranslationY(percent * (-mMostVisitedLayout.getTop() + scrollOffset
+ mNewTabPageLayout.getPaddingTop())); + mNewTabPageLayout.getPaddingTop()));
updateVisualsForToolbarTransition(percent);
} }
/** /**
* Updates the opacity of the fake omnibox and Google logo when scrolling. * Updates the opacity of the search box when scrolling.
* @param transitionPercentage *
* @param alpha opacity (alpha) value to use.
*/ */
private void updateVisualsForToolbarTransition(float transitionPercentage) { public void setSearchBoxAlpha(float alpha) {
// Complete the full alpha transition in the first 40% of the animation. mSearchBoxView.setAlpha(alpha);
float searchUiAlpha =
transitionPercentage >= 0.4f ? 0f : (0.4f - transitionPercentage) * 2.5f;
// Ensure there are no rounding issues when the animation percent is 0.
if (transitionPercentage == 0f) searchUiAlpha = 1f;
if (!mUseCardsUi) {
mSearchProviderLogoView.setAlpha(searchUiAlpha);
} }
mSearchBoxView.setAlpha(searchUiAlpha);
/**
* Updates the opacity of the search provider logo when scrolling.
*
* @param alpha opacity (alpha) value to use.
*/
public void setSearchProviderLogoAlpha(float alpha) {
mSearchProviderLogoView.setAlpha(alpha);
} }
/** /**
* Get the bounds of the search box in relation to the top level NewTabPage view. * Get the bounds of the search box in relation to the top level NewTabPage view.
* *
* @param originalBounds The bounding region of the search box without external transforms * @param bounds The current drawing location of the search box.
* applied. The delta between this and the transformed bounds determines * @param translation The translation applied to the search box by the parent view hierarchy up
* the amount of scroll applied to this view. * to the NewTabPage view.
* @param transformedBounds The bounding region of the search box including any transforms
* applied by the parent view hierarchy up to the NewTabPage view.
* This more accurately reflects the current drawing location of the
* search box.
*/ */
void getSearchBoxBounds(Rect originalBounds, Rect transformedBounds) { void getSearchBoxBounds(Rect bounds, Point translation) {
int searchBoxX = (int) mSearchBoxView.getX(); int searchBoxX = (int) mSearchBoxView.getX();
int searchBoxY = (int) mSearchBoxView.getY(); int searchBoxY = (int) mSearchBoxView.getY();
originalBounds.set( bounds.set(searchBoxX + mSearchBoxView.getPaddingLeft(),
searchBoxX + mSearchBoxView.getPaddingLeft(),
searchBoxY + mSearchBoxView.getPaddingTop(), searchBoxY + mSearchBoxView.getPaddingTop(),
searchBoxX + mSearchBoxView.getWidth() - mSearchBoxView.getPaddingRight(), searchBoxX + mSearchBoxView.getWidth() - mSearchBoxView.getPaddingRight(),
searchBoxY + mSearchBoxView.getHeight() - mSearchBoxView.getPaddingBottom()); searchBoxY + mSearchBoxView.getHeight() - mSearchBoxView.getPaddingBottom());
transformedBounds.set(originalBounds); translation.set(0, 0);
View view = (View) mSearchBoxView.getParent(); View view = (View) mSearchBoxView.getParent();
while (view != null) { while (view != null) {
transformedBounds.offset(-view.getScrollX(), -view.getScrollY()); translation.offset(-view.getScrollX(), -view.getScrollY());
if (view == this) break; if (view == this) break;
transformedBounds.offset((int) view.getX(), (int) view.getY()); translation.offset((int) view.getX(), (int) view.getY());
view = (View) view.getParent(); view = (View) view.getParent();
} }
bounds.offset(translation.x, translation.y);
} }
/** /**
......
...@@ -319,7 +319,8 @@ public class NewTabPageRecyclerView extends RecyclerView { ...@@ -319,7 +319,8 @@ public class NewTabPageRecyclerView extends RecyclerView {
// Snap scroll to prevent resting in the middle of the omnibox transition. // Snap scroll to prevent resting in the middle of the omnibox transition.
final int searchBoxTransitionLength = getResources() final int searchBoxTransitionLength = getResources()
.getDimensionPixelSize(R.dimen.ntp_search_box_transition_length); .getDimensionPixelSize(R.dimen.ntp_search_box_transition_length);
if (scrollOutOfRegion(fakeBox.getTop() - searchBoxTransitionLength, fakeBox.getTop())) { int fakeBoxUpperBound = fakeBox.getTop() + fakeBox.getPaddingTop();
if (scrollOutOfRegion(fakeBoxUpperBound - searchBoxTransitionLength, fakeBoxUpperBound)) {
// The snap scrolling regions should never overlap. // The snap scrolling regions should never overlap.
return; return;
} }
......
...@@ -172,8 +172,6 @@ public class LocationBarPhone extends LocationBarLayout { ...@@ -172,8 +172,6 @@ public class LocationBarPhone extends LocationBarLayout {
mUrlActionsContainer.setVisibility(GONE); mUrlActionsContainer.setVisibility(GONE);
} }
mDeleteButton.setAlpha(percent);
mMicButton.setAlpha(percent);
if (showMenuButtonInOmnibox()) mMenuButtonWrapper.setAlpha(1f - percent); if (showMenuButtonInOmnibox()) mMenuButtonWrapper.setAlpha(1f - percent);
updateButtonVisibility(); updateButtonVisibility();
......
...@@ -25,6 +25,7 @@ import android.graphics.drawable.Drawable; ...@@ -25,6 +25,7 @@ import android.graphics.drawable.Drawable;
import android.graphics.drawable.TransitionDrawable; import android.graphics.drawable.TransitionDrawable;
import android.os.Build; import android.os.Build;
import android.os.SystemClock; import android.os.SystemClock;
import android.support.v4.view.animation.FastOutSlowInInterpolator;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Property; import android.util.Property;
...@@ -36,6 +37,7 @@ import android.view.View.OnLongClickListener; ...@@ -36,6 +37,7 @@ import android.view.View.OnLongClickListener;
import android.view.ViewDebug; import android.view.ViewDebug;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.WindowManager; import android.view.WindowManager;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator; import android.view.animation.LinearInterpolator;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ImageView; import android.widget.ImageView;
...@@ -92,11 +94,12 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -92,11 +94,12 @@ public class ToolbarPhone extends ToolbarLayout
private static final float UNINITIALIZED_PERCENT = -1f; private static final float UNINITIALIZED_PERCENT = -1f;
private static final String TAG = "ToolbarPhone";
static final int LOCATION_BAR_TRANSPARENT_BACKGROUND_ALPHA = 51; 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;
private ViewGroup mToolbarButtonsContainer; private ViewGroup mToolbarButtonsContainer;
private ImageView mToggleTabStackButton; private ImageView mToggleTabStackButton;
...@@ -104,7 +107,7 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -104,7 +107,7 @@ public class ToolbarPhone extends ToolbarLayout
private TintedImageButton mReturnButton; private TintedImageButton mReturnButton;
private TintedImageButton mHomeButton; private TintedImageButton mHomeButton;
private TextView mUrlBar; private TextView mUrlBar;
private View mUrlActionsContainer; private View mUrlActionContainer;
private ImageView mToolbarShadow; private ImageView mToolbarShadow;
private final int mProgressBackBackgroundColorWhite; private final int mProgressBackBackgroundColorWhite;
...@@ -174,12 +177,13 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -174,12 +177,13 @@ public class ToolbarPhone extends ToolbarLayout
private int mUnfocusedLocationBarLayoutLeft; private int mUnfocusedLocationBarLayoutLeft;
private boolean mUnfocusedLocationBarUsesTransparentBg; private boolean mUnfocusedLocationBarUsesTransparentBg;
private int mUrlBackgroundAlpha = 255; private int mLocationBarBackgroundAlpha = 255;
private float mNtpSearchBoxScrollPercent = UNINITIALIZED_PERCENT; private float mNtpSearchBoxScrollPercent = UNINITIALIZED_PERCENT;
private ColorDrawable mToolbarBackground; private ColorDrawable mToolbarBackground;
// The omnibox background (white with a shadow). /** The omnibox background (white with a shadow). */
private Drawable mLocationBarBackground; private Drawable mLocationBarBackground;
private boolean mForceDrawLocationBarBackground; private boolean mForceDrawLocationBarBackground;
private TabSwitcherDrawable mTabSwitcherButtonDrawable; private TabSwitcherDrawable mTabSwitcherButtonDrawable;
private TabSwitcherDrawable mTabSwitcherButtonDrawableLight; private TabSwitcherDrawable mTabSwitcherButtonDrawableLight;
...@@ -187,16 +191,30 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -187,16 +191,30 @@ public class ToolbarPhone extends ToolbarLayout
private final int mLightModeDefaultColor; private final int mLightModeDefaultColor;
private final int mDarkModeDefaultColor; private final int mDarkModeDefaultColor;
private final Rect mUrlViewportBounds = new Rect(); /** The boundaries of the omnibox, without the NTP-specific offset applied. */
private final Rect mUrlBackgroundPadding = new Rect(); private final Rect mLocationBarBackgroundBounds = new Rect();
private final Rect mLocationBarBackgroundPadding = new Rect();
private final Rect mBackgroundOverlayBounds = new Rect(); private final Rect mBackgroundOverlayBounds = new Rect();
private final Rect mLocationBarBackgroundOffset = new Rect();
private final Rect mNtpSearchBoxOriginalBounds = new Rect(); /** Offset applied to the bounds of the omnibox if we are showing a New Tab Page. */
private final Rect mNtpSearchBoxTransformedBounds = new Rect(); 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 mToolbarSidePadding;
private final int mLocationBarVerticalMargin;
private final int mLocationBarBackgroundCornerRadius;
private ValueAnimator mBrandColorTransitionAnimation; private ValueAnimator mBrandColorTransitionAnimation;
private boolean mBrandColorTransitionActive; private boolean mBrandColorTransitionActive;
...@@ -277,9 +295,10 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -277,9 +295,10 @@ public class ToolbarPhone extends ToolbarLayout
super(context, attrs); super(context, attrs);
mToolbarSidePadding = getResources().getDimensionPixelOffset( mToolbarSidePadding = getResources().getDimensionPixelOffset(
R.dimen.toolbar_edge_padding); R.dimen.toolbar_edge_padding);
// Insets used for the PhoneLocatioBar background drawable. mLocationBarVerticalMargin =
mLocationBarInsets = getResources().getDimensionPixelSize(R.dimen.location_bar_margin_top) getResources().getDimensionPixelOffset(R.dimen.location_bar_vertical_margin);
+ getResources().getDimensionPixelSize(R.dimen.location_bar_margin_bottom); mLocationBarBackgroundCornerRadius =
getResources().getDimensionPixelOffset(R.dimen.location_bar_corner_radius);
mProgressBackBackgroundColorWhite = ApiCompatibilityUtils.getColor(getResources(), mProgressBackBackgroundColorWhite = ApiCompatibilityUtils.getColor(getResources(),
R.color.progress_bar_background_white); R.color.progress_bar_background_white);
mLightModeDefaultColor = mLightModeDefaultColor =
...@@ -291,7 +310,7 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -291,7 +310,7 @@ public class ToolbarPhone extends ToolbarLayout
@Override @Override
public void onFinishInflate() { public void onFinishInflate() {
super.onFinishInflate(); super.onFinishInflate();
mPhoneLocationBar = (LocationBarPhone) findViewById(R.id.location_bar); mLocationBar = (LocationBarPhone) findViewById(R.id.location_bar);
mToolbarButtonsContainer = (ViewGroup) findViewById(R.id.toolbar_buttons); mToolbarButtonsContainer = (ViewGroup) findViewById(R.id.toolbar_buttons);
...@@ -300,20 +319,20 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -300,20 +319,20 @@ public class ToolbarPhone extends ToolbarLayout
mUrlBar = (TextView) findViewById(R.id.url_bar); 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)); mToolbarBackground = new ColorDrawable(getToolbarColorForVisualState(VisualState.NORMAL));
mTabSwitcherAnimationBgOverlay = mTabSwitcherAnimationBgOverlay =
new ColorDrawable(getToolbarColorForVisualState(VisualState.NORMAL)); new ColorDrawable(getToolbarColorForVisualState(VisualState.NORMAL));
mLocationBarBackground = mLocationBarBackground =
ApiCompatibilityUtils.getDrawable(getResources(), R.drawable.inset_textbox); ApiCompatibilityUtils.getDrawable(getResources(), R.drawable.textbox);
mLocationBarBackground.getPadding(mUrlBackgroundPadding); mLocationBarBackground.getPadding(mLocationBarBackgroundPadding);
mPhoneLocationBar.setPadding( mLocationBar.setPadding(
mUrlBackgroundPadding.left, mUrlBackgroundPadding.top, mLocationBarBackgroundPadding.left, mLocationBarBackgroundPadding.top,
mUrlBackgroundPadding.right, mUrlBackgroundPadding.bottom); mLocationBarBackgroundPadding.right, mLocationBarBackgroundPadding.bottom);
setLayoutTransition(null); setLayoutTransition(null);
...@@ -440,7 +459,7 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -440,7 +459,7 @@ public class ToolbarPhone extends ToolbarLayout
}); });
onHomeButtonUpdate(HomepageManager.isHomepageEnabled(getContext())); onHomeButtonUpdate(HomepageManager.isHomepageEnabled(getContext()));
updateVisualsForToolbarState(mIsInTabSwitcherMode); updateVisualsForToolbarState();
} }
@Override @Override
...@@ -510,8 +529,8 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -510,8 +529,8 @@ public class ToolbarPhone extends ToolbarLayout
private void updateUnfocusedLocationBarLayoutParams() { private void updateUnfocusedLocationBarLayoutParams() {
boolean hasVisibleViewPriorToUrlBar = false; boolean hasVisibleViewPriorToUrlBar = false;
for (int i = 0; i < mPhoneLocationBar.getChildCount(); i++) { for (int i = 0; i < mLocationBar.getChildCount(); i++) {
View child = mPhoneLocationBar.getChildAt(i); View child = mLocationBar.getChildAt(i);
if (child == mUrlBar) break; if (child == mUrlBar) break;
if (child.getVisibility() != GONE) { if (child.getVisibility() != GONE) {
hasVisibleViewPriorToUrlBar = true; hasVisibleViewPriorToUrlBar = true;
...@@ -520,14 +539,21 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -520,14 +539,21 @@ public class ToolbarPhone extends ToolbarLayout
} }
int leftViewBounds = getViewBoundsLeftOfLocationBar(mVisualState); int leftViewBounds = getViewBoundsLeftOfLocationBar(mVisualState);
if (!hasVisibleViewPriorToUrlBar) leftViewBounds += mToolbarSidePadding;
int rightViewBounds = getViewBoundsRightOfLocationBar(mVisualState); int rightViewBounds = getViewBoundsRightOfLocationBar(mVisualState);
if (!mPhoneLocationBar.hasVisibleViewsAfterUrlBarWhenUnfocused()) { if (!hasVisibleViewPriorToUrlBar) {
if (ApiCompatibilityUtils.isLayoutRtl(mLocationBar)) {
rightViewBounds -= mToolbarSidePadding;
} else {
leftViewBounds += mToolbarSidePadding;
}
}
if (!mLocationBar.hasVisibleViewsAfterUrlBarWhenUnfocused()) {
// Add spacing between the end of the URL and the edge of the omnibox drawable. // 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 // This only applies if there is no end aligned view that should be visible
// while the omnibox is unfocused. // while the omnibox is unfocused.
if (ApiCompatibilityUtils.isLayoutRtl(mPhoneLocationBar)) { if (ApiCompatibilityUtils.isLayoutRtl(mLocationBar)) {
leftViewBounds += mToolbarSidePadding; leftViewBounds += mToolbarSidePadding;
} else { } else {
rightViewBounds -= mToolbarSidePadding; rightViewBounds -= mToolbarSidePadding;
...@@ -574,15 +600,15 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -574,15 +600,15 @@ public class ToolbarPhone extends ToolbarLayout
if (mLayoutLocationBarInFocusedMode || mVisualState == VisualState.NEW_TAB_NORMAL) { if (mLayoutLocationBarInFocusedMode || mVisualState == VisualState.NEW_TAB_NORMAL) {
int priorVisibleWidth = 0; int priorVisibleWidth = 0;
for (int i = 0; i < mPhoneLocationBar.getChildCount(); i++) { for (int i = 0; i < mLocationBar.getChildCount(); i++) {
View child = mPhoneLocationBar.getChildAt(i); View child = mLocationBar.getChildAt(i);
if (child == mPhoneLocationBar.getFirstViewVisibleWhenFocused()) break; if (child == mLocationBar.getFirstViewVisibleWhenFocused()) break;
if (child.getVisibility() == GONE) continue; if (child.getVisibility() == GONE) continue;
priorVisibleWidth += child.getMeasuredWidth(); priorVisibleWidth += child.getMeasuredWidth();
} }
width = containerWidth - (2 * mToolbarSidePadding) + priorVisibleWidth; width = containerWidth - (2 * mToolbarSidePadding) + priorVisibleWidth;
if (ApiCompatibilityUtils.isLayoutRtl(mPhoneLocationBar)) { if (ApiCompatibilityUtils.isLayoutRtl(mLocationBar)) {
leftMargin = mToolbarSidePadding; leftMargin = mToolbarSidePadding;
} else { } else {
leftMargin = -priorVisibleWidth + mToolbarSidePadding; leftMargin = -priorVisibleWidth + mToolbarSidePadding;
...@@ -677,8 +703,8 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -677,8 +703,8 @@ public class ToolbarPhone extends ToolbarLayout
} }
if (mLocationBarBackground != null if (mLocationBarBackground != null
&& (mPhoneLocationBar.getVisibility() == VISIBLE || mTextureCaptureMode)) { && (mLocationBar.getVisibility() == VISIBLE || mTextureCaptureMode)) {
updateUrlViewportBounds(mUrlViewportBounds, mVisualState, false); updateLocationBarBackgroundBounds(mLocationBarBackgroundBounds, mVisualState);
} }
if (mTextureCaptureMode) { if (mTextureCaptureMode) {
...@@ -732,18 +758,20 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -732,18 +758,20 @@ 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 {@code out}.
*/ */
private void updateUrlViewportBounds(Rect out, VisualState visualState, private void updateLocationBarBackgroundBounds(Rect out, VisualState visualState) {
boolean ignoreTranslationY) { // Calculate the visible boundaries of the left and right most child views of the
// Calculate the visible boundaries of the left and right most child views // location bar.
// of the location bar. float expansion = visualState == VisualState.NEW_TAB_NORMAL ? 1 : mUrlExpansionPercent;
int leftViewPosition = (int) MathUtils.interpolate( int leftViewPosition = (int) MathUtils.interpolate(
getViewBoundsLeftOfLocationBar(visualState), 0f, mUrlExpansionPercent) getViewBoundsLeftOfLocationBar(visualState),
- mUrlBackgroundPadding.left; -mLocationBarBackgroundCornerRadius,
expansion);
int rightViewPosition = (int) MathUtils.interpolate( int rightViewPosition = (int) MathUtils.interpolate(
getViewBoundsRightOfLocationBar(visualState), getWidth(), mUrlExpansionPercent) getViewBoundsRightOfLocationBar(visualState),
+ mUrlBackgroundPadding.right; getWidth() + mLocationBarBackgroundCornerRadius,
expansion);
// The bounds are set by the following: // The bounds are set by the following:
// - The left most visible location bar child view. // - The left most visible location bar child view.
...@@ -751,13 +779,11 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -751,13 +779,11 @@ public class ToolbarPhone extends ToolbarLayout
// - The right most visible location bar child view. // - The right most visible location bar child view.
// - The bottom of the viewport is aligned with the bottom of the location bar. // - The bottom of the viewport is aligned with the bottom of the location bar.
// Additional padding can be applied for use during animations. // Additional padding can be applied for use during animations.
float yOffset = ignoreTranslationY ? mPhoneLocationBar.getTop() : mPhoneLocationBar.getY(); int verticalMargin = (int) MathUtils.interpolate(mLocationBarVerticalMargin, 0, expansion);
out.set(leftViewPosition, out.set(leftViewPosition,
(int) (yOffset - (mUrlBackgroundPadding.top * mUrlExpansionPercent)), mLocationBar.getTop() + verticalMargin,
rightViewPosition, rightViewPosition,
(int) (yOffset + MathUtils.interpolate(mPhoneLocationBar.getMeasuredHeight(), mLocationBar.getBottom() - verticalMargin);
getHeight() + mUrlBackgroundPadding.bottom, mUrlExpansionPercent)));
} }
/** /**
...@@ -776,36 +802,78 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -776,36 +802,78 @@ public class ToolbarPhone extends ToolbarLayout
assert mUrlExpansionPercent <= 1; assert mUrlExpansionPercent <= 1;
} }
/**
* Updates the parameters relating to expanding the location bar, as the result of either a
* focus change or scrolling the New Tab Page.
*/
private void updateUrlExpansionAnimation() { private void updateUrlExpansionAnimation() {
if (mIsInTabSwitcherMode || isTabSwitcherAnimationRunning()) { if (mIsInTabSwitcherMode || isTabSwitcherAnimationRunning()) {
mToolbarButtonsContainer.setVisibility(VISIBLE); mToolbarButtonsContainer.setVisibility(VISIBLE);
return; return;
} }
mLocationBarBackgroundOffset.setEmpty(); FrameLayout.LayoutParams locationBarLayoutParams = getFrameLayoutParams(mLocationBar);
FrameLayout.LayoutParams locationBarLayoutParams =
getFrameLayoutParams(mPhoneLocationBar);
int currentLeftMargin = locationBarLayoutParams.leftMargin; int currentLeftMargin = locationBarLayoutParams.leftMargin;
int currentWidth = locationBarLayoutParams.width; int currentWidth = locationBarLayoutParams.width;
float inversePercent = 1f - mUrlExpansionPercent; float locationBarBaseTranslationX = mUnfocusedLocationBarLayoutLeft - currentLeftMargin;
float locationBarTranslationX = mUnfocusedLocationBarLayoutLeft - currentLeftMargin; boolean isLocationBarRtl = ApiCompatibilityUtils.isLayoutRtl(mLocationBar);
boolean isLocationBarRtl = ApiCompatibilityUtils.isLayoutRtl(mPhoneLocationBar);
if (isLocationBarRtl) { if (isLocationBarRtl) {
locationBarTranslationX += mUnfocusedLocationBarLayoutWidth - currentWidth; locationBarBaseTranslationX += mUnfocusedLocationBarLayoutWidth - currentWidth;
} }
locationBarTranslationX *= inversePercent; locationBarBaseTranslationX *= 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();
}
}
boolean isRtl = ApiCompatibilityUtils.isLayoutRtl(this);
float locationBarTranslationX;
// Get the padding straight from the location bar instead of
// |mLocationBarBackgroundPadding|, because it might be different in incognito mode.
if (isRtl) {
locationBarTranslationX = locationBarBaseTranslationX
+ mLocationBarNtpOffsetRight - mLocationBar.getPaddingRight();
} else {
locationBarTranslationX = locationBarBaseTranslationX
+ mLocationBarNtpOffsetLeft + mLocationBar.getPaddingLeft();
}
mLocationBar.setTranslationX(locationBarTranslationX);
// Negate the location bar translation to keep the URL action container in the same // Negate the location bar translation to keep the URL action container in the same
// place during the focus expansion. // place during the focus expansion.
if (!isLocationBarRtl || ApiCompatibilityUtils.isLayoutRtl(this)) { float urlActionsTranslationX = 0;
mUrlActionsContainer.setTranslationX(-locationBarTranslationX); if (!isLocationBarRtl || isRtl) {
urlActionsTranslationX = -locationBarBaseTranslationX;
}
if (isRtl) {
urlActionsTranslationX += mLocationBarNtpOffsetLeft - mLocationBarNtpOffsetRight;
} else {
urlActionsTranslationX += mLocationBarNtpOffsetRight - mLocationBarNtpOffsetLeft;
} }
mUrlActionContainer.setTranslationX(urlActionsTranslationX);
mPhoneLocationBar.setUrlFocusChangePercent(mUrlExpansionPercent); mLocationBar.setUrlFocusChangePercent(mUrlExpansionPercent);
// Ensure the buttons are invisible after focusing the omnibox to prevent them from // Ensure the buttons are invisible after focusing the omnibox to prevent them from
// accepting click events. // accepting click events.
...@@ -820,113 +888,99 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -820,113 +888,99 @@ public class ToolbarPhone extends ToolbarLayout
// Force an invalidation of the location bar to properly handle the clipping of the URL // 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. // bar text as a result of the url action container translations.
mPhoneLocationBar.invalidate(); mLocationBar.invalidate();
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();
} }
/**
* Reset the parameters for the New Tab Page transition animation (expanding the location bar as
* a result of scrolling the New Tab Page) to their default values.
*/
private void resetNtpAnimationValues() { private void resetNtpAnimationValues() {
mLocationBarBackgroundOffset.setEmpty(); mLocationBarBackgroundNtpOffset.setEmpty();
mPhoneLocationBar.setTranslationY(0); mLocationBar.setTranslationY(0);
if (!mUrlFocusChangeInProgress) { if (!mUrlFocusChangeInProgress) {
mToolbarButtonsContainer.setTranslationY(0); mToolbarButtonsContainer.setTranslationY(0);
mReturnButton.setTranslationY(0); mReturnButton.setTranslationY(0);
mHomeButton.setTranslationY(0); mHomeButton.setTranslationY(0);
} }
mToolbarShadow.setAlpha(1f); mToolbarShadow.setAlpha(1f);
mPhoneLocationBar.setAlpha(1); mLocationBar.setAlpha(1);
mForceDrawLocationBarBackground = false; mForceDrawLocationBarBackground = false;
mUrlBackgroundAlpha = isIncognito() mLocationBarBackgroundAlpha = 255;
|| (mUnfocusedLocationBarUsesTransparentBg if (isIncognito()
&& !mUrlFocusChangeInProgress || (mUnfocusedLocationBarUsesTransparentBg && !mUrlFocusChangeInProgress
&& !mPhoneLocationBar.hasFocus()) && !mLocationBar.hasFocus())) {
? LOCATION_BAR_TRANSPARENT_BACKGROUND_ALPHA : 255; mLocationBarBackgroundAlpha = LOCATION_BAR_TRANSPARENT_BACKGROUND_ALPHA;
}
setAncestorsShouldClipChildren(true); setAncestorsShouldClipChildren(true);
mNtpSearchBoxScrollPercent = UNINITIALIZED_PERCENT; mNtpSearchBoxScrollPercent = UNINITIALIZED_PERCENT;
updateUrlExpansionPercent(); updateUrlExpansionPercent();
} }
/**
* Updates the parameters of the New Tab Page transition animation (expanding the location bar
* as a result of scrolling the New Tab Page).
*/
private void updateNtpTransitionAnimation() { private void updateNtpTransitionAnimation() {
if (mIsInTabSwitcherMode) return; if (mIsInTabSwitcherMode) return;
NewTabPage ntp = getToolbarDataProvider().getNewTabPageForCurrentTab();
setAncestorsShouldClipChildren(mUrlExpansionPercent == 0f); setAncestorsShouldClipChildren(mUrlExpansionPercent == 0f);
mToolbarShadow.setAlpha(0f); mToolbarShadow.setAlpha(0f);
float growthPercent = 0f; NewTabPage ntp = getToolbarDataProvider().getNewTabPageForCurrentTab();
if (ntp.isCardsUiEnabled() || mUrlExpansionPercent == 0f || mUrlExpansionPercent == 1f) { ntp.getSearchBoxBounds(mNtpSearchBoxBounds, mNtpSearchBoxTranslation);
growthPercent = 1f - mUrlExpansionPercent; int locationBarTranslationY =
} else { Math.max(0, (mNtpSearchBoxBounds.top - mLocationBar.getTop()));
// During the transition from search box to omnibox, keep the omnibox drawing mLocationBar.setTranslationY(locationBarTranslationY);
// 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)));
if (!mUrlFocusChangeInProgress) { if (!mUrlFocusChangeInProgress) {
setButtonsTranslationY(); setButtonsTranslationY();
} }
mLocationBarBackgroundOffset.set( // Linearly interpolate between the bounds of the search box on the NTP and the omnibox
(int) ((mNtpSearchBoxTransformedBounds.left - mUrlViewportBounds.left // background bounds. |shrinkage| is the scaling factor for the offset -- if it's 1, we are
- mPhoneLocationBar.getPaddingLeft()) * growthPercent), // shrinking the omnibox down to the size of the search box.
(int) ((-halfHeightDifference - paddingTop) * growthPercent), float shrinkage;
(int) ((mNtpSearchBoxTransformedBounds.right - mUrlViewportBounds.right if (ntp.isCardsUiEnabled()) {
+ mPhoneLocationBar.getPaddingRight()) * growthPercent), shrinkage = 1f
(int) ((halfHeightDifference - paddingBottom + mLocationBarInsets) - NTP_SEARCH_BOX_EXPANSION_INTERPOLATOR.getInterpolation(mUrlExpansionPercent);
* 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);
} else { } 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 int leftBoundDifference = mNtpSearchBoxBounds.left - mLocationBarBackgroundBounds.left;
// scroll transition. int rightBoundDifference = mNtpSearchBoxBounds.right - mLocationBarBackgroundBounds.right;
mUrlBackgroundAlpha = mLocationBarBackgroundNtpOffset.set(
mUrlExpansionPercent >= 0.4f ? 255 : (int) ((mUrlExpansionPercent * 2.5f) * 255); (int) Math.round(leftBoundDifference * shrinkage),
if (mUrlExpansionPercent == 1f) mUrlBackgroundAlpha = 255; locationBarTranslationY,
mForceDrawLocationBarBackground = mUrlExpansionPercent != 0f; (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);
if (!ntp.isCardsUiEnabled()) {
ntp.setSearchProviderLogoAlpha(Math.max(1f - mUrlExpansionPercent * 2.5f, 0f));
}
} }
private void setButtonsTranslationY() { private void setButtonsTranslationY() {
float searchBoxTranslationY = int searchBoxTranslationY = Math.min(mNtpSearchBoxTranslation.y, 0);
mNtpSearchBoxTransformedBounds.top - mNtpSearchBoxOriginalBounds.top;
searchBoxTranslationY = Math.min(searchBoxTranslationY, 0);
mToolbarButtonsContainer.setTranslationY(searchBoxTranslationY); mToolbarButtonsContainer.setTranslationY(searchBoxTranslationY);
mReturnButton.setTranslationY(searchBoxTranslationY); mReturnButton.setTranslationY(searchBoxTranslationY);
mHomeButton.setTranslationY(searchBoxTranslationY); mHomeButton.setTranslationY(searchBoxTranslationY);
...@@ -983,13 +1037,13 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -983,13 +1037,13 @@ public class ToolbarPhone extends ToolbarLayout
} }
// Draw the location/URL bar. // Draw the location/URL bar.
previousAlpha = mPhoneLocationBar.getAlpha(); previousAlpha = mLocationBar.getAlpha();
mPhoneLocationBar.setAlpha(previousAlpha * floatAlpha); mLocationBar.setAlpha(previousAlpha * floatAlpha);
// If the location bar is now fully transparent, do not bother drawing it. // If the location bar is now fully transparent, do not bother drawing it.
if (mPhoneLocationBar.getAlpha() != 0) { if (mLocationBar.getAlpha() != 0) {
drawChild(canvas, mPhoneLocationBar, SystemClock.uptimeMillis()); drawChild(canvas, mLocationBar, SystemClock.uptimeMillis());
} }
mPhoneLocationBar.setAlpha(previousAlpha); mLocationBar.setAlpha(previousAlpha);
// Draw the tab stack button and associated text. // Draw the tab stack button and associated text.
translateCanvasToView(this, mToolbarButtonsContainer, canvas); translateCanvasToView(this, mToolbarButtonsContainer, canvas);
...@@ -1081,14 +1135,18 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1081,14 +1135,18 @@ public class ToolbarPhone extends ToolbarLayout
@Override @Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) { 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; boolean clipped = false;
if (mLocationBarBackground != null if (mLocationBarBackground != null
&& ((!mIsInTabSwitcherMode && !mTabSwitcherModeViews.contains(child)) && ((!mIsInTabSwitcherMode && !mTabSwitcherModeViews.contains(child))
|| (mIsInTabSwitcherMode && mBrowsingModeViews.contains(child)))) { || (mIsInTabSwitcherMode && mBrowsingModeViews.contains(child)))) {
canvas.save(); 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. // For other child views, use the inverse clipping of the URL viewport.
// Only necessary during animations. // Only necessary during animations.
// Hardware mode does not support unioned clip regions, so clip using the // Hardware mode does not support unioned clip regions, so clip using the
...@@ -1097,24 +1155,24 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1097,24 +1155,24 @@ public class ToolbarPhone extends ToolbarLayout
boolean isLeft = (child == mNewTabButton || child == mReturnButton boolean isLeft = (child == mNewTabButton || child == mReturnButton
|| child == mHomeButton) ^ LocalizationUtils.isLayoutRtl(); || child == mHomeButton) ^ LocalizationUtils.isLayoutRtl();
int clipTop = mUrlViewportBounds.top; int clipBottom = mLocationBarBackgroundBounds.bottom
int clipBottom = mUrlViewportBounds.bottom; + mLocationBarBackgroundPadding.bottom + translationY;
boolean verticalClip = false; boolean verticalClip = false;
if (mPhoneLocationBar.getTranslationY() > 0f) { if (translationY > 0f) {
clipTop = child.getTop(); clipTop = child.getTop();
clipBottom = mUrlViewportBounds.top; clipBottom = clipTop;
verticalClip = true; verticalClip = true;
} }
if (isLeft) { if (isLeft) {
canvas.clipRect( int clipRight = verticalClip ? child.getMeasuredWidth()
0, clipTop, : mLocationBarBackgroundBounds.left
verticalClip ? child.getMeasuredWidth() : mUrlViewportBounds.left, - mLocationBarBackgroundPadding.left;
clipBottom); canvas.clipRect(0, clipTop, clipRight, clipBottom);
} else { } else {
canvas.clipRect( int clipLeft = verticalClip ? 0 : mLocationBarBackgroundBounds.right
verticalClip ? 0 : mUrlViewportBounds.right, + mLocationBarBackgroundPadding.right;
clipTop, getMeasuredWidth(), clipBottom); canvas.clipRect(clipLeft, clipTop, getMeasuredWidth(), clipBottom);
} }
} }
clipped = true; clipped = true;
...@@ -1134,7 +1192,7 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1134,7 +1192,7 @@ public class ToolbarPhone extends ToolbarLayout
// Fade out/in the location bar towards the beginning of the animations to avoid // Fade out/in the location bar towards the beginning of the animations to avoid
// large jumps of stark white. // large jumps of stark white.
backgroundAlpha = backgroundAlpha =
(int) (Math.pow(mPhoneLocationBar.getAlpha(), 3) * mUrlBackgroundAlpha); (int) (Math.pow(mLocationBar.getAlpha(), 3) * mLocationBarBackgroundAlpha);
} else if (getToolbarDataProvider().isUsingBrandColor() } else if (getToolbarDataProvider().isUsingBrandColor()
&& !mBrandColorTransitionActive) { && !mBrandColorTransitionActive) {
backgroundAlpha = mUnfocusedLocationBarUsesTransparentBg backgroundAlpha = mUnfocusedLocationBarUsesTransparentBg
...@@ -1142,28 +1200,32 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1142,28 +1200,32 @@ public class ToolbarPhone extends ToolbarLayout
255, mUrlExpansionPercent)) 255, mUrlExpansionPercent))
: 255; : 255;
} else { } else {
backgroundAlpha = mUrlBackgroundAlpha; backgroundAlpha = mLocationBarBackgroundAlpha;
} }
mLocationBarBackground.setAlpha(backgroundAlpha); mLocationBarBackground.setAlpha(backgroundAlpha);
if ((mPhoneLocationBar.getAlpha() > 0 || mForceDrawLocationBarBackground) if ((mLocationBar.getAlpha() > 0 || mForceDrawLocationBarBackground)
&& !mTextureCaptureMode) { && !mTextureCaptureMode) {
mLocationBarBackground.setBounds( mLocationBarBackground.setBounds(
mUrlViewportBounds.left + mLocationBarBackgroundOffset.left, mLocationBarBackgroundBounds.left + mLocationBarBackgroundNtpOffset.left
mUrlViewportBounds.top + mLocationBarBackgroundOffset.top, - mLocationBarBackgroundPadding.left,
mUrlViewportBounds.right + mLocationBarBackgroundOffset.right, mLocationBarBackgroundBounds.top + mLocationBarBackgroundNtpOffset.top
mUrlViewportBounds.bottom + mLocationBarBackgroundOffset.bottom); - mLocationBarBackgroundPadding.top,
mLocationBarBackgroundBounds.right + mLocationBarBackgroundNtpOffset.right
+ mLocationBarBackgroundPadding.right,
mLocationBarBackgroundBounds.bottom + mLocationBarBackgroundNtpOffset.bottom
+ mLocationBarBackgroundPadding.bottom);
mLocationBarBackground.draw(canvas); mLocationBarBackground.draw(canvas);
} }
float locationBarClipLeft = mUrlViewportBounds.left float locationBarClipLeft =
+ mPhoneLocationBar.getPaddingLeft() + mLocationBarBackgroundOffset.left; mLocationBarBackgroundBounds.left + mLocationBarBackgroundNtpOffset.left;
float locationBarClipRight = mUrlViewportBounds.right float locationBarClipRight =
- mPhoneLocationBar.getPaddingRight() + mLocationBarBackgroundOffset.right; mLocationBarBackgroundBounds.right + mLocationBarBackgroundNtpOffset.right;
float locationBarClipTop = mUrlViewportBounds.top + mPhoneLocationBar.getPaddingTop() float locationBarClipTop =
+ mLocationBarBackgroundOffset.top; mLocationBarBackgroundBounds.top + mLocationBarBackgroundNtpOffset.top;
float locationBarClipBottom = mUrlViewportBounds.bottom float locationBarClipBottom =
- mPhoneLocationBar.getPaddingBottom() + mLocationBarBackgroundOffset.bottom; mLocationBarBackgroundBounds.bottom + mLocationBarBackgroundNtpOffset.bottom;
// When unexpanded, the location bar's visible content boundaries are inset from the // When unexpanded, the location bar's visible content boundaries are inset from the
// viewport used to draw the background. During expansion transitions, compensation // viewport used to draw the background. During expansion transitions, compensation
...@@ -1187,7 +1249,7 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1187,7 +1249,7 @@ public class ToolbarPhone extends ToolbarLayout
clipped = true; clipped = true;
} }
boolean retVal = super.drawChild(canvas, mPhoneLocationBar, drawingTime); boolean retVal = super.drawChild(canvas, mLocationBar, drawingTime);
if (clipped) canvas.restore(); if (clipped) canvas.restore();
return retVal; return retVal;
...@@ -1284,23 +1346,12 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1284,23 +1346,12 @@ public class ToolbarPhone extends ToolbarLayout
// The Android framework calls onAnimationEnd() on listeners before Animator#isRunning() // The Android framework calls onAnimationEnd() on listeners before Animator#isRunning()
// returns false. Sometimes this causes the progress bar visibility to be set incorrectly. // 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) // Update the visibility now that animations are set to null. (see crbug.com/606419)
updateProgressBarVisibility(mIsInTabSwitcherMode); updateProgressBarVisibility();
} }
@Override @Override
public void getLocationBarContentRect(Rect outRect) { public void getLocationBarContentRect(Rect outRect) {
mLocationBarBackground.getPadding(outRect); updateLocationBarBackgroundBounds(outRect, VisualState.NORMAL);
int paddingLeft = outRect.left;
int paddingTop = outRect.top;
int paddingRight = outRect.right;
int paddingBottom = outRect.bottom;
updateUrlViewportBounds(outRect, VisualState.NORMAL, true);
outRect.set(outRect.left + paddingLeft,
outRect.top + paddingTop,
outRect.right - paddingRight,
outRect.bottom - paddingBottom);
} }
@Override @Override
...@@ -1365,7 +1416,7 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1365,7 +1416,7 @@ public class ToolbarPhone extends ToolbarLayout
exitAnimation.addListener(new AnimatorListenerAdapter() { exitAnimation.addListener(new AnimatorListenerAdapter() {
@Override @Override
public void onAnimationEnd(Animator animation) { public void onAnimationEnd(Animator animation) {
updateViewsForTabSwitcherMode(mIsInTabSwitcherMode); updateViewsForTabSwitcherMode();
} }
}); });
...@@ -1380,7 +1431,7 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1380,7 +1431,7 @@ public class ToolbarPhone extends ToolbarLayout
exitAnimation.addListener(new AnimatorListenerAdapter() { exitAnimation.addListener(new AnimatorListenerAdapter() {
@Override @Override
public void onAnimationStart(Animator animation) { public void onAnimationStart(Animator animation) {
updateViewsForTabSwitcherMode(mIsInTabSwitcherMode); updateViewsForTabSwitcherMode();
// On older builds, force an update to ensure the new visuals are used // On older builds, force an update to ensure the new visuals are used
// when bringing in the toolbar. crbug.com/404571 // when bringing in the toolbar. crbug.com/404571
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN) { if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN) {
...@@ -1391,8 +1442,8 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1391,8 +1442,8 @@ public class ToolbarPhone extends ToolbarLayout
@Override @Override
public void onAnimationEnd(Animator animation) { public void onAnimationEnd(Animator animation) {
mDelayedTabSwitcherModeAnimation = null; mDelayedTabSwitcherModeAnimation = null;
updateShadowVisibility(mIsInTabSwitcherMode); updateShadowVisibility();
updateViewsForTabSwitcherMode(mIsInTabSwitcherMode); updateViewsForTabSwitcherMode();
} }
}); });
...@@ -1409,7 +1460,7 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1409,7 +1460,7 @@ public class ToolbarPhone extends ToolbarLayout
setAlpha(1); setAlpha(1);
} else { } else {
setAlpha(mPreTextureCaptureAlpha); setAlpha(mPreTextureCaptureAlpha);
updateShadowVisibility(mIsInTabSwitcherMode); updateShadowVisibility();
mPreTextureCaptureAlpha = 1f; mPreTextureCaptureAlpha = 1f;
} }
} }
...@@ -1421,9 +1472,9 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1421,9 +1472,9 @@ public class ToolbarPhone extends ToolbarLayout
&& mDelayedTabSwitcherModeAnimation.isRunning()); && mDelayedTabSwitcherModeAnimation.isRunning());
} }
private void updateViewsForTabSwitcherMode(boolean isInTabSwitcherMode) { private void updateViewsForTabSwitcherMode() {
int tabSwitcherViewsVisibility = isInTabSwitcherMode ? VISIBLE : INVISIBLE; int tabSwitcherViewsVisibility = mIsInTabSwitcherMode ? VISIBLE : INVISIBLE;
int browsingViewsVisibility = isInTabSwitcherMode ? INVISIBLE : VISIBLE; int browsingViewsVisibility = mIsInTabSwitcherMode ? INVISIBLE : VISIBLE;
for (View view : mTabSwitcherModeViews) { for (View view : mTabSwitcherModeViews) {
view.setVisibility(tabSwitcherViewsVisibility); view.setVisibility(tabSwitcherViewsVisibility);
...@@ -1432,27 +1483,28 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1432,27 +1483,28 @@ public class ToolbarPhone extends ToolbarLayout
view.setVisibility(browsingViewsVisibility); view.setVisibility(browsingViewsVisibility);
} }
if (mShowMenuBadge) { if (mShowMenuBadge) {
setMenuButtonContentDescription(!isInTabSwitcherMode); setMenuButtonContentDescription(!mIsInTabSwitcherMode);
} }
updateProgressBarVisibility(isInTabSwitcherMode); updateProgressBarVisibility();
updateVisualsForToolbarState(isInTabSwitcherMode); updateVisualsForToolbarState();
} }
private void updateProgressBarVisibility(boolean isInTabSwitcherMode) { private void updateProgressBarVisibility() {
getProgressBar().setVisibility( getProgressBar().setVisibility(
isInTabSwitcherMode || isTabSwitcherAnimationRunning() ? INVISIBLE : VISIBLE); mIsInTabSwitcherMode || isTabSwitcherAnimationRunning() ? INVISIBLE : VISIBLE);
} }
@Override @Override
protected void setContentAttached(boolean attached) { protected void setContentAttached(boolean attached) {
updateVisualsForToolbarState(mIsInTabSwitcherMode); updateVisualsForToolbarState();
} }
@Override @Override
protected void setTabSwitcherMode( protected void setTabSwitcherMode(
boolean inTabSwitcherMode, boolean showToolbar, boolean delayAnimation) { boolean inTabSwitcherMode, boolean showToolbar, boolean delayAnimation) {
if (mIsInTabSwitcherMode == inTabSwitcherMode) return; if (mIsInTabSwitcherMode == inTabSwitcherMode) return;
mIsInTabSwitcherMode = inTabSwitcherMode;
finishAnimations(); finishAnimations();
...@@ -1469,7 +1521,7 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1469,7 +1521,7 @@ public class ToolbarPhone extends ToolbarLayout
updateUrlExpansionAnimation(); updateUrlExpansionAnimation();
} }
mNewTabButton.setEnabled(true); mNewTabButton.setEnabled(true);
updateViewsForTabSwitcherMode(true); updateViewsForTabSwitcherMode();
mTabSwitcherModeAnimation = createEnterTabSwitcherModeAnimation(); mTabSwitcherModeAnimation = createEnterTabSwitcherModeAnimation();
} else { } else {
if (!mDelayingTabSwitcherAnimation) { if (!mDelayingTabSwitcherAnimation) {
...@@ -1479,7 +1531,6 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1479,7 +1531,6 @@ public class ToolbarPhone extends ToolbarLayout
} }
mAnimateNormalToolbar = showToolbar; mAnimateNormalToolbar = showToolbar;
mIsInTabSwitcherMode = inTabSwitcherMode;
if (mTabSwitcherModeAnimation != null) mTabSwitcherModeAnimation.start(); if (mTabSwitcherModeAnimation != null) mTabSwitcherModeAnimation.start();
if (SysUtils.isLowEndDevice()) finishAnimations(); if (SysUtils.isLowEndDevice()) finishAnimations();
...@@ -1496,7 +1547,7 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1496,7 +1547,7 @@ public class ToolbarPhone extends ToolbarLayout
if (!mAnimateNormalToolbar) { if (!mAnimateNormalToolbar) {
finishAnimations(); finishAnimations();
updateVisualsForToolbarState(mIsInTabSwitcherMode); updateVisualsForToolbarState();
} }
if (mDelayingTabSwitcherAnimation) { if (mDelayingTabSwitcherAnimation) {
...@@ -1504,11 +1555,11 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1504,11 +1555,11 @@ public class ToolbarPhone extends ToolbarLayout
mDelayedTabSwitcherModeAnimation = createPostExitTabSwitcherAnimation(); mDelayedTabSwitcherModeAnimation = createPostExitTabSwitcherAnimation();
mDelayedTabSwitcherModeAnimation.start(); mDelayedTabSwitcherModeAnimation.start();
} else { } else {
updateViewsForTabSwitcherMode(mIsInTabSwitcherMode); updateViewsForTabSwitcherMode();
} }
} }
private void updateOverlayDrawables(boolean isInTabSwitcherMode) { private void updateOverlayDrawables() {
if (!isNativeLibraryReady()) return; if (!isNativeLibraryReady()) return;
VisualState overlayState = computeVisualState(false); VisualState overlayState = computeVisualState(false);
...@@ -1528,7 +1579,7 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1528,7 +1579,7 @@ public class ToolbarPhone extends ToolbarLayout
setTabSwitcherAnimationMenuDrawable(); setTabSwitcherAnimationMenuDrawable();
setUseLightDrawablesForTextureCapture(); 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 // 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 // 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 // is entered immediately after a change to the tint color without any user interactions
...@@ -1594,9 +1645,9 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1594,9 +1645,9 @@ public class ToolbarPhone extends ToolbarLayout
animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE); animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
animators.add(animator); animators.add(animator);
for (int i = 0; i < mPhoneLocationBar.getChildCount(); i++) { for (int i = 0; i < mLocationBar.getChildCount(); i++) {
View childView = mPhoneLocationBar.getChildAt(i); View childView = mLocationBar.getChildAt(i);
if (childView == mPhoneLocationBar.getFirstViewVisibleWhenFocused()) break; if (childView == mLocationBar.getFirstViewVisibleWhenFocused()) break;
animator = ObjectAnimator.ofFloat(childView, ALPHA, 0); animator = ObjectAnimator.ofFloat(childView, ALPHA, 0);
animator.setDuration(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS); animator.setDuration(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS);
animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE); animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
...@@ -1665,9 +1716,9 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1665,9 +1716,9 @@ public class ToolbarPhone extends ToolbarLayout
animators.add(animator); animators.add(animator);
} }
for (int i = 0; i < mPhoneLocationBar.getChildCount(); i++) { for (int i = 0; i < mLocationBar.getChildCount(); i++) {
View childView = mPhoneLocationBar.getChildAt(i); View childView = mLocationBar.getChildAt(i);
if (childView == mPhoneLocationBar.getFirstViewVisibleWhenFocused()) break; if (childView == mLocationBar.getFirstViewVisibleWhenFocused()) break;
animator = ObjectAnimator.ofFloat(childView, ALPHA, 1); animator = ObjectAnimator.ofFloat(childView, ALPHA, 1);
animator.setStartDelay(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS); animator.setStartDelay(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
animator.setDuration(URL_CLEAR_FOCUS_MENU_DELAY_MS); animator.setDuration(URL_CLEAR_FOCUS_MENU_DELAY_MS);
...@@ -1680,7 +1731,7 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1680,7 +1731,7 @@ public class ToolbarPhone extends ToolbarLayout
// The call to getLayout() can return null briefly during text changes, but as it // 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 // is only needed for RTL calculations, we proceed if the location bar is showing
// LTR content. // LTR content.
boolean isLocationBarRtl = ApiCompatibilityUtils.isLayoutRtl(mPhoneLocationBar); boolean isLocationBarRtl = ApiCompatibilityUtils.isLayoutRtl(mLocationBar);
if (!isLocationBarRtl || mUrlBar.getLayout() != null) { if (!isLocationBarRtl || mUrlBar.getLayout() != null) {
int urlBarStartScrollX = 0; int urlBarStartScrollX = 0;
if (isLocationBarRtl) { if (isLocationBarRtl) {
...@@ -1693,10 +1744,8 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1693,10 +1744,8 @@ public class ToolbarPhone extends ToolbarLayout
// back to page URLs (despite it continually calling setScrollX with the same // back to page URLs (despite it continually calling setScrollX with the same
// number). // number).
if (mUrlBar.getScrollX() != urlBarStartScrollX) { if (mUrlBar.getScrollX() != urlBarStartScrollX) {
animator = ObjectAnimator.ofInt( animator = ObjectAnimator.ofInt(mUrlBar,
mUrlBar, buildUrlScrollProperty(mLocationBar, isLocationBarRtl), urlBarStartScrollX);
buildUrlScrollProperty(mPhoneLocationBar, isLocationBarRtl),
urlBarStartScrollX);
animator.setDuration(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS); animator.setDuration(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS);
animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE); animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
animators.add(animator); animators.add(animator);
...@@ -1772,7 +1821,7 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1772,7 +1821,7 @@ public class ToolbarPhone extends ToolbarLayout
mLayoutLocationBarInFocusedMode = false; mLayoutLocationBarInFocusedMode = false;
requestLayout(); requestLayout();
} }
mPhoneLocationBar.finishUrlFocusChange(hasFocus); mLocationBar.finishUrlFocusChange(hasFocus);
mUrlFocusChangeInProgress = false; mUrlFocusChangeInProgress = false;
} }
}); });
...@@ -1785,7 +1834,7 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1785,7 +1834,7 @@ public class ToolbarPhone extends ToolbarLayout
// allows the menu to translate off the screen on scroll to match the tabbed behavior. // allows the menu to translate off the screen on scroll to match the tabbed behavior.
if (mVisualState == VisualState.NEW_TAB_NORMAL) return true; if (mVisualState == VisualState.NEW_TAB_NORMAL) return true;
return !mPhoneLocationBar.showMenuButtonInOmnibox() && super.shouldShowMenuButton(); return !mLocationBar.showMenuButtonInOmnibox() && super.shouldShowMenuButton();
} }
@Override @Override
...@@ -1834,14 +1883,14 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1834,14 +1883,14 @@ public class ToolbarPhone extends ToolbarLayout
protected void onTabContentViewChanged() { protected void onTabContentViewChanged() {
super.onTabContentViewChanged(); super.onTabContentViewChanged();
updateNtpAnimationState(); updateNtpAnimationState();
updateVisualsForToolbarState(mIsInTabSwitcherMode); updateVisualsForToolbarState();
} }
@Override @Override
protected void onTabOrModelChanged() { protected void onTabOrModelChanged() {
super.onTabOrModelChanged(); super.onTabOrModelChanged();
updateNtpAnimationState(); updateNtpAnimationState();
updateVisualsForToolbarState(mIsInTabSwitcherMode); updateVisualsForToolbarState();
if (mHasCheckedIfTabSwitcherCalloutIsNecessary) { if (mHasCheckedIfTabSwitcherCalloutIsNecessary) {
dismissTabSwitcherCallout(); dismissTabSwitcherCallout();
...@@ -1867,7 +1916,7 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1867,7 +1916,7 @@ public class ToolbarPhone extends ToolbarLayout
if (initialColor == finalColor) return; if (initialColor == finalColor) return;
boolean shouldUseOpaque = ColorUtils.shouldUseOpaqueTextboxBackground(finalColor); boolean shouldUseOpaque = ColorUtils.shouldUseOpaqueTextboxBackground(finalColor);
final int initialAlpha = mUrlBackgroundAlpha; final int initialAlpha = mLocationBarBackgroundAlpha;
final int finalAlpha = final int finalAlpha =
shouldUseOpaque ? 255 : LOCATION_BAR_TRANSPARENT_BACKGROUND_ALPHA; shouldUseOpaque ? 255 : LOCATION_BAR_TRANSPARENT_BACKGROUND_ALPHA;
final boolean shouldAnimateAlpha = initialAlpha != finalAlpha; final boolean shouldAnimateAlpha = initialAlpha != finalAlpha;
...@@ -1879,7 +1928,7 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1879,7 +1928,7 @@ public class ToolbarPhone extends ToolbarLayout
public void onAnimationUpdate(ValueAnimator animation) { public void onAnimationUpdate(ValueAnimator animation) {
float fraction = animation.getAnimatedFraction(); float fraction = animation.getAnimatedFraction();
if (shouldAnimateAlpha) { if (shouldAnimateAlpha) {
mUrlBackgroundAlpha = mLocationBarBackgroundAlpha =
(int) (MathUtils.interpolate(initialAlpha, finalAlpha, fraction)); (int) (MathUtils.interpolate(initialAlpha, finalAlpha, fraction));
} }
updateToolbarBackground( updateToolbarBackground(
...@@ -1890,7 +1939,7 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1890,7 +1939,7 @@ public class ToolbarPhone extends ToolbarLayout
@Override @Override
public void onAnimationEnd(Animator animation) { public void onAnimationEnd(Animator animation) {
mBrandColorTransitionActive = false; mBrandColorTransitionActive = false;
updateVisualsForToolbarState(mIsInTabSwitcherMode); updateVisualsForToolbarState();
} }
}); });
mBrandColorTransitionAnimation.start(); mBrandColorTransitionAnimation.start();
...@@ -1936,7 +1985,7 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1936,7 +1985,7 @@ public class ToolbarPhone extends ToolbarLayout
post(new Runnable() { post(new Runnable() {
@Override @Override
public void run() { public void run() {
updateVisualsForToolbarState(mIsInTabSwitcherMode); updateVisualsForToolbarState();
updateNtpAnimationState(); updateNtpAnimationState();
} }
}); });
...@@ -1958,8 +2007,8 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1958,8 +2007,8 @@ public class ToolbarPhone extends ToolbarLayout
return ntp != null && ntp.isLocationBarShownInNTP(); return ntp != null && ntp.isLocationBarShownInNTP();
} }
private void updateShadowVisibility(boolean isInTabSwitcherMode) { private void updateShadowVisibility() {
boolean shouldDrawShadow = !isInTabSwitcherMode && !isTabSwitcherAnimationRunning(); boolean shouldDrawShadow = !mIsInTabSwitcherMode && !isTabSwitcherAnimationRunning();
int shadowVisibility = shouldDrawShadow ? View.VISIBLE : View.INVISIBLE; int shadowVisibility = shouldDrawShadow ? View.VISIBLE : View.INVISIBLE;
if (mToolbarShadow.getVisibility() != shadowVisibility) { if (mToolbarShadow.getVisibility() != shadowVisibility) {
...@@ -1976,10 +2025,10 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1976,10 +2025,10 @@ public class ToolbarPhone extends ToolbarLayout
return VisualState.NORMAL; return VisualState.NORMAL;
} }
private void updateVisualsForToolbarState(boolean isInTabSwitcherMode) { private void updateVisualsForToolbarState() {
final boolean isIncognito = isIncognito(); 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 // 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 // to run to completion as it will handle the triggering this path again and committing
...@@ -2024,8 +2073,9 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -2024,8 +2073,9 @@ public class ToolbarPhone extends ToolbarLayout
mVisualState = newVisualState; mVisualState = newVisualState;
updateOverlayDrawables(isInTabSwitcherMode); updateOverlayDrawables();
updateShadowVisibility(isInTabSwitcherMode); updateShadowVisibility();
updateUrlExpansionAnimation();
if (!visualStateChanged) { if (!visualStateChanged) {
if (mVisualState == VisualState.NEW_TAB_NORMAL) { if (mVisualState == VisualState.NEW_TAB_NORMAL) {
updateNtpTransitionAnimation(); updateNtpTransitionAnimation();
...@@ -2035,26 +2085,27 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -2035,26 +2085,27 @@ public class ToolbarPhone extends ToolbarLayout
mUseLightToolbarDrawables = false; mUseLightToolbarDrawables = false;
mUnfocusedLocationBarUsesTransparentBg = false; mUnfocusedLocationBarUsesTransparentBg = false;
mUrlBackgroundAlpha = 255; mLocationBarBackgroundAlpha = 255;
updateToolbarBackground(mVisualState); updateToolbarBackground(mVisualState);
getProgressBar().setThemeColor(themeColorForProgressBar, isIncognito()); getProgressBar().setThemeColor(themeColorForProgressBar, isIncognito());
if (isInTabSwitcherMode) { if (mIsInTabSwitcherMode) {
mUseLightToolbarDrawables = true; mUseLightToolbarDrawables = true;
mUrlBackgroundAlpha = LOCATION_BAR_TRANSPARENT_BACKGROUND_ALPHA; mLocationBarBackgroundAlpha = LOCATION_BAR_TRANSPARENT_BACKGROUND_ALPHA;
getProgressBar().setBackgroundColor(mProgressBackBackgroundColorWhite); getProgressBar().setBackgroundColor(mProgressBackBackgroundColorWhite);
getProgressBar().setForegroundColor(ApiCompatibilityUtils.getColor(getResources(), getProgressBar().setForegroundColor(ApiCompatibilityUtils.getColor(getResources(),
R.color.progress_bar_foreground_white)); R.color.progress_bar_foreground_white));
} else if (isIncognito()) { } else if (isIncognito()) {
mUseLightToolbarDrawables = true; mUseLightToolbarDrawables = true;
mUrlBackgroundAlpha = LOCATION_BAR_TRANSPARENT_BACKGROUND_ALPHA; mLocationBarBackgroundAlpha = LOCATION_BAR_TRANSPARENT_BACKGROUND_ALPHA;
} else if (mVisualState == VisualState.BRAND_COLOR) { } else if (mVisualState == VisualState.BRAND_COLOR) {
mUseLightToolbarDrawables = mUseLightToolbarDrawables =
ColorUtils.shouldUseLightForegroundOnBackground(currentPrimaryColor); ColorUtils.shouldUseLightForegroundOnBackground(currentPrimaryColor);
mUnfocusedLocationBarUsesTransparentBg = mUnfocusedLocationBarUsesTransparentBg =
!ColorUtils.shouldUseOpaqueTextboxBackground(currentPrimaryColor); !ColorUtils.shouldUseOpaqueTextboxBackground(currentPrimaryColor);
mUrlBackgroundAlpha = mUnfocusedLocationBarUsesTransparentBg mLocationBarBackgroundAlpha = mUnfocusedLocationBarUsesTransparentBg
? LOCATION_BAR_TRANSPARENT_BACKGROUND_ALPHA : 255; ? LOCATION_BAR_TRANSPARENT_BACKGROUND_ALPHA
: 255;
} }
if (mToggleTabStackButton != null) { if (mToggleTabStackButton != null) {
...@@ -2069,7 +2120,7 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -2069,7 +2120,7 @@ public class ToolbarPhone extends ToolbarLayout
if (shouldShowMenuButton()) { if (shouldShowMenuButton()) {
mMenuButton.setTint(mUseLightToolbarDrawables ? mLightModeTint : mDarkModeTint); mMenuButton.setTint(mUseLightToolbarDrawables ? mLightModeTint : mDarkModeTint);
if (mShowMenuBadge && !isInTabSwitcherMode) { if (mShowMenuBadge && !mIsInTabSwitcherMode) {
setAppMenuUpdateBadgeDrawable(mUseLightToolbarDrawables); setAppMenuUpdateBadgeDrawable(mUseLightToolbarDrawables);
} }
} }
...@@ -2077,25 +2128,25 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -2077,25 +2128,25 @@ public class ToolbarPhone extends ToolbarLayout
if (isReturnButtonVisible()) mReturnButton.setTint(tint); if (isReturnButtonVisible()) mReturnButton.setTint(tint);
if (mIsHomeButtonEnabled) mHomeButton.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 // Remove the side padding for incognito to ensure the badge icon aligns correctly with the
// background of the location bar. // background of the location bar.
if (isIncognito) { if (isIncognito) {
mPhoneLocationBar.setPadding( mLocationBar.setPadding(
0, mUrlBackgroundPadding.top, 0, mUrlBackgroundPadding.bottom); 0, mLocationBarBackgroundPadding.top, 0, mLocationBarBackgroundPadding.bottom);
} else { } else {
mPhoneLocationBar.setPadding( mLocationBar.setPadding(
mUrlBackgroundPadding.left, mUrlBackgroundPadding.top, mLocationBarBackgroundPadding.left, mLocationBarBackgroundPadding.top,
mUrlBackgroundPadding.right, mUrlBackgroundPadding.bottom); mLocationBarBackgroundPadding.right, mLocationBarBackgroundPadding.bottom);
} }
// We update the alpha before comparing the visual state as we need to change // We update the alpha before comparing the visual state as we need to change
// its value when entering and exiting TabSwitcher mode. // its value when entering and exiting TabSwitcher mode.
if (isLocationBarShownInNTP() && !isInTabSwitcherMode) { if (isLocationBarShownInNTP() && !mIsInTabSwitcherMode) {
updateNtpTransitionAnimation(); updateNtpTransitionAnimation();
} }
if (isInTabSwitcherMode) mNewTabButton.setIsIncognito(isIncognito); if (mIsInTabSwitcherMode) mNewTabButton.setIsIncognito(isIncognito);
CharSequence newTabContentDescription = getResources().getText( CharSequence newTabContentDescription = getResources().getText(
isIncognito ? R.string.accessibility_toolbar_btn_new_incognito_tab : isIncognito ? R.string.accessibility_toolbar_btn_new_incognito_tab :
...@@ -2110,7 +2161,7 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -2110,7 +2161,7 @@ public class ToolbarPhone extends ToolbarLayout
@Override @Override
public LocationBar getLocationBar() { public LocationBar getLocationBar() {
return mPhoneLocationBar; return mLocationBar;
} }
@Override @Override
...@@ -2134,7 +2185,7 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -2134,7 +2185,7 @@ public class ToolbarPhone extends ToolbarLayout
setAppMenuUpdateBadgeToVisible(true); setAppMenuUpdateBadgeToVisible(true);
} }
mPhoneLocationBar.showAppMenuUpdateBadge(true); mLocationBar.showAppMenuUpdateBadge(true);
} }
@Override @Override
...@@ -2147,7 +2198,7 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -2147,7 +2198,7 @@ public class ToolbarPhone extends ToolbarLayout
mTabSwitcherAnimationMenuBadgeLightDrawable = null; mTabSwitcherAnimationMenuBadgeLightDrawable = null;
} }
mPhoneLocationBar.removeAppMenuUpdateBadge(animate); mLocationBar.removeAppMenuUpdateBadge(animate);
} }
private void setTabSwitcherAnimationMenuDrawable() { private void setTabSwitcherAnimationMenuDrawable() {
......
...@@ -21,6 +21,7 @@ import org.chromium.chrome.R; ...@@ -21,6 +21,7 @@ import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeSwitches; import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.NavigationPopup; import org.chromium.chrome.browser.NavigationPopup;
import org.chromium.chrome.browser.device.DeviceClassManager; import org.chromium.chrome.browser.device.DeviceClassManager;
import org.chromium.chrome.browser.ntp.NewTabPage;
import org.chromium.chrome.browser.omnibox.LocationBar; import org.chromium.chrome.browser.omnibox.LocationBar;
import org.chromium.chrome.browser.omnibox.LocationBarTablet; import org.chromium.chrome.browser.omnibox.LocationBarTablet;
import org.chromium.chrome.browser.partnercustomizations.HomepageManager; import org.chromium.chrome.browser.partnercustomizations.HomepageManager;
...@@ -69,6 +70,8 @@ public class ToolbarTablet extends ToolbarLayout implements OnClickListener { ...@@ -69,6 +70,8 @@ public class ToolbarTablet extends ToolbarLayout implements OnClickListener {
private boolean mShouldAnimateButtonVisibilityChange; private boolean mShouldAnimateButtonVisibilityChange;
private AnimatorSet mButtonVisibilityAnimators; private AnimatorSet mButtonVisibilityAnimators;
private NewTabPage mVisibleNtp;
/** /**
* Constructs a ToolbarTablet object. * Constructs a ToolbarTablet object.
* @param context The Context in which this View object is created. * @param context The Context in which this View object is created.
...@@ -337,6 +340,38 @@ public class ToolbarTablet extends ToolbarLayout implements OnClickListener { ...@@ -337,6 +340,38 @@ public class ToolbarTablet extends ToolbarLayout implements OnClickListener {
} }
mUseLightColorAssets = incognito; mUseLightColorAssets = incognito;
} }
updateNtp();
}
/**
* Called when the currently visible New Tab Page changes.
*/
private void updateNtp() {
NewTabPage newVisibleNtp = getToolbarDataProvider().getNewTabPageForCurrentTab();
if (mVisibleNtp == newVisibleNtp) return;
if (mVisibleNtp != null) {
mVisibleNtp.setSearchBoxScrollListener(null);
}
mVisibleNtp = newVisibleNtp;
if (mVisibleNtp != null) {
mVisibleNtp.setSearchBoxScrollListener(new NewTabPage.OnSearchBoxScrollListener() {
@Override
public void onNtpScrollChanged(float scrollPercentage) {
// Fade the search box out in the first 40% of the scrolling transition.
float alpha = Math.max(1f - scrollPercentage * 2.5f, 0f);
mVisibleNtp.setSearchBoxAlpha(alpha);
mVisibleNtp.setSearchProviderLogoAlpha(alpha);
}
});
}
}
@Override
protected void onTabContentViewChanged() {
super.onTabContentViewChanged();
updateNtp();
} }
@Override @Override
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment