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" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 @property(nonatomic, strong) UIView* locationBarContainer; | 27 @property(nonatomic, strong) UIView* locationBarContainer; |
| 28 @property(nonatomic, strong) UIStackView* stackView; | 28 @property(nonatomic, strong) UIStackView* stackView; |
| 29 @property(nonatomic, strong) ToolbarButton* backButton; | 29 @property(nonatomic, strong) ToolbarButton* backButton; |
| 30 @property(nonatomic, strong) ToolbarButton* forwardButton; | 30 @property(nonatomic, strong) ToolbarButton* forwardButton; |
| 31 @property(nonatomic, strong) ToolbarButton* tabSwitchStripButton; | 31 @property(nonatomic, strong) ToolbarButton* tabSwitchStripButton; |
| 32 @property(nonatomic, strong) ToolbarButton* tabSwitchGridButton; | 32 @property(nonatomic, strong) ToolbarButton* tabSwitchGridButton; |
| 33 @property(nonatomic, strong) ToolbarButton* toolsMenuButton; | 33 @property(nonatomic, strong) ToolbarButton* toolsMenuButton; |
| 34 @property(nonatomic, strong) ToolbarButton* shareButton; | 34 @property(nonatomic, strong) ToolbarButton* shareButton; |
| 35 @property(nonatomic, strong) ToolbarButton* reloadButton; | 35 @property(nonatomic, strong) ToolbarButton* reloadButton; |
| 36 @property(nonatomic, strong) ToolbarButton* stopButton; | 36 @property(nonatomic, strong) ToolbarButton* stopButton; |
| 37 @property(nonatomic, assign) CGRect currentFrame; | |
| 37 @end | 38 @end |
| 38 | 39 |
| 39 @implementation ToolbarViewController | 40 @implementation ToolbarViewController |
| 40 @synthesize dispatcher = _dispatcher; | 41 @synthesize dispatcher = _dispatcher; |
| 41 @synthesize locationBarViewController = _locationBarViewController; | 42 @synthesize locationBarViewController = _locationBarViewController; |
| 42 @synthesize stackView = _stackView; | 43 @synthesize stackView = _stackView; |
| 43 @synthesize locationBarContainer = _locationBarContainer; | 44 @synthesize locationBarContainer = _locationBarContainer; |
| 44 @synthesize backButton = _backButton; | 45 @synthesize backButton = _backButton; |
| 45 @synthesize forwardButton = _forwardButton; | 46 @synthesize forwardButton = _forwardButton; |
| 46 @synthesize tabSwitchStripButton = _tabSwitchStripButton; | 47 @synthesize tabSwitchStripButton = _tabSwitchStripButton; |
| 47 @synthesize tabSwitchGridButton = _tabSwitchGridButton; | 48 @synthesize tabSwitchGridButton = _tabSwitchGridButton; |
| 48 @synthesize toolsMenuButton = _toolsMenuButton; | 49 @synthesize toolsMenuButton = _toolsMenuButton; |
| 49 @synthesize shareButton = _shareButton; | 50 @synthesize shareButton = _shareButton; |
| 50 @synthesize reloadButton = _reloadButton; | 51 @synthesize reloadButton = _reloadButton; |
| 51 @synthesize stopButton = _stopButton; | 52 @synthesize stopButton = _stopButton; |
| 53 @synthesize currentFrame = _currentFrame; | |
| 52 | 54 |
| 53 - (instancetype)init { | 55 - (instancetype)init { |
| 54 self = [super init]; | 56 self = [super init]; |
| 55 if (self) { | 57 if (self) { |
| 56 [self setUpToolbarButtons]; | 58 [self setUpToolbarButtons]; |
| 57 [self setUpLocationBarContainer]; | 59 [self setUpLocationBarContainer]; |
| 58 } | 60 } |
| 59 return self; | 61 return self; |
| 60 } | 62 } |
| 61 | 63 |
| 64 #pragma mark - View lifecyle | |
| 65 | |
| 62 - (void)viewDidLoad { | 66 - (void)viewDidLoad { |
| 63 self.view.backgroundColor = [UIColor lightGrayColor]; | 67 self.view.backgroundColor = [UIColor lightGrayColor]; |
| 64 | 68 |
| 65 [self addChildViewController:self.locationBarViewController | 69 [self addChildViewController:self.locationBarViewController |
| 66 toSubview:self.locationBarContainer]; | 70 toSubview:self.locationBarContainer]; |
| 67 | 71 |
| 68 // Stack view to contain toolbar items. | 72 // Stack view to contain toolbar items. |
| 69 self.stackView = [[UIStackView alloc] initWithArrangedSubviews:@[ | 73 self.stackView = [[UIStackView alloc] initWithArrangedSubviews:@[ |
| 70 self.backButton, self.forwardButton, self.reloadButton, self.stopButton, | 74 self.backButton, self.forwardButton, self.reloadButton, self.stopButton, |
| 71 self.locationBarContainer, self.shareButton, self.tabSwitchStripButton, | 75 self.locationBarContainer, self.shareButton, self.tabSwitchStripButton, |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 85 constant:kVerticalMargin], | 89 constant:kVerticalMargin], |
| 86 [self.stackView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor | 90 [self.stackView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor |
| 87 constant:-kVerticalMargin], | 91 constant:-kVerticalMargin], |
| 88 [self.stackView.leadingAnchor | 92 [self.stackView.leadingAnchor |
| 89 constraintEqualToAnchor:self.view.leadingAnchor | 93 constraintEqualToAnchor:self.view.leadingAnchor |
| 90 constant:kHorizontalMargin], | 94 constant:kHorizontalMargin], |
| 91 [self.stackView.trailingAnchor | 95 [self.stackView.trailingAnchor |
| 92 constraintEqualToAnchor:self.view.trailingAnchor | 96 constraintEqualToAnchor:self.view.trailingAnchor |
| 93 constant:-kHorizontalMargin], | 97 constant:-kHorizontalMargin], |
| 94 ]]; | 98 ]]; |
| 99 | |
| 100 self.currentFrame = self.view.frame; | |
| 101 } | |
| 102 | |
| 103 - (void)viewWillLayoutSubviews { | |
| 104 // We need to dismiss the ToolsMenu everytime the Toolbar frame changes | |
| 105 // (e.g. Size changes, rotation changes, etc.) | |
| 106 if (!CGRectEqualToRect(self.currentFrame, self.view.frame)) { | |
|
marq (ping after 24h)
2017/05/10 10:57:02
UIViewController (via the UIContentContainer proto
sczs
2017/05/10 15:32:32
I agree, its much better.
Done.
| |
| 107 [self.dispatcher closeToolsMenu]; | |
| 108 } | |
| 109 self.currentFrame = self.view.frame; | |
| 95 } | 110 } |
| 96 | 111 |
| 97 #pragma mark - Components Setup | 112 #pragma mark - Components Setup |
| 98 | 113 |
| 99 - (void)setUpToolbarButtons { | 114 - (void)setUpToolbarButtons { |
| 100 // Back button. | 115 // Back button. |
| 101 self.backButton = [ToolbarButton backToolbarButton]; | 116 self.backButton = [ToolbarButton backToolbarButton]; |
| 102 self.backButton.visibilityMask = ToolbarComponentVisibilityCompactWidth | | 117 self.backButton.visibilityMask = ToolbarComponentVisibilityCompactWidth | |
| 103 ToolbarComponentVisibilityRegularWidth; | 118 ToolbarComponentVisibilityRegularWidth; |
| 104 [self.backButton addTarget:self | 119 [self.backButton addTarget:self |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 307 - (void)updateAllButtonsVisibility { | 322 - (void)updateAllButtonsVisibility { |
| 308 for (UIView* view in self.stackView.arrangedSubviews) { | 323 for (UIView* view in self.stackView.arrangedSubviews) { |
| 309 if ([view isKindOfClass:[ToolbarButton class]]) { | 324 if ([view isKindOfClass:[ToolbarButton class]]) { |
| 310 ToolbarButton* button = base::mac::ObjCCastStrict<ToolbarButton>(view); | 325 ToolbarButton* button = base::mac::ObjCCastStrict<ToolbarButton>(view); |
| 311 [button setHiddenForCurrentStateAndSizeClass]; | 326 [button setHiddenForCurrentStateAndSizeClass]; |
| 312 } | 327 } |
| 313 } | 328 } |
| 314 } | 329 } |
| 315 | 330 |
| 316 @end | 331 @end |
| OLD | NEW |