OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/chrome/browser/ui/ntp/new_tab_page_controller.h" | 5 #import "ios/chrome/browser/ui/ntp/new_tab_page_controller.h" |
6 | 6 |
7 #import <QuartzCore/QuartzCore.h> | 7 #import <QuartzCore/QuartzCore.h> |
8 | 8 |
9 #import "base/ios/weak_nsobject.h" | 9 #import "base/ios/weak_nsobject.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 | 165 |
166 // To ease modernizing the NTP only the internal panels are being converted | 166 // To ease modernizing the NTP only the internal panels are being converted |
167 // to UIViewControllers. This means all the plumbing between the | 167 // to UIViewControllers. This means all the plumbing between the |
168 // BrowserViewController and the internal NTP panels (WebController, NTP) | 168 // BrowserViewController and the internal NTP panels (WebController, NTP) |
169 // hierarchy is skipped. While normally the logic to push and pop a view | 169 // hierarchy is skipped. While normally the logic to push and pop a view |
170 // controller would be owned by a coordinator, in this case the old NTP | 170 // controller would be owned by a coordinator, in this case the old NTP |
171 // controller adds and removes child view controllers itself when a load | 171 // controller adds and removes child view controllers itself when a load |
172 // is initiated, and when WebController calls -willBeDismissed. | 172 // is initiated, and when WebController calls -willBeDismissed. |
173 @property(nonatomic, assign) UIViewController* parentViewController; | 173 @property(nonatomic, assign) UIViewController* parentViewController; |
174 | 174 |
| 175 // To ease modernizing the NTP a non-descript CommandDispatcher is passed thru |
| 176 // to be used by the reuabled NTP panels. |
| 177 @property(nonatomic, assign) id dispatcher; |
| 178 |
175 @end | 179 @end |
176 | 180 |
177 @implementation NewTabPageController | 181 @implementation NewTabPageController |
178 | 182 |
179 @synthesize ntpView = newTabPageView_; | 183 @synthesize ntpView = newTabPageView_; |
180 @synthesize swipeRecognizerProvider = swipeRecognizerProvider_; | 184 @synthesize swipeRecognizerProvider = swipeRecognizerProvider_; |
181 @synthesize parentViewController = parentViewController_; | 185 @synthesize parentViewController = parentViewController_; |
| 186 @synthesize dispatcher = dispatcher_; |
182 | 187 |
183 - (id)initWithUrl:(const GURL&)url | 188 - (id)initWithUrl:(const GURL&)url |
184 loader:(id<UrlLoader>)loader | 189 loader:(id<UrlLoader>)loader |
185 focuser:(id<OmniboxFocuser>)focuser | 190 focuser:(id<OmniboxFocuser>)focuser |
186 ntpObserver:(id<NewTabPageControllerObserver>)ntpObserver | 191 ntpObserver:(id<NewTabPageControllerObserver>)ntpObserver |
187 browserState:(ios::ChromeBrowserState*)browserState | 192 browserState:(ios::ChromeBrowserState*)browserState |
188 colorCache:(NSMutableDictionary*)colorCache | 193 colorCache:(NSMutableDictionary*)colorCache |
189 webToolbarDelegate:(id<WebToolbarDelegate>)webToolbarDelegate | 194 webToolbarDelegate:(id<WebToolbarDelegate>)webToolbarDelegate |
190 tabModel:(TabModel*)tabModel | 195 tabModel:(TabModel*)tabModel |
191 parentViewController:(UIViewController*)parentViewController { | 196 parentViewController:(UIViewController*)parentViewController |
| 197 dispatcher:(id)dispatcher { |
192 self = [super initWithNibName:nil url:url]; | 198 self = [super initWithNibName:nil url:url]; |
193 if (self) { | 199 if (self) { |
194 DCHECK(browserState); | 200 DCHECK(browserState); |
195 propertyReleaser_NewTabPageController_.Init(self, | 201 propertyReleaser_NewTabPageController_.Init(self, |
196 [NewTabPageController class]); | 202 [NewTabPageController class]); |
197 browserState_ = browserState; | 203 browserState_ = browserState; |
198 loader_ = loader; | 204 loader_ = loader; |
199 newTabPageObserver_ = ntpObserver; | 205 newTabPageObserver_ = ntpObserver; |
200 parentViewController_ = parentViewController; | 206 parentViewController_ = parentViewController; |
| 207 dispatcher_ = dispatcher; |
201 focuser_.reset(focuser); | 208 focuser_.reset(focuser); |
202 webToolbarDelegate_.reset(webToolbarDelegate); | 209 webToolbarDelegate_.reset(webToolbarDelegate); |
203 tabModel_.reset([tabModel retain]); | 210 tabModel_.reset([tabModel retain]); |
204 dominantColorCache_ = colorCache; | 211 dominantColorCache_ = colorCache; |
205 self.title = l10n_util::GetNSString(IDS_NEW_TAB_TITLE); | 212 self.title = l10n_util::GetNSString(IDS_NEW_TAB_TITLE); |
206 scrollInitialized_ = NO; | 213 scrollInitialized_ = NO; |
207 | 214 |
208 base::scoped_nsobject<UIScrollView> scrollView( | 215 base::scoped_nsobject<UIScrollView> scrollView( |
209 [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 412)]); | 216 [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 412)]); |
210 [scrollView setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | | 217 [scrollView setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 bookmarkPanelControllerForBrowserState:browserState_ | 539 bookmarkPanelControllerForBrowserState:browserState_ |
533 loader:loader_ | 540 loader:loader_ |
534 colorCache:dominantColorCache_] retain]); | 541 colorCache:dominantColorCache_] retain]); |
535 } | 542 } |
536 panelController = bookmarkController_; | 543 panelController = bookmarkController_; |
537 view = [bookmarkController_ view]; | 544 view = [bookmarkController_ view]; |
538 [bookmarkController_ setDelegate:self]; | 545 [bookmarkController_ setDelegate:self]; |
539 } else if (item.identifier == NewTabPage::kMostVisitedPanel) { | 546 } else if (item.identifier == NewTabPage::kMostVisitedPanel) { |
540 if (!googleLandingController_) { | 547 if (!googleLandingController_) { |
541 googleLandingController_.reset([[GoogleLandingController alloc] init]); | 548 googleLandingController_.reset([[GoogleLandingController alloc] init]); |
| 549 [googleLandingController_ setDispatcher:self.dispatcher]; |
542 googleLandingMediator_.reset([[GoogleLandingMediator alloc] | 550 googleLandingMediator_.reset([[GoogleLandingMediator alloc] |
543 initWithConsumer:googleLandingController_ | 551 initWithConsumer:googleLandingController_ |
544 browserState:browserState_ | 552 browserState:browserState_ |
545 loader:loader_ | 553 dispatcher:self.dispatcher |
546 focuser:focuser_ | 554 webStateList:[tabModel_ webStateList]]); |
547 webToolbarDelegate:webToolbarDelegate_ | |
548 webStateList:[tabModel_ webStateList]]); | |
549 [googleLandingController_ setDataSource:googleLandingMediator_]; | 555 [googleLandingController_ setDataSource:googleLandingMediator_]; |
550 } | 556 } |
551 panelController = googleLandingController_; | 557 panelController = googleLandingController_; |
552 view = [googleLandingController_ view]; | 558 view = [googleLandingController_ view]; |
553 [googleLandingController_ setDelegate:self]; | 559 [googleLandingController_ setDelegate:self]; |
554 } else if (item.identifier == NewTabPage::kOpenTabsPanel) { | 560 } else if (item.identifier == NewTabPage::kOpenTabsPanel) { |
555 if (!openTabsController_) | 561 if (!openTabsController_) |
556 openTabsController_.reset([[RecentTabsPanelController alloc] | 562 openTabsController_.reset([[RecentTabsPanelController alloc] |
557 initWithLoader:loader_ | 563 initWithLoader:loader_ |
558 browserState:browserState_]); | 564 browserState:browserState_]); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 | 739 |
734 - (void)updateNtpBarShadowForPanelController: | 740 - (void)updateNtpBarShadowForPanelController: |
735 (id<NewTabPagePanelProtocol>)ntpPanelController { | 741 (id<NewTabPagePanelProtocol>)ntpPanelController { |
736 if (currentController_ != ntpPanelController) | 742 if (currentController_ != ntpPanelController) |
737 return; | 743 return; |
738 [self.ntpView.tabBar | 744 [self.ntpView.tabBar |
739 setShadowAlpha:[ntpPanelController alphaForBottomShadow]]; | 745 setShadowAlpha:[ntpPanelController alphaForBottomShadow]]; |
740 } | 746 } |
741 | 747 |
742 @end | 748 @end |
OLD | NEW |