Commit 2ac569cf authored by Stepan Khapugin's avatar Stepan Khapugin Committed by Commit Bot

[iOS][multiball] Extract TabSwitcherDelegate contents from MainController.

Moves the implementation of TabSwitcherDelegate "helpers" from Main to Scene
controller. Moves the temporary interface from MCGuts to SCGuts.

Bug: none
Change-Id: Ie874e8f754cd6e38ba3aa04c6e64ea68192c95dd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1992084
Commit-Queue: Stepan Khapugin <stkhapugin@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#732391}
parent d1b532dc
...@@ -1282,9 +1282,10 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData( ...@@ -1282,9 +1282,10 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
} }
if (self.tabSwitcherIsActive) { if (self.tabSwitcherIsActive) {
DCHECK(!self.dismissingTabSwitcher); DCHECK(!self.dismissingTabSwitcher);
[self beginDismissingTabSwitcherWithCurrentModel:self.mainTabModel [self.sceneController
focusOmnibox:NO]; beginDismissingTabSwitcherWithCurrentModel:self.mainTabModel
[self finishDismissingTabSwitcher]; focusOmnibox:NO];
[self.sceneController finishDismissingTabSwitcher];
} }
if (firstRun || if (firstRun ||
[self.sceneController shouldOpenNTPTabOnActivationOfTabModel:tabModel]) { [self.sceneController shouldOpenNTPTabOnActivationOfTabModel:tabModel]) {
...@@ -1546,68 +1547,6 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData( ...@@ -1546,68 +1547,6 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
[self.mainCoordinator showTabSwitcher:_tabSwitcher]; [self.mainCoordinator showTabSwitcher:_tabSwitcher];
} }
#pragma mark - TabSwitcherDelegate helper methods
- (void)beginDismissingTabSwitcherWithCurrentModel:(TabModel*)tabModel
focusOmnibox:(BOOL)focusOmnibox {
DCHECK(tabModel == self.mainTabModel || tabModel == self.otrTabModel);
self.dismissingTabSwitcher = YES;
ApplicationMode mode = (tabModel == self.mainTabModel)
? ApplicationMode::NORMAL
: ApplicationMode::INCOGNITO;
[self.sceneController setCurrentInterfaceForMode:mode];
// The call to set currentBVC above does not actually display the BVC, because
// self.dismissingTabSwitcher is YES. So: Force the BVC transition to start.
[self displayCurrentBVCAndFocusOmnibox:focusOmnibox];
}
- (void)finishDismissingTabSwitcher {
// In real world devices, it is possible to have an empty tab model at the
// finishing block of a BVC presentation animation. This can happen when the
// following occur: a) There is JS that closes the last incognito tab, b) that
// JS was paused while the user was in the tab switcher, c) the user enters
// the tab, activating the JS while the tab is being presented. Effectively,
// the BVC finishes the presentation animation, but there are no tabs to
// display. The only appropriate action is to dismiss the BVC and return the
// user to the tab switcher.
if (self.currentTabModel.count == 0U) {
self.tabSwitcherIsActive = NO;
self.dismissingTabSwitcher = NO;
self.modeToDisplayOnTabSwitcherDismissal = TabSwitcherDismissalMode::NONE;
self.NTPActionAfterTabSwitcherDismissal = NO_ACTION;
[self showTabSwitcher];
return;
}
// The tab switcher dismissal animation runs
// as part of the BVC presentation process. The BVC is presented before the
// animations begin, so it should be the current active VC at this point.
DCHECK_EQ(self.mainCoordinator.activeViewController, self.currentBVC);
if (self.modeToDisplayOnTabSwitcherDismissal ==
TabSwitcherDismissalMode::NORMAL) {
[self.sceneController setCurrentInterfaceForMode:ApplicationMode::NORMAL];
} else if (self.modeToDisplayOnTabSwitcherDismissal ==
TabSwitcherDismissalMode::INCOGNITO) {
[self.sceneController
setCurrentInterfaceForMode:ApplicationMode::INCOGNITO];
}
self.modeToDisplayOnTabSwitcherDismissal = TabSwitcherDismissalMode::NONE;
ProceduralBlock action = [self completionBlockForTriggeringAction:
self.NTPActionAfterTabSwitcherDismissal];
self.NTPActionAfterTabSwitcherDismissal = NO_ACTION;
if (action) {
action();
}
self.tabSwitcherIsActive = NO;
self.dismissingTabSwitcher = NO;
}
#pragma mark - App Navigation #pragma mark - App Navigation
- (void)presentSignedInAccountsViewControllerForBrowserState: - (void)presentSignedInAccountsViewControllerForBrowserState:
......
...@@ -106,18 +106,6 @@ enum class TabSwitcherDismissalMode { NONE, NORMAL, INCOGNITO }; ...@@ -106,18 +106,6 @@ enum class TabSwitcherDismissalMode { NONE, NORMAL, INCOGNITO };
- (void)startVoiceSearchInCurrentBVC; - (void)startVoiceSearchInCurrentBVC;
- (void)showTabSwitcher; - (void)showTabSwitcher;
// TabSwitcherDelegate helpers
// Begins the process of dismissing the tab switcher with the given current
// model, switching which BVC is suspended if necessary, but not updating the
// UI. The omnibox will be focused after the tab switcher dismissal is
// completed if |focusOmnibox| is YES.
- (void)beginDismissingTabSwitcherWithCurrentModel:(TabModel*)tabModel
focusOmnibox:(BOOL)focusOmnibox;
// Completes the process of dismissing the tab switcher, removing it from the
// screen and showing the appropriate BVC.
- (void)finishDismissingTabSwitcher;
// Sets |currentBVC| as the root view controller for the window. // Sets |currentBVC| as the root view controller for the window.
- (void)displayCurrentBVCAndFocusOmnibox:(BOOL)focusOmnibox; - (void)displayCurrentBVCAndFocusOmnibox:(BOOL)focusOmnibox;
......
...@@ -595,12 +595,78 @@ enum class EnterTabSwitcherSnapshotResult { ...@@ -595,12 +595,78 @@ enum class EnterTabSwitcherSnapshotResult {
- (void)tabSwitcher:(id<TabSwitcher>)tabSwitcher - (void)tabSwitcher:(id<TabSwitcher>)tabSwitcher
shouldFinishWithActiveModel:(TabModel*)tabModel shouldFinishWithActiveModel:(TabModel*)tabModel
focusOmnibox:(BOOL)focusOmnibox { focusOmnibox:(BOOL)focusOmnibox {
[self.mainController beginDismissingTabSwitcherWithCurrentModel:tabModel [self beginDismissingTabSwitcherWithCurrentModel:tabModel
focusOmnibox:focusOmnibox]; focusOmnibox:focusOmnibox];
} }
- (void)tabSwitcherDismissTransitionDidEnd:(id<TabSwitcher>)tabSwitcher { - (void)tabSwitcherDismissTransitionDidEnd:(id<TabSwitcher>)tabSwitcher {
[self.mainController finishDismissingTabSwitcher]; [self finishDismissingTabSwitcher];
}
- (void)beginDismissingTabSwitcherWithCurrentModel:(TabModel*)tabModel
focusOmnibox:(BOOL)focusOmnibox {
DCHECK(tabModel == self.mainInterface.tabModel ||
tabModel == self.incognitoInterface.tabModel);
self.mainController.dismissingTabSwitcher = YES;
ApplicationMode mode = (tabModel == self.mainInterface.tabModel)
? ApplicationMode::NORMAL
: ApplicationMode::INCOGNITO;
[self setCurrentInterfaceForMode:mode];
// The call to set currentBVC above does not actually display the BVC, because
// _dismissingTabSwitcher is YES. So: Force the BVC transition to start.
[self.mainController displayCurrentBVCAndFocusOmnibox:focusOmnibox];
}
- (void)finishDismissingTabSwitcher {
// In real world devices, it is possible to have an empty tab model at the
// finishing block of a BVC presentation animation. This can happen when the
// following occur: a) There is JS that closes the last incognito tab, b) that
// JS was paused while the user was in the tab switcher, c) the user enters
// the tab, activating the JS while the tab is being presented. Effectively,
// the BVC finishes the presentation animation, but there are no tabs to
// display. The only appropriate action is to dismiss the BVC and return the
// user to the tab switcher.
if (self.currentInterface.browser &&
self.currentInterface.browser->GetWebStateList() &&
self.currentInterface.browser->GetWebStateList()->count() == 0U) {
self.mainController.tabSwitcherIsActive = NO;
self.mainController.dismissingTabSwitcher = NO;
self.mainController.modeToDisplayOnTabSwitcherDismissal =
TabSwitcherDismissalMode::NONE;
self.mainController.NTPActionAfterTabSwitcherDismissal = NO_ACTION;
[self.mainController showTabSwitcher];
return;
}
// The tab switcher dismissal animation runs
// as part of the BVC presentation process. The BVC is presented before the
// animations begin, so it should be the current active VC at this point.
DCHECK_EQ(self.mainController.mainCoordinator.activeViewController,
self.mainController.currentBVC);
if (self.mainController.modeToDisplayOnTabSwitcherDismissal ==
TabSwitcherDismissalMode::NORMAL) {
[self setCurrentInterfaceForMode:ApplicationMode::NORMAL];
} else if (self.mainController.modeToDisplayOnTabSwitcherDismissal ==
TabSwitcherDismissalMode::INCOGNITO) {
[self setCurrentInterfaceForMode:ApplicationMode::INCOGNITO];
}
self.mainController.modeToDisplayOnTabSwitcherDismissal =
TabSwitcherDismissalMode::NONE;
ProceduralBlock action = [self.mainController
completionBlockForTriggeringAction:
self.mainController.NTPActionAfterTabSwitcherDismissal];
self.mainController.NTPActionAfterTabSwitcherDismissal = NO_ACTION;
if (action) {
action();
}
self.mainController.tabSwitcherIsActive = NO;
self.mainController.dismissingTabSwitcher = NO;
} }
#pragma mark - TabSwitching #pragma mark - TabSwitching
......
...@@ -38,6 +38,19 @@ ...@@ -38,6 +38,19 @@
completion:(ProceduralBlock)completion; completion:(ProceduralBlock)completion;
- (BOOL)shouldOpenNTPTabOnActivationOfTabModel:(TabModel*)tabModel; - (BOOL)shouldOpenNTPTabOnActivationOfTabModel:(TabModel*)tabModel;
// TabSwitcherDelegate helpers
// Begins the process of dismissing the tab switcher with the given current
// model, switching which BVC is suspended if necessary, but not updating the
// UI. The omnibox will be focused after the tab switcher dismissal is
// completed if |focusOmnibox| is YES.
- (void)beginDismissingTabSwitcherWithCurrentModel:(TabModel*)tabModel
focusOmnibox:(BOOL)focusOmnibox;
// Completes the process of dismissing the tab switcher, removing it from the
// screen and showing the appropriate BVC.
- (void)finishDismissingTabSwitcher;
@end @end
#endif // IOS_CHROME_BROWSER_UI_MAIN_SCENE_CONTROLLER_GUTS_H_ #endif // IOS_CHROME_BROWSER_UI_MAIN_SCENE_CONTROLLER_GUTS_H_
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