From deb59e397738cff226c67903d922273c7f4f3445 Mon Sep 17 00:00:00 2001 From: "dfalcantara@chromium.org" Date: Thu, 10 Dec 2015 10:57:33 -0800 Subject: [PATCH] [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} --- .../browser/compositor/layouts/Layout.java | 9 ++++++ .../compositor/layouts/LayoutManager.java | 30 +++++++++++++++++++ .../compositor/overlays/SceneOverlay.java | 5 ++++ .../strip/StripLayoutHelperManager.java | 5 ++++ 4 files changed, 49 insertions(+) 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 6e00e54bf4841..02c6cd3d4b0e7 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 @@ -814,6 +814,15 @@ public void onTabCreated(long time, int tabId, int tabIndex, int sourceTabId, } } + /** + * 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). * 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 c37a9d9038f19..7885266fb69d5 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 @@ 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.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 void init(TabModelSelector selector, TabCreatorManager creator, mContentContainer = androidContentContainer; if (mNextActiveLayout != null) startShowing(mNextActiveLayout, true); + + updateLayoutForTabModelSelector(); } /** @@ -525,4 +529,30 @@ private int getOrientation() { 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 e1538bfef5487..4054eb1795e1d 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 @@ -64,6 +64,11 @@ SceneOverlayLayer getUpdatedSceneOverlayTree(LayerTitleCache layerTitleCache, */ 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 4586b755bf85e..b2f8d46387f72 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 @@ -234,6 +234,11 @@ public boolean updateOverlay(long time, long dt) { return getActiveStripLayoutHelper().updateLayout(time, dt); } + @Override + public void tabStateInitialized() { + updateModelSwitcherButton(); + } + @Override public void tabModelSwitched(boolean incognito) { if (incognito == mIsIncognito) return;