Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(668)

Side by Side Diff: ios/chrome/browser/ui/ntp/new_tab_page_controller.mm

Issue 2820063003: Fix NTP parentViewController. (Closed)
Patch Set: Fix tests Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 // Update overlay scroll view value. 151 // Update overlay scroll view value.
152 - (void)updateOverlayScrollPosition; 152 - (void)updateOverlayScrollPosition;
153 // Disable the horizontal scroll view. 153 // Disable the horizontal scroll view.
154 - (void)disableScroll; 154 - (void)disableScroll;
155 // Enable the horizontal scroll view. 155 // Enable the horizontal scroll view.
156 - (void)enableScroll; 156 - (void)enableScroll;
157 // Returns the ID for the currently selected panel. 157 // Returns the ID for the currently selected panel.
158 - (NewTabPage::PanelIdentifier)selectedPanelID; 158 - (NewTabPage::PanelIdentifier)selectedPanelID;
159 159
160 @property(nonatomic, retain) NewTabPageView* ntpView; 160 @property(nonatomic, retain) NewTabPageView* ntpView;
161
162 // To ease modernizing the NTP only the internal panels are being converted
163 // to UIViewControllers. This means all the plumbing between the
164 // BrowserViewController and the internal NTP panels (WebController, NTP)
165 // hierarchy is skipped. While normally the logic to push and pop a view
166 // controller would be owned by a coordinator, in this case the old NTP
167 // controller adds and removes child view controllers itself when a load
168 // is initiated, and when WebController calls -willBeDismissed.
169 @property(nonatomic, assign) UIViewController* parentViewController;
170
161 @end 171 @end
162 172
163 @implementation NewTabPageController 173 @implementation NewTabPageController
164 174
165 @synthesize ntpView = newTabPageView_; 175 @synthesize ntpView = newTabPageView_;
166 @synthesize swipeRecognizerProvider = swipeRecognizerProvider_; 176 @synthesize swipeRecognizerProvider = swipeRecognizerProvider_;
167 @synthesize parentViewController = parentViewController_; 177 @synthesize parentViewController = parentViewController_;
168 178
169 - (id)initWithUrl:(const GURL&)url 179 - (id)initWithUrl:(const GURL&)url
170 loader:(id<UrlLoader>)loader 180 loader:(id<UrlLoader>)loader
171 focuser:(id<OmniboxFocuser>)focuser 181 focuser:(id<OmniboxFocuser>)focuser
172 ntpObserver:(id<NewTabPageControllerObserver>)ntpObserver 182 ntpObserver:(id<NewTabPageControllerObserver>)ntpObserver
173 browserState:(ios::ChromeBrowserState*)browserState 183 browserState:(ios::ChromeBrowserState*)browserState
174 colorCache:(NSMutableDictionary*)colorCache 184 colorCache:(NSMutableDictionary*)colorCache
175 webToolbarDelegate:(id<WebToolbarDelegate>)webToolbarDelegate 185 webToolbarDelegate:(id<WebToolbarDelegate>)webToolbarDelegate
176 tabModel:(TabModel*)tabModel { 186 tabModel:(TabModel*)tabModel
187 parentViewController:(UIViewController*)parentViewController {
177 self = [super initWithNibName:nil url:url]; 188 self = [super initWithNibName:nil url:url];
178 if (self) { 189 if (self) {
179 DCHECK(browserState); 190 DCHECK(browserState);
180 propertyReleaser_NewTabPageController_.Init(self, 191 propertyReleaser_NewTabPageController_.Init(self,
181 [NewTabPageController class]); 192 [NewTabPageController class]);
182 browserState_ = browserState; 193 browserState_ = browserState;
183 loader_ = loader; 194 loader_ = loader;
184 newTabPageObserver_ = ntpObserver; 195 newTabPageObserver_ = ntpObserver;
196 parentViewController_ = parentViewController;
185 focuser_.reset(focuser); 197 focuser_.reset(focuser);
186 webToolbarDelegate_.reset(webToolbarDelegate); 198 webToolbarDelegate_.reset(webToolbarDelegate);
187 tabModel_.reset([tabModel retain]); 199 tabModel_.reset([tabModel retain]);
188 dominantColorCache_ = colorCache; 200 dominantColorCache_ = colorCache;
189 self.title = l10n_util::GetNSString(IDS_NEW_TAB_TITLE); 201 self.title = l10n_util::GetNSString(IDS_NEW_TAB_TITLE);
190 scrollInitialized_ = NO; 202 scrollInitialized_ = NO;
191 203
192 base::scoped_nsobject<UIScrollView> scrollView( 204 base::scoped_nsobject<UIScrollView> scrollView(
193 [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 412)]); 205 [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 412)]);
194 [scrollView setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | 206 [scrollView setAutoresizingMask:(UIViewAutoresizingFlexibleWidth |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 504
493 - (void)loadControllerWithIndex:(NSUInteger)index { 505 - (void)loadControllerWithIndex:(NSUInteger)index {
494 if (index >= self.ntpView.tabBar.items.count) 506 if (index >= self.ntpView.tabBar.items.count)
495 return; 507 return;
496 508
497 NewTabPageBarItem* item = [self.ntpView.tabBar.items objectAtIndex:index]; 509 NewTabPageBarItem* item = [self.ntpView.tabBar.items objectAtIndex:index];
498 [self loadPanel:item]; 510 [self loadPanel:item];
499 } 511 }
500 512
501 - (BOOL)loadPanel:(NewTabPageBarItem*)item { 513 - (BOOL)loadPanel:(NewTabPageBarItem*)item {
514 DCHECK(self.parentViewController);
502 UIView* view = nil; 515 UIView* view = nil;
503 UIViewController* panelController = nil; 516 UIViewController* panelController = nil;
504 BOOL created = NO; 517 BOOL created = NO;
505 // Only load the controllers once. 518 // Only load the controllers once.
506 if (item.identifier == NewTabPage::kBookmarksPanel) { 519 if (item.identifier == NewTabPage::kBookmarksPanel) {
507 if (!bookmarkController_) { 520 if (!bookmarkController_) {
508 base::scoped_nsobject<BookmarkControllerFactory> factory( 521 base::scoped_nsobject<BookmarkControllerFactory> factory(
509 [[BookmarkControllerFactory alloc] init]); 522 [[BookmarkControllerFactory alloc] init]);
510 bookmarkController_.reset([[factory 523 bookmarkController_.reset([[factory
511 bookmarkPanelControllerForBrowserState:browserState_ 524 bookmarkPanelControllerForBrowserState:browserState_
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 722
710 - (void)updateNtpBarShadowForPanelController: 723 - (void)updateNtpBarShadowForPanelController:
711 (id<NewTabPagePanelProtocol>)ntpPanelController { 724 (id<NewTabPagePanelProtocol>)ntpPanelController {
712 if (currentController_ != ntpPanelController) 725 if (currentController_ != ntpPanelController)
713 return; 726 return;
714 [self.ntpView.tabBar 727 [self.ntpView.tabBar
715 setShadowAlpha:[ntpPanelController alphaForBottomShadow]]; 728 setShadowAlpha:[ntpPanelController alphaForBottomShadow]];
716 } 729 }
717 730
718 @end 731 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/ntp/new_tab_page_controller.h ('k') | ios/chrome/browser/ui/ntp/new_tab_page_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698