Commit 25865cf6 authored by edchin's avatar edchin Committed by Commit Bot

[ios] Wire up user actions from Grid and TabGrid

Bug: 804551, 804503, 804535
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: Idc8b33f73ad9f85cdadd30c5da3ad5978c19a4ba
Reviewed-on: https://chromium-review.googlesource.com/947581
Commit-Queue: edchin <edchin@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Reviewed-by: default avataredchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#540847}
parent 9c72d479
...@@ -100,7 +100,8 @@ ...@@ -100,7 +100,8 @@
self.incognitoTabsMediator = [[TabGridMediator alloc] self.incognitoTabsMediator = [[TabGridMediator alloc]
initWithConsumer:mainViewController.incognitoTabsConsumer]; initWithConsumer:mainViewController.incognitoTabsConsumer];
self.incognitoTabsMediator.tabModel = self.incognitoTabModel; self.incognitoTabsMediator.tabModel = self.incognitoTabModel;
mainViewController.regularTabsDelegate = self.regularTabsMediator;
mainViewController.incognitoTabsDelegate = self.incognitoTabsMediator;
mainViewController.regularTabsImageDataSource = self.regularTabsMediator; mainViewController.regularTabsImageDataSource = self.regularTabsMediator;
mainViewController.incognitoTabsImageDataSource = self.incognitoTabsMediator; mainViewController.incognitoTabsImageDataSource = self.incognitoTabsMediator;
} }
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
#import "ios/chrome/browser/ui/tab_grid/tab_grid_transition_state_provider.h" #import "ios/chrome/browser/ui/tab_grid/tab_grid_transition_state_provider.h"
@protocol GridConsumer; @protocol GridConsumer;
@protocol GridCommands;
@protocol GridImageDataSource; @protocol GridImageDataSource;
@protocol GridViewControllerDelegate;
// Page enumerates the kinds of grouped tabs. // Page enumerates the kinds of grouped tabs.
typedef NS_ENUM(NSUInteger, TabGridPage) { typedef NS_ENUM(NSUInteger, TabGridPage) {
...@@ -40,8 +40,8 @@ typedef NS_ENUM(NSUInteger, TabGridPage) { ...@@ -40,8 +40,8 @@ typedef NS_ENUM(NSUInteger, TabGridPage) {
@property(nonatomic, readonly) id<GridConsumer> incognitoTabsConsumer; @property(nonatomic, readonly) id<GridConsumer> incognitoTabsConsumer;
// Delegates send updates from the UI layer to the model layer. // Delegates send updates from the UI layer to the model layer.
@property(nonatomic, weak) id<GridViewControllerDelegate> regularTabsDelegate; @property(nonatomic, weak) id<GridCommands> regularTabsDelegate;
@property(nonatomic, weak) id<GridViewControllerDelegate> incognitoTabsDelegate; @property(nonatomic, weak) id<GridCommands> incognitoTabsDelegate;
// Data sources provide lazy access to heavy-weight resources. // Data sources provide lazy access to heavy-weight resources.
@property(nonatomic, weak) id<GridImageDataSource> regularTabsImageDataSource; @property(nonatomic, weak) id<GridImageDataSource> regularTabsImageDataSource;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#import "ios/chrome/browser/ui/tab_grid/tab_grid_view_controller.h" #import "ios/chrome/browser/ui/tab_grid/tab_grid_view_controller.h"
#import "base/logging.h" #import "base/logging.h"
#import "ios/chrome/browser/ui/tab_grid/grid_commands.h"
#import "ios/chrome/browser/ui/tab_grid/grid_consumer.h" #import "ios/chrome/browser/ui/tab_grid/grid_consumer.h"
#import "ios/chrome/browser/ui/tab_grid/grid_image_data_source.h" #import "ios/chrome/browser/ui/tab_grid/grid_image_data_source.h"
#import "ios/chrome/browser/ui/tab_grid/grid_view_controller.h" #import "ios/chrome/browser/ui/tab_grid/grid_view_controller.h"
...@@ -15,7 +16,22 @@ ...@@ -15,7 +16,22 @@
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
@interface TabGridViewController () namespace {
// Temporary alert used while building this feature.
UIAlertController* NotImplementedAlert() {
UIAlertController* alert =
[UIAlertController alertControllerWithTitle:@"Not implemented"
message:nil
preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"OK"
style:UIAlertActionStyleCancel
handler:nil]];
return alert;
}
} // namespace
@interface TabGridViewController ()<GridViewControllerDelegate,
UIScrollViewDelegate>
// Child view controllers. // Child view controllers.
@property(nonatomic, strong) GridViewController* regularTabsViewController; @property(nonatomic, strong) GridViewController* regularTabsViewController;
@property(nonatomic, strong) GridViewController* incognitoTabsViewController; @property(nonatomic, strong) GridViewController* incognitoTabsViewController;
...@@ -98,6 +114,16 @@ ...@@ -98,6 +114,16 @@
return UIStatusBarStyleLightContent; return UIStatusBarStyleLightContent;
} }
#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidEndDecelerating:(UIScrollView*)scrollView {
// Bookkeeping for the current page.
CGFloat pageWidth = scrollView.frame.size.width;
float fractionalPage = scrollView.contentOffset.x / pageWidth;
NSUInteger page = lround(fractionalPage);
self.currentPage = static_cast<TabGridPage>(page);
}
#pragma mark - TabGridTransitionStateProvider properties #pragma mark - TabGridTransitionStateProvider properties
- (BOOL)selectedTabVisible { - (BOOL)selectedTabVisible {
...@@ -110,12 +136,6 @@ ...@@ -110,12 +136,6 @@
return self.regularTabsViewController; return self.regularTabsViewController;
} }
- (void)setRegularTabsDelegate:
(id<GridViewControllerDelegate>)regularTabsDelegate {
self.regularTabsViewController.delegate = regularTabsDelegate;
_regularTabsDelegate = regularTabsDelegate;
}
- (void)setRegularTabsImageDataSource: - (void)setRegularTabsImageDataSource:
(id<GridImageDataSource>)regularTabsImageDataSource { (id<GridImageDataSource>)regularTabsImageDataSource {
self.regularTabsViewController.imageDataSource = regularTabsImageDataSource; self.regularTabsViewController.imageDataSource = regularTabsImageDataSource;
...@@ -126,12 +146,6 @@ ...@@ -126,12 +146,6 @@
return self.incognitoTabsViewController; return self.incognitoTabsViewController;
} }
- (void)setIncognitoTabsDelegate:
(id<GridViewControllerDelegate>)incognitoTabsDelegate {
self.incognitoTabsViewController.delegate = incognitoTabsDelegate;
_incognitoTabsDelegate = incognitoTabsDelegate;
}
- (void)setIncognitoTabsImageDataSource: - (void)setIncognitoTabsImageDataSource:
(id<GridImageDataSource>)incognitoTabsImageDataSource { (id<GridImageDataSource>)incognitoTabsImageDataSource {
self.incognitoTabsViewController.imageDataSource = self.incognitoTabsViewController.imageDataSource =
...@@ -147,6 +161,7 @@ ...@@ -147,6 +161,7 @@
scrollView.translatesAutoresizingMaskIntoConstraints = NO; scrollView.translatesAutoresizingMaskIntoConstraints = NO;
scrollView.scrollEnabled = YES; scrollView.scrollEnabled = YES;
scrollView.pagingEnabled = YES; scrollView.pagingEnabled = YES;
scrollView.delegate = self;
if (@available(iOS 11, *)) { if (@available(iOS 11, *)) {
// Ensures that scroll view does not add additional margins based on safe // Ensures that scroll view does not add additional margins based on safe
// areas. // areas.
...@@ -186,6 +201,7 @@ ...@@ -186,6 +201,7 @@
[contentView addSubview:viewController.view]; [contentView addSubview:viewController.view];
[viewController didMoveToParentViewController:self]; [viewController didMoveToParentViewController:self];
viewController.theme = GridThemeDark; viewController.theme = GridThemeDark;
viewController.delegate = self;
if (@available(iOS 11, *)) { if (@available(iOS 11, *)) {
// Adjustments are made in |-viewWillLayoutSubviews|. Automatic adjustments // Adjustments are made in |-viewWillLayoutSubviews|. Automatic adjustments
// do not work well with the scrollview. // do not work well with the scrollview.
...@@ -215,6 +231,7 @@ ...@@ -215,6 +231,7 @@
[contentView addSubview:viewController.view]; [contentView addSubview:viewController.view];
[viewController didMoveToParentViewController:self]; [viewController didMoveToParentViewController:self];
viewController.theme = GridThemeLight; viewController.theme = GridThemeLight;
viewController.delegate = self;
if (@available(iOS 11, *)) { if (@available(iOS 11, *)) {
// Adjustments are made in |-viewWillLayoutSubviews|. Automatic adjustments // Adjustments are made in |-viewWillLayoutSubviews|. Automatic adjustments
// do not work well with the scrollview. // do not work well with the scrollview.
...@@ -353,6 +370,27 @@ ...@@ -353,6 +370,27 @@
forControlEvents:UIControlEventTouchUpInside]; forControlEvents:UIControlEventTouchUpInside];
} }
#pragma mark - GridViewControllerDelegate
- (void)gridViewController:(GridViewController*)gridViewController
didSelectItemAtIndex:(NSUInteger)index {
if (gridViewController == self.regularTabsViewController) {
[self.regularTabsDelegate selectItemAtIndex:index];
} else if (gridViewController == self.incognitoTabsViewController) {
[self.incognitoTabsDelegate selectItemAtIndex:index];
}
[self.tabPresentationDelegate showActiveTab];
}
- (void)gridViewController:(GridViewController*)gridViewController
didCloseItemAtIndex:(NSUInteger)index {
if (gridViewController == self.regularTabsViewController) {
[self.regularTabsDelegate closeItemAtIndex:index];
} else if (gridViewController == self.incognitoTabsViewController) {
[self.incognitoTabsDelegate closeItemAtIndex:index];
}
}
#pragma mark - Button actions #pragma mark - Button actions
- (void)doneButtonTapped:(id)sender { - (void)doneButtonTapped:(id)sender {
...@@ -360,11 +398,23 @@ ...@@ -360,11 +398,23 @@
} }
- (void)closeAllButtonTapped:(id)sender { - (void)closeAllButtonTapped:(id)sender {
// TODO(crbug.com/804503) : Placeholder alerts. switch (self.currentPage) {
case TabGridPageIncognitoTabs:
[self.incognitoTabsDelegate closeAllItems];
break;
case TabGridPageRegularTabs:
[self.regularTabsDelegate closeAllItems];
break;
default:
NOTREACHED() << "Invalid TabGridPage when Close All button was tapped.";
break;
}
} }
- (void)newTabButtonTapped:(id)sender { - (void)newTabButtonTapped:(id)sender {
// TODO(crbug.com/804503) : Placeholder alerts. [self presentViewController:NotImplementedAlert()
animated:YES
completion:nil];
} }
@end @end
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#import "ios/showcase/tab_grid/sc_tab_grid_coordinator.h" #import "ios/showcase/tab_grid/sc_tab_grid_coordinator.h"
#import "ios/chrome/browser/ui/tab_grid/grid_commands.h"
#import "ios/chrome/browser/ui/tab_grid/grid_consumer.h" #import "ios/chrome/browser/ui/tab_grid/grid_consumer.h"
#import "ios/chrome/browser/ui/tab_grid/grid_item.h" #import "ios/chrome/browser/ui/tab_grid/grid_item.h"
#import "ios/chrome/browser/ui/tab_grid/tab_grid_view_controller.h" #import "ios/chrome/browser/ui/tab_grid/tab_grid_view_controller.h"
...@@ -24,14 +25,14 @@ ...@@ -24,14 +25,14 @@
@synthesize alerter = _alerter; @synthesize alerter = _alerter;
- (void)start { - (void)start {
self.alerter = [[ProtocolAlerter alloc] self.alerter =
initWithProtocols:@[ @protocol(GridViewControllerDelegate) ]]; [[ProtocolAlerter alloc] initWithProtocols:@[ @protocol(GridCommands) ]];
self.viewController = [[TabGridViewController alloc] init]; self.viewController = [[TabGridViewController alloc] init];
self.alerter.baseViewController = self.viewController; self.alerter.baseViewController = self.viewController;
self.viewController.incognitoTabsDelegate = self.viewController.incognitoTabsDelegate =
static_cast<id<GridViewControllerDelegate>>(self.alerter); static_cast<id<GridCommands>>(self.alerter);
self.viewController.regularTabsDelegate = self.viewController.regularTabsDelegate =
static_cast<id<GridViewControllerDelegate>>(self.alerter); static_cast<id<GridCommands>>(self.alerter);
self.viewController.title = @"Full TabGrid UI"; self.viewController.title = @"Full TabGrid UI";
self.baseViewController.delegate = self; self.baseViewController.delegate = self;
self.baseViewController.hidesBarsOnSwipe = YES; self.baseViewController.hidesBarsOnSwipe = YES;
......
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