Skip to content

Commit

Permalink
[Merge] Show Incognito tab switcher button on startup
Browse files Browse the repository at this point in the history
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@{crosswalk-project#311}
Cr-Branched-From: 1283eca-refs/heads/master@{#359700}
  • Loading branch information
[email protected] committed Dec 10, 2015
1 parent d955f68 commit deb59e3
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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).
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -245,6 +247,8 @@ public void init(TabModelSelector selector, TabCreatorManager creator,
mContentContainer = androidContentContainer;

if (mNextActiveLayout != null) startShowing(mNextActiveLayout, true);

updateLayoutForTabModelSelector();
}

/**
Expand Down Expand Up @@ -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);
}
});
}
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit deb59e3

Please sign in to comment.