[GMNext][TabSiwtcher] Change the toolbar background and icon tint

Force TabSelectionEditorToolbar to use colorSurface.

Note that this change does not work to change color onScroll.

Bug: 1217141, 1232307, 1233209
Change-Id: I7ceb7fb9b2412a54015a73b6c2353eb9197cef23
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3050150
Commit-Queue: Wenyu Fu <wenyufu@chromium.org>
Reviewed-by: Theresa  <twellington@chromium.org>
Reviewed-by: Sinan Sahin <sinansahin@google.com>
Reviewed-by: Yue Zhang <yuezhanggg@chromium.org>
Reviewed-by: Sky Malice <skym@chromium.org>
Cr-Commit-Position: refs/heads/master@{#909391}
diff --git a/chrome/android/features/tab_ui/java/res/values/colors.xml b/chrome/android/features/tab_ui/java/res/values/colors.xml
index 7dcaa53..2dda876 100644
--- a/chrome/android/features/tab_ui/java/res/values/colors.xml
+++ b/chrome/android/features/tab_ui/java/res/values/colors.xml
@@ -74,4 +74,6 @@
 
     <color name="incognito_tab_grid_dialog_ungroup_bar_text_color">@color/baseline_primary_200</color>
     <color name="incognito_tab_grid_dialog_ungroup_bar_text_hovered_color">@color/modern_white</color>
+
+    <color name="incognito_tab_selection_editor_toolbar_bg_color">@color/toolbar_background_primary_dark</color>
 </resources>
diff --git a/chrome/android/features/tab_ui/java/src/org/chromium/chrome/browser/tasks/tab_management/TabSelectionEditorLayoutBinder.java b/chrome/android/features/tab_ui/java/src/org/chromium/chrome/browser/tasks/tab_management/TabSelectionEditorLayoutBinder.java
index 5ba4d1eb..5dcb7e89 100644
--- a/chrome/android/features/tab_ui/java/src/org/chromium/chrome/browser/tasks/tab_management/TabSelectionEditorLayoutBinder.java
+++ b/chrome/android/features/tab_ui/java/src/org/chromium/chrome/browser/tasks/tab_management/TabSelectionEditorLayoutBinder.java
@@ -36,12 +36,12 @@
         } else if (TabSelectionEditorProperties.TOOLBAR_BACKGROUND_COLOR == propertyKey) {
             view.getToolbar().setToolbarBackgroundColor(
                     model.get(TabSelectionEditorProperties.TOOLBAR_BACKGROUND_COLOR));
+        } else if (TabSelectionEditorProperties.TOOLBAR_GROUP_TEXT_TINT == propertyKey) {
+            view.getToolbar().setTextColorStateList(
+                    model.get(TabSelectionEditorProperties.TOOLBAR_GROUP_TEXT_TINT));
         } else if (TabSelectionEditorProperties.TOOLBAR_GROUP_BUTTON_TINT == propertyKey) {
             view.getToolbar().setButtonTint(
                     model.get(TabSelectionEditorProperties.TOOLBAR_GROUP_BUTTON_TINT));
-        } else if (TabSelectionEditorProperties.TOOLBAR_TEXT_APPEARANCE == propertyKey) {
-            view.getToolbar().setTextAppearance(
-                    model.get(TabSelectionEditorProperties.TOOLBAR_TEXT_APPEARANCE));
         } else if (TabSelectionEditorProperties.TOOLBAR_ACTION_BUTTON_TEXT == propertyKey) {
             view.getToolbar().setActionButtonText(
                     model.get(TabSelectionEditorProperties.TOOLBAR_ACTION_BUTTON_TEXT));
diff --git a/chrome/android/features/tab_ui/java/src/org/chromium/chrome/browser/tasks/tab_management/TabSelectionEditorMediator.java b/chrome/android/features/tab_ui/java/src/org/chromium/chrome/browser/tasks/tab_management/TabSelectionEditorMediator.java
index 77c0042..4a5cc3b 100644
--- a/chrome/android/features/tab_ui/java/src/org/chromium/chrome/browser/tasks/tab_management/TabSelectionEditorMediator.java
+++ b/chrome/android/features/tab_ui/java/src/org/chromium/chrome/browser/tasks/tab_management/TabSelectionEditorMediator.java
@@ -10,9 +10,7 @@
 
 import androidx.annotation.ColorInt;
 import androidx.annotation.Nullable;
-import androidx.appcompat.content.res.AppCompatResources;
 
-import org.chromium.base.ApiCompatibilityUtils;
 import org.chromium.chrome.browser.tab.Tab;
 import org.chromium.chrome.browser.tab.TabCreationState;
 import org.chromium.chrome.browser.tab.TabLaunchType;
@@ -22,7 +20,7 @@
 import org.chromium.chrome.browser.tabmodel.TabModelSelectorTabModelObserver;
 import org.chromium.chrome.browser.tabmodel.TabModelUtils;
 import org.chromium.chrome.browser.tasks.tab_management.TabSelectionEditorCoordinator.TabSelectionEditorNavigationProvider;
-import org.chromium.chrome.tab_ui.R;
+import org.chromium.components.browser_ui.styles.ChromeColors;
 import org.chromium.components.browser_ui.widget.selectable_list.SelectionDelegate;
 import org.chromium.ui.modelutil.PropertyModel;
 
@@ -119,31 +117,11 @@
                 // Incognito in both light/dark theme is the same as non-incognito mode in dark
                 // theme. Non-incognito mode and incognito in both light/dark themes in dark theme
                 // all look dark.
-                boolean isIncognito = newModel.isIncognito();
-                @ColorInt
-                int primaryColor = ApiCompatibilityUtils.getColor(mContext.getResources(),
-                        isIncognito ? R.color.default_bg_color_dark : R.color.default_bg_color);
-                // TODO(995876): Update color modern_blue_300 to active_color_dark when the
-                // associated bug is landed.
-                @ColorInt
-                int toolbarBackgroundColor = ApiCompatibilityUtils.getColor(mContext.getResources(),
-                        isIncognito ? R.color.modern_blue_300
-                                    : R.color.default_control_color_active);
-                ColorStateList toolbarTintColorList = AppCompatResources.getColorStateList(mContext,
-                        isIncognito ? R.color.dark_text_color_list
-                                    : R.color.default_text_color_inverse_list);
-                int textAppearance = isIncognito ? R.style.TextAppearance_Headline_Primary_Dark
-                                                 : R.style.TextAppearance_Headline_Primary_Inverse;
-
-                mModel.set(TabSelectionEditorProperties.PRIMARY_COLOR, primaryColor);
-                mModel.set(TabSelectionEditorProperties.TOOLBAR_BACKGROUND_COLOR,
-                        toolbarBackgroundColor);
-                mModel.set(TabSelectionEditorProperties.TOOLBAR_GROUP_BUTTON_TINT,
-                        toolbarTintColorList);
-                mModel.set(TabSelectionEditorProperties.TOOLBAR_TEXT_APPEARANCE, textAppearance);
+                updateColors(newModel.isIncognito());
             }
         };
         mTabModelSelector.addObserver(mTabModelSelectorObserver);
