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

Side by Side Diff: ios/chrome/browser/ui/bookmarks/bookmark_collection_view.h

Issue 2586993002: Upstream Chrome on iOS source code [3/11]. (Closed)
Patch Set: Created 4 years 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef IOS_CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_COLLECTION_VIEW_H_
6 #define IOS_CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_COLLECTION_VIEW_H_
7
8 #import <UIKit/UIKit.h>
9
10 #include <set>
11 #include <vector>
12
13 #import "ios/chrome/browser/ui/bookmarks/bookmark_collection_cells.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"
16 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h"
17
18 @class BookmarkCollectionView;
19 class GURL;
20 @protocol UrlLoader;
21
22 namespace bookmarks {
23 class BookmarkModel;
24 class BookmarkNode;
25 } // namespace bookmarks
26
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>
33
34 // This method tells the delegate to add the node and cell
35 // to the list of those being edited.
36 - (void)bookmarkCollectionView:(BookmarkCollectionView*)view
37 cell:(UICollectionViewCell*)cell
38 addNodeForEditing:(const bookmarks::BookmarkNode*)node;
39
40 // This method tells the delegate to remove the node and cell from the list of
41 // those being edited.
42 - (void)bookmarkCollectionView:(BookmarkCollectionView*)view
43 cell:(UICollectionViewCell*)cell
44 removeNodeForEditing:(const bookmarks::BookmarkNode*)node;
45
46 // The delegate is responsible for keeping track of the nodes being edited.
47 - (const std::set<const bookmarks::BookmarkNode*>&)nodesBeingEdited;
48
49 // This method tells the delegate that the collection view was scrolled.
50 - (void)bookmarkCollectionViewDidScroll:(BookmarkCollectionView*)view;
51 - (void)bookmarkCollectionView:(BookmarkCollectionView*)view
52 selectedUrlForNavigation:(const GURL&)url;
53
54 // The user selected the menu button at the index path.
55 - (void)bookmarkCollectionView:(BookmarkCollectionView*)view
56 wantsMenuForBookmark:(const bookmarks::BookmarkNode*)node
57 onView:(UIView*)view
58 forCell:(BookmarkItemCell*)cell;
59
60 // The user performed a long press on the bookmark.
61 - (void)bookmarkCollectionView:(BookmarkCollectionView*)view
62 didLongPressCell:(UICollectionViewCell*)cell
63 forBookmark:(const bookmarks::BookmarkNode*)node;
64
65 // Returns true if a bookmarks promo cell should be shown.
66 - (BOOL)bookmarkCollectionViewShouldShowPromoCell:(BookmarkCollectionView*)view;
67
68 // Shows a sign-in view controller.
69 - (void)bookmarkCollectionViewShowSignIn:(BookmarkCollectionView*)view;
70
71 // Dismisses the promo.
72 - (void)bookmarkCollectionViewDismissPromo:(BookmarkCollectionView*)view;
73
74 @end
75
76 // This is an abstract class.
77 // It contains a collection view specific to bookmarks.
78 // This class is responsible for the UI of the collection view.
79 // Subclasses are responsible for handling the model layer.
80 //
81 // Note about the implementation of the |BookmarkHomePrimaryView| in this class:
82 // * |contentPositionInPortraitOrientation|: Regardless of the current
83 // orientation, returns the y of the content offset of the collection view
84 // if it were to have portrait orientation.
85 // * |applyContentPosition:|: Given a content position from portrait
86 // orientation, change the content offset of the collection view to match
87 // that position.
88 // * |changeOrientation:|: Calls |updateCollectionView|.
89 // * |setScrollsToTop:|: Applies |scrollsToTop| to the collection view.
90 // * |setEditing:animated:|: This method updates the editing property, but has
91 // no other effect. Subclasses must provide the actual functionality.
92 @interface BookmarkCollectionView
93 : UIView<BookmarkHomePrimaryView, BookmarkModelBridgeObserver>
94
95 // Designated initializer.
96 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState
97 frame:(CGRect)frame;
98
99 #pragma mark - Methods that subclasses can override
100
101 // Callback whenever the collection view is scrolled.
102 - (void)collectionViewScrolled;
103
104 #pragma mark - Methods that subclasses must override (non-UI)
105
106 // BookmarkModelBridgeObserver Callbacks
107 // Instances of this class automatically observe the bookmark model.
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
215 @property(nonatomic, assign, readonly) bookmarks::BookmarkModel* bookmarkModel;
216 @property(nonatomic, assign, readonly) id<UrlLoader> loader;
217 @property(nonatomic, assign, readonly) ios::ChromeBrowserState* browserState;
218
219 #pragma mark - Editing
220
221 @property(nonatomic, assign, readonly) BOOL editing;
222
223 #pragma mark - Promo Cell
224
225 // Return true if the section at the given index is a promo section.
226 - (BOOL)isPromoSection:(NSInteger)section;
227 - (BOOL)shouldShowPromoCell;
228 - (BOOL)isPromoActive;
229
230 @end
231
232 #endif // IOS_CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_COLLECTION_VIEW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698