diff options
author | dfalcantara@chromium.org <dfalcantara@chromium.org> | 2015-12-10 10:57:33 -0800 |
---|---|---|
committer | dfalcantara@chromium.org <dfalcantara@chromium.org> | 2015-12-10 18:59:52 +0000 |
commit | deb59e397738cff226c67903d922273c7f4f3445 (patch) | |
tree | ab9652da68fc438584b158c1d782d91b2360e027 | |
parent | d955f68167e2b60a14e09eef160f9065aea2c7eb (diff) | |
download | chromium_src-deb59e397738cff226c67903d922273c7f4f3445.zip chromium_src-deb59e397738cff226c67903d922273c7f4f3445.tar.gz chromium_src-deb59e397738cff226c67903d922273c7f4f3445.tar.bz2 |
[Merge] Show Incognito tab switcher button on startup
LayoutManagerChrome now observes the TabModelSelector to see
if any Incognito tabs exist during startup. If so, it signals
to the Layout that the Incognito tab switcher button should be
visible.
BUG=543885
TBR=dtrainor
Review URL: https://codereview.chromium.org/1514503002
Cr-Commit-Position: refs/heads/master@{#364225}
Review URL: https://codereview.chromium.org/1506203009 .
Cr-Commit-Position: refs/branch-heads/2564@{#311}
Cr-Branched-From: 1283eca15bd9f772387f75241576cde7bdec7f54-refs/heads/master@{#359700}
4 files changed, 49 insertions, 0 deletions
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/Layout.java b/chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/Layout.java index 6e00e54..02c6cd3 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/Layout.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/Layout.java @@ -815,6 +815,15 @@ public abstract class Layout implements TabContentManager.ThumbnailChangeListene } /** + * Called when the TabModelSelector has been initialized with an accurate tab count. + */ + public void onTabStateInitialized() { + for (int i = 0; i < mSceneOverlays.size(); i++) { + mSceneOverlays.get(i).tabStateInitialized(); + } + } + + /** * Called when the current tabModel switched (e.g. standard -> incognito). * * @param incognito True if the new model is incognito. diff --git a/chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/LayoutManager.java b/chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/LayoutManager.java index c37a9d9..7885266 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/LayoutManager.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/LayoutManager.java @@ -7,6 +7,7 @@ package org.chromium.chrome.browser.compositor.layouts; import android.graphics.Point; import android.graphics.Rect; import android.graphics.RectF; +import android.os.Handler; import android.os.SystemClock; import android.view.MotionEvent; import android.view.View; @@ -30,6 +31,7 @@ import org.chromium.chrome.browser.contextualsearch.ContextualSearchManagementDe import org.chromium.chrome.browser.dom_distiller.ReaderModeManagerDelegate; import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager; import org.chromium.chrome.browser.fullscreen.FullscreenManager; +import org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver; import org.chromium.chrome.browser.tabmodel.TabCreatorManager; import org.chromium.chrome.browser.tabmodel.TabModelSelector; import org.chromium.content.browser.SPenSupport; @@ -245,6 +247,8 @@ public abstract class LayoutManager implements LayoutUpdateHost, LayoutProvider, mContentContainer = androidContentContainer; if (mNextActiveLayout != null) startShowing(mNextActiveLayout, true); + + updateLayoutForTabModelSelector(); } /** @@ -525,4 +529,30 @@ public abstract class LayoutManager implements LayoutUpdateHost, LayoutProvider, return Orientation.PORTRAIT; } } + + /** + * Updates the Layout for the state of the {@link TabModelSelector} after initialization. + * If the TabModelSelector is not yet initialized when this function is called, a + * {@link TabModelSelectorObserver} is created to listen for when it is ready. + */ + private void updateLayoutForTabModelSelector() { + if (mTabModelSelector.isTabStateInitialized() && getActiveLayout() != null) { + getActiveLayout().onTabStateInitialized(); + } else { + mTabModelSelector.addObserver(new EmptyTabModelSelectorObserver() { + @Override + public void onTabStateInitialized() { + if (getActiveLayout() != null) getActiveLayout().onTabStateInitialized(); + + final EmptyTabModelSelectorObserver observer = this; + new Handler().post(new Runnable() { + @Override + public void run() { + mTabModelSelector.removeObserver(observer); + } + }); + } + }); + } + } } diff --git a/chrome/android/java/src/org/chromium/chrome/browser/compositor/overlays/SceneOverlay.java b/chrome/android/java/src/org/chromium/chrome/browser/compositor/overlays/SceneOverlay.java index e1538bf..4054eb1 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/compositor/overlays/SceneOverlay.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/compositor/overlays/SceneOverlay.java @@ -65,6 +65,11 @@ public interface SceneOverlay { void tabTitleChanged(int tabId, String title); /** + * Called when the TabModelSelector has been initialized with an accurate tab count. + */ + void tabStateInitialized(); + + /** * Called when the active {@link TabModel} switched (e.g. standard -> incognito). * @param incognito Whether or not the new active model is incognito. */ diff --git a/chrome/android/java/src/org/chromium/chrome/browser/compositor/overlays/strip/StripLayoutHelperManager.java b/chrome/android/java/src/org/chromium/chrome/browser/compositor/overlays/strip/StripLayoutHelperManager.java index 4586b75..b2f8d46 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/compositor/overlays/strip/StripLayoutHelperManager.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/compositor/overlays/strip/StripLayoutHelperManager.java @@ -235,6 +235,11 @@ public class StripLayoutHelperManager implements SceneOverlay { } @Override + public void tabStateInitialized() { + updateModelSwitcherButton(); + } + + @Override public void tabModelSwitched(boolean incognito) { if (incognito == mIsIncognito) return; mIsIncognito = incognito; |