Skip to content

Commit

Permalink
[ios] Add recent tabs to tab grid
Browse files Browse the repository at this point in the history
This CL replaces the green view controller with a real
remote/recent tabs view controller. The new view controller
is intentionally not connected to the model layer because
the remote/recent tabs view controller needs refactoring.
This CL simply displays the remote/recent tabs view controller.

Note: I want to comment on the nomenclature -- remote vs. recent.
While the class name is "RecentTabsTableViewController", it has
both recent tabs (on current device) and tabs from other devices.
The tab grid mocks show only remote tabs in this panel.
Also, the accessibility label reads "tabs from other devices" in
the tab grid. For now, I will refer to remote tabs in tab grid,
while using the RecentTabsTableViewController. This may change,
but I didn't want to go back and forth on naming for now.

Bug: 845192

Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Icb4cd8a25dbd172b70a86117cbdeeafc4d4418cf
Reviewed-on: https://chromium-review.googlesource.com/1063561
Reviewed-by: Sergio Collazos <sczs@chromium.org>
Reviewed-by: edchin <edchin@chromium.org>
Commit-Queue: edchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#560397}
  • Loading branch information
edx246 authored and Commit Bot committed May 21, 2018
1 parent ef82360 commit ba7282f
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,11 @@ - (void)viewDidLoad {
tapGesture.delegate = self;
[self.tableView addGestureRecognizer:tapGesture];

self.faviconLoader =
IOSChromeFaviconLoaderFactory::GetForBrowserState(self.browserState);
// TODO(crbug.com/845192) : Remove dependency on browserState.
if (self.browserState) {
self.faviconLoader =
IOSChromeFaviconLoaderFactory::GetForBrowserState(self.browserState);
}

// If the NavigationBar is not translucent, set
// |self.extendedLayoutIncludesOpaqueBars| to YES in order to avoid a top
Expand Down Expand Up @@ -817,7 +820,6 @@ - (void)showFullHistory {
ProceduralBlock openHistory = ^{
[weakSelf.dispatcher showHistory];
};
DCHECK(self.handsetCommandHandler);
[self.handsetCommandHandler dismissRecentTabsWithCompletion:openHistory];
}

Expand Down
3 changes: 3 additions & 0 deletions ios/chrome/browser/ui/tab_grid/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ source_set("tab_grid") {
"//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/coordinators:chrome_coordinators",
"//ios/chrome/browser/ui/main",
"//ios/chrome/browser/ui/recent_tabs",
"//ios/chrome/browser/ui/recent_tabs:recent_tabs_ui",
"//ios/chrome/browser/ui/tab_switcher",
"//ios/chrome/browser/web",
"//ios/chrome/browser/web_state_list",
Expand Down Expand Up @@ -70,6 +72,7 @@ source_set("tab_grid_ui") {
"//ios/chrome/app/strings",
"//ios/chrome/browser",
"//ios/chrome/browser/ui:ui_util",
"//ios/chrome/browser/ui/recent_tabs:recent_tabs_ui",
"//ios/chrome/browser/ui/tab_grid/transitions",
"//ios/chrome/browser/ui/util:constraints_ui",
"//ui/base",
Expand Down
22 changes: 21 additions & 1 deletion ios/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#import "ios/chrome/browser/ui/commands/command_dispatcher.h"
#import "ios/chrome/browser/ui/commands/open_new_tab_command.h"
#import "ios/chrome/browser/ui/main/bvc_container_view_controller.h"
#import "ios/chrome/browser/ui/recent_tabs/recent_tabs_mediator.h"
#import "ios/chrome/browser/ui/recent_tabs/recent_tabs_table_view_controller.h"
#import "ios/chrome/browser/ui/tab_grid/tab_grid_adaptor.h"
#import "ios/chrome/browser/ui/tab_grid/tab_grid_mediator.h"
#import "ios/chrome/browser/ui/tab_grid/tab_grid_paging.h"
Expand Down Expand Up @@ -37,6 +39,8 @@ @interface TabGridCoordinator ()<TabPresentationDelegate>
@property(nonatomic, strong) TabGridMediator* regularTabsMediator;
// Mediator for incognito Tabs.
@property(nonatomic, strong) TabGridMediator* incognitoTabsMediator;
// Mediator for remote Tabs.
@property(nonatomic, strong) RecentTabsMediator* remoteTabsMediator;
@end

@implementation TabGridCoordinator
Expand All @@ -53,6 +57,7 @@ @implementation TabGridCoordinator
@synthesize transitionHandler = _transitionHandler;
@synthesize regularTabsMediator = _regularTabsMediator;
@synthesize incognitoTabsMediator = _incognitoTabsMediator;
@synthesize remoteTabsMediator = _remoteTabsMediator;

- (instancetype)initWithWindow:(nullable UIWindow*)window
applicationCommandEndpoint:
Expand Down Expand Up @@ -120,7 +125,7 @@ - (void)start {
mainViewController.transitioningDelegate = self.transitionHandler;
mainViewController.tabPresentationDelegate = self;
_mainViewController = mainViewController;
self.window.rootViewController = self.mainViewController;

self.adaptor = [[TabGridAdaptor alloc] init];
self.adaptor.tabGridViewController = self.mainViewController;
self.adaptor.adaptedDispatcher =
Expand All @@ -139,15 +144,30 @@ - (void)start {
mainViewController.incognitoTabsDelegate = self.incognitoTabsMediator;
mainViewController.regularTabsImageDataSource = self.regularTabsMediator;
mainViewController.incognitoTabsImageDataSource = self.incognitoTabsMediator;

// TODO(crbug.com/845192) : Remove RecentTabsTableViewController dependency on
// ChromeBrowserState so that we don't need to expose the view controller.
mainViewController.remoteTabsViewController.browserState =
_regularTabModel.browserState;
self.remoteTabsMediator = [[RecentTabsMediator alloc] init];

// Once the mediators are set up, stop keeping pointers to the tab models used
// to initialize them.
_regularTabModel = nil;
_incognitoTabModel = nil;

self.window.rootViewController = self.mainViewController;
}

- (void)stop {
[self.dispatcher stopDispatchingForProtocol:@protocol(BrowserCommands)];
[self.dispatcher stopDispatchingForProtocol:@protocol(ApplicationCommands)];

// TODO(crbug.com/845192) : RecentTabsTableViewController behaves like a
// coordinator and that should be factored out.
[self.mainViewController.remoteTabsViewController dismissModals];
[self.remoteTabsMediator disconnect];
self.remoteTabsMediator = nil;
}

#pragma mark - ViewControllerSwapping
Expand Down
10 changes: 10 additions & 0 deletions ios/chrome/browser/ui/tab_grid/tab_grid_view_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@protocol GridConsumer;
@protocol GridCommands;
@protocol GridImageDataSource;
@protocol RecentTabsTableConsumer;
@class RecentTabsTableViewController;

// Delegate protocol for an object that can handle presenting ("opening") tabs
// from the tab grid.
Expand All @@ -32,6 +34,7 @@
// Consumers send updates from the model layer to the UI layer.
@property(nonatomic, readonly) id<GridConsumer> regularTabsConsumer;
@property(nonatomic, readonly) id<GridConsumer> incognitoTabsConsumer;
@property(nonatomic, readonly) id<RecentTabsTableConsumer> remoteTabsConsumer;

// Delegates send updates from the UI layer to the model layer.
@property(nonatomic, weak) id<GridCommands> regularTabsDelegate;
Expand All @@ -41,6 +44,13 @@
@property(nonatomic, weak) id<GridImageDataSource> regularTabsImageDataSource;
@property(nonatomic, weak) id<GridImageDataSource> incognitoTabsImageDataSource;

// The view controller for remote tabs.
// TODO(crbug.com/845192) : This was only exposed in the public interface so
// that TabGridViewController does not need to know about model objects. The
// model objects used in this view controller should be factored out.
@property(nonatomic, strong)
RecentTabsTableViewController* remoteTabsViewController;

@end

#endif // IOS_CHROME_BROWSER_UI_TAB_GRID_TAB_GRID_VIEW_CONTROLLER_H_
11 changes: 7 additions & 4 deletions ios/chrome/browser/ui/tab_grid/tab_grid_view_controller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#import "ios/chrome/browser/ui/tab_grid/tab_grid_view_controller.h"

#include "base/strings/sys_string_conversions.h"
#import "ios/chrome/browser/ui/recent_tabs/recent_tabs_table_view_controller.h"
#import "ios/chrome/browser/ui/rtl_geometry.h"
#import "ios/chrome/browser/ui/tab_grid/grid/grid_commands.h"
#import "ios/chrome/browser/ui/tab_grid/grid/grid_consumer.h"
Expand Down Expand Up @@ -58,7 +59,6 @@ @interface TabGridViewController ()<GridViewControllerDelegate,
// Child view controllers.
@property(nonatomic, strong) GridViewController* regularTabsViewController;
@property(nonatomic, strong) GridViewController* incognitoTabsViewController;
@property(nonatomic, strong) UIViewController* remoteTabsViewController;
// Other UI components.
@property(nonatomic, weak) UIScrollView* scrollView;
@property(nonatomic, weak) UIView* scrollContentView;
Expand Down Expand Up @@ -108,7 +108,7 @@ - (instancetype)init {
if (self = [super init]) {
_regularTabsViewController = [[GridViewController alloc] init];
_incognitoTabsViewController = [[GridViewController alloc] init];
_remoteTabsViewController = [[UIViewController alloc] init];
_remoteTabsViewController = [[RecentTabsTableViewController alloc] init];
}
return self;
}
Expand Down Expand Up @@ -167,6 +167,7 @@ - (void)viewWillLayoutSubviews {
}
self.incognitoTabsViewController.gridView.contentInset = contentInset;
self.regularTabsViewController.gridView.contentInset = contentInset;
self.remoteTabsViewController.tableView.contentInset = contentInset;
}

- (void)viewWillTransitionToSize:(CGSize)size
Expand Down Expand Up @@ -289,6 +290,10 @@ - (void)setIncognitoTabsImageDataSource:
_incognitoTabsImageDataSource = incognitoTabsImageDataSource;
}

- (id<RecentTabsTableConsumer>)remoteTabsConsumer {
return self.remoteTabsViewController;
}

#pragma mark - TabGridPaging

- (void)setCurrentPage:(TabGridPage)currentPage {
Expand Down Expand Up @@ -424,11 +429,9 @@ - (void)setupRegularTabsViewController {
// Adds the remote tabs view controller as a contained view controller, and
// sets constraints.
- (void)setupRemoteTabsViewController {
// TODO(crbug.com/804588) : Create remote tabs.
UIView* contentView = self.scrollContentView;
UIViewController* viewController = self.remoteTabsViewController;
viewController.view.translatesAutoresizingMaskIntoConstraints = NO;
viewController.view.backgroundColor = [UIColor greenColor];
[self addChildViewController:viewController];
[contentView addSubview:viewController.view];
[viewController didMoveToParentViewController:self];
Expand Down

0 comments on commit ba7282f

Please sign in to comment.