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

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

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