| 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/actions/tools_menu_actions.h" | 11 #import "ios/clean/chrome/browser/ui/commands/tools_menu_commands.h" |
| 12 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_button.h" | 12 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_button.h" |
| 13 #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" | 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 @interface MenuViewController () | 26 @interface MenuViewController () |
| 27 @property(nonatomic, strong) NSArray<ToolsMenuItem*>* menuItems; | 27 @property(nonatomic, strong) NSArray<ToolsMenuItem*>* menuItems; |
| 28 @property(nonatomic, strong) | 28 @property(nonatomic, strong) |
| 29 MenuOverflowControlsStackView* toolbarOverflowStackView; | 29 MenuOverflowControlsStackView* toolbarOverflowStackView; |
| 30 @end | 30 @end |
| 31 | 31 |
| 32 @implementation MenuViewController | 32 @implementation MenuViewController |
| 33 @synthesize menuItems = _menuItems; | 33 @synthesize menuItems = _menuItems; |
| 34 @synthesize toolbarOverflowStackView = _toolbarOverflowStackView; | 34 @synthesize toolbarOverflowStackView = _toolbarOverflowStackView; |
| 35 @synthesize dispatcher = _dispatcher; |
| 35 | 36 |
| 36 - (void)loadView { | 37 - (void)loadView { |
| 37 CGRect frame; | 38 CGRect frame; |
| 38 frame.size = CGSizeMake(kMenuWidth, kMenuItemHeight * _menuItems.count); | 39 frame.size = CGSizeMake(kMenuWidth, kMenuItemHeight * _menuItems.count); |
| 39 frame.origin = CGPointZero; | 40 frame.origin = CGPointZero; |
| 40 self.view = [[UIView alloc] initWithFrame:frame]; | 41 self.view = [[UIView alloc] initWithFrame:frame]; |
| 41 self.view.backgroundColor = [UIColor whiteColor]; | 42 self.view.backgroundColor = [UIColor whiteColor]; |
| 42 self.view.autoresizingMask = UIViewAutoresizingNone; | 43 self.view.autoresizingMask = UIViewAutoresizingNone; |
| 43 self.view.layer.borderColor = [UIColor clearColor].CGColor; | 44 self.view.layer.borderColor = [UIColor clearColor].CGColor; |
| 44 } | 45 } |
| 45 | 46 |
| 46 - (void)viewDidLoad { | 47 - (void)viewDidLoad { |
| 47 NSMutableArray<UIButton*>* buttons = | 48 NSMutableArray<UIButton*>* buttons = |
| 48 [[NSMutableArray alloc] initWithCapacity:_menuItems.count]; | 49 [[NSMutableArray alloc] initWithCapacity:_menuItems.count]; |
| 49 | 50 |
| 50 for (ToolsMenuItem* item in _menuItems) { | 51 for (ToolsMenuItem* item in _menuItems) { |
| 51 UIButton* menuButton = [UIButton buttonWithType:UIButtonTypeSystem]; | 52 UIButton* menuButton = [UIButton buttonWithType:UIButtonTypeSystem]; |
| 52 menuButton.translatesAutoresizingMaskIntoConstraints = NO; | 53 menuButton.translatesAutoresizingMaskIntoConstraints = NO; |
| 53 menuButton.tintColor = [UIColor blackColor]; | 54 menuButton.tintColor = [UIColor blackColor]; |
| 54 [menuButton setTitle:item.title forState:UIControlStateNormal]; | 55 [menuButton setTitle:item.title forState:UIControlStateNormal]; |
| 55 [menuButton setContentEdgeInsets:UIEdgeInsetsMakeDirected(0, 10.0f, 0, 0)]; | 56 [menuButton setContentEdgeInsets:UIEdgeInsetsMakeDirected(0, 10.0f, 0, 0)]; |
| 56 [menuButton.titleLabel | 57 [menuButton.titleLabel |
| 57 setFont:[[MDFRobotoFontLoader sharedInstance] regularFontOfSize:16]]; | 58 setFont:[[MDFRobotoFontLoader sharedInstance] regularFontOfSize:16]]; |
| 58 [menuButton.titleLabel setTextAlignment:NSTextAlignmentNatural]; | 59 [menuButton.titleLabel setTextAlignment:NSTextAlignmentNatural]; |
| 59 [menuButton addTarget:nil | 60 [menuButton addTarget:self |
| 60 action:@selector(closeToolsMenu:) | 61 action:@selector(closeToolsMenu:) |
| 61 forControlEvents:UIControlEventTouchUpInside]; | 62 forControlEvents:UIControlEventTouchUpInside]; |
| 62 if (item.action) { | 63 if (item.action) { |
| 63 [menuButton addTarget:nil | 64 [menuButton addTarget:nil |
| 64 action:item.action | 65 action:item.action |
| 65 forControlEvents:UIControlEventTouchUpInside]; | 66 forControlEvents:UIControlEventTouchUpInside]; |
| 66 } | 67 } |
| 67 [buttons addObject:menuButton]; | 68 [buttons addObject:menuButton]; |
| 68 } | 69 } |
| 69 | 70 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 96 | 97 |
| 97 [self.view addSubview:menu]; | 98 [self.view addSubview:menu]; |
| 98 [NSLayoutConstraint activateConstraints:@[ | 99 [NSLayoutConstraint activateConstraints:@[ |
| 99 [menu.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor], | 100 [menu.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor], |
| 100 [menu.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor], | 101 [menu.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor], |
| 101 [menu.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor], | 102 [menu.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor], |
| 102 [menu.topAnchor constraintEqualToAnchor:self.view.topAnchor], | 103 [menu.topAnchor constraintEqualToAnchor:self.view.topAnchor], |
| 103 ]]; | 104 ]]; |
| 104 } | 105 } |
| 105 | 106 |
| 107 #pragma mark - ToolsMenuCommands |
| 108 |
| 109 - (void)closeToolsMenu:(id)sender { |
| 110 [self.dispatcher closeToolsMenu]; |
| 111 } |
| 112 |
| 106 #pragma mark - Tools Consumer | 113 #pragma mark - Tools Consumer |
| 107 | 114 |
| 108 - (void)setToolsMenuItems:(NSArray*)menuItems { | 115 - (void)setToolsMenuItems:(NSArray*)menuItems { |
| 109 _menuItems = menuItems; | 116 _menuItems = menuItems; |
| 110 } | 117 } |
| 111 | 118 |
| 112 @end | 119 @end |
| OLD | NEW |