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

Side by Side Diff: ios/clean/chrome/browser/ui/toolbar/toolbar_view_controller.mm

Issue 2940853003: [ios clean] Use dispatcher for showing TabStrip (Closed)
Patch Set: Refactors ToolbarVC init Created 3 years, 6 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 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_view_controller.h" 5 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_view_controller.h"
6 6
7 #import "base/mac/foundation_util.h" 7 #import "base/mac/foundation_util.h"
8 #import "ios/chrome/browser/ui/uikit_ui_util.h" 8 #import "ios/chrome/browser/ui/uikit_ui_util.h"
9 #import "ios/clean/chrome/browser/ui/actions/tab_strip_actions.h"
10 #import "ios/clean/chrome/browser/ui/commands/navigation_commands.h" 9 #import "ios/clean/chrome/browser/ui/commands/navigation_commands.h"
11 #import "ios/clean/chrome/browser/ui/commands/tab_grid_commands.h" 10 #import "ios/clean/chrome/browser/ui/commands/tab_grid_commands.h"
11 #import "ios/clean/chrome/browser/ui/commands/tab_strip_commands.h"
12 #import "ios/clean/chrome/browser/ui/commands/tools_menu_commands.h" 12 #import "ios/clean/chrome/browser/ui/commands/tools_menu_commands.h"
13 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_button+factory.h" 13 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_button+factory.h"
14 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_component_options.h" 14 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_component_options.h"
15 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_constants.h" 15 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_constants.h"
16 #import "ios/third_party/material_components_ios/src/components/ProgressView/src /MaterialProgressView.h" 16 #import "ios/third_party/material_components_ios/src/components/ProgressView/src /MaterialProgressView.h"
17 17
18 #if !defined(__has_feature) || !__has_feature(objc_arc) 18 #if !defined(__has_feature) || !__has_feature(objc_arc)
19 #error "This file requires ARC support." 19 #error "This file requires ARC support."
20 #endif 20 #endif
21 21
(...skipping 29 matching lines...) Expand all
51 - (instancetype)init { 51 - (instancetype)init {
52 self = [super init]; 52 self = [super init];
53 if (self) { 53 if (self) {
54 [self setUpToolbarButtons]; 54 [self setUpToolbarButtons];
55 [self setUpLocationBarContainer]; 55 [self setUpLocationBarContainer];
56 [self setUpProgressBar]; 56 [self setUpProgressBar];
57 } 57 }
58 return self; 58 return self;
59 } 59 }
60 60
61 - (instancetype)initWithDispatcher:(id<NavigationCommands,
62 TabGridCommands,
63 TabStripCommands,
64 ToolsMenuCommands>)dispatcher {
65 _dispatcher = dispatcher;
66 return [self init];
67 }
68
61 #pragma mark - View lifecyle 69 #pragma mark - View lifecyle
62 70
63 - (void)viewDidLoad { 71 - (void)viewDidLoad {
64 self.view.backgroundColor = UIColorFromRGB(kToolbarBackgroundColor); 72 self.view.backgroundColor = UIColorFromRGB(kToolbarBackgroundColor);
65 [self addChildViewController:self.locationBarViewController 73 [self addChildViewController:self.locationBarViewController
66 toSubview:self.locationBarContainer]; 74 toSubview:self.locationBarContainer];
67 [self setUpToolbarStackView]; 75 [self setUpToolbarStackView];
68 [self.view addSubview:self.stackView]; 76 [self.view addSubview:self.stackView];
69 [self.view addSubview:self.progressBar]; 77 [self.view addSubview:self.progressBar];
70 [self setConstraints]; 78 [self setConstraints];
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 - (void)setUpToolbarButtons { 136 - (void)setUpToolbarButtons {
129 NSMutableArray* buttonConstraints = [[NSMutableArray alloc] init]; 137 NSMutableArray* buttonConstraints = [[NSMutableArray alloc] init];
130 138
131 // Back button. 139 // Back button.
132 self.backButton = [ToolbarButton backToolbarButton]; 140 self.backButton = [ToolbarButton backToolbarButton];
133 self.backButton.visibilityMask = ToolbarComponentVisibilityCompactWidth | 141 self.backButton.visibilityMask = ToolbarComponentVisibilityCompactWidth |
134 ToolbarComponentVisibilityRegularWidth; 142 ToolbarComponentVisibilityRegularWidth;
135 [buttonConstraints 143 [buttonConstraints
136 addObject:[self.backButton.widthAnchor 144 addObject:[self.backButton.widthAnchor
137 constraintEqualToConstant:kToolbarButtonWidth]]; 145 constraintEqualToConstant:kToolbarButtonWidth]];
138 [self.backButton addTarget:self 146 [self.backButton addTarget:self.dispatcher
139 action:@selector(goBack:) 147 action:@selector(goBack)
140 forControlEvents:UIControlEventTouchUpInside]; 148 forControlEvents:UIControlEventTouchUpInside];
141 149
142 // Forward button. 150 // Forward button.
143 self.forwardButton = [ToolbarButton forwardToolbarButton]; 151 self.forwardButton = [ToolbarButton forwardToolbarButton];
144 self.forwardButton.visibilityMask = 152 self.forwardButton.visibilityMask =
145 ToolbarComponentVisibilityCompactWidthOnlyWhenEnabled | 153 ToolbarComponentVisibilityCompactWidthOnlyWhenEnabled |
146 ToolbarComponentVisibilityRegularWidth; 154 ToolbarComponentVisibilityRegularWidth;
147 [buttonConstraints 155 [buttonConstraints
148 addObject:[self.forwardButton.widthAnchor 156 addObject:[self.forwardButton.widthAnchor
149 constraintEqualToConstant:kToolbarButtonWidth]]; 157 constraintEqualToConstant:kToolbarButtonWidth]];
150 [self.forwardButton addTarget:self 158 [self.forwardButton addTarget:self.dispatcher
151 action:@selector(goForward:) 159 action:@selector(goForward)
152 forControlEvents:UIControlEventTouchUpInside]; 160 forControlEvents:UIControlEventTouchUpInside];
153 161
154 // Tab switcher Strip button. 162 // Tab switcher Strip button.
155 self.tabSwitchStripButton = [ToolbarButton tabSwitcherStripToolbarButton]; 163 self.tabSwitchStripButton = [ToolbarButton tabSwitcherStripToolbarButton];
156 self.tabSwitchStripButton.visibilityMask = 164 self.tabSwitchStripButton.visibilityMask =
157 ToolbarComponentVisibilityCompactWidth | 165 ToolbarComponentVisibilityCompactWidth |
158 ToolbarComponentVisibilityRegularWidth; 166 ToolbarComponentVisibilityRegularWidth;
159 [buttonConstraints 167 [buttonConstraints
160 addObject:[self.tabSwitchStripButton.widthAnchor 168 addObject:[self.tabSwitchStripButton.widthAnchor
161 constraintEqualToConstant:kToolbarButtonWidth]]; 169 constraintEqualToConstant:kToolbarButtonWidth]];
162 [self.tabSwitchStripButton addTarget:nil 170 [self.tabSwitchStripButton addTarget:self.dispatcher
163 action:@selector(showTabStrip:) 171 action:@selector(showTabStrip)
164 forControlEvents:UIControlEventTouchUpInside]; 172 forControlEvents:UIControlEventTouchUpInside];
165 [self.tabSwitchStripButton 173 [self.tabSwitchStripButton
166 setTitleColor:UIColorFromRGB(kToolbarButtonTitleNormalColor) 174 setTitleColor:UIColorFromRGB(kToolbarButtonTitleNormalColor)
167 forState:UIControlStateNormal]; 175 forState:UIControlStateNormal];
168 [self.tabSwitchStripButton 176 [self.tabSwitchStripButton
169 setTitleColor:UIColorFromRGB(kToolbarButtonTitleHighlightedColor) 177 setTitleColor:UIColorFromRGB(kToolbarButtonTitleHighlightedColor)
170 forState:UIControlStateHighlighted]; 178 forState:UIControlStateHighlighted];
171 179
172 // Tab switcher Grid button. 180 // Tab switcher Grid button.
173 self.tabSwitchGridButton = [ToolbarButton tabSwitcherGridToolbarButton]; 181 self.tabSwitchGridButton = [ToolbarButton tabSwitcherGridToolbarButton];
174 self.tabSwitchGridButton.visibilityMask = 182 self.tabSwitchGridButton.visibilityMask =
175 ToolbarComponentVisibilityCompactWidth | 183 ToolbarComponentVisibilityCompactWidth |
176 ToolbarComponentVisibilityRegularWidth; 184 ToolbarComponentVisibilityRegularWidth;
177 [buttonConstraints 185 [buttonConstraints
178 addObject:[self.tabSwitchGridButton.widthAnchor 186 addObject:[self.tabSwitchGridButton.widthAnchor
179 constraintEqualToConstant:kToolbarButtonWidth]]; 187 constraintEqualToConstant:kToolbarButtonWidth]];
180 [self.tabSwitchGridButton addTarget:self 188 [self.tabSwitchGridButton addTarget:self.dispatcher
181 action:@selector(showTabGrid:) 189 action:@selector(showTabGrid)
182 forControlEvents:UIControlEventTouchUpInside]; 190 forControlEvents:UIControlEventTouchUpInside];
183 self.tabSwitchGridButton.hiddenInCurrentState = YES; 191 self.tabSwitchGridButton.hiddenInCurrentState = YES;
184 192
185 // Tools menu button. 193 // Tools menu button.
186 self.toolsMenuButton = [ToolbarButton toolsMenuToolbarButton]; 194 self.toolsMenuButton = [ToolbarButton toolsMenuToolbarButton];
187 self.toolsMenuButton.visibilityMask = ToolbarComponentVisibilityCompactWidth | 195 self.toolsMenuButton.visibilityMask = ToolbarComponentVisibilityCompactWidth |
188 ToolbarComponentVisibilityRegularWidth; 196 ToolbarComponentVisibilityRegularWidth;
189 [buttonConstraints 197 [buttonConstraints
190 addObject:[self.toolsMenuButton.widthAnchor 198 addObject:[self.toolsMenuButton.widthAnchor
191 constraintEqualToConstant:kToolbarButtonWidth]]; 199 constraintEqualToConstant:kToolbarButtonWidth]];
192 [self.toolsMenuButton addTarget:self 200 [self.toolsMenuButton addTarget:self.dispatcher
193 action:@selector(showToolsMenu:) 201 action:@selector(showToolsMenu)
194 forControlEvents:UIControlEventTouchUpInside]; 202 forControlEvents:UIControlEventTouchUpInside];
195 203
196 // Share button. 204 // Share button.
197 self.shareButton = [ToolbarButton shareToolbarButton]; 205 self.shareButton = [ToolbarButton shareToolbarButton];
198 self.shareButton.visibilityMask = ToolbarComponentVisibilityRegularWidth; 206 self.shareButton.visibilityMask = ToolbarComponentVisibilityRegularWidth;
199 [buttonConstraints 207 [buttonConstraints
200 addObject:[self.shareButton.widthAnchor 208 addObject:[self.shareButton.widthAnchor
201 constraintEqualToConstant:kToolbarButtonWidth]]; 209 constraintEqualToConstant:kToolbarButtonWidth]];
202 [self.shareButton addTarget:self 210 // TODO(crbug.com/683793):Dispatch command once someone is handling it.
203 action:@selector(showShareMenu:)
204 forControlEvents:UIControlEventTouchUpInside];
205 211
206 // Reload button. 212 // Reload button.
207 self.reloadButton = [ToolbarButton reloadToolbarButton]; 213 self.reloadButton = [ToolbarButton reloadToolbarButton];
208 self.reloadButton.visibilityMask = ToolbarComponentVisibilityRegularWidth; 214 self.reloadButton.visibilityMask = ToolbarComponentVisibilityRegularWidth;
209 [buttonConstraints 215 [buttonConstraints
210 addObject:[self.reloadButton.widthAnchor 216 addObject:[self.reloadButton.widthAnchor
211 constraintEqualToConstant:kToolbarButtonWidth]]; 217 constraintEqualToConstant:kToolbarButtonWidth]];
212 [self.reloadButton addTarget:self 218 [self.reloadButton addTarget:self.dispatcher
213 action:@selector(reload:) 219 action:@selector(reloadPage)
214 forControlEvents:UIControlEventTouchUpInside]; 220 forControlEvents:UIControlEventTouchUpInside];
215 221
216 // Stop button. 222 // Stop button.
217 self.stopButton = [ToolbarButton stopToolbarButton]; 223 self.stopButton = [ToolbarButton stopToolbarButton];
218 self.stopButton.visibilityMask = ToolbarComponentVisibilityRegularWidth; 224 self.stopButton.visibilityMask = ToolbarComponentVisibilityRegularWidth;
219 [buttonConstraints 225 [buttonConstraints
220 addObject:[self.stopButton.widthAnchor 226 addObject:[self.stopButton.widthAnchor
221 constraintEqualToConstant:kToolbarButtonWidth]]; 227 constraintEqualToConstant:kToolbarButtonWidth]];
222 [self.stopButton addTarget:self 228 [self.stopButton addTarget:self.dispatcher
223 action:@selector(stop:) 229 action:@selector(stopLoadingPage)
224 forControlEvents:UIControlEventTouchUpInside]; 230 forControlEvents:UIControlEventTouchUpInside];
225 231
226 // Set the button constraint priority to UILayoutPriorityDefaultHigh so 232 // Set the button constraint priority to UILayoutPriorityDefaultHigh so
227 // these are not broken when being hidden by the StackView. 233 // these are not broken when being hidden by the StackView.
228 [self activateConstraints:buttonConstraints 234 [self activateConstraints:buttonConstraints
229 withPriority:UILayoutPriorityDefaultHigh]; 235 withPriority:UILayoutPriorityDefaultHigh];
230 } 236 }
231 237
232 - (void)setUpLocationBarContainer { 238 - (void)setUpLocationBarContainer {
233 UIView* locationBarContainer = [[UIView alloc] initWithFrame:CGRectZero]; 239 UIView* locationBarContainer = [[UIView alloc] initWithFrame:CGRectZero];
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 [self.tabSwitchStripButton setAccessibilityValue:tabStripButtonValue]; 374 [self.tabSwitchStripButton setAccessibilityValue:tabStripButtonValue];
369 } 375 }
370 376
371 #pragma mark - ZoomTransitionDelegate 377 #pragma mark - ZoomTransitionDelegate
372 378
373 - (CGRect)rectForZoomWithKey:(NSObject*)key inView:(UIView*)view { 379 - (CGRect)rectForZoomWithKey:(NSObject*)key inView:(UIView*)view {
374 return [view convertRect:self.toolsMenuButton.bounds 380 return [view convertRect:self.toolsMenuButton.bounds
375 fromView:self.toolsMenuButton]; 381 fromView:self.toolsMenuButton];
376 } 382 }
377 383
378 #pragma mark - Private Methods
379
380 - (void)showToolsMenu:(id)sender {
381 [self.dispatcher showToolsMenu];
382 }
383
384 - (void)closeToolsMenu:(id)sender {
385 [self.dispatcher closeToolsMenu];
386 }
387
388 - (void)showShareMenu:(id)sender {
389 [self.dispatcher showShareMenu];
390 }
391
392 - (void)goBack:(id)sender {
393 [self.dispatcher goBack];
394 }
395
396 - (void)goForward:(id)sender {
397 [self.dispatcher goForward];
398 }
399
400 - (void)stop:(id)sender {
401 [self.dispatcher stopLoadingPage];
402 }
403
404 - (void)reload:(id)sender {
405 [self.dispatcher reloadPage];
406 }
407
408 - (void)showTabGrid:(id)sender {
409 [self.dispatcher showTabGrid];
410 }
411
412 #pragma mark - Helper Methods 384 #pragma mark - Helper Methods
413 385
414 // Updates all Buttons visibility to match any recent WebState change. 386 // Updates all Buttons visibility to match any recent WebState change.
415 - (void)updateAllButtonsVisibility { 387 - (void)updateAllButtonsVisibility {
416 for (UIView* view in self.stackView.arrangedSubviews) { 388 for (UIView* view in self.stackView.arrangedSubviews) {
417 if ([view isKindOfClass:[ToolbarButton class]]) { 389 if ([view isKindOfClass:[ToolbarButton class]]) {
418 ToolbarButton* button = base::mac::ObjCCastStrict<ToolbarButton>(view); 390 ToolbarButton* button = base::mac::ObjCCastStrict<ToolbarButton>(view);
419 [button setHiddenForCurrentStateAndSizeClass]; 391 [button setHiddenForCurrentStateAndSizeClass];
420 } 392 }
421 } 393 }
422 } 394 }
423 395
424 // Sets the priority for an array of constraints and activates them. 396 // Sets the priority for an array of constraints and activates them.
425 - (void)activateConstraints:(NSArray*)constraintsArray 397 - (void)activateConstraints:(NSArray*)constraintsArray
426 withPriority:(UILayoutPriority)priority { 398 withPriority:(UILayoutPriority)priority {
427 for (NSLayoutConstraint* constraint in constraintsArray) { 399 for (NSLayoutConstraint* constraint in constraintsArray) {
428 constraint.priority = priority; 400 constraint.priority = priority;
429 } 401 }
430 [NSLayoutConstraint activateConstraints:constraintsArray]; 402 [NSLayoutConstraint activateConstraints:constraintsArray];
431 } 403 }
432 404
433 @end 405 @end
OLDNEW
« no previous file with comments | « ios/clean/chrome/browser/ui/toolbar/toolbar_view_controller.h ('k') | ios/showcase/toolbar/sc_toolbar_coordinator.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698