OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_view.h" |
| 6 |
| 7 #import "base/mac/scoped_nsobject.h" |
| 8 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_cell.h" |
| 9 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_collection_view_l
ayout.h" |
| 10 |
| 11 @interface TabSwitcherPanelView () { |
| 12 base::scoped_nsobject<UICollectionView> _collectionView; |
| 13 base::scoped_nsobject<TabSwitcherPanelCollectionViewLayout> |
| 14 _collectionViewLayout; |
| 15 ios_internal::SessionType _sessionType; |
| 16 } |
| 17 |
| 18 @end |
| 19 |
| 20 @implementation TabSwitcherPanelView |
| 21 |
| 22 - (instancetype)initWithSessionType:(ios_internal::SessionType)sessionType { |
| 23 self = [super initWithFrame:CGRectZero]; |
| 24 if (self) { |
| 25 _sessionType = sessionType; |
| 26 [self loadSubviews]; |
| 27 } |
| 28 return self; |
| 29 } |
| 30 |
| 31 - (instancetype)initWithFrame:(CGRect)frame { |
| 32 NOTREACHED(); |
| 33 return nil; |
| 34 } |
| 35 |
| 36 - (instancetype)initWithCoder:(NSCoder*)aDecoder { |
| 37 NOTREACHED(); |
| 38 return nil; |
| 39 } |
| 40 |
| 41 - (UICollectionView*)collectionView { |
| 42 return _collectionView; |
| 43 } |
| 44 |
| 45 - (void)updateCollectionLayoutWithCompletion:(void (^)(void))completion { |
| 46 [_collectionView performBatchUpdates:nil |
| 47 completion:^(BOOL) { |
| 48 if (completion) |
| 49 completion(); |
| 50 }]; |
| 51 } |
| 52 |
| 53 - (CGSize)cellSize { |
| 54 return [_collectionViewLayout itemSize]; |
| 55 } |
| 56 |
| 57 #pragma mark - Private |
| 58 |
| 59 - (void)loadSubviews { |
| 60 _collectionViewLayout.reset( |
| 61 [[TabSwitcherPanelCollectionViewLayout alloc] init]); |
| 62 _collectionView.reset([[UICollectionView alloc] |
| 63 initWithFrame:self.bounds |
| 64 collectionViewLayout:_collectionViewLayout.get()]); |
| 65 if (_sessionType == ios_internal::SessionType::DISTANT_SESSION) { |
| 66 [_collectionView registerClass:[TabSwitcherDistantSessionCell class] |
| 67 forCellWithReuseIdentifier:[TabSwitcherDistantSessionCell identifier]]; |
| 68 } else { |
| 69 [_collectionView registerClass:[TabSwitcherLocalSessionCell class] |
| 70 forCellWithReuseIdentifier:[TabSwitcherLocalSessionCell identifier]]; |
| 71 } |
| 72 [_collectionView setBackgroundColor:[UIColor clearColor]]; |
| 73 [self addSubview:_collectionView]; |
| 74 [_collectionView setAutoresizingMask:UIViewAutoresizingFlexibleHeight | |
| 75 UIViewAutoresizingFlexibleWidth]; |
| 76 } |
| 77 |
| 78 @end |
OLD | NEW |