| 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" | |
| 10 #include "base/logging.h" | 9 #include "base/logging.h" |
| 11 #include "base/mac/objc_property_releaser.h" | 10 |
| 12 #include "base/metrics/user_metrics.h" | 11 #include "base/metrics/user_metrics.h" |
| 13 #include "base/metrics/user_metrics_action.h" | 12 #include "base/metrics/user_metrics_action.h" |
| 14 #include "components/prefs/pref_service.h" | 13 #include "components/prefs/pref_service.h" |
| 15 #include "components/search_engines/template_url_service.h" | 14 #include "components/search_engines/template_url_service.h" |
| 16 #include "components/strings/grit/components_strings.h" | 15 #include "components/strings/grit/components_strings.h" |
| 17 #include "components/sync_sessions/synced_session.h" | 16 #include "components/sync_sessions/synced_session.h" |
| 18 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 17 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 19 #include "ios/chrome/browser/pref_names.h" | 18 #include "ios/chrome/browser/pref_names.h" |
| 20 #include "ios/chrome/browser/search_engines/template_url_service_factory.h" | 19 #include "ios/chrome/browser/search_engines/template_url_service_factory.h" |
| 21 #include "ios/chrome/browser/sync/sync_setup_service.h" | 20 #include "ios/chrome/browser/sync/sync_setup_service.h" |
| 22 #include "ios/chrome/browser/sync/sync_setup_service_factory.h" | 21 #include "ios/chrome/browser/sync/sync_setup_service_factory.h" |
| 23 #import "ios/chrome/browser/tabs/tab_model.h" | 22 #import "ios/chrome/browser/tabs/tab_model.h" |
| 24 #import "ios/chrome/browser/ui/bookmarks/bookmark_controller_factory.h" | 23 #import "ios/chrome/browser/ui/bookmarks/bookmark_controller_factory.h" |
| 25 #import "ios/chrome/browser/ui/bookmarks/bookmark_home_tablet_ntp_controller.h" | 24 #import "ios/chrome/browser/ui/bookmarks/bookmark_home_tablet_ntp_controller.h" |
| 26 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" | 25 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" |
| 27 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" | 26 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" |
| 28 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" | 27 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" |
| 29 #import "ios/chrome/browser/ui/ntp/google_landing_mediator.h" | 28 #import "ios/chrome/browser/ui/ntp/google_landing_mediator.h" |
| 30 #import "ios/chrome/browser/ui/ntp/google_landing_view_controller.h" | 29 #import "ios/chrome/browser/ui/ntp/google_landing_view_controller.h" |
| 31 #import "ios/chrome/browser/ui/ntp/incognito_panel_controller.h" | 30 #import "ios/chrome/browser/ui/ntp/incognito_panel_controller.h" |
| 32 #import "ios/chrome/browser/ui/ntp/new_tab_page_bar_item.h" | 31 #import "ios/chrome/browser/ui/ntp/new_tab_page_bar_item.h" |
| 32 #import "ios/chrome/browser/ui/ntp/new_tab_page_controller_testing.h" |
| 33 #import "ios/chrome/browser/ui/ntp/new_tab_page_view.h" | 33 #import "ios/chrome/browser/ui/ntp/new_tab_page_view.h" |
| 34 #import "ios/chrome/browser/ui/ntp/recent_tabs/recent_tabs_panel_controller.h" | 34 #import "ios/chrome/browser/ui/ntp/recent_tabs/recent_tabs_panel_controller.h" |
| 35 #import "ios/chrome/browser/ui/rtl_geometry.h" | 35 #import "ios/chrome/browser/ui/rtl_geometry.h" |
| 36 #include "ios/chrome/browser/ui/toolbar/toolbar_model_ios.h" | 36 #include "ios/chrome/browser/ui/toolbar/toolbar_model_ios.h" |
| 37 #include "ios/chrome/browser/ui/ui_util.h" | 37 #include "ios/chrome/browser/ui/ui_util.h" |
| 38 #include "ios/chrome/grit/ios_strings.h" | 38 #include "ios/chrome/grit/ios_strings.h" |
| 39 #import "ios/web/web_state/ui/crw_swipe_recognizer_provider.h" | 39 #import "ios/web/web_state/ui/crw_swipe_recognizer_provider.h" |
| 40 #include "ui/base/l10n/l10n_util.h" | 40 #include "ui/base/l10n/l10n_util.h" |
| 41 #include "ui/base/l10n/l10n_util_mac.h" | 41 #include "ui/base/l10n/l10n_util_mac.h" |
| 42 | 42 |
| 43 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 44 #error "This file requires ARC support." |
| 45 #endif |
| 46 |
| 43 using base::UserMetricsAction; | 47 using base::UserMetricsAction; |
| 44 | 48 |
| 45 namespace { | 49 namespace { |
| 46 const char* kMostVisitedFragment = "most_visited"; | 50 const char* kMostVisitedFragment = "most_visited"; |
| 47 const char* kBookmarksFragment = "bookmarks"; | 51 const char* kBookmarksFragment = "bookmarks"; |
| 48 const char* kOpenTabsFragment = "open_tabs"; | 52 const char* kOpenTabsFragment = "open_tabs"; |
| 49 const char* kIncognitoFragment = "incognito"; | 53 const char* kIncognitoFragment = "incognito"; |
| 50 const CGFloat kToolbarHeight = 56; | 54 const CGFloat kToolbarHeight = 56; |
| 51 } | 55 } |
| 52 | 56 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 enum { | 105 enum { |
| 102 INDEX_MASK = (1 << kPageIdOffset) - 1, | 106 INDEX_MASK = (1 << kPageIdOffset) - 1, |
| 103 MOST_VISITED_PAGE_ID = 1 << kPageIdOffset, | 107 MOST_VISITED_PAGE_ID = 1 << kPageIdOffset, |
| 104 BOOKMARKS_PAGE_ID = 3 << kPageIdOffset, | 108 BOOKMARKS_PAGE_ID = 3 << kPageIdOffset, |
| 105 OPEN_TABS_PAGE_ID = 4 << kPageIdOffset, | 109 OPEN_TABS_PAGE_ID = 4 << kPageIdOffset, |
| 106 }; | 110 }; |
| 107 | 111 |
| 108 } // anonymous namespace | 112 } // anonymous namespace |
| 109 | 113 |
| 110 @interface NewTabPageController () { | 114 @interface NewTabPageController () { |
| 115 BookmarkHomeTabletNTPController* bookmarkController_; |
| 116 GoogleLandingViewController* googleLandingController_; |
| 117 id<NewTabPagePanelProtocol> incognitoController_; |
| 118 // The currently visible controller, one of the above. |
| 119 __weak id<NewTabPagePanelProtocol> currentController_; |
| 120 |
| 111 ios::ChromeBrowserState* browserState_; // Weak. | 121 ios::ChromeBrowserState* browserState_; // Weak. |
| 112 id<UrlLoader> loader_; // Weak. | 122 __weak id<UrlLoader> loader_; |
| 113 id<CRWSwipeRecognizerProvider> swipeRecognizerProvider_; // Weak. | 123 __weak id<CRWSwipeRecognizerProvider> swipeRecognizerProvider_; |
| 114 id<NewTabPageControllerObserver> newTabPageObserver_; // Weak. | 124 __weak id<NewTabPageControllerObserver> newTabPageObserver_; |
| 115 | 125 |
| 116 NewTabPageView* newTabPageView_; | 126 NewTabPageView* newTabPageView_; |
| 117 | 127 |
| 118 base::scoped_nsobject<GoogleLandingMediator> googleLandingMediator_; | 128 GoogleLandingMediator* googleLandingMediator_; |
| 119 | 129 |
| 120 base::scoped_nsobject<RecentTabsPanelController> openTabsController_; | 130 RecentTabsPanelController* openTabsController_; |
| 121 // Has the scrollView been initialized. | 131 // Has the scrollView been initialized. |
| 122 BOOL scrollInitialized_; | 132 BOOL scrollInitialized_; |
| 123 | 133 |
| 124 // Dominant color cache. Key: (NSString*)url, val: (UIColor*)dominantColor. | 134 // Dominant color cache. Key: (NSString*)url, val: (UIColor*)dominantColor. |
| 125 NSMutableDictionary* dominantColorCache_; // Weak, owned by bvc. | 135 NSMutableDictionary* dominantColorCache_; // Weak, owned by bvc. |
| 126 | 136 |
| 127 // Delegate to focus and blur the omnibox. | 137 // Delegate to focus and blur the omnibox. |
| 128 base::WeakNSProtocol<id<OmniboxFocuser>> focuser_; | 138 __weak id<OmniboxFocuser> focuser_; |
| 129 | 139 |
| 130 // Delegate to fetch the ToolbarModel and current web state from. | 140 // Delegate to fetch the ToolbarModel and current web state from. |
| 131 base::WeakNSProtocol<id<WebToolbarDelegate>> webToolbarDelegate_; | 141 __weak id<WebToolbarDelegate> webToolbarDelegate_; |
| 132 | 142 |
| 133 base::scoped_nsobject<TabModel> tabModel_; | 143 TabModel* tabModel_; |
| 134 | |
| 135 base::mac::ObjCPropertyReleaser propertyReleaser_NewTabPageController_; | |
| 136 } | 144 } |
| 137 | 145 |
| 138 // Load and bring panel into view. | 146 // Load and bring panel into view. |
| 139 - (void)showPanel:(NewTabPageBarItem*)item; | 147 - (void)showPanel:(NewTabPageBarItem*)item; |
| 140 // Load panel on demand. | 148 // Load panel on demand. |
| 141 - (BOOL)loadPanel:(NewTabPageBarItem*)item; | 149 - (BOOL)loadPanel:(NewTabPageBarItem*)item; |
| 142 // After a panel changes, update metrics and prefs information. | 150 // After a panel changes, update metrics and prefs information. |
| 143 - (void)panelChanged:(NewTabPageBarItem*)item; | 151 - (void)panelChanged:(NewTabPageBarItem*)item; |
| 144 // Update current controller and tab bar index. Used to call reload. | 152 // Update current controller and tab bar index. Used to call reload. |
| 145 - (void)updateCurrentController:(NewTabPageBarItem*)item | 153 - (void)updateCurrentController:(NewTabPageBarItem*)item |
| 146 index:(NSUInteger)index; | 154 index:(NSUInteger)index; |
| 147 // Bring panel into scroll view. | 155 // Bring panel into scroll view. |
| 148 - (void)scrollToPanel:(NewTabPageBarItem*)item animate:(BOOL)animate; | 156 - (void)scrollToPanel:(NewTabPageBarItem*)item animate:(BOOL)animate; |
| 149 // Returns index of item in tab bar. | 157 // Returns index of item in tab bar. |
| 150 - (NSUInteger)tabBarItemIndex:(NewTabPageBarItem*)item; | 158 - (NSUInteger)tabBarItemIndex:(NewTabPageBarItem*)item; |
| 151 // Call loadPanel by item index. | 159 // Call loadPanel by item index. |
| 152 - (void)loadControllerWithIndex:(NSUInteger)index; | 160 - (void)loadControllerWithIndex:(NSUInteger)index; |
| 153 // Initialize scroll view. | 161 // Initialize scroll view. |
| 154 - (void)setUpScrollView; | 162 - (void)setUpScrollView; |
| 155 // Update overlay scroll view value. | 163 // Update overlay scroll view value. |
| 156 - (void)updateOverlayScrollPosition; | 164 - (void)updateOverlayScrollPosition; |
| 157 // Disable the horizontal scroll view. | 165 // Disable the horizontal scroll view. |
| 158 - (void)disableScroll; | 166 - (void)disableScroll; |
| 159 // Enable the horizontal scroll view. | 167 // Enable the horizontal scroll view. |
| 160 - (void)enableScroll; | 168 - (void)enableScroll; |
| 161 // Returns the ID for the currently selected panel. | 169 // Returns the ID for the currently selected panel. |
| 162 - (NewTabPage::PanelIdentifier)selectedPanelID; | 170 - (NewTabPage::PanelIdentifier)selectedPanelID; |
| 163 | 171 |
| 164 @property(nonatomic, retain) NewTabPageView* ntpView; | 172 @property(nonatomic, strong) NewTabPageView* ntpView; |
| 165 | 173 |
| 166 // To ease modernizing the NTP only the internal panels are being converted | 174 // To ease modernizing the NTP only the internal panels are being converted |
| 167 // to UIViewControllers. This means all the plumbing between the | 175 // to UIViewControllers. This means all the plumbing between the |
| 168 // BrowserViewController and the internal NTP panels (WebController, NTP) | 176 // BrowserViewController and the internal NTP panels (WebController, NTP) |
| 169 // hierarchy is skipped. While normally the logic to push and pop a view | 177 // 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 | 178 // 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 | 179 // controller adds and removes child view controllers itself when a load |
| 172 // is initiated, and when WebController calls -willBeDismissed. | 180 // is initiated, and when WebController calls -willBeDismissed. |
| 173 @property(nonatomic, assign) UIViewController* parentViewController; | 181 @property(nonatomic, weak) UIViewController* parentViewController; |
| 174 | 182 |
| 175 // To ease modernizing the NTP a non-descript CommandDispatcher is passed thru | 183 // To ease modernizing the NTP a non-descript CommandDispatcher is passed thru |
| 176 // to be used by the reuabled NTP panels. | 184 // to be used by the reuabled NTP panels. |
| 177 @property(nonatomic, assign) id dispatcher; | 185 @property(nonatomic, weak) id dispatcher; |
| 178 | 186 |
| 179 @end | 187 @end |
| 180 | 188 |
| 181 @implementation NewTabPageController | 189 @implementation NewTabPageController |
| 182 | 190 |
| 183 @synthesize ntpView = newTabPageView_; | 191 @synthesize ntpView = newTabPageView_; |
| 184 @synthesize swipeRecognizerProvider = swipeRecognizerProvider_; | 192 @synthesize swipeRecognizerProvider = swipeRecognizerProvider_; |
| 185 @synthesize parentViewController = parentViewController_; | 193 @synthesize parentViewController = parentViewController_; |
| 186 @synthesize dispatcher = dispatcher_; | 194 @synthesize dispatcher = dispatcher_; |
| 187 | 195 |
| 188 - (id)initWithUrl:(const GURL&)url | 196 - (id)initWithUrl:(const GURL&)url |
| 189 loader:(id<UrlLoader>)loader | 197 loader:(id<UrlLoader>)loader |
| 190 focuser:(id<OmniboxFocuser>)focuser | 198 focuser:(id<OmniboxFocuser>)focuser |
| 191 ntpObserver:(id<NewTabPageControllerObserver>)ntpObserver | 199 ntpObserver:(id<NewTabPageControllerObserver>)ntpObserver |
| 192 browserState:(ios::ChromeBrowserState*)browserState | 200 browserState:(ios::ChromeBrowserState*)browserState |
| 193 colorCache:(NSMutableDictionary*)colorCache | 201 colorCache:(NSMutableDictionary*)colorCache |
| 194 webToolbarDelegate:(id<WebToolbarDelegate>)webToolbarDelegate | 202 webToolbarDelegate:(id<WebToolbarDelegate>)webToolbarDelegate |
| 195 tabModel:(TabModel*)tabModel | 203 tabModel:(TabModel*)tabModel |
| 196 parentViewController:(UIViewController*)parentViewController | 204 parentViewController:(UIViewController*)parentViewController |
| 197 dispatcher:(id)dispatcher { | 205 dispatcher:(id)dispatcher { |
| 198 self = [super initWithNibName:nil url:url]; | 206 self = [super initWithNibName:nil url:url]; |
| 199 if (self) { | 207 if (self) { |
| 200 DCHECK(browserState); | 208 DCHECK(browserState); |
| 201 propertyReleaser_NewTabPageController_.Init(self, | |
| 202 [NewTabPageController class]); | |
| 203 browserState_ = browserState; | 209 browserState_ = browserState; |
| 204 loader_ = loader; | 210 loader_ = loader; |
| 205 newTabPageObserver_ = ntpObserver; | 211 newTabPageObserver_ = ntpObserver; |
| 206 parentViewController_ = parentViewController; | 212 parentViewController_ = parentViewController; |
| 207 dispatcher_ = dispatcher; | 213 dispatcher_ = dispatcher; |
| 208 focuser_.reset(focuser); | 214 focuser_ = focuser; |
| 209 webToolbarDelegate_.reset(webToolbarDelegate); | 215 webToolbarDelegate_ = webToolbarDelegate; |
| 210 tabModel_.reset([tabModel retain]); | 216 tabModel_ = tabModel; |
| 211 dominantColorCache_ = colorCache; | 217 dominantColorCache_ = colorCache; |
| 212 self.title = l10n_util::GetNSString(IDS_NEW_TAB_TITLE); | 218 self.title = l10n_util::GetNSString(IDS_NEW_TAB_TITLE); |
| 213 scrollInitialized_ = NO; | 219 scrollInitialized_ = NO; |
| 214 | 220 |
| 215 base::scoped_nsobject<UIScrollView> scrollView( | 221 UIScrollView* scrollView = |
| 216 [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 412)]); | 222 [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 412)]; |
| 217 [scrollView setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | | 223 [scrollView setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | |
| 218 UIViewAutoresizingFlexibleHeight)]; | 224 UIViewAutoresizingFlexibleHeight)]; |
| 219 base::scoped_nsobject<NewTabPageBar> tabBar( | 225 NewTabPageBar* tabBar = |
| 220 [[NewTabPageBar alloc] initWithFrame:CGRectMake(0, 412, 320, 48)]); | 226 [[NewTabPageBar alloc] initWithFrame:CGRectMake(0, 412, 320, 48)]; |
| 221 newTabPageView_ = | 227 newTabPageView_ = |
| 222 [[NewTabPageView alloc] initWithFrame:CGRectMake(0, 0, 320, 460) | 228 [[NewTabPageView alloc] initWithFrame:CGRectMake(0, 0, 320, 460) |
| 223 andScrollView:scrollView | 229 andScrollView:scrollView |
| 224 andTabBar:tabBar]; | 230 andTabBar:tabBar]; |
| 225 // TODO(crbug.com/607113): Merge view and ntpView. | 231 // TODO(crbug.com/607113): Merge view and ntpView. |
| 226 self.view = newTabPageView_; | 232 self.view = newTabPageView_; |
| 227 [tabBar setDelegate:self]; | 233 [tabBar setDelegate:self]; |
| 228 | 234 |
| 229 bool isIncognito = browserState_->IsOffTheRecord(); | 235 bool isIncognito = browserState_->IsOffTheRecord(); |
| 230 | 236 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 // CRWNativeContent leaks, this will not be called. | 316 // CRWNativeContent leaks, this will not be called. |
| 311 // TODO(crbug.com/708319): Also call -removeFromParentViewController for | 317 // TODO(crbug.com/708319): Also call -removeFromParentViewController for |
| 312 // open tabs and incognito here. | 318 // open tabs and incognito here. |
| 313 [googleLandingController_ removeFromParentViewController]; | 319 [googleLandingController_ removeFromParentViewController]; |
| 314 [bookmarkController_ removeFromParentViewController]; | 320 [bookmarkController_ removeFromParentViewController]; |
| 315 | 321 |
| 316 [googleLandingController_ setDelegate:nil]; | 322 [googleLandingController_ setDelegate:nil]; |
| 317 [bookmarkController_ setDelegate:nil]; | 323 [bookmarkController_ setDelegate:nil]; |
| 318 [openTabsController_ setDelegate:nil]; | 324 [openTabsController_ setDelegate:nil]; |
| 319 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 325 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 320 [super dealloc]; | |
| 321 } | 326 } |
| 322 | 327 |
| 323 #pragma mark - CRWNativeContent | 328 #pragma mark - CRWNativeContent |
| 324 | 329 |
| 325 - (void)willBeDismissed { | 330 - (void)willBeDismissed { |
| 326 // This methods is called by //web immediately before |self|'s view is removed | 331 // This methods is called by //web immediately before |self|'s view is removed |
| 327 // from the view hierarchy, making it an ideal spot to intiate view controller | 332 // from the view hierarchy, making it an ideal spot to intiate view controller |
| 328 // containment methods. | 333 // containment methods. |
| 329 // TODO(crbug.com/708319): Also call -willMoveToParentViewController:nil for | 334 // TODO(crbug.com/708319): Also call -willMoveToParentViewController:nil for |
| 330 // open tabs and incognito here. | 335 // open tabs and incognito here. |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 } | 531 } |
| 527 | 532 |
| 528 - (BOOL)loadPanel:(NewTabPageBarItem*)item { | 533 - (BOOL)loadPanel:(NewTabPageBarItem*)item { |
| 529 DCHECK(self.parentViewController); | 534 DCHECK(self.parentViewController); |
| 530 UIView* view = nil; | 535 UIView* view = nil; |
| 531 UIViewController* panelController = nil; | 536 UIViewController* panelController = nil; |
| 532 BOOL created = NO; | 537 BOOL created = NO; |
| 533 // Only load the controllers once. | 538 // Only load the controllers once. |
| 534 if (item.identifier == NewTabPage::kBookmarksPanel) { | 539 if (item.identifier == NewTabPage::kBookmarksPanel) { |
| 535 if (!bookmarkController_) { | 540 if (!bookmarkController_) { |
| 536 base::scoped_nsobject<BookmarkControllerFactory> factory( | 541 BookmarkControllerFactory* factory = |
| 537 [[BookmarkControllerFactory alloc] init]); | 542 [[BookmarkControllerFactory alloc] init]; |
| 538 bookmarkController_.reset([[factory | 543 bookmarkController_ = |
| 539 bookmarkPanelControllerForBrowserState:browserState_ | 544 [factory bookmarkPanelControllerForBrowserState:browserState_ |
| 540 loader:loader_ | 545 loader:loader_ |
| 541 colorCache:dominantColorCache_] retain]); | 546 colorCache:dominantColorCache_]; |
| 542 } | 547 } |
| 543 panelController = bookmarkController_; | 548 panelController = bookmarkController_; |
| 544 view = [bookmarkController_ view]; | 549 view = [bookmarkController_ view]; |
| 545 [bookmarkController_ setDelegate:self]; | 550 [bookmarkController_ setDelegate:self]; |
| 546 } else if (item.identifier == NewTabPage::kMostVisitedPanel) { | 551 } else if (item.identifier == NewTabPage::kMostVisitedPanel) { |
| 547 if (!googleLandingController_) { | 552 if (!googleLandingController_) { |
| 548 googleLandingController_.reset( | 553 googleLandingController_ = [[GoogleLandingViewController alloc] init]; |
| 549 [[GoogleLandingViewController alloc] init]); | |
| 550 [googleLandingController_ setDispatcher:self.dispatcher]; | 554 [googleLandingController_ setDispatcher:self.dispatcher]; |
| 551 googleLandingMediator_.reset([[GoogleLandingMediator alloc] | 555 googleLandingMediator_ = [[GoogleLandingMediator alloc] |
| 552 initWithConsumer:googleLandingController_ | 556 initWithConsumer:googleLandingController_ |
| 553 browserState:browserState_ | 557 browserState:browserState_ |
| 554 dispatcher:self.dispatcher | 558 dispatcher:self.dispatcher |
| 555 webStateList:[tabModel_ webStateList]]); | 559 webStateList:[tabModel_ webStateList]]; |
| 556 [googleLandingController_ setDataSource:googleLandingMediator_]; | 560 [googleLandingController_ setDataSource:googleLandingMediator_]; |
| 557 } | 561 } |
| 558 panelController = googleLandingController_; | 562 panelController = googleLandingController_; |
| 559 view = [googleLandingController_ view]; | 563 view = [googleLandingController_ view]; |
| 560 [googleLandingController_ setDelegate:self]; | 564 [googleLandingController_ setDelegate:self]; |
| 561 } else if (item.identifier == NewTabPage::kOpenTabsPanel) { | 565 } else if (item.identifier == NewTabPage::kOpenTabsPanel) { |
| 562 if (!openTabsController_) | 566 if (!openTabsController_) |
| 563 openTabsController_.reset([[RecentTabsPanelController alloc] | 567 openTabsController_ = |
| 564 initWithLoader:loader_ | 568 [[RecentTabsPanelController alloc] initWithLoader:loader_ |
| 565 browserState:browserState_]); | 569 browserState:browserState_]; |
| 566 // TODO(crbug.com/708319): Also set panelController for opentabs here. | 570 // TODO(crbug.com/708319): Also set panelController for opentabs here. |
| 567 view = [openTabsController_ view]; | 571 view = [openTabsController_ view]; |
| 568 [openTabsController_ setDelegate:self]; | 572 [openTabsController_ setDelegate:self]; |
| 569 } else if (item.identifier == NewTabPage::kIncognitoPanel) { | 573 } else if (item.identifier == NewTabPage::kIncognitoPanel) { |
| 570 if (!incognitoController_) | 574 if (!incognitoController_) |
| 571 incognitoController_.reset([[IncognitoPanelController alloc] | 575 incognitoController_ = |
| 572 initWithLoader:loader_ | 576 [[IncognitoPanelController alloc] initWithLoader:loader_ |
| 573 browserState:browserState_ | 577 browserState:browserState_ |
| 574 webToolbarDelegate:webToolbarDelegate_]); | 578 webToolbarDelegate:webToolbarDelegate_]; |
| 575 // TODO(crbug.com/708319): Also set panelController for incognito here. | 579 // TODO(crbug.com/708319): Also set panelController for incognito here. |
| 576 view = [incognitoController_ view]; | 580 view = [incognitoController_ view]; |
| 577 } else { | 581 } else { |
| 578 NOTREACHED(); | 582 NOTREACHED(); |
| 579 return NO; | 583 return NO; |
| 580 } | 584 } |
| 581 | 585 |
| 582 // Add the panel views to the scroll view in the proper location. | 586 // Add the panel views to the scroll view in the proper location. |
| 583 NSUInteger index = [self tabBarItemIndex:item]; | 587 NSUInteger index = [self tabBarItemIndex:item]; |
| 584 if (view.superview == nil) { | 588 if (view.superview == nil) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 605 } | 609 } |
| 606 | 610 |
| 607 - (void)scrollToPanel:(NewTabPageBarItem*)item animate:(BOOL)animate { | 611 - (void)scrollToPanel:(NewTabPageBarItem*)item animate:(BOOL)animate { |
| 608 NSUInteger index = [self tabBarItemIndex:item]; | 612 NSUInteger index = [self tabBarItemIndex:item]; |
| 609 if (IsIPadIdiom()) { | 613 if (IsIPadIdiom()) { |
| 610 CGRect itemFrame = [self.ntpView panelFrameForItemAtIndex:index]; | 614 CGRect itemFrame = [self.ntpView panelFrameForItemAtIndex:index]; |
| 611 CGPoint point = CGPointMake(CGRectGetMinX(itemFrame), 0); | 615 CGPoint point = CGPointMake(CGRectGetMinX(itemFrame), 0); |
| 612 [self.ntpView.scrollView setContentOffset:point animated:animate]; | 616 [self.ntpView.scrollView setContentOffset:point animated:animate]; |
| 613 } else { | 617 } else { |
| 614 if (item.identifier == NewTabPage::kBookmarksPanel) { | 618 if (item.identifier == NewTabPage::kBookmarksPanel) { |
| 615 base::scoped_nsobject<GenericChromeCommand> command( | 619 GenericChromeCommand* command = |
| 616 [[GenericChromeCommand alloc] initWithTag:IDC_SHOW_BOOKMARK_MANAGER]); | 620 [[GenericChromeCommand alloc] initWithTag:IDC_SHOW_BOOKMARK_MANAGER]; |
| 617 [self.ntpView chromeExecuteCommand:command]; | 621 [self.ntpView chromeExecuteCommand:command]; |
| 618 } else if (item.identifier == NewTabPage::kOpenTabsPanel) { | 622 } else if (item.identifier == NewTabPage::kOpenTabsPanel) { |
| 619 base::scoped_nsobject<GenericChromeCommand> command( | 623 GenericChromeCommand* command = |
| 620 [[GenericChromeCommand alloc] initWithTag:IDC_SHOW_OTHER_DEVICES]); | 624 [[GenericChromeCommand alloc] initWithTag:IDC_SHOW_OTHER_DEVICES]; |
| 621 [self.ntpView chromeExecuteCommand:command]; | 625 [self.ntpView chromeExecuteCommand:command]; |
| 622 } | 626 } |
| 623 } | 627 } |
| 624 | 628 |
| 625 if (currentController_ == nil) { | 629 if (currentController_ == nil) { |
| 626 [self updateCurrentController:item index:index]; | 630 [self updateCurrentController:item index:index]; |
| 627 } | 631 } |
| 628 } | 632 } |
| 629 | 633 |
| 630 // Return the index of the tab item. For iPhone always return 0 since the | 634 // Return the index of the tab item. For iPhone always return 0 since the |
| (...skipping 24 matching lines...) Expand all Loading... |
| 655 if (!IsIPadIdiom() && (item.identifier == NewTabPage::kBookmarksPanel || | 659 if (!IsIPadIdiom() && (item.identifier == NewTabPage::kBookmarksPanel || |
| 656 item.identifier == NewTabPage::kOpenTabsPanel)) { | 660 item.identifier == NewTabPage::kOpenTabsPanel)) { |
| 657 // Don't update |currentController_| for iPhone since Bookmarks and Recent | 661 // Don't update |currentController_| for iPhone since Bookmarks and Recent |
| 658 // Tabs are presented in a modal view controller. | 662 // Tabs are presented in a modal view controller. |
| 659 return; | 663 return; |
| 660 } | 664 } |
| 661 | 665 |
| 662 id<NewTabPagePanelProtocol> oldController = currentController_; | 666 id<NewTabPagePanelProtocol> oldController = currentController_; |
| 663 self.ntpView.tabBar.selectedIndex = index; | 667 self.ntpView.tabBar.selectedIndex = index; |
| 664 if (item.identifier == NewTabPage::kBookmarksPanel) | 668 if (item.identifier == NewTabPage::kBookmarksPanel) |
| 665 currentController_ = bookmarkController_.get(); | 669 currentController_ = bookmarkController_; |
| 666 else if (item.identifier == NewTabPage::kMostVisitedPanel) | 670 else if (item.identifier == NewTabPage::kMostVisitedPanel) |
| 667 currentController_ = googleLandingController_.get(); | 671 currentController_ = googleLandingController_; |
| 668 else if (item.identifier == NewTabPage::kOpenTabsPanel) | 672 else if (item.identifier == NewTabPage::kOpenTabsPanel) |
| 669 currentController_ = openTabsController_.get(); | 673 currentController_ = openTabsController_; |
| 670 else if (item.identifier == NewTabPage::kIncognitoPanel) | 674 else if (item.identifier == NewTabPage::kIncognitoPanel) |
| 671 currentController_ = incognitoController_.get(); | 675 currentController_ = incognitoController_; |
| 672 | 676 |
| 673 [bookmarkController_ | 677 [bookmarkController_ |
| 674 setScrollsToTop:(currentController_ == bookmarkController_.get())]; | 678 setScrollsToTop:(currentController_ == bookmarkController_)]; |
| 675 [googleLandingController_ | 679 [googleLandingController_ |
| 676 setScrollsToTop:(currentController_ == googleLandingController_.get())]; | 680 setScrollsToTop:(currentController_ == googleLandingController_)]; |
| 677 [openTabsController_ | 681 [openTabsController_ |
| 678 setScrollsToTop:(currentController_ == openTabsController_.get())]; | 682 setScrollsToTop:(currentController_ == openTabsController_)]; |
| 679 [self.ntpView.tabBar | 683 [self.ntpView.tabBar |
| 680 setShadowAlpha:[currentController_ alphaForBottomShadow]]; | 684 setShadowAlpha:[currentController_ alphaForBottomShadow]]; |
| 681 | 685 |
| 682 if (oldController != currentController_) { | 686 if (oldController != currentController_) { |
| 683 [currentController_ wasShown]; | 687 [currentController_ wasShown]; |
| 684 [oldController wasHidden]; | 688 [oldController wasHidden]; |
| 685 } | 689 } |
| 686 } | 690 } |
| 687 | 691 |
| 688 - (void)panelChanged:(NewTabPageBarItem*)item { | 692 - (void)panelChanged:(NewTabPageBarItem*)item { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 739 #pragma mark - NewTabPagePanelControllerDelegate | 743 #pragma mark - NewTabPagePanelControllerDelegate |
| 740 | 744 |
| 741 - (void)updateNtpBarShadowForPanelController: | 745 - (void)updateNtpBarShadowForPanelController: |
| 742 (id<NewTabPagePanelProtocol>)ntpPanelController { | 746 (id<NewTabPagePanelProtocol>)ntpPanelController { |
| 743 if (currentController_ != ntpPanelController) | 747 if (currentController_ != ntpPanelController) |
| 744 return; | 748 return; |
| 745 [self.ntpView.tabBar | 749 [self.ntpView.tabBar |
| 746 setShadowAlpha:[ntpPanelController alphaForBottomShadow]]; | 750 setShadowAlpha:[ntpPanelController alphaForBottomShadow]]; |
| 747 } | 751 } |
| 748 | 752 |
| 753 #pragma mark - TestSupport |
| 754 |
| 755 - (id<NewTabPagePanelProtocol>)currentController { |
| 756 return currentController_; |
| 757 } |
| 758 |
| 759 - (BookmarkHomeTabletNTPController*)bookmarkController { |
| 760 return bookmarkController_; |
| 761 } |
| 762 |
| 763 - (id<NewTabPagePanelProtocol>)incognitoController { |
| 764 return incognitoController_; |
| 765 } |
| 766 |
| 767 - (GoogleLandingViewController*)googleLandingController { |
| 768 return googleLandingController_; |
| 769 } |
| 770 |
| 749 @end | 771 @end |
| OLD | NEW |