OLD | NEW |
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/tools_menu_commands.h" | 12 #import "ios/clean/chrome/browser/ui/commands/tools_menu_commands.h" |
12 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_button.h" | 13 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_button.h" |
13 #import "ios/clean/chrome/browser/ui/tools/menu_overflow_controls_stackview.h" | 14 #import "ios/clean/chrome/browser/ui/tools/menu_overflow_controls_stackview.h" |
| 15 #import "ios/clean/chrome/browser/ui/tools/tools_actions.h" |
14 #import "ios/clean/chrome/browser/ui/tools/tools_menu_item.h" | 16 #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" | 17 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF
ontLoader.h" |
16 | 18 |
17 #if !defined(__has_feature) || !__has_feature(objc_arc) | 19 #if !defined(__has_feature) || !__has_feature(objc_arc) |
18 #error "This file requires ARC support." | 20 #error "This file requires ARC support." |
19 #endif | 21 #endif |
20 | 22 |
21 namespace { | 23 namespace { |
22 const CGFloat kMenuWidth = 250; | 24 const CGFloat kMenuWidth = 250; |
23 const CGFloat kMenuItemHeight = 48; | 25 const CGFloat kMenuItemHeight = 48; |
24 } | 26 } |
25 | 27 |
26 @interface MenuViewController () | 28 @interface MenuViewController ()<ToolsActions> |
27 @property(nonatomic, strong) NSArray<ToolsMenuItem*>* menuItems; | 29 @property(nonatomic, strong) NSArray<ToolsMenuItem*>* menuItems; |
28 @property(nonatomic, strong) | 30 @property(nonatomic, strong) |
29 MenuOverflowControlsStackView* toolbarOverflowStackView; | 31 MenuOverflowControlsStackView* toolbarOverflowStackView; |
30 @end | 32 @end |
31 | 33 |
32 @implementation MenuViewController | 34 @implementation MenuViewController |
| 35 @synthesize dispatcher = _dispatcher; |
33 @synthesize menuItems = _menuItems; | 36 @synthesize menuItems = _menuItems; |
34 @synthesize toolbarOverflowStackView = _toolbarOverflowStackView; | 37 @synthesize toolbarOverflowStackView = _toolbarOverflowStackView; |
35 @synthesize dispatcher = _dispatcher; | |
36 | 38 |
37 - (void)loadView { | 39 - (void)loadView { |
38 CGRect frame; | 40 CGRect frame; |
39 frame.size = CGSizeMake(kMenuWidth, kMenuItemHeight * _menuItems.count); | 41 frame.size = CGSizeMake(kMenuWidth, kMenuItemHeight * _menuItems.count); |
40 frame.origin = CGPointZero; | 42 frame.origin = CGPointZero; |
41 self.view = [[UIView alloc] initWithFrame:frame]; | 43 self.view = [[UIView alloc] initWithFrame:frame]; |
42 self.view.backgroundColor = [UIColor whiteColor]; | 44 self.view.backgroundColor = [UIColor whiteColor]; |
43 self.view.autoresizingMask = UIViewAutoresizingNone; | 45 self.view.autoresizingMask = UIViewAutoresizingNone; |
44 self.view.layer.borderColor = [UIColor clearColor].CGColor; | 46 self.view.layer.borderColor = [UIColor clearColor].CGColor; |
45 } | 47 } |
46 | 48 |
47 - (void)viewDidLoad { | 49 - (void)viewDidLoad { |
48 NSMutableArray<UIButton*>* buttons = | 50 NSMutableArray<UIButton*>* buttons = |
49 [[NSMutableArray alloc] initWithCapacity:_menuItems.count]; | 51 [[NSMutableArray alloc] initWithCapacity:_menuItems.count]; |
50 | 52 |
51 for (ToolsMenuItem* item in _menuItems) { | 53 for (ToolsMenuItem* item in _menuItems) { |
52 UIButton* menuButton = [UIButton buttonWithType:UIButtonTypeSystem]; | 54 UIButton* menuButton = [UIButton buttonWithType:UIButtonTypeSystem]; |
53 menuButton.translatesAutoresizingMaskIntoConstraints = NO; | 55 menuButton.translatesAutoresizingMaskIntoConstraints = NO; |
54 menuButton.tintColor = [UIColor blackColor]; | 56 menuButton.tintColor = [UIColor blackColor]; |
55 [menuButton setTitle:item.title forState:UIControlStateNormal]; | 57 [menuButton setTitle:item.title forState:UIControlStateNormal]; |
56 [menuButton setContentEdgeInsets:UIEdgeInsetsMakeDirected(0, 10.0f, 0, 0)]; | 58 [menuButton setContentEdgeInsets:UIEdgeInsetsMakeDirected(0, 10.0f, 0, 0)]; |
57 [menuButton.titleLabel | 59 [menuButton.titleLabel |
58 setFont:[[MDFRobotoFontLoader sharedInstance] regularFontOfSize:16]]; | 60 setFont:[[MDFRobotoFontLoader sharedInstance] regularFontOfSize:16]]; |
59 [menuButton.titleLabel setTextAlignment:NSTextAlignmentNatural]; | 61 [menuButton.titleLabel setTextAlignment:NSTextAlignmentNatural]; |
60 [menuButton addTarget:self | 62 [menuButton addTarget:self |
61 action:@selector(closeToolsMenu:) | 63 action:@selector(closeToolsMenu:) |
62 forControlEvents:UIControlEventTouchUpInside]; | 64 forControlEvents:UIControlEventTouchUpInside]; |
63 if (item.action) { | 65 if (item.action) { |
64 [menuButton addTarget:nil | 66 id target = (item.action == @selector(showFindInPage)) ? self : nil; |
| 67 [menuButton addTarget:target |
65 action:item.action | 68 action:item.action |
66 forControlEvents:UIControlEventTouchUpInside]; | 69 forControlEvents:UIControlEventTouchUpInside]; |
67 } | 70 } |
68 [buttons addObject:menuButton]; | 71 [buttons addObject:menuButton]; |
69 } | 72 } |
70 | 73 |
71 // Placeholder stack view to hold menu contents. | 74 // Placeholder stack view to hold menu contents. |
72 UIStackView* menu = [[UIStackView alloc] initWithArrangedSubviews:buttons]; | 75 UIStackView* menu = [[UIStackView alloc] initWithArrangedSubviews:buttons]; |
73 menu.translatesAutoresizingMaskIntoConstraints = NO; | 76 menu.translatesAutoresizingMaskIntoConstraints = NO; |
74 menu.axis = UILayoutConstraintAxisVertical; | 77 menu.axis = UILayoutConstraintAxisVertical; |
(...skipping 28 matching lines...) Expand all Loading... |
103 [menu.topAnchor constraintEqualToAnchor:self.view.topAnchor], | 106 [menu.topAnchor constraintEqualToAnchor:self.view.topAnchor], |
104 ]]; | 107 ]]; |
105 } | 108 } |
106 | 109 |
107 #pragma mark - ToolsMenuCommands | 110 #pragma mark - ToolsMenuCommands |
108 | 111 |
109 - (void)closeToolsMenu:(id)sender { | 112 - (void)closeToolsMenu:(id)sender { |
110 [self.dispatcher closeToolsMenu]; | 113 [self.dispatcher closeToolsMenu]; |
111 } | 114 } |
112 | 115 |
| 116 - (void)showFindInPage { |
| 117 [self.dispatcher showFindInPage]; |
| 118 } |
| 119 |
113 #pragma mark - Tools Consumer | 120 #pragma mark - Tools Consumer |
114 | 121 |
115 - (void)setToolsMenuItems:(NSArray*)menuItems { | 122 - (void)setToolsMenuItems:(NSArray*)menuItems { |
116 _menuItems = menuItems; | 123 _menuItems = menuItems; |
117 } | 124 } |
118 | 125 |
119 @end | 126 @end |
OLD | NEW |