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/logging.h" |
7 #include "base/mac/foundation_util.h" | 8 #include "base/mac/foundation_util.h" |
8 #import "ios/clean/chrome/browser/ui/commands/tab_commands.h" | 9 #include "base/strings/sys_string_conversions.h" |
9 #import "ios/clean/chrome/browser/ui/tab_collection/tab_collection_data_source.h
" | 10 #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" | 11 #import "ios/clean/chrome/browser/ui/tab_collection/tab_collection_tab_cell.h" |
11 | 12 |
12 #if !defined(__has_feature) || !__has_feature(objc_arc) | 13 #if !defined(__has_feature) || !__has_feature(objc_arc) |
13 #error "This file requires ARC support." | 14 #error "This file requires ARC support." |
14 #endif | 15 #endif |
15 | 16 |
16 @interface TabCollectionViewController ()<UICollectionViewDataSource, | 17 @interface TabCollectionViewController ()<UICollectionViewDataSource, |
17 UICollectionViewDelegate, | 18 UICollectionViewDelegate, |
18 SessionCellDelegate> | 19 SessionCellDelegate> |
19 @property(nonatomic, readwrite) UICollectionView* tabs; | 20 @property(nonatomic, readwrite) UICollectionView* tabs; |
20 @end | 21 @end |
21 | 22 |
22 @implementation TabCollectionViewController | 23 @implementation TabCollectionViewController |
23 @synthesize tabs = _tabs; | 24 @synthesize tabs = _tabs; |
24 @synthesize dataSource = _dataSource; | 25 @synthesize dataSource = _dataSource; |
25 @synthesize tabCommandHandler = _tabCommandHandler; | |
26 | 26 |
27 #pragma mark - UIViewController | 27 #pragma mark - UIViewController |
28 | 28 |
29 - (void)viewDidLoad { | 29 - (void)viewDidLoad { |
30 [super viewDidLoad]; | 30 [super viewDidLoad]; |
31 UICollectionView* tabs = | 31 UICollectionView* tabs = |
32 [[UICollectionView alloc] initWithFrame:CGRectZero | 32 [[UICollectionView alloc] initWithFrame:CGRectZero |
33 collectionViewLayout:[self collectionViewLayout]]; | 33 collectionViewLayout:[self collectionViewLayout]]; |
34 tabs.translatesAutoresizingMaskIntoConstraints = NO; | 34 tabs.translatesAutoresizingMaskIntoConstraints = NO; |
35 tabs.backgroundColor = [UIColor blackColor]; | 35 tabs.backgroundColor = [UIColor blackColor]; |
(...skipping 13 matching lines...) Expand all Loading... |
49 ]]; | 49 ]]; |
50 } | 50 } |
51 | 51 |
52 - (UIStatusBarStyle)preferredStatusBarStyle { | 52 - (UIStatusBarStyle)preferredStatusBarStyle { |
53 return UIStatusBarStyleLightContent; | 53 return UIStatusBarStyleLightContent; |
54 } | 54 } |
55 | 55 |
56 #pragma mark - Required subclass override | 56 #pragma mark - Required subclass override |
57 | 57 |
58 - (UICollectionViewLayout*)collectionViewLayout { | 58 - (UICollectionViewLayout*)collectionViewLayout { |
59 [NSException | 59 NOTREACHED() << "You must override " |
60 raise:NSInternalInconsistencyException | 60 << base::SysNSStringToUTF8(NSStringFromSelector(_cmd)) |
61 format:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]; | 61 << " in a subclass."; |
62 return nil; | 62 return nil; |
63 } | 63 } |
64 | 64 |
| 65 - (void)showTabAtIndex:(int)index { |
| 66 NOTREACHED() << "You must override " |
| 67 << base::SysNSStringToUTF8(NSStringFromSelector(_cmd)) |
| 68 << " in a subclass."; |
| 69 } |
| 70 |
| 71 - (void)closeTabAtIndex:(int)index { |
| 72 NOTREACHED() << "You must override " |
| 73 << base::SysNSStringToUTF8(NSStringFromSelector(_cmd)) |
| 74 << " in a subclass."; |
| 75 } |
| 76 |
65 #pragma mark - UICollectionViewDataSource methods | 77 #pragma mark - UICollectionViewDataSource methods |
66 | 78 |
67 - (NSInteger)numberOfSectionsInCollectionView: | 79 - (NSInteger)numberOfSectionsInCollectionView: |
68 (UICollectionView*)collectionView { | 80 (UICollectionView*)collectionView { |
69 return 1; | 81 return 1; |
70 } | 82 } |
71 | 83 |
72 - (NSInteger)collectionView:(UICollectionView*)collectionView | 84 - (NSInteger)collectionView:(UICollectionView*)collectionView |
73 numberOfItemsInSection:(NSInteger)section { | 85 numberOfItemsInSection:(NSInteger)section { |
74 return [self.dataSource numberOfTabs]; | 86 return [self.dataSource numberOfTabs]; |
(...skipping 29 matching lines...) Expand all Loading... |
104 | 116 |
105 - (TabSwitcherCache*)tabSwitcherCache { | 117 - (TabSwitcherCache*)tabSwitcherCache { |
106 // PLACEHOLDER: return image cache. | 118 // PLACEHOLDER: return image cache. |
107 return nil; | 119 return nil; |
108 } | 120 } |
109 | 121 |
110 - (void)cellPressed:(UICollectionViewCell*)cell { | 122 - (void)cellPressed:(UICollectionViewCell*)cell { |
111 NSInteger item = [[self.tabs indexPathForCell:cell] item]; | 123 NSInteger item = [[self.tabs indexPathForCell:cell] item]; |
112 DCHECK_LE(item, INT_MAX); | 124 DCHECK_LE(item, INT_MAX); |
113 int index = static_cast<int>(item); | 125 int index = static_cast<int>(item); |
114 [self.tabCommandHandler showTabAtIndex:index]; | 126 [self showTabAtIndex:index]; |
115 } | 127 } |
116 | 128 |
117 - (void)deleteButtonPressedForCell:(UICollectionViewCell*)cell { | 129 - (void)deleteButtonPressedForCell:(UICollectionViewCell*)cell { |
118 NSInteger item = [[self.tabs indexPathForCell:cell] item]; | 130 NSInteger item = [[self.tabs indexPathForCell:cell] item]; |
119 DCHECK_LE(item, INT_MAX); | 131 DCHECK_LE(item, INT_MAX); |
120 int index = static_cast<int>(item); | 132 int index = static_cast<int>(item); |
121 [self.tabCommandHandler closeTabAtIndex:index]; | 133 [self closeTabAtIndex:index]; |
122 } | 134 } |
123 | 135 |
124 #pragma mark - TabCollectionConsumer methods | 136 #pragma mark - TabCollectionConsumer methods |
125 | 137 |
126 - (void)insertItemAtIndex:(int)index { | 138 - (void)insertItemAtIndex:(int)index { |
127 [self.tabs insertItemsAtIndexPaths:@[ [NSIndexPath indexPathForItem:index | 139 [self.tabs insertItemsAtIndexPaths:@[ [NSIndexPath indexPathForItem:index |
128 inSection:0] ]]; | 140 inSection:0] ]]; |
129 } | 141 } |
130 | 142 |
131 - (void)deleteItemAtIndex:(int)index { | 143 - (void)deleteItemAtIndex:(int)index { |
132 [self.tabs deleteItemsAtIndexPaths:@[ [NSIndexPath indexPathForItem:index | 144 [self.tabs deleteItemsAtIndexPaths:@[ [NSIndexPath indexPathForItem:index |
133 inSection:0] ]]; | 145 inSection:0] ]]; |
134 } | 146 } |
135 | 147 |
136 - (void)reloadItemsAtIndexes:(NSIndexSet*)indexes { | 148 - (void)reloadItemsAtIndexes:(NSIndexSet*)indexes { |
137 NSMutableArray<NSIndexPath*>* indexPaths = [[NSMutableArray alloc] init]; | 149 NSMutableArray<NSIndexPath*>* indexPaths = [[NSMutableArray alloc] init]; |
138 [indexes enumerateIndexesUsingBlock:^(NSUInteger index, BOOL* _Nonnull stop) { | 150 [indexes enumerateIndexesUsingBlock:^(NSUInteger index, BOOL* _Nonnull stop) { |
139 [indexPaths addObject:[NSIndexPath indexPathForItem:index inSection:0]]; | 151 [indexPaths addObject:[NSIndexPath indexPathForItem:index inSection:0]]; |
140 }]; | 152 }]; |
141 [self.tabs reloadItemsAtIndexPaths:indexPaths]; | 153 [self.tabs reloadItemsAtIndexPaths:indexPaths]; |
142 } | 154 } |
143 | 155 |
144 @end | 156 @end |
OLD | NEW |