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

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