Commit 86512e1e authored by Theresa's avatar Theresa Committed by Commit Bot

[Modern] Modernize top toolbar

BUG=803088

Change-Id: Idfdd6fa8f77a4d47a9ffcc9c807470cd23340ad2
Reviewed-on: https://chromium-review.googlesource.com/875146Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Commit-Queue: Theresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#531949}
parent ca8bc4ab
...@@ -2220,6 +2220,13 @@ public abstract class ChromeActivity extends AsyncInitializationActivity ...@@ -2220,6 +2220,13 @@ public abstract class ChromeActivity extends AsyncInitializationActivity
return false; return false;
} }
/**
* @return Whether this Activity supports modern design.
*/
public boolean supportsModernDesign() {
return false;
}
/** /**
* @return the reference pool for this activity. * @return the reference pool for this activity.
* @deprecated Use {@link ChromeApplication#getReferencePool} instead. * @deprecated Use {@link ChromeApplication#getReferencePool} instead.
......
...@@ -875,6 +875,12 @@ public class ChromeTabbedActivity ...@@ -875,6 +875,12 @@ public class ChromeTabbedActivity
mLayoutManager, mLayoutManager, tabSwitcherClickHandler, newTabClickHandler, mLayoutManager, mLayoutManager, tabSwitcherClickHandler, newTabClickHandler,
bookmarkClickHandler, null); bookmarkClickHandler, null);
// TODO(twellington): Move to toolbar manager construction after isModernUiEnabled is
// available before native is loaded.
if (FeatureUtilities.isChromeModernDesignEnabled()) {
getToolbarManager().setUseModernDesign(true);
}
if (isTablet()) { if (isTablet()) {
EmptyBackgroundViewWrapper bgViewWrapper = new EmptyBackgroundViewWrapper( EmptyBackgroundViewWrapper bgViewWrapper = new EmptyBackgroundViewWrapper(
getTabModelSelector(), getTabCreator(false), ChromeTabbedActivity.this, getTabModelSelector(), getTabCreator(false), ChromeTabbedActivity.this,
...@@ -2468,6 +2474,11 @@ public class ChromeTabbedActivity ...@@ -2468,6 +2474,11 @@ public class ChromeTabbedActivity
return !VrShellDelegate.isInVr(); return !VrShellDelegate.isInVr();
} }
@Override
public boolean supportsModernDesign() {
return true;
}
@Override @Override
public void onScreenshotTaken() { public void onScreenshotTaken() {
Tracker tracker = TrackerFactory.getTrackerForProfile(Profile.getLastUsedProfile()); Tracker tracker = TrackerFactory.getTrackerForProfile(Profile.getLastUsedProfile());
......
...@@ -42,6 +42,7 @@ import org.chromium.chrome.browser.tabmodel.TabCreatorManager; ...@@ -42,6 +42,7 @@ import org.chromium.chrome.browser.tabmodel.TabCreatorManager;
import org.chromium.chrome.browser.tabmodel.TabModelSelector; import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver; import org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver;
import org.chromium.chrome.browser.util.ColorUtils; import org.chromium.chrome.browser.util.ColorUtils;
import org.chromium.chrome.browser.util.FeatureUtilities;
import org.chromium.content.browser.ContentViewCore; import org.chromium.content.browser.ContentViewCore;
import org.chromium.ui.base.SPenSupport; import org.chromium.ui.base.SPenSupport;
import org.chromium.ui.resources.ResourceManager; import org.chromium.ui.resources.ResourceManager;
...@@ -421,8 +422,8 @@ public class LayoutManager ...@@ -421,8 +422,8 @@ public class LayoutManager
tab.getContentViewCore() != null && !tab.isShowingSadTab() && !isNativePage; tab.getContentViewCore() != null && !tab.isShowingSadTab() && !isNativePage;
boolean isNtp = tab.getNativePage() instanceof NewTabPage; boolean isNtp = tab.getNativePage() instanceof NewTabPage;
boolean useModernDesign = boolean useModernDesign = FeatureUtilities.isChromeModernDesignEnabled()
tab.getActivity() != null && tab.getActivity().getBottomSheet() != null; && tab.getActivity() != null && tab.getActivity().supportsModernDesign();
boolean needsUpdate = layoutTab.initFromHost(tab.getBackgroundColor(), tab.shouldStall(), boolean needsUpdate = layoutTab.initFromHost(tab.getBackgroundColor(), tab.shouldStall(),
canUseLiveTexture, themeColor, canUseLiveTexture, themeColor,
ColorUtils.getTextBoxColorForToolbarBackground( ColorUtils.getTextBoxColorForToolbarBackground(
......
...@@ -392,5 +392,13 @@ public class LocationBarPhone extends LocationBarLayout { ...@@ -392,5 +392,13 @@ public class LocationBarPhone extends LocationBarLayout {
public void onNativeLibraryReady() { public void onNativeLibraryReady() {
super.onNativeLibraryReady(); super.onNativeLibraryReady();
if (mBottomSheet != null) updateGoogleG(); if (mBottomSheet != null) updateGoogleG();
// TODO(twellington): Move this to constructor when isModernUiEnabled() is available before
// native is loaded.
if (useModernDesign()) {
// Modern does not use the incognito badge. Remove the View to save memory.
removeView(mIncognitoBadge);
mIncognitoBadge = null;
}
} }
} }
...@@ -632,7 +632,8 @@ public class Tab ...@@ -632,7 +632,8 @@ public class Tab
} }
private int calculateDefaultThemeColor() { private int calculateDefaultThemeColor() {
boolean useModernDesign = getActivity() != null && getActivity().getBottomSheet() != null; boolean useModernDesign = FeatureUtilities.isChromeModernDesignEnabled()
&& getActivity().supportsModernDesign();
Resources resources = mThemedApplicationContext.getResources(); Resources resources = mThemedApplicationContext.getResources();
return ColorUtils.getDefaultThemeColor(resources, useModernDesign, mIncognito); return ColorUtils.getDefaultThemeColor(resources, useModernDesign, mIncognito);
} }
......
...@@ -702,6 +702,14 @@ public class ToolbarManager implements ToolbarTabController, UrlFocusChangeListe ...@@ -702,6 +702,14 @@ public class ToolbarManager implements ToolbarTabController, UrlFocusChangeListe
mInitializedWithNative = true; mInitializedWithNative = true;
} }
/**
* @param useModernDesign Whether the modern design should be used for the toolbar managed by
* this manager.
*/
public void setUseModernDesign(boolean useModernDesign) {
mToolbarModel.setUseModernDesign(useModernDesign);
}
/** /**
* @return The bookmarks bridge. * @return The bookmarks bridge.
*/ */
......
...@@ -25,6 +25,7 @@ import org.chromium.chrome.browser.profiles.Profile; ...@@ -25,6 +25,7 @@ import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.search_engines.TemplateUrlService; import org.chromium.chrome.browser.search_engines.TemplateUrlService;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.toolbar.ToolbarModel.ToolbarModelDelegate; import org.chromium.chrome.browser.toolbar.ToolbarModel.ToolbarModelDelegate;
import org.chromium.chrome.browser.util.ColorUtils;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet; import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet;
import org.chromium.components.dom_distiller.core.DomDistillerService; import org.chromium.components.dom_distiller.core.DomDistillerService;
import org.chromium.components.dom_distiller.core.DomDistillerUrlUtils; import org.chromium.components.dom_distiller.core.DomDistillerUrlUtils;
...@@ -41,6 +42,7 @@ class ToolbarModelImpl extends ToolbarModel implements ToolbarDataProvider, Tool ...@@ -41,6 +42,7 @@ class ToolbarModelImpl extends ToolbarModel implements ToolbarDataProvider, Tool
private boolean mIsIncognito; private boolean mIsIncognito;
private int mPrimaryColor; private int mPrimaryColor;
private boolean mIsUsingBrandColor; private boolean mIsUsingBrandColor;
private boolean mUseModernDesign;
/** /**
* Default constructor for this class. * Default constructor for this class.
...@@ -60,6 +62,16 @@ class ToolbarModelImpl extends ToolbarModel implements ToolbarDataProvider, Tool ...@@ -60,6 +62,16 @@ class ToolbarModelImpl extends ToolbarModel implements ToolbarDataProvider, Tool
initialize(this); initialize(this);
} }
/**
* @param useModernDesign Whether the modern design should be used for the toolbar represented
* by this model.
*/
public void setUseModernDesign(boolean useModernDesign) {
mUseModernDesign = useModernDesign;
setPrimaryColor(ColorUtils.getDefaultThemeColor(
ContextUtils.getApplicationContext().getResources(), useModernDesign, false));
}
@Override @Override
public WebContents getActiveWebContents() { public WebContents getActiveWebContents() {
if (!hasTab()) return null; if (!hasTab()) return null;
...@@ -189,8 +201,8 @@ class ToolbarModelImpl extends ToolbarModel implements ToolbarDataProvider, Tool ...@@ -189,8 +201,8 @@ class ToolbarModelImpl extends ToolbarModel implements ToolbarDataProvider, Tool
Context context = ContextUtils.getApplicationContext(); Context context = ContextUtils.getApplicationContext();
mIsUsingBrandColor = !isIncognito() mIsUsingBrandColor = !isIncognito()
&& mPrimaryColor && mPrimaryColor
!= ApiCompatibilityUtils.getColor( != ColorUtils.getDefaultThemeColor(
context.getResources(), R.color.default_primary_color) context.getResources(), mUseModernDesign, isIncognito())
&& hasTab() && !mTab.isNativePage(); && hasTab() && !mTab.isNativePage();
} }
......
...@@ -26,6 +26,7 @@ import android.graphics.drawable.TransitionDrawable; ...@@ -26,6 +26,7 @@ import android.graphics.drawable.TransitionDrawable;
import android.os.Build; import android.os.Build;
import android.os.SystemClock; import android.os.SystemClock;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v4.view.animation.FastOutSlowInInterpolator; import android.support.v4.view.animation.FastOutSlowInInterpolator;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.AttributeSet; import android.util.AttributeSet;
...@@ -260,6 +261,29 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -260,6 +261,29 @@ public class ToolbarPhone extends ToolbarLayout
/** Token held when the TabSwitcherCallout is displayed to prevent the Toolbar from hiding. */ /** Token held when the TabSwitcherCallout is displayed to prevent the Toolbar from hiding. */
private int mFullscreenCalloutToken = FullscreenManager.INVALID_TOKEN; private int mFullscreenCalloutToken = FullscreenManager.INVALID_TOKEN;
/** The height of the location bar background when the modern UI is enabled. */
private float mModernLocationBarBackgroundHeight;
/**
* The float used to inset the rect returned by {@link #getLocationBarContentRect(Rect)} when
* the modern UI is enabled. This extra vertical inset is needed to ensure the anonymize layer
* doesn't draw outside of the background bounds.
*/
private float mModernLocationBarContentVerticalInset;
/**
* The float used to inset the rect returned by {@link #getLocationBarContentRect(Rect)} when
* the modern UI is enabled. This extra lateral inset is needed to ensure the anonymize layer
* doesn't draw outside of the background bounds.
*/
private float mModernLocationBarContentLateralInset;
/**
* The extra margin to apply to the left side of the location bar when it is focused and the
* modern UI is enabled.
*/
private int mModernLocationBarExtraFocusedLeftMargin;
/** /**
* Used to specify the visual state of the toolbar. * Used to specify the visual state of the toolbar.
*/ */
...@@ -360,17 +384,37 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -360,17 +384,37 @@ public class ToolbarPhone extends ToolbarLayout
* Initializes the background, padding, margins, etc. for the location bar background. * Initializes the background, padding, margins, etc. for the location bar background.
*/ */
protected void initLocationBarBackground() { protected void initLocationBarBackground() {
mLocationBarVerticalMargin = if (mLocationBar.useModernDesign()) {
getResources().getDimensionPixelOffset(R.dimen.location_bar_vertical_margin); Resources res = getResources();
mLocationBarBackgroundCornerRadius = mModernLocationBarBackgroundHeight =
getResources().getDimensionPixelOffset(R.dimen.location_bar_corner_radius); res.getDimensionPixelSize(R.dimen.modern_toolbar_background_size);
mLocationBarBackground =
ApiCompatibilityUtils.getDrawable(res, R.drawable.modern_toolbar_background);
mLocationBarBackground.getPadding(mLocationBarBackgroundPadding);
mLocationBarBackground.mutate();
mLocationBar.setPadding(mLocationBarBackgroundPadding.left,
mLocationBarBackgroundPadding.top, mLocationBarBackgroundPadding.right,
mLocationBarBackgroundPadding.bottom);
mModernLocationBarContentLateralInset = getResources().getDimensionPixelSize(
R.dimen.bottom_location_bar_content_lateral_inset);
mModernLocationBarContentVerticalInset = getResources().getDimensionPixelSize(
R.dimen.bottom_location_bar_content_vertical_inset);
mModernLocationBarExtraFocusedLeftMargin = getResources().getDimensionPixelSize(
R.dimen.bottom_toolbar_background_focused_left_margin);
} else {
mLocationBarVerticalMargin =
getResources().getDimensionPixelOffset(R.dimen.location_bar_vertical_margin);
mLocationBarBackgroundCornerRadius =
getResources().getDimensionPixelOffset(R.dimen.location_bar_corner_radius);
mLocationBarBackground = mLocationBarBackground =
ApiCompatibilityUtils.getDrawable(getResources(), R.drawable.card_single); ApiCompatibilityUtils.getDrawable(getResources(), R.drawable.card_single);
mLocationBarBackground.getPadding(mLocationBarBackgroundPadding); mLocationBarBackground.getPadding(mLocationBarBackgroundPadding);
mLocationBar.setPadding(mLocationBarBackgroundPadding.left, mLocationBar.setPadding(mLocationBarBackgroundPadding.left,
mLocationBarBackgroundPadding.top, mLocationBarBackgroundPadding.right, mLocationBarBackgroundPadding.top, mLocationBarBackgroundPadding.right,
mLocationBarBackgroundPadding.bottom); mLocationBarBackgroundPadding.bottom);
}
} }
private void inflateTabSwitchingResources() { private void inflateTabSwitchingResources() {
...@@ -436,6 +480,14 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -436,6 +480,14 @@ public class ToolbarPhone extends ToolbarLayout
@Override @Override
public void onNativeLibraryReady() { public void onNativeLibraryReady() {
super.onNativeLibraryReady(); super.onNativeLibraryReady();
// TODO(twellington): Move this to constructor when isModernUiEnabled() is available before
// native is loaded.
if (mLocationBar.useModernDesign()) {
mNewTabButton.setIsModern();
initLocationBarBackground();
}
getLocationBar().onNativeLibraryReady(); getLocationBar().onNativeLibraryReady();
enableTabSwitchingResources(); enableTabSwitchingResources();
...@@ -667,7 +719,14 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -667,7 +719,14 @@ public class ToolbarPhone extends ToolbarLayout
* @return The width of the location bar when it has focus. * @return The width of the location bar when it has focus.
*/ */
protected int getFocusedLocationBarWidth(int containerWidth, int priorVisibleWidth) { protected int getFocusedLocationBarWidth(int containerWidth, int priorVisibleWidth) {
return containerWidth - (2 * mToolbarSidePadding) + priorVisibleWidth; int width = containerWidth - (2 * mToolbarSidePadding) + priorVisibleWidth;
if (mLocationBar.useModernDesign()) {
width = width - mModernLocationBarExtraFocusedLeftMargin
- mLocationBarBackgroundPadding.left - mLocationBarBackgroundPadding.right;
}
return width;
} }
/** /**
...@@ -675,6 +734,15 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -675,6 +734,15 @@ public class ToolbarPhone extends ToolbarLayout
* @return The left margin of the location bar when it has focus. * @return The left margin of the location bar when it has focus.
*/ */
protected int getFocusedLocationBarLeftMargin(int priorVisibleWidth) { protected int getFocusedLocationBarLeftMargin(int priorVisibleWidth) {
if (mLocationBar.useModernDesign()) {
int baseMargin = mToolbarSidePadding + mModernLocationBarExtraFocusedLeftMargin;
if (ApiCompatibilityUtils.isLayoutRtl(mLocationBar)) {
return baseMargin - mLocationBarBackgroundPadding.right;
} else {
return baseMargin - priorVisibleWidth + mLocationBarBackgroundPadding.left;
}
}
if (ApiCompatibilityUtils.isLayoutRtl(mLocationBar)) { if (ApiCompatibilityUtils.isLayoutRtl(mLocationBar)) {
return mToolbarSidePadding; return mToolbarSidePadding;
} else { } else {
...@@ -749,9 +817,11 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -749,9 +817,11 @@ public class ToolbarPhone extends ToolbarLayout
case NEW_TAB_NORMAL: case NEW_TAB_NORMAL:
return Color.TRANSPARENT; return Color.TRANSPARENT;
case NORMAL: case NORMAL:
return ApiCompatibilityUtils.getColor(res, R.color.default_primary_color); return ColorUtils.getDefaultThemeColor(
getResources(), mLocationBar.useModernDesign(), false);
case INCOGNITO: case INCOGNITO:
return ApiCompatibilityUtils.getColor(res, R.color.incognito_primary_color); return ColorUtils.getDefaultThemeColor(
getResources(), mLocationBar.useModernDesign(), true);
case BRAND_COLOR: case BRAND_COLOR:
return getToolbarDataProvider().getPrimaryColor(); return getToolbarDataProvider().getPrimaryColor();
case TAB_SWITCHER_NORMAL: case TAB_SWITCHER_NORMAL:
...@@ -850,6 +920,10 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -850,6 +920,10 @@ public class ToolbarPhone extends ToolbarLayout
* clip the background. * clip the background.
*/ */
protected int getLocationBarBackgroundVerticalMargin(float expansion) { protected int getLocationBarBackgroundVerticalMargin(float expansion) {
if (mLocationBar.useModernDesign()) {
return (int) ((mLocationBar.getHeight() - mModernLocationBarBackgroundHeight) / 2);
}
return (int) MathUtils.interpolate(mLocationBarVerticalMargin, 0, expansion); return (int) MathUtils.interpolate(mLocationBarVerticalMargin, 0, expansion);
} }
...@@ -870,6 +944,7 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -870,6 +944,7 @@ public class ToolbarPhone extends ToolbarLayout
* has focus. * has focus.
*/ */
protected int getFocusedLeftPositionOfLocationBarBackground() { protected int getFocusedLeftPositionOfLocationBarBackground() {
if (mLocationBar.useModernDesign()) return mToolbarSidePadding;
return -mLocationBarBackgroundCornerRadius; return -mLocationBarBackgroundCornerRadius;
} }
...@@ -891,6 +966,7 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -891,6 +966,7 @@ public class ToolbarPhone extends ToolbarLayout
* has focus. * has focus.
*/ */
protected int getFocusedRightPositionOfLocationBarBackground() { protected int getFocusedRightPositionOfLocationBarBackground() {
if (mLocationBar.useModernDesign()) return getWidth() - mToolbarSidePadding;
return getWidth() + mLocationBarBackgroundCornerRadius; return getWidth() + mLocationBarBackgroundCornerRadius;
} }
...@@ -1388,7 +1464,7 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1388,7 +1464,7 @@ public class ToolbarPhone extends ToolbarLayout
*/ */
protected boolean shouldDrawLocationBarBackground() { protected boolean shouldDrawLocationBarBackground() {
return (mLocationBar.getAlpha() > 0 || mForceDrawLocationBarBackground) return (mLocationBar.getAlpha() > 0 || mForceDrawLocationBarBackground)
&& !mTextureCaptureMode; && (mLocationBar.useModernDesign() || !mTextureCaptureMode);
} }
@Override @Override
...@@ -1489,6 +1565,13 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1489,6 +1565,13 @@ public class ToolbarPhone extends ToolbarLayout
@Override @Override
public void getLocationBarContentRect(Rect outRect) { public void getLocationBarContentRect(Rect outRect) {
updateLocationBarBackgroundBounds(outRect, VisualState.NORMAL); updateLocationBarBackgroundBounds(outRect, VisualState.NORMAL);
if (mLocationBar.useModernDesign()) {
outRect.left += mModernLocationBarContentLateralInset;
outRect.top += mModernLocationBarContentVerticalInset;
outRect.right -= mModernLocationBarContentLateralInset;
outRect.bottom -= mModernLocationBarContentVerticalInset;
}
} }
@Override @Override
...@@ -2363,6 +2446,13 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -2363,6 +2446,13 @@ public class ToolbarPhone extends ToolbarLayout
} }
getMenuButtonWrapper().setVisibility(View.VISIBLE); getMenuButtonWrapper().setVisibility(View.VISIBLE);
if (mLocationBar.useModernDesign()) {
DrawableCompat.setTint(mLocationBarBackground,
isIncognito() ? Color.WHITE
: ApiCompatibilityUtils.getColor(
getResources(), R.color.modern_light_grey));
}
} }
@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