Commit bd7f4e96 authored by Robbie Gibson's avatar Robbie Gibson Committed by Chromium LUCI CQ

[iOS][Thumb Strip] Handle closing recent tabs correctly

When tapping Done on recent tabs, the tab grid shows a tab in the
activePage, without changing the actual tab grid. However, when the tab
grid is opened again, the tab grid still shows recent tabs. To fix this,
this CL has the tab grid scroll without animation to the active page
when the tab grid starts to appear.

This also handles opening the tab grid after "Open in new incognito
tab." The issue there was that before, the tab grid's active page was
being set by the SceneController in -showTabSwitcher. However, when
using the thumb strip, this method is not called. I swapped the data
flow around where the tab grid now requests the page from the
SceneController (via delegation) when it is about to open in the
thumb strip.

Fixed: 1155612
Change-Id: I791f7c0ca7fa7ada66241ab55411ac4daeb5c281
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2595051
Commit-Queue: Robbie Gibson <rkgibson@google.com>
Reviewed-by: default avataredchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#838664}
parent a807b7f2
...@@ -1582,6 +1582,10 @@ const char kMultiWindowOpenInNewWindowHistogram[] = ...@@ -1582,6 +1582,10 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
[self finishActivatingBrowserDismissingTabSwitcher:YES]; [self finishActivatingBrowserDismissingTabSwitcher:YES];
} }
- (TabGridPage)activePageForTabGrid:(TabGridCoordinator*)tabGrid {
return self.activePage;
}
// Begins the process of activating the given current model, switching which BVC // Begins the process of activating the given current model, switching which BVC
// is suspended if necessary. If |dismissTabSwitcher| is set, the tab switcher // is suspended if necessary. If |dismissTabSwitcher| is set, the tab switcher
// will also be dismissed. Note that this means that a browser can be activated // will also be dismissed. Note that this means that a browser can be activated
......
...@@ -60,7 +60,8 @@ ...@@ -60,7 +60,8 @@
RecentTabsContextMenuDelegate, RecentTabsContextMenuDelegate,
RecentTabsPresentationDelegate, RecentTabsPresentationDelegate,
TabGridMediatorDelegate, TabGridMediatorDelegate,
TabPresentationDelegate> { TabPresentationDelegate,
TabGridViewControllerDelegate> {
// Use an explicit ivar instead of synthesizing as the setter isn't using the // Use an explicit ivar instead of synthesizing as the setter isn't using the
// ivar. // ivar.
Browser* _incognitoBrowser; Browser* _incognitoBrowser;
...@@ -252,7 +253,6 @@ ...@@ -252,7 +253,6 @@
if (shouldCloseTabGrid) { if (shouldCloseTabGrid) {
[self.thumbStripCoordinator.panHandler setState:ViewRevealState::Hidden [self.thumbStripCoordinator.panHandler setState:ViewRevealState::Hidden
animated:YES]; animated:YES];
[self.delegate tabGridDismissTransitionDidEnd:self];
// Record when the tab switcher is dismissed. // Record when the tab switcher is dismissed.
base::RecordAction(base::UserMetricsAction("MobileTabGridExited")); base::RecordAction(base::UserMetricsAction("MobileTabGridExited"));
...@@ -334,6 +334,7 @@ ...@@ -334,6 +334,7 @@
baseViewController.reauthHandler = baseViewController.reauthHandler =
HandlerForProtocol(self.dispatcher, IncognitoReauthCommands); HandlerForProtocol(self.dispatcher, IncognitoReauthCommands);
baseViewController.tabPresentationDelegate = self; baseViewController.tabPresentationDelegate = self;
baseViewController.delegate = self;
_baseViewController = baseViewController; _baseViewController = baseViewController;
self.regularTabsMediator = [[TabGridMediator alloc] self.regularTabsMediator = [[TabGridMediator alloc]
...@@ -559,6 +560,18 @@ ...@@ -559,6 +560,18 @@
[self.actionSheetCoordinator start]; [self.actionSheetCoordinator start];
} }
#pragma mark - TabGridViewControllerDelegate
- (TabGridPage)activePageForTabGridViewController:
(TabGridViewController*)tabGridViewController {
return [self.delegate activePageForTabGrid:self];
}
- (void)tabGridViewControllerDidDismiss:
(TabGridViewController*)tabGridViewController {
[self.delegate tabGridDismissTransitionDidEnd:self];
}
#pragma mark - RecentTabsPresentationDelegate #pragma mark - RecentTabsPresentationDelegate
- (void)showHistoryFromRecentTabs { - (void)showHistoryFromRecentTabs {
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/tab_grid_paging.h"
class Browser; class Browser;
@class TabGridCoordinator; @class TabGridCoordinator;
...@@ -26,6 +28,9 @@ class Browser; ...@@ -26,6 +28,9 @@ class Browser;
// Informs the delegate that the tab switcher is done and should be dismissed. // Informs the delegate that the tab switcher is done and should be dismissed.
- (void)tabGridDismissTransitionDidEnd:(TabGridCoordinator*)tabGrid; - (void)tabGridDismissTransitionDidEnd:(TabGridCoordinator*)tabGrid;
// Asks the delegate for the page that should currently be active.
- (TabGridPage)activePageForTabGrid:(TabGridCoordinator*)tabGrid;
@end @end
#endif // IOS_CHROME_BROWSER_UI_TAB_SWITCHER_TAB_GRID_TAB_GRID_COORDINATOR_DELEGATE_H_ #endif // IOS_CHROME_BROWSER_UI_TAB_SWITCHER_TAB_GRID_TAB_GRID_COORDINATOR_DELEGATE_H_
...@@ -55,6 +55,10 @@ ...@@ -55,6 +55,10 @@
- (void)tabGridDismissTransitionDidEnd:(TabGridCoordinator*)tabGrid { - (void)tabGridDismissTransitionDidEnd:(TabGridCoordinator*)tabGrid {
self.didEndCalled = YES; self.didEndCalled = YES;
} }
- (TabGridPage)activePageForTabGrid:(TabGridCoordinator*)tabGrid {
return TabGridPageRegularTabs;
}
@end @end
namespace { namespace {
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
@protocol GridImageDataSource; @protocol GridImageDataSource;
@protocol RecentTabsConsumer; @protocol RecentTabsConsumer;
@class RecentTabsTableViewController; @class RecentTabsTableViewController;
@class TabGridViewController;
// Delegate protocol for an object that can handle presenting ("opening") tabs // Delegate protocol for an object that can handle presenting ("opening") tabs
// from the tab grid. // from the tab grid.
...@@ -36,6 +37,19 @@ ...@@ -36,6 +37,19 @@
closeTabGrid:(BOOL)closeTabGrid; closeTabGrid:(BOOL)closeTabGrid;
@end @end
@protocol TabGridViewControllerDelegate <NSObject>
// Asks the delegate for the page that should currently be active.
- (TabGridPage)activePageForTabGridViewController:
(TabGridViewController*)tabGridViewController;
// Notifies the delegate that the tab grid was dismissed via the
// ViewRevealingAnimatee.
- (void)tabGridViewControllerDidDismiss:
(TabGridViewController*)tabGridViewController;
@end
// View controller representing a tab switcher. The tab switcher has an // View controller representing a tab switcher. The tab switcher has an
// incognito tab grid, regular tab grid, and remote tabs. // incognito tab grid, regular tab grid, and remote tabs.
@interface TabGridViewController @interface TabGridViewController
...@@ -50,6 +64,8 @@ ...@@ -50,6 +64,8 @@
// Delegate for this view controller to handle presenting tab UI. // Delegate for this view controller to handle presenting tab UI.
@property(nonatomic, weak) id<TabPresentationDelegate> tabPresentationDelegate; @property(nonatomic, weak) id<TabPresentationDelegate> tabPresentationDelegate;
@property(nonatomic, weak) id<TabGridViewControllerDelegate> delegate;
// Consumers send updates from the model layer to the UI layer. // Consumers send updates from the model layer to the UI layer.
@property(nonatomic, readonly) id<GridConsumer> regularTabsConsumer; @property(nonatomic, readonly) id<GridConsumer> regularTabsConsumer;
@property(nonatomic, readonly) id<GridConsumer, IncognitoReauthConsumer> @property(nonatomic, readonly) id<GridConsumer, IncognitoReauthConsumer>
......
...@@ -501,10 +501,20 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) { ...@@ -501,10 +501,20 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
#pragma mark - ViewRevealingAnimatee #pragma mark - ViewRevealingAnimatee
- (void)willAnimateViewReveal:(ViewRevealState)currentViewRevealState { - (void)willAnimateViewReveal:(ViewRevealState)currentViewRevealState {
DCHECK_NE(TabGridPageRemoteTabs, self.currentPage);
self.scrollView.scrollEnabled = NO; self.scrollView.scrollEnabled = NO;
switch (currentViewRevealState) { switch (currentViewRevealState) {
case ViewRevealState::Hidden: { case ViewRevealState::Hidden: {
// If the tab grid is just showing up, make sure that the active page is
// current. This can happen when the user closes the tab grid using the
// done button on RecentTabs. The current page would stay RecentTabs, but
// the active page comes from the currently displayed BVC.
if (self.delegate) {
self.activePage =
[self.delegate activePageForTabGridViewController:self];
}
if (self.currentPage != self.activePage) {
[self scrollToPage:self.activePage animated:NO];
}
self.topToolbar.transform = CGAffineTransformMakeTranslation( self.topToolbar.transform = CGAffineTransformMakeTranslation(
0, [self hiddenTopToolbarYTranslation]); 0, [self hiddenTopToolbarYTranslation]);
GridViewController* regularViewController = GridViewController* regularViewController =
...@@ -580,9 +590,17 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) { ...@@ -580,9 +590,17 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
} }
- (void)didAnimateViewReveal:(ViewRevealState)viewRevealState { - (void)didAnimateViewReveal:(ViewRevealState)viewRevealState {
if (viewRevealState == ViewRevealState::Revealed) { switch (viewRevealState) {
self.scrollView.scrollEnabled = YES; case ViewRevealState::Hidden:
[self setInsetForRemoteTabs]; [self.delegate tabGridViewControllerDidDismiss:self];
break;
case ViewRevealState::Peeked:
// No-op.
break;
case ViewRevealState::Revealed:
self.scrollView.scrollEnabled = YES;
[self setInsetForRemoteTabs];
break;
} }
} }
......
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