| OLD | NEW |
| 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 Loading... |
| 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 items = [self.dataSource numberOfTabsInTabGrid]; |
| 109 // HACK: Do not make showing noTabsOverlay a side effect of the dataSource | 109 // HACK: Do not make showing noTabsOverlay a side effect of the dataSource |
| 110 // callback. | 110 // callback. |
| 111 if (items) { | 111 if (items) { |
| 112 [self removeNoTabsOverlay]; | 112 [self removeNoTabsOverlay]; |
| 113 } else { | 113 } else { |
| 114 [self showNoTabsOverlay]; | 114 [self showNoTabsOverlay]; |
| 115 } | 115 } |
| 116 return items; | 116 return items; |
| 117 } | 117 } |
| 118 | 118 |
| 119 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView | 119 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView |
| 120 cellForItemAtIndexPath:(nonnull NSIndexPath*)indexPath { | 120 cellForItemAtIndexPath:(nonnull NSIndexPath*)indexPath { |
| 121 TabGridTabCell* cell = | 121 TabGridTabCell* cell = |
| 122 base::mac::ObjCCastStrict<TabGridTabCell>([collectionView | 122 base::mac::ObjCCastStrict<TabGridTabCell>([collectionView |
| 123 dequeueReusableCellWithReuseIdentifier:[TabGridTabCell identifier] | 123 dequeueReusableCellWithReuseIdentifier:[TabGridTabCell identifier] |
| 124 forIndexPath:indexPath]); | 124 forIndexPath:indexPath]); |
| 125 cell.delegate = self; | 125 cell.delegate = self; |
| 126 [cell setSessionType:TabSwitcherSessionType::REGULAR_SESSION]; | 126 [cell setSessionType:TabSwitcherSessionType::REGULAR_SESSION]; |
| 127 [cell setAppearanceForTabTitle:[self.dataSource titleAtIndex:indexPath.item] | 127 DCHECK_LE(indexPath.item, INT_MAX); |
| 128 int item = static_cast<int>(indexPath.item); |
| 129 [cell setAppearanceForTabTitle:[self.dataSource titleAtIndex:item] |
| 128 favicon:nil | 130 favicon:nil |
| 129 cellSize:CGSizeZero]; | 131 cellSize:CGSizeZero]; |
| 130 [cell setSelected:(indexPath.item == [self.dataSource indexOfActiveTab])]; | 132 [cell setSelected:(indexPath.item == [self.dataSource indexOfActiveTab])]; |
| 131 return cell; | 133 return cell; |
| 132 } | 134 } |
| 133 | 135 |
| 134 #pragma mark - UICollectionViewDelegate methods | 136 #pragma mark - UICollectionViewDelegate methods |
| 135 | 137 |
| 136 - (BOOL)collectionView:(UICollectionView*)collectionView | 138 - (BOOL)collectionView:(UICollectionView*)collectionView |
| 137 shouldSelectItemAtIndexPath:(NSIndexPath*)indexPath { | 139 shouldSelectItemAtIndexPath:(NSIndexPath*)indexPath { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 155 [self.settingsCommandHandler showSettings]; | 157 [self.settingsCommandHandler showSettings]; |
| 156 } | 158 } |
| 157 | 159 |
| 158 #pragma mark - TabGridActions | 160 #pragma mark - TabGridActions |
| 159 | 161 |
| 160 - (void)showTabGrid:(id)sender { | 162 - (void)showTabGrid:(id)sender { |
| 161 [self.tabGridCommandHandler showTabGrid]; | 163 [self.tabGridCommandHandler showTabGrid]; |
| 162 } | 164 } |
| 163 | 165 |
| 164 - (void)createNewTab:(id)sender { | 166 - (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]; | 167 NSInteger index = [self.grid numberOfItemsInSection:0]; |
| 168 NSIndexPath* indexPath = [NSIndexPath indexPathForItem:index inSection:0]; | 168 NSIndexPath* indexPath = [NSIndexPath indexPathForItem:index inSection:0]; |
| 169 auto updateBlock = ^{ | 169 auto updateBlock = ^{ |
| 170 // Unselect current selected item. | 170 // Unselect current selected item. |
| 171 NSInteger selectedIndex = [self.dataSource indexOfActiveTab]; | |
| 172 NSIndexPath* selectedIndexPath = | 171 NSIndexPath* selectedIndexPath = |
| 173 [NSIndexPath indexPathForItem:selectedIndex inSection:0]; | 172 [NSIndexPath indexPathForItem:[self.dataSource indexOfActiveTab] |
| 173 inSection:0]; |
| 174 [self.grid reloadItemsAtIndexPaths:@[ selectedIndexPath ]]; | 174 [self.grid reloadItemsAtIndexPaths:@[ selectedIndexPath ]]; |
| 175 | 175 |
| 176 // Create and show new tab. | 176 // Create and show new tab. |
| 177 [self.tabCommandHandler createNewTabAtIndexPath:indexPath]; | 177 [self.tabCommandHandler createNewTabAtIndexPath:indexPath]; |
| 178 [self.tabCommandHandler showTabAtIndexPath:indexPath]; | 178 [self.tabCommandHandler showTabAtIndexPath:indexPath]; |
| 179 [self.grid insertItemsAtIndexPaths:@[ indexPath ]]; | 179 [self.grid insertItemsAtIndexPaths:@[ indexPath ]]; |
| 180 }; | 180 }; |
| 181 [self.grid performBatchUpdates:updateBlock completion:nil]; | 181 [self.grid performBatchUpdates:updateBlock completion:nil]; |
| 182 } | 182 } |
| 183 | 183 |
| 184 #pragma mark - SessionCellDelegate | 184 #pragma mark - SessionCellDelegate |
| 185 | 185 |
| 186 - (TabSwitcherCache*)tabSwitcherCache { | 186 - (TabSwitcherCache*)tabSwitcherCache { |
| 187 // PLACEHOLDER: return image cache. | 187 // PLACEHOLDER: return image cache. |
| 188 return nil; | 188 return nil; |
| 189 } | 189 } |
| 190 | 190 |
| 191 - (void)cellPressed:(UICollectionViewCell*)cell { | 191 - (void)cellPressed:(UICollectionViewCell*)cell { |
| 192 NSInteger selectedIndex = [self.dataSource indexOfActiveTab]; | 192 int selectedIndex = [self.dataSource indexOfActiveTab]; |
| 193 NSIndexPath* newSelectedIndexPath = [self.grid indexPathForCell:cell]; | 193 NSIndexPath* newSelectedIndexPath = [self.grid indexPathForCell:cell]; |
| 194 [self.tabCommandHandler showTabAtIndexPath:newSelectedIndexPath]; | 194 [self.tabCommandHandler showTabAtIndexPath:newSelectedIndexPath]; |
| 195 if (newSelectedIndexPath.item != selectedIndex) { | 195 if (selectedIndex == kTabGridDataSourceInvalidIndex) { |
| 196 [self.grid reloadItemsAtIndexPaths:@[ newSelectedIndexPath ]]; |
| 197 } else if (newSelectedIndexPath.item != selectedIndex) { |
| 196 NSIndexPath* selectedIndexPath = | 198 NSIndexPath* selectedIndexPath = |
| 197 [NSIndexPath indexPathForItem:selectedIndex inSection:0]; | 199 [NSIndexPath indexPathForItem:selectedIndex inSection:0]; |
| 198 [self.grid | 200 [self.grid |
| 199 reloadItemsAtIndexPaths:@[ selectedIndexPath, newSelectedIndexPath ]]; | 201 reloadItemsAtIndexPaths:@[ selectedIndexPath, newSelectedIndexPath ]]; |
| 200 } | 202 } |
| 201 } | 203 } |
| 202 | 204 |
| 203 - (void)deleteButtonPressedForCell:(UICollectionViewCell*)cell { | 205 - (void)deleteButtonPressedForCell:(UICollectionViewCell*)cell { |
| 204 auto updateBlock = ^{ | 206 auto updateBlock = ^{ |
| 205 NSIndexPath* indexPath = [self.grid indexPathForCell:cell]; | 207 NSIndexPath* indexPath = [self.grid indexPathForCell:cell]; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 227 [self.grid addSubview:overlayView]; | 229 [self.grid addSubview:overlayView]; |
| 228 self.noTabsOverlay = overlayView; | 230 self.noTabsOverlay = overlayView; |
| 229 } | 231 } |
| 230 | 232 |
| 231 // Removes the noTabsOverlay covering the entire tab grid. | 233 // Removes the noTabsOverlay covering the entire tab grid. |
| 232 - (void)removeNoTabsOverlay { | 234 - (void)removeNoTabsOverlay { |
| 233 [self.noTabsOverlay removeFromSuperview]; | 235 [self.noTabsOverlay removeFromSuperview]; |
| 234 } | 236 } |
| 235 | 237 |
| 236 @end | 238 @end |
| OLD | NEW |