+        updateColors(mTabModelSelector.isIncognitoSelected());
 
         // Default action for action button is to group selected tabs.
         mActionProvider = new TabSelectionEditorActionProvider(
@@ -157,6 +135,21 @@
         return mModel.get(TabSelectionEditorProperties.IS_VISIBLE);
     }
 
+    private void updateColors(boolean isIncognito) {
+        @ColorInt
+        int primaryColor = ChromeColors.getPrimaryBackgroundColor(mContext, isIncognito);
+        @ColorInt
+        int toolbarBackgroundColor =
+                TabUiThemeProvider.getTabSelectionToolbarBackground(mContext, isIncognito);
+        ColorStateList toolbarTintColorList =
+                TabUiThemeProvider.getTabSelectionToolbarIconTintList(mContext, isIncognito);
+
+        mModel.set(TabSelectionEditorProperties.PRIMARY_COLOR, primaryColor);
+        mModel.set(TabSelectionEditorProperties.TOOLBAR_BACKGROUND_COLOR, toolbarBackgroundColor);
+        mModel.set(TabSelectionEditorProperties.TOOLBAR_GROUP_TEXT_TINT, toolbarTintColorList);
+        mModel.set(TabSelectionEditorProperties.TOOLBAR_GROUP_BUTTON_TINT, toolbarTintColorList);
+    }
+
     /**
      * {@link TabSelectionEditorCoordinator.TabSelectionEditorController} implementation.
      */
