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

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

Issue 2709563002: [tab_grid] Hack-in border for active tab. (Closed)
Patch Set: Rebase Created 3 years, 10 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
11 #include "base/mac/foundation_util.h" 11 #include "base/mac/foundation_util.h"
12 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_cell.h"
13 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_collection_view_l ayout.h" 12 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_collection_view_l ayout.h"
14 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_overlay_view.h" 13 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_overlay_view.h"
15 #import "ios/clean/chrome/browser/ui/actions/settings_actions.h" 14 #import "ios/clean/chrome/browser/ui/actions/settings_actions.h"
16 #import "ios/clean/chrome/browser/ui/actions/tab_grid_actions.h" 15 #import "ios/clean/chrome/browser/ui/actions/tab_grid_actions.h"
17 #import "ios/clean/chrome/browser/ui/commands/settings_commands.h" 16 #import "ios/clean/chrome/browser/ui/commands/settings_commands.h"
18 #import "ios/clean/chrome/browser/ui/commands/tab_commands.h" 17 #import "ios/clean/chrome/browser/ui/commands/tab_commands.h"
19 #import "ios/clean/chrome/browser/ui/commands/tab_grid_commands.h" 18 #import "ios/clean/chrome/browser/ui/commands/tab_grid_commands.h"
20 #import "ios/clean/chrome/browser/ui/tab_grid/mdc_floating_button+cr_tab_grid.h" 19 #import "ios/clean/chrome/browser/ui/tab_grid/mdc_floating_button+cr_tab_grid.h"
21 #import "ios/clean/chrome/browser/ui/tab_grid/tab_grid_collection_view_layout.h" 20 #import "ios/clean/chrome/browser/ui/tab_grid/tab_grid_collection_view_layout.h"
21 #import "ios/clean/chrome/browser/ui/tab_grid/tab_grid_tab_cell.h"
22 #import "ios/clean/chrome/browser/ui/tab_grid/ui_stack_view+cr_tab_grid.h" 22 #import "ios/clean/chrome/browser/ui/tab_grid/ui_stack_view+cr_tab_grid.h"
23 23
24 #if !defined(__has_feature) || !__has_feature(objc_arc) 24 #if !defined(__has_feature) || !__has_feature(objc_arc)
25 #error "This file requires ARC support." 25 #error "This file requires ARC support."
26 #endif 26 #endif
27 27
28 namespace { 28 namespace {
29 // Height of toolbar in tab grid. 29 // Height of toolbar in tab grid.
30 const CGFloat kToolbarHeight = 64.0f; 30 const CGFloat kToolbarHeight = 64.0f;
31 } 31 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 [[TabGridCollectionViewLayout alloc] init]; 66 [[TabGridCollectionViewLayout alloc] init];
67 UICollectionView* grid = [[UICollectionView alloc] initWithFrame:CGRectZero 67 UICollectionView* grid = [[UICollectionView alloc] initWithFrame:CGRectZero
68 collectionViewLayout:layout]; 68 collectionViewLayout:layout];
69 grid.translatesAutoresizingMaskIntoConstraints = NO; 69 grid.translatesAutoresizingMaskIntoConstraints = NO;
70 grid.backgroundColor = [UIColor blackColor]; 70 grid.backgroundColor = [UIColor blackColor];
71 71
72 [self.view addSubview:grid]; 72 [self.view addSubview:grid];
73 self.grid = grid; 73 self.grid = grid;
74 self.grid.dataSource = self; 74 self.grid.dataSource = self;
75 self.grid.delegate = self; 75 self.grid.delegate = self;
76 [self.grid registerClass:[TabSwitcherLocalSessionCell class] 76 [self.grid registerClass:[TabGridTabCell class]
77 forCellWithReuseIdentifier:[TabSwitcherLocalSessionCell identifier]]; 77 forCellWithReuseIdentifier:[TabGridTabCell identifier]];
78 78
79 [NSLayoutConstraint activateConstraints:@[ 79 [NSLayoutConstraint activateConstraints:@[
80 [self.grid.topAnchor constraintEqualToAnchor:toolbar.bottomAnchor], 80 [self.grid.topAnchor constraintEqualToAnchor:toolbar.bottomAnchor],
81 [self.grid.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor], 81 [self.grid.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor],
82 [self.grid.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor], 82 [self.grid.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
83 [self.grid.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor], 83 [self.grid.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor],
84 ]]; 84 ]];
85 } 85 }
86 86
87 - (void)viewWillAppear:(BOOL)animated { 87 - (void)viewWillAppear:(BOOL)animated {
(...skipping 24 matching lines...) Expand all
112 if (items) { 112 if (items) {
113 [self removeNoTabsOverlay]; 113 [self removeNoTabsOverlay];
114 } else { 114 } else {
115 [self showNoTabsOverlay]; 115 [self showNoTabsOverlay];
116 } 116 }
117 return items; 117 return items;
118 } 118 }
119 119
120 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView 120 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView
121 cellForItemAtIndexPath:(nonnull NSIndexPath*)indexPath { 121 cellForItemAtIndexPath:(nonnull NSIndexPath*)indexPath {
122 TabSwitcherLocalSessionCell* cell = 122 TabGridTabCell* cell =
123 base::mac::ObjCCastStrict<TabSwitcherLocalSessionCell>([collectionView 123 base::mac::ObjCCastStrict<TabGridTabCell>([collectionView
124 dequeueReusableCellWithReuseIdentifier: 124 dequeueReusableCellWithReuseIdentifier:[TabGridTabCell identifier]
125 [TabSwitcherLocalSessionCell identifier]
126 forIndexPath:indexPath]); 125 forIndexPath:indexPath]);
127 cell.delegate = self; 126 cell.delegate = self;
128 [cell setSessionType:TabSwitcherSessionType::REGULAR_SESSION]; 127 [cell setSessionType:TabSwitcherSessionType::REGULAR_SESSION];
129 [cell setAppearanceForTabTitle:[self.dataSource titleAtIndex:indexPath.item] 128 [cell setAppearanceForTabTitle:[self.dataSource titleAtIndex:indexPath.item]
130 favicon:nil 129 favicon:nil
131 cellSize:CGSizeZero]; 130 cellSize:CGSizeZero];
131 [cell setSelected:(indexPath.item == [self.dataSource indexOfActiveTab])];
132 return cell; 132 return cell;
133 } 133 }
134 134
135 #pragma mark - UICollectionViewDelegate methods
136
137 - (BOOL)collectionView:(UICollectionView*)collectionView
138 shouldSelectItemAtIndexPath:(NSIndexPath*)indexPath {
139 // Prevent user selection of items.
140 return NO;
141 }
142
135 #pragma mark - ZoomTransitionDelegate methods 143 #pragma mark - ZoomTransitionDelegate methods
136 144
137 - (CGRect)rectForZoomWithKey:(NSObject*)key inView:(UIView*)view { 145 - (CGRect)rectForZoomWithKey:(NSObject*)key inView:(UIView*)view {
138 NSIndexPath* cellPath = base::mac::ObjCCastStrict<NSIndexPath>(key); 146 NSIndexPath* cellPath = base::mac::ObjCCastStrict<NSIndexPath>(key);
139 if (!key) 147 if (!key)
140 return CGRectNull; 148 return CGRectNull;
141 UICollectionViewCell* cell = [self.grid cellForItemAtIndexPath:cellPath]; 149 UICollectionViewCell* cell = [self.grid cellForItemAtIndexPath:cellPath];
142 return [view convertRect:cell.bounds fromView:cell]; 150 return [view convertRect:cell.bounds fromView:cell];
143 } 151 }
144 152
145 #pragma mark - SettingsActions 153 #pragma mark - SettingsActions
146 154
147 - (void)showSettings:(id)sender { 155 - (void)showSettings:(id)sender {
148 [self.settingsCommandHandler showSettings]; 156 [self.settingsCommandHandler showSettings];
149 } 157 }
150 158
151 #pragma mark - TabGridActions 159 #pragma mark - TabGridActions
152 160
153 - (void)showTabGrid:(id)sender { 161 - (void)showTabGrid:(id)sender {
154 [self.tabGridCommandHandler showTabGrid]; 162 [self.tabGridCommandHandler showTabGrid];
155 } 163 }
156 164
157 - (void)createNewTab:(id)sender { 165 - (void)createNewTab:(id)sender {
158 // PLACEHOLDER: The new WebStateList data structure will have implications 166 // PLACEHOLDER: The new WebStateList data structure will have implications
159 // on how new tabs are created. 167 // on how new tabs are created.
160 NSInteger index = [self.grid numberOfItemsInSection:0]; 168 NSInteger index = [self.grid numberOfItemsInSection:0];
161 NSIndexPath* indexPath = [NSIndexPath indexPathForItem:index inSection:0]; 169 NSIndexPath* indexPath = [NSIndexPath indexPathForItem:index inSection:0];
162 auto updateBlock = ^{ 170 auto updateBlock = ^{
171 // Unselect current selected item.
172 NSInteger selectedIndex = [self.dataSource indexOfActiveTab];
173 NSIndexPath* selectedIndexPath =
174 [NSIndexPath indexPathForItem:selectedIndex inSection:0];
175 [self.grid reloadItemsAtIndexPaths:@[ selectedIndexPath ]];
176
177 // Create and show new tab.
163 [self.tabCommandHandler createNewTabAtIndexPath:indexPath]; 178 [self.tabCommandHandler createNewTabAtIndexPath:indexPath];
164 [self.tabCommandHandler showTabAtIndexPath:indexPath]; 179 [self.tabCommandHandler showTabAtIndexPath:indexPath];
165 [self.grid insertItemsAtIndexPaths:@[ indexPath ]]; 180 [self.grid insertItemsAtIndexPaths:@[ indexPath ]];
166 }; 181 };
167 [self.grid performBatchUpdates:updateBlock completion:nil]; 182 [self.grid performBatchUpdates:updateBlock completion:nil];
168 } 183 }
169 184
170 #pragma mark - SessionCellDelegate 185 #pragma mark - SessionCellDelegate
171 186
172 - (TabSwitcherCache*)tabSwitcherCache { 187 - (TabSwitcherCache*)tabSwitcherCache {
173 // PLACEHOLDER: return image cache. 188 // PLACEHOLDER: return image cache.
174 return nil; 189 return nil;
175 } 190 }
176 191
177 - (void)cellPressed:(UICollectionViewCell*)cell { 192 - (void)cellPressed:(UICollectionViewCell*)cell {
178 [self.tabCommandHandler showTabAtIndexPath:[self.grid indexPathForCell:cell]]; 193 NSInteger selectedIndex = [self.dataSource indexOfActiveTab];
194 NSIndexPath* selectedIndexPath =
195 [NSIndexPath indexPathForItem:selectedIndex inSection:0];
196
197 NSIndexPath* newSelectedIndexPath = [self.grid indexPathForCell:cell];
198 [self.tabCommandHandler showTabAtIndexPath:newSelectedIndexPath];
199 [self.grid
200 reloadItemsAtIndexPaths:@[ selectedIndexPath, newSelectedIndexPath ]];
179 } 201 }
180 202
181 - (void)deleteButtonPressedForCell:(UICollectionViewCell*)cell { 203 - (void)deleteButtonPressedForCell:(UICollectionViewCell*)cell {
182 auto updateBlock = ^{ 204 auto updateBlock = ^{
183 NSIndexPath* indexPath = [self.grid indexPathForCell:cell]; 205 NSIndexPath* indexPath = [self.grid indexPathForCell:cell];
184 [self.tabCommandHandler closeTabAtIndexPath:indexPath]; 206 [self.tabCommandHandler closeTabAtIndexPath:indexPath];
185 [self.grid deleteItemsAtIndexPaths:@[ indexPath ]]; 207 [self.grid deleteItemsAtIndexPaths:@[ indexPath ]];
186 }; 208 };
187 [self.grid performBatchUpdates:updateBlock completion:nil]; 209 [self.grid performBatchUpdates:updateBlock completion:nil];
188 } 210 }
(...skipping 16 matching lines...) Expand all
205 [self.grid addSubview:overlayView]; 227 [self.grid addSubview:overlayView];
206 self.noTabsOverlay = overlayView; 228 self.noTabsOverlay = overlayView;
207 } 229 }
208 230
209 // Removes the noTabsOverlay covering the entire tab grid. 231 // Removes the noTabsOverlay covering the entire tab grid.
210 - (void)removeNoTabsOverlay { 232 - (void)removeNoTabsOverlay {
211 [self.noTabsOverlay removeFromSuperview]; 233 [self.noTabsOverlay removeFromSuperview];
212 } 234 }
213 235
214 @end 236 @end
OLDNEW
« no previous file with comments | « ios/clean/chrome/browser/ui/tab_grid/tab_grid_view_controller.h ('k') | ios/showcase/tab_grid/sc_tab_grid_coordinator.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698