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

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: Use RTL for EdgeInssets 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/chrome/browser/ui/rtl_geometry.h"
14 #import "ios/clean/chrome/browser/ui/actions/settings_actions.h" 15 #import "ios/clean/chrome/browser/ui/actions/settings_actions.h"
15 #import "ios/clean/chrome/browser/ui/actions/tools_menu_actions.h" 16 #import "ios/clean/chrome/browser/ui/actions/tools_menu_actions.h"
17 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_button.h"
18 #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" 19 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF ontLoader.h"
17 20
18 #if !defined(__has_feature) || !__has_feature(objc_arc) 21 #if !defined(__has_feature) || !__has_feature(objc_arc)
19 #error "This file requires ARC support." 22 #error "This file requires ARC support."
20 #endif 23 #endif
21 24
22 namespace { 25 namespace {
23 const CGFloat kMenuWidth = 250; 26 const CGFloat kMenuWidth = 250;
24 const CGFloat kMenuItemHeight = 48; 27 const CGFloat kMenuItemHeight = 48;
25 } 28 }
26 29
27 // Placeholder model for menu item configuration. 30 // Placeholder model for menu item configuration.
28 @interface MenuItem : NSObject 31 @interface MenuItem : NSObject
29 @property(nonatomic, copy) NSString* title; 32 @property(nonatomic, copy) NSString* title;
30 @property(nonatomic) SEL action; 33 @property(nonatomic) SEL action;
31 @end 34 @end
32 35
33 @implementation MenuItem 36 @implementation MenuItem
34 @synthesize title = _title; 37 @synthesize title = _title;
35 @synthesize action = _action; 38 @synthesize action = _action;
36 @end 39 @end
37 40
38 @interface MenuViewController () 41 @interface MenuViewController ()
39 @property(nonatomic, readonly) NSArray<MenuItem*>* menuItems; 42 @property(nonatomic, readonly) NSArray<MenuItem*>* menuItems;
43 @property(nonatomic, strong)
44 MenuOverflowControlsStackView* toolbarOverflowStackView;
40 @end 45 @end
41 46
42 @implementation MenuViewController 47 @implementation MenuViewController
43 @synthesize menuItems = _menuItems; 48 @synthesize menuItems = _menuItems;
49 @synthesize toolbarOverflowStackView = _toolbarOverflowStackView;
44 50
45 - (instancetype)init { 51 - (instancetype)init {
46 if ((self = [super init])) { 52 if ((self = [super init])) {
47 _menuItems = @[ 53 _menuItems = @[
48 [[MenuItem alloc] init], [[MenuItem alloc] init], [[MenuItem alloc] init], 54 [[MenuItem alloc] init], [[MenuItem alloc] init], [[MenuItem alloc] init],
49 [[MenuItem alloc] init], [[MenuItem alloc] init], [[MenuItem alloc] init], 55 [[MenuItem alloc] init], [[MenuItem alloc] init], [[MenuItem alloc] init],
50 [[MenuItem alloc] init], [[MenuItem alloc] init], [[MenuItem alloc] init], 56 [[MenuItem alloc] init], [[MenuItem alloc] init], [[MenuItem alloc] init],
51 [[MenuItem alloc] init], [[MenuItem alloc] init] 57 [[MenuItem alloc] init], [[MenuItem alloc] init]
52 ]; 58 ];
53 59
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 95
90 - (void)viewDidLoad { 96 - (void)viewDidLoad {
91 NSMutableArray<UIButton*>* buttons = 97 NSMutableArray<UIButton*>* buttons =
92 [[NSMutableArray alloc] initWithCapacity:_menuItems.count]; 98 [[NSMutableArray alloc] initWithCapacity:_menuItems.count];
93 99
94 for (MenuItem* item in _menuItems) { 100 for (MenuItem* item in _menuItems) {
95 UIButton* menuButton = [UIButton buttonWithType:UIButtonTypeSystem]; 101 UIButton* menuButton = [UIButton buttonWithType:UIButtonTypeSystem];
96 menuButton.translatesAutoresizingMaskIntoConstraints = NO; 102 menuButton.translatesAutoresizingMaskIntoConstraints = NO;
97 menuButton.tintColor = [UIColor blackColor]; 103 menuButton.tintColor = [UIColor blackColor];
98 [menuButton setTitle:item.title forState:UIControlStateNormal]; 104 [menuButton setTitle:item.title forState:UIControlStateNormal];
105 [menuButton setContentEdgeInsets:UIEdgeInsetsMakeDirected(0, 10.0f, 0, 0)];
99 [menuButton.titleLabel 106 [menuButton.titleLabel
100 setFont:[[MDFRobotoFontLoader sharedInstance] regularFontOfSize:16]]; 107 setFont:[[MDFRobotoFontLoader sharedInstance] regularFontOfSize:16]];
101 [menuButton.titleLabel setTextAlignment:NSTextAlignmentNatural]; 108 [menuButton.titleLabel setTextAlignment:NSTextAlignmentNatural];
102 [menuButton addTarget:nil 109 [menuButton addTarget:nil
103 action:@selector(closeToolsMenu:) 110 action:@selector(closeToolsMenu:)
104 forControlEvents:UIControlEventTouchUpInside]; 111 forControlEvents:UIControlEventTouchUpInside];
105 if (item.action) { 112 if (item.action) {
106 [menuButton addTarget:nil 113 [menuButton addTarget:nil
107 action:item.action 114 action:item.action
108 forControlEvents:UIControlEventTouchUpInside]; 115 forControlEvents:UIControlEventTouchUpInside];
109 } 116 }
110 [buttons addObject:menuButton]; 117 [buttons addObject:menuButton];
111 } 118 }
112 119
113 // Placeholder stack view to hold menu contents. 120 // Placeholder stack view to hold menu contents.
114 UIStackView* menu = [[UIStackView alloc] initWithArrangedSubviews:buttons]; 121 UIStackView* menu = [[UIStackView alloc] initWithArrangedSubviews:buttons];
115 menu.translatesAutoresizingMaskIntoConstraints = NO; 122 menu.translatesAutoresizingMaskIntoConstraints = NO;
116 menu.axis = UILayoutConstraintAxisVertical; 123 menu.axis = UILayoutConstraintAxisVertical;
117 menu.distribution = UIStackViewDistributionFillEqually; 124 menu.distribution = UIStackViewDistributionFillEqually;
118 menu.alignment = UIStackViewAlignmentLeading; 125 menu.alignment = UIStackViewAlignmentLeading;
119 126
127 // Stack view to hold overflow ToolbarButtons.
128 if (self.traitCollection.horizontalSizeClass ==
129 UIUserInterfaceSizeClassCompact) {
130 self.toolbarOverflowStackView =
131 [[MenuOverflowControlsStackView alloc] init];
132 // PLACEHOLDER: ToolsMenuButton might end up being part of the MenuVC's view
133 // instead of the StackView. We are waiting confirmation on this.
134 [self.toolbarOverflowStackView.toolsMenuButton
135 addTarget:nil
136 action:@selector(closeToolsMenu:)
137 forControlEvents:UIControlEventTouchUpInside];
138 [menu insertArrangedSubview:self.toolbarOverflowStackView atIndex:0];
139 [NSLayoutConstraint activateConstraints:@[
140 [self.toolbarOverflowStackView.leadingAnchor
141 constraintEqualToAnchor:menu.leadingAnchor],
142 [self.toolbarOverflowStackView.trailingAnchor
143 constraintEqualToAnchor:menu.trailingAnchor],
144 ]];
145 }
146
120 [self.view addSubview:menu]; 147 [self.view addSubview:menu];
121 [NSLayoutConstraint activateConstraints:@[ 148 [NSLayoutConstraint activateConstraints:@[
122 [menu.leadingAnchor 149 [menu.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
123 constraintEqualToAnchor:self.view.layoutMarginsGuide.leadingAnchor], 150 [menu.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor],
124 [menu.trailingAnchor 151 [menu.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor],
125 constraintEqualToAnchor:self.view.layoutMarginsGuide.trailingAnchor], 152 [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 ]]; 153 ]];
131 } 154 }
132 155
133 @end 156 @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