| 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 #ifndef IOS_CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_COLLECTION_VIEW_H_ | 5 #ifndef IOS_CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_COLLECTION_VIEW_H_ |
| 6 #define IOS_CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_COLLECTION_VIEW_H_ | 6 #define IOS_CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_COLLECTION_VIEW_H_ |
| 7 | 7 |
| 8 #import <UIKit/UIKit.h> | 8 #import <UIKit/UIKit.h> |
| 9 | 9 |
| 10 #include <set> | 10 #include <set> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #import "ios/chrome/browser/ui/bookmarks/bookmark_collection_cells.h" | 13 #import "ios/chrome/browser/ui/bookmarks/bookmark_collection_cells.h" |
| 14 #import "ios/chrome/browser/ui/bookmarks/bookmark_home_primary_view.h" | 14 #import "ios/chrome/browser/ui/bookmarks/bookmark_home_primary_view.h" |
| 15 #include "ios/chrome/browser/ui/bookmarks/bookmark_model_bridge_observer.h" | 15 #include "ios/chrome/browser/ui/bookmarks/bookmark_model_bridge_observer.h" |
| 16 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" | 16 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" |
| 17 | 17 |
| 18 @class BookmarkCollectionView; | 18 @class BookmarkCollectionView; |
| 19 class GURL; | 19 class GURL; |
| 20 @protocol UrlLoader; | 20 @protocol UrlLoader; |
| 21 | 21 |
| 22 namespace bookmarks { | 22 namespace bookmarks { |
| 23 class BookmarkModel; | |
| 24 class BookmarkNode; | 23 class BookmarkNode; |
| 25 } // namespace bookmarks | 24 } // namespace bookmarks |
| 26 | 25 |
| 27 namespace ios { | |
| 28 class ChromeBrowserState; | |
| 29 } // namespace ios | |
| 30 | |
| 31 // This protocol is provided for subclasses, and is not used in this class. | |
| 32 @protocol BookmarkCollectionViewDelegate<NSObject> | 26 @protocol BookmarkCollectionViewDelegate<NSObject> |
| 33 | 27 |
| 34 // This method tells the delegate to add the node and cell | 28 // This method tells the delegate to add the node and cell |
| 35 // to the list of those being edited. | 29 // to the list of those being edited. |
| 36 - (void)bookmarkCollectionView:(BookmarkCollectionView*)view | 30 - (void)bookmarkCollectionView:(BookmarkCollectionView*)view |
| 37 cell:(UICollectionViewCell*)cell | 31 cell:(UICollectionViewCell*)cell |
| 38 addNodeForEditing:(const bookmarks::BookmarkNode*)node; | 32 addNodeForEditing:(const bookmarks::BookmarkNode*)node; |
| 39 | 33 |
| 40 // This method tells the delegate to remove the node and cell from the list of | 34 // This method tells the delegate to remove the node and cell from the list of |
| 41 // those being edited. | 35 // those being edited. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 64 | 58 |
| 65 // Returns true if a bookmarks promo cell should be shown. | 59 // Returns true if a bookmarks promo cell should be shown. |
| 66 - (BOOL)bookmarkCollectionViewShouldShowPromoCell:(BookmarkCollectionView*)view; | 60 - (BOOL)bookmarkCollectionViewShouldShowPromoCell:(BookmarkCollectionView*)view; |
| 67 | 61 |
| 68 // Shows a sign-in view controller. | 62 // Shows a sign-in view controller. |
| 69 - (void)bookmarkCollectionViewShowSignIn:(BookmarkCollectionView*)view; | 63 - (void)bookmarkCollectionViewShowSignIn:(BookmarkCollectionView*)view; |
| 70 | 64 |
| 71 // Dismisses the promo. | 65 // Dismisses the promo. |
| 72 - (void)bookmarkCollectionViewDismissPromo:(BookmarkCollectionView*)view; | 66 - (void)bookmarkCollectionViewDismissPromo:(BookmarkCollectionView*)view; |
| 73 | 67 |
| 68 // Tells the delegate that a folder was selected for navigation. |
| 69 - (void)bookmarkCollectionView:(BookmarkCollectionView*)view |
| 70 selectedFolderForNavigation:(const bookmarks::BookmarkNode*)folder; |
| 74 @end | 71 @end |
| 75 | 72 |
| 76 // This is an abstract class. | 73 // Shows all sub-folders and sub-urls of a folder node in a collection view. |
| 77 // It contains a collection view specific to bookmarks. | 74 // Note: This class intentionally does not try to maintain state through a |
| 78 // This class is responsible for the UI of the collection view. | 75 // folder transition. Depending on the type of animation that the designers |
| 79 // Subclasses are responsible for handling the model layer. | 76 // choose, we may require multiple instances of this view. |
| 80 // | |
| 81 // Note about the implementation of the |BookmarkHomePrimaryView| in this class: | 77 // Note about the implementation of the |BookmarkHomePrimaryView| in this class: |
| 82 // * |contentPositionInPortraitOrientation|: Regardless of the current | 78 // * |contentPositionInPortraitOrientation|: Regardless of the current |
| 83 // orientation, returns the y of the content offset of the collection view | 79 // orientation, returns the y of the content offset of the collection view |
| 84 // if it were to have portrait orientation. | 80 // if it were to have portrait orientation. |
| 85 // * |applyContentPosition:|: Given a content position from portrait | 81 // * |applyContentPosition:|: Given a content position from portrait |
| 86 // orientation, change the content offset of the collection view to match | 82 // orientation, change the content offset of the collection view to match |
| 87 // that position. | 83 // that position. |
| 88 // * |changeOrientation:|: Calls |updateCollectionView|. | 84 // * |changeOrientation:|: Calls |updateCollectionView|. |
| 89 // * |setScrollsToTop:|: Applies |scrollsToTop| to the collection view. | 85 // * |setScrollsToTop:|: Applies |scrollsToTop| to the collection view. |
| 90 // * |setEditing:animated:|: This method updates the editing property, but has | 86 // * |setEditing:animated:|: This method updates the editing property, but has |
| 91 // no other effect. Subclasses must provide the actual functionality. | 87 // no other effect. Subclasses must provide the actual functionality. |
| 92 @interface BookmarkCollectionView | 88 @interface BookmarkCollectionView |
| 93 : UIView<BookmarkHomePrimaryView, BookmarkModelBridgeObserver> | 89 : UIView<BookmarkHomePrimaryView, BookmarkModelBridgeObserver> |
| 94 | 90 |
| 95 // Designated initializer. | 91 // Designated initializer. |
| 96 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState | 92 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState |
| 97 frame:(CGRect)frame; | 93 frame:(CGRect)frame; |
| 98 | 94 |
| 99 #pragma mark - Methods that subclasses can override | |
| 100 | |
| 101 // Callback whenever the collection view is scrolled. | 95 // Callback whenever the collection view is scrolled. |
| 102 - (void)collectionViewScrolled; | 96 - (void)collectionViewScrolled; |
| 103 | 97 |
| 104 #pragma mark - Methods that subclasses must override (non-UI) | 98 // Refreshes the entire view to reflect |folder|. |
| 99 - (void)resetFolder:(const bookmarks::BookmarkNode*)folder; |
| 105 | 100 |
| 106 // BookmarkModelBridgeObserver Callbacks | 101 // Called when something outside the view causes the promo state to change. |
| 107 // Instances of this class automatically observe the bookmark model. | 102 - (void)promoStateChangedAnimated:(BOOL)animate; |
| 108 // The bookmark model has loaded. | |
| 109 - (void)bookmarkModelLoaded; | |
| 110 // The node has changed, but not its children. | |
| 111 - (void)bookmarkNodeChanged:(const bookmarks::BookmarkNode*)bookmarkNode; | |
| 112 // The node has not changed, but its children have. | |
| 113 - (void)bookmarkNodeChildrenChanged: | |
| 114 (const bookmarks::BookmarkNode*)bookmarkNode; | |
| 115 // The node has moved to a new parent folder. | |
| 116 - (void)bookmarkNode:(const bookmarks::BookmarkNode*)bookmarkNode | |
| 117 movedFromParent:(const bookmarks::BookmarkNode*)oldParent | |
| 118 toParent:(const bookmarks::BookmarkNode*)newParent; | |
| 119 // |node| was deleted from |folder|. | |
| 120 - (void)bookmarkNodeDeleted:(const bookmarks::BookmarkNode*)node | |
| 121 fromFolder:(const bookmarks::BookmarkNode*)folder; | |
| 122 // All non-permanent nodes have been removed. | |
| 123 - (void)bookmarkModelRemovedAllNodes; | |
| 124 | |
| 125 // Called when a user is attempting to select a cell. | |
| 126 // Returning NO prevents the cell from being selected. | |
| 127 - (BOOL)shouldSelectCellAtIndexPath:(NSIndexPath*)indexPath; | |
| 128 // Called when a cell is tapped outside of editing mode. | |
| 129 - (void)didTapCellAtIndexPath:(NSIndexPath*)indexPath; | |
| 130 // Called when a user selected a cell in the editing state. | |
| 131 - (void)didAddCellForEditingAtIndexPath:(NSIndexPath*)indexPath; | |
| 132 - (void)didRemoveCellForEditingAtIndexPath:(NSIndexPath*)indexPath; | |
| 133 // Called when a user taps the menu button on a cell. | |
| 134 - (void)didTapMenuButtonAtIndexPath:(NSIndexPath*)indexPath | |
| 135 onView:(UIView*)view | |
| 136 forCell:(BookmarkItemCell*)cell; | |
| 137 | |
| 138 // Whether a cell should show a button and of which type. | |
| 139 - (bookmark_cell::ButtonType)buttonTypeForCellAtIndexPath: | |
| 140 (NSIndexPath*)indexPath; | |
| 141 | |
| 142 // Whether a long press at the cell at |indexPath| should be allowed. | |
| 143 - (BOOL)allowLongPressForCellAtIndexPath:(NSIndexPath*)indexPath; | |
| 144 // The |cell| at |indexPath| received a long press. | |
| 145 - (void)didLongPressCell:(UICollectionViewCell*)cell | |
| 146 atIndexPath:(NSIndexPath*)indexPath; | |
| 147 | |
| 148 // Whether the cell has been selected in editing mode. | |
| 149 - (BOOL)cellIsSelectedForEditingAtIndexPath:(NSIndexPath*)indexPath; | |
| 150 | |
| 151 // Updates the collection view based on the current state of all models and | |
| 152 // contextual parameters, such as the interface orientation. | |
| 153 - (void)updateCollectionView; | |
| 154 | |
| 155 // Returns the bookmark node associated with |indexPath|. | |
| 156 - (const bookmarks::BookmarkNode*)nodeAtIndexPath:(NSIndexPath*)indexPath; | |
| 157 | |
| 158 #pragma mark - Methods that subclasses must override (UI) | |
| 159 | |
| 160 // The size of the header for |section|. A return value of CGSizeZero prevents | |
| 161 // a header from showing. | |
| 162 - (CGSize)headerSizeForSection:(NSInteger)section; | |
| 163 // Create a cell for display at |indexPath|. | |
| 164 - (UICollectionViewCell*)cellAtIndexPath:(NSIndexPath*)indexPath; | |
| 165 // Create a header view for the element at |indexPath|. | |
| 166 - (UICollectionReusableView*)headerAtIndexPath:(NSIndexPath*)indexPath; | |
| 167 - (NSInteger)numberOfItemsInSection:(NSInteger)section; | |
| 168 - (NSInteger)numberOfSections; | |
| 169 | |
| 170 #pragma mark - Methods that subclasses can override (UI) | |
| 171 | |
| 172 // The inset of the section. | |
| 173 - (UIEdgeInsets)insetForSectionAtIndex:(NSInteger)section; | |
| 174 // The size of the cell at |indexPath|. | |
| 175 - (CGSize)cellSizeForIndexPath:(NSIndexPath*)indexPath; | |
| 176 // The minimal horizontal space between items to respect between cells in | |
| 177 // |section|. | |
| 178 - (CGFloat)minimumInteritemSpacingForSectionAtIndex:(NSInteger)section; | |
| 179 // The minimal vertical space between items to respect between cells in | |
| 180 // |section|. | |
| 181 - (CGFloat)minimumLineSpacingForSectionAtIndex:(NSInteger)section; | |
| 182 // The text to display when there are no items in the collection. Default is | |
| 183 // |IDS_IOS_BOOKMARK_NO_BOOKMARKS_LABEL|. | |
| 184 - (NSString*)textWhenCollectionIsEmpty; | |
| 185 | |
| 186 #pragma mark - Convenience methods for subclasses | |
| 187 | |
| 188 - (BookmarkItemCell*)cellForBookmark:(const bookmarks::BookmarkNode*)node | |
| 189 indexPath:(NSIndexPath*)indexPath; | |
| 190 - (BookmarkFolderCell*)cellForFolder:(const bookmarks::BookmarkNode*)node | |
| 191 indexPath:(NSIndexPath*)indexPath; | |
| 192 | |
| 193 // |animateMenuVisibility| refers to whether the change in the visibility of the | |
| 194 // menu button is animated. | |
| 195 // |animateSelectedState| refers to whether the change in the selected state (in | |
| 196 // editing mode) of the cell is animated. | |
| 197 // This method updates the visibility of the menu button. | |
| 198 // This method updates the selected state of the cell (in editing mode). | |
| 199 - (void)updateEditingStateOfCellAtIndexPath:(NSIndexPath*)indexPath | |
| 200 animateMenuVisibility:(BOOL)animateMenuVisibility | |
| 201 animateSelectedState:(BOOL)animateSelectedState; | |
| 202 | |
| 203 // Cancels all async loads of favicons. Subclasses should call this method when | |
| 204 // the bookmark model is going through significant changes, then manually call | |
| 205 // loadFaviconAtIndexPath: for everything that needs to be loaded; or | |
| 206 // just reload relevant cells. | |
| 207 - (void)cancelAllFaviconLoads; | |
| 208 | |
| 209 // Asynchronously loads favicon for given index path. The loads are cancelled | |
| 210 // upon cell reuse automatically. | |
| 211 - (void)loadFaviconAtIndexPath:(NSIndexPath*)indexPath; | |
| 212 | |
| 213 #pragma mark - Commonly used properties | |
| 214 | 103 |
| 215 @property(nonatomic, assign, readonly) bookmarks::BookmarkModel* bookmarkModel; | 104 @property(nonatomic, assign, readonly) bookmarks::BookmarkModel* bookmarkModel; |
| 216 @property(nonatomic, weak, readonly) id<UrlLoader> loader; | 105 @property(nonatomic, weak, readonly) id<UrlLoader> loader; |
| 217 @property(nonatomic, assign, readonly) ios::ChromeBrowserState* browserState; | 106 @property(nonatomic, assign, readonly) ios::ChromeBrowserState* browserState; |
| 107 @property(nonatomic, weak) id<BookmarkCollectionViewDelegate> delegate; |
| 108 @property(nonatomic, assign, readonly) const bookmarks::BookmarkNode* folder; |
| 218 | 109 |
| 219 #pragma mark - Editing | 110 #pragma mark - Editing |
| 220 | 111 |
| 221 @property(nonatomic, assign, readonly) BOOL editing; | 112 @property(nonatomic, assign, readonly) BOOL editing; |
| 222 | 113 |
| 223 #pragma mark - Promo Cell | 114 #pragma mark - Promo Cell |
| 224 | 115 |
| 225 // Return true if the section at the given index is a promo section. | 116 // Return true if the section at the given index is a promo section. |
| 226 - (BOOL)isPromoSection:(NSInteger)section; | 117 - (BOOL)isPromoSection:(NSInteger)section; |
| 227 - (BOOL)shouldShowPromoCell; | 118 - (BOOL)shouldShowPromoCell; |
| 228 - (BOOL)isPromoActive; | 119 - (BOOL)isPromoActive; |
| 229 | 120 |
| 230 @end | 121 @end |
| 231 | 122 |
| 232 #endif // IOS_CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_COLLECTION_VIEW_H_ | 123 #endif // IOS_CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_COLLECTION_VIEW_H_ |
| OLD | NEW |