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]; | |
|
rohitrao (ping after 24h)
2017/04/12 12:45:09
Why is this not covered by the willBeDismissed cod
justincohen
2017/04/12 14:23:12
-willMoveToParentViewController is called before t
| |
| 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 { |
| 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; |
|
rohitrao (ping after 24h)
2017/04/12 12:45:09
Consider changing this to:
UIView* panelView = ni
justincohen
2017/04/12 14:23:12
I was planning on doing this when adding the other
| |
| 489 BOOL created = NO; | 497 BOOL created = NO; |
| 490 // Only load the controllers once. | 498 // Only load the controllers once. |
| 491 if (item.identifier == NewTabPage::kBookmarksPanel) { | 499 if (item.identifier == NewTabPage::kBookmarksPanel) { |
| 492 if (!bookmarkController_) { | 500 if (!bookmarkController_) { |
| 493 base::scoped_nsobject<BookmarkControllerFactory> factory( | 501 base::scoped_nsobject<BookmarkControllerFactory> factory( |
| 494 [[BookmarkControllerFactory alloc] init]); | 502 [[BookmarkControllerFactory alloc] init]); |
| 495 bookmarkController_.reset([[factory | 503 bookmarkController_.reset([[factory |
| 496 bookmarkPanelControllerForBrowserState:browserState_ | 504 bookmarkPanelControllerForBrowserState:browserState_ |
| 497 loader:loader_ | 505 loader:loader_ |
| 498 colorCache:dominantColorCache_] retain]); | 506 colorCache:dominantColorCache_] retain]); |
| 499 } | 507 } |
| 500 view = [bookmarkController_ view]; | 508 view = [bookmarkController_ view]; |
| 509 // TODO(crbug.com/708319): Also addChildViewController for bookmarks here. | |
| 501 [bookmarkController_ setDelegate:self]; | 510 [bookmarkController_ setDelegate:self]; |
| 502 } else if (item.identifier == NewTabPage::kMostVisitedPanel) { | 511 } else if (item.identifier == NewTabPage::kMostVisitedPanel) { |
| 503 if (!googleLandingController_) { | 512 if (!googleLandingController_) { |
| 504 googleLandingController_.reset([[GoogleLandingController alloc] | 513 googleLandingController_.reset([[GoogleLandingController alloc] |
| 505 initWithLoader:loader_ | 514 initWithLoader:loader_ |
| 506 browserState:browserState_ | 515 browserState:browserState_ |
| 507 focuser:focuser_ | 516 focuser:focuser_ |
| 508 webToolbarDelegate:webToolbarDelegate_ | 517 webToolbarDelegate:webToolbarDelegate_ |
| 509 tabModel:tabModel_]); | 518 tabModel:tabModel_]); |
| 510 } | 519 } |
| 520 [self.parentViewController addChildViewController:googleLandingController_]; | |
| 511 view = [googleLandingController_ view]; | 521 view = [googleLandingController_ view]; |
| 512 [googleLandingController_ setDelegate:self]; | 522 [googleLandingController_ setDelegate:self]; |
| 513 } else if (item.identifier == NewTabPage::kOpenTabsPanel) { | 523 } else if (item.identifier == NewTabPage::kOpenTabsPanel) { |
| 514 if (!openTabsController_) | 524 if (!openTabsController_) |
| 515 openTabsController_.reset([[RecentTabsPanelController alloc] | 525 openTabsController_.reset([[RecentTabsPanelController alloc] |
| 516 initWithLoader:loader_ | 526 initWithLoader:loader_ |
| 517 browserState:browserState_]); | 527 browserState:browserState_]); |
| 528 // TODO(crbug.com/708319): Also addChildViewController for opentabs here. | |
| 518 view = [openTabsController_ view]; | 529 view = [openTabsController_ view]; |
| 519 [openTabsController_ setDelegate:self]; | 530 [openTabsController_ setDelegate:self]; |
| 520 } else if (item.identifier == NewTabPage::kIncognitoPanel) { | 531 } else if (item.identifier == NewTabPage::kIncognitoPanel) { |
| 521 if (!incognitoController_) | 532 if (!incognitoController_) |
| 522 incognitoController_.reset([[IncognitoPanelController alloc] | 533 incognitoController_.reset([[IncognitoPanelController alloc] |
| 523 initWithLoader:loader_ | 534 initWithLoader:loader_ |
| 524 browserState:browserState_ | 535 browserState:browserState_ |
| 525 webToolbarDelegate:webToolbarDelegate_]); | 536 webToolbarDelegate:webToolbarDelegate_]); |
| 537 // TODO(crbug.com/708319): Also addChildViewController for incognito here. | |
| 526 view = [incognitoController_ view]; | 538 view = [incognitoController_ view]; |
| 527 } else { | 539 } else { |
| 528 NOTREACHED(); | 540 NOTREACHED(); |
| 529 return NO; | 541 return NO; |
| 530 } | 542 } |
| 531 | 543 |
| 532 // Add the panel views to the scroll view in the proper location. | 544 // Add the panel views to the scroll view in the proper location. |
| 533 NSUInteger index = [self tabBarItemIndex:item]; | 545 NSUInteger index = [self tabBarItemIndex:item]; |
| 534 if (view.superview == nil) { | 546 if (view.superview == nil) { |
| 535 created = YES; | 547 created = YES; |
| 536 view.frame = [self.ntpView panelFrameForItemAtIndex:index]; | 548 view.frame = [self.ntpView panelFrameForItemAtIndex:index]; |
| 537 item.view = view; | 549 item.view = view; |
| 538 [self.ntpView.scrollView addSubview:view]; | 550 [self.ntpView.scrollView addSubview:view]; |
| 551 | |
| 552 // Also didMoveToParentViewController for bookmarks, open tabs and incognito | |
| 553 // here. | |
| 554 if (item.identifier == NewTabPage::kMostVisitedPanel) { | |
| 555 [googleLandingController_ | |
| 556 didMoveToParentViewController:self.parentViewController]; | |
| 557 } | |
| 539 } | 558 } |
| 540 return created; | 559 return created; |
| 541 } | 560 } |
| 542 | 561 |
| 543 - (void)scrollToPanel:(NewTabPageBarItem*)item animate:(BOOL)animate { | 562 - (void)scrollToPanel:(NewTabPageBarItem*)item animate:(BOOL)animate { |
| 544 NSUInteger index = [self tabBarItemIndex:item]; | 563 NSUInteger index = [self tabBarItemIndex:item]; |
| 545 if (IsIPadIdiom()) { | 564 if (IsIPadIdiom()) { |
| 546 CGRect itemFrame = [self.ntpView panelFrameForItemAtIndex:index]; | 565 CGRect itemFrame = [self.ntpView panelFrameForItemAtIndex:index]; |
| 547 CGPoint point = CGPointMake(CGRectGetMinX(itemFrame), 0); | 566 CGPoint point = CGPointMake(CGRectGetMinX(itemFrame), 0); |
| 548 [self.ntpView.scrollView setContentOffset:point animated:animate]; | 567 [self.ntpView.scrollView setContentOffset:point animated:animate]; |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 676 | 695 |
| 677 - (void)updateNtpBarShadowForPanelController: | 696 - (void)updateNtpBarShadowForPanelController: |
| 678 (id<NewTabPagePanelProtocol>)ntpPanelController { | 697 (id<NewTabPagePanelProtocol>)ntpPanelController { |
| 679 if (currentController_ != ntpPanelController) | 698 if (currentController_ != ntpPanelController) |
| 680 return; | 699 return; |
| 681 [self.ntpView.tabBar | 700 [self.ntpView.tabBar |
| 682 setShadowAlpha:[ntpPanelController alphaForBottomShadow]]; | 701 setShadowAlpha:[ntpPanelController alphaForBottomShadow]]; |
| 683 } | 702 } |
| 684 | 703 |
| 685 @end | 704 @end |
| OLD | NEW |