diff --git a/chrome/android/features/tab_ui/java/src/org/chromium/chrome/browser/tasks/tab_management/TabSelectionEditorProperties.java b/chrome/android/features/tab_ui/java/src/org/chromium/chrome/browser/tasks/tab_management/TabSelectionEditorProperties.java
index e5e6101..2410368 100644
--- a/chrome/android/features/tab_ui/java/src/org/chromium/chrome/browser/tasks/tab_management/TabSelectionEditorProperties.java
+++ b/chrome/android/features/tab_ui/java/src/org/chromium/chrome/browser/tasks/tab_management/TabSelectionEditorProperties.java
@@ -38,11 +38,12 @@
             new PropertyModel.WritableIntPropertyKey();
 
     public static final PropertyModel
-            .WritableObjectPropertyKey<ColorStateList> TOOLBAR_GROUP_BUTTON_TINT =
+            .WritableObjectPropertyKey<ColorStateList> TOOLBAR_GROUP_TEXT_TINT =
             new PropertyModel.WritableObjectPropertyKey<>();
 
-    public static final PropertyModel.WritableIntPropertyKey TOOLBAR_TEXT_APPEARANCE =
-            new PropertyModel.WritableIntPropertyKey();
+    public static final PropertyModel
+            .WritableObjectPropertyKey<ColorStateList> TOOLBAR_GROUP_BUTTON_TINT =
+            new PropertyModel.WritableObjectPropertyKey<>();
 
     public static final PropertyModel
             .WritableIntPropertyKey TOOLBAR_ACTION_BUTTON_DESCRIPTION_RESOURCE_ID =
@@ -51,6 +52,6 @@
     public static final PropertyKey[] ALL_KEYS = new PropertyKey[] {IS_VISIBLE,
             TOOLBAR_ACTION_BUTTON_LISTENER, TOOLBAR_ACTION_BUTTON_TEXT,
             TOOLBAR_ACTION_BUTTON_ENABLING_THRESHOLD, TOOLBAR_NAVIGATION_LISTENER, PRIMARY_COLOR,
-            TOOLBAR_BACKGROUND_COLOR, TOOLBAR_GROUP_BUTTON_TINT, TOOLBAR_TEXT_APPEARANCE,
+            TOOLBAR_BACKGROUND_COLOR, TOOLBAR_GROUP_TEXT_TINT, TOOLBAR_GROUP_BUTTON_TINT,
             TOOLBAR_ACTION_BUTTON_DESCRIPTION_RESOURCE_ID};
 }
diff --git a/chrome/android/features/tab_ui/java/src/org/chromium/chrome/browser/tasks/tab_management/TabSelectionEditorToolbar.java b/chrome/android/features/tab_ui/java/src/org/chromium/chrome/browser/tasks/tab_management/TabSelectionEditorToolbar.java
index 44ee9ad..2bdb5ad 100644
--- a/chrome/android/features/tab_ui/java/src/org/chromium/chrome/browser/tasks/tab_management/TabSelectionEditorToolbar.java
+++ b/chrome/android/features/tab_ui/java/src/org/chromium/chrome/browser/tasks/tab_management/TabSelectionEditorToolbar.java
@@ -120,11 +120,11 @@
     }
 
     /**
-     * Update the text appearance for {@link NumberRollView}.
-     * @param resId The new text appearance to use.
+     * Update the {@link ColorStateList} used for text in {@link NumberRollView}.
+     * @param colorStateList The new {@link ColorStateList} to use.
      */
