| 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/toolbar/toolbar_view_controller.h" | |
| 10 | |
| 11 #import "ios/chrome/browser/ui/actions/tab_grid_actions.h" | |
| 12 #import "ios/chrome/browser/ui/actions/tools_menu_actions.h" | |
| 13 #import "ios/chrome/browser/ui/commands/toolbar_commands.h" | |
| 14 | |
| 15 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 16 #error "This file requires ARC support." | |
| 17 #endif | |
| 18 | |
| 19 @interface ToolbarViewController ()<ToolsMenuActions> | |
| 20 @property(nonatomic, weak) UITextField* omnibox; | |
| 21 @property(nonatomic, weak) UIButton* toolsMenu; | |
| 22 @end | |
| 23 | |
| 24 @implementation ToolbarViewController | |
| 25 @synthesize toolbarCommandHandler = _toolbarCommandHandler; | |
| 26 @synthesize omnibox = _omnibox; | |
| 27 @synthesize toolsMenu = _toolsMenu; | |
| 28 | |
| 29 - (void)viewDidLoad { | |
| 30 self.view.backgroundColor = [UIColor lightGrayColor]; | |
| 31 | |
| 32 // Tab switcher button. | |
| 33 UIButton* tabSwitcher = [UIButton buttonWithType:UIButtonTypeSystem]; | |
| 34 tabSwitcher.translatesAutoresizingMaskIntoConstraints = NO; | |
| 35 [tabSwitcher setTitle:@"⊞" forState:UIControlStateNormal]; | |
| 36 tabSwitcher.titleLabel.font = [UIFont systemFontOfSize:24.0]; | |
| 37 [tabSwitcher addTarget:nil | |
| 38 action:@selector(showTabGrid:) | |
| 39 forControlEvents:UIControlEventTouchUpInside]; | |
| 40 | |
| 41 // Placeholder omnibox. | |
| 42 UITextField* omnibox = [[UITextField alloc] initWithFrame:CGRectZero]; | |
| 43 omnibox.translatesAutoresizingMaskIntoConstraints = NO; | |
| 44 omnibox.backgroundColor = [UIColor whiteColor]; | |
| 45 omnibox.enabled = NO; | |
| 46 self.omnibox = omnibox; | |
| 47 | |
| 48 // Tools menu button. | |
| 49 UIButton* toolsMenu = [UIButton buttonWithType:UIButtonTypeSystem]; | |
| 50 toolsMenu.translatesAutoresizingMaskIntoConstraints = NO; | |
| 51 [toolsMenu setTitle:@"⋮" forState:UIControlStateNormal]; | |
| 52 toolsMenu.titleLabel.font = [UIFont systemFontOfSize:24.0]; | |
| 53 [toolsMenu addTarget:nil | |
| 54 action:@selector(showToolsMenu:) | |
| 55 forControlEvents:UIControlEventTouchUpInside]; | |
| 56 self.toolsMenu = toolsMenu; | |
| 57 | |
| 58 // Stack view to contain toolbar items. | |
| 59 UIStackView* toolbarItems = [[UIStackView alloc] | |
| 60 initWithArrangedSubviews:@[ tabSwitcher, omnibox, toolsMenu ]]; | |
| 61 toolbarItems.translatesAutoresizingMaskIntoConstraints = NO; | |
| 62 toolbarItems.spacing = 16.0; | |
| 63 toolbarItems.distribution = UIStackViewDistributionFillProportionally; | |
| 64 [self.view addSubview:toolbarItems]; | |
| 65 [NSLayoutConstraint activateConstraints:@[ | |
| 66 [toolbarItems.leadingAnchor | |
| 67 constraintEqualToAnchor:self.view.layoutMarginsGuide.leadingAnchor], | |
| 68 [toolbarItems.trailingAnchor | |
| 69 constraintEqualToAnchor:self.view.layoutMarginsGuide.trailingAnchor], | |
| 70 [toolbarItems.bottomAnchor | |
| 71 constraintEqualToAnchor:self.view.layoutMarginsGuide.bottomAnchor], | |
| 72 ]]; | |
| 73 } | |
| 74 | |
| 75 #pragma mark - Public API | |
| 76 | |
| 77 - (void)setCurrentPageText:(NSString*)text { | |
| 78 self.omnibox.text = text; | |
| 79 } | |
| 80 | |
| 81 #pragma mark - ZoomTransitionDelegate | |
| 82 | |
| 83 - (CGRect)rectForZoomWithKey:(NSObject*)key inView:(UIView*)view { | |
| 84 return [view convertRect:self.toolsMenu.bounds fromView:self.toolsMenu]; | |
| 85 } | |
| 86 | |
| 87 #pragma mark - ToolsMenuActions | |
| 88 | |
| 89 - (void)showToolsMenu:(id)sender { | |
| 90 [self.toolbarCommandHandler showToolsMenu]; | |
| 91 } | |
| 92 | |
| 93 - (void)closeToolsMenu:(id)sender { | |
| 94 [self.toolbarCommandHandler closeToolsMenu]; | |
| 95 } | |
| 96 | |
| 97 @end | |
| OLD | NEW |