| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // ====== New Architecture ===== | |
| 6 // = This code is only used in the new iOS Chrome architecture. = | |
| 7 // ============================================================================ | |
| 8 | |
| 9 #import "ios/chrome/browser/ui/tools/menu_view_controller.h" | |
| 10 | |
| 11 #import "base/logging.h" | |
| 12 #import "base/macros.h" | |
| 13 #import "ios/chrome/browser/ui/actions/settings_actions.h" | |
| 14 #import "ios/chrome/browser/ui/actions/tools_menu_actions.h" | |
| 15 | |
| 16 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 17 #error "This file requires ARC support." | |
| 18 #endif | |
| 19 | |
| 20 @implementation MenuViewController | |
| 21 | |
| 22 - (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 = | |
| 35 [[NSMutableArray alloc] initWithCapacity:arraysize(menuItems)]; | |
| 36 | |
| 37 for (size_t i = 0; i < arraysize(menuItems); ++i) { | |
| 38 const MenuItem& item = menuItems[i]; | |
| 39 UIButton* menuButton = [UIButton buttonWithType:UIButtonTypeSystem]; | |
| 40 menuButton.translatesAutoresizingMaskIntoConstraints = NO; | |
| 41 [menuButton setTitle:item.title forState:UIControlStateNormal]; | |
| 42 [menuButton addTarget:nil | |
| 43 action:@selector(closeToolsMenu:) | |
| 44 forControlEvents:UIControlEventTouchUpInside]; | |
| 45 if (item.action) { | |
| 46 [menuButton addTarget:nil | |
| 47 action:item.action | |
| 48 forControlEvents:UIControlEventTouchUpInside]; | |
| 49 } | |
| 50 [buttons addObject:menuButton]; | |
| 51 } | |
| 52 | |
| 53 // Placeholder stack view to hold menu contents. | |
| 54 UIStackView* menu = [[UIStackView alloc] initWithArrangedSubviews:buttons]; | |
| 55 menu.translatesAutoresizingMaskIntoConstraints = NO; | |
| 56 menu.axis = UILayoutConstraintAxisVertical; | |
| 57 menu.distribution = UIStackViewDistributionFillEqually; | |
| 58 menu.alignment = UIStackViewAlignmentLeading; | |
| 59 | |
| 60 [self.view addSubview:menu]; | |
| 61 [NSLayoutConstraint activateConstraints:@[ | |
| 62 [menu.leadingAnchor | |
| 63 constraintEqualToAnchor:self.view.layoutMarginsGuide.leadingAnchor], | |
| 64 [menu.trailingAnchor | |
| 65 constraintEqualToAnchor:self.view.layoutMarginsGuide.trailingAnchor], | |
| 66 [menu.bottomAnchor | |
| 67 constraintEqualToAnchor:self.view.layoutMarginsGuide.bottomAnchor], | |
| 68 [menu.topAnchor | |
| 69 constraintEqualToAnchor:self.view.layoutMarginsGuide.topAnchor], | |
| 70 ]]; | |
| 71 } | |
| 72 | |
| 73 @end | |
| OLD | NEW |