-    public void setTextAppearance(int resId) {
-        mNumberRollView.setTextAppearance(resId);
+    public void setTextColorStateList(ColorStateList colorStateList) {
+        mNumberRollView.setTextColorStateList(colorStateList);
     }
 
     /**
diff --git a/chrome/android/features/tab_ui/java/src/org/chromium/chrome/browser/tasks/tab_management/TabUiThemeProvider.java b/chrome/android/features/tab_ui/java/src/org/chromium/chrome/browser/tasks/tab_management/TabUiThemeProvider.java
index 6b35a5d..dcee530 100644
--- a/chrome/android/features/tab_ui/java/src/org/chromium/chrome/browser/tasks/tab_management/TabUiThemeProvider.java
+++ b/chrome/android/features/tab_ui/java/src/org/chromium/chrome/browser/tasks/tab_management/TabUiThemeProvider.java
@@ -507,6 +507,50 @@
     }
 
     /**
+     * Return the background color used for tab UI toolbar in selection edit mode.
+     *
+     * @param context {@link Context} used to retrieve color.
+     * @param isIncognito Whether the color is used for incognito mode.
+     * @return The background color for the toolbar when tab switcher is in selection edit mode.
+     */
+    @ColorInt
+    public static int getTabSelectionToolbarBackground(Context context, boolean isIncognito) {
+        if (!themeRefactorEnabled()) {
+            return ApiCompatibilityUtils.getColor(context.getResources(),
+                    isIncognito ? R.color.default_control_color_active_dark
+                                : R.color.default_control_color_active);
+        } else {
+            if (isIncognito) {
+                return ApiCompatibilityUtils.getColor(context.getResources(),
+                        R.color.incognito_tab_selection_editor_toolbar_bg_color);
+            } else {
+                return MaterialColors.getColor(context, R.attr.colorSurface, TAG);
+            }
+        }
+    }
+
+    /**
+     * Returns the {@link ColorStateList} for icons on the tab UI toolbar in selection edit mode.
+     *
+     * @param context {@link Context} used to retrieve color.
+     * @param isIncognito Whether the color is used for incognito mode.
+     * @return The {@link ColorStateList} for icons on the toolbar when tab switcher is in selection
+     *         edit mode.
+     */
+    public static ColorStateList getTabSelectionToolbarIconTintList(
+            Context context, boolean isIncognito) {
+        if (!themeRefactorEnabled()) {
+            return AppCompatResources.getColorStateList(context,
+                    isIncognito ? R.color.dark_text_color_list
+                                : R.color.default_text_color_inverse_list);
+        }
+
+        return AppCompatResources.getColorStateList(context,
+                isIncognito ? R.color.default_text_color_light_list
+                            : R.color.default_text_color_list);
+    }
+
+    /**
      * Returns the message card background resource id based on the incognito mode.
      *
      * @param isIncognito Whether the resource is used for incognito mode.
diff --git a/components/browser_ui/widget/android/java/src/org/chromium/components/browser_ui/widget/NumberRollView.java b/components/browser_ui/widget/android/java/src/org/chromium/components/browser_ui/widget/NumberRollView.java
index b26408b..74f1938 100644
--- a/components/browser_ui/widget/android/java/src/org/chromium/components/browser_ui/widget/NumberRollView.java
+++ b/components/browser_ui/widget/android/java/src/org/chromium/components/browser_ui/widget/NumberRollView.java
@@ -7,6 +7,7 @@
 import android.animation.Animator;
 import android.animation.ObjectAnimator;
 import android.content.Context;
+import android.content.res.ColorStateList;
 import android.util.AttributeSet;
 import android.util.Property;
 import android.widget.FrameLayout;
@@ -155,11 +156,11 @@
     }
 
     /**
-     * Update the text appearance for both {@link TextView}.
-     * @param resId The new text appearance to use.
+     * Update the text color with {@link ColorStateList} for both {@link TextView}.
+     * @param resId The new text {@link ColorStateList} to use.
      */
-    public void setTextAppearance(int resId) {
-        mUpNumber.setTextAppearance(mUpNumber.getContext(), resId);
-        mDownNumber.setTextAppearance(mDownNumber.getContext(), resId);
+    public void setTextColorStateList(ColorStateList colorStateList) {
+        mUpNumber.setTextColor(colorStateList);
+        mDownNumber.setTextColor(colorStateList);
     }
 }
\ No newline at end of file