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/tools/menu_view_controller.h" | 5 #import "ios/clean/chrome/browser/ui/tools/menu_view_controller.h" |
| 6 | 6 |
| 7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
| 8 #import "base/logging.h" | 8 #import "base/logging.h" |
| 9 #import "base/macros.h" | 9 #import "base/macros.h" |
| 10 #import "ios/chrome/browser/ui/rtl_geometry.h" | 10 #import "ios/chrome/browser/ui/rtl_geometry.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.h" | 12 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_button.h" |
| 13 #import "ios/clean/chrome/browser/ui/tools/menu_overflow_controls_stackview.h" | 13 #import "ios/clean/chrome/browser/ui/tools/menu_overflow_controls_stackview.h" |
| 14 #import "ios/clean/chrome/browser/ui/tools/tools_menu_item.h" | 14 #import "ios/clean/chrome/browser/ui/tools/tools_menu_item.h" |
| 15 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h" | 15 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h" |
| 16 | 16 |
| 17 #if !defined(__has_feature) || !__has_feature(objc_arc) | 17 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 18 #error "This file requires ARC support." | 18 #error "This file requires ARC support." |
| 19 #endif | 19 #endif |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 const CGFloat kMenuWidth = 250; | 22 const CGFloat kMenuWidth = 250; |
| 23 const CGFloat kMenuItemHeight = 48; | 23 const CGFloat kMenuItemHeight = 48; |
| 24 } | 24 } |
| 25 | 25 |
| 26 @interface MenuViewController () | 26 @interface MenuViewController () |
| 27 @property(nonatomic, strong) NSArray<ToolsMenuItem*>* menuItems; | 27 @property(nonatomic, strong) NSArray<ToolsMenuItem*>* menuItems; |
| 28 @property(nonatomic, strong) | 28 @property(nonatomic, strong) |
| 29 MenuOverflowControlsStackView* toolbarOverflowStackView; | 29 MenuOverflowControlsStackView* toolbarOverflowStackView; |
| 30 @property(nonatomic, assign) BOOL displayOverflowControls; | |
| 30 @end | 31 @end |
| 31 | 32 |
| 32 @implementation MenuViewController | 33 @implementation MenuViewController |
| 33 @synthesize menuItems = _menuItems; | 34 @synthesize menuItems = _menuItems; |
| 34 @synthesize toolbarOverflowStackView = _toolbarOverflowStackView; | 35 @synthesize toolbarOverflowStackView = _toolbarOverflowStackView; |
| 35 @synthesize dispatcher = _dispatcher; | 36 @synthesize dispatcher = _dispatcher; |
| 37 @synthesize displayOverflowControls = _displayOverflowControls; | |
| 36 | 38 |
| 37 - (void)loadView { | 39 - (void)loadView { |
| 38 CGRect frame; | 40 CGRect frame; |
| 39 frame.size = CGSizeMake(kMenuWidth, kMenuItemHeight * _menuItems.count); | 41 frame.size = CGSizeMake(kMenuWidth, kMenuItemHeight * _menuItems.count); |
| 40 frame.origin = CGPointZero; | 42 frame.origin = CGPointZero; |
| 41 self.view = [[UIView alloc] initWithFrame:frame]; | 43 self.view = [[UIView alloc] initWithFrame:frame]; |
| 42 self.view.backgroundColor = [UIColor whiteColor]; | 44 self.view.backgroundColor = [UIColor whiteColor]; |
| 43 self.view.autoresizingMask = UIViewAutoresizingNone; | 45 self.view.autoresizingMask = UIViewAutoresizingNone; |
| 44 self.view.layer.borderColor = [UIColor clearColor].CGColor; | 46 self.view.layer.borderColor = [UIColor clearColor].CGColor; |
| 45 } | 47 } |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 69 | 71 |
| 70 // Placeholder stack view to hold menu contents. | 72 // Placeholder stack view to hold menu contents. |
| 71 UIStackView* menu = [[UIStackView alloc] initWithArrangedSubviews:buttons]; | 73 UIStackView* menu = [[UIStackView alloc] initWithArrangedSubviews:buttons]; |
| 72 menu.translatesAutoresizingMaskIntoConstraints = NO; | 74 menu.translatesAutoresizingMaskIntoConstraints = NO; |
| 73 menu.axis = UILayoutConstraintAxisVertical; | 75 menu.axis = UILayoutConstraintAxisVertical; |
| 74 menu.distribution = UIStackViewDistributionFillEqually; | 76 menu.distribution = UIStackViewDistributionFillEqually; |
| 75 menu.alignment = UIStackViewAlignmentLeading; | 77 menu.alignment = UIStackViewAlignmentLeading; |
| 76 | 78 |
| 77 // Stack view to hold overflow ToolbarButtons. | 79 // Stack view to hold overflow ToolbarButtons. |
| 78 if (self.traitCollection.horizontalSizeClass == | 80 if (self.traitCollection.horizontalSizeClass == |
| 79 UIUserInterfaceSizeClassCompact) { | 81 UIUserInterfaceSizeClassCompact && |
| 82 self.displayOverflowControls) { | |
| 80 self.toolbarOverflowStackView = | 83 self.toolbarOverflowStackView = |
| 81 [[MenuOverflowControlsStackView alloc] init]; | 84 [[MenuOverflowControlsStackView alloc] init]; |
| 82 // PLACEHOLDER: ToolsMenuButton might end up being part of the MenuVC's view | 85 // PLACEHOLDER: ToolsMenuButton might end up being part of the MenuVC's view |
| 83 // instead of the StackView. We are waiting confirmation on this. | 86 // instead of the StackView. We are waiting confirmation on this. |
| 84 [self.toolbarOverflowStackView.toolsMenuButton | 87 [self.toolbarOverflowStackView.toolsMenuButton |
| 85 addTarget:nil | 88 addTarget:nil |
| 86 action:@selector(closeToolsMenu:) | 89 action:@selector(closeToolsMenu:) |
| 87 forControlEvents:UIControlEventTouchUpInside]; | 90 forControlEvents:UIControlEventTouchUpInside]; |
| 88 [menu insertArrangedSubview:self.toolbarOverflowStackView atIndex:0]; | 91 [menu insertArrangedSubview:self.toolbarOverflowStackView atIndex:0]; |
| 89 [NSLayoutConstraint activateConstraints:@[ | 92 [NSLayoutConstraint activateConstraints:@[ |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 108 - (void)closeToolsMenu:(id)sender { | 111 - (void)closeToolsMenu:(id)sender { |
| 109 [self.dispatcher closeToolsMenu]; | 112 [self.dispatcher closeToolsMenu]; |
| 110 } | 113 } |
| 111 | 114 |
| 112 #pragma mark - Tools Consumer | 115 #pragma mark - Tools Consumer |
| 113 | 116 |
| 114 - (void)setToolsMenuItems:(NSArray*)menuItems { | 117 - (void)setToolsMenuItems:(NSArray*)menuItems { |
| 115 _menuItems = menuItems; | 118 _menuItems = menuItems; |
| 116 } | 119 } |
| 117 | 120 |
| 121 - (void)canDisplayOverflowControls:(BOOL)displayOverflowControls { | |
|
marq (ping after 24h)
2017/04/12 11:17:07
This depends on device size/format, which is somet
sczs
2017/04/12 15:06:08
This also depends on who is displaying the ToolsMe
marq (ping after 24h)
2017/04/14 10:01:52
Indeed! My mistake.
| |
| 122 self.displayOverflowControls = displayOverflowControls; | |
| 123 } | |
| 124 | |
| 118 @end | 125 @end |
| OLD | NEW |