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

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

Issue 2806153004: Convert main NTP panel to UIViewController. (Closed)
Patch Set: Update comments 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 @end 161 @end
162 162
163 @implementation NewTabPageController 163 @implementation NewTabPageController
164 164
165 @synthesize ntpView = newTabPageView_; 165 @synthesize ntpView = newTabPageView_;
166 @synthesize swipeRecognizerProvider = swipeRecognizerProvider_; 166 @synthesize swipeRecognizerProvider = swipeRecognizerProvider_;
167 @synthesize parentViewController = parentViewController_;
167 168
168 - (id)initWithUrl:(const GURL&)url 169 - (id)initWithUrl:(const GURL&)url
169 loader:(id<UrlLoader>)loader 170 loader:(id<UrlLoader>)loader
170 focuser:(id<OmniboxFocuser>)focuser 171 focuser:(id<OmniboxFocuser>)focuser
171 ntpObserver:(id<NewTabPageControllerObserver>)ntpObserver 172 ntpObserver:(id<NewTabPageControllerObserver>)ntpObserver
172 browserState:(ios::ChromeBrowserState*)browserState 173 browserState:(ios::ChromeBrowserState*)browserState
173 colorCache:(NSMutableDictionary*)colorCache 174 colorCache:(NSMutableDictionary*)colorCache
174 webToolbarDelegate:(id<WebToolbarDelegate>)webToolbarDelegate 175 webToolbarDelegate:(id<WebToolbarDelegate>)webToolbarDelegate
175 tabModel:(TabModel*)tabModel { 176 tabModel:(TabModel*)tabModel {
176 self = [super initWithNibName:nil url:url]; 177 self = [super initWithNibName:nil url:url];
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 [self showPanel:itemToDisplay]; 272 [self showPanel:itemToDisplay];
272 [self updateOverlayScrollPosition]; 273 [self updateOverlayScrollPosition];
273 } 274 }
274 return self; 275 return self;
275 } 276 }
276 277
277 - (void)dealloc { 278 - (void)dealloc {
278 // Animations can last past the life of the NTP controller, nil out the 279 // Animations can last past the life of the NTP controller, nil out the
279 // delegate. 280 // delegate.
280 self.ntpView.scrollView.delegate = nil; 281 self.ntpView.scrollView.delegate = nil;
282
283 // This is not an ideal place to put view controller contaimnent, rather a
284 // //web -wasDismissed method on CRWNativeContent would be more accurate. If
285 // CRWNativeContent leaks, this will not be called.
286 // TODO(crbug.com/708319): Also call -removeFromParentViewController for
287 // bookmarks, open tabs and incognit here.
288 [googleLandingController_ removeFromParentViewController];
289
281 [googleLandingController_ setDelegate:nil]; 290 [googleLandingController_ setDelegate:nil];
282 [bookmarkController_ setDelegate:nil]; 291 [bookmarkController_ setDelegate:nil];
283 [openTabsController_ setDelegate:nil]; 292 [openTabsController_ setDelegate:nil];
284 [[NSNotificationCenter defaultCenter] removeObserver:self]; 293 [[NSNotificationCenter defaultCenter] removeObserver:self];
285 [super dealloc]; 294 [super dealloc];
286 } 295 }
287 296
288 #pragma mark - CRWNativeContent 297 #pragma mark - CRWNativeContent
289 298
290 // Note: No point implementing -handleLowMemory because all native content 299 - (void)willBeDismissed {
291 // views but the selected one are dropped, and the selected view doesn't 300 // This methods is called by //web immediately before |self|'s view is removed
292 // need to do anything. 301 // from the view hierarchy, making it an ideal spot to intiate view controller
302 // containment methods.
303 // TODO(crbug.com/708319): Also call -willMoveToParentViewController:nil for
304 // bookmarks, open tabs and incognito here.
305 [googleLandingController_ willMoveToParentViewController:nil];
306 }
293 307
294 - (void)reload { 308 - (void)reload {
295 [currentController_ reload]; 309 [currentController_ reload];
296 [super reload]; 310 [super reload];
297 } 311 }
298 312
299 - (void)wasShown { 313 - (void)wasShown {
300 [currentController_ wasShown]; 314 [currentController_ wasShown];
301 // Ensure that the NTP has the latest data when it is shown. 315 // Ensure that the NTP has the latest data when it is shown.
302 [self reload]; 316 [self reload];
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 492
479 - (void)loadControllerWithIndex:(NSUInteger)index { 493 - (void)loadControllerWithIndex:(NSUInteger)index {
480 if (index >= self.ntpView.tabBar.items.count) 494 if (index >= self.ntpView.tabBar.items.count)
481 return; 495 return;
482 496
483 NewTabPageBarItem* item = [self.ntpView.tabBar.items objectAtIndex:index]; 497 NewTabPageBarItem* item = [self.ntpView.tabBar.items objectAtIndex:index];
484 [self loadPanel:item]; 498 [self loadPanel:item];
485 } 499 }
486 500
487 - (BOOL)loadPanel:(NewTabPageBarItem*)item { 501 - (BOOL)loadPanel:(NewTabPageBarItem*)item {
488 UIView* view; 502 UIView* view = nil;
503 UIViewController* panelController = nil;
489 BOOL created = NO; 504 BOOL created = NO;
490 // Only load the controllers once. 505 // Only load the controllers once.
491 if (item.identifier == NewTabPage::kBookmarksPanel) { 506 if (item.identifier == NewTabPage::kBookmarksPanel) {
492 if (!bookmarkController_) { 507 if (!bookmarkController_) {
493 base::scoped_nsobject<BookmarkControllerFactory> factory( 508 base::scoped_nsobject<BookmarkControllerFactory> factory(
494 [[BookmarkControllerFactory alloc] init]); 509 [[BookmarkControllerFactory alloc] init]);
495 bookmarkController_.reset([[factory 510 bookmarkController_.reset([[factory
496 bookmarkPanelControllerForBrowserState:browserState_ 511 bookmarkPanelControllerForBrowserState:browserState_
497 loader:loader_ 512 loader:loader_
498 colorCache:dominantColorCache_] retain]); 513 colorCache:dominantColorCache_] retain]);
499 } 514 }
500 view = [bookmarkController_ view]; 515 view = [bookmarkController_ view];
516 // TODO(crbug.com/708319): Also set panelController for bookmarks here.
501 [bookmarkController_ setDelegate:self]; 517 [bookmarkController_ setDelegate:self];
502 } else if (item.identifier == NewTabPage::kMostVisitedPanel) { 518 } else if (item.identifier == NewTabPage::kMostVisitedPanel) {
503 if (!googleLandingController_) { 519 if (!googleLandingController_) {
504 googleLandingController_.reset([[GoogleLandingController alloc] 520 googleLandingController_.reset([[GoogleLandingController alloc]
505 initWithLoader:loader_ 521 initWithLoader:loader_
506 browserState:browserState_ 522 browserState:browserState_
507 focuser:focuser_ 523 focuser:focuser_
508 webToolbarDelegate:webToolbarDelegate_ 524 webToolbarDelegate:webToolbarDelegate_
509 tabModel:tabModel_]); 525 tabModel:tabModel_]);
510 } 526 }
527 panelController = googleLandingController_;
511 view = [googleLandingController_ view]; 528 view = [googleLandingController_ view];
512 [googleLandingController_ setDelegate:self]; 529 [googleLandingController_ setDelegate:self];
513 } else if (item.identifier == NewTabPage::kOpenTabsPanel) { 530 } else if (item.identifier == NewTabPage::kOpenTabsPanel) {
514 if (!openTabsController_) 531 if (!openTabsController_)
515 openTabsController_.reset([[RecentTabsPanelController alloc] 532 openTabsController_.reset([[RecentTabsPanelController alloc]
516 initWithLoader:loader_ 533 initWithLoader:loader_
517 browserState:browserState_]); 534 browserState:browserState_]);
535 // TODO(crbug.com/708319): Also set panelController for opentabs here.
518 view = [openTabsController_ view]; 536 view = [openTabsController_ view];
519 [openTabsController_ setDelegate:self]; 537 [openTabsController_ setDelegate:self];
520 } else if (item.identifier == NewTabPage::kIncognitoPanel) { 538 } else if (item.identifier == NewTabPage::kIncognitoPanel) {
521 if (!incognitoController_) 539 if (!incognitoController_)
522 incognitoController_.reset([[IncognitoPanelController alloc] 540 incognitoController_.reset([[IncognitoPanelController alloc]
523 initWithLoader:loader_ 541 initWithLoader:loader_
524 browserState:browserState_ 542 browserState:browserState_
525 webToolbarDelegate:webToolbarDelegate_]); 543 webToolbarDelegate:webToolbarDelegate_]);
544 // TODO(crbug.com/708319): Also set panelController for incognito here.
526 view = [incognitoController_ view]; 545 view = [incognitoController_ view];
527 } else { 546 } else {
528 NOTREACHED(); 547 NOTREACHED();
529 return NO; 548 return NO;
530 } 549 }
531 550
532 // Add the panel views to the scroll view in the proper location. 551 // Add the panel views to the scroll view in the proper location.
533 NSUInteger index = [self tabBarItemIndex:item]; 552 NSUInteger index = [self tabBarItemIndex:item];
534 if (view.superview == nil) { 553 if (view.superview == nil) {
535 created = YES; 554 created = YES;
536 view.frame = [self.ntpView panelFrameForItemAtIndex:index]; 555 view.frame = [self.ntpView panelFrameForItemAtIndex:index];
537 item.view = view; 556 item.view = view;
557
558 // To ease modernizing the NTP only the internal panels are being converted
559 // to UIViewControllers. This means all the plumbing between the
560 // BrowserViewController and the internal NTP panels (WebController, NTP)
561 // hierarchy is skipped. While normally the logic to push and pop a view
562 // controller would be owned by a coordinator, in this case the old NTP
563 // controller adds and removes child view controllers itself when a load
564 // is initiated, and when WebController calls -willBeDismissed.
565 // TODO(crbug.com/708319):This 'if' can become a DCHECK once all panels move
566 // to panelControllers.
567 if (panelController)
568 [self.parentViewController addChildViewController:panelController];
538 [self.ntpView.scrollView addSubview:view]; 569 [self.ntpView.scrollView addSubview:view];
570 if (panelController)
571 [panelController didMoveToParentViewController:self.parentViewController];
539 } 572 }
540 return created; 573 return created;
541 } 574 }
542 575
543 - (void)scrollToPanel:(NewTabPageBarItem*)item animate:(BOOL)animate { 576 - (void)scrollToPanel:(NewTabPageBarItem*)item animate:(BOOL)animate {
544 NSUInteger index = [self tabBarItemIndex:item]; 577 NSUInteger index = [self tabBarItemIndex:item];
545 if (IsIPadIdiom()) { 578 if (IsIPadIdiom()) {
546 CGRect itemFrame = [self.ntpView panelFrameForItemAtIndex:index]; 579 CGRect itemFrame = [self.ntpView panelFrameForItemAtIndex:index];
547 CGPoint point = CGPointMake(CGRectGetMinX(itemFrame), 0); 580 CGPoint point = CGPointMake(CGRectGetMinX(itemFrame), 0);
548 [self.ntpView.scrollView setContentOffset:point animated:animate]; 581 [self.ntpView.scrollView setContentOffset:point animated:animate];
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 709
677 - (void)updateNtpBarShadowForPanelController: 710 - (void)updateNtpBarShadowForPanelController:
678 (id<NewTabPagePanelProtocol>)ntpPanelController { 711 (id<NewTabPagePanelProtocol>)ntpPanelController {
679 if (currentController_ != ntpPanelController) 712 if (currentController_ != ntpPanelController)
680 return; 713 return;
681 [self.ntpView.tabBar 714 [self.ntpView.tabBar
682 setShadowAlpha:[ntpPanelController alphaForBottomShadow]]; 715 setShadowAlpha:[ntpPanelController alphaForBottomShadow]];
683 } 716 }
684 717
685 @end 718 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/ntp/new_tab_page_controller.h ('k') | ios/clean/chrome/browser/ui/ntp/ntp_home_coordinator.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698