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

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

Issue 2859363002: [ios clean] Adds Progress Bar to Toolbar. (Closed)
Patch Set: Uses MDCProgressView and adds unittest. Created 3 years, 7 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/clean/chrome/browser/ui/actions/tab_strip_actions.h" 8 #import "ios/clean/chrome/browser/ui/actions/tab_strip_actions.h"
9 #import "ios/clean/chrome/browser/ui/commands/navigation_commands.h" 9 #import "ios/clean/chrome/browser/ui/commands/navigation_commands.h"
10 #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/tools_menu_commands.h" 11 #import "ios/clean/chrome/browser/ui/commands/tools_menu_commands.h"
12 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_button+factory.h" 12 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_button+factory.h"
13 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_component_options.h" 13 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_component_options.h"
14 #import "ios/third_party/material_components_ios/src/components/ProgressView/src /MaterialProgressView.h"
14 15
15 #if !defined(__has_feature) || !__has_feature(objc_arc) 16 #if !defined(__has_feature) || !__has_feature(objc_arc)
16 #error "This file requires ARC support." 17 #error "This file requires ARC support."
17 #endif 18 #endif
18 19
19 namespace { 20 namespace {
20 // Stackview Vertical Margin. 21 // Stackview Vertical Margin.
21 CGFloat kVerticalMargin = 5.0f; 22 CGFloat kVerticalMargin = 5.0f;
22 // Stackview Horizontal Margin. 23 // Stackview Horizontal Margin.
23 CGFloat kHorizontalMargin = 8.0f; 24 CGFloat kHorizontalMargin = 8.0f;
25 // Progress Bar Height.
26 CGFloat kProgressBarHeight = 2.0f;
24 } // namespace 27 } // namespace
25 28
26 @interface ToolbarViewController () 29 @interface ToolbarViewController ()
27 @property(nonatomic, strong) UIView* locationBarContainer; 30 @property(nonatomic, strong) UIView* locationBarContainer;
28 @property(nonatomic, strong) UIStackView* stackView; 31 @property(nonatomic, strong) UIStackView* stackView;
29 @property(nonatomic, strong) ToolbarButton* backButton; 32 @property(nonatomic, strong) ToolbarButton* backButton;
30 @property(nonatomic, strong) ToolbarButton* forwardButton; 33 @property(nonatomic, strong) ToolbarButton* forwardButton;
31 @property(nonatomic, strong) ToolbarButton* tabSwitchStripButton; 34 @property(nonatomic, strong) ToolbarButton* tabSwitchStripButton;
32 @property(nonatomic, strong) ToolbarButton* tabSwitchGridButton; 35 @property(nonatomic, strong) ToolbarButton* tabSwitchGridButton;
33 @property(nonatomic, strong) ToolbarButton* toolsMenuButton; 36 @property(nonatomic, strong) ToolbarButton* toolsMenuButton;
34 @property(nonatomic, strong) ToolbarButton* shareButton; 37 @property(nonatomic, strong) ToolbarButton* shareButton;
35 @property(nonatomic, strong) ToolbarButton* reloadButton; 38 @property(nonatomic, strong) ToolbarButton* reloadButton;
36 @property(nonatomic, strong) ToolbarButton* stopButton; 39 @property(nonatomic, strong) ToolbarButton* stopButton;
40 @property(nonatomic, strong) MDCProgressView* progressBar;
37 @end 41 @end
38 42
39 @implementation ToolbarViewController 43 @implementation ToolbarViewController
40 @synthesize dispatcher = _dispatcher; 44 @synthesize dispatcher = _dispatcher;
41 @synthesize locationBarViewController = _locationBarViewController; 45 @synthesize locationBarViewController = _locationBarViewController;
42 @synthesize stackView = _stackView; 46 @synthesize stackView = _stackView;
43 @synthesize locationBarContainer = _locationBarContainer; 47 @synthesize locationBarContainer = _locationBarContainer;
44 @synthesize backButton = _backButton; 48 @synthesize backButton = _backButton;
45 @synthesize forwardButton = _forwardButton; 49 @synthesize forwardButton = _forwardButton;
46 @synthesize tabSwitchStripButton = _tabSwitchStripButton; 50 @synthesize tabSwitchStripButton = _tabSwitchStripButton;
47 @synthesize tabSwitchGridButton = _tabSwitchGridButton; 51 @synthesize tabSwitchGridButton = _tabSwitchGridButton;
48 @synthesize toolsMenuButton = _toolsMenuButton; 52 @synthesize toolsMenuButton = _toolsMenuButton;
49 @synthesize shareButton = _shareButton; 53 @synthesize shareButton = _shareButton;
50 @synthesize reloadButton = _reloadButton; 54 @synthesize reloadButton = _reloadButton;
51 @synthesize stopButton = _stopButton; 55 @synthesize stopButton = _stopButton;
56 @synthesize progressBar = _progressBar;
52 57
53 - (instancetype)init { 58 - (instancetype)init {
54 self = [super init]; 59 self = [super init];
55 if (self) { 60 if (self) {
56 [self setUpToolbarButtons]; 61 [self setUpToolbarButtons];
57 [self setUpLocationBarContainer]; 62 [self setUpLocationBarContainer];
63 [self setUpProgressBar];
58 } 64 }
59 return self; 65 return self;
60 } 66 }
61 67
62 - (void)viewDidLoad { 68 - (void)viewDidLoad {
63 self.view.backgroundColor = [UIColor lightGrayColor]; 69 self.view.backgroundColor = [UIColor lightGrayColor];
64
65 [self addChildViewController:self.locationBarViewController 70 [self addChildViewController:self.locationBarViewController
66 toSubview:self.locationBarContainer]; 71 toSubview:self.locationBarContainer];
72 [self setUpToolbarStackView];
73 [self.view addSubview:self.stackView];
74 [self.view addSubview:self.progressBar];
75 [self setConstraints];
76 }
67 77
68 // Stack view to contain toolbar items. 78 #pragma mark - View Setup
79
80 // Sets up the StackView that contains toolbar navigation items.
81 - (void)setUpToolbarStackView {
69 self.stackView = [[UIStackView alloc] initWithArrangedSubviews:@[ 82 self.stackView = [[UIStackView alloc] initWithArrangedSubviews:@[
70 self.backButton, self.forwardButton, self.reloadButton, self.stopButton, 83 self.backButton, self.forwardButton, self.reloadButton, self.stopButton,
71 self.locationBarContainer, self.shareButton, self.tabSwitchStripButton, 84 self.locationBarContainer, self.shareButton, self.tabSwitchStripButton,
72 self.tabSwitchGridButton, self.toolsMenuButton 85 self.tabSwitchGridButton, self.toolsMenuButton
73 ]]; 86 ]];
74 [self updateAllButtonsVisibility];
75 self.stackView.translatesAutoresizingMaskIntoConstraints = NO; 87 self.stackView.translatesAutoresizingMaskIntoConstraints = NO;
76 self.stackView.spacing = 16.0; 88 self.stackView.spacing = 16.0;
77 self.stackView.distribution = UIStackViewDistributionFill; 89 self.stackView.distribution = UIStackViewDistributionFill;
78 [self.view addSubview:self.stackView]; 90 [self updateAllButtonsVisibility];
91 }
79 92
80 // Set constraints. 93 - (void)setConstraints {
81 [self.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth | 94 [self.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth |
82 UIViewAutoresizingFlexibleHeight]; 95 UIViewAutoresizingFlexibleHeight];
83 [NSLayoutConstraint activateConstraints:@[ 96 [NSLayoutConstraint activateConstraints:@[
84 [self.stackView.topAnchor constraintEqualToAnchor:self.view.topAnchor 97 [self.stackView.topAnchor constraintEqualToAnchor:self.view.topAnchor
85 constant:kVerticalMargin], 98 constant:kVerticalMargin],
86 [self.stackView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor 99 [self.stackView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor
87 constant:-kVerticalMargin], 100 constant:-kVerticalMargin],
88 [self.stackView.leadingAnchor 101 [self.stackView.leadingAnchor
89 constraintEqualToAnchor:self.view.leadingAnchor 102 constraintEqualToAnchor:self.view.leadingAnchor
90 constant:kHorizontalMargin], 103 constant:kHorizontalMargin],
91 [self.stackView.trailingAnchor 104 [self.stackView.trailingAnchor
92 constraintEqualToAnchor:self.view.trailingAnchor 105 constraintEqualToAnchor:self.view.trailingAnchor
93 constant:-kHorizontalMargin], 106 constant:-kHorizontalMargin],
107 [self.progressBar.leadingAnchor
108 constraintEqualToAnchor:self.view.leadingAnchor],
109 [self.progressBar.trailingAnchor
110 constraintEqualToAnchor:self.view.trailingAnchor],
111 [self.progressBar.bottomAnchor
112 constraintEqualToAnchor:self.view.bottomAnchor],
113 [self.progressBar.heightAnchor
114 constraintEqualToConstant:kProgressBarHeight],
94 ]]; 115 ]];
95 } 116 }
96 117
97 #pragma mark - Components Setup 118 #pragma mark - Components Setup
98 119
99 - (void)setUpToolbarButtons { 120 - (void)setUpToolbarButtons {
100 // Back button. 121 // Back button.
101 self.backButton = [ToolbarButton backToolbarButton]; 122 self.backButton = [ToolbarButton backToolbarButton];
102 self.backButton.visibilityMask = ToolbarComponentVisibilityCompactWidth | 123 self.backButton.visibilityMask = ToolbarComponentVisibilityCompactWidth |
103 ToolbarComponentVisibilityRegularWidth; 124 ToolbarComponentVisibilityRegularWidth;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 - (void)setUpLocationBarContainer { 187 - (void)setUpLocationBarContainer {
167 UIView* locationBarContainer = [[UIView alloc] initWithFrame:CGRectZero]; 188 UIView* locationBarContainer = [[UIView alloc] initWithFrame:CGRectZero];
168 locationBarContainer.translatesAutoresizingMaskIntoConstraints = NO; 189 locationBarContainer.translatesAutoresizingMaskIntoConstraints = NO;
169 locationBarContainer.backgroundColor = [UIColor whiteColor]; 190 locationBarContainer.backgroundColor = [UIColor whiteColor];
170 [locationBarContainer 191 [locationBarContainer
171 setContentHuggingPriority:UILayoutPriorityDefaultLow 192 setContentHuggingPriority:UILayoutPriorityDefaultLow
172 forAxis:UILayoutConstraintAxisHorizontal]; 193 forAxis:UILayoutConstraintAxisHorizontal];
173 self.locationBarContainer = locationBarContainer; 194 self.locationBarContainer = locationBarContainer;
174 } 195 }
175 196
197 - (void)setUpProgressBar {
198 MDCProgressView* progressBar = [[MDCProgressView alloc] init];
199 progressBar.translatesAutoresizingMaskIntoConstraints = NO;
200 progressBar.hidden = YES;
201 self.progressBar = progressBar;
202 }
203
176 #pragma mark - View Controller Containment 204 #pragma mark - View Controller Containment
177 205
178 - (void)addChildViewController:(UIViewController*)viewController 206 - (void)addChildViewController:(UIViewController*)viewController
179 toSubview:(UIView*)subview { 207 toSubview:(UIView*)subview {
180 if (!viewController || !subview) { 208 if (!viewController || !subview) {
181 return; 209 return;
182 } 210 }
183 [self addChildViewController:viewController]; 211 [self addChildViewController:viewController];
184 viewController.view.translatesAutoresizingMaskIntoConstraints = YES; 212 viewController.view.translatesAutoresizingMaskIntoConstraints = YES;
185 viewController.view.autoresizingMask = 213 viewController.view.autoresizingMask =
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 if ([view isKindOfClass:[ToolbarButton class]]) { 247 if ([view isKindOfClass:[ToolbarButton class]]) {
220 ToolbarButton* button = base::mac::ObjCCastStrict<ToolbarButton>(view); 248 ToolbarButton* button = base::mac::ObjCCastStrict<ToolbarButton>(view);
221 [button updateHiddenInCurrentSizeClass]; 249 [button updateHiddenInCurrentSizeClass];
222 } 250 }
223 } 251 }
224 } 252 }
225 } 253 }
226 254
227 #pragma mark - ToolbarWebStateConsumer 255 #pragma mark - ToolbarWebStateConsumer
228 256
229 - (void)setCurrentPageText:(NSString*)text {
230 }
231
232 - (void)setCanGoForward:(BOOL)canGoForward { 257 - (void)setCanGoForward:(BOOL)canGoForward {
233 self.forwardButton.enabled = canGoForward; 258 self.forwardButton.enabled = canGoForward;
234 // Update the visibility since the Forward button will be hidden on 259 // Update the visibility since the Forward button will be hidden on
235 // CompactWidth when disabled. 260 // CompactWidth when disabled.
236 [self.forwardButton updateHiddenInCurrentSizeClass]; 261 [self.forwardButton updateHiddenInCurrentSizeClass];
237 } 262 }
238 263
239 - (void)setCanGoBack:(BOOL)canGoBack { 264 - (void)setCanGoBack:(BOOL)canGoBack {
240 self.backButton.enabled = canGoBack; 265 self.backButton.enabled = canGoBack;
241 } 266 }
242 267
243 - (void)setIsLoading:(BOOL)isLoading { 268 - (void)setIsLoading:(BOOL)isLoading {
244 self.reloadButton.hiddenInCurrentState = isLoading; 269 self.reloadButton.hiddenInCurrentState = isLoading;
245 self.stopButton.hiddenInCurrentState = !isLoading; 270 self.stopButton.hiddenInCurrentState = !isLoading;
271 [self.progressBar setHidden:!isLoading animated:YES completion:nil];
246 [self updateAllButtonsVisibility]; 272 [self updateAllButtonsVisibility];
247 } 273 }
248 274
275 - (void)setLoadingProgress:(double)progress {
276 [self.progressBar setProgress:progress animated:YES completion:nil];
277 }
278
249 #pragma mark - ZoomTransitionDelegate 279 #pragma mark - ZoomTransitionDelegate
250 280
251 - (CGRect)rectForZoomWithKey:(NSObject*)key inView:(UIView*)view { 281 - (CGRect)rectForZoomWithKey:(NSObject*)key inView:(UIView*)view {
252 return [view convertRect:self.toolsMenuButton.bounds 282 return [view convertRect:self.toolsMenuButton.bounds
253 fromView:self.toolsMenuButton]; 283 fromView:self.toolsMenuButton];
254 } 284 }
255 285
256 #pragma mark - Private Methods 286 #pragma mark - Private Methods
257 287
258 - (void)showToolsMenu:(id)sender { 288 - (void)showToolsMenu:(id)sender {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 - (void)updateAllButtonsVisibility { 337 - (void)updateAllButtonsVisibility {
308 for (UIView* view in self.stackView.arrangedSubviews) { 338 for (UIView* view in self.stackView.arrangedSubviews) {
309 if ([view isKindOfClass:[ToolbarButton class]]) { 339 if ([view isKindOfClass:[ToolbarButton class]]) {
310 ToolbarButton* button = base::mac::ObjCCastStrict<ToolbarButton>(view); 340 ToolbarButton* button = base::mac::ObjCCastStrict<ToolbarButton>(view);
311 [button setHiddenForCurrentStateAndSizeClass]; 341 [button setHiddenForCurrentStateAndSizeClass];
312 } 342 }
313 } 343 }
314 } 344 }
315 345
316 @end 346 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698