Commit a65f80f8 authored by Patrick Noland's avatar Patrick Noland Committed by Commit Bot

[ToolbarMVC] Remove direct MenuButton interactions from Tabswitcher

This only requires giving TabSwitcherModeTTCoordinatorPhone a
MenuButtonCoordinator and setting the MenuButton view once inflation happens.
The logic removed (tinting, setting the onClick/accessibilityDelegate)
is now handled internally by MenuButtonCoordinator/MenuButton.

Bug: 1086676
Change-Id: Iafbe6539974406fcd3db0f8a904e581d355a872b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2411401
Commit-Queue: Patrick Noland <pnoland@chromium.org>
Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810750}
parent 5fa65816
...@@ -11,6 +11,7 @@ import android.view.ViewStub; ...@@ -11,6 +11,7 @@ import android.view.ViewStub;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.flags.ChromeFeatureList; import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.incognito.IncognitoUtils; import org.chromium.chrome.browser.incognito.IncognitoUtils;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
...@@ -21,7 +22,7 @@ import org.chromium.chrome.browser.tabmodel.TabModelObserver; ...@@ -21,7 +22,7 @@ import org.chromium.chrome.browser.tabmodel.TabModelObserver;
import org.chromium.chrome.browser.tabmodel.TabModelSelector; import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.tasks.tab_management.TabUiFeatureUtilities; import org.chromium.chrome.browser.tasks.tab_management.TabUiFeatureUtilities;
import org.chromium.chrome.browser.toolbar.TabCountProvider; import org.chromium.chrome.browser.toolbar.TabCountProvider;
import org.chromium.chrome.browser.ui.appmenu.AppMenuButtonHelper; import org.chromium.chrome.browser.toolbar.menu_button.MenuButtonCoordinator;
/** /**
* The coordinator for the tab switcher mode top toolbar shown on phones, responsible for * The coordinator for the tab switcher mode top toolbar shown on phones, responsible for
...@@ -34,12 +35,12 @@ class TabSwitcherModeTTCoordinatorPhone { ...@@ -34,12 +35,12 @@ class TabSwitcherModeTTCoordinatorPhone {
// TODO(twellington): Create a model to hold all of these properties. Consider using // TODO(twellington): Create a model to hold all of these properties. Consider using
// LazyConstructionPropertyMcp to collect all of the properties since it is designed to // LazyConstructionPropertyMcp to collect all of the properties since it is designed to
// aggregate properties and bind them to a view the first time it's shown. // aggregate properties and bind them to a view the first time it's shown.
private AppMenuButtonHelper mAppMenuButtonHelper;
private View.OnClickListener mTabSwitcherListener; private View.OnClickListener mTabSwitcherListener;
private View.OnClickListener mNewTabListener; private View.OnClickListener mNewTabListener;
private TabCountProvider mTabCountProvider; private TabCountProvider mTabCountProvider;
private TabModelSelector mTabModelSelector; private TabModelSelector mTabModelSelector;
private IncognitoStateProvider mIncognitoStateProvider; private IncognitoStateProvider mIncognitoStateProvider;
private MenuButtonCoordinator mMenuButtonCoordinator;
private boolean mAccessibilityEnabled; private boolean mAccessibilityEnabled;
private TabSwitcherModeTTPhone mTabSwitcherModeToolbar; private TabSwitcherModeTTPhone mTabSwitcherModeToolbar;
...@@ -47,8 +48,10 @@ class TabSwitcherModeTTCoordinatorPhone { ...@@ -47,8 +48,10 @@ class TabSwitcherModeTTCoordinatorPhone {
@Nullable @Nullable
private TabModelObserver mTabModelObserver; private TabModelObserver mTabModelObserver;
TabSwitcherModeTTCoordinatorPhone(ViewStub tabSwitcherToolbarStub) { TabSwitcherModeTTCoordinatorPhone(
ViewStub tabSwitcherToolbarStub, MenuButtonCoordinator menuButtonCoordinator) {
mTabSwitcherToolbarStub = tabSwitcherToolbarStub; mTabSwitcherToolbarStub = tabSwitcherToolbarStub;
mMenuButtonCoordinator = menuButtonCoordinator;
} }
/** /**
...@@ -62,6 +65,10 @@ class TabSwitcherModeTTCoordinatorPhone { ...@@ -62,6 +65,10 @@ class TabSwitcherModeTTCoordinatorPhone {
if (mTabModelSelector != null && mTabModelObserver != null) { if (mTabModelSelector != null && mTabModelObserver != null) {
mTabModelSelector.getModel(true).removeObserver(mTabModelObserver); mTabModelSelector.getModel(true).removeObserver(mTabModelObserver);
} }
if (mMenuButtonCoordinator != null) {
mMenuButtonCoordinator.destroy();
mMenuButtonCoordinator = null;
}
} }
/** /**
...@@ -80,16 +87,6 @@ class TabSwitcherModeTTCoordinatorPhone { ...@@ -80,16 +87,6 @@ class TabSwitcherModeTTCoordinatorPhone {
} }
} }
/**
* @param appMenuButtonHelper The helper for managing menu button interactions.
*/
void setAppMenuButtonHelper(AppMenuButtonHelper appMenuButtonHelper) {
mAppMenuButtonHelper = appMenuButtonHelper;
if (mTabSwitcherModeToolbar != null) {
mTabSwitcherModeToolbar.setAppMenuButtonHelper(appMenuButtonHelper);
}
}
/** /**
* Sets the OnClickListener that will be notified when the TabSwitcher button is pressed. * Sets the OnClickListener that will be notified when the TabSwitcher button is pressed.
* @param listener The callback that will be notified when the TabSwitcher button is pressed. * @param listener The callback that will be notified when the TabSwitcher button is pressed.
...@@ -180,11 +177,10 @@ class TabSwitcherModeTTCoordinatorPhone { ...@@ -180,11 +177,10 @@ class TabSwitcherModeTTCoordinatorPhone {
}); });
} }
/**
* @param isVisible Whether the bottom toolbar is visible.
*/
private void initializeTabSwitcherToolbar() { private void initializeTabSwitcherToolbar() {
mTabSwitcherModeToolbar = (TabSwitcherModeTTPhone) mTabSwitcherToolbarStub.inflate(); mTabSwitcherModeToolbar = (TabSwitcherModeTTPhone) mTabSwitcherToolbarStub.inflate();
mMenuButtonCoordinator.setMenuButton(
mTabSwitcherModeToolbar.findViewById(R.id.menu_button_wrapper));
// It's expected that these properties are set by the time the tab switcher is entered. // It's expected that these properties are set by the time the tab switcher is entered.
assert mTabSwitcherListener != null; assert mTabSwitcherListener != null;
...@@ -193,9 +189,6 @@ class TabSwitcherModeTTCoordinatorPhone { ...@@ -193,9 +189,6 @@ class TabSwitcherModeTTCoordinatorPhone {
assert mNewTabListener != null; assert mNewTabListener != null;
mTabSwitcherModeToolbar.setOnNewTabClickHandler(mNewTabListener); mTabSwitcherModeToolbar.setOnNewTabClickHandler(mNewTabListener);
assert mAppMenuButtonHelper != null;
mTabSwitcherModeToolbar.setAppMenuButtonHelper(mAppMenuButtonHelper);
assert mTabCountProvider != null; assert mTabCountProvider != null;
mTabSwitcherModeToolbar.setTabCountProvider(mTabCountProvider); mTabSwitcherModeToolbar.setTabCountProvider(mTabCountProvider);
......
...@@ -12,11 +12,8 @@ import android.graphics.Color; ...@@ -12,11 +12,8 @@ import android.graphics.Color;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.View; import android.view.View;
import android.view.ViewStub; import android.view.ViewStub;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.content.res.AppCompatResources; import androidx.appcompat.content.res.AppCompatResources;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.device.DeviceClassManager; import org.chromium.chrome.browser.device.DeviceClassManager;
import org.chromium.chrome.browser.flags.ChromeFeatureList; import org.chromium.chrome.browser.flags.ChromeFeatureList;
...@@ -27,8 +24,6 @@ import org.chromium.chrome.browser.tasks.tab_management.TabUiFeatureUtilities; ...@@ -27,8 +24,6 @@ import org.chromium.chrome.browser.tasks.tab_management.TabUiFeatureUtilities;
import org.chromium.chrome.browser.toolbar.IncognitoToggleTabLayout; import org.chromium.chrome.browser.toolbar.IncognitoToggleTabLayout;
import org.chromium.chrome.browser.toolbar.NewTabButton; import org.chromium.chrome.browser.toolbar.NewTabButton;
import org.chromium.chrome.browser.toolbar.TabCountProvider; import org.chromium.chrome.browser.toolbar.TabCountProvider;
import org.chromium.chrome.browser.toolbar.menu_button.MenuButton;
import org.chromium.chrome.browser.ui.appmenu.AppMenuButtonHelper;
import org.chromium.components.browser_ui.styles.ChromeColors; import org.chromium.components.browser_ui.styles.ChromeColors;
import org.chromium.components.browser_ui.widget.animation.CancelAwareAnimatorListener; import org.chromium.components.browser_ui.widget.animation.CancelAwareAnimatorListener;
import org.chromium.components.browser_ui.widget.animation.Interpolators; import org.chromium.components.browser_ui.widget.animation.Interpolators;
...@@ -51,7 +46,6 @@ public class TabSwitcherModeTTPhone extends OptimizedFrameLayout ...@@ -51,7 +46,6 @@ public class TabSwitcherModeTTPhone extends OptimizedFrameLayout
// The following three buttons are not used when Duet is enabled. // The following three buttons are not used when Duet is enabled.
private @Nullable NewTabButton mNewTabImageButton; private @Nullable NewTabButton mNewTabImageButton;
private @Nullable MenuButton mMenuButton;
private @Nullable ToggleTabStackButton mToggleTabStackButton; private @Nullable ToggleTabStackButton mToggleTabStackButton;
private int mPrimaryColor; private int mPrimaryColor;
...@@ -74,7 +68,6 @@ public class TabSwitcherModeTTPhone extends OptimizedFrameLayout ...@@ -74,7 +68,6 @@ public class TabSwitcherModeTTPhone extends OptimizedFrameLayout
mNewTabImageButton = findViewById(R.id.new_tab_button); mNewTabImageButton = findViewById(R.id.new_tab_button);
mNewTabViewButton = findViewById(R.id.new_tab_view); mNewTabViewButton = findViewById(R.id.new_tab_view);
mMenuButton = findViewById(R.id.menu_button_wrapper);
mToggleTabStackButton = findViewById(R.id.tab_switcher_mode_tab_switcher_button); mToggleTabStackButton = findViewById(R.id.tab_switcher_mode_tab_switcher_button);
// TODO(twellington): Try to make NewTabButton responsible for handling its own clicks. // TODO(twellington): Try to make NewTabButton responsible for handling its own clicks.
...@@ -117,9 +110,6 @@ public class TabSwitcherModeTTPhone extends OptimizedFrameLayout ...@@ -117,9 +110,6 @@ public class TabSwitcherModeTTPhone extends OptimizedFrameLayout
mIncognitoToggleTabLayout.destroy(); mIncognitoToggleTabLayout.destroy();
mIncognitoToggleTabLayout = null; mIncognitoToggleTabLayout = null;
} }
if (mMenuButton != null) {
mMenuButton = null;
}
} }
/** /**
...@@ -178,17 +168,6 @@ public class TabSwitcherModeTTPhone extends OptimizedFrameLayout ...@@ -178,17 +168,6 @@ public class TabSwitcherModeTTPhone extends OptimizedFrameLayout
if (DeviceClassManager.enableAccessibilityLayout()) mVisiblityAnimator.end(); if (DeviceClassManager.enableAccessibilityLayout()) mVisiblityAnimator.end();
} }
/**
* @param appMenuButtonHelper The helper for managing menu button interactions.
*/
void setAppMenuButtonHelper(AppMenuButtonHelper appMenuButtonHelper) {
if (mMenuButton == null) return;
mMenuButton.getImageButton().setOnTouchListener(appMenuButtonHelper);
mMenuButton.getImageButton().setAccessibilityDelegate(
appMenuButtonHelper.getAccessibilityDelegate());
}
/** /**
* Sets the OnClickListener that will be notified when the TabSwitcher button is pressed. * Sets the OnClickListener that will be notified when the TabSwitcher button is pressed.
* @param listener The callback that will be notified when the TabSwitcher button is pressed. * @param listener The callback that will be notified when the TabSwitcher button is pressed.
...@@ -285,12 +264,6 @@ public class TabSwitcherModeTTPhone extends OptimizedFrameLayout ...@@ -285,12 +264,6 @@ public class TabSwitcherModeTTPhone extends OptimizedFrameLayout
} }
} }
private void setMenuButtonVisibility(boolean isButtonVisible) {
if (mMenuButton != null) {
mMenuButton.setVisibility(isButtonVisible ? VISIBLE : GONE);
}
}
private void updatePrimaryColorAndTint() { private void updatePrimaryColorAndTint() {
int primaryColor = getToolbarColorForCurrentState(); int primaryColor = getToolbarColorForCurrentState();
if (mPrimaryColor != primaryColor) { if (mPrimaryColor != primaryColor) {
...@@ -322,11 +295,6 @@ public class TabSwitcherModeTTPhone extends OptimizedFrameLayout ...@@ -322,11 +295,6 @@ public class TabSwitcherModeTTPhone extends OptimizedFrameLayout
getContext(), R.color.default_icon_color_tint_list); getContext(), R.color.default_icon_color_tint_list);
} }
ColorStateList tintList = useLightIcons ? mLightIconTint : mDarkIconTint;
if (mMenuButton != null) {
ApiCompatibilityUtils.setImageTintList(mMenuButton.getImageButton(), tintList);
}
if (mToggleTabStackButton != null) { if (mToggleTabStackButton != null) {
mToggleTabStackButton.setUseLightDrawables(useLightIcons); mToggleTabStackButton.setUseLightDrawables(useLightIcons);
} }
......
...@@ -106,7 +106,7 @@ public class TopToolbarCoordinator implements Toolbar { ...@@ -106,7 +106,7 @@ public class TopToolbarCoordinator implements Toolbar {
ThemeColorProvider normalThemeColorProvider, ThemeColorProvider normalThemeColorProvider,
ThemeColorProvider overviewThemeColorProvider, ThemeColorProvider overviewThemeColorProvider,
MenuButtonCoordinator browsingModeMenuButtonCoordinator, MenuButtonCoordinator browsingModeMenuButtonCoordinator,
MenuButtonCoordinator startSurfaceMenuButtonCoordinator, MenuButtonCoordinator overviewModeMenuButtonCoordinator,
ObservableSupplier<AppMenuButtonHelper> appMenuButtonHelperSupplier, ObservableSupplier<AppMenuButtonHelper> appMenuButtonHelperSupplier,
ObservableSupplier<TabModelSelector> tabModelSelectorSupplier, ObservableSupplier<TabModelSelector> tabModelSelectorSupplier,
ObservableSupplier<Boolean> homeButtonVisibilitySupplier, ObservableSupplier<Boolean> homeButtonVisibilitySupplier,
...@@ -129,11 +129,11 @@ public class TopToolbarCoordinator implements Toolbar { ...@@ -129,11 +129,11 @@ public class TopToolbarCoordinator implements Toolbar {
controlContainer.getRootView().findViewById(R.id.tab_switcher_toolbar_stub), controlContainer.getRootView().findViewById(R.id.tab_switcher_toolbar_stub),
userEducationHelper, overviewModeBehaviorSupplier, userEducationHelper, overviewModeBehaviorSupplier,
identityDiscStateSupplier, overviewThemeColorProvider, identityDiscStateSupplier, overviewThemeColorProvider,
startSurfaceMenuButtonCoordinator, identityDiscButtonSupplier); overviewModeMenuButtonCoordinator, identityDiscButtonSupplier);
} else { } else {
mTabSwitcherModeCoordinatorPhone = new TabSwitcherModeTTCoordinatorPhone( mTabSwitcherModeCoordinatorPhone = new TabSwitcherModeTTCoordinatorPhone(
controlContainer.getRootView().findViewById( controlContainer.getRootView().findViewById(R.id.tab_switcher_toolbar_stub),
R.id.tab_switcher_toolbar_stub)); overviewModeMenuButtonCoordinator);
} }
} }
controlContainer.setToolbar(this); controlContainer.setToolbar(this);
...@@ -151,9 +151,6 @@ public class TopToolbarCoordinator implements Toolbar { ...@@ -151,9 +151,6 @@ public class TopToolbarCoordinator implements Toolbar {
*/ */
public void setAppMenuButtonHelper(AppMenuButtonHelper appMenuButtonHelper) { public void setAppMenuButtonHelper(AppMenuButtonHelper appMenuButtonHelper) {
mToolbarLayout.setAppMenuButtonHelper(appMenuButtonHelper); mToolbarLayout.setAppMenuButtonHelper(appMenuButtonHelper);
if (mTabSwitcherModeCoordinatorPhone != null) {
mTabSwitcherModeCoordinatorPhone.setAppMenuButtonHelper(appMenuButtonHelper);
}
} }
/** /**
......
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