OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "ios/clean/chrome/browser/ui/ntp/ntp_coordinator.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "ios/chrome/browser/ui/ui_util.h" |
| 9 #import "ios/clean/chrome/browser/ui/bookmarks/bookmarks_coordinator.h" |
| 10 #import "ios/clean/chrome/browser/ui/commands/ntp_commands.h" |
| 11 #import "ios/clean/chrome/browser/ui/ntp/ntp_home_coordinator.h" |
| 12 #import "ios/clean/chrome/browser/ui/ntp/ntp_mediator.h" |
| 13 #import "ios/clean/chrome/browser/ui/ntp/ntp_view_controller.h" |
| 14 #import "ios/clean/chrome/browser/ui/recent_tabs/recent_tabs_coordinator.h" |
| 15 #import "ios/shared/chrome/browser/ui/browser_list/browser.h" |
| 16 #import "ios/shared/chrome/browser/ui/commands/command_dispatcher.h" |
| 17 #import "ios/shared/chrome/browser/ui/coordinators/browser_coordinator+internal.
h" |
| 18 |
| 19 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 20 #error "This file requires ARC support." |
| 21 #endif |
| 22 |
| 23 @interface NTPCoordinator ()<NTPCommands> |
| 24 @property(nonatomic, strong) NTPMediator* mediator; |
| 25 @property(nonatomic, strong) NTPViewController* viewController; |
| 26 @end |
| 27 |
| 28 @implementation NTPCoordinator |
| 29 @synthesize mediator = _mediator; |
| 30 @synthesize viewController = _viewController; |
| 31 |
| 32 - (void)start { |
| 33 self.viewController = [[NTPViewController alloc] init]; |
| 34 self.mediator = [[NTPMediator alloc] initWithConsumer:self.viewController]; |
| 35 |
| 36 CommandDispatcher* dispatcher = self.browser->dispatcher(); |
| 37 // NTPCommands |
| 38 [dispatcher startDispatchingToTarget:self |
| 39 forSelector:@selector(showNTPHomePanel)]; |
| 40 [dispatcher startDispatchingToTarget:self |
| 41 forSelector:@selector(showNTPBookmarksPanel)]; |
| 42 [dispatcher startDispatchingToTarget:self |
| 43 forSelector:@selector(showNTPRecentTabsPanel)]; |
| 44 self.viewController.dispatcher = static_cast<id>(self.browser->dispatcher()); |
| 45 [super start]; |
| 46 } |
| 47 |
| 48 - (void)stop { |
| 49 [super stop]; |
| 50 // PLACEHOLDER: Stop child coordinators here for now. We might deal with this |
| 51 // differently later on. |
| 52 for (BrowserCoordinator* child in self.children) { |
| 53 [child stop]; |
| 54 } |
| 55 [self.browser->dispatcher() stopDispatchingToTarget:self]; |
| 56 } |
| 57 |
| 58 - (void)childCoordinatorDidStart:(BrowserCoordinator*)coordinator { |
| 59 if ([coordinator isKindOfClass:[NTPHomeCoordinator class]]) { |
| 60 self.viewController.homeViewController = coordinator.viewController; |
| 61 |
| 62 } else if ([coordinator isKindOfClass:[BookmarksCoordinator class]]) { |
| 63 if (IsIPadIdiom()) { |
| 64 self.viewController.bookmarksViewController = coordinator.viewController; |
| 65 } else { |
| 66 [self.viewController presentViewController:coordinator.viewController |
| 67 animated:YES |
| 68 completion:nil]; |
| 69 } |
| 70 |
| 71 } else if ([coordinator isKindOfClass:[RecentTabsCoordinator class]]) { |
| 72 if (IsIPadIdiom()) { |
| 73 self.viewController.recentTabsViewController = coordinator.viewController; |
| 74 } else { |
| 75 [self.viewController presentViewController:coordinator.viewController |
| 76 animated:YES |
| 77 completion:nil]; |
| 78 } |
| 79 } |
| 80 } |
| 81 |
| 82 #pragma mark - NTPCommands |
| 83 |
| 84 - (void)showNTPHomePanel { |
| 85 NTPHomeCoordinator* panelCoordinator = [[NTPHomeCoordinator alloc] init]; |
| 86 [self addChildCoordinator:panelCoordinator]; |
| 87 [panelCoordinator start]; |
| 88 } |
| 89 |
| 90 - (void)showNTPBookmarksPanel { |
| 91 BookmarksCoordinator* panelCoordinator = [[BookmarksCoordinator alloc] init]; |
| 92 [self addChildCoordinator:panelCoordinator]; |
| 93 [panelCoordinator start]; |
| 94 } |
| 95 |
| 96 - (void)showNTPRecentTabsPanel { |
| 97 RecentTabsCoordinator* panelCoordinator = |
| 98 [[RecentTabsCoordinator alloc] init]; |
| 99 [self addChildCoordinator:panelCoordinator]; |
| 100 [panelCoordinator start]; |
| 101 } |
| 102 |
| 103 @end |
OLD | NEW |