Chromium Code Reviews| 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 Loading... | |
| 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 // TODO(crbug.com/708319): Also call -removeFromParentViewController for | |
| 284 // bookmarks, open tabs and incognit here. | |
| 285 [googleLandingController_ removeFromParentViewController]; | |
| 286 | |
| 281 [googleLandingController_ setDelegate:nil]; | 287 [googleLandingController_ setDelegate:nil]; |
| 282 [bookmarkController_ setDelegate:nil]; | 288 [bookmarkController_ setDelegate:nil]; |
| 283 [openTabsController_ setDelegate:nil]; | 289 [openTabsController_ setDelegate:nil]; |
| 284 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 290 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 285 [super dealloc]; | 291 [super dealloc]; |
| 286 } | 292 } |
| 287 | 293 |
| 288 #pragma mark - CRWNativeContent | 294 #pragma mark - CRWNativeContent |
| 289 | 295 |
| 290 // Note: No point implementing -handleLowMemory because all native content | 296 - (void)willBeDismissed { |
|
rohitrao (ping after 24h)
2017/04/13 12:48:52
Explain that this is called by //web immediately b
justincohen
2017/04/13 13:58:02
Done.
| |
| 291 // views but the selected one are dropped, and the selected view doesn't | 297 // TODO(crbug.com/708319): Also call -willMoveToParentViewController:nil for |
| 292 // need to do anything. | 298 // bookmarks, open tabs and incognito here. |
| 299 [googleLandingController_ willMoveToParentViewController:nil]; | |
| 300 } | |
| 293 | 301 |
| 294 - (void)reload { | 302 - (void)reload { |
| 295 [currentController_ reload]; | 303 [currentController_ reload]; |
| 296 [super reload]; | 304 [super reload]; |
| 297 } | 305 } |
| 298 | 306 |
| 299 - (void)wasShown { | 307 - (void)wasShown { |
| 300 [currentController_ wasShown]; | 308 [currentController_ wasShown]; |
| 301 // Ensure that the NTP has the latest data when it is shown. | 309 // Ensure that the NTP has the latest data when it is shown. |
| 302 [self reload]; | 310 [self reload]; |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 478 | 486 |
| 479 - (void)loadControllerWithIndex:(NSUInteger)index { | 487 - (void)loadControllerWithIndex:(NSUInteger)index { |
| 480 if (index >= self.ntpView.tabBar.items.count) | 488 if (index >= self.ntpView.tabBar.items.count) |
| 481 return; | 489 return; |
| 482 | 490 |
| 483 NewTabPageBarItem* item = [self.ntpView.tabBar.items objectAtIndex:index]; | 491 NewTabPageBarItem* item = [self.ntpView.tabBar.items objectAtIndex:index]; |
| 484 [self loadPanel:item]; | 492 [self loadPanel:item]; |
| 485 } | 493 } |
| 486 | 494 |
| 487 - (BOOL)loadPanel:(NewTabPageBarItem*)item { | 495 - (BOOL)loadPanel:(NewTabPageBarItem*)item { |
| 488 UIView* view; | 496 UIView* view = nil; |
| 497 UIViewController* panelController = nil; | |
| 489 BOOL created = NO; | 498 BOOL created = NO; |
| 490 // Only load the controllers once. | 499 // Only load the controllers once. |
| 491 if (item.identifier == NewTabPage::kBookmarksPanel) { | 500 if (item.identifier == NewTabPage::kBookmarksPanel) { |
| 492 if (!bookmarkController_) { | 501 if (!bookmarkController_) { |
| 493 base::scoped_nsobject<BookmarkControllerFactory> factory( | 502 base::scoped_nsobject<BookmarkControllerFactory> factory( |
| 494 [[BookmarkControllerFactory alloc] init]); | 503 [[BookmarkControllerFactory alloc] init]); |
| 495 bookmarkController_.reset([[factory | 504 bookmarkController_.reset([[factory |
| 496 bookmarkPanelControllerForBrowserState:browserState_ | 505 bookmarkPanelControllerForBrowserState:browserState_ |
| 497 loader:loader_ | 506 loader:loader_ |
| 498 colorCache:dominantColorCache_] retain]); | 507 colorCache:dominantColorCache_] retain]); |
| 499 } | 508 } |
| 500 view = [bookmarkController_ view]; | 509 view = [bookmarkController_ view]; |
| 510 // TODO(crbug.com/708319): Also set panelController for bookmarks here. | |
| 501 [bookmarkController_ setDelegate:self]; | 511 [bookmarkController_ setDelegate:self]; |
| 502 } else if (item.identifier == NewTabPage::kMostVisitedPanel) { | 512 } else if (item.identifier == NewTabPage::kMostVisitedPanel) { |
| 503 if (!googleLandingController_) { | 513 if (!googleLandingController_) { |
| 504 googleLandingController_.reset([[GoogleLandingController alloc] | 514 googleLandingController_.reset([[GoogleLandingController alloc] |
| 505 initWithLoader:loader_ | 515 initWithLoader:loader_ |
| 506 browserState:browserState_ | 516 browserState:browserState_ |
| 507 focuser:focuser_ | 517 focuser:focuser_ |
| 508 webToolbarDelegate:webToolbarDelegate_ | 518 webToolbarDelegate:webToolbarDelegate_ |
| 509 tabModel:tabModel_]); | 519 tabModel:tabModel_]); |
| 510 } | 520 } |
| 521 panelController = googleLandingController_; | |
| 511 view = [googleLandingController_ view]; | 522 view = [googleLandingController_ view]; |
| 512 [googleLandingController_ setDelegate:self]; | 523 [googleLandingController_ setDelegate:self]; |
| 513 } else if (item.identifier == NewTabPage::kOpenTabsPanel) { | 524 } else if (item.identifier == NewTabPage::kOpenTabsPanel) { |
| 514 if (!openTabsController_) | 525 if (!openTabsController_) |
| 515 openTabsController_.reset([[RecentTabsPanelController alloc] | 526 openTabsController_.reset([[RecentTabsPanelController alloc] |
| 516 initWithLoader:loader_ | 527 initWithLoader:loader_ |
| 517 browserState:browserState_]); | 528 browserState:browserState_]); |
| 529 // TODO(crbug.com/708319): Also set panelController for opentabs here. | |
| 518 view = [openTabsController_ view]; | 530 view = [openTabsController_ view]; |
| 519 [openTabsController_ setDelegate:self]; | 531 [openTabsController_ setDelegate:self]; |
| 520 } else if (item.identifier == NewTabPage::kIncognitoPanel) { | 532 } else if (item.identifier == NewTabPage::kIncognitoPanel) { |
| 521 if (!incognitoController_) | 533 if (!incognitoController_) |
| 522 incognitoController_.reset([[IncognitoPanelController alloc] | 534 incognitoController_.reset([[IncognitoPanelController alloc] |
| 523 initWithLoader:loader_ | 535 initWithLoader:loader_ |
| 524 browserState:browserState_ | 536 browserState:browserState_ |
| 525 webToolbarDelegate:webToolbarDelegate_]); | 537 webToolbarDelegate:webToolbarDelegate_]); |
| 538 // TODO(crbug.com/708319): Also set panelController for incognito here. | |
| 526 view = [incognitoController_ view]; | 539 view = [incognitoController_ view]; |
| 527 } else { | 540 } else { |
| 528 NOTREACHED(); | 541 NOTREACHED(); |
| 529 return NO; | 542 return NO; |
| 530 } | 543 } |
| 531 | 544 |
| 532 // Add the panel views to the scroll view in the proper location. | 545 // Add the panel views to the scroll view in the proper location. |
| 533 NSUInteger index = [self tabBarItemIndex:item]; | 546 NSUInteger index = [self tabBarItemIndex:item]; |
| 534 if (view.superview == nil) { | 547 if (view.superview == nil) { |
| 535 created = YES; | 548 created = YES; |
| 536 view.frame = [self.ntpView panelFrameForItemAtIndex:index]; | 549 view.frame = [self.ntpView panelFrameForItemAtIndex:index]; |
| 537 item.view = view; | 550 item.view = view; |
| 551 | |
| 552 // To ease modernizing the NTP only the internal panels are being converted | |
| 553 // to UIViewControllers. This means all the plumbing between the | |
| 554 // BrowserViewController and the internal NTP panels (WebController, NTP) | |
| 555 // hierarchy is skipped. While normally the logic to push and pop a view | |
| 556 // controller would be owned by a coordinator, in this case the old NTP | |
| 557 // controller adds and removes child view controllers itself when a load | |
| 558 // is initiated, and when WebController calls -willBeDismissed. | |
| 559 // TODO(crbug.com/708319):This 'if' can become a DCHECK once all panels move | |
| 560 // to panelControllers. | |
| 561 if (panelController) | |
| 562 [self.parentViewController addChildViewController:panelController]; | |
| 538 [self.ntpView.scrollView addSubview:view]; | 563 [self.ntpView.scrollView addSubview:view]; |
| 564 if (panelController) | |
| 565 [panelController didMoveToParentViewController:self.parentViewController]; | |
| 539 } | 566 } |
| 540 return created; | 567 return created; |
| 541 } | 568 } |
| 542 | 569 |
| 543 - (void)scrollToPanel:(NewTabPageBarItem*)item animate:(BOOL)animate { | 570 - (void)scrollToPanel:(NewTabPageBarItem*)item animate:(BOOL)animate { |
| 544 NSUInteger index = [self tabBarItemIndex:item]; | 571 NSUInteger index = [self tabBarItemIndex:item]; |
| 545 if (IsIPadIdiom()) { | 572 if (IsIPadIdiom()) { |
| 546 CGRect itemFrame = [self.ntpView panelFrameForItemAtIndex:index]; | 573 CGRect itemFrame = [self.ntpView panelFrameForItemAtIndex:index]; |
| 547 CGPoint point = CGPointMake(CGRectGetMinX(itemFrame), 0); | 574 CGPoint point = CGPointMake(CGRectGetMinX(itemFrame), 0); |
| 548 [self.ntpView.scrollView setContentOffset:point animated:animate]; | 575 [self.ntpView.scrollView setContentOffset:point animated:animate]; |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 676 | 703 |
| 677 - (void)updateNtpBarShadowForPanelController: | 704 - (void)updateNtpBarShadowForPanelController: |
| 678 (id<NewTabPagePanelProtocol>)ntpPanelController { | 705 (id<NewTabPagePanelProtocol>)ntpPanelController { |
| 679 if (currentController_ != ntpPanelController) | 706 if (currentController_ != ntpPanelController) |
| 680 return; | 707 return; |
| 681 [self.ntpView.tabBar | 708 [self.ntpView.tabBar |
| 682 setShadowAlpha:[ntpPanelController alphaForBottomShadow]]; | 709 setShadowAlpha:[ntpPanelController alphaForBottomShadow]]; |
| 683 } | 710 } |
| 684 | 711 |
| 685 @end | 712 @end |
| OLD | NEW |