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_grid_actions.h" | 8 #import "ios/clean/chrome/browser/ui/actions/tab_grid_actions.h" |
| 9 #import "ios/clean/chrome/browser/ui/actions/tab_strip_actions.h" | 9 #import "ios/clean/chrome/browser/ui/actions/tab_strip_actions.h" |
| 10 #import "ios/clean/chrome/browser/ui/actions/tools_menu_actions.h" | |
| 11 #import "ios/clean/chrome/browser/ui/commands/navigation_commands.h" | 10 #import "ios/clean/chrome/browser/ui/commands/navigation_commands.h" |
| 12 #import "ios/clean/chrome/browser/ui/commands/toolbar_commands.h" | 11 #import "ios/clean/chrome/browser/ui/commands/tools_menu_commands.h" |
| 13 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_button+factory.h" | 12 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_button+factory.h" |
| 14 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_component_options.h" | 13 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_component_options.h" |
| 15 | 14 |
| 16 #if !defined(__has_feature) || !__has_feature(objc_arc) | 15 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 17 #error "This file requires ARC support." | 16 #error "This file requires ARC support." |
| 18 #endif | 17 #endif |
| 19 | 18 |
| 20 namespace { | 19 namespace { |
| 21 // Stackview Vertical Margin. | 20 // Stackview Vertical Margin. |
| 22 CGFloat kVerticalMargin = 5.0f; | 21 CGFloat kVerticalMargin = 5.0f; |
| 23 // Stackview Horizontal Margin. | 22 // Stackview Horizontal Margin. |
| 24 CGFloat kHorizontalMargin = 8.0f; | 23 CGFloat kHorizontalMargin = 8.0f; |
| 25 } // namespace | 24 } // namespace |
| 26 | 25 |
| 27 @interface ToolbarViewController ()<ToolsMenuActions> | 26 @interface ToolbarViewController () |
| 28 @property(nonatomic, strong) UITextField* omnibox; | 27 @property(nonatomic, strong) UITextField* omnibox; |
| 29 @property(nonatomic, strong) UIStackView* stackView; | 28 @property(nonatomic, strong) UIStackView* stackView; |
| 30 @property(nonatomic, strong) ToolbarButton* backButton; | 29 @property(nonatomic, strong) ToolbarButton* backButton; |
| 31 @property(nonatomic, strong) ToolbarButton* forwardButton; | 30 @property(nonatomic, strong) ToolbarButton* forwardButton; |
| 32 @property(nonatomic, strong) ToolbarButton* tabSwitchStripButton; | 31 @property(nonatomic, strong) ToolbarButton* tabSwitchStripButton; |
| 33 @property(nonatomic, strong) ToolbarButton* tabSwitchGridButton; | 32 @property(nonatomic, strong) ToolbarButton* tabSwitchGridButton; |
| 34 @property(nonatomic, strong) ToolbarButton* toolsMenuButton; | 33 @property(nonatomic, strong) ToolbarButton* toolsMenuButton; |
| 35 @property(nonatomic, strong) ToolbarButton* shareButton; | 34 @property(nonatomic, strong) ToolbarButton* shareButton; |
| 36 @property(nonatomic, strong) ToolbarButton* reloadButton; | 35 @property(nonatomic, strong) ToolbarButton* reloadButton; |
| 37 @property(nonatomic, strong) ToolbarButton* stopButton; | 36 @property(nonatomic, strong) ToolbarButton* stopButton; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 ToolbarComponentVisibilityRegularWidth; | 131 ToolbarComponentVisibilityRegularWidth; |
| 133 [self.tabSwitchGridButton addTarget:nil | 132 [self.tabSwitchGridButton addTarget:nil |
| 134 action:@selector(showTabGrid:) | 133 action:@selector(showTabGrid:) |
| 135 forControlEvents:UIControlEventTouchUpInside]; | 134 forControlEvents:UIControlEventTouchUpInside]; |
| 136 self.tabSwitchGridButton.hiddenInCurrentState = YES; | 135 self.tabSwitchGridButton.hiddenInCurrentState = YES; |
| 137 | 136 |
| 138 // Tools menu button. | 137 // Tools menu button. |
| 139 self.toolsMenuButton = [ToolbarButton toolsMenuToolbarButton]; | 138 self.toolsMenuButton = [ToolbarButton toolsMenuToolbarButton]; |
| 140 self.toolsMenuButton.visibilityMask = ToolbarComponentVisibilityCompactWidth | | 139 self.toolsMenuButton.visibilityMask = ToolbarComponentVisibilityCompactWidth | |
| 141 ToolbarComponentVisibilityRegularWidth; | 140 ToolbarComponentVisibilityRegularWidth; |
| 142 [self.toolsMenuButton addTarget:nil | 141 [self.toolsMenuButton addTarget:self |
| 143 action:@selector(showToolsMenu:) | 142 action:@selector(showToolsMenu:) |
| 144 forControlEvents:UIControlEventTouchUpInside]; | 143 forControlEvents:UIControlEventTouchUpInside]; |
| 145 | 144 |
| 146 // Share button. | 145 // Share button. |
| 147 self.shareButton = [ToolbarButton shareToolbarButton]; | 146 self.shareButton = [ToolbarButton shareToolbarButton]; |
| 148 self.shareButton.visibilityMask = ToolbarComponentVisibilityRegularWidth; | 147 self.shareButton.visibilityMask = ToolbarComponentVisibilityRegularWidth; |
| 149 [self.shareButton addTarget:nil | 148 [self.shareButton addTarget:self |
| 150 action:@selector(showShareMenu:) | 149 action:@selector(showShareMenu:) |
| 151 forControlEvents:UIControlEventTouchUpInside]; | 150 forControlEvents:UIControlEventTouchUpInside]; |
| 152 | 151 |
| 153 // Reload button. | 152 // Reload button. |
| 154 self.reloadButton = [ToolbarButton reloadToolbarButton]; | 153 self.reloadButton = [ToolbarButton reloadToolbarButton]; |
| 155 self.reloadButton.visibilityMask = ToolbarComponentVisibilityRegularWidth; | 154 self.reloadButton.visibilityMask = ToolbarComponentVisibilityRegularWidth; |
| 156 [self.reloadButton addTarget:self | 155 [self.reloadButton addTarget:self |
| 157 action:@selector(reload:) | 156 action:@selector(reload:) |
| 158 forControlEvents:UIControlEventTouchUpInside]; | 157 forControlEvents:UIControlEventTouchUpInside]; |
| 159 | 158 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 [self updateAllButtonsVisibility]; | 199 [self updateAllButtonsVisibility]; |
| 201 } | 200 } |
| 202 | 201 |
| 203 #pragma mark - ZoomTransitionDelegate | 202 #pragma mark - ZoomTransitionDelegate |
| 204 | 203 |
| 205 - (CGRect)rectForZoomWithKey:(NSObject*)key inView:(UIView*)view { | 204 - (CGRect)rectForZoomWithKey:(NSObject*)key inView:(UIView*)view { |
| 206 return [view convertRect:self.toolsMenuButton.bounds | 205 return [view convertRect:self.toolsMenuButton.bounds |
| 207 fromView:self.toolsMenuButton]; | 206 fromView:self.toolsMenuButton]; |
| 208 } | 207 } |
| 209 | 208 |
| 210 #pragma mark - ToolsMenuActions | 209 #pragma mark - ToolsMenuCommands |
|
edchin
2017/03/31 02:44:57
These methods can just be marked as Private method
sczs
2017/03/31 17:32:57
I like the idea, thanks! Done.
| |
| 211 | 210 |
| 212 - (void)showToolsMenu:(id)sender { | 211 - (void)showToolsMenu:(id)sender { |
| 213 [self.dispatcher showToolsMenu]; | 212 [self.dispatcher showToolsMenu]; |
| 214 } | 213 } |
| 215 | 214 |
| 216 - (void)closeToolsMenu:(id)sender { | 215 - (void)closeToolsMenu:(id)sender { |
| 217 [self.dispatcher closeToolsMenu]; | 216 [self.dispatcher closeToolsMenu]; |
| 218 } | 217 } |
| 219 | 218 |
| 220 #pragma mark - NavigationActions | 219 - (void)showShareMenu:(id)sender { |
| 220 [self.dispatcher showShareMenu]; | |
| 221 } | |
| 222 | |
| 223 #pragma mark - NavigationCommands | |
| 221 | 224 |
| 222 - (void)goBack:(id)sender { | 225 - (void)goBack:(id)sender { |
| 223 [self.dispatcher goBack]; | 226 [self.dispatcher goBack]; |
| 224 } | 227 } |
| 225 | 228 |
| 226 - (void)goForward:(id)sender { | 229 - (void)goForward:(id)sender { |
| 227 [self.dispatcher goForward]; | 230 [self.dispatcher goForward]; |
| 228 } | 231 } |
| 229 | 232 |
| 230 - (void)stop:(id)sender { | 233 - (void)stop:(id)sender { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 244 } | 247 } |
| 245 | 248 |
| 246 - (void)tabStripDidHide:(id)sender { | 249 - (void)tabStripDidHide:(id)sender { |
| 247 self.tabSwitchStripButton.hiddenInCurrentState = NO; | 250 self.tabSwitchStripButton.hiddenInCurrentState = NO; |
| 248 self.tabSwitchGridButton.hiddenInCurrentState = YES; | 251 self.tabSwitchGridButton.hiddenInCurrentState = YES; |
| 249 [self updateAllButtonsVisibility]; | 252 [self updateAllButtonsVisibility]; |
| 250 } | 253 } |
| 251 | 254 |
| 252 #pragma mark - Helper Methods | 255 #pragma mark - Helper Methods |
| 253 | 256 |
| 254 // PLACEHOLDER: We are not sure yet how WebState changes will affect Toolbar | |
| 255 // Buttons, but the VC will eventually set the flag on the ToolbarButton | |
| 256 // indicating it could or not it should be hidden. Once this is done we will | |
| 257 // update all the ToolbarButtons visibility. | |
| 258 // Updates all Buttons visibility to match any recent WebState change. | 257 // Updates all Buttons visibility to match any recent WebState change. |
| 259 - (void)updateAllButtonsVisibility { | 258 - (void)updateAllButtonsVisibility { |
| 260 for (UIView* view in self.stackView.arrangedSubviews) { | 259 for (UIView* view in self.stackView.arrangedSubviews) { |
| 261 if ([view isKindOfClass:[ToolbarButton class]]) { | 260 if ([view isKindOfClass:[ToolbarButton class]]) { |
| 262 ToolbarButton* button = base::mac::ObjCCastStrict<ToolbarButton>(view); | 261 ToolbarButton* button = base::mac::ObjCCastStrict<ToolbarButton>(view); |
| 263 [button setHiddenForCurrentStateAndSizeClass]; | 262 [button setHiddenForCurrentStateAndSizeClass]; |
| 264 } | 263 } |
| 265 } | 264 } |
| 266 } | 265 } |
| 267 | 266 |
| 268 @end | 267 @end |
| OLD | NEW |