| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/showcase/toolbar/sc_toolbar_coordinator.h" | 5 #import "ios/showcase/toolbar/sc_toolbar_coordinator.h" |
| 6 | 6 |
| 7 #import "ios/clean/chrome/browser/ui/commands/navigation_commands.h" | 7 #import "ios/clean/chrome/browser/ui/commands/navigation_commands.h" |
| 8 #import "ios/clean/chrome/browser/ui/commands/tab_grid_commands.h" | 8 #import "ios/clean/chrome/browser/ui/commands/tab_grid_commands.h" |
| 9 #import "ios/clean/chrome/browser/ui/commands/tab_strip_commands.h" |
| 9 #import "ios/clean/chrome/browser/ui/commands/tools_menu_commands.h" | 10 #import "ios/clean/chrome/browser/ui/commands/tools_menu_commands.h" |
| 10 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_view_controller.h" | 11 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_view_controller.h" |
| 11 #import "ios/showcase/common/protocol_alerter.h" | 12 #import "ios/showcase/common/protocol_alerter.h" |
| 12 | 13 |
| 13 #if !defined(__has_feature) || !__has_feature(objc_arc) | 14 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 14 #error "This file requires ARC support." | 15 #error "This file requires ARC support." |
| 15 #endif | 16 #endif |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 // Toolbar height. | 19 // Toolbar height. |
| 19 CGFloat kToolbarHeight = 50.0f; | 20 CGFloat kToolbarHeight = 50.0f; |
| 20 } // namespace | 21 } // namespace |
| 21 | 22 |
| 22 @interface SCToolbarCoordinator () | 23 @interface SCToolbarCoordinator () |
| 23 @property(nonatomic, strong) ProtocolAlerter* alerter; | 24 @property(nonatomic, strong) ProtocolAlerter* alerter; |
| 24 @end | 25 @end |
| 25 | 26 |
| 26 @implementation SCToolbarCoordinator | 27 @implementation SCToolbarCoordinator |
| 27 @synthesize baseViewController = _baseViewController; | 28 @synthesize baseViewController = _baseViewController; |
| 28 @synthesize alerter = _alerter; | 29 @synthesize alerter = _alerter; |
| 29 | 30 |
| 30 - (void)start { | 31 - (void)start { |
| 31 self.alerter = [[ProtocolAlerter alloc] initWithProtocols:@[ | 32 self.alerter = [[ProtocolAlerter alloc] initWithProtocols:@[ |
| 32 @protocol(NavigationCommands), @protocol(TabGridCommands), | 33 @protocol(NavigationCommands), @protocol(TabGridCommands), |
| 33 @protocol(ToolsMenuCommands) | 34 @protocol(TabStripCommands), @protocol(ToolsMenuCommands) |
| 34 ]]; | 35 ]]; |
| 35 self.alerter.baseViewController = self.baseViewController; | 36 self.alerter.baseViewController = self.baseViewController; |
| 36 | 37 |
| 37 UIViewController* containerViewController = [[UIViewController alloc] init]; | 38 UIViewController* containerViewController = [[UIViewController alloc] init]; |
| 38 containerViewController.view.backgroundColor = [UIColor whiteColor]; | 39 containerViewController.view.backgroundColor = [UIColor whiteColor]; |
| 39 containerViewController.title = @"Toolbar"; | 40 containerViewController.title = @"Toolbar"; |
| 40 | 41 |
| 41 UIView* containerView = [[UIView alloc] init]; | 42 UIView* containerView = [[UIView alloc] init]; |
| 42 [containerViewController.view addSubview:containerView]; | 43 [containerViewController.view addSubview:containerView]; |
| 43 containerView.backgroundColor = [UIColor redColor]; | 44 containerView.backgroundColor = [UIColor redColor]; |
| 44 containerView.translatesAutoresizingMaskIntoConstraints = NO; | 45 containerView.translatesAutoresizingMaskIntoConstraints = NO; |
| 45 | 46 |
| 46 ToolbarViewController* toolbarViewController = | 47 ToolbarViewController* toolbarViewController = |
| 47 [[ToolbarViewController alloc] init]; | 48 [[ToolbarViewController alloc] init]; |
| 48 toolbarViewController.dispatcher = | 49 toolbarViewController.dispatcher = |
| 49 static_cast<id<NavigationCommands, TabGridCommands, ToolsMenuCommands>>( | 50 static_cast<id<NavigationCommands, TabGridCommands, TabStripCommands, |
| 50 self.alerter); | 51 ToolsMenuCommands>>(self.alerter); |
| 51 [containerViewController addChildViewController:toolbarViewController]; | 52 [containerViewController addChildViewController:toolbarViewController]; |
| 52 toolbarViewController.view.frame = containerView.frame; | 53 toolbarViewController.view.frame = containerView.frame; |
| 53 [containerView addSubview:toolbarViewController.view]; | 54 [containerView addSubview:toolbarViewController.view]; |
| 54 [toolbarViewController didMoveToParentViewController:containerViewController]; | 55 [toolbarViewController didMoveToParentViewController:containerViewController]; |
| 55 | 56 |
| 56 [NSLayoutConstraint activateConstraints:@[ | 57 [NSLayoutConstraint activateConstraints:@[ |
| 57 [containerView.heightAnchor constraintEqualToConstant:kToolbarHeight], | 58 [containerView.heightAnchor constraintEqualToConstant:kToolbarHeight], |
| 58 [containerView.leadingAnchor | 59 [containerView.leadingAnchor |
| 59 constraintEqualToAnchor:containerViewController.view.leadingAnchor], | 60 constraintEqualToAnchor:containerViewController.view.leadingAnchor], |
| 60 [containerView.trailingAnchor | 61 [containerView.trailingAnchor |
| 61 constraintEqualToAnchor:containerViewController.view.trailingAnchor], | 62 constraintEqualToAnchor:containerViewController.view.trailingAnchor], |
| 62 [containerView.centerYAnchor | 63 [containerView.centerYAnchor |
| 63 constraintEqualToAnchor:containerViewController.view.centerYAnchor], | 64 constraintEqualToAnchor:containerViewController.view.centerYAnchor], |
| 64 ]]; | 65 ]]; |
| 65 | 66 |
| 66 [self.baseViewController pushViewController:containerViewController | 67 [self.baseViewController pushViewController:containerViewController |
| 67 animated:YES]; | 68 animated:YES]; |
| 68 } | 69 } |
| 69 | 70 |
| 70 @end | 71 @end |
| OLD | NEW |