Commit b53d021f authored by Becky Zhou's avatar Becky Zhou Committed by Commit Bot

Add incognito badge and update background for location bar

+ Add an incognito badge on location bar on phone
+ Update incognito location bar background to black

Bug: 942776
Change-Id: I13d64ac21a082e77a8df7b640f68f87ff9798072
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1566754Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Commit-Queue: Becky Zhou <huayinz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#652276}
parent f93d43e5
...@@ -285,6 +285,7 @@ chrome_test_java_sources = [ ...@@ -285,6 +285,7 @@ chrome_test_java_sources = [
"javatests/src/org/chromium/chrome/browser/omnibox/UrlBarTest.java", "javatests/src/org/chromium/chrome/browser/omnibox/UrlBarTest.java",
"javatests/src/org/chromium/chrome/browser/omnibox/UrlBarIntegrationTest.java", "javatests/src/org/chromium/chrome/browser/omnibox/UrlBarIntegrationTest.java",
"javatests/src/org/chromium/chrome/browser/omnibox/geo/GeolocationHeaderTest.java", "javatests/src/org/chromium/chrome/browser/omnibox/geo/GeolocationHeaderTest.java",
"javatests/src/org/chromium/chrome/browser/omnibox/status/StatusViewTest.java",
"javatests/src/org/chromium/chrome/browser/omnibox/suggestions/VoiceSuggestionProviderTest.java", "javatests/src/org/chromium/chrome/browser/omnibox/suggestions/VoiceSuggestionProviderTest.java",
"javatests/src/org/chromium/chrome/browser/page_info/ConnectionInfoPopupTest.java", "javatests/src/org/chromium/chrome/browser/page_info/ConnectionInfoPopupTest.java",
"javatests/src/org/chromium/chrome/browser/page_info/PageInfoControllerTest.java", "javatests/src/org/chromium/chrome/browser/page_info/PageInfoControllerTest.java",
......
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2019 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. -->
<!-- The location bar incognito badge has a 22dpx22dp circle instead of the regular 24dpx24dp
circle. -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:targetApi="21"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:pathData="M12,12m-11,0a11,11 0,1 1,22 0a11,11 0,1 1,-22 0"
android:fillColor="@color/default_icon_color_dark" />
<path
android:pathData="M8.175,8.506L9.333,4.95L12,5.839L14.667,4.95L15.906,8.506L8.175,8.506ZM16.62,10L20,12L4,12L7.497,10L16.62,10ZM12,15.333C12.353,15.333 12.682,15.436 12.959,15.614C13.234,14.434 14.292,13.556 15.556,13.556C17.028,13.556 18.222,14.749 18.222,16.222C18.222,17.695 17.028,18.889 15.556,18.889C14.166,18.889 13.025,17.826 12.9,16.469C12.637,16.312 12.329,16.222 12,16.222C11.671,16.222 11.363,16.312 11.1,16.469C10.975,17.826 9.834,18.889 8.444,18.889C6.972,18.889 5.778,17.695 5.778,16.222C5.778,14.749 6.972,13.556 8.444,13.556C9.708,13.556 10.766,14.434 11.041,15.613C11.318,15.436 11.647,15.333 12,15.333ZM8.444,18C9.426,18 10.222,17.204 10.222,16.222C10.222,15.24 9.426,14.444 8.444,14.444C7.462,14.444 6.667,15.24 6.667,16.222C6.667,17.204 7.462,18 8.444,18ZM15.556,18C16.537,18 17.333,17.204 17.333,16.222C17.333,15.24 16.537,14.444 15.556,14.444C14.573,14.444 13.778,15.24 13.778,16.222C13.778,17.204 14.573,18 15.556,18Z"
android:fillColor="@android:color/white" />
</vector>
\ No newline at end of file
...@@ -11,6 +11,15 @@ ...@@ -11,6 +11,15 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent"> android:layout_height="match_parent">
<!-- End padding is adjusted programmatically. -->
<ViewStub
android:id="@+id/location_bar_incognito_badge_stub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:inflatedId="@+id/location_bar_incognito_badge"
android:layout="@layout/location_status_incognito_badge" />
<include layout="@layout/location_status_icon" /> <include layout="@layout/location_status_icon" />
<TextView android:id="@+id/location_bar_verbose_status" <TextView android:id="@+id/location_bar_verbose_status"
......
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2019 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. -->
<org.chromium.ui.widget.ChromeImageView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:visibility="gone"
android:contentDescription="@string/accessibility_incognito_badge"
app:srcCompat="@drawable/ic_location_bar_incognito_badge" />
...@@ -136,6 +136,7 @@ ...@@ -136,6 +136,7 @@
<color name="toolbar_background_primary">@color/default_bg_color_elev_3</color> <color name="toolbar_background_primary">@color/default_bg_color_elev_3</color>
<color name="toolbar_background_primary_incognito">@color/modern_grey_800</color> <color name="toolbar_background_primary_incognito">@color/modern_grey_800</color>
<color name="toolbar_text_box_background">@color/modern_grey_100</color> <color name="toolbar_text_box_background">@color/modern_grey_100</color>
<color name="toolbar_text_box_background_incognito">@color/black_alpha_38</color>
<color name="toolbar_shadow_color">@color/black_alpha_11</color> <color name="toolbar_shadow_color">@color/black_alpha_11</color>
<!-- LocationBar colors --> <!-- LocationBar colors -->
......
...@@ -276,6 +276,8 @@ ...@@ -276,6 +276,8 @@
<dimen name="location_bar_status_separator_spacer">8dp</dimen> <dimen name="location_bar_status_separator_spacer">8dp</dimen>
<dimen name="location_bar_min_url_width">68dp</dimen> <dimen name="location_bar_min_url_width">68dp</dimen>
<dimen name="location_bar_min_verbose_status_text_width">48dp</dimen> <dimen name="location_bar_min_verbose_status_text_width">48dp</dimen>
<dimen name="location_bar_incognito_badge_end_padding_with_status_icon">2dp</dimen>
<dimen name="location_bar_incognito_badge_end_padding_without_status_icon">8dp</dimen>
<dimen name="tablet_toolbar_start_padding">4dp</dimen> <dimen name="tablet_toolbar_start_padding">4dp</dimen>
<dimen name="tablet_toolbar_end_padding">6dp</dimen> <dimen name="tablet_toolbar_end_padding">6dp</dimen>
......
...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser; ...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser;
import android.content.Context; import android.content.Context;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
import android.support.annotation.ColorInt;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import org.chromium.base.ObserverList; import org.chromium.base.ObserverList;
...@@ -98,6 +99,14 @@ public abstract class ThemeColorProvider { ...@@ -98,6 +99,14 @@ public abstract class ThemeColorProvider {
mTintObservers.removeObserver(observer); mTintObservers.removeObserver(observer);
} }
/**
* @return The current theme color of this provider.
*/
@ColorInt
public int getThemeColor() {
return mPrimaryColor;
}
/** /**
* @return The current tint of this provider. * @return The current tint of this provider.
*/ */
......
...@@ -653,8 +653,8 @@ public class LayoutManager implements LayoutUpdateHost, LayoutProvider, ...@@ -653,8 +653,8 @@ public class LayoutManager implements LayoutUpdateHost, LayoutProvider,
boolean needsUpdate = layoutTab.initFromHost(TabThemeColorHelper.getBackgroundColor(tab), boolean needsUpdate = layoutTab.initFromHost(TabThemeColorHelper.getBackgroundColor(tab),
shouldStall(tab), canUseLiveTexture, ColorUtils.getToolbarSceneLayerBackground(tab), shouldStall(tab), canUseLiveTexture, ColorUtils.getToolbarSceneLayerBackground(tab),
ColorUtils.getTextBoxColorForToolbarBackground( ColorUtils.getTextBoxColorForToolbarBackground(mContext.getResources(),
mContext.getResources(), isLocationBarShownInNtp, themeColor), isLocationBarShownInNtp, themeColor, tab.isIncognito()),
ColorUtils.getTextBoxAlphaForToolbarBackground(tab)); ColorUtils.getTextBoxAlphaForToolbarBackground(tab));
if (needsUpdate) requestUpdate(); if (needsUpdate) requestUpdate();
......
...@@ -94,6 +94,7 @@ public class ToolbarSceneLayer extends SceneOverlayLayer implements SceneOverlay ...@@ -94,6 +94,7 @@ public class ToolbarSceneLayer extends SceneOverlayLayer implements SceneOverlay
|| forceHideAndroidBrowserControls; || forceHideAndroidBrowserControls;
boolean isLocationBarShownInNtp = false; boolean isLocationBarShownInNtp = false;
boolean isIncognito = false;
Tab currentTab = fullscreenManager.getTab(); Tab currentTab = fullscreenManager.getTab();
if (currentTab != null) { if (currentTab != null) {
boolean isNtp = boolean isNtp =
...@@ -102,10 +103,11 @@ public class ToolbarSceneLayer extends SceneOverlayLayer implements SceneOverlay ...@@ -102,10 +103,11 @@ public class ToolbarSceneLayer extends SceneOverlayLayer implements SceneOverlay
isLocationBarShownInNtp = isLocationBarShownInNtp =
((NewTabPage) currentTab.getNativePage()).isLocationBarShownInNTP(); ((NewTabPage) currentTab.getNativePage()).isLocationBarShownInNTP();
} }
isIncognito = currentTab.isIncognito();
} }
int textBoxColor = ColorUtils.getTextBoxColorForToolbarBackground( int textBoxColor = ColorUtils.getTextBoxColorForToolbarBackground(mContext.getResources(),
mContext.getResources(), isLocationBarShownInNtp, browserControlsBackgroundColor); isLocationBarShownInNtp, browserControlsBackgroundColor, isIncognito);
int textBoxResourceId = R.drawable.modern_location_bar; int textBoxResourceId = R.drawable.modern_location_bar;
nativeUpdateToolbarLayer(mNativePtr, resourceManager, R.id.control_container, nativeUpdateToolbarLayer(mNativePtr, resourceManager, R.id.control_container,
......
...@@ -1036,6 +1036,8 @@ public class LocationBarLayout extends FrameLayout ...@@ -1036,6 +1036,8 @@ public class LocationBarLayout extends FrameLayout
} }
mStatusViewCoordinator.setUseDarkColors(useDarkColors); mStatusViewCoordinator.setUseDarkColors(useDarkColors);
mStatusViewCoordinator.setIncognitoBadgeVisibility(
mToolbarDataProvider.isIncognito() && !mIsTablet);
mAutocompleteCoordinator.updateVisualsForState( mAutocompleteCoordinator.updateVisualsForState(
useDarkColors, mToolbarDataProvider.isIncognito()); useDarkColors, mToolbarDataProvider.isIncognito());
} }
......
...@@ -195,6 +195,13 @@ class StatusMediator { ...@@ -195,6 +195,13 @@ class StatusMediator {
} }
} }
/**
* @param incognitoBadgeVisible Whether or not the incognito badge is visible.
*/
void setIncognitoBadgeVisibility(boolean incognitoBadgeVisible) {
mModel.set(StatusProperties.INCOGNITO_BADGE_VISIBLE, incognitoBadgeVisible);
}
/** /**
* Specify minimum width of the verbose status text field. * Specify minimum width of the verbose status text field.
*/ */
......
...@@ -52,11 +52,15 @@ class StatusProperties { ...@@ -52,11 +52,15 @@ class StatusProperties {
/** Specifies width of the verbose status text view. */ /** Specifies width of the verbose status text view. */
static final WritableIntPropertyKey VERBOSE_STATUS_TEXT_WIDTH = new WritableIntPropertyKey(); static final WritableIntPropertyKey VERBOSE_STATUS_TEXT_WIDTH = new WritableIntPropertyKey();
/** Specifies whether the incognito badge is visible or not. */
static final WritableBooleanPropertyKey INCOGNITO_BADGE_VISIBLE =
new WritableBooleanPropertyKey();
public static final PropertyKey[] ALL_KEYS = new PropertyKey[] {ANIMATIONS_ENABLED, public static final PropertyKey[] ALL_KEYS = new PropertyKey[] {ANIMATIONS_ENABLED,
STATUS_ICON_ACCESSIBILITY_TOAST_RES, STATUS_ICON_RES, STATUS_ICON_TINT_RES, STATUS_ICON_ACCESSIBILITY_TOAST_RES, STATUS_ICON_RES, STATUS_ICON_TINT_RES,
STATUS_ICON_DESCRIPTION_RES, SEPARATOR_COLOR_RES, STATUS_CLICK_LISTENER, STATUS_ICON_DESCRIPTION_RES, SEPARATOR_COLOR_RES, STATUS_CLICK_LISTENER,
VERBOSE_STATUS_TEXT_COLOR_RES, VERBOSE_STATUS_TEXT_STRING_RES, VERBOSE_STATUS_TEXT_COLOR_RES, VERBOSE_STATUS_TEXT_STRING_RES,
VERBOSE_STATUS_TEXT_VISIBLE, VERBOSE_STATUS_TEXT_WIDTH}; VERBOSE_STATUS_TEXT_VISIBLE, VERBOSE_STATUS_TEXT_WIDTH, INCOGNITO_BADGE_VISIBLE};
private StatusProperties() {} private StatusProperties() {}
} }
...@@ -11,9 +11,12 @@ import android.graphics.drawable.Drawable; ...@@ -11,9 +11,12 @@ import android.graphics.drawable.Drawable;
import android.graphics.drawable.TransitionDrawable; import android.graphics.drawable.TransitionDrawable;
import android.support.annotation.ColorRes; import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes; import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes; import android.support.annotation.StringRes;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.View; import android.view.View;
import android.view.ViewStub;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
...@@ -27,6 +30,10 @@ import org.chromium.chrome.browser.widget.TintedDrawable; ...@@ -27,6 +30,10 @@ import org.chromium.chrome.browser.widget.TintedDrawable;
* StatusView is a location bar's view displaying status (icons and/or text). * StatusView is a location bar's view displaying status (icons and/or text).
*/ */
public class StatusView extends LinearLayout { public class StatusView extends LinearLayout {
private @Nullable View mIncognitoBadge;
private int mIncognitoBadgeEndPaddingWithIcon;
private int mIncognitoBadgeEndPaddingWithoutIcon;
private ImageView mIconView; private ImageView mIconView;
private TextView mVerboseStatusTextView; private TextView mVerboseStatusTextView;
private View mSeparatorView; private View mSeparatorView;
...@@ -104,6 +111,7 @@ public class StatusView extends LinearLayout { ...@@ -104,6 +111,7 @@ public class StatusView extends LinearLayout {
mAnimatingStatusIconShow = true; mAnimatingStatusIconShow = true;
mIconView.setVisibility(View.VISIBLE); mIconView.setVisibility(View.VISIBLE);
updateIncognitoBadgeEndPadding();
mIconView.animate() mIconView.animate()
.alpha(1.0f) .alpha(1.0f)
.setDuration(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS) .setDuration(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS)
...@@ -126,6 +134,9 @@ public class StatusView extends LinearLayout { ...@@ -126,6 +134,9 @@ public class StatusView extends LinearLayout {
.withEndAction(() -> { .withEndAction(() -> {
mIconView.setVisibility(View.GONE); mIconView.setVisibility(View.GONE);
mAnimatingStatusIconHide = false; mAnimatingStatusIconHide = false;
// Update incognito badge padding after the animation to avoid a glitch on
// focusing location bar.
updateIncognitoBadgeEndPadding();
}) })
.start(); .start();
} }
...@@ -265,6 +276,37 @@ public class StatusView extends LinearLayout { ...@@ -265,6 +276,37 @@ public class StatusView extends LinearLayout {
mVerboseStatusTextView.setMaxWidth(width); mVerboseStatusTextView.setMaxWidth(width);
} }
/**
* @param incognitoBadgeVisible Whether or not the incognito badge is visible.
*/
void setIncognitoBadgeVisibility(boolean incognitoBadgeVisible) {
// Initialize the incognito badge on the first time it becomes visible.
if (mIncognitoBadge == null && !incognitoBadgeVisible) return;
if (mIncognitoBadge == null) initializeIncognitoBadge();
mIncognitoBadge.setVisibility(incognitoBadgeVisible ? View.VISIBLE : View.GONE);
}
private void initializeIncognitoBadge() {
ViewStub viewStub = findViewById(R.id.location_bar_incognito_badge_stub);
mIncognitoBadge = viewStub.inflate();
mIncognitoBadgeEndPaddingWithIcon = getResources().getDimensionPixelSize(
R.dimen.location_bar_incognito_badge_end_padding_with_status_icon);
mIncognitoBadgeEndPaddingWithoutIcon = getResources().getDimensionPixelSize(
R.dimen.location_bar_incognito_badge_end_padding_without_status_icon);
updateIncognitoBadgeEndPadding();
}
private void updateIncognitoBadgeEndPadding() {
if (mIncognitoBadge == null) return;
ViewCompat.setPaddingRelative(mIncognitoBadge, ViewCompat.getPaddingStart(mIncognitoBadge),
mIncognitoBadge.getPaddingTop(),
mIconRes != 0 ? mIncognitoBadgeEndPaddingWithIcon
: mIncognitoBadgeEndPaddingWithoutIcon,
mIncognitoBadge.getPaddingBottom());
}
// TODO(ender): The final last purpose of this method is to allow // TODO(ender): The final last purpose of this method is to allow
// ToolbarButtonInProductHelpController set up help bubbles. This dependency is about to // ToolbarButtonInProductHelpController set up help bubbles. This dependency is about to
// change. Do not depend on this method when creating new code. // change. Do not depend on this method when creating new code.
......
...@@ -42,6 +42,8 @@ class StatusViewBinder implements ViewBinder<PropertyModel, StatusView, Property ...@@ -42,6 +42,8 @@ class StatusViewBinder implements ViewBinder<PropertyModel, StatusView, Property
model.get(StatusProperties.VERBOSE_STATUS_TEXT_VISIBLE)); model.get(StatusProperties.VERBOSE_STATUS_TEXT_VISIBLE));
} else if (StatusProperties.VERBOSE_STATUS_TEXT_WIDTH.equals(propertyKey)) { } else if (StatusProperties.VERBOSE_STATUS_TEXT_WIDTH.equals(propertyKey)) {
view.setVerboseStatusTextWidth(model.get(StatusProperties.VERBOSE_STATUS_TEXT_WIDTH)); view.setVerboseStatusTextWidth(model.get(StatusProperties.VERBOSE_STATUS_TEXT_WIDTH));
} else if (StatusProperties.INCOGNITO_BADGE_VISIBLE.equals(propertyKey)) {
view.setIncognitoBadgeVisibility(model.get(StatusProperties.INCOGNITO_BADGE_VISIBLE));
} else { } else {
assert false : "Unhandled property update"; assert false : "Unhandled property update";
} }
......
...@@ -97,6 +97,13 @@ public class StatusViewCoordinator implements View.OnClickListener { ...@@ -97,6 +97,13 @@ public class StatusViewCoordinator implements View.OnClickListener {
updateStatusIcon(); updateStatusIcon();
} }
/**
* @param incognitoBadgeVisible Whether or not the incognito badge is visible.
*/
public void setIncognitoBadgeVisibility(boolean incognitoBadgeVisible) {
mMediator.setIncognitoBadgeVisibility(incognitoBadgeVisible);
}
/** /**
* Updates the security icon displayed in the LocationBar. * Updates the security icon displayed in the LocationBar.
*/ */
......
...@@ -80,7 +80,8 @@ class BottomToolbarCoordinator { ...@@ -80,7 +80,8 @@ class BottomToolbarCoordinator {
TabCountProvider tabCountProvider, IncognitoStateProvider incognitoStateProvider, TabCountProvider tabCountProvider, IncognitoStateProvider incognitoStateProvider,
ViewGroup topToolbarRoot) { ViewGroup topToolbarRoot) {
mBrowsingModeCoordinator.initializeWithNative(tabSwitcherListener, menuButtonHelper, mBrowsingModeCoordinator.initializeWithNative(tabSwitcherListener, menuButtonHelper,
overviewModeBehavior, tabCountProvider, mThemeColorProvider); overviewModeBehavior, tabCountProvider, mThemeColorProvider,
incognitoStateProvider);
mTabSwitcherModeCoordinator = new TabSwitcherBottomToolbarCoordinator(mTabSwitcherModeStub, mTabSwitcherModeCoordinator = new TabSwitcherBottomToolbarCoordinator(mTabSwitcherModeStub,
topToolbarRoot, incognitoStateProvider, mThemeColorProvider, newTabClickListener, topToolbarRoot, incognitoStateProvider, mThemeColorProvider, newTabClickListener,
closeTabsClickListener, menuButtonHelper, overviewModeBehavior, tabCountProvider); closeTabsClickListener, menuButtonHelper, overviewModeBehavior, tabCountProvider);
......
...@@ -59,7 +59,7 @@ class BottomToolbarNewTabButton extends ChromeImageButton ...@@ -59,7 +59,7 @@ class BottomToolbarNewTabButton extends ChromeImageButton
*/ */
void destroy() { void destroy() {
if (mIncognitoStateProvider != null) { if (mIncognitoStateProvider != null) {
mIncognitoStateProvider.removeObserver((IncognitoStateObserver) this); mIncognitoStateProvider.removeObserver(this);
mIncognitoStateProvider = null; mIncognitoStateProvider = null;
} }
if (mThemeColorProvider != null) { if (mThemeColorProvider != null) {
...@@ -86,6 +86,7 @@ class BottomToolbarNewTabButton extends ChromeImageButton ...@@ -86,6 +86,7 @@ class BottomToolbarNewTabButton extends ChromeImageButton
: R.string.accessibility_toolbar_btn_new_tab; : R.string.accessibility_toolbar_btn_new_tab;
} }
setContentDescription(getResources().getText(resId)); setContentDescription(getResources().getText(resId));
updateBackground();
} }
void setThemeColorProvider(ThemeColorProvider themeColorProvider) { void setThemeColorProvider(ThemeColorProvider themeColorProvider) {
...@@ -96,13 +97,23 @@ class BottomToolbarNewTabButton extends ChromeImageButton ...@@ -96,13 +97,23 @@ class BottomToolbarNewTabButton extends ChromeImageButton
@Override @Override
public void onThemeColorChanged(int primaryColor, boolean shouldAnimate) { public void onThemeColorChanged(int primaryColor, boolean shouldAnimate) {
mBackground.setColorFilter( updateBackground();
ColorUtils.getTextBoxColorForToolbarBackground(mResources, false, primaryColor),
PorterDuff.Mode.SRC_IN);
} }
@Override @Override
public void onTintChanged(ColorStateList tint, boolean useLight) { public void onTintChanged(ColorStateList tint, boolean useLight) {
ApiCompatibilityUtils.setImageTintList(this, tint); ApiCompatibilityUtils.setImageTintList(this, tint);
updateBackground();
}
private void updateBackground() {
if (mThemeColorProvider == null || mIncognitoStateProvider == null) return;
mBackground.setColorFilter(
ColorUtils.getTextBoxColorForToolbarBackground(mResources, false,
mThemeColorProvider.getThemeColor(),
mThemeColorProvider.useLight()
&& mIncognitoStateProvider.isIncognitoSelected()),
PorterDuff.Mode.SRC_IN);
} }
} }
...@@ -17,6 +17,7 @@ import org.chromium.chrome.browser.compositor.layouts.OverviewModeBehavior; ...@@ -17,6 +17,7 @@ import org.chromium.chrome.browser.compositor.layouts.OverviewModeBehavior;
import org.chromium.chrome.browser.feature_engagement.TrackerFactory; import org.chromium.chrome.browser.feature_engagement.TrackerFactory;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.toolbar.HomeButton; import org.chromium.chrome.browser.toolbar.HomeButton;
import org.chromium.chrome.browser.toolbar.IncognitoStateProvider;
import org.chromium.chrome.browser.toolbar.MenuButton; import org.chromium.chrome.browser.toolbar.MenuButton;
import org.chromium.chrome.browser.toolbar.TabCountProvider; import org.chromium.chrome.browser.toolbar.TabCountProvider;
import org.chromium.chrome.browser.toolbar.TabSwitcherButtonCoordinator; import org.chromium.chrome.browser.toolbar.TabSwitcherButtonCoordinator;
...@@ -106,16 +107,19 @@ public class BrowsingModeBottomToolbarCoordinator { ...@@ -106,16 +107,19 @@ public class BrowsingModeBottomToolbarCoordinator {
* @param overviewModeBehavior The overview mode manager. * @param overviewModeBehavior The overview mode manager.
* @param tabCountProvider Updates the tab count number in the tab switcher button. * @param tabCountProvider Updates the tab count number in the tab switcher button.
* @param themeColorProvider Notifies components when theme color changes. * @param themeColorProvider Notifies components when theme color changes.
* @param incognitoStateProvider Notifies components when incognito state changes.
*/ */
void initializeWithNative(OnClickListener tabSwitcherListener, void initializeWithNative(OnClickListener tabSwitcherListener,
AppMenuButtonHelper menuButtonHelper, OverviewModeBehavior overviewModeBehavior, AppMenuButtonHelper menuButtonHelper, OverviewModeBehavior overviewModeBehavior,
TabCountProvider tabCountProvider, ThemeColorProvider themeColorProvider) { TabCountProvider tabCountProvider, ThemeColorProvider themeColorProvider,
IncognitoStateProvider incognitoStateProvider) {
mMediator.setOverviewModeBehavior(overviewModeBehavior); mMediator.setOverviewModeBehavior(overviewModeBehavior);
mMediator.setThemeColorProvider(themeColorProvider); mMediator.setThemeColorProvider(themeColorProvider);
mHomeButton.setThemeColorProvider(themeColorProvider); mHomeButton.setThemeColorProvider(themeColorProvider);
mShareButton.setThemeColorProvider(themeColorProvider); mShareButton.setThemeColorProvider(themeColorProvider);
mSearchAccelerator.setThemeColorProvider(themeColorProvider); mSearchAccelerator.setThemeColorProvider(themeColorProvider);
mSearchAccelerator.setIncognitoStateProvider(incognitoStateProvider);
mTabSwitcherButtonCoordinator.setTabSwitcherListener(tabSwitcherListener); mTabSwitcherButtonCoordinator.setTabSwitcherListener(tabSwitcherListener);
mTabSwitcherButtonCoordinator.setThemeColorProvider(themeColorProvider); mTabSwitcherButtonCoordinator.setThemeColorProvider(themeColorProvider);
......
...@@ -16,22 +16,28 @@ import org.chromium.chrome.R; ...@@ -16,22 +16,28 @@ import org.chromium.chrome.R;
import org.chromium.chrome.browser.ThemeColorProvider; import org.chromium.chrome.browser.ThemeColorProvider;
import org.chromium.chrome.browser.ThemeColorProvider.ThemeColorObserver; import org.chromium.chrome.browser.ThemeColorProvider.ThemeColorObserver;
import org.chromium.chrome.browser.ThemeColorProvider.TintObserver; import org.chromium.chrome.browser.ThemeColorProvider.TintObserver;
import org.chromium.chrome.browser.toolbar.IncognitoStateProvider;
import org.chromium.chrome.browser.toolbar.IncognitoStateProvider.IncognitoStateObserver;
import org.chromium.chrome.browser.util.ColorUtils; import org.chromium.chrome.browser.util.ColorUtils;
import org.chromium.ui.widget.ChromeImageButton; import org.chromium.ui.widget.ChromeImageButton;
/** /**
* The search accelerator. * The search accelerator.
*/ */
class SearchAccelerator extends ChromeImageButton implements ThemeColorObserver, TintObserver { class SearchAccelerator extends ChromeImageButton
/** A provider that notifies components when the theme color changes.*/ implements ThemeColorObserver, TintObserver, IncognitoStateObserver {
private ThemeColorProvider mThemeColorProvider;
/** The gray pill background behind the search icon. */ /** The gray pill background behind the search icon. */
private final Drawable mBackground; private final Drawable mBackground;
/** The {@link Resources} used to compute the background color. */ /** The {@link Resources} used to compute the background color. */
private final Resources mResources; private final Resources mResources;
/** A provider that notifies components when the theme color changes.*/
private ThemeColorProvider mThemeColorProvider;
/** A provider that notifies when incognito mode is entered or exited. */
private IncognitoStateProvider mIncognitoStateProvider;
public SearchAccelerator(Context context, AttributeSet attrs) { public SearchAccelerator(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
...@@ -48,23 +54,45 @@ class SearchAccelerator extends ChromeImageButton implements ThemeColorObserver, ...@@ -48,23 +54,45 @@ class SearchAccelerator extends ChromeImageButton implements ThemeColorObserver,
mThemeColorProvider.addTintObserver(this); mThemeColorProvider.addTintObserver(this);
} }
void setIncognitoStateProvider(IncognitoStateProvider provider) {
mIncognitoStateProvider = provider;
mIncognitoStateProvider.addIncognitoStateObserverAndTrigger(this);
}
void destroy() { void destroy() {
if (mThemeColorProvider != null) { if (mThemeColorProvider != null) {
mThemeColorProvider.removeThemeColorObserver(this); mThemeColorProvider.removeThemeColorObserver(this);
mThemeColorProvider.removeTintObserver(this); mThemeColorProvider.removeTintObserver(this);
mThemeColorProvider = null; mThemeColorProvider = null;
} }
if (mIncognitoStateProvider != null) {
mIncognitoStateProvider.removeObserver(this);
mIncognitoStateProvider = null;
}
} }
@Override @Override
public void onThemeColorChanged(int color, boolean shouldAnimate) { public void onThemeColorChanged(int color, boolean shouldAnimate) {
mBackground.setColorFilter( updateBackground();
ColorUtils.getTextBoxColorForToolbarBackground(mResources, false, color),
PorterDuff.Mode.SRC_IN);
} }
@Override @Override
public void onTintChanged(ColorStateList tint, boolean useLight) { public void onTintChanged(ColorStateList tint, boolean useLight) {
ApiCompatibilityUtils.setImageTintList(this, tint); ApiCompatibilityUtils.setImageTintList(this, tint);
} }
@Override
public void onIncognitoStateChanged(boolean isIncognito) {
updateBackground();
}
private void updateBackground() {
if (mThemeColorProvider == null || mIncognitoStateProvider == null) return;
mBackground.setColorFilter(ColorUtils.getTextBoxColorForToolbarBackground(mResources, false,
mThemeColorProvider.getThemeColor(),
mIncognitoStateProvider.isIncognitoSelected()),
PorterDuff.Mode.SRC_IN);
}
} }
...@@ -437,7 +437,8 @@ public class ToolbarPhone extends ToolbarLayout implements Invalidator.Client, O ...@@ -437,7 +437,8 @@ public class ToolbarPhone extends ToolbarLayout implements Invalidator.Client, O
* @return The location bar color. * @return The location bar color.
*/ */
private int getLocationBarColorForToolbarColor(int toolbarColor) { private int getLocationBarColorForToolbarColor(int toolbarColor) {
return ColorUtils.getTextBoxColorForToolbarBackground(getResources(), false, toolbarColor); return ColorUtils.getTextBoxColorForToolbarBackground(
getResources(), false, toolbarColor, isIncognito());
} }
private void inflateTabSwitchingResources() { private void inflateTabSwitchingResources() {
......
...@@ -371,8 +371,8 @@ public class ToolbarTablet extends ToolbarLayout ...@@ -371,8 +371,8 @@ public class ToolbarTablet extends ToolbarLayout
@Override @Override
public void onThemeColorChanged(int color, boolean shouldAnimate) { public void onThemeColorChanged(int color, boolean shouldAnimate) {
setBackgroundColor(color); setBackgroundColor(color);
final int textBoxColor = final int textBoxColor = ColorUtils.getTextBoxColorForToolbarBackground(
ColorUtils.getTextBoxColorForToolbarBackground(getResources(), false, color); getResources(), false, color, isIncognito());
mLocationBar.getBackground().setColorFilter(textBoxColor, PorterDuff.Mode.SRC_IN); mLocationBar.getBackground().setColorFilter(textBoxColor, PorterDuff.Mode.SRC_IN);
mLocationBar.updateVisualsForState(); mLocationBar.updateVisualsForState();
......
...@@ -134,10 +134,21 @@ public class ColorUtils { ...@@ -134,10 +134,21 @@ public class ColorUtils {
* that this should be false if the returned text box color is * that this should be false if the returned text box color is
* not used in an NTP. * not used in an NTP.
* @param color The color of the toolbar background. * @param color The color of the toolbar background.
* @param isIncognito Whether or not the color is used for incognito mode.
* @return The base color for the textbox given a toolbar background color. * @return The base color for the textbox given a toolbar background color.
*/ */
public static int getTextBoxColorForToolbarBackground( public static int getTextBoxColorForToolbarBackground(
Resources res, boolean isLocationBarShownInNtp, int color) { Resources res, boolean isLocationBarShownInNtp, int color, boolean isIncognito) {
// Text box color on default toolbar background in incognito mode is a pre-defined
// color. We calculate the equivalent opaque color from the pre-defined translucent color.
if (isIncognito) {
final int overlayColor = ApiCompatibilityUtils.getColor(
res, R.color.toolbar_text_box_background_incognito);
final float overlayColorAlpha = Color.alpha(overlayColor) / 255f;
final int overlayColorOpaque = overlayColor & 0xFF000000;
return getColorWithOverlay(color, overlayColorOpaque, overlayColorAlpha);
}
// NTP should have no visible text box in the toolbar, so just return the NTP // NTP should have no visible text box in the toolbar, so just return the NTP
// background color. // background color.
if (isLocationBarShownInNtp) return getPrimaryBackgroundColor(res, false); if (isLocationBarShownInNtp) return getPrimaryBackgroundColor(res, false);
......
...@@ -3380,6 +3380,9 @@ To change this setting, <ph name="BEGIN_LINK">&lt;resetlink&gt;</ph>reset sync<p ...@@ -3380,6 +3380,9 @@ To change this setting, <ph name="BEGIN_LINK">&lt;resetlink&gt;</ph>reset sync<p
<message name="IDS_ACCESSIBILITY_TOOLBAR_BTN_CLOSE_ALL_PRIVATE_TABS" desc="Content description for the close all private tabs button."> <message name="IDS_ACCESSIBILITY_TOOLBAR_BTN_CLOSE_ALL_PRIVATE_TABS" desc="Content description for the close all private tabs button.">
Close all private tabs Close all private tabs
</message> </message>
<message name="IDS_ACCESSIBILITY_INCOGNITO_BADGE" desc="Content description for the badge indicating that the user is in Incognito mode.">
Incognito mode
</message>
<message name="IDS_ACCESSIBILITY_TOOLBAR_BTN_TABSWITCHER_TOGGLE" desc="Content description for the button that enters or leaves the tab switcher. [ICU Syntax]"> <message name="IDS_ACCESSIBILITY_TOOLBAR_BTN_TABSWITCHER_TOGGLE" desc="Content description for the button that enters or leaves the tab switcher. [ICU Syntax]">
{OPEN_TABS, plural, {OPEN_TABS, plural,
......
894b3902bd07fab8bacd6149ffba06440b4ed691
\ No newline at end of file
// Copyright 2019 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.
package org.chromium.chrome.browser.omnibox.status;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertFalse;
import static org.chromium.content_public.browser.test.util.TestThreadUtils.runOnUiThreadBlocking;
import android.support.test.filters.MediumTest;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.R;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.ui.DummyUiActivityTestCase;
import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.modelutil.PropertyModelChangeProcessor;
/**
* Tests for {@link StatusView} and {@link StatusViewBinder}.
*/
@RunWith(ChromeJUnit4ClassRunner.class)
public class StatusViewTest extends DummyUiActivityTestCase {
private StatusView mStatusView;
private PropertyModel mStatusModel;
private PropertyModelChangeProcessor mStatusMCP;
@Override
public void setUpTest() throws Exception {
super.setUpTest();
runOnUiThreadBlocking(() -> {
ViewGroup view = new LinearLayout(getActivity());
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
getActivity().setContentView(view, params);
mStatusView = getActivity()
.getLayoutInflater()
.inflate(R.layout.location_status, view, true)
.findViewById(R.id.location_bar_status);
mStatusModel = new PropertyModel.Builder(StatusProperties.ALL_KEYS).build();
mStatusMCP = PropertyModelChangeProcessor.create(
mStatusModel, mStatusView, new StatusViewBinder());
});
}
@Override
public void tearDownTest() throws Exception {
mStatusMCP.destroy();
super.tearDownTest();
}
@Test
@MediumTest
@Feature({"Omnibox"})
public void testIncognitoBadgeVisibility() {
// Verify that the incognito badge is not inflated by default.
assertFalse(mStatusModel.get(StatusProperties.INCOGNITO_BADGE_VISIBLE));
onView(withId(R.id.location_bar_incognito_badge)).check(doesNotExist());
// Set incognito badge visible.
runOnUiThreadBlocking(
() -> { mStatusModel.set(StatusProperties.INCOGNITO_BADGE_VISIBLE, true); });
onView(withId(R.id.location_bar_incognito_badge)).check(matches(isCompletelyDisplayed()));
// Set incognito badge gone.
runOnUiThreadBlocking(
() -> { mStatusModel.set(StatusProperties.INCOGNITO_BADGE_VISIBLE, false); });
onView(withId(R.id.location_bar_incognito_badge)).check(matches(not(isDisplayed())));
}
}
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