Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: ios/clean/chrome/browser/ui/tab_collection/tab_collection_view_controller.mm

Issue 2971113002: [ios] Plumb SnapshotCache into tab grid. (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 12 matching lines...) Expand all
23 // The model backing the collection view. 23 // The model backing the collection view.
24 @property(nonatomic, readwrite) NSMutableArray<TabCollectionItem*>* items; 24 @property(nonatomic, readwrite) NSMutableArray<TabCollectionItem*>* items;
25 // Selected index of tab collection. 25 // Selected index of tab collection.
26 @property(nonatomic, assign) int selectedIndex; 26 @property(nonatomic, assign) int selectedIndex;
27 @end 27 @end
28 28
29 @implementation TabCollectionViewController 29 @implementation TabCollectionViewController
30 @synthesize tabs = _tabs; 30 @synthesize tabs = _tabs;
31 @synthesize items = _items; 31 @synthesize items = _items;
32 @synthesize selectedIndex = _selectedIndex; 32 @synthesize selectedIndex = _selectedIndex;
33 @synthesize snapshotCache = _snapshotCache;
33 34
34 #pragma mark - UIViewController 35 #pragma mark - UIViewController
35 36
36 - (void)viewDidLoad { 37 - (void)viewDidLoad {
37 [super viewDidLoad]; 38 [super viewDidLoad];
38 UICollectionView* tabs = 39 UICollectionView* tabs =
39 [[UICollectionView alloc] initWithFrame:CGRectZero 40 [[UICollectionView alloc] initWithFrame:CGRectZero
40 collectionViewLayout:[self collectionViewLayout]]; 41 collectionViewLayout:[self collectionViewLayout]];
41 tabs.translatesAutoresizingMaskIntoConstraints = NO; 42 tabs.translatesAutoresizingMaskIntoConstraints = NO;
42 tabs.backgroundColor = [UIColor blackColor]; 43 tabs.backgroundColor = [UIColor blackColor];
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 cellForItemAtIndexPath:(nonnull NSIndexPath*)indexPath { 114 cellForItemAtIndexPath:(nonnull NSIndexPath*)indexPath {
114 TabCollectionTabCell* cell = 115 TabCollectionTabCell* cell =
115 base::mac::ObjCCastStrict<TabCollectionTabCell>([collectionView 116 base::mac::ObjCCastStrict<TabCollectionTabCell>([collectionView
116 dequeueReusableCellWithReuseIdentifier:[TabCollectionTabCell 117 dequeueReusableCellWithReuseIdentifier:[TabCollectionTabCell
117 identifier] 118 identifier]
118 forIndexPath:indexPath]); 119 forIndexPath:indexPath]);
119 cell.delegate = self; 120 cell.delegate = self;
120 [cell setSessionType:TabSwitcherSessionType::REGULAR_SESSION]; 121 [cell setSessionType:TabSwitcherSessionType::REGULAR_SESSION];
121 DCHECK_LE(indexPath.item, INT_MAX); 122 DCHECK_LE(indexPath.item, INT_MAX);
122 int index = static_cast<int>(indexPath.item); 123 int index = static_cast<int>(indexPath.item);
123 // PLACEHOLDER: SnapshotCache will be passed into the cell. 124 [cell configureCell:self.items[index] snapshotCache:self.snapshotCache];
124 [cell configureCell:self.items[index] snapshotCache:nil];
125 return cell; 125 return cell;
126 } 126 }
127 127
128 #pragma mark - UICollectionViewDelegate methods 128 #pragma mark - UICollectionViewDelegate methods
129 129
130 - (BOOL)collectionView:(UICollectionView*)collectionView 130 - (BOOL)collectionView:(UICollectionView*)collectionView
131 shouldSelectItemAtIndexPath:(NSIndexPath*)indexPath { 131 shouldSelectItemAtIndexPath:(NSIndexPath*)indexPath {
132 // Prevent user selection of items. 132 // Prevent user selection of items.
133 return NO; 133 return NO;
134 } 134 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 } 190 }
191 191
192 - (void)replaceItemAtIndex:(int)index withItem:(TabCollectionItem*)item { 192 - (void)replaceItemAtIndex:(int)index withItem:(TabCollectionItem*)item {
193 DCHECK(item); 193 DCHECK(item);
194 DCHECK_GE(index, 0); 194 DCHECK_GE(index, 0);
195 DCHECK_LT(static_cast<NSUInteger>(index), self.items.count); 195 DCHECK_LT(static_cast<NSUInteger>(index), self.items.count);
196 self.items[index] = item; 196 self.items[index] = item;
197 TabCollectionTabCell* cell = base::mac::ObjCCastStrict<TabCollectionTabCell>( 197 TabCollectionTabCell* cell = base::mac::ObjCCastStrict<TabCollectionTabCell>(
198 [self.tabs cellForItemAtIndexPath:[NSIndexPath indexPathForItem:index 198 [self.tabs cellForItemAtIndexPath:[NSIndexPath indexPathForItem:index
199 inSection:0]]); 199 inSection:0]]);
200 // PLACEHOLDER: SnapshotCache will be passed into the cell. 200 [cell configureCell:self.items[index] snapshotCache:self.snapshotCache];
201 [cell configureCell:self.items[index] snapshotCache:nil];
202 } 201 }
203 202
204 - (void)populateItems:(NSArray<TabCollectionItem*>*)items 203 - (void)populateItems:(NSArray<TabCollectionItem*>*)items
205 selectedIndex:(int)selectedIndex { 204 selectedIndex:(int)selectedIndex {
206 self.items = [items mutableCopy]; 205 self.items = [items mutableCopy];
207 [self.tabs reloadItemsAtIndexPaths:[self.tabs indexPathsForVisibleItems]]; 206 [self.tabs reloadItemsAtIndexPaths:[self.tabs indexPathsForVisibleItems]];
208 self.selectedIndex = selectedIndex; 207 self.selectedIndex = selectedIndex;
209 } 208 }
210 209
211 - (void)updateSnapshotAtIndex:(int)index { 210 - (void)updateSnapshotAtIndex:(int)index {
212 DCHECK_GE(index, 0); 211 DCHECK_GE(index, 0);
213 DCHECK_LT(static_cast<NSUInteger>(index), self.items.count); 212 DCHECK_LT(static_cast<NSUInteger>(index), self.items.count);
214 TabCollectionTabCell* cell = base::mac::ObjCCastStrict<TabCollectionTabCell>( 213 TabCollectionTabCell* cell = base::mac::ObjCCastStrict<TabCollectionTabCell>(
215 [self.tabs cellForItemAtIndexPath:[NSIndexPath indexPathForItem:index 214 [self.tabs cellForItemAtIndexPath:[NSIndexPath indexPathForItem:index
216 inSection:0]]); 215 inSection:0]]);
217 // PLACEHOLDER: SnapshotCache will be passed into the cell. 216 [cell configureCell:self.items[index] snapshotCache:self.snapshotCache];
218 [cell configureCell:self.items[index] snapshotCache:nil];
219 } 217 }
220 218
221 @end 219 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698