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

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

Issue 2588733002: Upstream Chrome on iOS source code [9/11]. (Closed)
Patch Set: Created 4 years 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
(Empty)
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
3 // found in the LICENSE file.
4
5 // ====== New Architecture =====
6 // = This code is only used in the new iOS Chrome architecture. =
7 // ============================================================================
8
9 #import "ios/chrome/browser/ui/tab_grid/tab_grid_view_controller.h"
10
11 #include "base/mac/foundation_util.h"
12 #import "ios/chrome/browser/ui/actions/settings_actions.h"
13 #import "ios/chrome/browser/ui/actions/tab_grid_actions.h"
14 #import "ios/chrome/browser/ui/tab_grid/tab_grid_tab_cell.h"
15
16 #if !defined(__has_feature) || !__has_feature(objc_arc)
17 #error "This file requires ARC support."
18 #endif
19
20 namespace {
21 NSString* const kTabGridCellIdentifier = @"tabGridCell";
22 const CGFloat kSpace = 20;
23 const CGFloat kTabSize = 150;
24 }
25
26 @interface TabGridViewController ()<SettingsActions,
27 TabGridActions,
28 UICollectionViewDataSource,
29 UICollectionViewDelegate>
30 @property(nonatomic, weak) UICollectionView* grid;
31 @end
32
33 @implementation TabGridViewController
34
35 @synthesize dataSource = _dataSource;
36 @synthesize actionDelegate = _actionDelegate;
37 @synthesize grid = _grid;
38
39 - (void)viewDidLoad {
40 // Placeholder dark grey stripe at the top of the view.
41 UIView* stripe = [[UIView alloc] initWithFrame:CGRectZero];
42 stripe.translatesAutoresizingMaskIntoConstraints = NO;
43 stripe.backgroundColor = [UIColor darkGrayColor];
44 [self.view addSubview:stripe];
45
46 // Placeholder settings button at in the stripe.
47 UIButton* settings = [UIButton buttonWithType:UIButtonTypeSystem];
48 settings.translatesAutoresizingMaskIntoConstraints = NO;
49 [settings setTitle:@"⚙" forState:UIControlStateNormal];
50 settings.titleLabel.font = [UIFont systemFontOfSize:24.0];
51 [settings addTarget:nil
52 action:@selector(showSettings:)
53 forControlEvents:UIControlEventTouchUpInside];
54 [stripe addSubview:settings];
55
56 [NSLayoutConstraint activateConstraints:@[
57 [stripe.heightAnchor constraintEqualToConstant:64.0],
58 [stripe.widthAnchor constraintEqualToAnchor:self.view.widthAnchor],
59 [stripe.topAnchor constraintEqualToAnchor:self.view.topAnchor],
60 [stripe.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor],
61 [settings.leadingAnchor
62 constraintEqualToAnchor:stripe.layoutMarginsGuide.leadingAnchor],
63 [settings.centerYAnchor constraintEqualToAnchor:stripe.centerYAnchor]
64 ]];
65
66 UICollectionViewFlowLayout* layout =
67 [[UICollectionViewFlowLayout alloc] init];
68 layout.minimumLineSpacing = kSpace;
69 layout.minimumInteritemSpacing = kSpace;
70 layout.sectionInset = UIEdgeInsetsMake(kSpace, kSpace, kSpace, kSpace);
71 layout.itemSize = CGSizeMake(kTabSize, kTabSize);
72
73 UICollectionView* grid = [[UICollectionView alloc] initWithFrame:CGRectZero
74 collectionViewLayout:layout];
75 grid.translatesAutoresizingMaskIntoConstraints = NO;
76 grid.backgroundColor = [UIColor blackColor];
77
78 [self.view addSubview:grid];
79 self.grid = grid;
80 self.grid.dataSource = self;
81 self.grid.delegate = self;
82 [self.grid registerClass:[TabGridTabCell class]
83 forCellWithReuseIdentifier:kTabGridCellIdentifier];
84
85 [NSLayoutConstraint activateConstraints:@[
86 [self.grid.topAnchor constraintEqualToAnchor:stripe.bottomAnchor],
87 [self.grid.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor],
88 [self.grid.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
89 [self.grid.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor],
90 ]];
91 }
92
93 - (void)viewWillAppear:(BOOL)animated {
94 [self.grid reloadData];
95 }
96
97 #pragma mark - UICollectionViewDataSource methods
98
99 - (NSInteger)numberOfSectionsInCollectionView:
100 (UICollectionView*)collectionView {
101 return 1;
102 }
103
104 - (NSInteger)collectionView:(UICollectionView*)collectionView
105 numberOfItemsInSection:(NSInteger)section {
106 return [self.dataSource numberOfTabsInTabGrid];
107 }
108
109 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView
110 cellForItemAtIndexPath:(nonnull NSIndexPath*)indexPath {
111 TabGridTabCell* cell =
112 base::mac::ObjCCastStrict<TabGridTabCell>([collectionView
113 dequeueReusableCellWithReuseIdentifier:kTabGridCellIdentifier
114 forIndexPath:indexPath]);
115 cell.contentView.backgroundColor = [UIColor purpleColor];
116 cell.selected = YES;
117 cell.label.text = [self.dataSource titleAtIndex:indexPath.item];
118 return cell;
119 }
120
121 #pragma mark - UICollectionViewDelegate methods
122
123 - (void)collectionView:(UICollectionView*)collectionView
124 didSelectItemAtIndexPath:(NSIndexPath*)indexPath {
125 [self.actionDelegate showTabAtIndexPath:indexPath];
126 }
127
128 #pragma mark - ZoomTransitionDelegate methods
129
130 - (CGRect)rectForZoomWithKey:(NSObject*)key inView:(UIView*)view {
131 NSIndexPath* cellPath = base::mac::ObjCCastStrict<NSIndexPath>(key);
132 if (!key)
133 return CGRectNull;
134 UICollectionViewCell* cell = [self.grid cellForItemAtIndexPath:cellPath];
135 return [view convertRect:cell.bounds fromView:cell];
136 }
137
138 #pragma mark - SettingsActions
139
140 - (void)showSettings:(id)sender {
141 [self.actionDelegate showSettings];
142 }
143
144 #pragma mark - TabGridActions
145
146 - (void)showTabGrid:(id)sender {
147 [self.actionDelegate showTabGrid];
148 }
149
150 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/tab_grid/tab_grid_view_controller.h ('k') | ios/chrome/browser/ui/tab_switcher/session_changes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698