Commit 4ba95566 authored by edchin's avatar edchin Committed by Commit Bot

[ios] Wire up TabGridMediator

Bug: 804528
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I84bee4638790a586b741edf67fe2cb781766a208
Reviewed-on: https://chromium-review.googlesource.com/944049
Commit-Queue: edchin <edchin@chromium.org>
Reviewed-by: default avataredchin <edchin@chromium.org>
Reviewed-by: default avatarKurt Horimoto <kkhorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#540359}
parent 28322d7a
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#import "ios/chrome/browser/ui/tab_grid/grid_view_controller.h" #import "ios/chrome/browser/ui/tab_grid/grid_view_controller.h"
#import "base/ios/block_types.h"
#import "base/mac/foundation_util.h" #import "base/mac/foundation_util.h"
#import "base/numerics/safe_conversions.h" #import "base/numerics/safe_conversions.h"
#import "ios/chrome/browser/ui/tab_grid/grid_cell.h" #import "ios/chrome/browser/ui/tab_grid/grid_cell.h"
...@@ -152,30 +153,46 @@ NSIndexPath* CreateIndexPath(NSInteger index) { ...@@ -152,30 +153,46 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
- (void)insertItem:(GridItem*)item - (void)insertItem:(GridItem*)item
atIndex:(NSUInteger)index atIndex:(NSUInteger)index
selectedIndex:(NSUInteger)selectedIndex { selectedIndex:(NSUInteger)selectedIndex {
[self.items insertObject:item atIndex:index]; ProceduralBlock performDataSourceUpdates = ^{
self.selectedIndex = selectedIndex; [self.items insertObject:item atIndex:index];
if (![self isViewVisible]) self.selectedIndex = selectedIndex;
};
if (![self isViewVisible]) {
performDataSourceUpdates();
return; return;
[self.collectionView insertItemsAtIndexPaths:@[ CreateIndexPath(index) ]]; }
[self.collectionView ProceduralBlock performAllUpdates = ^{
selectItemAtIndexPath:CreateIndexPath(selectedIndex) performDataSourceUpdates();
animated:YES [self.collectionView insertItemsAtIndexPaths:@[ CreateIndexPath(index) ]];
scrollPosition:UICollectionViewScrollPositionNone]; [self.collectionView
selectItemAtIndexPath:CreateIndexPath(selectedIndex)
animated:YES
scrollPosition:UICollectionViewScrollPositionNone];
};
[self.collectionView performBatchUpdates:performAllUpdates completion:nil];
} }
- (void)removeItemAtIndex:(NSUInteger)index - (void)removeItemAtIndex:(NSUInteger)index
selectedIndex:(NSUInteger)selectedIndex { selectedIndex:(NSUInteger)selectedIndex {
[self.items removeObjectAtIndex:index]; ProceduralBlock performDataSourceUpdates = ^{
self.selectedIndex = selectedIndex; [self.items removeObjectAtIndex:index];
if (![self isViewVisible]) self.selectedIndex = selectedIndex;
};
if (![self isViewVisible]) {
performDataSourceUpdates();
return; return;
[self.collectionView deleteItemsAtIndexPaths:@[ CreateIndexPath(index) ]]; }
if (self.items.count == 0) ProceduralBlock performAllUpdates = ^{
return; performDataSourceUpdates();
[self.collectionView [self.collectionView deleteItemsAtIndexPaths:@[ CreateIndexPath(index) ]];
selectItemAtIndexPath:CreateIndexPath(selectedIndex) if (self.items.count > 0) {
animated:YES [self.collectionView
scrollPosition:UICollectionViewScrollPositionNone]; selectItemAtIndexPath:CreateIndexPath(selectedIndex)
animated:YES
scrollPosition:UICollectionViewScrollPositionNone];
}
};
[self.collectionView performBatchUpdates:performAllUpdates completion:nil];
} }
- (void)selectItemAtIndex:(NSUInteger)selectedIndex { - (void)selectItemAtIndex:(NSUInteger)selectedIndex {
...@@ -198,14 +215,26 @@ NSIndexPath* CreateIndexPath(NSInteger index) { ...@@ -198,14 +215,26 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
- (void)moveItemFromIndex:(NSUInteger)fromIndex - (void)moveItemFromIndex:(NSUInteger)fromIndex
toIndex:(NSUInteger)toIndex toIndex:(NSUInteger)toIndex
selectedIndex:(NSUInteger)selectedIndex { selectedIndex:(NSUInteger)selectedIndex {
GridItem* item = self.items[fromIndex]; ProceduralBlock performDataSourceUpdates = ^{
[self.items removeObjectAtIndex:fromIndex]; GridItem* item = self.items[fromIndex];
[self.items insertObject:item atIndex:toIndex]; [self.items removeObjectAtIndex:fromIndex];
self.selectedIndex = selectedIndex; [self.items insertObject:item atIndex:toIndex];
if (![self isViewVisible]) self.selectedIndex = selectedIndex;
};
if (![self isViewVisible]) {
performDataSourceUpdates();
return; return;
[self.collectionView moveItemAtIndexPath:CreateIndexPath(fromIndex) }
toIndexPath:CreateIndexPath(toIndex)]; ProceduralBlock performAllUpdates = ^{
performDataSourceUpdates();
[self.collectionView moveItemAtIndexPath:CreateIndexPath(fromIndex)
toIndexPath:CreateIndexPath(toIndex)];
[self.collectionView
selectItemAtIndexPath:CreateIndexPath(selectedIndex)
animated:YES
scrollPosition:UICollectionViewScrollPositionNone];
};
[self.collectionView performBatchUpdates:performAllUpdates completion:nil];
} }
#pragma mark - Private #pragma mark - Private
......
...@@ -93,6 +93,13 @@ ...@@ -93,6 +93,13 @@
self.adaptor.adaptedDispatcher = self.adaptor.adaptedDispatcher =
static_cast<id<ApplicationCommands, BrowserCommands, OmniboxFocuser, static_cast<id<ApplicationCommands, BrowserCommands, OmniboxFocuser,
ToolbarCommands>>(self.dispatcher); ToolbarCommands>>(self.dispatcher);
self.regularTabsMediator = [[TabGridMediator alloc]
initWithConsumer:mainViewController.regularTabsConsumer];
self.regularTabsMediator.tabModel = self.regularTabModel;
self.incognitoTabsMediator = [[TabGridMediator alloc]
initWithConsumer:mainViewController.incognitoTabsConsumer];
self.incognitoTabsMediator.tabModel = self.incognitoTabModel;
} }
- (void)stop { - (void)stop {
......
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