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