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