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

Side by Side Diff: ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_controller.mm

Issue 2810193002: [ObjC ARC] Converts ios/chrome/browser/ui/tab_switcher:tab_switcher to ARC. (Closed)
Patch Set: comment Created 3 years, 7 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 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_panel_controller.h" 5 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_controller.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #import "base/mac/foundation_util.h" 8 #import "base/mac/foundation_util.h"
9 #import "base/mac/scoped_nsobject.h"
10 #include "base/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
11 #import "ios/chrome/browser/tabs/tab.h" 10 #import "ios/chrome/browser/tabs/tab.h"
12 #include "ios/chrome/browser/ui/ntp/recent_tabs/synced_sessions.h" 11 #include "ios/chrome/browser/ui/ntp/recent_tabs/synced_sessions.h"
13 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_cache.h" 12 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_cache.h"
14 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_cell.h" 13 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_cell.h"
15 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_overlay_view.h" 14 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_overlay_view.h"
16 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_view.h" 15 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_view.h"
17 #include "ios/chrome/browser/ui/tab_switcher/tab_switcher_session_changes.h" 16 #include "ios/chrome/browser/ui/tab_switcher/tab_switcher_session_changes.h"
18 17
18 #if !defined(__has_feature) || !__has_feature(objc_arc)
19 #error "This file requires ARC support."
20 #endif
21
19 namespace { 22 namespace {
20 23
21 void FillVectorWithHashesUsingDistantSession( 24 void FillVectorWithHashesUsingDistantSession(
22 synced_sessions::DistantSession const& session, 25 synced_sessions::DistantSession const& session,
23 std::vector<size_t>* hashes) { 26 std::vector<size_t>* hashes) {
24 DCHECK(hashes); 27 DCHECK(hashes);
25 DCHECK(hashes->empty()); 28 DCHECK(hashes->empty());
26 for (size_t i = 0; i < session.tabs.size(); ++i) { 29 for (size_t i = 0; i < session.tabs.size(); ++i) {
27 hashes->push_back(session.tabs[i]->hashOfUserVisibleProperties()); 30 hashes->push_back(session.tabs[i]->hashOfUserVisibleProperties());
28 } 31 }
29 } 32 }
30 33
31 } // namespace 34 } // namespace
32 35
33 @interface TabSwitcherPanelController ()<UICollectionViewDataSource, 36 @interface TabSwitcherPanelController ()<UICollectionViewDataSource,
34 UICollectionViewDelegate, 37 UICollectionViewDelegate,
35 SessionCellDelegate> { 38 SessionCellDelegate> {
36 ios::ChromeBrowserState* _browserState; // Weak. 39 ios::ChromeBrowserState* _browserState; // Weak.
37 base::scoped_nsobject<TabSwitcherPanelView> _panelView; 40 TabSwitcherPanelView* _panelView;
38 base::scoped_nsobject<TabSwitcherModel> _model; 41 TabSwitcherModel* _model;
39 std::string _sessionTag; 42 std::string _sessionTag;
40 TabSwitcherSessionType _sessionType; 43 TabSwitcherSessionType _sessionType;
41 base::scoped_nsobject<TabSwitcherCache> _cache; 44 TabSwitcherCache* _cache;
42 base::scoped_nsobject<TabSwitcherPanelOverlayView> _overlayView; 45 TabSwitcherPanelOverlayView* _overlayView;
43 std::unique_ptr<const synced_sessions::DistantSession> _distantSession; 46 std::unique_ptr<const synced_sessions::DistantSession> _distantSession;
44 std::unique_ptr<const TabModelSnapshot> _localSession; 47 std::unique_ptr<const TabModelSnapshot> _localSession;
45 } 48 }
46 49
47 // Changes the visibility of the zero tab state overlay view. 50 // Changes the visibility of the zero tab state overlay view.
48 - (void)setZeroTabStateOverlayVisible:(BOOL)show; 51 - (void)setZeroTabStateOverlayVisible:(BOOL)show;
49 52
50 @end 53 @end
51 54
52 @implementation TabSwitcherPanelController 55 @implementation TabSwitcherPanelController
53 56
54 @synthesize delegate = _delegate; 57 @synthesize delegate = _delegate;
55 @synthesize sessionType = _sessionType; 58 @synthesize sessionType = _sessionType;
56 59
57 - (instancetype)initWithModel:(TabSwitcherModel*)model 60 - (instancetype)initWithModel:(TabSwitcherModel*)model
58 forDistantSessionWithTag:(std::string const&)sessionTag 61 forDistantSessionWithTag:(std::string const&)sessionTag
59 browserState:(ios::ChromeBrowserState*)browserState { 62 browserState:(ios::ChromeBrowserState*)browserState {
60 self = [super init]; 63 self = [super init];
61 if (self) { 64 if (self) {
62 DCHECK(model); 65 DCHECK(model);
63 _sessionType = TabSwitcherSessionType::DISTANT_SESSION; 66 _sessionType = TabSwitcherSessionType::DISTANT_SESSION;
64 _model.reset([model retain]); 67 _model = model;
65 _distantSession = [model distantSessionForTag:sessionTag]; 68 _distantSession = [model distantSessionForTag:sessionTag];
66 _sessionTag = sessionTag; 69 _sessionTag = sessionTag;
67 _browserState = browserState; 70 _browserState = browserState;
68 [self loadView]; 71 [self loadView];
69 } 72 }
70 return self; 73 return self;
71 } 74 }
72 75
73 - (instancetype)initWithModel:(TabSwitcherModel*)model 76 - (instancetype)initWithModel:(TabSwitcherModel*)model
74 forLocalSessionOfType:(TabSwitcherSessionType)sessionType 77 forLocalSessionOfType:(TabSwitcherSessionType)sessionType
75 withCache:(TabSwitcherCache*)cache 78 withCache:(TabSwitcherCache*)cache
76 browserState:(ios::ChromeBrowserState*)browserState { 79 browserState:(ios::ChromeBrowserState*)browserState {
77 self = [super init]; 80 self = [super init];
78 if (self) { 81 if (self) {
79 DCHECK(model); 82 DCHECK(model);
80 _sessionType = sessionType; 83 _sessionType = sessionType;
81 _model.reset([model retain]); 84 _model = model;
82 _localSession = [model tabModelSnapshotForLocalSession:sessionType]; 85 _localSession = [model tabModelSnapshotForLocalSession:sessionType];
83 _cache.reset([cache retain]); 86 _cache = cache;
84 _browserState = browserState; 87 _browserState = browserState;
85 [self loadView]; 88 [self loadView];
86 } 89 }
87 return self; 90 return self;
88 } 91 }
89 92
90 - (TabSwitcherPanelView*)view { 93 - (TabSwitcherPanelView*)view {
91 return _panelView; 94 return _panelView;
92 } 95 }
93 96
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 return _overlayView && [_overlayView alpha] != 0.0; 307 return _overlayView && [_overlayView alpha] != 0.0;
305 } 308 }
306 309
307 - (void)setZeroTabStateOverlayVisible:(BOOL)show { 310 - (void)setZeroTabStateOverlayVisible:(BOOL)show {
308 if (show == [self isOverlayVisible]) 311 if (show == [self isOverlayVisible])
309 return; 312 return;
310 313
311 DCHECK(TabSwitcherSessionTypeIsLocalSession(_sessionType)); 314 DCHECK(TabSwitcherSessionTypeIsLocalSession(_sessionType));
312 315
313 if (!_overlayView) { 316 if (!_overlayView) {
314 _overlayView.reset([[TabSwitcherPanelOverlayView alloc] 317 _overlayView =
315 initWithFrame:[_panelView bounds] 318 [[TabSwitcherPanelOverlayView alloc] initWithFrame:[_panelView bounds]
316 browserState:_browserState]); 319 browserState:_browserState];
317 [_overlayView 320 [_overlayView
318 setOverlayType: 321 setOverlayType:
319 (_sessionType == TabSwitcherSessionType::OFF_THE_RECORD_SESSION) 322 (_sessionType == TabSwitcherSessionType::OFF_THE_RECORD_SESSION)
320 ? TabSwitcherPanelOverlayType:: 323 ? TabSwitcherPanelOverlayType::
321 OVERLAY_PANEL_USER_NO_INCOGNITO_TABS 324 OVERLAY_PANEL_USER_NO_INCOGNITO_TABS
322 : TabSwitcherPanelOverlayType::OVERLAY_PANEL_USER_NO_OPEN_TABS]; 325 : TabSwitcherPanelOverlayType::OVERLAY_PANEL_USER_NO_OPEN_TABS];
323 326
324 [_overlayView setAlpha:0]; 327 [_overlayView setAlpha:0];
325 [_overlayView setAutoresizingMask:UIViewAutoresizingFlexibleHeight | 328 [_overlayView setAutoresizingMask:UIViewAutoresizingFlexibleHeight |
326 UIViewAutoresizingFlexibleWidth]; 329 UIViewAutoresizingFlexibleWidth];
327 [_panelView addSubview:_overlayView]; 330 [_panelView addSubview:_overlayView];
328 [_overlayView setNeedsLayout]; 331 [_overlayView setNeedsLayout];
329 } 332 }
330 333
331 [UIView 334 [UIView
332 animateWithDuration:0.25 335 animateWithDuration:0.25
333 animations:^{ 336 animations:^{
334 [_overlayView setAlpha:show ? 1.0 : 0.0]; 337 [_overlayView setAlpha:show ? 1.0 : 0.0];
335 [self.delegate 338 [self.delegate
336 tabSwitcherPanelControllerDidUpdateOverlayViewVisibility: 339 tabSwitcherPanelControllerDidUpdateOverlayViewVisibility:
337 self]; 340 self];
338 }]; 341 }];
339 } 342 }
340 343
341 - (void)loadView { 344 - (void)loadView {
342 _panelView.reset( 345 _panelView = [[TabSwitcherPanelView alloc] initWithSessionType:_sessionType];
343 [[TabSwitcherPanelView alloc] initWithSessionType:_sessionType]); 346 _panelView.collectionView.dataSource = self;
344 _panelView.get().collectionView.dataSource = self; 347 _panelView.collectionView.delegate = self;
345 _panelView.get().collectionView.delegate = self;
346 } 348 }
347 349
348 - (synced_sessions::DistantSession const*)distantSession { 350 - (synced_sessions::DistantSession const*)distantSession {
349 return _distantSession.get(); 351 return _distantSession.get();
350 } 352 }
351 353
352 @end 354 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698