-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract some tab switcher button logic from ToolbarPhone
Move some of the tab switcher button logic that is shared between browsing and tab switcher modes from ToolbarPhone into a new ToggleTabStackButton. This new class will eventually be replaced by TabSwitcherButtonCoordinator, but more refactoring is needed first. BUG=897294 Change-Id: Iaa123432148ccea7181f9f222df30056a308b12f Reviewed-on: https://chromium-review.googlesource.com/c/1358914 Reviewed-by: Matthew Jones <mdjones@chromium.org> Commit-Queue: Theresa <twellington@chromium.org> Cr-Commit-Position: refs/heads/master@{#613648}
- Loading branch information
Theresa
authored and
Commit Bot
committed
Dec 4, 2018
1 parent
76da8c7
commit 93b7c08
Showing
8 changed files
with
149 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
chrome/android/java/src/org/chromium/chrome/browser/toolbar/top/ToggleTabStackButton.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// 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.top; | ||
|
||
import android.content.Context; | ||
import android.support.annotation.Nullable; | ||
import android.util.AttributeSet; | ||
import android.view.View; | ||
import android.widget.ImageButton; | ||
|
||
import org.chromium.chrome.R; | ||
import org.chromium.chrome.browser.toolbar.TabCountProvider; | ||
import org.chromium.chrome.browser.toolbar.TabSwitcherDrawable; | ||
import org.chromium.chrome.browser.util.AccessibilityUtil; | ||
|
||
/** | ||
* A button displaying the number of open tabs. Clicking the button toggles the tab switcher view. | ||
* TODO(twellington): Replace with TabSwitcherButtonCoordinator so code can be shared with bottom | ||
* toolbar. | ||
*/ | ||
public class ToggleTabStackButton extends ImageButton implements TabCountProvider.TabCountObserver, | ||
View.OnClickListener, | ||
View.OnLongClickListener { | ||
private TabSwitcherDrawable mTabSwitcherButtonDrawable; | ||
private TabSwitcherDrawable mTabSwitcherButtonDrawableLight; | ||
private TabCountProvider mTabCountProvider; | ||
private OnClickListener mTabSwitcherListener; | ||
|
||
public ToggleTabStackButton(Context context, @Nullable AttributeSet attrs) { | ||
super(context, attrs); | ||
} | ||
|
||
@Override | ||
public void onFinishInflate() { | ||
super.onFinishInflate(); | ||
|
||
mTabSwitcherButtonDrawable = | ||
TabSwitcherDrawable.createTabSwitcherDrawable(getContext(), false); | ||
mTabSwitcherButtonDrawableLight = | ||
TabSwitcherDrawable.createTabSwitcherDrawable(getContext(), true); | ||
setImageDrawable(mTabSwitcherButtonDrawable); | ||
setOnClickListener(this); | ||
setOnLongClickListener(this); | ||
} | ||
|
||
/** | ||
* Called to destroy the tab stack button. | ||
*/ | ||
void destroy() { | ||
if (mTabCountProvider != null) mTabCountProvider.removeObserver(this); | ||
} | ||
|
||
/** | ||
* 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. | ||
*/ | ||
void setOnTabSwitcherClickHandler(OnClickListener listener) { | ||
mTabSwitcherListener = listener; | ||
} | ||
|
||
/** | ||
* Updates the contained drawable. | ||
* @param useLightDrawables Whether light drawables should be used. | ||
*/ | ||
void setUseLightDrawables(boolean useLightDrawables) { | ||
setImageDrawable( | ||
useLightDrawables ? mTabSwitcherButtonDrawableLight : mTabSwitcherButtonDrawable); | ||
} | ||
|
||
/** | ||
* @param provider The {@link TabCountProvider} used to observe the number of tabs in the | ||
* current model. | ||
*/ | ||
void setTabCountProvider(TabCountProvider provider) { | ||
mTabCountProvider = provider; | ||
mTabCountProvider.addObserverAndTrigger(this); | ||
} | ||
|
||
@Override | ||
public void onTabCountChanged(int numberOfTabs, boolean isIncognito) { | ||
setEnabled(numberOfTabs >= 1); | ||
setContentDescription(getResources().getQuantityString( | ||
R.plurals.accessibility_toolbar_btn_tabswitcher_toggle, numberOfTabs, | ||
numberOfTabs)); | ||
mTabSwitcherButtonDrawableLight.updateForTabCount(numberOfTabs, isIncognito); | ||
mTabSwitcherButtonDrawable.updateForTabCount(numberOfTabs, isIncognito); | ||
} | ||
|
||
@Override | ||
public void onClick(View v) { | ||
if (mTabSwitcherListener != null && isClickable()) { | ||
mTabSwitcherListener.onClick(this); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean onLongClick(View v) { | ||
CharSequence description = getResources().getString(org.chromium.chrome.R.string.open_tabs); | ||
return AccessibilityUtil.showAccessibilityToast(getContext(), v, description); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.