Skip to content

Commit

Permalink
[Tab Strip Redesign] Update status bar color
Browse files Browse the repository at this point in the history
Folio-light: https://screenshot.googleplex.com/BqMeCUzxFxLTDbH
Folio-dark: https://screenshot.googleplex.com/5SYn4BBvxvCQHLU

Detached-light: https://screenshot.googleplex.com/463FyKJcrpx3pmY
Detached-dark: https://screenshot.googleplex.com/5AY3uekMRV8oVxr

Settings-light: https://screenshot.googleplex.com/4RvSk8BE5iST8UA
Settings-dark: https://screenshot.googleplex.com/AJA4epJSFPkLF99

Bug: 1373631
Change-Id: I94a1f1a08975d9ed7c892defa99ea47b8b144d42
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4017176
Reviewed-by: Neil Coronado <nemco@google.com>
Reviewed-by: Theresa Sullivan <twellington@chromium.org>
Commit-Queue: Zhe Li <zheliooo@google.com>
Reviewed-by: Sirisha Kavuluru <skavuluru@google.com>
Cr-Commit-Position: refs/heads/main@{#1070577}
  • Loading branch information
Zhe Li authored and Chromium LUCI CQ committed Nov 12, 2022
1 parent 1fe6bf6 commit cde1a64
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.android.material.elevation.ElevationOverlayProvider;

import org.chromium.chrome.tab_ui.R;
import org.chromium.components.browser_ui.styles.ChromeColors;
import org.chromium.components.browser_ui.styles.SemanticColorUtils;

/**
Expand Down Expand Up @@ -54,6 +55,34 @@ public static int getCardViewBackgroundColor(
}
}

/**
* Returns the color for the tab strip background.
*
* @param context {@link Context} used to retrieve color.
* @param isIncognito Whether the color is used for incognito mode.
* @return The {@link ColorInt} for tab strip redesign background.
*/
public static @ColorInt int getTabStripBackgroundColor(Context context, boolean isIncognito) {
if (TabUiFeatureUtilities.isTabStripFolioEnabled()) {
if (isIncognito) {
return Color.BLACK;
}
// @TODO(crbug.com/1373630): May change the color for night theme after finalizing the
// spec
return ChromeColors.getSurfaceColor(
context, org.chromium.chrome.R.dimen.default_elevation_2);
} else if (TabUiFeatureUtilities.isTabStripDetachedEnabled()) {
if (isIncognito) {
// Use a non-dynamic dark background color for incognito, slightly greyer than
// Color.BLACK
return ChromeColors.getPrimaryBackgroundColor(context, isIncognito);
}
return ChromeColors.getSurfaceColor(
context, org.chromium.chrome.R.dimen.default_elevation_0);
}
return Color.BLACK;
}

/**
* Returns the text color for the number used on the tab group cards based on the incognito
* mode.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.RectF;
import android.os.Handler;
import android.os.SystemClock;
Expand Down Expand Up @@ -52,7 +51,7 @@
import org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver;
import org.chromium.chrome.browser.tasks.tab_groups.TabGroupModelFilter;
import org.chromium.chrome.browser.tasks.tab_management.TabUiFeatureUtilities;
import org.chromium.components.browser_ui.styles.ChromeColors;
import org.chromium.chrome.browser.tasks.tab_management.TabUiThemeProvider;
import org.chromium.components.browser_ui.widget.animation.Interpolators;
import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.ui.base.LocalizationUtils;
Expand Down Expand Up @@ -685,23 +684,7 @@ public int getOrientation() {
}

public @ColorInt int getBackgroundColor() {
if (TabUiFeatureUtilities.isTabStripFolioEnabled()) {
if (mIsIncognito) {
return Color.BLACK;
}
// @TODO(crbug.com/1373630): May change the color for night theme after finalizing the
// spec
return ChromeColors.getSurfaceColor(mContext, R.dimen.default_elevation_2);
} else if (TabUiFeatureUtilities.isTabStripDetachedEnabled()) {
if (mIsIncognito) {
// Use a non-dynamic dark background color for incognito, slightly greyer than
// Color.BLACK
return ChromeColors.getPrimaryBackgroundColor(mContext, mIsIncognito);
}
return ChromeColors.getSurfaceColor(mContext, R.dimen.default_elevation_0);
}
// This is the default color for tab strip and fades
return Color.BLACK;
return TabUiThemeProvider.getTabStripBackgroundColor(mContext, mIsIncognito);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.content.res.Configuration;
import android.graphics.Color;
import android.os.Build;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
Expand All @@ -38,6 +39,7 @@
import org.chromium.chrome.browser.browsing_data.ClearBrowsingDataFragmentBasic;
import org.chromium.chrome.browser.feedback.FragmentHelpAndFeedbackLauncher;
import org.chromium.chrome.browser.feedback.HelpAndFeedbackLauncherImpl;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.history.HistoryActivity;
import org.chromium.chrome.browser.image_descriptions.ImageDescriptionsController;
import org.chromium.chrome.browser.image_descriptions.ImageDescriptionsSettings;
Expand Down Expand Up @@ -76,6 +78,7 @@
import org.chromium.components.browser_ui.widget.scrim.ScrimCoordinator;
import org.chromium.ui.KeyboardVisibilityDelegate;
import org.chromium.ui.UiUtils;
import org.chromium.ui.base.DeviceFormFactor;
import org.chromium.ui.modaldialog.ModalDialogManager;
import org.chromium.ui.modaldialog.ModalDialogManager.ModalDialogType;

Expand Down Expand Up @@ -471,7 +474,13 @@ private void ensureActivityNotExported() {
*/
private void setStatusBarColor() {
// On P+, the status bar color is set via the XML theme.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) return;
if ((!DeviceFormFactor.isNonMultiDisplayContextOnTablet(this)
&& VERSION.SDK_INT >= Build.VERSION_CODES.P)
|| (DeviceFormFactor.isNonMultiDisplayContextOnTablet(this)
&& !ChromeFeatureList.sTabStripRedesign.isEnabled()
&& VERSION.SDK_INT >= Build.VERSION_CODES.P)) {
return;
}

if (UiUtils.isSystemUiThemingDisabled()) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.chromium.chrome.browser.tabmodel.TabModel;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.tabmodel.TabModelSelectorObserver;
import org.chromium.chrome.browser.tasks.tab_management.TabUiThemeProvider;
import org.chromium.chrome.browser.theme.TopUiThemeColorProvider;
import org.chromium.chrome.browser.toolbar.ToolbarColors;
import org.chromium.chrome.browser.toolbar.top.TopToolbarCoordinator;
Expand Down Expand Up @@ -367,9 +368,10 @@ public void updateStatusBarColor(@ColorInt int color) {
return baseStatusBarColor;
}

// We don't adjust status bar color for tablet when status bar color is not overridden by
// StatusBarColorProvider.
if (mIsTablet) return Color.BLACK;
if (mIsTablet) {
return TabUiThemeProvider.getTabStripBackgroundColor(
mWindow.getContext(), mIsIncognito);
}

// When Omnibox gains focus, we want to clear the status bar theme color.
// The theme should be restored when Omnibox focus clears.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package org.chromium.chrome.browser.ui.system;

import static org.junit.Assert.assertEquals;

import android.app.Activity;
import android.graphics.Color;
import android.os.Build;
Expand All @@ -12,6 +14,7 @@
import androidx.test.filters.LargeTest;

import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.ClassRule;
Expand All @@ -34,13 +37,16 @@
import org.chromium.chrome.browser.layouts.LayoutType;
import org.chromium.chrome.browser.tab.TabLaunchType;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.tasks.tab_management.TabUiFeatureUtilities;
import org.chromium.chrome.browser.tasks.tab_management.TabUiThemeProvider;
import org.chromium.chrome.browser.toolbar.top.ToolbarLayout;
import org.chromium.chrome.browser.toolbar.top.ToolbarPhone;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.chrome.test.batch.BlankCTATabInitialStateRule;
import org.chromium.chrome.test.util.OmniboxTestUtils;
import org.chromium.chrome.test.util.browser.Features;
import org.chromium.chrome.test.util.browser.Features.EnableFeatures;
import org.chromium.chrome.test.util.browser.ThemeTestUtils;
import org.chromium.components.browser_ui.styles.ChromeColors;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
Expand Down Expand Up @@ -79,6 +85,12 @@ public void setUp() {
mOmniboxUtils = new OmniboxTestUtils(sActivityTestRule.getActivity());
}

@After
public void tearDown() {
TabUiFeatureUtilities.setTabStripRedesignEnableDetachedForTesting(false);
TabUiFeatureUtilities.setTabStripRedesignEnableFolioForTesting(false);
}

/**
* Test that the status bar color is toggled when toggling incognito while in overview mode.
*/
Expand Down Expand Up @@ -309,6 +321,64 @@ public void testColorWithStatusIndicator_FeatureMatchToolbarColorEnabled() {
initialColor, statusBarColor.get().intValue());
}

/**
* Test status bar color for Tab Strip Redesign Folio.
*/
@Test
@LargeTest
@Feature({"StatusBar"})
@EnableFeatures({ChromeFeatureList.TAB_STRIP_REDESIGN})
@Restriction({UiRestriction.RESTRICTION_TYPE_TABLET})
public void testStatusBarColorForTabStripRedesignFolioTablet() throws Exception {
final ChromeActivity activity = sActivityTestRule.getActivity();
final StatusBarColorController statusBarColorController =
sActivityTestRule.getActivity()
.getRootUiCoordinatorForTesting()
.getStatusBarColorController();

// Before enable tab strip redesign, status bar should be black.
assertEquals("Wrong initial value returned before enable Tab Strip Redesign Folio",
Color.BLACK, activity.getWindow().getStatusBarColor());

// Enable Tab strip redesign folio, and status bar color should update to the same as folio
// background color.
TabUiFeatureUtilities.setTabStripRedesignEnableFolioForTesting(true);
TestThreadUtils.runOnUiThreadBlocking(
() -> statusBarColorController.updateStatusBarColor());
assertEquals("Wrong value returned for Tab Strip Redesign Folio.",
TabUiThemeProvider.getTabStripBackgroundColor(activity, false),
activity.getWindow().getStatusBarColor());
}

/**
* Test status bar color for Tab Strip Redesign Detached.
*/
@Test
@LargeTest
@Feature({"StatusBar"})
@EnableFeatures({ChromeFeatureList.TAB_STRIP_REDESIGN})
@Restriction({UiRestriction.RESTRICTION_TYPE_TABLET})
public void testStatusBarColorForTabStripRedesignDetachedTablet() throws Exception {
final ChromeActivity activity = sActivityTestRule.getActivity();
final StatusBarColorController statusBarColorController =
sActivityTestRule.getActivity()
.getRootUiCoordinatorForTesting()
.getStatusBarColorController();

// Before enable tab strip redesign, status bar should be black.
assertEquals("Wrong initial value returned before enable Tab Strip Redesign Detached",
Color.BLACK, activity.getWindow().getStatusBarColor());

// Enable Tab strip redesign detached, and status bar color should update to the same as
// detached background color.
TabUiFeatureUtilities.setTabStripRedesignEnableDetachedForTesting(true);
TestThreadUtils.runOnUiThreadBlocking(
() -> statusBarColorController.updateStatusBarColor());
assertEquals("Wrong value returned for Tab Strip Redesign Detached.",
TabUiThemeProvider.getTabStripBackgroundColor(activity, false),
activity.getWindow().getStatusBarColor());
}

private int defaultColorFallbackToBlack(int color) {
return (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) ? Color.BLACK : color;
}
Expand Down

0 comments on commit cde1a64

Please sign in to comment.