Commit 61bed816 authored by Pedro Amaral's avatar Pedro Amaral Committed by Commit Bot

Horizontal tab switcher use tab toggle

Replace the HTS Incognito Button with a toggle.

Bug: 851166
Change-Id: I5c431abb508930ee1a9a24792f2299ea08d944cf
Reviewed-on: https://chromium-review.googlesource.com/1246453Reviewed-by: default avatarYusuf Ozuysal <yusufo@chromium.org>
Commit-Queue: Pedro Amaral <amaralp@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594780}
parent 1534ee3f
...@@ -4,5 +4,5 @@ ...@@ -4,5 +4,5 @@
found in the LICENSE file. --> found in the LICENSE file. -->
<!-- The incognito toggle toolbar button. --> <!-- The incognito toggle toolbar button. -->
<org.chromium.chrome.browser.widget.incognitotoggle.IncognitoToggleButton <org.chromium.chrome.browser.toolbar.IncognitoToggleTabLayout
style="@style/ToolbarButton" /> style="@style/ToolbarButton" />
...@@ -38,6 +38,14 @@ ...@@ -38,6 +38,14 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="top" /> android:layout_gravity="top" />
<ViewStub
android:id="@+id/incognito_tabs_stub"
android:inflatedId="@+id/incognito_toggle_tabs"
android:layout="@layout/incognito_toggle_tabs"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center" />
<LinearLayout android:id="@+id/toolbar_buttons" <LinearLayout android:id="@+id/toolbar_buttons"
android:orientation="horizontal" android:orientation="horizontal"
android:layout_width="wrap_content" android:layout_width="wrap_content"
...@@ -55,14 +63,6 @@ ...@@ -55,14 +63,6 @@
style="@style/ToolbarButton" style="@style/ToolbarButton"
android:paddingStart="8dp" android:paddingStart="8dp"
android:visibility="gone" /> android:visibility="gone" />
<ViewStub
android:id="@+id/incognito_button_stub"
android:inflatedId="@+id/incognito_button"
android:layout="@layout/toolbar_phone_incognito_button"
style="@style/ToolbarButton"
android:contentDescription="@string/accessibility_tabstrip_btn_incognito_toggle_standard"
android:visibility="gone" />
</FrameLayout> </FrameLayout>
<ImageButton android:id="@+id/tab_switcher_button" <ImageButton android:id="@+id/tab_switcher_button"
......
// Copyright 2018 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;
import android.content.Context;
import android.content.res.ColorStateList;
import android.support.design.widget.TabLayout;
import android.support.v7.content.res.AppCompatResources;
import android.util.AttributeSet;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeFeatureList;
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.widget.TintedImageView;
/**
* TabLayout shown in the Horizontal Tab Switcher.
*/
public class IncognitoToggleTabLayout extends TabLayout {
private TabLayout.Tab mStandardButton;
private TabLayout.Tab mIncognitoButton;
private TintedImageView mStandardButtonIcon;
private TintedImageView mIncognitoButtonIcon;
private TabSwitcherDrawable mTabSwitcherDrawable;
private ColorStateList mTabIconDarkColor;
private ColorStateList mTabIconLightColor;
private ColorStateList mTabIconSelectedDarkColor;
private ColorStateList mTabIconSelectedLightColor;
private TabModelSelector mTabModelSelector;
/**
* Constructor for inflating from XML.
*/
public IncognitoToggleTabLayout(Context context, AttributeSet attrs) {
super(context, attrs);
mTabIconDarkColor =
AppCompatResources.getColorStateList(getContext(), R.color.dark_mode_tint);
mTabIconSelectedDarkColor =
AppCompatResources.getColorStateList(getContext(), R.color.light_active_color);
mTabIconLightColor =
AppCompatResources.getColorStateList(getContext(), R.color.white_alpha_70);
mTabIconSelectedLightColor =
AppCompatResources.getColorStateList(getContext(), R.color.white_mode_tint);
mStandardButtonIcon = new TintedImageView(getContext());
mTabSwitcherDrawable = TabSwitcherDrawable.createTabSwitcherDrawable(getContext(), false);
mStandardButtonIcon.setImageDrawable(mTabSwitcherDrawable);
mIncognitoButtonIcon = new TintedImageView(getContext());
mIncognitoButtonIcon.setImageResource(R.drawable.incognito_simple);
mStandardButton =
newTab().setCustomView(mStandardButtonIcon)
.setContentDescription(R.string.accessibility_tab_switcher_standard_stack);
addTab(mStandardButton);
mIncognitoButton =
newTab().setCustomView(mIncognitoButtonIcon)
.setContentDescription(
ChromeFeatureList.isEnabled(ChromeFeatureList.INCOGNITO_STRINGS)
? R.string.accessibility_tab_switcher_private_stack
: R.string.accessibility_tab_switcher_incognito_stack);
addTab(mIncognitoButton);
addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
setSelectedModel(mIncognitoButton.isSelected());
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {}
@Override
public void onTabReselected(TabLayout.Tab tab) {}
});
}
/**
* @param selector A {@link TabModelSelector} to provide information about open tabs.
*/
public void setTabModelSelector(TabModelSelector selector) {
mTabModelSelector = selector;
if (mTabModelSelector == null) return;
mTabModelSelector.addObserver(new EmptyTabModelSelectorObserver() {
@Override
public void onTabModelSelected(TabModel newModel, TabModel oldModel) {
setStateBasedOnModel();
}
});
setStateBasedOnModel();
}
/**
* Update the visual state based on number of normal (non-incognito) tabs present.
* @param tabCount The number of normal tabs.
*/
public void updateTabCount(int tabCount) {
mTabSwitcherDrawable.updateForTabCount(tabCount, false);
}
private void setStateBasedOnModel() {
if (mTabModelSelector == null) return;
final boolean isIncognitoSelected = mTabModelSelector.isIncognitoSelected();
if (isIncognitoSelected) {
setSelectedTabIndicatorColor(mTabIconSelectedLightColor.getDefaultColor());
mStandardButtonIcon.setTint(mTabIconLightColor);
mTabSwitcherDrawable.setTint(mTabIconLightColor);
mIncognitoButtonIcon.setTint(mTabIconSelectedLightColor);
} else {
setSelectedTabIndicatorColor(mTabIconSelectedDarkColor.getDefaultColor());
mStandardButtonIcon.setTint(mTabIconSelectedDarkColor);
mTabSwitcherDrawable.setTint(mTabIconSelectedDarkColor);
mIncognitoButtonIcon.setTint(mTabIconDarkColor);
}
// Ensure the tab in tab layout is correctly selected when tab switcher is
// first opened.
if (isIncognitoSelected && !mIncognitoButton.isSelected()) {
mIncognitoButton.select();
} else if (!isIncognitoSelected && !mStandardButton.isSelected()) {
mStandardButton.select();
}
}
private void setSelectedModel(boolean incognitoSelected) {
if (mTabModelSelector == null
|| incognitoSelected == mTabModelSelector.isIncognitoSelected()) {
return;
}
mTabModelSelector.commitAllTabClosures();
mTabModelSelector.selectModel(incognitoSelected);
}
}
...@@ -78,7 +78,6 @@ import org.chromium.chrome.browser.util.MathUtils; ...@@ -78,7 +78,6 @@ import org.chromium.chrome.browser.util.MathUtils;
import org.chromium.chrome.browser.util.ViewUtils; import org.chromium.chrome.browser.util.ViewUtils;
import org.chromium.chrome.browser.widget.TintedImageButton; import org.chromium.chrome.browser.widget.TintedImageButton;
import org.chromium.chrome.browser.widget.animation.CancelAwareAnimatorListener; import org.chromium.chrome.browser.widget.animation.CancelAwareAnimatorListener;
import org.chromium.chrome.browser.widget.incognitotoggle.IncognitoToggleButton;
import org.chromium.chrome.browser.widget.newtab.NewTabButton; import org.chromium.chrome.browser.widget.newtab.NewTabButton;
import org.chromium.chrome.browser.widget.textbubble.TextBubble; import org.chromium.chrome.browser.widget.textbubble.TextBubble;
import org.chromium.components.feature_engagement.EventConstants; import org.chromium.components.feature_engagement.EventConstants;
...@@ -139,7 +138,7 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -139,7 +138,7 @@ public class ToolbarPhone extends ToolbarLayout
protected LocationBarPhone mLocationBar; protected LocationBarPhone mLocationBar;
protected ViewGroup mToolbarButtonsContainer; protected ViewGroup mToolbarButtonsContainer;
private IncognitoToggleButton mIncognitoToggleButton; private IncognitoToggleTabLayout mIncognitoToggleTabLayout;
protected ImageView mToggleTabStackButton; protected ImageView mToggleTabStackButton;
protected NewTabButton mNewTabButton; protected NewTabButton mNewTabButton;
protected @Nullable TintedImageButton mHomeButton; protected @Nullable TintedImageButton mHomeButton;
...@@ -189,7 +188,6 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -189,7 +188,6 @@ public class ToolbarPhone extends ToolbarLayout
private OnClickListener mTabSwitcherListener; private OnClickListener mTabSwitcherListener;
private OnClickListener mNewTabListener; private OnClickListener mNewTabListener;
private OnClickListener mIncognitoListener;
@ViewDebug.ExportedProperty(category = "chrome") @ViewDebug.ExportedProperty(category = "chrome")
protected boolean mUrlFocusChangeInProgress; protected boolean mUrlFocusChangeInProgress;
...@@ -577,8 +575,6 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -577,8 +575,6 @@ public class ToolbarPhone extends ToolbarLayout
RecordUserAction.record("MobileNewTabOpened"); RecordUserAction.record("MobileNewTabOpened");
// TODO(kkimlabs): Record UMA action for homepage button. // TODO(kkimlabs): Record UMA action for homepage button.
} }
} else if (mIncognitoToggleButton == v) {
if (mIncognitoListener != null) mIncognitoListener.onClick(v);
} else if (mHomeButton != null && mHomeButton == v) { } else if (mHomeButton != null && mHomeButton == v) {
openHomepage(); openHomepage();
if (isNativeLibraryReady() if (isNativeLibraryReady()
...@@ -773,19 +769,7 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -773,19 +769,7 @@ public class ToolbarPhone extends ToolbarLayout
* @return The right bounds of the location bar after accounting for any visible left buttons. * @return The right bounds of the location bar after accounting for any visible left buttons.
*/ */
protected int getBoundsAfterAccountingForRightButtons() { protected int getBoundsAfterAccountingForRightButtons() {
// We set the incognito toggle button's visibility from GONE to VISIBLE when the tab return Math.max(mToolbarSidePadding, mToolbarButtonsContainer.getMeasuredWidth());
// switcher starts to open, but we don't want this to affect the Omnibox's size during the
// animation, so we have to make an adjustment here.
// However, if the experimental button is showing it sits in a FrameLayout with the
// incognito button and the omnibox will be appropriately sized without an explicit
// adjustment.
int incognitoButtonWidth = 0;
if (mIncognitoToggleButton != null && mIncognitoToggleButton.getVisibility() == VISIBLE
&& (mExperimentalButton == null || mExperimentalButton.getVisibility() == GONE)) {
incognitoButtonWidth += mIncognitoToggleButton.getMeasuredWidth();
}
return Math.max(mToolbarSidePadding,
mToolbarButtonsContainer.getMeasuredWidth() - incognitoButtonWidth);
} }
protected void updateToolbarBackground(int color) { protected void updateToolbarBackground(int color) {
...@@ -1733,25 +1717,22 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1733,25 +1717,22 @@ public class ToolbarPhone extends ToolbarLayout
// Don't inflate the incognito toggle button unless the horizontal tab switcher experiment // Don't inflate the incognito toggle button unless the horizontal tab switcher experiment
// is enabled and the user actually enters the tab switcher. // is enabled and the user actually enters the tab switcher.
if (!FeatureUtilities.isBottomToolbarEnabled() && mIncognitoToggleButton == null if (!FeatureUtilities.isBottomToolbarEnabled() && mIncognitoToggleTabLayout == null
&& mTabSwitcherState != STATIC_TAB && usingHorizontalTabSwitcher() && mTabSwitcherState != STATIC_TAB && usingHorizontalTabSwitcher()
&& PrefServiceBridge.getInstance().isIncognitoModeEnabled()) { && PrefServiceBridge.getInstance().isIncognitoModeEnabled()) {
ViewStub incognitoToggleButtonStub = findViewById(R.id.incognito_button_stub); ViewStub incognitoToggleTabsStub = findViewById(R.id.incognito_tabs_stub);
mIncognitoToggleButton = (IncognitoToggleButton) incognitoToggleButtonStub.inflate(); mIncognitoToggleTabLayout =
mIncognitoToggleButton.setOnClickListener(this); (IncognitoToggleTabLayout) incognitoToggleTabsStub.inflate();
mIncognitoToggleButton.setTabModelSelector(mTabModelSelector); mIncognitoToggleTabLayout.setTabModelSelector(mTabModelSelector);
mTabSwitcherModeViews.add(mIncognitoToggleButton); mTabSwitcherModeViews.add(mIncognitoToggleTabLayout);
mIncognitoToggleTabLayout.updateTabCount(mTabModelSelector.getModel(false).getCount());
mBrowsingModeViews.add(mToggleTabStackButton);
} }
for (View view : mTabSwitcherModeViews) { for (View view : mTabSwitcherModeViews) {
// The incognito toggle button needs to be set to GONE rather than INVISIBLE so it
// doesn't reduce the space available for the Omnibox.
if (view == mIncognitoToggleButton && tabSwitcherViewsVisibility == INVISIBLE) {
view.setVisibility(GONE);
} else {
view.setVisibility(tabSwitcherViewsVisibility); view.setVisibility(tabSwitcherViewsVisibility);
} }
}
for (View view : mBrowsingModeViews) { for (View view : mBrowsingModeViews) {
view.setVisibility(browsingViewsVisibility); view.setVisibility(browsingViewsVisibility);
} }
...@@ -1820,7 +1801,8 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1820,7 +1801,8 @@ public class ToolbarPhone extends ToolbarLayout
} else { } else {
if (!mDelayingTabSwitcherAnimation) { if (!mDelayingTabSwitcherAnimation) {
mTabSwitcherModeAnimation = createExitTabSwitcherAnimation(showToolbar); mTabSwitcherModeAnimation = createExitTabSwitcherAnimation(showToolbar);
if (mIncognitoToggleButton != null) mIncognitoToggleButton.setClickable(false); if (mIncognitoToggleTabLayout != null)
mIncognitoToggleTabLayout.setClickable(false);
} }
} }
...@@ -1853,7 +1835,7 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1853,7 +1835,7 @@ public class ToolbarPhone extends ToolbarLayout
@Override @Override
protected void onTabSwitcherTransitionFinished() { protected void onTabSwitcherTransitionFinished() {
if (mIncognitoToggleButton != null) mIncognitoToggleButton.setClickable(true); if (mIncognitoToggleTabLayout != null) mIncognitoToggleTabLayout.setClickable(true);
setAlpha(1.f); setAlpha(1.f);
mClipRect = null; mClipRect = null;
...@@ -1897,11 +1879,6 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1897,11 +1879,6 @@ public class ToolbarPhone extends ToolbarLayout
mNewTabListener = listener; mNewTabListener = listener;
} }
@Override
public void setIncognitoClickHandler(OnClickListener listener) {
mIncognitoListener = listener;
}
@Override @Override
protected void onAccessibilityStatusChanged(boolean enabled) { protected void onAccessibilityStatusChanged(boolean enabled) {
super.onAccessibilityStatusChanged(enabled); super.onAccessibilityStatusChanged(enabled);
...@@ -2126,6 +2103,10 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -2126,6 +2103,10 @@ public class ToolbarPhone extends ToolbarLayout
mTabSwitcherButtonDrawableLight.updateForTabCount(numberOfTabs, isIncognito()); mTabSwitcherButtonDrawableLight.updateForTabCount(numberOfTabs, isIncognito());
mTabSwitcherButtonDrawable.updateForTabCount(numberOfTabs, isIncognito()); mTabSwitcherButtonDrawable.updateForTabCount(numberOfTabs, isIncognito());
if (!isIncognito() && mIncognitoToggleTabLayout != null) {
mIncognitoToggleTabLayout.updateTabCount(numberOfTabs);
}
boolean useTabStackDrawableLight = isIncognito() boolean useTabStackDrawableLight = isIncognito()
|| ColorUtils.shouldUseLightForegroundOnBackground(getTabThemeColor()); || ColorUtils.shouldUseLightForegroundOnBackground(getTabThemeColor());
if (mTabSwitcherAnimationTabStackDrawable == null if (mTabSwitcherAnimationTabStackDrawable == null
...@@ -2531,8 +2512,8 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -2531,8 +2512,8 @@ public class ToolbarPhone extends ToolbarLayout
@Override @Override
public void setTabModelSelector(TabModelSelector selector) { public void setTabModelSelector(TabModelSelector selector) {
mTabModelSelector = selector; mTabModelSelector = selector;
if (mIncognitoToggleButton != null) { if (mIncognitoToggleTabLayout != null) {
mIncognitoToggleButton.setTabModelSelector(mTabModelSelector); mIncognitoToggleTabLayout.setTabModelSelector(mTabModelSelector);
} }
} }
......
...@@ -1499,6 +1499,7 @@ chrome_java_sources = [ ...@@ -1499,6 +1499,7 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/toolbar/MenuButton.java", "java/src/org/chromium/chrome/browser/toolbar/MenuButton.java",
"java/src/org/chromium/chrome/browser/toolbar/ToolbarButtonSlotData.java", "java/src/org/chromium/chrome/browser/toolbar/ToolbarButtonSlotData.java",
"java/src/org/chromium/chrome/browser/toolbar/HomePageButton.java", "java/src/org/chromium/chrome/browser/toolbar/HomePageButton.java",
"java/src/org/chromium/chrome/browser/toolbar/IncognitoToggleTabLayout.java",
"java/src/org/chromium/chrome/browser/toolbar/KeyboardNavigationListener.java", "java/src/org/chromium/chrome/browser/toolbar/KeyboardNavigationListener.java",
"java/src/org/chromium/chrome/browser/toolbar/ScrollingBottomViewResourceFrameLayout.java", "java/src/org/chromium/chrome/browser/toolbar/ScrollingBottomViewResourceFrameLayout.java",
"java/src/org/chromium/chrome/browser/toolbar/TabSwitcherButtonViewBinder.java", "java/src/org/chromium/chrome/browser/toolbar/TabSwitcherButtonViewBinder.java",
......
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