OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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/tab_coordinator.h" | 5 #import "ios/clean/chrome/browser/ui/tab/tab_coordinator.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #import "ios/clean/chrome/browser/ui/animators/zoom_transition_animator.h" | 11 #import "ios/clean/chrome/browser/ui/animators/zoom_transition_animator.h" |
12 #import "ios/clean/chrome/browser/ui/ntp/new_tab_page_coordinator.h" | 12 #import "ios/clean/chrome/browser/ui/ntp/new_tab_page_coordinator.h" |
13 #import "ios/clean/chrome/browser/ui/tab/tab_container_view_controller.h" | 13 #import "ios/clean/chrome/browser/ui/tab/tab_container_view_controller.h" |
14 #import "ios/clean/chrome/browser/ui/tab_strip/tab_strip_coordinator.h" | 14 #import "ios/clean/chrome/browser/ui/tab_strip/tab_strip_coordinator.h" |
15 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_coordinator.h" | 15 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_coordinator.h" |
16 #import "ios/clean/chrome/browser/ui/web_contents/web_coordinator.h" | 16 #import "ios/clean/chrome/browser/ui/web_contents/web_coordinator.h" |
17 #import "ios/shared/chrome/browser/coordinator_context/coordinator_context.h" | |
18 #import "ios/shared/chrome/browser/ui/coordinators/browser_coordinator+internal.
h" | 17 #import "ios/shared/chrome/browser/ui/coordinators/browser_coordinator+internal.
h" |
19 #import "ios/web/public/web_state/web_state.h" | 18 #import "ios/web/public/web_state/web_state.h" |
20 #import "ios/web/public/web_state/web_state_observer_bridge.h" | 19 #import "ios/web/public/web_state/web_state_observer_bridge.h" |
21 | 20 |
22 #if !defined(__has_feature) || !__has_feature(objc_arc) | 21 #if !defined(__has_feature) || !__has_feature(objc_arc) |
23 #error "This file requires ARC support." | 22 #error "This file requires ARC support." |
24 #endif | 23 #endif |
25 | 24 |
26 namespace { | 25 namespace { |
27 // Placeholder "experiment" flag. Change this to YES to have the toolbar at the | 26 // Placeholder "experiment" flag. Change this to YES to have the toolbar at the |
(...skipping 19 matching lines...) Expand all Loading... |
47 - (void)start { | 46 - (void)start { |
48 self.viewController = [self newTabContainer]; | 47 self.viewController = [self newTabContainer]; |
49 self.viewController.transitioningDelegate = self; | 48 self.viewController.transitioningDelegate = self; |
50 self.viewController.modalPresentationStyle = UIModalPresentationCustom; | 49 self.viewController.modalPresentationStyle = UIModalPresentationCustom; |
51 _webStateObserver = | 50 _webStateObserver = |
52 base::MakeUnique<web::WebStateObserverBridge>(self.webState, self); | 51 base::MakeUnique<web::WebStateObserverBridge>(self.webState, self); |
53 | 52 |
54 WebCoordinator* webCoordinator = [[WebCoordinator alloc] init]; | 53 WebCoordinator* webCoordinator = [[WebCoordinator alloc] init]; |
55 webCoordinator.webState = self.webState; | 54 webCoordinator.webState = self.webState; |
56 [self addChildCoordinator:webCoordinator]; | 55 [self addChildCoordinator:webCoordinator]; |
57 // Unset the base view controller, so |webCoordinator| doesn't present its | |
58 // view controller. | |
59 webCoordinator.context.baseViewController = nil; | |
60 [webCoordinator start]; | 56 [webCoordinator start]; |
61 | 57 |
62 ToolbarCoordinator* toolbarCoordinator = [[ToolbarCoordinator alloc] init]; | 58 ToolbarCoordinator* toolbarCoordinator = [[ToolbarCoordinator alloc] init]; |
63 toolbarCoordinator.webState = self.webState; | 59 toolbarCoordinator.webState = self.webState; |
64 [self addChildCoordinator:toolbarCoordinator]; | 60 [self addChildCoordinator:toolbarCoordinator]; |
65 // Unset the base view controller, so |toolbarCoordinator| doesn't present | |
66 // its view controller. | |
67 toolbarCoordinator.context.baseViewController = nil; | |
68 [toolbarCoordinator start]; | 61 [toolbarCoordinator start]; |
69 | 62 |
70 TabStripCoordinator* tabStripCoordinator = [[TabStripCoordinator alloc] init]; | 63 TabStripCoordinator* tabStripCoordinator = [[TabStripCoordinator alloc] init]; |
71 [self addChildCoordinator:tabStripCoordinator]; | 64 [self addChildCoordinator:tabStripCoordinator]; |
72 // Unset the base view controller since this is a contained view controller. | |
73 tabStripCoordinator.context.baseViewController = nil; | |
74 [tabStripCoordinator start]; | 65 [tabStripCoordinator start]; |
75 | 66 |
76 [self.context.baseViewController presentViewController:self.viewController | |
77 animated:self.context.animated | |
78 completion:nil]; | |
79 [super start]; | 67 [super start]; |
80 } | 68 } |
81 | 69 |
82 - (void)stop { | 70 - (void)stop { |
83 [super stop]; | 71 [super stop]; |
84 // PLACEHOLDER: Stop child coordinators here for now. We might deal with this | 72 // PLACEHOLDER: Stop child coordinators here for now. We might deal with this |
85 // differently later on. | 73 // differently later on. |
86 for (BrowserCoordinator* child in self.children) { | 74 for (BrowserCoordinator* child in self.children) { |
87 [child stop]; | 75 [child stop]; |
88 } | 76 } |
89 [self.viewController.presentingViewController | |
90 dismissViewControllerAnimated:self.context.animated | |
91 completion:nil]; | |
92 _webStateObserver.reset(); | 77 _webStateObserver.reset(); |
93 } | 78 } |
94 | 79 |
95 - (void)childCoordinatorDidStart:(BrowserCoordinator*)coordinator { | 80 - (void)childCoordinatorDidStart:(BrowserCoordinator*)childCoordinator { |
96 if ([coordinator isKindOfClass:[ToolbarCoordinator class]]) { | 81 if ([childCoordinator isKindOfClass:[ToolbarCoordinator class]]) { |
97 self.viewController.toolbarViewController = coordinator.viewController; | 82 self.viewController.toolbarViewController = childCoordinator.viewController; |
98 } else if ([coordinator isKindOfClass:[WebCoordinator class]]) { | 83 } else if ([childCoordinator isKindOfClass:[WebCoordinator class]] || |
99 self.viewController.contentViewController = coordinator.viewController; | 84 [childCoordinator isKindOfClass:[NTPCoordinator class]]) { |
100 } else if ([coordinator isKindOfClass:[TabStripCoordinator class]]) { | 85 self.viewController.contentViewController = childCoordinator.viewController; |
101 self.viewController.tabStripViewController = coordinator.viewController; | 86 } else if ([childCoordinator isKindOfClass:[TabStripCoordinator class]]) { |
| 87 self.viewController.tabStripViewController = |
| 88 childCoordinator.viewController; |
102 } | 89 } |
103 } | 90 } |
104 | 91 |
105 - (BOOL)canAddOverlayCoordinator:(BrowserCoordinator*)overlayCoordinator { | 92 - (BOOL)canAddOverlayCoordinator:(BrowserCoordinator*)overlayCoordinator { |
106 // This coordinator will always accept overlay coordinators. | 93 // This coordinator will always accept overlay coordinators. |
107 return YES; | 94 return YES; |
108 } | 95 } |
109 | 96 |
110 #pragma mark - Experiment support | 97 #pragma mark - Experiment support |
111 | 98 |
112 // Create and return a new view controller for use as a tab container; | 99 // Create and return a new view controller for use as a tab container; |
113 // experimental configurations determine which subclass of | 100 // experimental configurations determine which subclass of |
114 // TabContainerViewController to return. | 101 // TabContainerViewController to return. |
115 - (TabContainerViewController*)newTabContainer { | 102 - (TabContainerViewController*)newTabContainer { |
116 if (kUseBottomToolbar) { | 103 if (kUseBottomToolbar) { |
117 return [[BottomToolbarTabViewController alloc] init]; | 104 return [[BottomToolbarTabViewController alloc] init]; |
118 } | 105 } |
119 return [[TopToolbarTabViewController alloc] init]; | 106 return [[TopToolbarTabViewController alloc] init]; |
120 } | 107 } |
121 | 108 |
122 #pragma mark - CRWWebStateObserver | 109 #pragma mark - CRWWebStateObserver |
123 | 110 |
124 // This will eventually be called in -didFinishNavigation and perhaps as an | 111 // This will eventually be called in -didFinishNavigation and perhaps as an |
125 // optimization in some equivalent to loadURL. | 112 // optimization in some equivalent to loadURL. |
126 - (void)webState:(web::WebState*)webState | 113 - (void)webState:(web::WebState*)webState |
127 didCommitNavigationWithDetails:(const web::LoadCommittedDetails&)details { | 114 didCommitNavigationWithDetails:(const web::LoadCommittedDetails&)details { |
128 if (webState->GetLastCommittedURL() == GURL("chrome://newtab/")) { | 115 if (webState->GetLastCommittedURL() == GURL("chrome://newtab/")) { |
129 NTPCoordinator* ntpCoordinator = [[NTPCoordinator alloc] init]; | 116 NTPCoordinator* ntpCoordinator = [[NTPCoordinator alloc] init]; |
130 [self addChildCoordinator:ntpCoordinator]; | 117 [self addChildCoordinator:ntpCoordinator]; |
131 ntpCoordinator.context.baseViewController = nil; | |
132 [ntpCoordinator start]; | 118 [ntpCoordinator start]; |
133 self.viewController.contentViewController = ntpCoordinator.viewController; | |
134 } | 119 } |
135 } | 120 } |
136 | 121 |
137 #pragma mark - UIViewControllerTransitioningDelegate | 122 #pragma mark - UIViewControllerTransitioningDelegate |
138 | 123 |
139 - (id<UIViewControllerAnimatedTransitioning>) | 124 - (id<UIViewControllerAnimatedTransitioning>) |
140 animationControllerForPresentedController:(UIViewController*)presented | 125 animationControllerForPresentedController:(UIViewController*)presented |
141 presentingController:(UIViewController*)presenting | 126 presentingController:(UIViewController*)presenting |
142 sourceController:(UIViewController*)source { | 127 sourceController:(UIViewController*)source { |
143 ZoomTransitionAnimator* animator = [[ZoomTransitionAnimator alloc] init]; | 128 ZoomTransitionAnimator* animator = [[ZoomTransitionAnimator alloc] init]; |
144 animator.presenting = YES; | 129 animator.presenting = YES; |
145 animator.presentationKey = self.presentationKey; | 130 animator.presentationKey = self.presentationKey; |
146 [animator selectDelegate:@[ source, presenting ]]; | 131 [animator selectDelegate:@[ source, presenting ]]; |
147 return animator; | 132 return animator; |
148 } | 133 } |
149 | 134 |
150 - (id<UIViewControllerAnimatedTransitioning>) | 135 - (id<UIViewControllerAnimatedTransitioning>) |
151 animationControllerForDismissedController:(UIViewController*)dismissed { | 136 animationControllerForDismissedController:(UIViewController*)dismissed { |
152 ZoomTransitionAnimator* animator = [[ZoomTransitionAnimator alloc] init]; | 137 ZoomTransitionAnimator* animator = [[ZoomTransitionAnimator alloc] init]; |
153 animator.presenting = NO; | 138 animator.presenting = NO; |
154 animator.presentationKey = self.presentationKey; | 139 animator.presentationKey = self.presentationKey; |
155 [animator selectDelegate:@[ dismissed.presentingViewController ]]; | 140 [animator selectDelegate:@[ dismissed.presentingViewController ]]; |
156 return animator; | 141 return animator; |
157 } | 142 } |
158 | 143 |
159 @end | 144 @end |
OLD | NEW |