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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 cellForItemAtIndexPath:(nonnull NSIndexPath*)indexPath { | 111 cellForItemAtIndexPath:(nonnull NSIndexPath*)indexPath { |
112 TabCollectionTabCell* cell = | 112 TabCollectionTabCell* cell = |
113 base::mac::ObjCCastStrict<TabCollectionTabCell>([collectionView | 113 base::mac::ObjCCastStrict<TabCollectionTabCell>([collectionView |
114 dequeueReusableCellWithReuseIdentifier:[TabCollectionTabCell | 114 dequeueReusableCellWithReuseIdentifier:[TabCollectionTabCell |
115 identifier] | 115 identifier] |
116 forIndexPath:indexPath]); | 116 forIndexPath:indexPath]); |
117 cell.delegate = self; | 117 cell.delegate = self; |
118 [cell setSessionType:TabSwitcherSessionType::REGULAR_SESSION]; | 118 [cell setSessionType:TabSwitcherSessionType::REGULAR_SESSION]; |
119 DCHECK_LE(indexPath.item, INT_MAX); | 119 DCHECK_LE(indexPath.item, INT_MAX); |
120 int index = static_cast<int>(indexPath.item); | 120 int index = static_cast<int>(indexPath.item); |
121 cell.item = self.items[index]; | 121 // PLACEHOLDER: SnapshotCache will be passed into the cell. |
| 122 [cell configureCell:self.items[index] snapshotCache:nil]; |
122 return cell; | 123 return cell; |
123 } | 124 } |
124 | 125 |
125 #pragma mark - UICollectionViewDelegate methods | 126 #pragma mark - UICollectionViewDelegate methods |
126 | 127 |
127 - (BOOL)collectionView:(UICollectionView*)collectionView | 128 - (BOOL)collectionView:(UICollectionView*)collectionView |
128 shouldSelectItemAtIndexPath:(NSIndexPath*)indexPath { | 129 shouldSelectItemAtIndexPath:(NSIndexPath*)indexPath { |
129 // Prevent user selection of items. | 130 // Prevent user selection of items. |
130 return NO; | 131 return NO; |
131 } | 132 } |
132 | 133 |
133 #pragma mark - SessionCellDelegate | 134 #pragma mark - SessionCellDelegate |
134 | 135 |
135 - (TabSwitcherCache*)tabSwitcherCache { | 136 - (TabSwitcherCache*)tabSwitcherCache { |
136 // PLACEHOLDER: return image cache. | 137 // PLACEHOLDER: SnapshotCache will be passed into the cell. |
137 return nil; | 138 return nil; |
138 } | 139 } |
139 | 140 |
140 - (void)cellPressed:(UICollectionViewCell*)cell { | 141 - (void)cellPressed:(UICollectionViewCell*)cell { |
141 NSInteger item = [[self.tabs indexPathForCell:cell] item]; | 142 NSInteger item = [[self.tabs indexPathForCell:cell] item]; |
142 DCHECK_LE(item, INT_MAX); | 143 DCHECK_LE(item, INT_MAX); |
143 int index = static_cast<int>(item); | 144 int index = static_cast<int>(item); |
144 [self showTabAtIndex:index]; | 145 [self showTabAtIndex:index]; |
145 } | 146 } |
146 | 147 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 TabCollectionItem* item = self.items[fromIndex]; | 180 TabCollectionItem* item = self.items[fromIndex]; |
180 [self.items removeObjectAtIndex:fromIndex]; | 181 [self.items removeObjectAtIndex:fromIndex]; |
181 [self.items insertObject:item atIndex:toIndex]; | 182 [self.items insertObject:item atIndex:toIndex]; |
182 [self.tabs | 183 [self.tabs |
183 moveItemAtIndexPath:[NSIndexPath indexPathForItem:fromIndex inSection:0] | 184 moveItemAtIndexPath:[NSIndexPath indexPathForItem:fromIndex inSection:0] |
184 toIndexPath:[NSIndexPath indexPathForItem:toIndex inSection:0]]; | 185 toIndexPath:[NSIndexPath indexPathForItem:toIndex inSection:0]]; |
185 self.selectedIndex = selectedIndex; | 186 self.selectedIndex = selectedIndex; |
186 } | 187 } |
187 | 188 |
188 - (void)replaceItemAtIndex:(int)index withItem:(TabCollectionItem*)item { | 189 - (void)replaceItemAtIndex:(int)index withItem:(TabCollectionItem*)item { |
| 190 DCHECK(item); |
189 DCHECK_GE(index, 0); | 191 DCHECK_GE(index, 0); |
190 DCHECK_LT(static_cast<NSUInteger>(index), self.items.count); | 192 DCHECK_LT(static_cast<NSUInteger>(index), self.items.count); |
191 self.items[index] = item; | 193 self.items[index] = item; |
192 TabCollectionTabCell* cell = base::mac::ObjCCastStrict<TabCollectionTabCell>( | 194 TabCollectionTabCell* cell = base::mac::ObjCCastStrict<TabCollectionTabCell>( |
193 [self.tabs cellForItemAtIndexPath:[NSIndexPath indexPathForItem:index | 195 [self.tabs cellForItemAtIndexPath:[NSIndexPath indexPathForItem:index |
194 inSection:0]]); | 196 inSection:0]]); |
195 cell.item = self.items[index]; | 197 // PLACEHOLDER: SnapshotCache will be passed into the cell. |
| 198 [cell configureCell:self.items[index] snapshotCache:nil]; |
196 } | 199 } |
197 | 200 |
198 - (void)populateItems:(NSArray<TabCollectionItem*>*)items | 201 - (void)populateItems:(NSArray<TabCollectionItem*>*)items |
199 selectedIndex:(int)selectedIndex { | 202 selectedIndex:(int)selectedIndex { |
200 self.items = [items mutableCopy]; | 203 self.items = [items mutableCopy]; |
201 [self.tabs reloadItemsAtIndexPaths:[self.tabs indexPathsForVisibleItems]]; | 204 [self.tabs reloadItemsAtIndexPaths:[self.tabs indexPathsForVisibleItems]]; |
202 self.selectedIndex = selectedIndex; | 205 self.selectedIndex = selectedIndex; |
203 } | 206 } |
204 | 207 |
205 @end | 208 @end |
OLD | NEW |