| 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 TabSwitcherLocalSessionCell* cell = | 111 TabSwitcherLocalSessionCell* cell = |
| 112 base::mac::ObjCCastStrict<TabSwitcherLocalSessionCell>([collectionView | 112 base::mac::ObjCCastStrict<TabSwitcherLocalSessionCell>([collectionView |
| 113 dequeueReusableCellWithReuseIdentifier: | 113 dequeueReusableCellWithReuseIdentifier: |
| 114 [TabSwitcherLocalSessionCell identifier] | 114 [TabSwitcherLocalSessionCell identifier] |
| 115 forIndexPath:indexPath]); | 115 forIndexPath:indexPath]); |
| 116 cell.delegate = self; | 116 cell.delegate = self; |
| 117 [cell setSessionType:TabSwitcherSessionType::REGULAR_SESSION]; | 117 [cell setSessionType:TabSwitcherSessionType::REGULAR_SESSION]; |
| 118 [cell setAppearanceForTabTitle:[self.dataSource titleAtIndex:indexPath.item] | 118 [cell setAppearanceForTabTitle:[self.dataSource titleAtIndex:indexPath.item] |
| 119 favicon:nil | 119 favicon:nil |
| 120 cellSize:CGSizeZero]; | 120 cellSize:CGSizeZero]; |
| 121 [cell setSelected:(indexPath.item == [self.dataSource indexOfActiveTab])]; |
| 121 return cell; | 122 return cell; |
| 122 } | 123 } |
| 123 | 124 |
| 125 #pragma mark - UICollectionViewDelegate methods |
| 126 |
| 127 - (BOOL)collectionView:(UICollectionView*)collectionView |
| 128 shouldSelectItemAtIndexPath:(NSIndexPath*)indexPath { |
| 129 // Prevent user selection of items. |
| 130 return NO; |
| 131 } |
| 132 |
| 124 #pragma mark - ZoomTransitionDelegate methods | 133 #pragma mark - ZoomTransitionDelegate methods |
| 125 | 134 |
| 126 - (CGRect)rectForZoomWithKey:(NSObject*)key inView:(UIView*)view { | 135 - (CGRect)rectForZoomWithKey:(NSObject*)key inView:(UIView*)view { |
| 127 NSIndexPath* cellPath = base::mac::ObjCCastStrict<NSIndexPath>(key); | 136 NSIndexPath* cellPath = base::mac::ObjCCastStrict<NSIndexPath>(key); |
| 128 if (!key) | 137 if (!key) |
| 129 return CGRectNull; | 138 return CGRectNull; |
| 130 UICollectionViewCell* cell = [self.grid cellForItemAtIndexPath:cellPath]; | 139 UICollectionViewCell* cell = [self.grid cellForItemAtIndexPath:cellPath]; |
| 131 return [view convertRect:cell.bounds fromView:cell]; | 140 return [view convertRect:cell.bounds fromView:cell]; |
| 132 } | 141 } |
| 133 | 142 |
| 134 #pragma mark - SettingsActions | 143 #pragma mark - SettingsActions |
| 135 | 144 |
| 136 - (void)showSettings:(id)sender { | 145 - (void)showSettings:(id)sender { |
| 137 [self.settingsCommandHandler showSettings]; | 146 [self.settingsCommandHandler showSettings]; |
| 138 } | 147 } |
| 139 | 148 |
| 140 #pragma mark - TabGridActions | 149 #pragma mark - TabGridActions |
| 141 | 150 |
| 142 - (void)showTabGrid:(id)sender { | 151 - (void)showTabGrid:(id)sender { |
| 143 [self.tabGridCommandHandler showTabGrid]; | 152 [self.tabGridCommandHandler showTabGrid]; |
| 144 } | 153 } |
| 145 | 154 |
| 146 - (void)createNewTab:(id)sender { | 155 - (void)createNewTab:(id)sender { |
| 147 // PLACEHOLDER: The new WebStateList data structure will have implications | 156 // PLACEHOLDER: The new WebStateList data structure will have implications |
| 148 // on how new tabs are created. | 157 // on how new tabs are created. |
| 149 NSInteger index = [self.grid numberOfItemsInSection:0]; | 158 NSInteger index = [self.grid numberOfItemsInSection:0]; |
| 150 NSIndexPath* indexPath = [NSIndexPath indexPathForItem:index inSection:0]; | 159 NSIndexPath* indexPath = [NSIndexPath indexPathForItem:index inSection:0]; |
| 151 auto updateBlock = ^{ | 160 auto updateBlock = ^{ |
| 161 // Unselect current selected item. |
| 162 NSInteger selectedIndex = [self.dataSource indexOfActiveTab]; |
| 163 NSIndexPath* selectedIndexPath = |
| 164 [NSIndexPath indexPathForItem:selectedIndex inSection:0]; |
| 165 [self.grid reloadItemsAtIndexPaths:@[ selectedIndexPath ]]; |
| 166 |
| 167 // Create and show new tab. |
| 152 [self.tabCommandHandler createNewTabAtIndexPath:indexPath]; | 168 [self.tabCommandHandler createNewTabAtIndexPath:indexPath]; |
| 153 [self.tabCommandHandler showTabAtIndexPath:indexPath]; | 169 [self.tabCommandHandler showTabAtIndexPath:indexPath]; |
| 154 [self.grid insertItemsAtIndexPaths:@[ indexPath ]]; | 170 [self.grid insertItemsAtIndexPaths:@[ indexPath ]]; |
| 155 }; | 171 }; |
| 156 [self.grid performBatchUpdates:updateBlock completion:nil]; | 172 [self.grid performBatchUpdates:updateBlock completion:nil]; |
| 157 } | 173 } |
| 158 | 174 |
| 159 #pragma mark - SessionCellDelegate | 175 #pragma mark - SessionCellDelegate |
| 160 | 176 |
| 161 - (TabSwitcherCache*)tabSwitcherCache { | 177 - (TabSwitcherCache*)tabSwitcherCache { |
| 162 // PLACEHOLDER: return image cache. | 178 // PLACEHOLDER: return image cache. |
| 163 return nil; | 179 return nil; |
| 164 } | 180 } |
| 165 | 181 |
| 166 - (void)cellPressed:(UICollectionViewCell*)cell { | 182 - (void)cellPressed:(UICollectionViewCell*)cell { |
| 167 [self.tabCommandHandler showTabAtIndexPath:[self.grid indexPathForCell:cell]]; | 183 NSInteger selectedIndex = [self.dataSource indexOfActiveTab]; |
| 184 NSIndexPath* selectedIndexPath = |
| 185 [NSIndexPath indexPathForItem:selectedIndex inSection:0]; |
| 186 |
| 187 NSIndexPath* newSelectedIndexPath = [self.grid indexPathForCell:cell]; |
| 188 [self.tabCommandHandler showTabAtIndexPath:newSelectedIndexPath]; |
| 189 [self.grid |
| 190 reloadItemsAtIndexPaths:@[ selectedIndexPath, newSelectedIndexPath ]]; |
| 168 } | 191 } |
| 169 | 192 |
| 170 - (void)deleteButtonPressedForCell:(UICollectionViewCell*)cell { | 193 - (void)deleteButtonPressedForCell:(UICollectionViewCell*)cell { |
| 171 auto updateBlock = ^{ | 194 auto updateBlock = ^{ |
| 172 NSIndexPath* indexPath = [self.grid indexPathForCell:cell]; | 195 NSIndexPath* indexPath = [self.grid indexPathForCell:cell]; |
| 173 [self.tabCommandHandler closeTabAtIndexPath:indexPath]; | 196 [self.tabCommandHandler closeTabAtIndexPath:indexPath]; |
| 174 [self.grid deleteItemsAtIndexPaths:@[ indexPath ]]; | 197 [self.grid deleteItemsAtIndexPaths:@[ indexPath ]]; |
| 175 }; | 198 }; |
| 176 [self.grid performBatchUpdates:updateBlock completion:nil]; | 199 [self.grid performBatchUpdates:updateBlock completion:nil]; |
| 177 } | 200 } |
| 178 | 201 |
| 179 @end | 202 @end |
| OLD | NEW |