Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: ios/clean/chrome/browser/ui/tools/menu_view_controller.mm

Issue 2693043002: [ios clean] Add overflow buttons for ToolsMenu. (Closed)
Patch Set: CL Feedback Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ios/clean/chrome/browser/ui/tools/menu_overflow_controls_stackview.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // ====== New Architecture ===== 5 // ====== New Architecture =====
6 // = This code is only used in the new iOS Chrome architecture. = 6 // = This code is only used in the new iOS Chrome architecture. =
7 // ============================================================================ 7 // ============================================================================
8 8
9 #import "ios/clean/chrome/browser/ui/tools/menu_view_controller.h" 9 #import "ios/clean/chrome/browser/ui/tools/menu_view_controller.h"
10 10
11 #include "base/i18n/rtl.h" 11 #include "base/i18n/rtl.h"
12 #import "base/logging.h" 12 #import "base/logging.h"
13 #import "base/macros.h" 13 #import "base/macros.h"
14 #import "ios/clean/chrome/browser/ui/actions/settings_actions.h" 14 #import "ios/clean/chrome/browser/ui/actions/settings_actions.h"
15 #import "ios/clean/chrome/browser/ui/actions/tools_menu_actions.h" 15 #import "ios/clean/chrome/browser/ui/actions/tools_menu_actions.h"
16 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_button.h"
17 #import "ios/clean/chrome/browser/ui/tools/menu_overflow_controls_stackview.h"
16 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF ontLoader.h" 18 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF ontLoader.h"
17 19
18 #if !defined(__has_feature) || !__has_feature(objc_arc) 20 #if !defined(__has_feature) || !__has_feature(objc_arc)
19 #error "This file requires ARC support." 21 #error "This file requires ARC support."
20 #endif 22 #endif
21 23
22 namespace { 24 namespace {
23 const CGFloat kMenuWidth = 250; 25 const CGFloat kMenuWidth = 250;
24 const CGFloat kMenuItemHeight = 48; 26 const CGFloat kMenuItemHeight = 48;
25 } 27 }
26 28
27 // Placeholder model for menu item configuration. 29 // Placeholder model for menu item configuration.
28 @interface MenuItem : NSObject 30 @interface MenuItem : NSObject
29 @property(nonatomic, copy) NSString* title; 31 @property(nonatomic, copy) NSString* title;
30 @property(nonatomic) SEL action; 32 @property(nonatomic) SEL action;
31 @end 33 @end
32 34
33 @implementation MenuItem 35 @implementation MenuItem
34 @synthesize title = _title; 36 @synthesize title = _title;
35 @synthesize action = _action; 37 @synthesize action = _action;
36 @end 38 @end
37 39
38 @interface MenuViewController () 40 @interface MenuViewController ()
39 @property(nonatomic, readonly) NSArray<MenuItem*>* menuItems; 41 @property(nonatomic, readonly) NSArray<MenuItem*>* menuItems;
42 @property(nonatomic, strong)
43 MenuOverflowControlsStackView* toolbarOverflowStackView;
40 @end 44 @end
41 45
42 @implementation MenuViewController 46 @implementation MenuViewController
43 @synthesize menuItems = _menuItems; 47 @synthesize menuItems = _menuItems;
48 @synthesize toolbarOverflowStackView = _toolbarOverflowStackView;
44 49
45 - (instancetype)init { 50 - (instancetype)init {
46 if ((self = [super init])) { 51 if ((self = [super init])) {
47 _menuItems = @[ 52 _menuItems = @[
48 [[MenuItem alloc] init], [[MenuItem alloc] init], [[MenuItem alloc] init], 53 [[MenuItem alloc] init], [[MenuItem alloc] init], [[MenuItem alloc] init],
49 [[MenuItem alloc] init], [[MenuItem alloc] init], [[MenuItem alloc] init], 54 [[MenuItem alloc] init], [[MenuItem alloc] init], [[MenuItem alloc] init],
50 [[MenuItem alloc] init], [[MenuItem alloc] init], [[MenuItem alloc] init], 55 [[MenuItem alloc] init], [[MenuItem alloc] init], [[MenuItem alloc] init],
51 [[MenuItem alloc] init], [[MenuItem alloc] init] 56 [[MenuItem alloc] init], [[MenuItem alloc] init]
52 ]; 57 ];
53 58
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 94
90 - (void)viewDidLoad { 95 - (void)viewDidLoad {
91 NSMutableArray<UIButton*>* buttons = 96 NSMutableArray<UIButton*>* buttons =
92 [[NSMutableArray alloc] initWithCapacity:_menuItems.count]; 97 [[NSMutableArray alloc] initWithCapacity:_menuItems.count];
93 98
94 for (MenuItem* item in _menuItems) { 99 for (MenuItem* item in _menuItems) {
95 UIButton* menuButton = [UIButton buttonWithType:UIButtonTypeSystem]; 100 UIButton* menuButton = [UIButton buttonWithType:UIButtonTypeSystem];
96 menuButton.translatesAutoresizingMaskIntoConstraints = NO; 101 menuButton.translatesAutoresizingMaskIntoConstraints = NO;
97 menuButton.tintColor = [UIColor blackColor]; 102 menuButton.tintColor = [UIColor blackColor];
98 [menuButton setTitle:item.title forState:UIControlStateNormal]; 103 [menuButton setTitle:item.title forState:UIControlStateNormal];
104 [menuButton setContentEdgeInsets:UIEdgeInsetsMake(0, 10.0f, 0, 0)];
marq (ping after 24h) 2017/02/16 10:54:42 Since you are setting different left and right ins
99 [menuButton.titleLabel 105 [menuButton.titleLabel
100 setFont:[[MDFRobotoFontLoader sharedInstance] regularFontOfSize:16]]; 106 setFont:[[MDFRobotoFontLoader sharedInstance] regularFontOfSize:16]];
101 [menuButton.titleLabel setTextAlignment:NSTextAlignmentNatural]; 107 [menuButton.titleLabel setTextAlignment:NSTextAlignmentNatural];
102 [menuButton addTarget:nil 108 [menuButton addTarget:nil
103 action:@selector(closeToolsMenu:) 109 action:@selector(closeToolsMenu:)
104 forControlEvents:UIControlEventTouchUpInside]; 110 forControlEvents:UIControlEventTouchUpInside];
105 if (item.action) { 111 if (item.action) {
106 [menuButton addTarget:nil 112 [menuButton addTarget:nil
107 action:item.action 113 action:item.action
108 forControlEvents:UIControlEventTouchUpInside]; 114 forControlEvents:UIControlEventTouchUpInside];
109 } 115 }
110 [buttons addObject:menuButton]; 116 [buttons addObject:menuButton];
111 } 117 }
112 118
113 // Placeholder stack view to hold menu contents. 119 // Placeholder stack view to hold menu contents.
114 UIStackView* menu = [[UIStackView alloc] initWithArrangedSubviews:buttons]; 120 UIStackView* menu = [[UIStackView alloc] initWithArrangedSubviews:buttons];
115 menu.translatesAutoresizingMaskIntoConstraints = NO; 121 menu.translatesAutoresizingMaskIntoConstraints = NO;
116 menu.axis = UILayoutConstraintAxisVertical; 122 menu.axis = UILayoutConstraintAxisVertical;
117 menu.distribution = UIStackViewDistributionFillEqually; 123 menu.distribution = UIStackViewDistributionFillEqually;
118 menu.alignment = UIStackViewAlignmentLeading; 124 menu.alignment = UIStackViewAlignmentLeading;
119 125
126 // Stack view to hold overflow ToolbarButtons.
127 if (self.traitCollection.horizontalSizeClass ==
128 UIUserInterfaceSizeClassCompact) {
129 self.toolbarOverflowStackView =
130 [[MenuOverflowControlsStackView alloc] init];
131 // PLACEHOLDER: ToolsMenuButton might end up being part of the MenuVC's view
132 // instead of the StackView. We are waiting confirmation on this.
133 [self.toolbarOverflowStackView.toolsMenuButton
134 addTarget:nil
135 action:@selector(closeToolsMenu:)
136 forControlEvents:UIControlEventTouchUpInside];
137 [menu insertArrangedSubview:self.toolbarOverflowStackView atIndex:0];
138 [NSLayoutConstraint activateConstraints:@[
139 [self.toolbarOverflowStackView.leadingAnchor
140 constraintEqualToAnchor:menu.leadingAnchor],
141 [self.toolbarOverflowStackView.trailingAnchor
142 constraintEqualToAnchor:menu.trailingAnchor],
143 ]];
144 }
145
120 [self.view addSubview:menu]; 146 [self.view addSubview:menu];
121 [NSLayoutConstraint activateConstraints:@[ 147 [NSLayoutConstraint activateConstraints:@[
122 [menu.leadingAnchor 148 [menu.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
123 constraintEqualToAnchor:self.view.layoutMarginsGuide.leadingAnchor], 149 [menu.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor],
124 [menu.trailingAnchor 150 [menu.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor],
125 constraintEqualToAnchor:self.view.layoutMarginsGuide.trailingAnchor], 151 [menu.topAnchor constraintEqualToAnchor:self.view.topAnchor],
126 [menu.bottomAnchor
127 constraintEqualToAnchor:self.view.layoutMarginsGuide.bottomAnchor],
128 [menu.topAnchor
129 constraintEqualToAnchor:self.view.layoutMarginsGuide.topAnchor],
130 ]]; 152 ]];
131 } 153 }
132 154
133 @end 155 @end
OLDNEW
« no previous file with comments | « ios/clean/chrome/browser/ui/tools/menu_overflow_controls_stackview.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698