Commit 885d7086 authored by Mark Cogan's avatar Mark Cogan Committed by Commit Bot

[iOS] Wire up "done" control in TabGrid toolbar.

This CL adds a "tab presentation delegate" to the tab grid view
controller, and has the coordinator implement that delegate protocol.

For now, the path to actually trigger the presentation of the active
tab goes through the tab switcher delegate (that is, MainController).
Once there are fewer tab switchers to support, that can be cleaned up.

Bug: 804534
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I6d32e6c8145fe361ed4d6de51ced3d1178737a3d
Reviewed-on: https://chromium-review.googlesource.com/942344
Commit-Queue: Mark Cogan <marq@chromium.org>
Reviewed-by: default avataredchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#540286}
parent 7c231bfc
...@@ -18,7 +18,9 @@ ...@@ -18,7 +18,9 @@
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
@interface TabGridCoordinator () @interface TabGridCoordinator ()<TabPresentationDelegate>
// Superclass property specialized for the class that this coordinator uses.
@property(nonatomic, weak) TabGridViewController* mainViewController;
// Commad dispatcher used while this coordinator's view controller is active. // Commad dispatcher used while this coordinator's view controller is active.
// (for compatibility with the TabSwitcher protocol). // (for compatibility with the TabSwitcher protocol).
@property(nonatomic, strong) CommandDispatcher* dispatcher; @property(nonatomic, strong) CommandDispatcher* dispatcher;
...@@ -83,6 +85,7 @@ ...@@ -83,6 +85,7 @@
self.transitionHandler = [[TabGridTransitionHandler alloc] init]; self.transitionHandler = [[TabGridTransitionHandler alloc] init];
self.transitionHandler.provider = mainViewController; self.transitionHandler.provider = mainViewController;
mainViewController.transitioningDelegate = self.transitionHandler; mainViewController.transitioningDelegate = self.transitionHandler;
mainViewController.tabPresentationDelegate = self;
_mainViewController = mainViewController; _mainViewController = mainViewController;
self.window.rootViewController = self.mainViewController; self.window.rootViewController = self.mainViewController;
self.adaptor = [[TabGridAdaptor alloc] init]; self.adaptor = [[TabGridAdaptor alloc] init];
...@@ -170,6 +173,23 @@ ...@@ -170,6 +173,23 @@
completion:extendedCompletion]; completion:extendedCompletion];
} }
#pragma mark - TabPresentationDelegate
- (void)showActiveTab {
// Figure out which tab model is the active one. If the view controller is
// showing the incognito panel, and there's more than one incognito tab, then
// the incognito model is active. Otherwise the regular model is active.
TabModel* activeTabModel = self.regularTabModel;
if (self.mainViewController.currentPage == TabGridPageIncognitoTabs &&
self.incognitoTabModel.count > 0) {
activeTabModel = self.incognitoTabModel;
}
// Trigger the transition through the TabSwitcher delegate. This will in turn
// call back into this coordinator via the ViewControllerSwapping protocol.
[self.tabSwitcher.delegate tabSwitcher:self.tabSwitcher
shouldFinishWithActiveModel:activeTabModel];
}
#pragma mark - BrowserCommands #pragma mark - BrowserCommands
- (void)openNewTab:(OpenNewTabCommand*)command { - (void)openNewTab:(OpenNewTabCommand*)command {
......
...@@ -20,11 +20,21 @@ typedef NS_ENUM(NSUInteger, TabGridPage) { ...@@ -20,11 +20,21 @@ typedef NS_ENUM(NSUInteger, TabGridPage) {
TabGridPageRemoteTabs = 2, TabGridPageRemoteTabs = 2,
}; };
// Delegate protocol for an object that can handle presenting ("opening") tabs
// from the tab grid.
@protocol TabPresentationDelegate<NSObject>
// Show the active tab, presented on top of the tab grid.
- (void)showActiveTab;
@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
: UIViewController<TabGridTransitionStateProvider> : UIViewController<TabGridTransitionStateProvider>
// Delegate for this view controller to handle presenting tab UI.
@property(nonatomic, weak) id<TabPresentationDelegate> tabPresentationDelegate;
// 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> incognitoTabsConsumer; @property(nonatomic, readonly) id<GridConsumer> incognitoTabsConsumer;
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
@implementation TabGridViewController @implementation TabGridViewController
// Public properties. // Public properties.
@synthesize tabPresentationDelegate = _tabPresentationDelegate;
@synthesize regularTabsDelegate = _regularTabsDelegate; @synthesize regularTabsDelegate = _regularTabsDelegate;
@synthesize incognitoTabsDelegate = _incognitoTabsDelegate; @synthesize incognitoTabsDelegate = _incognitoTabsDelegate;
@synthesize regularTabsImageDataSource = _regularTabsImageDataSource; @synthesize regularTabsImageDataSource = _regularTabsImageDataSource;
...@@ -355,7 +356,7 @@ ...@@ -355,7 +356,7 @@
#pragma mark - Button actions #pragma mark - Button actions
- (void)doneButtonTapped:(id)sender { - (void)doneButtonTapped:(id)sender {
// TODO(crbug.com/804503) : Placeholder alerts. [self.tabPresentationDelegate showActiveTab];
} }
- (void)closeAllButtonTapped:(id)sender { - (void)closeAllButtonTapped:(id)sender {
......
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