| Index: chrome/android/java/src/org/chromium/chrome/browser/widget/bottomsheet/BottomSheetNewTabController.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/widget/bottomsheet/BottomSheetNewTabController.java b/chrome/android/java/src/org/chromium/chrome/browser/widget/bottomsheet/BottomSheetNewTabController.java
|
| index 9b825225398c5c20b90e552bb033ccd4c8500b8e..b5d7782a4dbddd6579bed56e5a0b3c0767088f62 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/widget/bottomsheet/BottomSheetNewTabController.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/widget/bottomsheet/BottomSheetNewTabController.java
|
| @@ -22,7 +22,7 @@ public class BottomSheetNewTabController extends EmptyBottomSheetObserver {
|
| private LayoutManagerChrome mLayoutManager;
|
| private TabModelSelector mTabModelSelector;
|
|
|
| - private boolean mIsShowingNewTab;
|
| + private boolean mIsShowingNewTabUi;
|
|
|
| /**
|
| * Creates a new {@link BottomSheetNewTabController}.
|
| @@ -56,7 +56,10 @@ public class BottomSheetNewTabController extends EmptyBottomSheetObserver {
|
| * @param isIncognito Whether to display the incognito new tab UI.
|
| */
|
| public void displayNewTabUi(boolean isIncognito) {
|
| - mIsShowingNewTab = true;
|
| + mIsShowingNewTabUi = true;
|
| +
|
| + // Tell the model that a new tab may be added soon.
|
| + mTabModelSelector.getModel(isIncognito).setIsPendingTabAdd(true);
|
|
|
| // Select the correct model, immediately ending animations so that the sheet content is not
|
| // in transition while the sheet is opening.
|
| @@ -68,45 +71,40 @@ public class BottomSheetNewTabController extends EmptyBottomSheetObserver {
|
| // Update the loading status so that the location bar will update its contents.
|
| mLocationBar.updateLoadingState(true);
|
|
|
| + // Show the tab switcher if needed. The overview should be shown before the sheet is opened
|
| + // to ensure the toolbar ends up in the correct state.
|
| + if (!mLayoutManager.overviewVisible()) mLayoutManager.showOverview(true);
|
| +
|
| // Open the sheet.
|
| mBottomSheet.setSheetState(mTabModelSelector.getTotalTabCount() == 0
|
| ? BottomSheet.SHEET_STATE_FULL
|
| : BottomSheet.SHEET_STATE_HALF,
|
| true);
|
|
|
| - // Show the tab switcher if needed.
|
| - if (!mLayoutManager.overviewVisible()) mLayoutManager.showOverview(true);
|
| -
|
| mBottomSheet.getBottomSheetMetrics().recordSheetOpenReason(
|
| BottomSheetMetrics.OPENED_BY_NEW_TAB_CREATION);
|
| }
|
|
|
| /**
|
| - * Called when the activity containing the {@link BottomSheet} processes a url view intent.
|
| - * The new tab UI will be hidden.
|
| + * @return Whether the the new tab UI is showing.
|
| */
|
| - public void onProcessUrlViewIntent() {
|
| - if (!mIsShowingNewTab) return;
|
| -
|
| - mIsShowingNewTab = false;
|
| - mLayoutManager.hideOverview(true);
|
| + public boolean isShowingNewTabUi() {
|
| + return mIsShowingNewTabUi;
|
| }
|
|
|
| @Override
|
| public void onLoadUrl(String url) {
|
| - onProcessUrlViewIntent();
|
| - }
|
| + if (!mIsShowingNewTabUi) return;
|
|
|
| - /**
|
| - * @return Whether the the new tab UI is showing.
|
| - */
|
| - public boolean isShowingNewTab() {
|
| - return mIsShowingNewTab;
|
| + mLayoutManager.hideOverview(true);
|
| +
|
| + // BottomSheet closes itself when URLs are loaded; wait to finish hiding the new tab UI
|
| + // until the bottom sheet is closed.
|
| }
|
|
|
| @Override
|
| public void onSheetOpened() {
|
| - if (!mIsShowingNewTab) return;
|
| + if (!mIsShowingNewTabUi) return;
|
|
|
| // Transition from the tab switcher toolbar to the normal toolbar.
|
| mToolbar.showNormalToolbar();
|
| @@ -118,7 +116,7 @@ public class BottomSheetNewTabController extends EmptyBottomSheetObserver {
|
|
|
| @Override
|
| public void onSheetReleased() {
|
| - if (!mIsShowingNewTab) return;
|
| + if (!mIsShowingNewTabUi) return;
|
|
|
| // Start transitioning back to the tab switcher toolbar when the sheet is released to help
|
| // smooth out animations.
|
| @@ -129,9 +127,7 @@ public class BottomSheetNewTabController extends EmptyBottomSheetObserver {
|
|
|
| @Override
|
| public void onSheetClosed() {
|
| - if (!mIsShowingNewTab) return;
|
| -
|
| - mIsShowingNewTab = false;
|
| + if (!mIsShowingNewTabUi) return;
|
|
|
| // If the incognito tab model is showing, but has no tabs, this indicates that the model
|
| // was switched during the creation of an incognito ntp and the user closed the sheet
|
| @@ -143,5 +139,15 @@ public class BottomSheetNewTabController extends EmptyBottomSheetObserver {
|
|
|
| // Transition back to the tab switcher toolbar if the tab switcher is sill visible.
|
| if (mLayoutManager.overviewVisible()) mToolbar.showTabSwitcherToolbar();
|
| +
|
| + onNewTabUiHidden();
|
| +
|
| + mIsShowingNewTabUi = false;
|
| + }
|
| +
|
| + /** Called after the new tab UI is hidden. Resets properties on the tab models. */
|
| + private void onNewTabUiHidden() {
|
| + mTabModelSelector.getModel(false).setIsPendingTabAdd(false);
|
| + mTabModelSelector.getModel(true).setIsPendingTabAdd(false);
|
| }
|
| }
|
|
|