OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/tab_switcher/tab_switcher_controller.h" | 5 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_controller.h" |
6 | 6 |
7 #include "base/ios/block_types.h" | 7 #include "base/ios/block_types.h" |
8 #include "base/ios/weak_nsobject.h" | |
9 #include "base/mac/scoped_nsobject.h" | |
10 #include "base/metrics/user_metrics.h" | 8 #include "base/metrics/user_metrics.h" |
11 #include "base/metrics/user_metrics_action.h" | 9 #include "base/metrics/user_metrics_action.h" |
12 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
13 #include "components/browser_sync/profile_sync_service.h" | 11 #include "components/browser_sync/profile_sync_service.h" |
14 #include "components/sessions/core/tab_restore_service_helper.h" | 12 #include "components/sessions/core/tab_restore_service_helper.h" |
15 #include "components/sync/driver/sync_service.h" | 13 #include "components/sync/driver/sync_service.h" |
16 #include "components/sync_sessions/open_tabs_ui_delegate.h" | 14 #include "components/sync_sessions/open_tabs_ui_delegate.h" |
17 #import "ios/chrome/browser/browser_state/chrome_browser_state.h" | 15 #import "ios/chrome/browser/browser_state/chrome_browser_state.h" |
18 #include "ios/chrome/browser/chrome_url_constants.h" | 16 #include "ios/chrome/browser/chrome_url_constants.h" |
19 #import "ios/chrome/browser/metrics/tab_usage_recorder.h" | 17 #import "ios/chrome/browser/metrics/tab_usage_recorder.h" |
(...skipping 26 matching lines...) Expand all Loading... |
46 #include "ios/chrome/browser/ui/ui_util.h" | 44 #include "ios/chrome/browser/ui/ui_util.h" |
47 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 45 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
48 #include "ios/chrome/grit/ios_strings.h" | 46 #include "ios/chrome/grit/ios_strings.h" |
49 #include "ios/chrome/grit/ios_theme_resources.h" | 47 #include "ios/chrome/grit/ios_theme_resources.h" |
50 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" | 48 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" |
51 #import "ios/web/public/navigation_manager.h" | 49 #import "ios/web/public/navigation_manager.h" |
52 #include "ios/web/public/referrer.h" | 50 #include "ios/web/public/referrer.h" |
53 #include "ui/base/l10n/l10n_util.h" | 51 #include "ui/base/l10n/l10n_util.h" |
54 #include "ui/base/l10n/l10n_util_mac.h" | 52 #include "ui/base/l10n/l10n_util_mac.h" |
55 | 53 |
| 54 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 55 #error "This file requires ARC support." |
| 56 #endif |
| 57 |
56 namespace { | 58 namespace { |
57 | 59 |
58 // Offsets for computing the panels' indexes in the TabSwitcherView. | 60 // Offsets for computing the panels' indexes in the TabSwitcherView. |
59 const int kSignInPromoPanelIndex = 2; | 61 const int kSignInPromoPanelIndex = 2; |
60 const int kHeaderDistantSessionIndexOffset = 2; | 62 const int kHeaderDistantSessionIndexOffset = 2; |
61 const int kLocalTabsOffTheRecordPanelIndex = 0; | 63 const int kLocalTabsOffTheRecordPanelIndex = 0; |
62 const int kLocalTabsOnTheRecordPanelIndex = 1; | 64 const int kLocalTabsOnTheRecordPanelIndex = 1; |
63 // The duration of the tab switcher toggle animation. | 65 // The duration of the tab switcher toggle animation. |
64 const CGFloat kTransitionAnimationDuration = 0.25; | 66 const CGFloat kTransitionAnimationDuration = 0.25; |
65 // The height of the browser view controller header. | 67 // The height of the browser view controller header. |
(...skipping 18 matching lines...) Expand all Loading... |
84 TabSwitcherHeaderViewDataSource, | 86 TabSwitcherHeaderViewDataSource, |
85 TabSwitcherPanelControllerDelegate> { | 87 TabSwitcherPanelControllerDelegate> { |
86 // weak. | 88 // weak. |
87 ios::ChromeBrowserState* _browserState; | 89 ios::ChromeBrowserState* _browserState; |
88 // weak. | 90 // weak. |
89 id<TabSwitcherDelegate> _delegate; | 91 id<TabSwitcherDelegate> _delegate; |
90 // The model selected when the tab switcher was toggled. | 92 // The model selected when the tab switcher was toggled. |
91 // weak. | 93 // weak. |
92 TabModel* _onLoadActiveModel; | 94 TabModel* _onLoadActiveModel; |
93 // The view this controller manages. | 95 // The view this controller manages. |
94 base::scoped_nsobject<TabSwitcherView> _tabSwitcherView; | 96 TabSwitcherView* _tabSwitcherView; |
95 // The list of panels controllers for distant sessions. | 97 // The list of panels controllers for distant sessions. |
96 base::scoped_nsobject<NSMutableArray> _controllersOfDistantSessions; | 98 NSMutableArray* _controllersOfDistantSessions; |
97 // The panel controllers for the local sessions. | 99 // The panel controllers for the local sessions. |
98 base::scoped_nsobject<TabSwitcherPanelController> _onTheRecordSession; | 100 TabSwitcherPanelController* _onTheRecordSession; |
99 base::scoped_nsobject<TabSwitcherPanelController> _offTheRecordSession; | 101 TabSwitcherPanelController* _offTheRecordSession; |
100 // The model storing the state of what is shown by the tab switcher. | 102 // The model storing the state of what is shown by the tab switcher. |
101 base::scoped_nsobject<TabSwitcherModel> _tabSwitcherModel; | 103 TabSwitcherModel* _tabSwitcherModel; |
102 // Stores the current sign-in panel type. | 104 // Stores the current sign-in panel type. |
103 TabSwitcherSignInPanelsType _signInPanelType; | 105 TabSwitcherSignInPanelsType _signInPanelType; |
104 // Cache for the panel's cells. | 106 // Cache for the panel's cells. |
105 base::scoped_nsobject<TabSwitcherCache> _cache; | 107 TabSwitcherCache* _cache; |
106 // Stores the background color of the window when the tab switcher was | 108 // Stores the background color of the window when the tab switcher was |
107 // presented. | 109 // presented. |
108 base::scoped_nsobject<UIColor> _initialWindowBackgroundColor; | 110 UIColor* _initialWindowBackgroundColor; |
109 // Indicate whether a previous promo panel header cell should be removed or | 111 // Indicate whether a previous promo panel header cell should be removed or |
110 // added. | 112 // added. |
111 BOOL _shouldRemovePromoPanelHeaderCell; | 113 BOOL _shouldRemovePromoPanelHeaderCell; |
112 BOOL _shouldAddPromoPanelHeaderCell; | 114 BOOL _shouldAddPromoPanelHeaderCell; |
113 } | 115 } |
114 | 116 |
115 // Updates the window background color to the tab switcher's background color. | 117 // Updates the window background color to the tab switcher's background color. |
116 // The original background color can be restored by calling | 118 // The original background color can be restored by calling |
117 // -restoreWindowBackgroundColor. | 119 // -restoreWindowBackgroundColor. |
118 - (void)updateWindowBackgroundColor; | 120 - (void)updateWindowBackgroundColor; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 mainTabModel:(TabModel*)mainTabModel | 188 mainTabModel:(TabModel*)mainTabModel |
187 otrTabModel:(TabModel*)otrTabModel | 189 otrTabModel:(TabModel*)otrTabModel |
188 activeTabModel:(TabModel*)activeTabModel { | 190 activeTabModel:(TabModel*)activeTabModel { |
189 DCHECK(mainTabModel); | 191 DCHECK(mainTabModel); |
190 DCHECK(otrTabModel); | 192 DCHECK(otrTabModel); |
191 DCHECK(activeTabModel == otrTabModel || activeTabModel == mainTabModel); | 193 DCHECK(activeTabModel == otrTabModel || activeTabModel == mainTabModel); |
192 self = [super initWithNibName:nil bundle:nil]; | 194 self = [super initWithNibName:nil bundle:nil]; |
193 if (self) { | 195 if (self) { |
194 _browserState = browserState; | 196 _browserState = browserState; |
195 _onLoadActiveModel = activeTabModel; | 197 _onLoadActiveModel = activeTabModel; |
196 _cache.reset([[TabSwitcherCache alloc] init]); | 198 _cache = [[TabSwitcherCache alloc] init]; |
197 [_cache setMainTabModel:mainTabModel otrTabModel:otrTabModel]; | 199 [_cache setMainTabModel:mainTabModel otrTabModel:otrTabModel]; |
198 _tabSwitcherModel.reset([[TabSwitcherModel alloc] | 200 _tabSwitcherModel = |
199 initWithBrowserState:browserState | 201 [[TabSwitcherModel alloc] initWithBrowserState:browserState |
200 delegate:self | 202 delegate:self |
201 mainTabModel:mainTabModel | 203 mainTabModel:mainTabModel |
202 otrTabModel:otrTabModel | 204 otrTabModel:otrTabModel |
203 withCache:_cache]); | 205 withCache:_cache]; |
204 _controllersOfDistantSessions.reset([[NSMutableArray alloc] init]); | 206 _controllersOfDistantSessions = [[NSMutableArray alloc] init]; |
205 [self loadTabSwitcherView]; | 207 [self loadTabSwitcherView]; |
206 _onTheRecordSession.reset([[TabSwitcherPanelController alloc] | 208 _onTheRecordSession = [[TabSwitcherPanelController alloc] |
207 initWithModel:_tabSwitcherModel | 209 initWithModel:_tabSwitcherModel |
208 forLocalSessionOfType:TabSwitcherSessionType::REGULAR_SESSION | 210 forLocalSessionOfType:TabSwitcherSessionType::REGULAR_SESSION |
209 withCache:_cache | 211 withCache:_cache |
210 browserState:_browserState]); | 212 browserState:_browserState]; |
211 [_onTheRecordSession setDelegate:self]; | 213 [_onTheRecordSession setDelegate:self]; |
212 _offTheRecordSession.reset([[TabSwitcherPanelController alloc] | 214 _offTheRecordSession = [[TabSwitcherPanelController alloc] |
213 initWithModel:_tabSwitcherModel | 215 initWithModel:_tabSwitcherModel |
214 forLocalSessionOfType:TabSwitcherSessionType::OFF_THE_RECORD_SESSION | 216 forLocalSessionOfType:TabSwitcherSessionType::OFF_THE_RECORD_SESSION |
215 withCache:_cache | 217 withCache:_cache |
216 browserState:_browserState]); | 218 browserState:_browserState]; |
217 [_offTheRecordSession setDelegate:self]; | 219 [_offTheRecordSession setDelegate:self]; |
218 [_tabSwitcherView addPanelView:[_offTheRecordSession view] | 220 [_tabSwitcherView addPanelView:[_offTheRecordSession view] |
219 atIndex:kLocalTabsOffTheRecordPanelIndex]; | 221 atIndex:kLocalTabsOffTheRecordPanelIndex]; |
220 [_tabSwitcherView addPanelView:[_onTheRecordSession view] | 222 [_tabSwitcherView addPanelView:[_onTheRecordSession view] |
221 atIndex:kLocalTabsOnTheRecordPanelIndex]; | 223 atIndex:kLocalTabsOnTheRecordPanelIndex]; |
222 [self addPromoPanelForSignInPanelType:[_tabSwitcherModel signInPanelType]]; | 224 [self addPromoPanelForSignInPanelType:[_tabSwitcherModel signInPanelType]]; |
223 [[_tabSwitcherView headerView] reloadData]; | 225 [[_tabSwitcherView headerView] reloadData]; |
224 [_tabSwitcherModel syncedSessionsChanged]; | 226 [_tabSwitcherModel syncedSessionsChanged]; |
225 [self selectPanelForTabModel:_onLoadActiveModel]; | 227 [self selectPanelForTabModel:_onLoadActiveModel]; |
226 } | 228 } |
227 return self; | 229 return self; |
228 } | 230 } |
229 | 231 |
230 #pragma mark - UIViewController | 232 #pragma mark - UIViewController |
231 | 233 |
232 - (BOOL)prefersStatusBarHidden { | 234 - (BOOL)prefersStatusBarHidden { |
233 return NO; | 235 return NO; |
234 } | 236 } |
235 | 237 |
236 - (UIStatusBarStyle)preferredStatusBarStyle { | 238 - (UIStatusBarStyle)preferredStatusBarStyle { |
237 return UIStatusBarStyleLightContent; | 239 return UIStatusBarStyleLightContent; |
238 } | 240 } |
239 | 241 |
240 - (CGRect)tabSwitcherInitialFrame { | 242 - (CGRect)tabSwitcherInitialFrame { |
241 return [[UIScreen mainScreen] bounds]; | 243 return [[UIScreen mainScreen] bounds]; |
242 } | 244 } |
243 | 245 |
244 - (void)loadTabSwitcherView { | 246 - (void)loadTabSwitcherView { |
245 DCHECK(![_tabSwitcherView superview]); | 247 DCHECK(![_tabSwitcherView superview]); |
246 _tabSwitcherView.reset( | 248 _tabSwitcherView = |
247 [[TabSwitcherView alloc] initWithFrame:[self tabSwitcherInitialFrame]]); | 249 [[TabSwitcherView alloc] initWithFrame:[self tabSwitcherInitialFrame]]; |
248 [_tabSwitcherView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | | 250 [_tabSwitcherView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | |
249 UIViewAutoresizingFlexibleHeight]; | 251 UIViewAutoresizingFlexibleHeight]; |
250 [_tabSwitcherView setDelegate:self]; | 252 [_tabSwitcherView setDelegate:self]; |
251 [[_tabSwitcherView headerView] setDelegate:self]; | 253 [[_tabSwitcherView headerView] setDelegate:self]; |
252 [[_tabSwitcherView headerView] setDataSource:self]; | 254 [[_tabSwitcherView headerView] setDataSource:self]; |
253 } | 255 } |
254 | 256 |
255 - (void)viewDidLoad { | 257 - (void)viewDidLoad { |
256 [super viewDidLoad]; | 258 [super viewDidLoad]; |
257 [self.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth | | 259 [self.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth | |
258 UIViewAutoresizingFlexibleHeight]; | 260 UIViewAutoresizingFlexibleHeight]; |
259 [_tabSwitcherView setFrame:self.view.bounds]; | 261 [_tabSwitcherView setFrame:self.view.bounds]; |
260 [self.view addSubview:_tabSwitcherView]; | 262 [self.view addSubview:_tabSwitcherView]; |
261 } | 263 } |
262 | 264 |
263 #pragma mark - UIResponder | 265 #pragma mark - UIResponder |
264 | 266 |
265 - (NSArray*)keyCommands { | 267 - (NSArray*)keyCommands { |
266 base::WeakNSObject<TabSwitcherController> weakSelf(self); | 268 __weak TabSwitcherController* weakSelf = self; |
267 return @[ | 269 return @[ |
268 [UIKeyCommand | 270 [UIKeyCommand |
269 cr_keyCommandWithInput:@"t" | 271 cr_keyCommandWithInput:@"t" |
270 modifierFlags:UIKeyModifierCommand | 272 modifierFlags:UIKeyModifierCommand |
271 title:l10n_util::GetNSStringWithFixup( | 273 title:l10n_util::GetNSStringWithFixup( |
272 IDS_IOS_TOOLS_MENU_NEW_TAB) | 274 IDS_IOS_TOOLS_MENU_NEW_TAB) |
273 action:^{ | 275 action:^{ |
274 base::scoped_nsobject<TabSwitcherController> | 276 TabSwitcherController* strongSelf = weakSelf; |
275 strongSelf([weakSelf retain]); | |
276 if (!strongSelf) | 277 if (!strongSelf) |
277 return; | 278 return; |
278 if ([strongSelf currentPanelIndex] == | 279 if ([strongSelf currentPanelIndex] == |
279 kLocalTabsOffTheRecordPanelIndex) { | 280 kLocalTabsOffTheRecordPanelIndex) { |
280 [strongSelf openNewTabInPanelAtIndex: | 281 [strongSelf openNewTabInPanelAtIndex: |
281 kLocalTabsOffTheRecordPanelIndex]; | 282 kLocalTabsOffTheRecordPanelIndex]; |
282 } else { | 283 } else { |
283 [strongSelf openNewTabInPanelAtIndex: | 284 [strongSelf openNewTabInPanelAtIndex: |
284 kLocalTabsOnTheRecordPanelIndex]; | 285 kLocalTabsOnTheRecordPanelIndex]; |
285 } | 286 } |
(...skipping 13 matching lines...) Expand all Loading... |
299 title:l10n_util::GetNSStringWithFixup( | 300 title:l10n_util::GetNSStringWithFixup( |
300 IDS_IOS_KEYBOARD_REOPEN_CLOSED_TAB) | 301 IDS_IOS_KEYBOARD_REOPEN_CLOSED_TAB) |
301 action:^{ | 302 action:^{ |
302 [weakSelf reopenClosedTab]; | 303 [weakSelf reopenClosedTab]; |
303 }], | 304 }], |
304 [UIKeyCommand | 305 [UIKeyCommand |
305 cr_keyCommandWithInput:@"n" | 306 cr_keyCommandWithInput:@"n" |
306 modifierFlags:UIKeyModifierCommand | 307 modifierFlags:UIKeyModifierCommand |
307 title:nil | 308 title:nil |
308 action:^{ | 309 action:^{ |
309 base::scoped_nsobject<TabSwitcherController> | 310 TabSwitcherController* strongSelf = weakSelf; |
310 strongSelf([weakSelf retain]); | |
311 if (!strongSelf) | 311 if (!strongSelf) |
312 return; | 312 return; |
313 if ([strongSelf currentPanelIndex] == | 313 if ([strongSelf currentPanelIndex] == |
314 kLocalTabsOffTheRecordPanelIndex) { | 314 kLocalTabsOffTheRecordPanelIndex) { |
315 [strongSelf openNewTabInPanelAtIndex: | 315 [strongSelf openNewTabInPanelAtIndex: |
316 kLocalTabsOffTheRecordPanelIndex]; | 316 kLocalTabsOffTheRecordPanelIndex]; |
317 } else { | 317 } else { |
318 [strongSelf openNewTabInPanelAtIndex: | 318 [strongSelf openNewTabInPanelAtIndex: |
319 kLocalTabsOnTheRecordPanelIndex]; | 319 kLocalTabsOnTheRecordPanelIndex]; |
320 } | 320 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 default: | 407 default: |
408 [super chromeExecuteCommand:sender]; | 408 [super chromeExecuteCommand:sender]; |
409 break; | 409 break; |
410 } | 410 } |
411 } | 411 } |
412 | 412 |
413 #pragma mark - Private | 413 #pragma mark - Private |
414 | 414 |
415 - (void)updateWindowBackgroundColor { | 415 - (void)updateWindowBackgroundColor { |
416 DCHECK(!_initialWindowBackgroundColor); | 416 DCHECK(!_initialWindowBackgroundColor); |
417 _initialWindowBackgroundColor.reset( | 417 _initialWindowBackgroundColor = self.view.window.backgroundColor; |
418 [self.view.window.backgroundColor retain]); | |
419 self.view.window.backgroundColor = [[MDCPalette greyPalette] tint900]; | 418 self.view.window.backgroundColor = [[MDCPalette greyPalette] tint900]; |
420 } | 419 } |
421 | 420 |
422 - (void)restoreWindowBackgroundColor { | 421 - (void)restoreWindowBackgroundColor { |
423 self.view.window.backgroundColor = _initialWindowBackgroundColor; | 422 self.view.window.backgroundColor = _initialWindowBackgroundColor; |
424 _initialWindowBackgroundColor.reset(); | 423 _initialWindowBackgroundColor = nil; |
425 } | 424 } |
426 | 425 |
427 - (UIView*)snapshotViewForView:(UIView*)inputView | 426 - (UIView*)snapshotViewForView:(UIView*)inputView |
428 withModel:(TabModel*)tabModel | 427 withModel:(TabModel*)tabModel |
429 option:(SnapshotViewOption)option { | 428 option:(SnapshotViewOption)option { |
430 if (inputView) { | 429 if (inputView) { |
431 if (option == SnapshotViewOption::SNAPSHOT_VIEW) { | 430 if (option == SnapshotViewOption::SNAPSHOT_VIEW) { |
432 UIView* view = [inputView snapshotViewAfterScreenUpdates:NO]; | 431 UIView* view = [inputView snapshotViewAfterScreenUpdates:NO]; |
433 if (view) | 432 if (view) |
434 return view; | 433 return view; |
435 } | 434 } |
436 // If the view has just been created, it has not been rendered by Core | 435 // If the view has just been created, it has not been rendered by Core |
437 // Animation and the snapshot view can't be generated. In that case we | 436 // Animation and the snapshot view can't be generated. In that case we |
438 // trigger a client side rendering of the view and use the rendered image | 437 // trigger a client side rendering of the view and use the rendered image |
439 // as the backing store of a view layer. | 438 // as the backing store of a view layer. |
440 UIGraphicsBeginImageContextWithOptions(inputView.bounds.size, | 439 UIGraphicsBeginImageContextWithOptions(inputView.bounds.size, |
441 inputView.opaque, 0); | 440 inputView.opaque, 0); |
442 [inputView.layer renderInContext:UIGraphicsGetCurrentContext()]; | 441 [inputView.layer renderInContext:UIGraphicsGetCurrentContext()]; |
443 UIImage* screenshot = UIGraphicsGetImageFromCurrentImageContext(); | 442 UIImage* screenshot = UIGraphicsGetImageFromCurrentImageContext(); |
444 UIGraphicsEndImageContext(); | 443 UIGraphicsEndImageContext(); |
445 UIView* view = [[[UIView alloc] initWithFrame:CGRectZero] autorelease]; | 444 UIView* view = [[UIView alloc] initWithFrame:CGRectZero]; |
446 [view layer].contents = static_cast<id>(screenshot.CGImage); | 445 [view layer].contents = static_cast<id>(screenshot.CGImage); |
447 return view; | 446 return view; |
448 } else { | 447 } else { |
449 // When the input view is nil, we can't generate a snapshot so a placeholder | 448 // When the input view is nil, we can't generate a snapshot so a placeholder |
450 // is returned. | 449 // is returned. |
451 UIColor* backgroundColor = [tabModel isOffTheRecord] | 450 UIColor* backgroundColor = [tabModel isOffTheRecord] |
452 ? [[MDCPalette greyPalette] tint700] | 451 ? [[MDCPalette greyPalette] tint700] |
453 : [[MDCPalette greyPalette] tint100]; | 452 : [[MDCPalette greyPalette] tint100]; |
454 UIView* placeholdView = | 453 UIView* placeholdView = [[UIView alloc] initWithFrame:CGRectZero]; |
455 [[[UIView alloc] initWithFrame:CGRectZero] autorelease]; | |
456 placeholdView.backgroundColor = backgroundColor; | 454 placeholdView.backgroundColor = backgroundColor; |
457 return placeholdView; | 455 return placeholdView; |
458 } | 456 } |
459 } | 457 } |
460 | 458 |
461 - (TabSwitcherTransitionContextContent*)transitionContextContentForTabModel: | 459 - (TabSwitcherTransitionContextContent*)transitionContextContentForTabModel: |
462 (TabModel*)tabModel { | 460 (TabModel*)tabModel { |
463 if ([tabModel isOffTheRecord]) | 461 if ([tabModel isOffTheRecord]) |
464 return self.transitionContext.incognitoContent; | 462 return self.transitionContext.incognitoContent; |
465 else | 463 else |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 | 552 |
555 // Compute initial and final toolbar screenshot frames. | 553 // Compute initial and final toolbar screenshot frames. |
556 const CGRect initialToolbarFrame = toolbarController.view.frame; | 554 const CGRect initialToolbarFrame = toolbarController.view.frame; |
557 CGRect initialToolbarScreenshotFrame = CGRectMake( | 555 CGRect initialToolbarScreenshotFrame = CGRectMake( |
558 0, 0, initialToolbarFrame.size.width, initialToolbarFrame.size.height); | 556 0, 0, initialToolbarFrame.size.width, initialToolbarFrame.size.height); |
559 | 557 |
560 const CGFloat cellTopBarHeight = tabSwitcherLocalSessionCellTopBarHeight(); | 558 const CGFloat cellTopBarHeight = tabSwitcherLocalSessionCellTopBarHeight(); |
561 CGRect finalToolbarScreenshotFrame = | 559 CGRect finalToolbarScreenshotFrame = |
562 CGRectMake(0, 0, selectedCellFrame.size.width, cellTopBarHeight); | 560 CGRectMake(0, 0, selectedCellFrame.size.width, cellTopBarHeight); |
563 | 561 |
564 base::scoped_nsobject<UIImageView> tabScreenshotImageView( | 562 UIImageView* tabScreenshotImageView = |
565 [[UIImageView alloc] initWithFrame:CGRectZero]); | 563 [[UIImageView alloc] initWithFrame:CGRectZero]; |
566 | 564 |
567 base::WeakNSObject<UIImageView> weakTabScreenshotImageView( | 565 __weak UIImageView* weakTabScreenshotImageView = tabScreenshotImageView; |
568 tabScreenshotImageView.get()); | |
569 | 566 |
570 if ([self initialTabModelAndTabIDMatchesTabModel:tabModel | 567 if ([self initialTabModelAndTabIDMatchesTabModel:tabModel |
571 tabID:selectedTab.tabId]) { | 568 tabID:selectedTab.tabId]) { |
572 tabScreenshotImageView.get().image = | 569 tabScreenshotImageView.image = self.transitionContext.tabSnapshotImage; |
573 self.transitionContext.tabSnapshotImage; | |
574 } else { | 570 } else { |
575 // If transitioning to a different tab than the one animated in | 571 // If transitioning to a different tab than the one animated in |
576 // from, a new snapshot should be generated instead of using the transition | 572 // from, a new snapshot should be generated instead of using the transition |
577 // context | 573 // context |
578 tabScreenshotImageView.get().image = | 574 tabScreenshotImageView.image = |
579 [self updateScreenshotForCellIfNeeded:selectedCell tabModel:tabModel]; | 575 [self updateScreenshotForCellIfNeeded:selectedCell tabModel:tabModel]; |
580 [selectedTab retrieveSnapshot:^(UIImage* snapshot) { | 576 [selectedTab retrieveSnapshot:^(UIImage* snapshot) { |
581 [weakTabScreenshotImageView setImage:snapshot]; | 577 [weakTabScreenshotImageView setImage:snapshot]; |
582 }]; | 578 }]; |
583 } | 579 } |
584 | 580 |
585 const CGSize tabScreenshotImageSize = tabScreenshotImageView.get().image.size; | 581 const CGSize tabScreenshotImageSize = tabScreenshotImageView.image.size; |
586 | 582 |
587 CGRect initialTabScreenshotFrame = CGRectZero; | 583 CGRect initialTabScreenshotFrame = CGRectZero; |
588 const CGSize toolbarSize = toolbarController.view.bounds.size; | 584 const CGSize toolbarSize = toolbarController.view.bounds.size; |
589 CGSize initialTabTargetSize = | 585 CGSize initialTabTargetSize = |
590 CGSizeMake(initialTabFrame.size.width, | 586 CGSizeMake(initialTabFrame.size.width, |
591 initialTabFrame.size.height - toolbarSize.height); | 587 initialTabFrame.size.height - toolbarSize.height); |
592 CGSize revisedTargetSize = CGSizeZero; | 588 CGSize revisedTargetSize = CGSizeZero; |
593 CalculateProjection(tabScreenshotImageSize, initialTabTargetSize, | 589 CalculateProjection(tabScreenshotImageSize, initialTabTargetSize, |
594 ProjectionMode::kAspectFill, revisedTargetSize, | 590 ProjectionMode::kAspectFill, revisedTargetSize, |
595 initialTabScreenshotFrame); | 591 initialTabScreenshotFrame); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 std::swap(initialToolbarScreenshotFrame, finalToolbarScreenshotFrame); | 629 std::swap(initialToolbarScreenshotFrame, finalToolbarScreenshotFrame); |
634 } else { | 630 } else { |
635 [tabStripPlaceholderView foldWithCompletion:^{ | 631 [tabStripPlaceholderView foldWithCompletion:^{ |
636 [tabStripPlaceholderView removeFromSuperview]; | 632 [tabStripPlaceholderView removeFromSuperview]; |
637 }]; | 633 }]; |
638 } | 634 } |
639 | 635 |
640 tabStripPlaceholderView.frame = tabStripInitialFrame; | 636 tabStripPlaceholderView.frame = tabStripInitialFrame; |
641 | 637 |
642 // Create and setup placeholder view and subviews. | 638 // Create and setup placeholder view and subviews. |
643 base::scoped_nsobject<UIView> placeholderView( | 639 UIView* placeholderView = [[UIView alloc] initWithFrame:initialTabFrame]; |
644 [[UIView alloc] initWithFrame:initialTabFrame]); | |
645 [placeholderView setClipsToBounds:YES]; | 640 [placeholderView setClipsToBounds:YES]; |
646 [placeholderView setUserInteractionEnabled:NO]; | 641 [placeholderView setUserInteractionEnabled:NO]; |
647 | 642 |
648 tabScreenshotImageView.get().frame = initialTabScreenshotFrame; | 643 tabScreenshotImageView.frame = initialTabScreenshotFrame; |
649 tabScreenshotImageView.get().contentMode = UIViewContentModeScaleToFill; | 644 tabScreenshotImageView.contentMode = UIViewContentModeScaleToFill; |
650 tabScreenshotImageView.get().autoresizingMask = UIViewAutoresizingNone; | 645 tabScreenshotImageView.autoresizingMask = UIViewAutoresizingNone; |
651 [placeholderView addSubview:tabScreenshotImageView]; | 646 [placeholderView addSubview:tabScreenshotImageView]; |
652 | 647 |
653 // Try using a snapshot view for dismissal animation because it's faster and | 648 // Try using a snapshot view for dismissal animation because it's faster and |
654 // the collection view has already been rendered. Use a client rendering | 649 // the collection view has already been rendered. Use a client rendering |
655 // otherwise. | 650 // otherwise. |
656 SnapshotViewOption snapshotOption = SnapshotViewOption::SNAPSHOT_VIEW; | 651 SnapshotViewOption snapshotOption = SnapshotViewOption::SNAPSHOT_VIEW; |
657 if (transitionType == TransitionType::TRANSITION_PRESENT) | 652 if (transitionType == TransitionType::TRANSITION_PRESENT) |
658 snapshotOption = SnapshotViewOption::CLIENT_RENDERING; | 653 snapshotOption = SnapshotViewOption::CLIENT_RENDERING; |
659 | 654 |
660 UIView* finalToolbarScreenshotImageView = | 655 UIView* finalToolbarScreenshotImageView = |
661 [self snapshotViewForView:selectedCell.topBar | 656 [self snapshotViewForView:selectedCell.topBar |
662 withModel:tabModel | 657 withModel:tabModel |
663 option:snapshotOption]; | 658 option:snapshotOption]; |
664 finalToolbarScreenshotImageView.autoresizingMask = UIViewAutoresizingNone; | 659 finalToolbarScreenshotImageView.autoresizingMask = UIViewAutoresizingNone; |
665 finalToolbarScreenshotImageView.frame = initialToolbarScreenshotFrame; | 660 finalToolbarScreenshotImageView.frame = initialToolbarScreenshotFrame; |
666 [placeholderView addSubview:finalToolbarScreenshotImageView]; | 661 [placeholderView addSubview:finalToolbarScreenshotImageView]; |
667 | 662 |
668 UIView* toolbarScreenshotImageView = | 663 UIView* toolbarScreenshotImageView = |
669 transitionContextContent.toolbarSnapshotView; | 664 transitionContextContent.toolbarSnapshotView; |
670 toolbarScreenshotImageView.autoresizingMask = UIViewAutoresizingNone; | 665 toolbarScreenshotImageView.autoresizingMask = UIViewAutoresizingNone; |
671 toolbarScreenshotImageView.frame = initialToolbarScreenshotFrame; | 666 toolbarScreenshotImageView.frame = initialToolbarScreenshotFrame; |
672 [placeholderView addSubview:toolbarScreenshotImageView]; | 667 [placeholderView addSubview:toolbarScreenshotImageView]; |
673 | 668 |
674 base::scoped_nsobject<UIImageView> toolbarShadowImageView( | 669 UIImageView* toolbarShadowImageView = |
675 [[UIImageView alloc] initWithFrame:shadowInitialFrame]); | 670 [[UIImageView alloc] initWithFrame:shadowInitialFrame]; |
676 [toolbarShadowImageView setAutoresizingMask:UIViewAutoresizingNone]; | 671 [toolbarShadowImageView setAutoresizingMask:UIViewAutoresizingNone]; |
677 [toolbarShadowImageView setImage:NativeImage(IDR_IOS_TOOLBAR_SHADOW)]; | 672 [toolbarShadowImageView setImage:NativeImage(IDR_IOS_TOOLBAR_SHADOW)]; |
678 [placeholderView addSubview:toolbarShadowImageView]; | 673 [placeholderView addSubview:toolbarShadowImageView]; |
679 | 674 |
680 [self.view addSubview:placeholderView]; | 675 [self.view addSubview:placeholderView]; |
681 | 676 |
682 [selectedCell setHidden:YES]; | 677 [selectedCell setHidden:YES]; |
683 toolbarScreenshotImageView.alpha = | 678 toolbarScreenshotImageView.alpha = |
684 (transitionType == TransitionType::TRANSITION_DISMISS) ? 0 : 1.0; | 679 (transitionType == TransitionType::TRANSITION_DISMISS) ? 0 : 1.0; |
685 | 680 |
686 base::WeakNSObject<TabSwitcherController> weakSelf(self); | 681 __weak TabSwitcherController* weakSelf = self; |
687 void (^completionBlock)(BOOL) = ^(BOOL finished) { | 682 void (^completionBlock)(BOOL) = ^(BOOL finished) { |
688 base::scoped_nsobject<TabSwitcherController> strongSelf([weakSelf retain]); | 683 TabSwitcherController* strongSelf = weakSelf; |
689 | 684 |
690 [tabStripPlaceholderView removeFromSuperview]; | 685 [tabStripPlaceholderView removeFromSuperview]; |
691 [toolbarScreenshotImageView removeFromSuperview]; | 686 [toolbarScreenshotImageView removeFromSuperview]; |
692 [selectedCell setHidden:NO]; | 687 [selectedCell setHidden:NO]; |
693 [placeholderView removeFromSuperview]; | 688 [placeholderView removeFromSuperview]; |
694 | 689 |
695 if (transitionType == TransitionType::TRANSITION_DISMISS) { | 690 if (transitionType == TransitionType::TRANSITION_DISMISS) { |
696 [strongSelf restoreWindowBackgroundColor]; | 691 [strongSelf restoreWindowBackgroundColor]; |
697 if (finished) { | 692 if (finished) { |
698 [strongSelf setTransitionContext:nil]; | 693 [strongSelf setTransitionContext:nil]; |
699 } | 694 } |
700 } | 695 } |
701 [[[strongSelf delegate] tabSwitcherTransitionToolbarOwner] | 696 [[[strongSelf delegate] tabSwitcherTransitionToolbarOwner] |
702 reparentToolbarController]; | 697 reparentToolbarController]; |
703 [[strongSelf view] setUserInteractionEnabled:YES]; | 698 [[strongSelf view] setUserInteractionEnabled:YES]; |
704 completion(); | 699 completion(); |
705 }; | 700 }; |
706 | 701 |
707 ProceduralBlock animationBlock = ^{ | 702 ProceduralBlock animationBlock = ^{ |
708 toolbarScreenshotImageView.alpha = | 703 toolbarScreenshotImageView.alpha = |
709 transitionType == TransitionType::TRANSITION_DISMISS ? 1.0 : 0; | 704 transitionType == TransitionType::TRANSITION_DISMISS ? 1.0 : 0; |
710 tabStripPlaceholderView.frame = tabStripFinalFrame; | 705 tabStripPlaceholderView.frame = tabStripFinalFrame; |
711 toolbarShadowImageView.get().frame = shadowFinalFrame; | 706 toolbarShadowImageView.frame = shadowFinalFrame; |
712 placeholderView.get().frame = finalTabFrame; | 707 placeholderView.frame = finalTabFrame; |
713 toolbarScreenshotImageView.frame = finalToolbarScreenshotFrame; | 708 toolbarScreenshotImageView.frame = finalToolbarScreenshotFrame; |
714 finalToolbarScreenshotImageView.frame = finalToolbarScreenshotFrame; | 709 finalToolbarScreenshotImageView.frame = finalToolbarScreenshotFrame; |
715 tabScreenshotImageView.get().frame = finalTabScreenshotFrame; | 710 tabScreenshotImageView.frame = finalTabScreenshotFrame; |
716 }; | 711 }; |
717 | 712 |
718 [UIView animateWithDuration:animated ? kTransitionAnimationDuration : 0 | 713 [UIView animateWithDuration:animated ? kTransitionAnimationDuration : 0 |
719 delay:0 | 714 delay:0 |
720 options:UIViewAnimationCurveEaseInOut | 715 options:UIViewAnimationCurveEaseInOut |
721 animations:animationBlock | 716 animations:animationBlock |
722 completion:completionBlock]; | 717 completion:completionBlock]; |
723 } | 718 } |
724 | 719 |
725 - (BOOL)initialTabModelAndTabIDMatchesTabModel:(nonnull TabModel*)tabModel | 720 - (BOOL)initialTabModelAndTabIDMatchesTabModel:(nonnull TabModel*)tabModel |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 (selectedTabModel == [_tabSwitcherModel otrTabModel]) | 784 (selectedTabModel == [_tabSwitcherModel otrTabModel]) |
790 ? kLocalTabsOffTheRecordPanelIndex | 785 ? kLocalTabsOffTheRecordPanelIndex |
791 : kLocalTabsOnTheRecordPanelIndex; | 786 : kLocalTabsOnTheRecordPanelIndex; |
792 [_tabSwitcherView selectPanelAtIndex:selectedPanel]; | 787 [_tabSwitcherView selectPanelAtIndex:selectedPanel]; |
793 } | 788 } |
794 | 789 |
795 - (TabSwitcherPanelController*)panelControllerForTabModel:(TabModel*)tabModel { | 790 - (TabSwitcherPanelController*)panelControllerForTabModel:(TabModel*)tabModel { |
796 DCHECK(tabModel == [_tabSwitcherModel mainTabModel] || | 791 DCHECK(tabModel == [_tabSwitcherModel mainTabModel] || |
797 tabModel == [_tabSwitcherModel otrTabModel]); | 792 tabModel == [_tabSwitcherModel otrTabModel]); |
798 if (tabModel == [_tabSwitcherModel mainTabModel]) | 793 if (tabModel == [_tabSwitcherModel mainTabModel]) |
799 return _onTheRecordSession.get(); | 794 return _onTheRecordSession; |
800 if (tabModel == [_tabSwitcherModel otrTabModel]) | 795 if (tabModel == [_tabSwitcherModel otrTabModel]) |
801 return _offTheRecordSession.get(); | 796 return _offTheRecordSession; |
802 return nil; | 797 return nil; |
803 } | 798 } |
804 | 799 |
805 - (void)tabSwitcherDismissWithModel:(TabModel*)model { | 800 - (void)tabSwitcherDismissWithModel:(TabModel*)model { |
806 [self tabSwitcherDismissWithModel:model animated:YES]; | 801 [self tabSwitcherDismissWithModel:model animated:YES]; |
807 } | 802 } |
808 | 803 |
809 - (void)tabSwitcherDismissWithModel:(TabModel*)model animated:(BOOL)animated { | 804 - (void)tabSwitcherDismissWithModel:(TabModel*)model animated:(BOOL)animated { |
810 [self tabSwitcherDismissWithModel:model | 805 [self tabSwitcherDismissWithModel:model |
811 animated:animated | 806 animated:animated |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
949 // with the indexes in |_controllersOfDistantSessions|. | 944 // with the indexes in |_controllersOfDistantSessions|. |
950 for (NSNumber* objCIndex in [removedIndexes reverseObjectEnumerator]) { | 945 for (NSNumber* objCIndex in [removedIndexes reverseObjectEnumerator]) { |
951 int index = [objCIndex intValue]; | 946 int index = [objCIndex intValue]; |
952 [_tabSwitcherView removePanelViewAtIndex:index + offset]; | 947 [_tabSwitcherView removePanelViewAtIndex:index + offset]; |
953 [_controllersOfDistantSessions removeObjectAtIndex:index]; | 948 [_controllersOfDistantSessions removeObjectAtIndex:index]; |
954 } | 949 } |
955 | 950 |
956 for (NSNumber* objCIndex in insertedIndexes) { | 951 for (NSNumber* objCIndex in insertedIndexes) { |
957 int index = [objCIndex intValue]; | 952 int index = [objCIndex intValue]; |
958 std::string tag = [_tabSwitcherModel tagOfDistantSessionAtIndex:index]; | 953 std::string tag = [_tabSwitcherModel tagOfDistantSessionAtIndex:index]; |
959 base::scoped_nsobject<TabSwitcherPanelController> panelController( | 954 TabSwitcherPanelController* panelController = |
960 [[TabSwitcherPanelController alloc] initWithModel:_tabSwitcherModel | 955 [[TabSwitcherPanelController alloc] initWithModel:_tabSwitcherModel |
961 forDistantSessionWithTag:tag | 956 forDistantSessionWithTag:tag |
962 browserState:_browserState]); | 957 browserState:_browserState]; |
963 [panelController setDelegate:self]; | 958 [panelController setDelegate:self]; |
964 [_tabSwitcherView addPanelView:[panelController view] | 959 [_tabSwitcherView addPanelView:[panelController view] |
965 atIndex:index + offset]; | 960 atIndex:index + offset]; |
966 [_controllersOfDistantSessions insertObject:panelController.get() | 961 [_controllersOfDistantSessions insertObject:panelController atIndex:index]; |
967 atIndex:index]; | |
968 } | 962 } |
969 | 963 |
970 // Update the header view. | 964 // Update the header view. |
971 // The header view's content is created using the panel's content. | 965 // The header view's content is created using the panel's content. |
972 [[_tabSwitcherView headerView] reloadData]; | 966 [[_tabSwitcherView headerView] reloadData]; |
973 } | 967 } |
974 | 968 |
975 - (void)distantSessionMayNeedUpdate:(std::string const&)tag { | 969 - (void)distantSessionMayNeedUpdate:(std::string const&)tag { |
976 for (TabSwitcherPanelController* panel in _controllersOfDistantSessions | 970 for (TabSwitcherPanelController* panel in _controllersOfDistantSessions) { |
977 .get()) { | |
978 DCHECK([panel isKindOfClass:[TabSwitcherPanelController class]]); | 971 DCHECK([panel isKindOfClass:[TabSwitcherPanelController class]]); |
979 if ([panel sessionTag] == tag) { | 972 if ([panel sessionTag] == tag) { |
980 [panel updateCollectionViewIfNeeded]; | 973 [panel updateCollectionViewIfNeeded]; |
981 return; | 974 return; |
982 } | 975 } |
983 } | 976 } |
984 } | 977 } |
985 | 978 |
986 - (void)localSessionMayNeedUpdate:(TabSwitcherSessionType)type { | 979 - (void)localSessionMayNeedUpdate:(TabSwitcherSessionType)type { |
987 if (type == TabSwitcherSessionType::REGULAR_SESSION) { | 980 if (type == TabSwitcherSessionType::REGULAR_SESSION) { |
(...skipping 18 matching lines...) Expand all Loading... |
1006 } else { | 999 } else { |
1007 _shouldAddPromoPanelHeaderCell = YES; | 1000 _shouldAddPromoPanelHeaderCell = YES; |
1008 } | 1001 } |
1009 [self addPromoPanelForSignInPanelType:newPanelType]; | 1002 [self addPromoPanelForSignInPanelType:newPanelType]; |
1010 } | 1003 } |
1011 | 1004 |
1012 - (void)addPromoPanelForSignInPanelType:(TabSwitcherSignInPanelsType)panelType { | 1005 - (void)addPromoPanelForSignInPanelType:(TabSwitcherSignInPanelsType)panelType { |
1013 _signInPanelType = panelType; | 1006 _signInPanelType = panelType; |
1014 if (panelType != TabSwitcherSignInPanelsType::NO_PANEL) { | 1007 if (panelType != TabSwitcherSignInPanelsType::NO_PANEL) { |
1015 TabSwitcherPanelOverlayView* panelView = | 1008 TabSwitcherPanelOverlayView* panelView = |
1016 [[[TabSwitcherPanelOverlayView alloc] initWithFrame:CGRectZero | 1009 [[TabSwitcherPanelOverlayView alloc] initWithFrame:CGRectZero |
1017 browserState:_browserState] | 1010 browserState:_browserState]; |
1018 autorelease]; | |
1019 [panelView setOverlayType:PanelOverlayTypeFromSignInPanelsType(panelType)]; | 1011 [panelView setOverlayType:PanelOverlayTypeFromSignInPanelsType(panelType)]; |
1020 [_tabSwitcherView addPanelView:panelView atIndex:kSignInPromoPanelIndex]; | 1012 [_tabSwitcherView addPanelView:panelView atIndex:kSignInPromoPanelIndex]; |
1021 } | 1013 } |
1022 } | 1014 } |
1023 | 1015 |
1024 - (CGSize)sizeForItemAtIndex:(NSUInteger)index | 1016 - (CGSize)sizeForItemAtIndex:(NSUInteger)index |
1025 inSession:(TabSwitcherSessionType)session { | 1017 inSession:(TabSwitcherSessionType)session { |
1026 switch (session) { | 1018 switch (session) { |
1027 case TabSwitcherSessionType::OFF_THE_RECORD_SESSION: | 1019 case TabSwitcherSessionType::OFF_THE_RECORD_SESSION: |
1028 return [[_offTheRecordSession view] cellSize]; | 1020 return [[_offTheRecordSession view] cellSize]; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1075 if (![_tabSwitcherModel distantSessionCount]) { | 1067 if (![_tabSwitcherModel distantSessionCount]) { |
1076 // Display promo panel cell if there is no distant sessions. | 1068 // Display promo panel cell if there is no distant sessions. |
1077 return [TabSwitcherSessionCellData otherDevicesSessionCellData]; | 1069 return [TabSwitcherSessionCellData otherDevicesSessionCellData]; |
1078 } else { | 1070 } else { |
1079 index -= kHeaderDistantSessionIndexOffset; | 1071 index -= kHeaderDistantSessionIndexOffset; |
1080 | 1072 |
1081 sync_sessions::SyncedSession::DeviceType deviceType = | 1073 sync_sessions::SyncedSession::DeviceType deviceType = |
1082 sync_sessions::SyncedSession::TYPE_UNSET; | 1074 sync_sessions::SyncedSession::TYPE_UNSET; |
1083 NSString* cellTitle = nil; | 1075 NSString* cellTitle = nil; |
1084 | 1076 |
1085 if (index < _controllersOfDistantSessions.get().count) { | 1077 if (index < _controllersOfDistantSessions.count) { |
1086 TabSwitcherPanelController* panel = | 1078 TabSwitcherPanelController* panel = |
1087 [_controllersOfDistantSessions objectAtIndex:index]; | 1079 [_controllersOfDistantSessions objectAtIndex:index]; |
1088 const synced_sessions::DistantSession* distantSession = | 1080 const synced_sessions::DistantSession* distantSession = |
1089 [panel distantSession]; | 1081 [panel distantSession]; |
1090 deviceType = distantSession->device_type; | 1082 deviceType = distantSession->device_type; |
1091 cellTitle = base::SysUTF8ToNSString(distantSession->name); | 1083 cellTitle = base::SysUTF8ToNSString(distantSession->name); |
1092 } | 1084 } |
1093 TabSwitcherSessionCellType cellType; | 1085 TabSwitcherSessionCellType cellType; |
1094 switch (deviceType) { | 1086 switch (deviceType) { |
1095 case sync_sessions::SyncedSession::TYPE_PHONE: | 1087 case sync_sessions::SyncedSession::TYPE_PHONE: |
1096 cellType = kPhoneRemoteSessionCell; | 1088 cellType = kPhoneRemoteSessionCell; |
1097 break; | 1089 break; |
1098 case sync_sessions::SyncedSession::TYPE_TABLET: | 1090 case sync_sessions::SyncedSession::TYPE_TABLET: |
1099 cellType = kTabletRemoteSessionCell; | 1091 cellType = kTabletRemoteSessionCell; |
1100 break; | 1092 break; |
1101 default: | 1093 default: |
1102 cellType = kLaptopRemoteSessionCell; | 1094 cellType = kLaptopRemoteSessionCell; |
1103 break; | 1095 break; |
1104 } | 1096 } |
1105 TabSwitcherSessionCellData* sessionData = | 1097 TabSwitcherSessionCellData* sessionData = |
1106 [[[TabSwitcherSessionCellData alloc] initWithSessionCellType:cellType] | 1098 [[TabSwitcherSessionCellData alloc] initWithSessionCellType:cellType]; |
1107 autorelease]; | |
1108 sessionData.title = cellTitle; | 1099 sessionData.title = cellTitle; |
1109 return sessionData; | 1100 return sessionData; |
1110 } | 1101 } |
1111 } | 1102 } |
1112 } | 1103 } |
1113 | 1104 |
1114 - (NSInteger)tabSwitcherHeaderViewSelectedPanelIndex { | 1105 - (NSInteger)tabSwitcherHeaderViewSelectedPanelIndex { |
1115 return [_tabSwitcherView currentPanelIndex]; | 1106 return [_tabSwitcherView currentPanelIndex]; |
1116 } | 1107 } |
1117 | 1108 |
1118 #pragma mark - TabSwitcherViewDelegate | 1109 #pragma mark - TabSwitcherViewDelegate |
1119 | 1110 |
1120 - (void)openNewTabInPanelAtIndex:(NSInteger)panelIndex { | 1111 - (void)openNewTabInPanelAtIndex:(NSInteger)panelIndex { |
1121 CHECK(panelIndex >= 0); | 1112 CHECK(panelIndex >= 0); |
1122 DCHECK([self isPanelIndexForLocalSession:panelIndex]); | 1113 DCHECK([self isPanelIndexForLocalSession:panelIndex]); |
1123 const NSInteger tag = (panelIndex == kLocalTabsOnTheRecordPanelIndex) | 1114 const NSInteger tag = (panelIndex == kLocalTabsOnTheRecordPanelIndex) |
1124 ? IDC_NEW_TAB | 1115 ? IDC_NEW_TAB |
1125 : IDC_NEW_INCOGNITO_TAB; | 1116 : IDC_NEW_INCOGNITO_TAB; |
1126 if (tag == IDC_NEW_INCOGNITO_TAB) { | 1117 if (tag == IDC_NEW_INCOGNITO_TAB) { |
1127 base::RecordAction( | 1118 base::RecordAction( |
1128 base::UserMetricsAction("MobileTabSwitcherCreateIncognitoTab")); | 1119 base::UserMetricsAction("MobileTabSwitcherCreateIncognitoTab")); |
1129 } else { | 1120 } else { |
1130 base::RecordAction( | 1121 base::RecordAction( |
1131 base::UserMetricsAction("MobileTabSwitcherCreateNonIncognitoTab")); | 1122 base::UserMetricsAction("MobileTabSwitcherCreateNonIncognitoTab")); |
1132 } | 1123 } |
1133 // Create and execute command to create the tab. | 1124 // Create and execute command to create the tab. |
1134 base::scoped_nsobject<GenericChromeCommand> command( | 1125 GenericChromeCommand* command = |
1135 [[GenericChromeCommand alloc] initWithTag:tag]); | 1126 [[GenericChromeCommand alloc] initWithTag:tag]; |
1136 [self chromeExecuteCommand:command]; | 1127 [self chromeExecuteCommand:command]; |
1137 } | 1128 } |
1138 | 1129 |
1139 - (ios_internal::NewTabButtonStyle)buttonStyleForPanelAtIndex: | 1130 - (ios_internal::NewTabButtonStyle)buttonStyleForPanelAtIndex: |
1140 (NSInteger)panelIndex { | 1131 (NSInteger)panelIndex { |
1141 CHECK(panelIndex >= 0); | 1132 CHECK(panelIndex >= 0); |
1142 switch (panelIndex) { | 1133 switch (panelIndex) { |
1143 case kLocalTabsOnTheRecordPanelIndex: | 1134 case kLocalTabsOnTheRecordPanelIndex: |
1144 if ([_onTheRecordSession shouldShowNewTabButton]) { | 1135 if ([_onTheRecordSession shouldShowNewTabButton]) { |
1145 return ios_internal::NewTabButtonStyle::BLUE; | 1136 return ios_internal::NewTabButtonStyle::BLUE; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1225 base::UserMetricsAction("MobileTabSwitcherCloseNonIncognitoTab")); | 1216 base::UserMetricsAction("MobileTabSwitcherCloseNonIncognitoTab")); |
1226 } | 1217 } |
1227 } | 1218 } |
1228 | 1219 |
1229 - (void)tabSwitcherPanelControllerDidUpdateOverlayViewVisibility: | 1220 - (void)tabSwitcherPanelControllerDidUpdateOverlayViewVisibility: |
1230 (TabSwitcherPanelController*)tabSwitcherPanelController { | 1221 (TabSwitcherPanelController*)tabSwitcherPanelController { |
1231 [_tabSwitcherView updateOverlayButtonState]; | 1222 [_tabSwitcherView updateOverlayButtonState]; |
1232 } | 1223 } |
1233 | 1224 |
1234 @end | 1225 @end |
OLD | NEW |