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 @@
self.incognitoTabsMediator = [[TabGridMediator alloc]
initWithConsumer:mainViewController.incognitoTabsConsumer];
self.incognitoTabsMediator.tabModel = self.incognitoTabModel;
mainViewController.regularTabsDelegate = self.regularTabsMediator;
mainViewController.incognitoTabsDelegate = self.incognitoTabsMediator;
mainViewController.regularTabsImageDataSource = self.regularTabsMediator;
mainViewController.incognitoTabsImageDataSource = self.incognitoTabsMediator;
}
......
......@@ -10,8 +10,8 @@
#import "ios/chrome/browser/ui/tab_grid/tab_grid_transition_state_provider.h"
@protocol GridConsumer;
@protocol GridCommands;
@protocol GridImageDataSource;
@protocol GridViewControllerDelegate;
// Page enumerates the kinds of grouped tabs.
typedef NS_ENUM(NSUInteger, TabGridPage) {
......@@ -40,8 +40,8 @@ typedef NS_ENUM(NSUInteger, TabGridPage) {
@property(nonatomic, readonly) id<GridConsumer> incognitoTabsConsumer;
// Delegates send updates from the UI layer to the model layer.
@property(nonatomic, weak) id<GridViewControllerDelegate> regularTabsDelegate;
@property(nonatomic, weak) id<GridViewControllerDelegate> incognitoTabsDelegate;
@property(nonatomic, weak) id<GridCommands> regularTabsDelegate;
@property(nonatomic, weak) id<GridCommands> incognitoTabsDelegate;
// Data sources provide lazy access to heavy-weight resources.
@property(nonatomic, weak) id<GridImageDataSource> regularTabsImageDataSource;
......
......@@ -5,6 +5,7 @@
#import "ios/chrome/browser/ui/tab_grid/tab_grid_view_controller.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_image_data_source.h"
#import "ios/chrome/browser/ui/tab_grid/grid_view_controller.h"
......@@ -15,7 +16,22 @@
#error "This file requires ARC support."
#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.
@property(nonatomic, strong) GridViewController* regularTabsViewController;
@property(nonatomic, strong) GridViewController* incognitoTabsViewController;
......@@ -98,6 +114,16 @@
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
- (BOOL)selectedTabVisible {
......@@ -110,12 +136,6 @@
return self.regularTabsViewController;
}
- (void)setRegularTabsDelegate:
(id<GridViewControllerDelegate>)regularTabsDelegate {
self.regularTabsViewController.delegate = regularTabsDelegate;
_regularTabsDelegate = regularTabsDelegate;
}
- (void)setRegularTabsImageDataSource:
(id<GridImageDataSource>)regularTabsImageDataSource {
self.regularTabsViewController.imageDataSource = regularTabsImageDataSource;
......@@ -126,12 +146,6 @@
return self.incognitoTabsViewController;
}
- (void)setIncognitoTabsDelegate:
(id<GridViewControllerDelegate>)incognitoTabsDelegate {
self.incognitoTabsViewController.delegate = incognitoTabsDelegate;
_incognitoTabsDelegate = incognitoTabsDelegate;
}
- (void)setIncognitoTabsImageDataSource:
(id<GridImageDataSource>)incognitoTabsImageDataSource {
self.incognitoTabsViewController.imageDataSource =
......@@ -147,6 +161,7 @@
scrollView.translatesAutoresizingMaskIntoConstraints = NO;
scrollView.scrollEnabled = YES;
scrollView.pagingEnabled = YES;
scrollView.delegate = self;
if (@available(iOS 11, *)) {
// Ensures that scroll view does not add additional margins based on safe
// areas.
......@@ -186,6 +201,7 @@
[contentView addSubview:viewController.view];
[viewController didMoveToParentViewController:self];
viewController.theme = GridThemeDark;
viewController.delegate = self;
if (@available(iOS 11, *)) {
// Adjustments are made in |-viewWillLayoutSubviews|. Automatic adjustments
// do not work well with the scrollview.
......@@ -215,6 +231,7 @@
[contentView addSubview:viewController.view];
[viewController didMoveToParentViewController:self];
viewController.theme = GridThemeLight;
viewController.delegate = self;
if (@available(iOS 11, *)) {
// Adjustments are made in |-viewWillLayoutSubviews|. Automatic adjustments
// do not work well with the scrollview.
......@@ -353,6 +370,27 @@
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
- (void)doneButtonTapped:(id)sender {
......@@ -360,11 +398,23 @@
}
- (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 {
// TODO(crbug.com/804503) : Placeholder alerts.
[self presentViewController:NotImplementedAlert()
animated:YES
completion:nil];
}
@end
......@@ -4,6 +4,7 @@
#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_item.h"
#import "ios/chrome/browser/ui/tab_grid/tab_grid_view_controller.h"
......@@ -24,14 +25,14 @@
@synthesize alerter = _alerter;
- (void)start {
self.alerter = [[ProtocolAlerter alloc]
initWithProtocols:@[ @protocol(GridViewControllerDelegate) ]];
self.alerter =
[[ProtocolAlerter alloc] initWithProtocols:@[ @protocol(GridCommands) ]];
self.viewController = [[TabGridViewController alloc] init];
self.alerter.baseViewController = self.viewController;
self.viewController.incognitoTabsDelegate =
static_cast<id<GridViewControllerDelegate>>(self.alerter);
static_cast<id<GridCommands>>(self.alerter);
self.viewController.regularTabsDelegate =
static_cast<id<GridViewControllerDelegate>>(self.alerter);
static_cast<id<GridCommands>>(self.alerter);
self.viewController.title = @"Full TabGrid UI";
self.baseViewController.delegate = self;
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