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/chrome/browser/ui/uikit_ui_util.h" | |
| 8 #import "ios/clean/chrome/browser/ui/actions/tab_strip_actions.h" | 9 #import "ios/clean/chrome/browser/ui/actions/tab_strip_actions.h" |
| 9 #import "ios/clean/chrome/browser/ui/commands/navigation_commands.h" | 10 #import "ios/clean/chrome/browser/ui/commands/navigation_commands.h" |
| 10 #import "ios/clean/chrome/browser/ui/commands/tab_grid_commands.h" | 11 #import "ios/clean/chrome/browser/ui/commands/tab_grid_commands.h" |
| 11 #import "ios/clean/chrome/browser/ui/commands/tools_menu_commands.h" | 12 #import "ios/clean/chrome/browser/ui/commands/tools_menu_commands.h" |
| 12 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_button+factory.h" | 13 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_button+factory.h" |
| 13 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_component_options.h" | 14 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_component_options.h" |
| 14 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_constants.h" | 15 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_constants.h" |
| 15 #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" |
| 16 | 17 |
| 17 #if !defined(__has_feature) || !__has_feature(objc_arc) | 18 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 [self setUpToolbarButtons]; | 54 [self setUpToolbarButtons]; |
| 54 [self setUpLocationBarContainer]; | 55 [self setUpLocationBarContainer]; |
| 55 [self setUpProgressBar]; | 56 [self setUpProgressBar]; |
| 56 } | 57 } |
| 57 return self; | 58 return self; |
| 58 } | 59 } |
| 59 | 60 |
| 60 #pragma mark - View lifecyle | 61 #pragma mark - View lifecyle |
| 61 | 62 |
| 62 - (void)viewDidLoad { | 63 - (void)viewDidLoad { |
| 63 self.view.backgroundColor = | 64 self.view.backgroundColor = UIColorFromRGB(kToolbarBackgroundColor); |
| 64 [UIColor colorWithWhite:kToolbarBackgroundBrightness alpha:1.0]; | |
| 65 [self addChildViewController:self.locationBarViewController | 65 [self addChildViewController:self.locationBarViewController |
| 66 toSubview:self.locationBarContainer]; | 66 toSubview:self.locationBarContainer]; |
| 67 [self setUpToolbarStackView]; | 67 [self setUpToolbarStackView]; |
| 68 [self.view addSubview:self.stackView]; | 68 [self.view addSubview:self.stackView]; |
| 69 [self.view addSubview:self.progressBar]; | 69 [self.view addSubview:self.progressBar]; |
| 70 [self setConstraints]; | 70 [self setConstraints]; |
| 71 } | 71 } |
| 72 | 72 |
| 73 #pragma mark - View Setup | 73 #pragma mark - View Setup |
| 74 | 74 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 self.tabSwitchStripButton = [ToolbarButton tabSwitcherStripToolbarButton]; | 155 self.tabSwitchStripButton = [ToolbarButton tabSwitcherStripToolbarButton]; |
| 156 self.tabSwitchStripButton.visibilityMask = | 156 self.tabSwitchStripButton.visibilityMask = |
| 157 ToolbarComponentVisibilityCompactWidth | | 157 ToolbarComponentVisibilityCompactWidth | |
| 158 ToolbarComponentVisibilityRegularWidth; | 158 ToolbarComponentVisibilityRegularWidth; |
| 159 [buttonConstraints | 159 [buttonConstraints |
| 160 addObject:[self.tabSwitchStripButton.widthAnchor | 160 addObject:[self.tabSwitchStripButton.widthAnchor |
| 161 constraintEqualToConstant:kToolbarButtonWidth]]; | 161 constraintEqualToConstant:kToolbarButtonWidth]]; |
| 162 [self.tabSwitchStripButton addTarget:nil | 162 [self.tabSwitchStripButton addTarget:nil |
| 163 action:@selector(showTabStrip:) | 163 action:@selector(showTabStrip:) |
| 164 forControlEvents:UIControlEventTouchUpInside]; | 164 forControlEvents:UIControlEventTouchUpInside]; |
| 165 [self.tabSwitchStripButton | |
| 166 setTitleColor:UIColorFromRGB(kToolbarButtonTitleNormalColor) | |
| 167 forState:UIControlStateNormal]; | |
| 168 [self.tabSwitchStripButton | |
| 169 setTitleColor:UIColorFromRGB(kToolbarButtonTitleHighlightedColor) | |
| 170 forState:UIControlStateHighlighted]; | |
| 165 | 171 |
| 166 // Tab switcher Grid button. | 172 // Tab switcher Grid button. |
| 167 self.tabSwitchGridButton = [ToolbarButton tabSwitcherGridToolbarButton]; | 173 self.tabSwitchGridButton = [ToolbarButton tabSwitcherGridToolbarButton]; |
| 168 self.tabSwitchGridButton.visibilityMask = | 174 self.tabSwitchGridButton.visibilityMask = |
| 169 ToolbarComponentVisibilityCompactWidth | | 175 ToolbarComponentVisibilityCompactWidth | |
| 170 ToolbarComponentVisibilityRegularWidth; | 176 ToolbarComponentVisibilityRegularWidth; |
| 171 [buttonConstraints | 177 [buttonConstraints |
| 172 addObject:[self.tabSwitchGridButton.widthAnchor | 178 addObject:[self.tabSwitchGridButton.widthAnchor |
| 173 constraintEqualToConstant:kToolbarButtonWidth]]; | 179 constraintEqualToConstant:kToolbarButtonWidth]]; |
| 174 [self.tabSwitchGridButton addTarget:self | 180 [self.tabSwitchGridButton addTarget:self |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 // Stop button. | 216 // Stop button. |
| 211 self.stopButton = [ToolbarButton stopToolbarButton]; | 217 self.stopButton = [ToolbarButton stopToolbarButton]; |
| 212 self.stopButton.visibilityMask = ToolbarComponentVisibilityRegularWidth; | 218 self.stopButton.visibilityMask = ToolbarComponentVisibilityRegularWidth; |
| 213 [buttonConstraints | 219 [buttonConstraints |
| 214 addObject:[self.stopButton.widthAnchor | 220 addObject:[self.stopButton.widthAnchor |
| 215 constraintEqualToConstant:kToolbarButtonWidth]]; | 221 constraintEqualToConstant:kToolbarButtonWidth]]; |
| 216 [self.stopButton addTarget:self | 222 [self.stopButton addTarget:self |
| 217 action:@selector(stop:) | 223 action:@selector(stop:) |
| 218 forControlEvents:UIControlEventTouchUpInside]; | 224 forControlEvents:UIControlEventTouchUpInside]; |
| 219 | 225 |
| 220 // // Set the buttons constraints priority to UILayoutPriorityDefaultHigh so | 226 // Set the button constraint priority to UILayoutPriorityDefaultHigh so |
| 221 // these are not broken when being hidden by the StackView. | 227 // these are not broken when being hidden by the StackView. |
| 222 [self activateConstraints:buttonConstraints | 228 [self activateConstraints:buttonConstraints |
| 223 withPriority:UILayoutPriorityDefaultHigh]; | 229 withPriority:UILayoutPriorityDefaultHigh]; |
| 224 } | 230 } |
| 225 | 231 |
| 226 - (void)setUpLocationBarContainer { | 232 - (void)setUpLocationBarContainer { |
| 227 UIView* locationBarContainer = [[UIView alloc] initWithFrame:CGRectZero]; | 233 UIView* locationBarContainer = [[UIView alloc] initWithFrame:CGRectZero]; |
| 228 locationBarContainer.translatesAutoresizingMaskIntoConstraints = NO; | 234 locationBarContainer.translatesAutoresizingMaskIntoConstraints = NO; |
| 229 locationBarContainer.backgroundColor = [UIColor whiteColor]; | 235 locationBarContainer.backgroundColor = [UIColor whiteColor]; |
| 230 locationBarContainer.layer.borderWidth = kLocationBarBorderWidth; | 236 locationBarContainer.layer.borderWidth = kLocationBarBorderWidth; |
| 231 locationBarContainer.layer.borderColor = | 237 locationBarContainer.layer.borderColor = |
| 232 [UIColor colorWithWhite:kLocationBarBorderColorBrightness alpha:1.0] | 238 UIColorFromRGB(kLocationBarBorderColor).CGColor; |
| 233 .CGColor; | |
| 234 locationBarContainer.layer.shadowRadius = kLocationBarShadowRadius; | 239 locationBarContainer.layer.shadowRadius = kLocationBarShadowRadius; |
| 235 locationBarContainer.layer.shadowOpacity = kLocationBarShadowOpacity; | 240 locationBarContainer.layer.shadowOpacity = kLocationBarShadowOpacity; |
| 236 locationBarContainer.layer.shadowOffset = CGSizeMake(0.0f, 0.5f); | 241 locationBarContainer.layer.shadowOffset = CGSizeMake(0.0f, 0.5f); |
| 237 | 242 |
| 238 [locationBarContainer | 243 [locationBarContainer |
| 239 setContentHuggingPriority:UILayoutPriorityDefaultLow | 244 setContentHuggingPriority:UILayoutPriorityDefaultLow |
| 240 forAxis:UILayoutConstraintAxisHorizontal]; | 245 forAxis:UILayoutConstraintAxisHorizontal]; |
| 241 self.locationBarContainer = locationBarContainer; | 246 self.locationBarContainer = locationBarContainer; |
| 242 } | 247 } |
| 243 | 248 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 322 - (void)setLoadingProgress:(double)progress { | 327 - (void)setLoadingProgress:(double)progress { |
| 323 [self.progressBar setProgress:progress animated:YES completion:nil]; | 328 [self.progressBar setProgress:progress animated:YES completion:nil]; |
| 324 } | 329 } |
| 325 | 330 |
| 326 - (void)setTabStripVisible:(BOOL)visible { | 331 - (void)setTabStripVisible:(BOOL)visible { |
| 327 self.tabSwitchStripButton.hiddenInCurrentState = visible; | 332 self.tabSwitchStripButton.hiddenInCurrentState = visible; |
| 328 self.tabSwitchGridButton.hiddenInCurrentState = !visible; | 333 self.tabSwitchGridButton.hiddenInCurrentState = !visible; |
| 329 [self updateAllButtonsVisibility]; | 334 [self updateAllButtonsVisibility]; |
| 330 } | 335 } |
| 331 | 336 |
| 337 - (void)setTabCount:(int)tabCount { | |
| 338 // Return if tabSwitchStripButton wasn't initialized. | |
| 339 if (!self.tabSwitchStripButton) | |
| 340 return; | |
| 341 | |
| 342 // Update the text shown in the |self.tabSwitchStripButton|. Note that the | |
| 343 // button's title may be empty or contain an easter egg, but the accessibility | |
| 344 // value will always be equal to |tabCount|. | |
| 345 NSString* tabStripButtonValue = [NSString stringWithFormat:@"%d", tabCount]; | |
| 346 NSString* tabStripButtonTitle; | |
| 347 if (tabCount <= 0) { | |
| 348 tabStripButtonTitle = @""; | |
| 349 } else if (tabCount > kShowTabStripButtonMaxTabCount) { | |
| 350 tabStripButtonTitle = @":)"; | |
|
marq (ping after 24h)
2017/05/31 09:47:26
Just for clarity, I'd add a comment here to the ef
sczs
2017/05/31 23:19:07
Done.
| |
| 351 [[self.tabSwitchStripButton titleLabel] | |
| 352 setFont:[UIFont boldSystemFontOfSize:kFontSizeFewerThanTenTabs]]; | |
| 353 } else { | |
| 354 tabStripButtonTitle = tabStripButtonValue; | |
| 355 if (tabCount < 10) { | |
| 356 [[self.tabSwitchStripButton titleLabel] | |
| 357 setFont:[UIFont boldSystemFontOfSize:kFontSizeFewerThanTenTabs]]; | |
| 358 } else { | |
| 359 [[self.tabSwitchStripButton titleLabel] | |
| 360 setFont:[UIFont boldSystemFontOfSize:kFontSizeTenTabsOrMore]]; | |
| 361 } | |
| 362 } | |
| 363 | |
| 364 [self.tabSwitchStripButton setTitle:tabStripButtonTitle | |
| 365 forState:UIControlStateNormal]; | |
| 366 [self.tabSwitchStripButton setAccessibilityValue:tabStripButtonValue]; | |
| 367 } | |
| 368 | |
| 332 #pragma mark - ZoomTransitionDelegate | 369 #pragma mark - ZoomTransitionDelegate |
| 333 | 370 |
| 334 - (CGRect)rectForZoomWithKey:(NSObject*)key inView:(UIView*)view { | 371 - (CGRect)rectForZoomWithKey:(NSObject*)key inView:(UIView*)view { |
| 335 return [view convertRect:self.toolsMenuButton.bounds | 372 return [view convertRect:self.toolsMenuButton.bounds |
| 336 fromView:self.toolsMenuButton]; | 373 fromView:self.toolsMenuButton]; |
| 337 } | 374 } |
| 338 | 375 |
| 339 #pragma mark - Private Methods | 376 #pragma mark - Private Methods |
| 340 | 377 |
| 341 - (void)showToolsMenu:(id)sender { | 378 - (void)showToolsMenu:(id)sender { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 385 // Sets the priority for an array of constraints and activates them. | 422 // Sets the priority for an array of constraints and activates them. |
| 386 - (void)activateConstraints:(NSArray*)constraintsArray | 423 - (void)activateConstraints:(NSArray*)constraintsArray |
| 387 withPriority:(UILayoutPriority)priority { | 424 withPriority:(UILayoutPriority)priority { |
| 388 for (NSLayoutConstraint* constraint in constraintsArray) { | 425 for (NSLayoutConstraint* constraint in constraintsArray) { |
| 389 constraint.priority = priority; | 426 constraint.priority = priority; |
| 390 } | 427 } |
| 391 [NSLayoutConstraint activateConstraints:constraintsArray]; | 428 [NSLayoutConstraint activateConstraints:constraintsArray]; |
| 392 } | 429 } |
| 393 | 430 |
| 394 @end | 431 @end |
| OLD | NEW |