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
return false;
}
/**
* @return Whether this Activity supports modern design.
*/
public boolean supportsModernDesign() {
return false;
}
/**
* @return the reference pool for this activity.
* @deprecated Use {@link ChromeApplication#getReferencePool} instead.
......
......@@ -875,6 +875,12 @@ public class ChromeTabbedActivity
mLayoutManager, mLayoutManager, tabSwitcherClickHandler, newTabClickHandler,
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()) {
EmptyBackgroundViewWrapper bgViewWrapper = new EmptyBackgroundViewWrapper(
getTabModelSelector(), getTabCreator(false), ChromeTabbedActivity.this,
......@@ -2468,6 +2474,11 @@ public class ChromeTabbedActivity
return !VrShellDelegate.isInVr();
}
@Override
public boolean supportsModernDesign() {
return true;
}
@Override
public void onScreenshotTaken() {
Tracker tracker = TrackerFactory.getTrackerForProfile(Profile.getLastUsedProfile());
......
......@@ -42,6 +42,7 @@ import org.chromium.chrome.browser.tabmodel.TabCreatorManager;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver;
import org.chromium.chrome.browser.util.ColorUtils;
import org.chromium.chrome.browser.util.FeatureUtilities;
import org.chromium.content.browser.ContentViewCore;
import org.chromium.ui.base.SPenSupport;
import org.chromium.ui.resources.ResourceManager;
......@@ -421,8 +422,8 @@ public class LayoutManager
tab.getContentViewCore() != null && !tab.isShowingSadTab() && !isNativePage;
boolean isNtp = tab.getNativePage() instanceof NewTabPage;
boolean useModernDesign =
tab.getActivity() != null && tab.getActivity().getBottomSheet() != null;
boolean useModernDesign = FeatureUtilities.isChromeModernDesignEnabled()
&& tab.getActivity() != null && tab.getActivity().supportsModernDesign();
boolean needsUpdate = layoutTab.initFromHost(tab.getBackgroundColor(), tab.shouldStall(),
canUseLiveTexture, themeColor,
ColorUtils.getTextBoxColorForToolbarBackground(
......
......@@ -392,5 +392,13 @@ public class LocationBarPhone extends LocationBarLayout {
public void onNativeLibraryReady() {
super.onNativeLibraryReady();
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
}
private int calculateDefaultThemeColor() {
boolean useModernDesign = getActivity() != null && getActivity().getBottomSheet() != null;
boolean useModernDesign = FeatureUtilities.isChromeModernDesignEnabled()
&& getActivity().supportsModernDesign();
Resources resources = mThemedApplicationContext.getResources();
return ColorUtils.getDefaultThemeColor(resources, useModernDesign, mIncognito);
}
......
......@@ -702,6 +702,14 @@ public class ToolbarManager implements ToolbarTabController, UrlFocusChangeListe
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.
*/
......
......@@ -25,6 +25,7 @@ import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.search_engines.TemplateUrlService;
import org.chromium.chrome.browser.tab.Tab;
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.components.dom_distiller.core.DomDistillerService;
import org.chromium.components.dom_distiller.core.DomDistillerUrlUtils;
......@@ -41,6 +42,7 @@ class ToolbarModelImpl extends ToolbarModel implements ToolbarDataProvider, Tool
private boolean mIsIncognito;
private int mPrimaryColor;
private boolean mIsUsingBrandColor;
private boolean mUseModernDesign;
/**
* Default constructor for this class.
......@@ -60,6 +62,16 @@ class ToolbarModelImpl extends ToolbarModel implements ToolbarDataProvider, Tool
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
public WebContents getActiveWebContents() {
if (!hasTab()) return null;
......@@ -189,8 +201,8 @@ class ToolbarModelImpl extends ToolbarModel implements ToolbarDataProvider, Tool
Context context = ContextUtils.getApplicationContext();
mIsUsingBrandColor = !isIncognito()
&& mPrimaryColor
!= ApiCompatibilityUtils.getColor(
context.getResources(), R.color.default_primary_color)
!= ColorUtils.getDefaultThemeColor(
context.getResources(), mUseModernDesign, isIncognito())
&& hasTab() && !mTab.isNativePage();
}
......
......@@ -26,6 +26,7 @@ import android.graphics.drawable.TransitionDrawable;
import android.os.Build;
import android.os.SystemClock;
import android.support.annotation.Nullable;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v4.view.animation.FastOutSlowInInterpolator;
import android.text.TextUtils;
import android.util.AttributeSet;
......@@ -260,6 +261,29 @@ public class ToolbarPhone extends ToolbarLayout
/** Token held when the TabSwitcherCallout is displayed to prevent the Toolbar from hiding. */
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.
*/
......@@ -360,17 +384,37 @@ public class ToolbarPhone extends ToolbarLayout
* Initializes the background, padding, margins, etc. for the location bar background.
*/
protected void initLocationBarBackground() {
mLocationBarVerticalMargin =
getResources().getDimensionPixelOffset(R.dimen.location_bar_vertical_margin);
mLocationBarBackgroundCornerRadius =
getResources().getDimensionPixelOffset(R.dimen.location_bar_corner_radius);
if (mLocationBar.useModernDesign()) {
Resources res = getResources();
mModernLocationBarBackgroundHeight =
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 =
ApiCompatibilityUtils.getDrawable(getResources(), R.drawable.card_single);
mLocationBarBackground.getPadding(mLocationBarBackgroundPadding);
mLocationBar.setPadding(mLocationBarBackgroundPadding.left,
mLocationBarBackgroundPadding.top, mLocationBarBackgroundPadding.right,
mLocationBarBackgroundPadding.bottom);
mLocationBarBackground =
ApiCompatibilityUtils.getDrawable(getResources(), R.drawable.card_single);
mLocationBarBackground.getPadding(mLocationBarBackgroundPadding);
mLocationBar.setPadding(mLocationBarBackgroundPadding.left,
mLocationBarBackgroundPadding.top, mLocationBarBackgroundPadding.right,
mLocationBarBackgroundPadding.bottom);
}
}
private void inflateTabSwitchingResources() {
......@@ -436,6 +480,14 @@ public class ToolbarPhone extends ToolbarLayout
@Override
public void 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();
enableTabSwitchingResources();
......@@ -667,7 +719,14 @@ public class ToolbarPhone extends ToolbarLayout
* @return The width of the location bar when it has focus.
*/
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
* @return The left margin of the location bar when it has focus.
*/
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)) {
return mToolbarSidePadding;
} else {
......@@ -749,9 +817,11 @@ public class ToolbarPhone extends ToolbarLayout
case NEW_TAB_NORMAL:
return Color.TRANSPARENT;
case NORMAL:
return ApiCompatibilityUtils.getColor(res, R.color.default_primary_color);
return ColorUtils.getDefaultThemeColor(
getResources(), mLocationBar.useModernDesign(), false);
case INCOGNITO:
return ApiCompatibilityUtils.getColor(res, R.color.incognito_primary_color);
return ColorUtils.getDefaultThemeColor(
getResources(), mLocationBar.useModernDesign(), true);
case BRAND_COLOR:
return getToolbarDataProvider().getPrimaryColor();
case TAB_SWITCHER_NORMAL:
......@@ -850,6 +920,10 @@ public class ToolbarPhone extends ToolbarLayout
* clip the background.
*/
protected int getLocationBarBackgroundVerticalMargin(float expansion) {
if (mLocationBar.useModernDesign()) {
return (int) ((mLocationBar.getHeight() - mModernLocationBarBackgroundHeight) / 2);
}
return (int) MathUtils.interpolate(mLocationBarVerticalMargin, 0, expansion);
}
......@@ -870,6 +944,7 @@ public class ToolbarPhone extends ToolbarLayout
* has focus.
*/
protected int getFocusedLeftPositionOfLocationBarBackground() {
if (mLocationBar.useModernDesign()) return mToolbarSidePadding;
return -mLocationBarBackgroundCornerRadius;
}
......@@ -891,6 +966,7 @@ public class ToolbarPhone extends ToolbarLayout
* has focus.
*/
protected int getFocusedRightPositionOfLocationBarBackground() {
if (mLocationBar.useModernDesign()) return getWidth() - mToolbarSidePadding;
return getWidth() + mLocationBarBackgroundCornerRadius;
}
......@@ -1388,7 +1464,7 @@ public class ToolbarPhone extends ToolbarLayout
*/
protected boolean shouldDrawLocationBarBackground() {
return (mLocationBar.getAlpha() > 0 || mForceDrawLocationBarBackground)
&& !mTextureCaptureMode;
&& (mLocationBar.useModernDesign() || !mTextureCaptureMode);
}
@Override
......@@ -1489,6 +1565,13 @@ public class ToolbarPhone extends ToolbarLayout
@Override
public void getLocationBarContentRect(Rect outRect) {
updateLocationBarBackgroundBounds(outRect, VisualState.NORMAL);
if (mLocationBar.useModernDesign()) {
outRect.left += mModernLocationBarContentLateralInset;
outRect.top += mModernLocationBarContentVerticalInset;
outRect.right -= mModernLocationBarContentLateralInset;
outRect.bottom -= mModernLocationBarContentVerticalInset;
}
}
@Override
......@@ -2363,6 +2446,13 @@ public class ToolbarPhone extends ToolbarLayout
}
getMenuButtonWrapper().setVisibility(View.VISIBLE);
if (mLocationBar.useModernDesign()) {
DrawableCompat.setTint(mLocationBarBackground,
isIncognito() ? Color.WHITE
: ApiCompatibilityUtils.getColor(
getResources(), R.color.modern_light_grey));
}
}
@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