| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/bookmarks/bookmark_folder_collection_view.h" | 5 #import "ios/chrome/browser/ui/bookmarks/bookmark_folder_collection_view.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/mac/objc_property_releaser.h" |
| 8 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 9 #include "components/bookmarks/browser/bookmark_model.h" | 10 #include "components/bookmarks/browser/bookmark_model.h" |
| 10 #include "ios/chrome/browser/bookmarks/bookmarks_utils.h" | 11 #include "ios/chrome/browser/bookmarks/bookmarks_utils.h" |
| 11 #include "ios/chrome/browser/experimental_flags.h" | 12 #include "ios/chrome/browser/experimental_flags.h" |
| 12 #import "ios/chrome/browser/ui/bookmarks/bookmark_collection_cells.h" | 13 #import "ios/chrome/browser/ui/bookmarks/bookmark_collection_cells.h" |
| 13 #import "ios/chrome/browser/ui/bookmarks/bookmark_promo_cell.h" | 14 #import "ios/chrome/browser/ui/bookmarks/bookmark_promo_cell.h" |
| 14 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" | 15 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" |
| 15 | 16 |
| 16 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 17 #error "This file requires ARC support." | |
| 18 #endif | |
| 19 | |
| 20 using bookmarks::BookmarkNode; | 17 using bookmarks::BookmarkNode; |
| 21 | 18 |
| 22 @interface BookmarkFolderCollectionView ()<BookmarkPromoCellDelegate> { | 19 @interface BookmarkFolderCollectionView ()<BookmarkPromoCellDelegate> { |
| 20 base::mac::ObjCPropertyReleaser |
| 21 _propertyReleaser_BookmarkFolderCollectionView; |
| 23 // A vector of folders to display in the collection view. | 22 // A vector of folders to display in the collection view. |
| 24 std::vector<const BookmarkNode*> _subFolders; | 23 std::vector<const BookmarkNode*> _subFolders; |
| 25 // A vector of bookmark urls to display in the collection view. | 24 // A vector of bookmark urls to display in the collection view. |
| 26 std::vector<const BookmarkNode*> _subItems; | 25 std::vector<const BookmarkNode*> _subItems; |
| 27 | 26 |
| 28 // True if the promo is visible. | 27 // True if the promo is visible. |
| 29 BOOL _promoVisible; | 28 BOOL _promoVisible; |
| 30 } | 29 } |
| 31 @property(nonatomic, assign) const bookmarks::BookmarkNode* folder; | 30 @property(nonatomic, assign) const bookmarks::BookmarkNode* folder; |
| 32 | 31 |
| 33 // Section indices. | 32 // Section indices. |
| 34 @property(nonatomic, readonly, assign) NSInteger promoSection; | 33 @property(nonatomic, readonly, assign) NSInteger promoSection; |
| 35 @property(nonatomic, readonly, assign) NSInteger folderSection; | 34 @property(nonatomic, readonly, assign) NSInteger folderSection; |
| 36 @property(nonatomic, readonly, assign) NSInteger itemsSection; | 35 @property(nonatomic, readonly, assign) NSInteger itemsSection; |
| 37 @property(nonatomic, readonly, assign) NSInteger sectionCount; | 36 @property(nonatomic, readonly, assign) NSInteger sectionCount; |
| 38 | 37 |
| 39 // Keep a reference to the promo cell to deregister as delegate. | 38 // Keep a reference to the promo cell to deregister as delegate. |
| 40 @property(nonatomic, strong) BookmarkPromoCell* promoCell; | 39 @property(nonatomic, retain) BookmarkPromoCell* promoCell; |
| 41 | 40 |
| 42 @end | 41 @end |
| 43 | 42 |
| 44 @implementation BookmarkFolderCollectionView | 43 @implementation BookmarkFolderCollectionView |
| 45 @synthesize delegate = _delegate; | 44 @synthesize delegate = _delegate; |
| 46 @synthesize folder = _folder; | 45 @synthesize folder = _folder; |
| 47 @synthesize promoCell = _promoCell; | 46 @synthesize promoCell = _promoCell; |
| 48 | 47 |
| 49 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState | 48 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState |
| 50 frame:(CGRect)frame { | 49 frame:(CGRect)frame { |
| 51 self = [super initWithBrowserState:browserState frame:frame]; | 50 self = [super initWithBrowserState:browserState frame:frame]; |
| 52 if (self) { | 51 if (self) { |
| 52 _propertyReleaser_BookmarkFolderCollectionView.Init( |
| 53 self, [BookmarkFolderCollectionView class]); |
| 54 |
| 53 [self updateCollectionView]; | 55 [self updateCollectionView]; |
| 54 } | 56 } |
| 55 return self; | 57 return self; |
| 56 } | 58 } |
| 57 | 59 |
| 58 - (void)dealloc { | 60 - (void)dealloc { |
| 59 _promoCell.delegate = nil; | 61 _promoCell.delegate = nil; |
| 62 [super dealloc]; |
| 60 } | 63 } |
| 61 | 64 |
| 62 - (void)setDelegate:(id<BookmarkFolderCollectionViewDelegate>)delegate { | 65 - (void)setDelegate:(id<BookmarkFolderCollectionViewDelegate>)delegate { |
| 63 _delegate = delegate; | 66 _delegate = delegate; |
| 64 [self promoStateChangedAnimated:NO]; | 67 [self promoStateChangedAnimated:NO]; |
| 65 } | 68 } |
| 66 | 69 |
| 67 - (NSInteger)promoSection { | 70 - (NSInteger)promoSection { |
| 68 return [self shouldShowPromoCell] ? 0 : -1; | 71 return [self shouldShowPromoCell] ? 0 : -1; |
| 69 } | 72 } |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 [self.delegate bookmarkCollectionViewDismissPromo:self]; | 462 [self.delegate bookmarkCollectionViewDismissPromo:self]; |
| 460 } | 463 } |
| 461 | 464 |
| 462 #pragma mark - Promo Cell | 465 #pragma mark - Promo Cell |
| 463 | 466 |
| 464 - (BOOL)shouldShowPromoCell { | 467 - (BOOL)shouldShowPromoCell { |
| 465 return _promoVisible; | 468 return _promoVisible; |
| 466 } | 469 } |
| 467 | 470 |
| 468 @end | 471 @end |
| OLD | NEW |