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

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

Issue 2769963007: [ios clean] Creates ToolsMenu Mediator and Consumer (Closed)
Patch Set: Created 3 years, 8 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
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 #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/actions/settings_actions.h"
12 #import "ios/clean/chrome/browser/ui/actions/tools_menu_actions.h" 11 #import "ios/clean/chrome/browser/ui/actions/tools_menu_actions.h"
13 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_button.h" 12 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_button.h"
14 #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"
15 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF ontLoader.h" 15 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF ontLoader.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 // Placeholder model for menu item configuration.
27 @interface MenuItem : NSObject
28 @property(nonatomic, copy) NSString* title;
29 @property(nonatomic) SEL action;
30 @end
31
32 @implementation MenuItem
33 @synthesize title = _title;
34 @synthesize action = _action;
35 @end
36
37 @interface MenuViewController () 26 @interface MenuViewController ()
38 @property(nonatomic, readonly) NSArray<MenuItem*>* menuItems; 27 @property(nonatomic, strong) NSArray<ToolsMenuItem*>* menuItems;
39 @property(nonatomic, strong) 28 @property(nonatomic, strong)
40 MenuOverflowControlsStackView* toolbarOverflowStackView; 29 MenuOverflowControlsStackView* toolbarOverflowStackView;
41 @end 30 @end
42 31
43 @implementation MenuViewController 32 @implementation MenuViewController
44 @synthesize menuItems = _menuItems; 33 @synthesize menuItems = _menuItems;
45 @synthesize toolbarOverflowStackView = _toolbarOverflowStackView; 34 @synthesize toolbarOverflowStackView = _toolbarOverflowStackView;
46 35
47 - (instancetype)init {
48 if ((self = [super init])) {
49 _menuItems = @[
50 [[MenuItem alloc] init], [[MenuItem alloc] init], [[MenuItem alloc] init],
51 [[MenuItem alloc] init], [[MenuItem alloc] init], [[MenuItem alloc] init],
52 [[MenuItem alloc] init], [[MenuItem alloc] init], [[MenuItem alloc] init],
53 [[MenuItem alloc] init], [[MenuItem alloc] init]
54 ];
55
56 _menuItems[0].title = @"New Tab";
57
58 _menuItems[1].title = @"New Incognito Tab";
59
60 _menuItems[2].title = @"Bookmarks";
61
62 _menuItems[3].title = @"Reading List";
63
64 _menuItems[4].title = @"Recent Tabs";
65
66 _menuItems[5].title = @"History";
67
68 _menuItems[6].title = @"Report an Issue";
69
70 _menuItems[7].title = @"Find in Page…";
71
72 _menuItems[8].title = @"Request Desktop Site";
73
74 _menuItems[9].title = @"Settings";
75 _menuItems[9].action = @selector(showSettings:);
76
77 _menuItems[10].title = @"Help";
78 }
79 return self;
80 }
81
82 - (void)loadView { 36 - (void)loadView {
83 CGRect frame; 37 CGRect frame;
84 frame.size = CGSizeMake(kMenuWidth, kMenuItemHeight * _menuItems.count); 38 frame.size = CGSizeMake(kMenuWidth, kMenuItemHeight * _menuItems.count);
85 frame.origin = CGPointZero; 39 frame.origin = CGPointZero;
86 self.view = [[UIView alloc] initWithFrame:frame]; 40 self.view = [[UIView alloc] initWithFrame:frame];
87 self.view.backgroundColor = [UIColor whiteColor]; 41 self.view.backgroundColor = [UIColor whiteColor];
88 self.view.autoresizingMask = UIViewAutoresizingNone; 42 self.view.autoresizingMask = UIViewAutoresizingNone;
89 self.view.layer.borderColor = [UIColor clearColor].CGColor; 43 self.view.layer.borderColor = [UIColor clearColor].CGColor;
90 } 44 }
91 45
92 - (void)viewDidLoad { 46 - (void)viewDidLoad {
93 NSMutableArray<UIButton*>* buttons = 47 NSMutableArray<UIButton*>* buttons =
94 [[NSMutableArray alloc] initWithCapacity:_menuItems.count]; 48 [[NSMutableArray alloc] initWithCapacity:_menuItems.count];
95 49
96 for (MenuItem* item in _menuItems) { 50 for (ToolsMenuItem* item in _menuItems) {
97 UIButton* menuButton = [UIButton buttonWithType:UIButtonTypeSystem]; 51 UIButton* menuButton = [UIButton buttonWithType:UIButtonTypeSystem];
98 menuButton.translatesAutoresizingMaskIntoConstraints = NO; 52 menuButton.translatesAutoresizingMaskIntoConstraints = NO;
99 menuButton.tintColor = [UIColor blackColor]; 53 menuButton.tintColor = [UIColor blackColor];
100 [menuButton setTitle:item.title forState:UIControlStateNormal]; 54 [menuButton setTitle:item.title forState:UIControlStateNormal];
101 [menuButton setContentEdgeInsets:UIEdgeInsetsMakeDirected(0, 10.0f, 0, 0)]; 55 [menuButton setContentEdgeInsets:UIEdgeInsetsMakeDirected(0, 10.0f, 0, 0)];
102 [menuButton.titleLabel 56 [menuButton.titleLabel
103 setFont:[[MDFRobotoFontLoader sharedInstance] regularFontOfSize:16]]; 57 setFont:[[MDFRobotoFontLoader sharedInstance] regularFontOfSize:16]];
104 [menuButton.titleLabel setTextAlignment:NSTextAlignmentNatural]; 58 [menuButton.titleLabel setTextAlignment:NSTextAlignmentNatural];
105 [menuButton addTarget:nil 59 [menuButton addTarget:nil
106 action:@selector(closeToolsMenu:) 60 action:@selector(closeToolsMenu:)
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 96
143 [self.view addSubview:menu]; 97 [self.view addSubview:menu];
144 [NSLayoutConstraint activateConstraints:@[ 98 [NSLayoutConstraint activateConstraints:@[
145 [menu.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor], 99 [menu.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
146 [menu.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor], 100 [menu.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor],
147 [menu.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor], 101 [menu.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor],
148 [menu.topAnchor constraintEqualToAnchor:self.view.topAnchor], 102 [menu.topAnchor constraintEqualToAnchor:self.view.topAnchor],
149 ]]; 103 ]];
150 } 104 }
151 105
106 #pragma mark - Tools Consumer
107
108 - (void)setToolsMenuItems:(NSArray*)menuItems {
109 _menuItems = menuItems;
110 }
111
152 @end 112 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698