Skip to content

Commit

Permalink
[TabletGTS] Fix polish toolbar for first relaunch and a11y switcher
Browse files Browse the repository at this point in the history
Fix polish toolbar for first relaunch and a11y switcher.
-Pass both the fullscreen and non-fullscreen tab switcher toolbar stubs
 when the polished tablet GTS is enabled.
-Choose which one to use based on our flag and if the a11y list switcher
 is enabled.

(cherry picked from commit 50515c1)

Bug: 1312980, 1317611
Change-Id: I7af7056a3324b6c97160e28787f6333d243fd85d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3603266
Commit-Queue: Neil Coronado <nemco@google.com>
Reviewed-by: Sirisha Kavuluru <skavuluru@google.com>
Reviewed-by: Theresa Sullivan <twellington@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1000562}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3635358
Commit-Queue: Theresa Sullivan <twellington@chromium.org>
Auto-Submit: Neil Coronado <nemco@google.com>
Cr-Commit-Position: refs/branch-heads/5005@{#573}
Cr-Branched-From: 5b4d945-refs/heads/main@{#992738}
  • Loading branch information
Neil Coronado authored and Chromium LUCI CQ committed May 9, 2022
1 parent 36c0b2d commit 1b9e3f2
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 68 deletions.
Expand Up @@ -26,6 +26,7 @@
import org.chromium.chrome.browser.compositor.layouts.eventfilter.AreaGestureEventFilter;
import org.chromium.chrome.browser.compositor.layouts.eventfilter.GestureHandler;
import org.chromium.chrome.browser.compositor.scene_layer.TabStripSceneLayer;
import org.chromium.chrome.browser.device.DeviceClassManager;
import org.chromium.chrome.browser.flags.CachedFeatureFlags;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.layouts.EventFilter;
Expand Down Expand Up @@ -87,6 +88,7 @@ public class StripLayoutHelperManager implements SceneOverlay {
private int mOrientation;
private final CompositorButton mModelSelectorButton;

private Context mContext;
private final StripScrim mStripScrim;
private boolean mBrowserScrimShowing;
private ValueAnimator mScrimFadeAnimation;
Expand Down Expand Up @@ -191,7 +193,9 @@ public void onStartedHiding(
private void updateScrimVisibility(boolean visibility) {
// Handled by separate scrim over entire browser in the polished version.
if (isGridTabSwitcherPolishEnabled()) {
mBrowserScrimShowing = visibility;
// Scrim doesn't actually show if the a11y list switcher is showing.
mBrowserScrimShowing =
visibility && !DeviceClassManager.enableAccessibilityLayout(mContext);
return;
}

Expand Down Expand Up @@ -643,6 +647,7 @@ public int getOrientation() {
* @param context The current Android {@link Context}.
*/
public void onContextChanged(Context context) {
mContext = context;
mNormalHelper.onContextChanged(context);
mIncognitoHelper.onContextChanged(context);
}
Expand Down
Expand Up @@ -1017,19 +1017,19 @@ private TopToolbarCoordinator createTopToolbarCoordinator(
boolean isStartSurfaceEnabled, boolean isTabGroupsAndroidContinuationEnabled,
boolean initializeWithIncognitoColors, ObservableSupplier<Profile> profileSupplier,
Callback<LoadUrlParams> logoClickedCallback) {
ViewStub tabSwitcherToolbarStub;
ViewStub tabSwitcherToolbarStub = mActivity.findViewById(R.id.tab_switcher_toolbar_stub);
ViewStub tabSwitcherFullscreenToolbarStub = null;
if (TabUiFeatureUtilities.isTabletGridTabSwitcherPolishEnabled(mActivity)) {
// Need to inflate grid_tab_switcher_view_holder_stub, as it contains
// fullscreen_tab_switcher_toolbar_stub.
((ViewStub) mActivity.findViewById(R.id.grid_tab_switcher_view_holder_stub)).inflate();
tabSwitcherToolbarStub =
tabSwitcherFullscreenToolbarStub =
mActivity.findViewById(R.id.fullscreen_tab_switcher_toolbar_stub);
} else {
tabSwitcherToolbarStub = mActivity.findViewById(R.id.tab_switcher_toolbar_stub);
}
// clang-format off
TopToolbarCoordinator toolbar = new TopToolbarCoordinator(controlContainer,
tabSwitcherToolbarStub, toolbarLayout, mLocationBarModel, mToolbarTabController,
tabSwitcherToolbarStub, tabSwitcherFullscreenToolbarStub, toolbarLayout,
mLocationBarModel, mToolbarTabController,
new UserEducationHelper(mActivity, mHandler), buttonDataProviders,
mLayoutStateProviderSupplier, browsingModeThemeColorProvider,
mAppThemeColorProvider, mMenuButtonCoordinator, mOverviewModeMenuButtonCoordinator,
Expand Down
Expand Up @@ -117,13 +117,17 @@ public void disableMenuButton() {

/**
* Set the underlying MenuButton view. Use only if the MenuButton instance isn't available at
* construction time, e.g. if it's lazily inflated. This should only be called once.
* construction time, e.g. if it's lazily inflated. This should only be called once, unless
* switching the active toolbar.
* @param menuButton The underlying MenuButton view.
*/
public void setMenuButton(MenuButton menuButton) {
assert mMenuButton == null;
assert menuButton != null;
mMenuButton = menuButton;

if (mChangeProcessor != null) {
mChangeProcessor.destroy();
}
mChangeProcessor = PropertyModelChangeProcessor.create(
mPropertyModel, menuButton, new MenuButtonViewBinder());
}
Expand Down
Expand Up @@ -10,6 +10,7 @@
import androidx.annotation.Nullable;

import org.chromium.base.supplier.BooleanSupplier;
import org.chromium.chrome.browser.device.DeviceClassManager;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.tabmodel.IncognitoStateProvider;
import org.chromium.chrome.browser.tabmodel.IncognitoTabModelObserver;
Expand All @@ -25,6 +26,7 @@
*/
class TabSwitcherModeTTCoordinator {
private final ViewStub mTabSwitcherToolbarStub;
private final ViewStub mTabSwitcherFullscreenToolbarStub;

// 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
Expand All @@ -37,7 +39,9 @@ class TabSwitcherModeTTCoordinator {
private MenuButtonCoordinator mMenuButtonCoordinator;
private boolean mAccessibilityEnabled;

private TabSwitcherModeTopToolbar mTabSwitcherModeToolbar;
private TabSwitcherModeTopToolbar mActiveTabSwitcherToolbar;
private TabSwitcherModeTopToolbar mTabSwitcherToolbar;
private TabSwitcherModeTopToolbar mTabSwitcherFullscreenToolbar;

@Nullable
private IncognitoTabModelObserver mIncognitoTabModelObserver;
Expand All @@ -48,10 +52,11 @@ class TabSwitcherModeTTCoordinator {
private final BooleanSupplier mIsIncognitoModeEnabledSupplier;

TabSwitcherModeTTCoordinator(ViewStub tabSwitcherToolbarStub,
MenuButtonCoordinator menuButtonCoordinator, boolean isGridTabSwitcherEnabled,
boolean isTabletGtsPolishEnabled, boolean isTabToGtsAnimationEnabled,
BooleanSupplier isIncognitoModeEnabledSupplier) {
ViewStub tabSwitcherFullscreenToolbarStub, MenuButtonCoordinator menuButtonCoordinator,
boolean isGridTabSwitcherEnabled, boolean isTabletGtsPolishEnabled,
boolean isTabToGtsAnimationEnabled, BooleanSupplier isIncognitoModeEnabledSupplier) {
mTabSwitcherToolbarStub = tabSwitcherToolbarStub;
mTabSwitcherFullscreenToolbarStub = tabSwitcherFullscreenToolbarStub;
mMenuButtonCoordinator = menuButtonCoordinator;
mIsGridTabSwitcherEnabled = isGridTabSwitcherEnabled;
mIsTabletGtsPolishEnabled = isTabletGtsPolishEnabled;
Expand All @@ -63,9 +68,9 @@ class TabSwitcherModeTTCoordinator {
* Cleans up any code and removes observers as necessary.
*/
void destroy() {
if (mTabSwitcherModeToolbar != null) {
mTabSwitcherModeToolbar.destroy();
mTabSwitcherModeToolbar = null;
if (mActiveTabSwitcherToolbar != null) {
mActiveTabSwitcherToolbar.destroy();
mActiveTabSwitcherToolbar = null;
}
if (mTabModelSelector != null && mIncognitoTabModelObserver != null) {
mTabModelSelector.removeIncognitoTabModelObserver(mIncognitoTabModelObserver);
Expand All @@ -82,13 +87,11 @@ void destroy() {
*/
void setTabSwitcherMode(boolean inTabSwitcherMode) {
if (inTabSwitcherMode) {
if (mTabSwitcherModeToolbar == null) {
initializeTabSwitcherToolbar();
}
maybeInflateAndSetToolbar();

mTabSwitcherModeToolbar.setTabSwitcherMode(inTabSwitcherMode);
} else if (mTabSwitcherModeToolbar != null) {
mTabSwitcherModeToolbar.setTabSwitcherMode(inTabSwitcherMode);
mActiveTabSwitcherToolbar.setTabSwitcherMode(inTabSwitcherMode);
} else if (mActiveTabSwitcherToolbar != null) {
mActiveTabSwitcherToolbar.setTabSwitcherMode(inTabSwitcherMode);
}
}

Expand All @@ -98,8 +101,8 @@ void setTabSwitcherMode(boolean inTabSwitcherMode) {
*/
void setOnTabSwitcherClickHandler(View.OnClickListener listener) {
mTabSwitcherListener = listener;
if (mTabSwitcherModeToolbar != null) {
mTabSwitcherModeToolbar.setOnTabSwitcherClickHandler(listener);
if (mActiveTabSwitcherToolbar != null) {
mActiveTabSwitcherToolbar.setOnTabSwitcherClickHandler(listener);
}
}

Expand All @@ -109,8 +112,8 @@ void setOnTabSwitcherClickHandler(View.OnClickListener listener) {
*/
void setOnNewTabClickHandler(View.OnClickListener listener) {
mNewTabListener = listener;
if (mTabSwitcherModeToolbar != null) {
mTabSwitcherModeToolbar.setOnNewTabClickHandler(listener);
if (mActiveTabSwitcherToolbar != null) {
mActiveTabSwitcherToolbar.setOnNewTabClickHandler(listener);
}
}

Expand All @@ -120,8 +123,8 @@ void setOnNewTabClickHandler(View.OnClickListener listener) {
*/
void setTabCountProvider(TabCountProvider tabCountProvider) {
mTabCountProvider = tabCountProvider;
if (mTabSwitcherModeToolbar != null) {
mTabSwitcherModeToolbar.setTabCountProvider(tabCountProvider);
if (mActiveTabSwitcherToolbar != null) {
mActiveTabSwitcherToolbar.setTabCountProvider(tabCountProvider);
}
}

Expand All @@ -131,8 +134,8 @@ void setTabCountProvider(TabCountProvider tabCountProvider) {
*/
void setTabModelSelector(TabModelSelector selector) {
mTabModelSelector = selector;
if (mTabSwitcherModeToolbar != null) {
mTabSwitcherModeToolbar.setTabModelSelector(selector);
if (mActiveTabSwitcherToolbar != null) {
mActiveTabSwitcherToolbar.setTabModelSelector(selector);
}

maybeInitializeIncognitoTabModelObserver();
Expand All @@ -144,47 +147,100 @@ void setTabModelSelector(TabModelSelector selector) {
*/
void setIncognitoStateProvider(IncognitoStateProvider provider) {
mIncognitoStateProvider = provider;
if (mTabSwitcherModeToolbar != null) {
mTabSwitcherModeToolbar.setIncognitoStateProvider(provider);
if (mActiveTabSwitcherToolbar != null) {
mActiveTabSwitcherToolbar.setIncognitoStateProvider(provider);
}
}

/** Called when accessibility status changes. */
void onAccessibilityStatusChanged(boolean enabled) {
mAccessibilityEnabled = enabled;
if (mTabSwitcherModeToolbar != null) {
mTabSwitcherModeToolbar.onAccessibilityStatusChanged(enabled);
if (mActiveTabSwitcherToolbar != null) {
mActiveTabSwitcherToolbar.onAccessibilityStatusChanged(enabled);
}
}

/**
* Inflates the toolbar if necessary. Swaps between the fullscreen and non-fullscreen toolbars
* if necessary.
*/
private void maybeInflateAndSetToolbar() {
if (!mIsTabletGtsPolishEnabled) {
if (mActiveTabSwitcherToolbar == null) {
mActiveTabSwitcherToolbar =
(TabSwitcherModeTopToolbar) mTabSwitcherToolbarStub.inflate();
initializeToolbar(mActiveTabSwitcherToolbar, false);

maybeInitializeIncognitoTabModelObserver();
maybeNotifyOnIncognitoTabsExistenceChanged();
}
} else {
boolean useFullscreenToolbar = !DeviceClassManager.enableAccessibilityLayout(
mTabSwitcherToolbarStub.getContext());
TabSwitcherModeTopToolbar activeToolbar =
maybeInflateActiveToolbar(useFullscreenToolbar);

if (mActiveTabSwitcherToolbar != activeToolbar) {
mActiveTabSwitcherToolbar = activeToolbar;

maybeInitializeIncognitoTabModelObserver();
maybeNotifyOnIncognitoTabsExistenceChanged();
}
}
}

/**
* Inflates the toolbar (fullscreen vs. non-fullscreen) that will be shown.
*
* @param useFullscreenToolbar Whether or not to use the fullscreen toolbar.
* @return The active toolbar.
*/
private TabSwitcherModeTopToolbar maybeInflateActiveToolbar(boolean useFullscreenToolbar) {
if (useFullscreenToolbar) {
if (mTabSwitcherFullscreenToolbar == null) {
mTabSwitcherFullscreenToolbar =
(TabSwitcherModeTopToolbar) mTabSwitcherFullscreenToolbarStub.inflate();
initializeToolbar(mTabSwitcherFullscreenToolbar, true);
}
return mTabSwitcherFullscreenToolbar;
} else {
if (mTabSwitcherToolbar == null) {
mTabSwitcherToolbar = (TabSwitcherModeTopToolbar) mTabSwitcherToolbarStub.inflate();
initializeToolbar(mTabSwitcherToolbar, false);
}
return mTabSwitcherToolbar;
}
}

private void initializeTabSwitcherToolbar() {
mTabSwitcherModeToolbar = (TabSwitcherModeTopToolbar) mTabSwitcherToolbarStub.inflate();
mTabSwitcherModeToolbar.initialize(mIsGridTabSwitcherEnabled, mIsTabletGtsPolishEnabled,
/**
* Initialize the toolbar with the requisite listeners, providers, etc.
*
* @param toolbar The toolbar to initialize.
* @param isFullscreenToolbar Whether or not the given toolbar is fullscreen or not.
*/
private void initializeToolbar(TabSwitcherModeTopToolbar toolbar, boolean isFullscreenToolbar) {
toolbar.initialize(mIsGridTabSwitcherEnabled, isFullscreenToolbar,
mIsTabToGtsAnimationEnabled, mIsIncognitoModeEnabledSupplier);
mMenuButtonCoordinator.setMenuButton(
mTabSwitcherModeToolbar.findViewById(R.id.menu_button_wrapper));
mMenuButtonCoordinator.setMenuButton(toolbar.findViewById(R.id.menu_button_wrapper));

// It's expected that these properties are set by the time the tab switcher is entered.
assert mTabSwitcherListener != null;
mTabSwitcherModeToolbar.setOnTabSwitcherClickHandler(mTabSwitcherListener);
toolbar.setOnTabSwitcherClickHandler(mTabSwitcherListener);

assert mNewTabListener != null;
mTabSwitcherModeToolbar.setOnNewTabClickHandler(mNewTabListener);
toolbar.setOnNewTabClickHandler(mNewTabListener);

assert mTabCountProvider != null;
mTabSwitcherModeToolbar.setTabCountProvider(mTabCountProvider);
toolbar.setTabCountProvider(mTabCountProvider);

assert mTabModelSelector != null;
mTabSwitcherModeToolbar.setTabModelSelector(mTabModelSelector);
toolbar.setTabModelSelector(mTabModelSelector);

assert mIncognitoStateProvider != null;
mTabSwitcherModeToolbar.setIncognitoStateProvider(mIncognitoStateProvider);

maybeInitializeIncognitoTabModelObserver();
maybeNotifyOnIncognitoTabsExistenceChanged();
toolbar.setIncognitoStateProvider(mIncognitoStateProvider);

if (mAccessibilityEnabled) {
mTabSwitcherModeToolbar.onAccessibilityStatusChanged(mAccessibilityEnabled);
toolbar.onAccessibilityStatusChanged(mAccessibilityEnabled);
}
}

Expand All @@ -201,32 +257,32 @@ private boolean isNewTabVariationEnabled() {
* @param highlight If the new tab button should be highlighted.
*/
void setNewTabButtonHighlight(boolean highlight) {
assert mTabSwitcherModeToolbar != null;
mTabSwitcherModeToolbar.setNewTabButtonHighlight(highlight);
assert mActiveTabSwitcherToolbar != null;
mActiveTabSwitcherToolbar.setNewTabButtonHighlight(highlight);
}

/**
* Initialize {@link IncognitoTabModelObserver}, if the new tab variation is enabled. This
* function will initialize observer, if it is not initialized before.
*/
private void maybeInitializeIncognitoTabModelObserver() {
if (mTabModelSelector == null || mTabSwitcherModeToolbar == null
if (mTabModelSelector == null || mActiveTabSwitcherToolbar == null
|| !isNewTabVariationEnabled() || mIncognitoTabModelObserver != null) {
return;
}

mIncognitoTabModelObserver = new IncognitoTabModelObserver() {
@Override
public void wasFirstTabCreated() {
if (mTabSwitcherModeToolbar != null) {
mTabSwitcherModeToolbar.onIncognitoTabsExistenceChanged(true);
if (mActiveTabSwitcherToolbar != null) {
mActiveTabSwitcherToolbar.onIncognitoTabsExistenceChanged(true);
}
}

@Override
public void didBecomeEmpty() {
if (mTabSwitcherModeToolbar != null) {
mTabSwitcherModeToolbar.onIncognitoTabsExistenceChanged(false);
if (mActiveTabSwitcherToolbar != null) {
mActiveTabSwitcherToolbar.onIncognitoTabsExistenceChanged(false);
}
}
};
Expand All @@ -237,12 +293,12 @@ public void didBecomeEmpty() {
* Update incognito logo visibility on toolbar, if the new tab variation is enabled.
*/
private void maybeNotifyOnIncognitoTabsExistenceChanged() {
if (mTabModelSelector == null || mTabSwitcherModeToolbar == null
if (mTabModelSelector == null || mActiveTabSwitcherToolbar == null
|| !isNewTabVariationEnabled()) {
return;
}

boolean doesExist = mTabModelSelector.getModel(true).getCount() != 0;
mTabSwitcherModeToolbar.onIncognitoTabsExistenceChanged(doesExist);
mActiveTabSwitcherToolbar.onIncognitoTabsExistenceChanged(doesExist);
}
}

0 comments on commit 1b9e3f2

Please sign in to comment.