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

Side by Side Diff: ios/clean/chrome/browser/ui/tab_grid/tab_grid_view_controller.mm

Issue 2741883002: [ios] Use WebStateList to back the tab grid. (Closed)
Patch Set: Make readonly reference property. Created 3 years, 9 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 // ====== New Architecture ===== 5 // ====== New Architecture =====
6 // = This code is only used in the new iOS Chrome architecture. = 6 // = This code is only used in the new iOS Chrome architecture. =
7 // ============================================================================ 7 // ============================================================================
8 8
9 #import "ios/clean/chrome/browser/ui/tab_grid/tab_grid_view_controller.h" 9 #import "ios/clean/chrome/browser/ui/tab_grid/tab_grid_view_controller.h"
10 10
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 98
99 #pragma mark - UICollectionViewDataSource methods 99 #pragma mark - UICollectionViewDataSource methods
100 100
101 - (NSInteger)numberOfSectionsInCollectionView: 101 - (NSInteger)numberOfSectionsInCollectionView:
102 (UICollectionView*)collectionView { 102 (UICollectionView*)collectionView {
103 return 1; 103 return 1;
104 } 104 }
105 105
106 - (NSInteger)collectionView:(UICollectionView*)collectionView 106 - (NSInteger)collectionView:(UICollectionView*)collectionView
107 numberOfItemsInSection:(NSInteger)section { 107 numberOfItemsInSection:(NSInteger)section {
108 NSInteger items = [self.dataSource numberOfTabsInTabGrid]; 108 int tabs = [self.dataSource numberOfTabsInTabGrid];
109 DCHECK_LE(tabs, NSIntegerMax);
sdefresne 2017/03/14 09:04:08 This is unnecessary, NSInteger is at least as larg
edchin 2017/03/14 16:02:42 Done.
110 NSInteger items = static_cast<NSInteger>(tabs);
109 // HACK: Do not make showing noTabsOverlay a side effect of the dataSource 111 // HACK: Do not make showing noTabsOverlay a side effect of the dataSource
110 // callback. 112 // callback.
111 if (items) { 113 if (items) {
112 [self removeNoTabsOverlay]; 114 [self removeNoTabsOverlay];
113 } else { 115 } else {
114 [self showNoTabsOverlay]; 116 [self showNoTabsOverlay];
115 } 117 }
116 return items; 118 return items;
117 } 119 }
118 120
119 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView 121 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView
120 cellForItemAtIndexPath:(nonnull NSIndexPath*)indexPath { 122 cellForItemAtIndexPath:(nonnull NSIndexPath*)indexPath {
121 TabGridTabCell* cell = 123 TabGridTabCell* cell =
122 base::mac::ObjCCastStrict<TabGridTabCell>([collectionView 124 base::mac::ObjCCastStrict<TabGridTabCell>([collectionView
123 dequeueReusableCellWithReuseIdentifier:[TabGridTabCell identifier] 125 dequeueReusableCellWithReuseIdentifier:[TabGridTabCell identifier]
124 forIndexPath:indexPath]); 126 forIndexPath:indexPath]);
125 cell.delegate = self; 127 cell.delegate = self;
126 [cell setSessionType:TabSwitcherSessionType::REGULAR_SESSION]; 128 [cell setSessionType:TabSwitcherSessionType::REGULAR_SESSION];
127 [cell setAppearanceForTabTitle:[self.dataSource titleAtIndex:indexPath.item] 129 DCHECK_LE(indexPath.item, INT_MAX);
130 int item = static_cast<int>(indexPath.item);
131 [cell setAppearanceForTabTitle:[self.dataSource titleAtIndex:item]
128 favicon:nil 132 favicon:nil
129 cellSize:CGSizeZero]; 133 cellSize:CGSizeZero];
130 [cell setSelected:(indexPath.item == [self.dataSource indexOfActiveTab])]; 134 int tab = [self.dataSource indexOfActiveTab];
135 DCHECK_LE(tab, NSIntegerMax);
sdefresne 2017/03/14 09:04:08 ditto, remove the DCHECK and cast here (int -> NSI
136 NSInteger index = static_cast<NSInteger>(tab);
137 [cell setSelected:(indexPath.item == index)];
131 return cell; 138 return cell;
132 } 139 }
133 140
134 #pragma mark - UICollectionViewDelegate methods 141 #pragma mark - UICollectionViewDelegate methods
135 142
136 - (BOOL)collectionView:(UICollectionView*)collectionView 143 - (BOOL)collectionView:(UICollectionView*)collectionView
137 shouldSelectItemAtIndexPath:(NSIndexPath*)indexPath { 144 shouldSelectItemAtIndexPath:(NSIndexPath*)indexPath {
138 // Prevent user selection of items. 145 // Prevent user selection of items.
139 return NO; 146 return NO;
140 } 147 }
(...skipping 14 matching lines...) Expand all
155 [self.settingsCommandHandler showSettings]; 162 [self.settingsCommandHandler showSettings];
156 } 163 }
157 164
158 #pragma mark - TabGridActions 165 #pragma mark - TabGridActions
159 166
160 - (void)showTabGrid:(id)sender { 167 - (void)showTabGrid:(id)sender {
161 [self.tabGridCommandHandler showTabGrid]; 168 [self.tabGridCommandHandler showTabGrid];
162 } 169 }
163 170
164 - (void)createNewTab:(id)sender { 171 - (void)createNewTab:(id)sender {
165 // PLACEHOLDER: The new WebStateList data structure will have implications
166 // on how new tabs are created.
167 NSInteger index = [self.grid numberOfItemsInSection:0]; 172 NSInteger index = [self.grid numberOfItemsInSection:0];
168 NSIndexPath* indexPath = [NSIndexPath indexPathForItem:index inSection:0]; 173 NSIndexPath* indexPath = [NSIndexPath indexPathForItem:index inSection:0];
169 auto updateBlock = ^{ 174 auto updateBlock = ^{
170 // Unselect current selected item. 175 // Unselect current selected item.
171 NSInteger selectedIndex = [self.dataSource indexOfActiveTab]; 176 int index = [self.dataSource indexOfActiveTab];
177 DCHECK_LE(index, NSIntegerMax);
sdefresne 2017/03/14 09:04:08 ditto, remove the DCHECK and cast here (int -> NSI
178 NSInteger selectedIndex = static_cast<NSInteger>(index);
172 NSIndexPath* selectedIndexPath = 179 NSIndexPath* selectedIndexPath =
173 [NSIndexPath indexPathForItem:selectedIndex inSection:0]; 180 [NSIndexPath indexPathForItem:selectedIndex inSection:0];
174 [self.grid reloadItemsAtIndexPaths:@[ selectedIndexPath ]]; 181 [self.grid reloadItemsAtIndexPaths:@[ selectedIndexPath ]];
175 182
176 // Create and show new tab. 183 // Create and show new tab.
177 [self.tabCommandHandler createNewTabAtIndexPath:indexPath]; 184 [self.tabCommandHandler createNewTabAtIndexPath:indexPath];
178 [self.tabCommandHandler showTabAtIndexPath:indexPath]; 185 [self.tabCommandHandler showTabAtIndexPath:indexPath];
179 [self.grid insertItemsAtIndexPaths:@[ indexPath ]]; 186 [self.grid insertItemsAtIndexPaths:@[ indexPath ]];
180 }; 187 };
181 [self.grid performBatchUpdates:updateBlock completion:nil]; 188 [self.grid performBatchUpdates:updateBlock completion:nil];
182 } 189 }
183 190
184 #pragma mark - SessionCellDelegate 191 #pragma mark - SessionCellDelegate
185 192
186 - (TabSwitcherCache*)tabSwitcherCache { 193 - (TabSwitcherCache*)tabSwitcherCache {
187 // PLACEHOLDER: return image cache. 194 // PLACEHOLDER: return image cache.
188 return nil; 195 return nil;
189 } 196 }
190 197
191 - (void)cellPressed:(UICollectionViewCell*)cell { 198 - (void)cellPressed:(UICollectionViewCell*)cell {
192 NSInteger selectedIndex = [self.dataSource indexOfActiveTab]; 199 int index = [self.dataSource indexOfActiveTab];
200 DCHECK_LE(index, NSIntegerMax);
sdefresne 2017/03/14 09:04:09 ditto, remove the DCHECK and cast here (int -> NSI
201 NSInteger selectedIndex = static_cast<NSInteger>(index);
193 NSIndexPath* newSelectedIndexPath = [self.grid indexPathForCell:cell]; 202 NSIndexPath* newSelectedIndexPath = [self.grid indexPathForCell:cell];
194 [self.tabCommandHandler showTabAtIndexPath:newSelectedIndexPath]; 203 [self.tabCommandHandler showTabAtIndexPath:newSelectedIndexPath];
195 if (newSelectedIndexPath.item != selectedIndex) { 204 if (newSelectedIndexPath.item != selectedIndex) {
196 NSIndexPath* selectedIndexPath = 205 NSIndexPath* selectedIndexPath =
197 [NSIndexPath indexPathForItem:selectedIndex inSection:0]; 206 [NSIndexPath indexPathForItem:selectedIndex inSection:0];
198 [self.grid 207 [self.grid
199 reloadItemsAtIndexPaths:@[ selectedIndexPath, newSelectedIndexPath ]]; 208 reloadItemsAtIndexPaths:@[ selectedIndexPath, newSelectedIndexPath ]];
200 } 209 }
201 } 210 }
202 211
(...skipping 24 matching lines...) Expand all
227 [self.grid addSubview:overlayView]; 236 [self.grid addSubview:overlayView];
228 self.noTabsOverlay = overlayView; 237 self.noTabsOverlay = overlayView;
229 } 238 }
230 239
231 // Removes the noTabsOverlay covering the entire tab grid. 240 // Removes the noTabsOverlay covering the entire tab grid.
232 - (void)removeNoTabsOverlay { 241 - (void)removeNoTabsOverlay {
233 [self.noTabsOverlay removeFromSuperview]; 242 [self.noTabsOverlay removeFromSuperview];
234 } 243 }
235 244
236 @end 245 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698