| 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_all_collection_view.h" | 5 #import "ios/chrome/browser/ui/bookmarks/bookmark_all_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/mac/objc_release_properties.h" |
| 9 #include "base/mac/scoped_nsobject.h" | 9 #include "base/mac/scoped_nsobject.h" |
| 10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| 11 #include "components/bookmarks/browser/bookmark_model.h" | 11 #include "components/bookmarks/browser/bookmark_model.h" |
| 12 #include "ios/chrome/browser/bookmarks/bookmarks_utils.h" | 12 #include "ios/chrome/browser/bookmarks/bookmarks_utils.h" |
| 13 #import "ios/chrome/browser/ui/bookmarks/bookmark_collection_cells.h" | 13 #import "ios/chrome/browser/ui/bookmarks/bookmark_collection_cells.h" |
| 14 #include "ios/chrome/browser/ui/bookmarks/bookmark_promo_cell.h" | 14 #include "ios/chrome/browser/ui/bookmarks/bookmark_promo_cell.h" |
| 15 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" | 15 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
| 17 #include "ui/base/models/tree_node_iterator.h" | 17 #include "ui/base/models/tree_node_iterator.h" |
| 18 | 18 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 34 // This enum tracks the state of the refresh. See -collectionViewNeedsUpdate | 34 // This enum tracks the state of the refresh. See -collectionViewNeedsUpdate |
| 35 // for the state machine. | 35 // for the state machine. |
| 36 typedef enum { kNoUpdate = 0, kOneUpdateDone, kUpdateScheduled } UpdateState; | 36 typedef enum { kNoUpdate = 0, kOneUpdateDone, kUpdateScheduled } UpdateState; |
| 37 } // namespace | 37 } // namespace |
| 38 | 38 |
| 39 @interface BookmarkAllCollectionView ()<BookmarkPromoCellDelegate> { | 39 @interface BookmarkAllCollectionView ()<BookmarkPromoCellDelegate> { |
| 40 // A vector of vectors. Url nodes are segregated by month of creation. | 40 // A vector of vectors. Url nodes are segregated by month of creation. |
| 41 ScopedVector<NodesSection> _nodesSectionVector; | 41 ScopedVector<NodesSection> _nodesSectionVector; |
| 42 // To avoid refreshing the internal model too often. | 42 // To avoid refreshing the internal model too often. |
| 43 UpdateState _updateScheduled; | 43 UpdateState _updateScheduled; |
| 44 base::mac::ObjCPropertyReleaser _propertyReleaser_BookmarkAllCollectionView; | |
| 45 } | 44 } |
| 46 | 45 |
| 47 // Keep a reference to the promo cell to deregister as delegate. | 46 // Keep a reference to the promo cell to deregister as delegate. |
| 48 @property(nonatomic, retain) BookmarkPromoCell* promoCell; | 47 @property(nonatomic, retain) BookmarkPromoCell* promoCell; |
| 49 | 48 |
| 50 // Triggers an update of the collection, but delayed in order to coallesce a lot | 49 // Triggers an update of the collection, but delayed in order to coallesce a lot |
| 51 // of events into one update. | 50 // of events into one update. |
| 52 - (void)collectionViewNeedsUpdate; | 51 - (void)collectionViewNeedsUpdate; |
| 53 | 52 |
| 54 @end | 53 @end |
| 55 | 54 |
| 56 @implementation BookmarkAllCollectionView | 55 @implementation BookmarkAllCollectionView |
| 57 | 56 |
| 58 @synthesize delegate = _delegate; | 57 @synthesize delegate = _delegate; |
| 59 @synthesize promoCell = _promoCell; | 58 @synthesize promoCell = _promoCell; |
| 60 | 59 |
| 61 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState | 60 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState |
| 62 frame:(CGRect)frame { | 61 frame:(CGRect)frame { |
| 63 self = [super initWithBrowserState:browserState frame:frame]; | 62 self = [super initWithBrowserState:browserState frame:frame]; |
| 64 if (self) { | 63 if (self) { |
| 65 _propertyReleaser_BookmarkAllCollectionView.Init( | |
| 66 self, [BookmarkAllCollectionView class]); | |
| 67 self.accessibilityIdentifier = @"bookmark_all_collection_view"; | 64 self.accessibilityIdentifier = @"bookmark_all_collection_view"; |
| 68 [self updateCollectionView]; | 65 [self updateCollectionView]; |
| 69 } | 66 } |
| 70 return self; | 67 return self; |
| 71 } | 68 } |
| 72 | 69 |
| 73 - (void)dealloc { | 70 - (void)dealloc { |
| 74 _promoCell.delegate = nil; | 71 _promoCell.delegate = nil; |
| 72 base::mac::ReleaseProperties(self); |
| 75 [super dealloc]; | 73 [super dealloc]; |
| 76 } | 74 } |
| 77 | 75 |
| 78 - (void)updateCollectionView { | 76 - (void)updateCollectionView { |
| 79 if (!self.bookmarkModel->loaded()) | 77 if (!self.bookmarkModel->loaded()) |
| 80 return; | 78 return; |
| 81 | 79 |
| 82 // Regenerate the list of all bookmarks. | 80 // Regenerate the list of all bookmarks. |
| 83 NodeVector allItems; | 81 NodeVector allItems; |
| 84 ui::TreeNodeIterator<const BookmarkNode> iterator( | 82 ui::TreeNodeIterator<const BookmarkNode> iterator( |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 - (BOOL)isPromoActive { | 403 - (BOOL)isPromoActive { |
| 406 return [self.delegate bookmarkCollectionViewShouldShowPromoCell:self]; | 404 return [self.delegate bookmarkCollectionViewShouldShowPromoCell:self]; |
| 407 } | 405 } |
| 408 | 406 |
| 409 - (BOOL)shouldShowPromoCell { | 407 - (BOOL)shouldShowPromoCell { |
| 410 // The promo cell is not shown in edit mode. | 408 // The promo cell is not shown in edit mode. |
| 411 return !self.editing && [self isPromoActive]; | 409 return !self.editing && [self isPromoActive]; |
| 412 } | 410 } |
| 413 | 411 |
| 414 @end | 412 @end |
| OLD | NEW |