| 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 // ====== New Architecture ===== | 5 // ====== New Architecture ===== |
| 6 // = This code is only used in the new iOS Chrome architecture. = | 6 // = This code is only used in the new iOS Chrome architecture. = |
| 7 // ============================================================================ | 7 // ============================================================================ |
| 8 | 8 |
| 9 #import "ios/clean/chrome/browser/ui/tools/menu_view_controller.h" | 9 #import "ios/clean/chrome/browser/ui/tools/menu_view_controller.h" |
| 10 | 10 |
| 11 #import "base/logging.h" | 11 #import "base/logging.h" |
| 12 #import "base/macros.h" | 12 #import "base/macros.h" |
| 13 #import "ios/clean/chrome/browser/ui/actions/settings_actions.h" | 13 #import "ios/clean/chrome/browser/ui/actions/settings_actions.h" |
| 14 #import "ios/clean/chrome/browser/ui/actions/tools_menu_actions.h" | 14 #import "ios/clean/chrome/browser/ui/actions/tools_menu_actions.h" |
| 15 | 15 |
| 16 #if !defined(__has_feature) || !__has_feature(objc_arc) | 16 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 17 #error "This file requires ARC support." | 17 #error "This file requires ARC support." |
| 18 #endif | 18 #endif |
| 19 | 19 |
| 20 namespace { |
| 21 const CGFloat kMenuWidth = 250; |
| 22 const CGFloat kMenuItemHeight = 44; |
| 23 } |
| 24 |
| 25 // Placeholder model for menu item configuration. |
| 26 @interface MenuItem : NSObject |
| 27 @property(nonatomic, copy) NSString* title; |
| 28 @property(nonatomic) SEL action; |
| 29 @end |
| 30 |
| 31 @implementation MenuItem |
| 32 @synthesize title = _title; |
| 33 @synthesize action = _action; |
| 34 @end |
| 35 |
| 36 @interface MenuViewController () |
| 37 @property(nonatomic, readonly) NSArray<MenuItem*>* menuItems; |
| 38 @end |
| 39 |
| 20 @implementation MenuViewController | 40 @implementation MenuViewController |
| 41 @synthesize menuItems = _menuItems; |
| 42 |
| 43 - (instancetype)init { |
| 44 if ((self = [super init])) { |
| 45 _menuItems = @[ |
| 46 [[MenuItem alloc] init], [[MenuItem alloc] init], [[MenuItem alloc] init], |
| 47 [[MenuItem alloc] init] |
| 48 ]; |
| 49 |
| 50 _menuItems[0].title = @"New Tab"; |
| 51 |
| 52 _menuItems[1].title = @"Find in Page…"; |
| 53 |
| 54 _menuItems[2].title = @"Request Desktop Site"; |
| 55 |
| 56 _menuItems[3].title = @"Settings"; |
| 57 _menuItems[3].action = @selector(showSettings:); |
| 58 } |
| 59 return self; |
| 60 } |
| 61 |
| 62 - (void)loadView { |
| 63 CGRect frame; |
| 64 frame.size = CGSizeMake(kMenuWidth, kMenuItemHeight * _menuItems.count); |
| 65 frame.origin = CGPointZero; |
| 66 self.view = [[UIView alloc] initWithFrame:frame]; |
| 67 self.view.backgroundColor = [UIColor whiteColor]; |
| 68 self.view.autoresizingMask = UIViewAutoresizingNone; |
| 69 } |
| 21 | 70 |
| 22 - (void)viewDidLoad { | 71 - (void)viewDidLoad { |
| 23 self.view.backgroundColor = [UIColor whiteColor]; | |
| 24 struct MenuItem { | |
| 25 NSString* title; | |
| 26 SEL action; | |
| 27 }; | |
| 28 MenuItem menuItems[] = { | |
| 29 {@"New Tab", nullptr}, | |
| 30 {@"Find in Page…", nullptr}, | |
| 31 {@"Request Desktop Site", nullptr}, | |
| 32 {@"Settings", @selector(showSettings:)}, | |
| 33 }; | |
| 34 NSMutableArray<UIButton*>* buttons = | 72 NSMutableArray<UIButton*>* buttons = |
| 35 [[NSMutableArray alloc] initWithCapacity:arraysize(menuItems)]; | 73 [[NSMutableArray alloc] initWithCapacity:_menuItems.count]; |
| 36 | 74 |
| 37 for (size_t i = 0; i < arraysize(menuItems); ++i) { | 75 for (MenuItem* item in _menuItems) { |
| 38 const MenuItem& item = menuItems[i]; | |
| 39 UIButton* menuButton = [UIButton buttonWithType:UIButtonTypeSystem]; | 76 UIButton* menuButton = [UIButton buttonWithType:UIButtonTypeSystem]; |
| 40 menuButton.translatesAutoresizingMaskIntoConstraints = NO; | 77 menuButton.translatesAutoresizingMaskIntoConstraints = NO; |
| 41 [menuButton setTitle:item.title forState:UIControlStateNormal]; | 78 [menuButton setTitle:item.title forState:UIControlStateNormal]; |
| 42 [menuButton addTarget:nil | 79 [menuButton addTarget:nil |
| 43 action:@selector(closeToolsMenu:) | 80 action:@selector(closeToolsMenu:) |
| 44 forControlEvents:UIControlEventTouchUpInside]; | 81 forControlEvents:UIControlEventTouchUpInside]; |
| 45 if (item.action) { | 82 if (item.action) { |
| 46 [menuButton addTarget:nil | 83 [menuButton addTarget:nil |
| 47 action:item.action | 84 action:item.action |
| 48 forControlEvents:UIControlEventTouchUpInside]; | 85 forControlEvents:UIControlEventTouchUpInside]; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 64 [menu.trailingAnchor | 101 [menu.trailingAnchor |
| 65 constraintEqualToAnchor:self.view.layoutMarginsGuide.trailingAnchor], | 102 constraintEqualToAnchor:self.view.layoutMarginsGuide.trailingAnchor], |
| 66 [menu.bottomAnchor | 103 [menu.bottomAnchor |
| 67 constraintEqualToAnchor:self.view.layoutMarginsGuide.bottomAnchor], | 104 constraintEqualToAnchor:self.view.layoutMarginsGuide.bottomAnchor], |
| 68 [menu.topAnchor | 105 [menu.topAnchor |
| 69 constraintEqualToAnchor:self.view.layoutMarginsGuide.topAnchor], | 106 constraintEqualToAnchor:self.view.layoutMarginsGuide.topAnchor], |
| 70 ]]; | 107 ]]; |
| 71 } | 108 } |
| 72 | 109 |
| 73 @end | 110 @end |
| OLD | NEW |