Commit 59e5d6ff authored by Gang Wu's avatar Gang Wu Committed by Commit Bot

[duet] Check go-to tab when no active tab presents

Home page button seems enabled for a while on switching between tabs.
It is because during transition between views, HomeButton only check
the active tab, if no active tab, HomeButton did not check go-to
tab. In this CL, HomeButton will check go-to tab if no active tab.


Bug: 935266
Change-Id: I59f5a617ebefce21b461fbcbf95ca0d04c186ceb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1873396
Commit-Queue: Gang Wu <gangwu@chromium.org>
Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709794}
parent d5f9416a
...@@ -121,7 +121,7 @@ public class HomeButton extends ChromeImageButton ...@@ -121,7 +121,7 @@ public class HomeButton extends ChromeImageButton
@Override @Override
public void onHomepageStateUpdated() { public void onHomepageStateUpdated() {
updateButtonEnabledState(); updateButtonEnabledState(null);
} }
public void setActivityTabProvider(ActivityTabProvider activityTabProvider) { public void setActivityTabProvider(ActivityTabProvider activityTabProvider) {
...@@ -129,12 +129,14 @@ public class HomeButton extends ChromeImageButton ...@@ -129,12 +129,14 @@ public class HomeButton extends ChromeImageButton
mActivityTabTabObserver = new ActivityTabTabObserver(activityTabProvider) { mActivityTabTabObserver = new ActivityTabTabObserver(activityTabProvider) {
@Override @Override
public void onObservingDifferentTab(Tab tab) { public void onObservingDifferentTab(Tab tab) {
updateButtonEnabledState(); if (tab == null) return;
updateButtonEnabledState(tab);
} }
@Override @Override
public void onUpdateUrl(Tab tab, String url) { public void onUpdateUrl(Tab tab, String url) {
updateButtonEnabledState(); if (tab == null) return;
updateButtonEnabledState(tab);
} }
}; };
} }
...@@ -142,23 +144,45 @@ public class HomeButton extends ChromeImageButton ...@@ -142,23 +144,45 @@ public class HomeButton extends ChromeImageButton
/** /**
* Menu button is enabled when not in NTP or if in NTP and homepage is enabled and set to * Menu button is enabled when not in NTP or if in NTP and homepage is enabled and set to
* somewhere other than the NTP. * somewhere other than the NTP.
* @param tab The notifying {@link Tab} that might be selected soon, this is a hint that a tab
* change is likely.
*/ */
private void updateButtonEnabledState() { private void updateButtonEnabledState(Tab tab) {
// New tab page button takes precedence over homepage. // New tab page button takes precedence over homepage.
final boolean isHomepageEnabled = HomepageManager.isHomepageEnabled(); final boolean isHomepageEnabled = HomepageManager.isHomepageEnabled();
final boolean isEnabled = !isActiveTabNTP()
|| (isHomepageEnabled && !NewTabPage.isNTPUrl(HomepageManager.getHomepageUri())); boolean isEnabled;
if (getActiveTab() != null) {
// Now tab shows a webpage, let's check if the webpage is not the NTP, or the webpage is
// NTP but homepage is not NTP.
isEnabled = !isTabNTP(getActiveTab())
|| (isHomepageEnabled
&& !NewTabPage.isNTPUrl(HomepageManager.getHomepageUri()));
} else {
// There is no active tab, which means tab is in transition, ex tab swither view to tab
// view, or from one tab to another tab.
isEnabled = !isTabNTP(tab);
}
setEnabled(isEnabled); setEnabled(isEnabled);
if (mWrapper != null) mWrapper.setEnabled(isEnabled); if (mWrapper != null) mWrapper.setEnabled(isEnabled);
if (mLabel != null) mLabel.setEnabled(isEnabled); if (mLabel != null) mLabel.setEnabled(isEnabled);
} }
private boolean isActiveTabNTP() { /**
if (mActivityTabProvider == null) return false; * Check if the provided tab is NTP. The tab is a hint that
* @param tab The notifying {@link Tab} that might be selected soon, this is a hint that a tab
* change is likely.
*/
private boolean isTabNTP(Tab tab) {
return tab != null && NewTabPage.isNTPUrl(tab.getUrl());
}
final Tab tab = mActivityTabProvider.get(); /**
if (tab == null) return false; * Return the active tab. If no active tab is shown, return null.
*/
private Tab getActiveTab() {
if (mActivityTabProvider == null) return null;
return NewTabPage.isNTPUrl(tab.getUrl()); return mActivityTabProvider.get();
} }
} }
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