| 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/logging.h" |
| 8 #include "base/mac/foundation_util.h" | 8 #include "base/mac/foundation_util.h" |
| 9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 10 #import "ios/clean/chrome/browser/ui/tab_collection/tab_collection_item.h" | 10 #import "ios/clean/chrome/browser/ui/tab_collection/tab_collection_item.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 // The model backing the collection view. | 21 // The model backing the collection view. |
| 22 @property(nonatomic, readwrite) NSMutableArray<TabCollectionItem*>* items; | 22 @property(nonatomic, readwrite) NSMutableArray<TabCollectionItem*>* items; |
| 23 // Selected index of tab collection. | 23 // Selected index of tab collection. |
| 24 @property(nonatomic, assign) int selectedIndex; | 24 @property(nonatomic, assign) int selectedIndex; |
| 25 @end | 25 @end |
| 26 | 26 |
| 27 @implementation TabCollectionViewController | 27 @implementation TabCollectionViewController |
| 28 @synthesize tabs = _tabs; | 28 @synthesize tabs = _tabs; |
| 29 @synthesize items = _items; | 29 @synthesize items = _items; |
| 30 @synthesize selectedIndex = _selectedIndex; | 30 @synthesize selectedIndex = _selectedIndex; |
| 31 @synthesize snapshotCache = _snapshotCache; |
| 31 | 32 |
| 32 #pragma mark - UIViewController | 33 #pragma mark - UIViewController |
| 33 | 34 |
| 34 - (void)viewDidLoad { | 35 - (void)viewDidLoad { |
| 35 [super viewDidLoad]; | 36 [super viewDidLoad]; |
| 36 UICollectionView* tabs = | 37 UICollectionView* tabs = |
| 37 [[UICollectionView alloc] initWithFrame:CGRectZero | 38 [[UICollectionView alloc] initWithFrame:CGRectZero |
| 38 collectionViewLayout:[self collectionViewLayout]]; | 39 collectionViewLayout:[self collectionViewLayout]]; |
| 39 tabs.translatesAutoresizingMaskIntoConstraints = NO; | 40 tabs.translatesAutoresizingMaskIntoConstraints = NO; |
| 40 tabs.backgroundColor = [UIColor blackColor]; | 41 tabs.backgroundColor = [UIColor blackColor]; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 cellForItemAtIndexPath:(nonnull NSIndexPath*)indexPath { | 112 cellForItemAtIndexPath:(nonnull NSIndexPath*)indexPath { |
| 112 TabCollectionTabCell* cell = | 113 TabCollectionTabCell* cell = |
| 113 base::mac::ObjCCastStrict<TabCollectionTabCell>([collectionView | 114 base::mac::ObjCCastStrict<TabCollectionTabCell>([collectionView |
| 114 dequeueReusableCellWithReuseIdentifier:[TabCollectionTabCell | 115 dequeueReusableCellWithReuseIdentifier:[TabCollectionTabCell |
| 115 identifier] | 116 identifier] |
| 116 forIndexPath:indexPath]); | 117 forIndexPath:indexPath]); |
| 117 cell.delegate = self; | 118 cell.delegate = self; |
| 118 [cell setSessionType:TabSwitcherSessionType::REGULAR_SESSION]; | 119 [cell setSessionType:TabSwitcherSessionType::REGULAR_SESSION]; |
| 119 DCHECK_LE(indexPath.item, INT_MAX); | 120 DCHECK_LE(indexPath.item, INT_MAX); |
| 120 int index = static_cast<int>(indexPath.item); | 121 int index = static_cast<int>(indexPath.item); |
| 121 // PLACEHOLDER: SnapshotCache will be passed into the cell. | 122 [cell configureCell:self.items[index] snapshotCache:self.snapshotCache]; |
| 122 [cell configureCell:self.items[index] snapshotCache:nil]; | |
| 123 return cell; | 123 return cell; |
| 124 } | 124 } |
| 125 | 125 |
| 126 #pragma mark - UICollectionViewDelegate methods | 126 #pragma mark - UICollectionViewDelegate methods |
| 127 | 127 |
| 128 - (BOOL)collectionView:(UICollectionView*)collectionView | 128 - (BOOL)collectionView:(UICollectionView*)collectionView |
| 129 shouldSelectItemAtIndexPath:(NSIndexPath*)indexPath { | 129 shouldSelectItemAtIndexPath:(NSIndexPath*)indexPath { |
| 130 // Prevent user selection of items. | 130 // Prevent user selection of items. |
| 131 return NO; | 131 return NO; |
| 132 } | 132 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 } | 187 } |
| 188 | 188 |
| 189 - (void)replaceItemAtIndex:(int)index withItem:(TabCollectionItem*)item { | 189 - (void)replaceItemAtIndex:(int)index withItem:(TabCollectionItem*)item { |
| 190 DCHECK(item); | 190 DCHECK(item); |
| 191 DCHECK_GE(index, 0); | 191 DCHECK_GE(index, 0); |
| 192 DCHECK_LT(static_cast<NSUInteger>(index), self.items.count); | 192 DCHECK_LT(static_cast<NSUInteger>(index), self.items.count); |
| 193 self.items[index] = item; | 193 self.items[index] = item; |
| 194 TabCollectionTabCell* cell = base::mac::ObjCCastStrict<TabCollectionTabCell>( | 194 TabCollectionTabCell* cell = base::mac::ObjCCastStrict<TabCollectionTabCell>( |
| 195 [self.tabs cellForItemAtIndexPath:[NSIndexPath indexPathForItem:index | 195 [self.tabs cellForItemAtIndexPath:[NSIndexPath indexPathForItem:index |
| 196 inSection:0]]); | 196 inSection:0]]); |
| 197 // PLACEHOLDER: SnapshotCache will be passed into the cell. | 197 [cell configureCell:self.items[index] snapshotCache:self.snapshotCache]; |
| 198 [cell configureCell:self.items[index] snapshotCache:nil]; | |
| 199 } | 198 } |
| 200 | 199 |
| 201 - (void)populateItems:(NSArray<TabCollectionItem*>*)items | 200 - (void)populateItems:(NSArray<TabCollectionItem*>*)items |
| 202 selectedIndex:(int)selectedIndex { | 201 selectedIndex:(int)selectedIndex { |
| 203 self.items = [items mutableCopy]; | 202 self.items = [items mutableCopy]; |
| 204 [self.tabs reloadItemsAtIndexPaths:[self.tabs indexPathsForVisibleItems]]; | 203 [self.tabs reloadItemsAtIndexPaths:[self.tabs indexPathsForVisibleItems]]; |
| 205 self.selectedIndex = selectedIndex; | 204 self.selectedIndex = selectedIndex; |
| 206 } | 205 } |
| 207 | 206 |
| 208 @end | 207 @end |
| OLD | NEW |