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/clean/chrome/browser/ui/tab_strip/tab_strip_coordinator.h" | 5 #import "ios/clean/chrome/browser/ui/tab_strip/tab_strip_coordinator.h" |
6 | 6 |
| 7 #import "ios/clean/chrome/browser/ui/commands/tab_strip_commands.h" |
7 #import "ios/clean/chrome/browser/ui/tab_collection/tab_collection_mediator.h" | 8 #import "ios/clean/chrome/browser/ui/tab_collection/tab_collection_mediator.h" |
8 #import "ios/clean/chrome/browser/ui/tab_strip/tab_strip_view_controller.h" | 9 #import "ios/clean/chrome/browser/ui/tab_strip/tab_strip_view_controller.h" |
9 #import "ios/shared/chrome/browser/coordinator_context/coordinator_context.h" | 10 #import "ios/shared/chrome/browser/coordinator_context/coordinator_context.h" |
10 #import "ios/shared/chrome/browser/tabs/web_state_list.h" | 11 #import "ios/shared/chrome/browser/tabs/web_state_list.h" |
11 #import "ios/shared/chrome/browser/ui/browser_list/browser.h" | 12 #import "ios/shared/chrome/browser/ui/browser_list/browser.h" |
| 13 #import "ios/shared/chrome/browser/ui/commands/command_dispatcher.h" |
| 14 #include "ios/web/public/web_state/web_state.h" |
12 | 15 |
13 #if !defined(__has_feature) || !__has_feature(objc_arc) | 16 #if !defined(__has_feature) || !__has_feature(objc_arc) |
14 #error "This file requires ARC support." | 17 #error "This file requires ARC support." |
15 #endif | 18 #endif |
16 | 19 |
17 @interface TabStripCoordinator () | 20 @interface TabStripCoordinator ()<TabStripCommands> |
18 @property(nonatomic, strong) TabStripViewController* viewController; | 21 @property(nonatomic, strong) TabStripViewController* viewController; |
19 @property(nonatomic, strong) TabCollectionMediator* mediator; | 22 @property(nonatomic, strong) TabCollectionMediator* mediator; |
20 @property(nonatomic, readonly) WebStateList& webStateList; | 23 @property(nonatomic, readonly) WebStateList& webStateList; |
21 @end | 24 @end |
22 | 25 |
23 @implementation TabStripCoordinator | 26 @implementation TabStripCoordinator |
24 @synthesize viewController = _viewController; | 27 @synthesize viewController = _viewController; |
25 @synthesize mediator = _mediator; | 28 @synthesize mediator = _mediator; |
26 | 29 |
27 #pragma mark - Properties | 30 #pragma mark - Properties |
28 | 31 |
29 - (WebStateList&)webStateList { | 32 - (WebStateList&)webStateList { |
30 return self.browser->web_state_list(); | 33 return self.browser->web_state_list(); |
31 } | 34 } |
32 | 35 |
33 #pragma mark - BrowserCoordinator | 36 #pragma mark - BrowserCoordinator |
34 | 37 |
35 - (void)start { | 38 - (void)start { |
| 39 CommandDispatcher* dispatcher = self.browser->dispatcher(); |
| 40 [dispatcher startDispatchingToTarget:self |
| 41 forSelector:@selector(showTabStripTabAtIndex:)]; |
| 42 [dispatcher startDispatchingToTarget:self |
| 43 forSelector:@selector(closeTabStripTabAtIndex:)]; |
| 44 |
36 self.viewController = [[TabStripViewController alloc] init]; | 45 self.viewController = [[TabStripViewController alloc] init]; |
37 self.mediator = [[TabCollectionMediator alloc] init]; | 46 self.mediator = [[TabCollectionMediator alloc] init]; |
38 self.mediator.webStateList = &self.webStateList; | 47 self.mediator.webStateList = &self.webStateList; |
39 self.mediator.consumer = self.viewController; | 48 self.mediator.consumer = self.viewController; |
40 self.viewController.dataSource = self.mediator; | 49 self.viewController.dataSource = self.mediator; |
| 50 self.viewController.dispatcher = static_cast<id>(self.browser->dispatcher()); |
41 | 51 |
42 [self.context.baseViewController presentViewController:self.viewController | 52 [self.context.baseViewController presentViewController:self.viewController |
43 animated:self.context.animated | 53 animated:self.context.animated |
44 completion:nil]; | 54 completion:nil]; |
45 [super start]; | 55 [super start]; |
46 } | 56 } |
47 | 57 |
| 58 - (void)stop { |
| 59 [super stop]; |
| 60 [self.browser->dispatcher() stopDispatchingToTarget:self]; |
| 61 } |
| 62 |
| 63 #pragma mark - TabStripCommands |
| 64 |
| 65 - (void)showTabStripTabAtIndex:(int)index { |
| 66 self.webStateList.ActivateWebStateAt(index); |
| 67 } |
| 68 |
| 69 - (void)closeTabStripTabAtIndex:(int)index { |
| 70 std::unique_ptr<web::WebState> closedWebState( |
| 71 self.webStateList.DetachWebStateAt(index)); |
| 72 } |
| 73 |
48 @end | 74 @end |
OLD | NEW |