Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ios/clean/chrome/browser/ui/tab_collection/tab_collection_view_controll er.h" | 5 #import "ios/clean/chrome/browser/ui/tab_collection/tab_collection_view_controll er.h" |
| 6 | 6 |
| 7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
| 8 #import "ios/clean/chrome/browser/ui/commands/tab_commands.h" | |
| 9 #import "ios/clean/chrome/browser/ui/tab_collection/tab_collection_data_source.h " | 8 #import "ios/clean/chrome/browser/ui/tab_collection/tab_collection_data_source.h " |
| 10 #import "ios/clean/chrome/browser/ui/tab_collection/tab_collection_tab_cell.h" | 9 #import "ios/clean/chrome/browser/ui/tab_collection/tab_collection_tab_cell.h" |
| 11 | 10 |
| 12 #if !defined(__has_feature) || !__has_feature(objc_arc) | 11 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 13 #error "This file requires ARC support." | 12 #error "This file requires ARC support." |
| 14 #endif | 13 #endif |
| 15 | 14 |
| 16 @interface TabCollectionViewController ()<UICollectionViewDataSource, | 15 @interface TabCollectionViewController ()<UICollectionViewDataSource, |
| 17 UICollectionViewDelegate, | 16 UICollectionViewDelegate, |
| 18 SessionCellDelegate> | 17 SessionCellDelegate> |
| 19 @property(nonatomic, readwrite) UICollectionView* tabs; | 18 @property(nonatomic, readwrite) UICollectionView* tabs; |
| 20 @end | 19 @end |
| 21 | 20 |
| 22 @implementation TabCollectionViewController | 21 @implementation TabCollectionViewController |
| 23 @synthesize tabs = _tabs; | 22 @synthesize tabs = _tabs; |
| 24 @synthesize dataSource = _dataSource; | 23 @synthesize dataSource = _dataSource; |
| 25 @synthesize tabCommandHandler = _tabCommandHandler; | |
| 26 | 24 |
| 27 #pragma mark - UIViewController | 25 #pragma mark - UIViewController |
| 28 | 26 |
| 29 - (void)viewDidLoad { | 27 - (void)viewDidLoad { |
| 30 [super viewDidLoad]; | 28 [super viewDidLoad]; |
| 31 UICollectionView* tabs = | 29 UICollectionView* tabs = |
| 32 [[UICollectionView alloc] initWithFrame:CGRectZero | 30 [[UICollectionView alloc] initWithFrame:CGRectZero |
| 33 collectionViewLayout:[self collectionViewLayout]]; | 31 collectionViewLayout:[self collectionViewLayout]]; |
| 34 tabs.translatesAutoresizingMaskIntoConstraints = NO; | 32 tabs.translatesAutoresizingMaskIntoConstraints = NO; |
| 35 tabs.backgroundColor = [UIColor blackColor]; | 33 tabs.backgroundColor = [UIColor blackColor]; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 55 | 53 |
| 56 #pragma mark - Required subclass override | 54 #pragma mark - Required subclass override |
| 57 | 55 |
| 58 - (UICollectionViewLayout*)collectionViewLayout { | 56 - (UICollectionViewLayout*)collectionViewLayout { |
| 59 [NSException | 57 [NSException |
| 60 raise:NSInternalInconsistencyException | 58 raise:NSInternalInconsistencyException |
| 61 format:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]; | 59 format:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]; |
| 62 return nil; | 60 return nil; |
| 63 } | 61 } |
| 64 | 62 |
| 63 - (void)showTabAtIndex:(int)index { | |
| 64 [NSException | |
|
marq (ping after 24h)
2017/03/30 08:46:18
We prefer not to raise ObjC exceptions (see https:
edchin
2017/03/30 18:15:51
Done.
| |
| 65 raise:NSInternalInconsistencyException | |
| 66 format:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]; | |
| 67 } | |
| 68 | |
| 69 - (void)closeTabAtIndex:(int)index { | |
| 70 [NSException | |
| 71 raise:NSInternalInconsistencyException | |
| 72 format:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]; | |
| 73 } | |
| 74 | |
| 65 #pragma mark - UICollectionViewDataSource methods | 75 #pragma mark - UICollectionViewDataSource methods |
| 66 | 76 |
| 67 - (NSInteger)numberOfSectionsInCollectionView: | 77 - (NSInteger)numberOfSectionsInCollectionView: |
| 68 (UICollectionView*)collectionView { | 78 (UICollectionView*)collectionView { |
| 69 return 1; | 79 return 1; |
| 70 } | 80 } |
| 71 | 81 |
| 72 - (NSInteger)collectionView:(UICollectionView*)collectionView | 82 - (NSInteger)collectionView:(UICollectionView*)collectionView |
| 73 numberOfItemsInSection:(NSInteger)section { | 83 numberOfItemsInSection:(NSInteger)section { |
| 74 return [self.dataSource numberOfTabs]; | 84 return [self.dataSource numberOfTabs]; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 104 | 114 |
| 105 - (TabSwitcherCache*)tabSwitcherCache { | 115 - (TabSwitcherCache*)tabSwitcherCache { |
| 106 // PLACEHOLDER: return image cache. | 116 // PLACEHOLDER: return image cache. |
| 107 return nil; | 117 return nil; |
| 108 } | 118 } |
| 109 | 119 |
| 110 - (void)cellPressed:(UICollectionViewCell*)cell { | 120 - (void)cellPressed:(UICollectionViewCell*)cell { |
| 111 NSInteger item = [[self.tabs indexPathForCell:cell] item]; | 121 NSInteger item = [[self.tabs indexPathForCell:cell] item]; |
| 112 DCHECK_LE(item, INT_MAX); | 122 DCHECK_LE(item, INT_MAX); |
| 113 int index = static_cast<int>(item); | 123 int index = static_cast<int>(item); |
| 114 [self.tabCommandHandler showTabAtIndex:index]; | 124 [self showTabAtIndex:index]; |
| 115 } | 125 } |
| 116 | 126 |
| 117 - (void)deleteButtonPressedForCell:(UICollectionViewCell*)cell { | 127 - (void)deleteButtonPressedForCell:(UICollectionViewCell*)cell { |
| 118 NSInteger item = [[self.tabs indexPathForCell:cell] item]; | 128 NSInteger item = [[self.tabs indexPathForCell:cell] item]; |
| 119 DCHECK_LE(item, INT_MAX); | 129 DCHECK_LE(item, INT_MAX); |
| 120 int index = static_cast<int>(item); | 130 int index = static_cast<int>(item); |
| 121 [self.tabCommandHandler closeTabAtIndex:index]; | 131 [self closeTabAtIndex:index]; |
| 122 } | 132 } |
| 123 | 133 |
| 124 #pragma mark - TabCollectionConsumer methods | 134 #pragma mark - TabCollectionConsumer methods |
| 125 | 135 |
| 126 - (void)insertItemAtIndex:(int)index { | 136 - (void)insertItemAtIndex:(int)index { |
| 127 [self.tabs insertItemsAtIndexPaths:@[ [NSIndexPath indexPathForItem:index | 137 [self.tabs insertItemsAtIndexPaths:@[ [NSIndexPath indexPathForItem:index |
| 128 inSection:0] ]]; | 138 inSection:0] ]]; |
| 129 } | 139 } |
| 130 | 140 |
| 131 - (void)deleteItemAtIndex:(int)index { | 141 - (void)deleteItemAtIndex:(int)index { |
| 132 [self.tabs deleteItemsAtIndexPaths:@[ [NSIndexPath indexPathForItem:index | 142 [self.tabs deleteItemsAtIndexPaths:@[ [NSIndexPath indexPathForItem:index |
| 133 inSection:0] ]]; | 143 inSection:0] ]]; |
| 134 } | 144 } |
| 135 | 145 |
| 136 - (void)reloadItemsAtIndexes:(NSIndexSet*)indexes { | 146 - (void)reloadItemsAtIndexes:(NSIndexSet*)indexes { |
| 137 NSMutableArray<NSIndexPath*>* indexPaths = [[NSMutableArray alloc] init]; | 147 NSMutableArray<NSIndexPath*>* indexPaths = [[NSMutableArray alloc] init]; |
| 138 [indexes enumerateIndexesUsingBlock:^(NSUInteger index, BOOL* _Nonnull stop) { | 148 [indexes enumerateIndexesUsingBlock:^(NSUInteger index, BOOL* _Nonnull stop) { |
| 139 [indexPaths addObject:[NSIndexPath indexPathForItem:index inSection:0]]; | 149 [indexPaths addObject:[NSIndexPath indexPathForItem:index inSection:0]]; |
| 140 }]; | 150 }]; |
| 141 [self.tabs reloadItemsAtIndexPaths:indexPaths]; | 151 [self.tabs reloadItemsAtIndexPaths:indexPaths]; |
| 142 } | 152 } |
| 143 | 153 |
| 144 @end | 154 @end |
| OLD | NEW |