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

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

Issue 2817203003: [ios clean] Functionality for menu overflow navigation buttons (Closed)
Patch Set: Refactor 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
« no previous file with comments | « ios/clean/chrome/browser/ui/tools/menu_view_controller.h ('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 #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/find_in_page_visibility_commands.h " 11 #import "ios/clean/chrome/browser/ui/commands/find_in_page_visibility_commands.h "
12 #import "ios/clean/chrome/browser/ui/commands/navigation_commands.h"
12 #import "ios/clean/chrome/browser/ui/commands/tools_menu_commands.h" 13 #import "ios/clean/chrome/browser/ui/commands/tools_menu_commands.h"
13 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_button.h" 14 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_button.h"
14 #import "ios/clean/chrome/browser/ui/tools/menu_overflow_controls_stackview.h" 15 #import "ios/clean/chrome/browser/ui/tools/menu_overflow_controls_stackview.h"
15 #import "ios/clean/chrome/browser/ui/tools/tools_actions.h" 16 #import "ios/clean/chrome/browser/ui/tools/tools_actions.h"
16 #import "ios/clean/chrome/browser/ui/tools/tools_menu_item.h" 17 #import "ios/clean/chrome/browser/ui/tools/tools_menu_item.h"
17 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h" 18 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h"
18 19
19 #if !defined(__has_feature) || !__has_feature(objc_arc) 20 #if !defined(__has_feature) || !__has_feature(objc_arc)
20 #error "This file requires ARC support." 21 #error "This file requires ARC support."
21 #endif 22 #endif
22 23
23 namespace { 24 namespace {
24 const CGFloat kMenuWidth = 250; 25 const CGFloat kMenuWidth = 250;
25 const CGFloat kMenuItemHeight = 48; 26 const CGFloat kMenuItemHeight = 48;
26 } 27 }
27 28
28 @interface MenuViewController ()<ToolsActions> 29 @interface MenuViewController ()<ToolsActions>
30 @property(nonatomic, strong) UIStackView* menuStackView;
29 @property(nonatomic, strong) NSArray<ToolsMenuItem*>* menuItems; 31 @property(nonatomic, strong) NSArray<ToolsMenuItem*>* menuItems;
30 @property(nonatomic, strong) 32 @property(nonatomic, strong)
31 MenuOverflowControlsStackView* toolbarOverflowStackView; 33 MenuOverflowControlsStackView* toolbarOverflowStackView;
32 @end 34 @end
33 35
34 @implementation MenuViewController 36 @implementation MenuViewController
35 @synthesize dispatcher = _dispatcher; 37 @synthesize dispatcher = _dispatcher;
36 @synthesize menuItems = _menuItems; 38 @synthesize menuItems = _menuItems;
39 @synthesize menuStackView = _menuStackView;
37 @synthesize toolbarOverflowStackView = _toolbarOverflowStackView; 40 @synthesize toolbarOverflowStackView = _toolbarOverflowStackView;
38 41
39 - (void)loadView { 42 - (void)loadView {
40 CGRect frame; 43 CGRect frame;
41 frame.size = CGSizeMake(kMenuWidth, kMenuItemHeight * _menuItems.count); 44 frame.size = CGSizeMake(kMenuWidth, kMenuItemHeight * _menuItems.count);
42 frame.origin = CGPointZero; 45 frame.origin = CGPointZero;
43 self.view = [[UIView alloc] initWithFrame:frame]; 46 self.view = [[UIView alloc] initWithFrame:frame];
44 self.view.backgroundColor = [UIColor whiteColor]; 47 self.view.backgroundColor = [UIColor whiteColor];
45 self.view.autoresizingMask = UIViewAutoresizingNone; 48 self.view.autoresizingMask = UIViewAutoresizingNone;
46 self.view.layer.borderColor = [UIColor clearColor].CGColor; 49 self.view.layer.borderColor = [UIColor clearColor].CGColor;
47 } 50 }
48 51
49 - (void)viewDidLoad { 52 - (void)viewDidLoad {
50 NSMutableArray<UIButton*>* buttons = 53 NSMutableArray<UIButton*>* buttons =
51 [[NSMutableArray alloc] initWithCapacity:_menuItems.count]; 54 [[NSMutableArray alloc] initWithCapacity:_menuItems.count];
52 55
56 // Load menu items.
53 for (ToolsMenuItem* item in _menuItems) { 57 for (ToolsMenuItem* item in _menuItems) {
54 UIButton* menuButton = [UIButton buttonWithType:UIButtonTypeSystem]; 58 UIButton* menuButton = [UIButton buttonWithType:UIButtonTypeSystem];
55 menuButton.translatesAutoresizingMaskIntoConstraints = NO; 59 menuButton.translatesAutoresizingMaskIntoConstraints = NO;
56 menuButton.tintColor = [UIColor blackColor]; 60 menuButton.tintColor = [UIColor blackColor];
57 [menuButton setTitle:item.title forState:UIControlStateNormal]; 61 [menuButton setTitle:item.title forState:UIControlStateNormal];
58 [menuButton setContentEdgeInsets:UIEdgeInsetsMakeDirected(0, 10.0f, 0, 0)]; 62 [menuButton setContentEdgeInsets:UIEdgeInsetsMakeDirected(0, 10.0f, 0, 0)];
59 [menuButton.titleLabel setFont:[MDCTypography subheadFont]]; 63 [menuButton.titleLabel setFont:[MDCTypography subheadFont]];
60 [menuButton.titleLabel setTextAlignment:NSTextAlignmentNatural]; 64 [menuButton.titleLabel setTextAlignment:NSTextAlignmentNatural];
61 [menuButton addTarget:self 65 [menuButton addTarget:self
62 action:@selector(closeToolsMenu:) 66 action:@selector(closeToolsMenu)
63 forControlEvents:UIControlEventTouchUpInside]; 67 forControlEvents:UIControlEventTouchUpInside];
64 if (item.action) { 68 if (item.action) {
65 id target = (item.action == @selector(showFindInPage)) ? self : nil; 69 id target = (item.action == @selector(showFindInPage)) ? self : nil;
66 [menuButton addTarget:target 70 [menuButton addTarget:target
67 action:item.action 71 action:item.action
68 forControlEvents:UIControlEventTouchUpInside]; 72 forControlEvents:UIControlEventTouchUpInside];
69 } 73 }
70 [buttons addObject:menuButton]; 74 [buttons addObject:menuButton];
71 } 75 }
72 76
73 // Placeholder stack view to hold menu contents. 77 // Placeholder stack view to hold menu contents.
74 UIStackView* menu = [[UIStackView alloc] initWithArrangedSubviews:buttons]; 78 self.menuStackView = [[UIStackView alloc] initWithArrangedSubviews:buttons];
75 menu.translatesAutoresizingMaskIntoConstraints = NO; 79 self.menuStackView.translatesAutoresizingMaskIntoConstraints = NO;
76 menu.axis = UILayoutConstraintAxisVertical; 80 self.menuStackView.axis = UILayoutConstraintAxisVertical;
77 menu.distribution = UIStackViewDistributionFillEqually; 81 self.menuStackView.distribution = UIStackViewDistributionFillEqually;
78 menu.alignment = UIStackViewAlignmentLeading; 82 self.menuStackView.alignment = UIStackViewAlignmentLeading;
79 83
80 // Stack view to hold overflow ToolbarButtons. 84 // Stack view to hold overflow ToolbarButtons.
81 if (self.traitCollection.horizontalSizeClass == 85 if (self.traitCollection.horizontalSizeClass ==
82 UIUserInterfaceSizeClassCompact) { 86 UIUserInterfaceSizeClassCompact) {
83 self.toolbarOverflowStackView = 87 [self setUpOverFlowControlsStackView];
84 [[MenuOverflowControlsStackView alloc] init];
85 // PLACEHOLDER: ToolsMenuButton might end up being part of the MenuVC's view
86 // instead of the StackView. We are waiting confirmation on this.
87 [self.toolbarOverflowStackView.toolsMenuButton
88 addTarget:nil
89 action:@selector(closeToolsMenu:)
90 forControlEvents:UIControlEventTouchUpInside];
91 [menu insertArrangedSubview:self.toolbarOverflowStackView atIndex:0];
92 [NSLayoutConstraint activateConstraints:@[
93 [self.toolbarOverflowStackView.leadingAnchor
94 constraintEqualToAnchor:menu.leadingAnchor],
95 [self.toolbarOverflowStackView.trailingAnchor
96 constraintEqualToAnchor:menu.trailingAnchor],
97 ]];
98 } 88 }
99 89
100 [self.view addSubview:menu]; 90 // Setup constraints.
91 [self.view addSubview:self.menuStackView];
101 [NSLayoutConstraint activateConstraints:@[ 92 [NSLayoutConstraint activateConstraints:@[
102 [menu.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor], 93 [self.menuStackView.leadingAnchor
103 [menu.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor], 94 constraintEqualToAnchor:self.view.leadingAnchor],
104 [menu.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor], 95 [self.menuStackView.trailingAnchor
105 [menu.topAnchor constraintEqualToAnchor:self.view.topAnchor], 96 constraintEqualToAnchor:self.view.trailingAnchor],
97 [self.menuStackView.bottomAnchor
98 constraintEqualToAnchor:self.view.bottomAnchor],
99 [self.menuStackView.topAnchor constraintEqualToAnchor:self.view.topAnchor],
100 ]];
101 }
102
103 - (void)setUpOverFlowControlsStackView {
104 self.toolbarOverflowStackView = [[MenuOverflowControlsStackView alloc] init];
105 // PLACEHOLDER: ToolsMenuButton might end up being part of the MenuVC's view
106 // instead of the StackView. We are waiting confirmation on this.
107 [self.toolbarOverflowStackView.toolsMenuButton
108 addTarget:nil
lpromero 2017/04/18 09:34:11 This uses nil-targeting but not the others. Consid
sczs 2017/04/19 22:49:00 Good catch. Done.
109 action:@selector(closeToolsMenu)
110 forControlEvents:UIControlEventTouchUpInside];
111 [self.toolbarOverflowStackView.reloadButton
112 addTarget:self
113 action:@selector(reloadPage)
114 forControlEvents:UIControlEventTouchUpInside];
115 [self.toolbarOverflowStackView.stopButton
116 addTarget:self
117 action:@selector(stopLoadingPage)
118 forControlEvents:UIControlEventTouchUpInside];
119
120 [self.menuStackView insertArrangedSubview:self.toolbarOverflowStackView
121 atIndex:0];
122 [NSLayoutConstraint activateConstraints:@[
123 [self.toolbarOverflowStackView.leadingAnchor
124 constraintEqualToAnchor:self.menuStackView.leadingAnchor],
125 [self.toolbarOverflowStackView.trailingAnchor
126 constraintEqualToAnchor:self.menuStackView.trailingAnchor],
106 ]]; 127 ]];
107 } 128 }
108 129
109 #pragma mark - ToolsMenuCommands 130 #pragma mark - ToolsMenuCommands
110 131
111 - (void)closeToolsMenu:(id)sender { 132 - (void)closeToolsMenu {
112 [self.dispatcher closeToolsMenu]; 133 [self.dispatcher closeToolsMenu];
113 } 134 }
114 135
115 - (void)showFindInPage { 136 - (void)showFindInPage {
116 [self.dispatcher showFindInPage]; 137 [self.dispatcher showFindInPage];
lpromero 2017/04/18 09:34:11 Should this also close the tools menu if opened?
marq (ping after 24h) 2017/04/18 12:11:23 It does already; all of the regular menu buttons h
lpromero 2017/04/18 12:12:16 Acknowledged.
117 } 138 }
118 139
140 #pragma mark - NavigationCommands
141
142 - (void)reloadPage {
143 [self.dispatcher reloadPage];
144 [self closeToolsMenu];
marq (ping after 24h) 2017/04/18 12:11:23 Please follow the pattern of the other menu contro
sczs 2017/04/19 22:49:00 Done.
145 }
146
147 - (void)stopLoadingPage {
148 [self.dispatcher stopLoadingPage];
149 [self closeToolsMenu];
150 }
151
119 #pragma mark - Tools Consumer 152 #pragma mark - Tools Consumer
120 153
121 - (void)setToolsMenuItems:(NSArray*)menuItems { 154 - (void)setToolsMenuItems:(NSArray*)menuItems {
122 _menuItems = menuItems; 155 _menuItems = menuItems;
123 } 156 }
124 157
125 @end 158 @end
OLDNEW
« no previous file with comments | « ios/clean/chrome/browser/ui/tools/menu_view_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698