Commit d3925377 authored by Mia Glaese's avatar Mia Glaese Committed by Commit Bot

[Start Surface] Introduce StartSurfaceToolbar

MVP with the same functionality as the current TabswitcherModeTTPhone Toolbar,
except for the animations.

Screen videos here:
https://drive.google.com/drive/folders/1bqxiTsr5SSX2p73eZrLao7GRA5ZwIkLw?usp=sharing

In follow up CLs:
Add animations.
Dynamically remove Google logo depending on screen width.
Dynamically change toolbar with OverviewModeState.
Add identity disc.

Bug: 1025296
Change-Id: I6b48b7854088469638a2a4cb22829f24c1e98fdc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1975051Reviewed-by: default avatarYusuf Ozuysal <yusufo@chromium.org>
Reviewed-by: default avatarGanggui Tang <gogerald@chromium.org>
Reviewed-by: default avatarPatrick Noland <pnoland@chromium.org>
Commit-Queue: Mia Glaese <glamia@chromium.org>
Cr-Commit-Position: refs/heads/master@{#728576}
parent 2708646c
......@@ -1736,6 +1736,11 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/toolbar/top/IncognitoSwitchCoordinator.java",
"java/src/org/chromium/chrome/browser/toolbar/top/IncognitoSwitchProperties.java",
"java/src/org/chromium/chrome/browser/toolbar/top/IncognitoSwitchViewBinder.java",
"java/src/org/chromium/chrome/browser/toolbar/top/StartSurfaceToolbarCoordinator.java",
"java/src/org/chromium/chrome/browser/toolbar/top/StartSurfaceToolbarMediator.java",
"java/src/org/chromium/chrome/browser/toolbar/top/StartSurfaceToolbarProperties.java",
"java/src/org/chromium/chrome/browser/toolbar/top/StartSurfaceToolbarView.java",
"java/src/org/chromium/chrome/browser/toolbar/top/StartSurfaceToolbarViewBinder.java",
"java/src/org/chromium/chrome/browser/toolbar/top/TabSwitcherActionMenuCoordinator.java",
"java/src/org/chromium/chrome/browser/toolbar/top/TabSwitcherModeTTCoordinatorPhone.java",
"java/src/org/chromium/chrome/browser/toolbar/top/TabSwitcherModeTTPhone.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. -->
<org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/tab_switcher_toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height_no_shadow"
android:clickable="true" >
<Switch
android:id="@+id/incognito_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:thumb="@drawable/incognito_switch"
android:track="@drawable/incognito_switch_track"
android:visibility="gone"/>
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:scaleType="centerInside"
app:srcCompat="@drawable/google_logo"
android:visibility="gone"
android:contentDescription="@null"/>
<org.chromium.chrome.browser.toolbar.NewTabButton
android:id="@+id/new_tab_button"
style="@style/ToolbarButton"
android:layout_width="wrap_content"
android:layout_toStartOf="@+id/menu_anchor"
android:layout_centerVertical="true"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:contentDescription="@string/accessibility_toolbar_btn_new_tab" />
<FrameLayout
android:id="@+id/menu_anchor"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="false">
<include layout="@layout/menu_button"/>
</FrameLayout>
</org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarView>
// 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.toolbar.top;
import android.view.View;
import android.view.ViewStub;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.toolbar.IncognitoStateProvider;
import org.chromium.chrome.browser.ui.appmenu.AppMenuButtonHelper;
import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.modelutil.PropertyModelChangeProcessor;
/**
* The controller for the StartSurfaceToolbar. This class handles all interactions that the
* StartSurfaceToolbar has with the outside world. Lazily creates the tab toolbar the first time
* it's needed.
*/
class StartSurfaceToolbarCoordinator {
private final StartSurfaceToolbarMediator mToolbarMediator;
private final ViewStub mStub;
private final PropertyModel mPropertyModel;
private StartSurfaceToolbarView mView;
private TabModelSelector mTabModelSelector;
private IncognitoSwitchCoordinator mIncognitoSwitchCoordinator;
StartSurfaceToolbarCoordinator(ViewStub startSurfaceToolbarStub) {
mStub = startSurfaceToolbarStub;
mPropertyModel = new PropertyModel(StartSurfaceToolbarProperties.ALL_KEYS);
mToolbarMediator = new StartSurfaceToolbarMediator(mPropertyModel);
}
/**
* Cleans up any code and removes observers as necessary.
*/
void destroy() {
mToolbarMediator.destroy();
}
/**
* @param appMenuButtonHelper The helper for managing menu button interactions.
*/
void setAppMenuButtonHelper(AppMenuButtonHelper appMenuButtonHelper) {
mToolbarMediator.setAppMenuButtonHelper(appMenuButtonHelper);
}
/**
* Sets the OnClickListener that will be notified when the New Tab button is pressed.
* @param listener The callback that will be notified when the New Tab button is pressed.
*/
void setOnNewTabClickHandler(View.OnClickListener listener) {
mToolbarMediator.setOnNewTabClickHandler(listener);
}
/**
* Sets the current {@Link TabModelSelector} so the toolbar can pass it into buttons that need
* access to it.
*/
void setTabModelSelector(TabModelSelector selector) {
mTabModelSelector = selector;
mToolbarMediator.setTabModelSelector(selector);
}
/**
* Called when Start Surface mode is entered or exited.
* @param inStartSurfaceMode Whether or not start surface mode should be shown or hidden.
*/
void setStartSurfaceMode(boolean inStartSurfaceMode) {
if (!isInflated()) {
inflate();
}
mToolbarMediator.setStartSurfaceMode(inStartSurfaceMode);
}
/**
* @param provider The provider used to determine incognito state.
*/
void setIncognitoStateProvider(IncognitoStateProvider provider) {
mToolbarMediator.setIncognitoStateProvider(provider);
}
/**
* Called to set the visibility in Start Surface mode.
* @param shouldShowStartSurfaceToolbar whether the toolbar should be visible.
*/
void setStartSurfaceToolbarVisibility(boolean shouldShowStartSurfaceToolbar) {
mToolbarMediator.setStartSurfaceToolbarVisibility(shouldShowStartSurfaceToolbar);
}
/**
* Called when accessibility status changes.
* @param enabled whether accessibility status is enabled.
*/
void onAccessibilityStatusChanged(boolean enabled) {
mToolbarMediator.onAccessibilityStatusChanged(enabled);
}
/**
* @param isVisible Whether the bottom toolbar is visible.
*/
void onBottomToolbarVisibilityChanged(boolean isVisible) {
mToolbarMediator.onBottomToolbarVisibilityChanged(isVisible);
}
void onNativeLibraryReady() {
mToolbarMediator.onNativeLibraryReady();
}
private void inflate() {
mStub.setLayoutResource(R.layout.start_top_toolbar);
mView = (StartSurfaceToolbarView) mStub.inflate();
PropertyModelChangeProcessor.create(
mPropertyModel, mView, StartSurfaceToolbarViewBinder::bind);
mIncognitoSwitchCoordinator = new IncognitoSwitchCoordinator(mView, mTabModelSelector);
}
private boolean isInflated() {
return mView != null;
}
}
// 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.toolbar.top;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.ACCESSIBILITY_ENABLED;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.APP_MENU_BUTTON_HELPER;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.INCOGNITO_STATE_PROVIDER;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.IS_INCOGNITO;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.IS_VISIBLE;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.LOGO_IS_VISIBLE;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.MENU_IS_VISIBLE;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.NEW_TAB_CLICK_HANDLER;
import android.view.View;
import org.chromium.chrome.browser.flags.FeatureUtilities;
import org.chromium.chrome.browser.search_engines.TemplateUrlServiceFactory;
import org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver;
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.toolbar.IncognitoStateProvider;
import org.chromium.chrome.browser.ui.appmenu.AppMenuButtonHelper;
import org.chromium.components.search_engines.TemplateUrlService.TemplateUrlServiceObserver;
import org.chromium.ui.modelutil.PropertyModel;
/** The mediator implements interacts between the views and the caller. */
class StartSurfaceToolbarMediator {
private final PropertyModel mPropertyModel;
private TabModelSelector mTabModelSelector;
private TemplateUrlServiceObserver mTemplateUrlObserver;
private TabModelSelectorObserver mTabModelSelectorObserver;
StartSurfaceToolbarMediator(PropertyModel model) {
mPropertyModel = model;
mPropertyModel.set(MENU_IS_VISIBLE, !FeatureUtilities.isBottomToolbarEnabled());
// Observers
mTabModelSelectorObserver = new EmptyTabModelSelectorObserver() {
@Override
public void onTabModelSelected(TabModel newModel, TabModel oldModel) {
mPropertyModel.set(IS_INCOGNITO, mTabModelSelector.isIncognitoSelected());
}
};
}
void onNativeLibraryReady() {
if (mTemplateUrlObserver != null) {
mTemplateUrlObserver = new TemplateUrlServiceObserver() {
@Override
public void onTemplateURLServiceChanged() {
mPropertyModel.set(LOGO_IS_VISIBLE,
TemplateUrlServiceFactory.get().isDefaultSearchEngineGoogle());
}
};
}
TemplateUrlServiceFactory.get().addObserver(mTemplateUrlObserver);
mPropertyModel.set(
LOGO_IS_VISIBLE, TemplateUrlServiceFactory.get().isDefaultSearchEngineGoogle());
}
void destroy() {
if (mTemplateUrlObserver != null) {
TemplateUrlServiceFactory.get().removeObserver(mTemplateUrlObserver);
}
if (mTabModelSelectorObserver != null) {
mTabModelSelector.removeObserver(mTabModelSelectorObserver);
}
}
void setAppMenuButtonHelper(AppMenuButtonHelper appMenuButtonHelper) {
mPropertyModel.set(APP_MENU_BUTTON_HELPER, appMenuButtonHelper);
}
void setOnNewTabClickHandler(View.OnClickListener listener) {
mPropertyModel.set(NEW_TAB_CLICK_HANDLER, listener);
}
void setTabModelSelector(TabModelSelector selector) {
mTabModelSelector = selector;
if (mTabModelSelector != null) {
mTabModelSelectorObserver = new EmptyTabModelSelectorObserver() {
@Override
public void onTabModelSelected(TabModel newModel, TabModel oldModel) {
mPropertyModel.set(IS_INCOGNITO, mTabModelSelector.isIncognitoSelected());
}
};
}
mTabModelSelector.addObserver(mTabModelSelectorObserver);
}
void setStartSurfaceMode(boolean inStartSurfaceMode) {
mPropertyModel.set(IS_VISIBLE, inStartSurfaceMode);
}
void setIncognitoStateProvider(IncognitoStateProvider provider) {
mPropertyModel.set(INCOGNITO_STATE_PROVIDER, provider);
}
void setStartSurfaceToolbarVisibility(boolean shouldShowStartSurfaceToolbar) {
mPropertyModel.set(IS_VISIBLE, shouldShowStartSurfaceToolbar);
}
void onAccessibilityStatusChanged(boolean enabled) {
mPropertyModel.set(ACCESSIBILITY_ENABLED, enabled);
}
void onBottomToolbarVisibilityChanged(boolean isVisible) {
mPropertyModel.set(MENU_IS_VISIBLE, !isVisible);
}
}
// 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.toolbar.top;
import android.view.View;
import org.chromium.chrome.browser.toolbar.IncognitoStateProvider;
import org.chromium.chrome.browser.ui.appmenu.AppMenuButtonHelper;
import org.chromium.ui.modelutil.PropertyKey;
import org.chromium.ui.modelutil.PropertyModel;
/** List of the start surface toolbar properties. */
class StartSurfaceToolbarProperties {
private StartSurfaceToolbarProperties() {}
public static final PropertyModel
.WritableObjectPropertyKey<AppMenuButtonHelper> APP_MENU_BUTTON_HELPER =
new PropertyModel.WritableObjectPropertyKey<AppMenuButtonHelper>();
public static final PropertyModel
.WritableObjectPropertyKey<IncognitoStateProvider> INCOGNITO_STATE_PROVIDER =
new PropertyModel.WritableObjectPropertyKey<IncognitoStateProvider>();
public static final PropertyModel
.WritableObjectPropertyKey<View.OnClickListener> NEW_TAB_CLICK_HANDLER =
new PropertyModel.WritableObjectPropertyKey<View.OnClickListener>();
public static final PropertyModel.WritableBooleanPropertyKey IS_VISIBLE =
new PropertyModel.WritableBooleanPropertyKey();
public static final PropertyModel.WritableBooleanPropertyKey LOGO_IS_VISIBLE =
new PropertyModel.WritableBooleanPropertyKey();
public static final PropertyModel.WritableBooleanPropertyKey IS_INCOGNITO =
new PropertyModel.WritableBooleanPropertyKey();
public static final PropertyModel.WritableBooleanPropertyKey ACCESSIBILITY_ENABLED =
new PropertyModel.WritableBooleanPropertyKey();
public static final PropertyModel.WritableBooleanPropertyKey MENU_IS_VISIBLE =
new PropertyModel.WritableBooleanPropertyKey();
public static final PropertyKey[] ALL_KEYS = new PropertyKey[] {APP_MENU_BUTTON_HELPER,
NEW_TAB_CLICK_HANDLER, IS_VISIBLE, LOGO_IS_VISIBLE, IS_INCOGNITO,
INCOGNITO_STATE_PROVIDER, ACCESSIBILITY_ENABLED, MENU_IS_VISIBLE};
}
// 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.toolbar.top;
import android.content.Context;
import android.content.res.ColorStateList;
import android.support.v7.content.res.AppCompatResources;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RelativeLayout;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.toolbar.IncognitoStateProvider;
import org.chromium.chrome.browser.toolbar.MenuButton;
import org.chromium.chrome.browser.toolbar.NewTabButton;
import org.chromium.chrome.browser.ui.appmenu.AppMenuButtonHelper;
import org.chromium.chrome.browser.util.ColorUtils;
import org.chromium.components.browser_ui.styles.ChromeColors;
/** View of the StartSurfaceToolbar */
class StartSurfaceToolbarView extends RelativeLayout {
private NewTabButton mNewTabButton;
private View mIncognitoSwitch;
private MenuButton mMenuButton;
private View mLogo;
private int mPrimaryColor;
private ColorStateList mLightIconTint;
private ColorStateList mDarkIconTint;
public StartSurfaceToolbarView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mNewTabButton = findViewById(R.id.new_tab_button);
mIncognitoSwitch = findViewById(R.id.incognito_switch);
mMenuButton = findViewById(R.id.menu_button_wrapper);
mLogo = findViewById(R.id.logo);
updatePrimaryColorAndTint(false);
}
/**
* @param appMenuButtonHelper The {@link AppMenuButtonHelper} for managing menu button
* interactions.
*/
void setAppMenuButtonHelper(AppMenuButtonHelper appMenuButtonHelper) {
mMenuButton.getImageButton().setOnTouchListener(appMenuButtonHelper);
mMenuButton.getImageButton().setAccessibilityDelegate(
appMenuButtonHelper.getAccessibilityDelegate());
}
/**
* Sets the {@link OnClickListener} that will be notified when the New Tab button is pressed.
* @param listener The callback that will be notified when the New Tab button is pressed.
*/
void setOnNewTabClickHandler(View.OnClickListener listener) {
mNewTabButton.setOnClickListener(listener);
}
/**
* @param isVisible Whether the Logo is visible.
*/
void setLogoVisibility(boolean isVisible) {
mLogo.setVisibility(isVisible ? View.VISIBLE : View.GONE);
}
/**
* @param isVisible Whether the menu button is visible.
*/
void setMenuButtonVisibility(boolean isVisible) {
mMenuButton.setVisibility(isVisible ? View.VISIBLE : View.GONE);
}
/** Called when incognito mode changes. */
void updateIncognito(boolean isIncognito) {
updatePrimaryColorAndTint(isIncognito);
}
/**
* @param provider The {@link IncognitoStateProvider} passed to buttons that need access to it.
*/
void setIncognitoStateProvider(IncognitoStateProvider provider) {
mNewTabButton.setIncognitoStateProvider(provider);
}
/** Called when accessibility status changes. */
void onAccessibilityStatusChanged(boolean enabled) {
mNewTabButton.onAccessibilityStatusChanged();
}
private void updatePrimaryColorAndTint(boolean isIncognito) {
int primaryColor = ChromeColors.getPrimaryBackgroundColor(getResources(), isIncognito);
setBackgroundColor(primaryColor);
if (mLightIconTint == null) {
mLightIconTint =
AppCompatResources.getColorStateList(getContext(), R.color.tint_on_dark_bg);
mDarkIconTint =
AppCompatResources.getColorStateList(getContext(), R.color.standard_mode_tint);
}
boolean useLightIcons = ColorUtils.shouldUseLightForegroundOnBackground(primaryColor);
ColorStateList tintList = useLightIcons ? mLightIconTint : mDarkIconTint;
ApiCompatibilityUtils.setImageTintList(mMenuButton.getImageButton(), tintList);
}
}
// 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.toolbar.top;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.ACCESSIBILITY_ENABLED;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.APP_MENU_BUTTON_HELPER;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.INCOGNITO_STATE_PROVIDER;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.IS_INCOGNITO;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.IS_VISIBLE;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.LOGO_IS_VISIBLE;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.MENU_IS_VISIBLE;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.NEW_TAB_CLICK_HANDLER;
import android.view.View;
import org.chromium.ui.modelutil.PropertyKey;
import org.chromium.ui.modelutil.PropertyModel;
// The view binder of the tasks surface view.
class StartSurfaceToolbarViewBinder {
public static void bind(
PropertyModel model, StartSurfaceToolbarView view, PropertyKey propertyKey) {
if (propertyKey == APP_MENU_BUTTON_HELPER) {
view.setAppMenuButtonHelper(model.get(APP_MENU_BUTTON_HELPER));
} else if (propertyKey == NEW_TAB_CLICK_HANDLER) {
view.setOnNewTabClickHandler(model.get(NEW_TAB_CLICK_HANDLER));
} else if (propertyKey == IS_VISIBLE) {
view.setVisibility(model.get(IS_VISIBLE) ? View.VISIBLE : View.GONE);
} else if (propertyKey == LOGO_IS_VISIBLE) {
view.setLogoVisibility(model.get(LOGO_IS_VISIBLE));
} else if (propertyKey == IS_INCOGNITO) {
view.updateIncognito(model.get(IS_INCOGNITO));
} else if (propertyKey == INCOGNITO_STATE_PROVIDER) {
view.setIncognitoStateProvider(model.get(INCOGNITO_STATE_PROVIDER));
} else if (propertyKey == ACCESSIBILITY_ENABLED) {
view.onAccessibilityStatusChanged(model.get(ACCESSIBILITY_ENABLED));
} else if (propertyKey == MENU_IS_VISIBLE) {
view.setMenuButtonVisibility(model.get(MENU_IS_VISIBLE));
}
}
}
......@@ -21,6 +21,7 @@ import org.chromium.chrome.browser.compositor.Invalidator;
import org.chromium.chrome.browser.compositor.layouts.LayoutManager;
import org.chromium.chrome.browser.compositor.layouts.OverviewModeBehavior;
import org.chromium.chrome.browser.findinpage.FindToolbar;
import org.chromium.chrome.browser.flags.FeatureUtilities;
import org.chromium.chrome.browser.omnibox.LocationBar;
import org.chromium.chrome.browser.partnercustomizations.HomepageManager;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
......@@ -57,6 +58,11 @@ public class TopToolbarCoordinator implements Toolbar {
* after ToolbarLayout is inflated.
*/
private @Nullable TabSwitcherModeTTCoordinatorPhone mTabSwitcherModeCoordinatorPhone;
/**
* The coordinator for the start surface mode toolbar (phones only) if the StartSurface is
* enabled. This will be lazily created after ToolbarLayout is inflated.
*/
private @Nullable StartSurfaceToolbarCoordinator mStartSurfaceToolbarCoordinator;
private HomepageManager.HomepageStateListener mHomepageStateListener =
new HomepageManager.HomepageStateListener() {
......@@ -75,8 +81,15 @@ public class TopToolbarCoordinator implements Toolbar {
ToolbarControlContainer controlContainer, ToolbarLayout toolbarLayout) {
mToolbarLayout = toolbarLayout;
if (mToolbarLayout instanceof ToolbarPhone) {
mTabSwitcherModeCoordinatorPhone = new TabSwitcherModeTTCoordinatorPhone(
controlContainer.getRootView().findViewById(R.id.tab_switcher_toolbar_stub));
if (FeatureUtilities.isStartSurfaceEnabled()) {
mStartSurfaceToolbarCoordinator = new StartSurfaceToolbarCoordinator(
controlContainer.getRootView().findViewById(
R.id.tab_switcher_toolbar_stub));
} else {
mTabSwitcherModeCoordinatorPhone = new TabSwitcherModeTTCoordinatorPhone(
controlContainer.getRootView().findViewById(
R.id.tab_switcher_toolbar_stub));
}
}
controlContainer.setToolbar(this);
HomepageManager.getInstance().addListener(mHomepageStateListener);
......@@ -99,6 +112,8 @@ public class TopToolbarCoordinator implements Toolbar {
mToolbarLayout.setAppMenuButtonHelper(appMenuButtonHelper);
if (mTabSwitcherModeCoordinatorPhone != null) {
mTabSwitcherModeCoordinatorPhone.setAppMenuButtonHelper(appMenuButtonHelper);
} else if (mStartSurfaceToolbarCoordinator != null) {
mStartSurfaceToolbarCoordinator.setAppMenuButtonHelper(appMenuButtonHelper);
}
}
......@@ -126,6 +141,10 @@ public class TopToolbarCoordinator implements Toolbar {
mTabSwitcherModeCoordinatorPhone.setOnTabSwitcherClickHandler(tabSwitcherClickHandler);
mTabSwitcherModeCoordinatorPhone.setOnNewTabClickHandler(newTabClickHandler);
mTabSwitcherModeCoordinatorPhone.setTabModelSelector(tabModelSelector);
} else if (mStartSurfaceToolbarCoordinator != null) {
mStartSurfaceToolbarCoordinator.setOnNewTabClickHandler(newTabClickHandler);
mStartSurfaceToolbarCoordinator.setTabModelSelector(tabModelSelector);
mStartSurfaceToolbarCoordinator.onNativeLibraryReady();
}
mToolbarLayout.setTabModelSelector(tabModelSelector);
......@@ -170,6 +189,8 @@ public class TopToolbarCoordinator implements Toolbar {
mToolbarLayout.destroy();
if (mTabSwitcherModeCoordinatorPhone != null) {
mTabSwitcherModeCoordinatorPhone.destroy();
} else if (mStartSurfaceToolbarCoordinator != null) {
mStartSurfaceToolbarCoordinator.destroy();
}
}
......@@ -211,13 +232,12 @@ public class TopToolbarCoordinator implements Toolbar {
@Override
public void updateTabSwitcherToolbarState(boolean requestToShow) {
if (mTabSwitcherModeCoordinatorPhone == null
if (mStartSurfaceToolbarCoordinator == null
|| mToolbarLayout.getToolbarDataProvider() == null
|| !mToolbarLayout.getToolbarDataProvider().isInOverviewAndShowingOmnibox()) {
return;
}
mTabSwitcherModeCoordinatorPhone.setTabSwitcherToolbarVisibility(requestToShow);
mStartSurfaceToolbarCoordinator.setStartSurfaceToolbarVisibility(requestToShow);
}
@Override
......@@ -311,6 +331,8 @@ public class TopToolbarCoordinator implements Toolbar {
mToolbarLayout.onAccessibilityStatusChanged(enabled);
if (mTabSwitcherModeCoordinatorPhone != null) {
mTabSwitcherModeCoordinatorPhone.onAccessibilityStatusChanged(enabled);
} else if (mStartSurfaceToolbarCoordinator != null) {
mStartSurfaceToolbarCoordinator.onAccessibilityStatusChanged(enabled);
}
}
......@@ -421,6 +443,8 @@ public class TopToolbarCoordinator implements Toolbar {
mToolbarLayout.setTabSwitcherMode(inTabSwitcherMode, showToolbar, delayAnimation);
if (mTabSwitcherModeCoordinatorPhone != null) {
mTabSwitcherModeCoordinatorPhone.setTabSwitcherMode(inTabSwitcherMode);
} else if (mStartSurfaceToolbarCoordinator != null) {
mStartSurfaceToolbarCoordinator.setStartSurfaceMode(inTabSwitcherMode);
}
}
......@@ -449,6 +473,8 @@ public class TopToolbarCoordinator implements Toolbar {
public void setIncognitoStateProvider(IncognitoStateProvider provider) {
if (mTabSwitcherModeCoordinatorPhone != null) {
mTabSwitcherModeCoordinatorPhone.setIncognitoStateProvider(provider);
} else if (mStartSurfaceToolbarCoordinator != null) {
mStartSurfaceToolbarCoordinator.setIncognitoStateProvider(provider);
}
}
......@@ -606,6 +632,8 @@ public class TopToolbarCoordinator implements Toolbar {
mToolbarLayout.onBottomToolbarVisibilityChanged(isVisible);
if (mTabSwitcherModeCoordinatorPhone != null) {
mTabSwitcherModeCoordinatorPhone.onBottomToolbarVisibilityChanged(isVisible);
} else if (mStartSurfaceToolbarCoordinator != null) {
mStartSurfaceToolbarCoordinator.onBottomToolbarVisibilityChanged(isVisible);
}
}
......
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