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

Side by Side Diff: ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.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 (c) 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_UTILS_IOS_H_
6 #define IOS_CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_UTILS_IOS_H_
7
8 #import <UIKit/UIKit.h>
9 #include <set>
10 #include <vector>
11
12 #include "base/memory/scoped_vector.h"
13 #include "base/strings/string16.h"
14 #include "base/time/time.h"
15
16 @class BookmarkCell;
17 @class BookmarkMenuItem;
18 @class BookmarkPositionCache;
19 class GURL;
20
21 namespace bookmarks {
22 class BookmarkModel;
23 class BookmarkNode;
24 } // namespace bookmarks
25
26 namespace ios {
27 class ChromeBrowserState;
28 } // namespace ios
29
30 namespace bookmark_utils_ios {
31
32 typedef std::vector<const bookmarks::BookmarkNode*> NodeVector;
33 typedef std::set<const bookmarks::BookmarkNode*> NodeSet;
34
35 // The iOS code is doing some munging of the bookmark folder names in order
36 // to display a slighly different wording for the default folders.
37 NSString* TitleForBookmarkNode(const bookmarks::BookmarkNode* node);
38
39 // Returns the default color for |url| when no image is available.
40 UIColor* DefaultColor(const GURL& url);
41
42 // Returns the subtitle relevant to the bookmark navigation ui.
43 NSString* subtitleForBookmarkNode(const bookmarks::BookmarkNode* node);
44
45 // This margin is designed to align with the menu button in the navigation bar.
46 extern const CGFloat menuMargin;
47 // The margin from the left of the screen for the title of the navigation bar.
48 extern const CGFloat titleMargin;
49 // The distance between the icon in hamburger menu and the menu item title.
50 extern const CGFloat titleToIconDistance;
51 // The amount of time it takes to show or hide the bookmark menu.
52 extern const CGFloat menuAnimationDuration;
53
54 // On iPad, background color can be transparent. Wrapper for the light grey
55 // background color.
56 UIColor* mainBackgroundColor();
57 // Returns the menu's background color. White when the menu is in a slide over
58 // panel, transparent otherwise.
59 UIColor* menuBackgroundColor();
60 // Primary title labels use this color.
61 UIColor* darkTextColor();
62 // Secondary title labels use this color.
63 UIColor* lightTextColor();
64 // The color to use if the text needs to change color when highlighted.
65 UIColor* highlightedDarkTextColor();
66 // The color used for the editing bar.
67 UIColor* blueColor();
68 // The color used for the navigation bar.
69 UIColor* GrayColor();
70 // The gray color for line separators.
71 UIColor* separatorColor();
72 // The black color for the folder labels.
73 UIColor* FolderLabelColor();
74
75 // Returns the current status bar height.
76 CGFloat StatusBarHeight();
77
78 // Returns whether the bookmark menu should be presented in a slide in panel.
79 BOOL bookmarkMenuIsInSlideInPanel();
80
81 // Creates a drop shadow with the given width.
82 UIView* dropShadowWithWidth(CGFloat width);
83
84 #pragma mark - Updating Bookmarks
85
86 // Creates the bookmark if |node| is NULL. Otherwise updates |node|.
87 // |folder| is the intended parent of |node|.
88 // A snackbar is presented, that let the user undo the changes.
89 void CreateOrUpdateBookmarkWithUndoToast(
90 const bookmarks::BookmarkNode* node,
91 NSString* title,
92 const GURL& url,
93 const bookmarks::BookmarkNode* folder,
94 bookmarks::BookmarkModel* bookmark_model,
95 ios::ChromeBrowserState* browser_state);
96
97 // Deletes all bookmarks in |model| that are in |bookmarks|, and presents a
98 // snackbar with an undo action.
99 void DeleteBookmarksWithUndoToast(
100 const std::set<const bookmarks::BookmarkNode*>& bookmarks,
101 bookmarks::BookmarkModel* model,
102 ios::ChromeBrowserState* browser_state);
103
104 // Deletes all nodes in |bookmarks|.
105 void DeleteBookmarks(const std::set<const bookmarks::BookmarkNode*>& bookmarks,
106 bookmarks::BookmarkModel* model);
107
108 // Move all |bookmarks| to the given |folder|, and presents a snackbar with an
109 // undo action.
110 void MoveBookmarksWithUndoToast(
111 const std::set<const bookmarks::BookmarkNode*>& bookmarks,
112 bookmarks::BookmarkModel* model,
113 const bookmarks::BookmarkNode* folder,
114 ios::ChromeBrowserState* browser_state);
115
116 // Move all |bookmarks| to the given |folder|.
117 // Returns whether this method actually moved bookmarks (for example, only
118 // moving a folder to its parent will return |false|).
119 bool MoveBookmarks(const std::set<const bookmarks::BookmarkNode*>& bookmarks,
120 bookmarks::BookmarkModel* model,
121 const bookmarks::BookmarkNode* folder);
122
123 // Category name for all bookmarks related snackbars.
124 extern NSString* const kBookmarksSnackbarCategory;
125
126 // Returns the parent, if all the bookmarks are siblings.
127 // Otherwise returns the mobile_node.
128 const bookmarks::BookmarkNode* defaultMoveFolder(
129 const std::set<const bookmarks::BookmarkNode*>& bookmarks,
130 bookmarks::BookmarkModel* model);
131
132 #pragma mark - Segregation of nodes by time.
133
134 // A container for nodes which have been aggregated by some time property.
135 // e.g. (creation date) or (last access date).
136 class NodesSection {
137 public:
138 NodesSection();
139 virtual ~NodesSection();
140
141 // |vector| is sorted by the relevant time property.
142 NodeVector vector;
143 // A representative time of all nodes in vector.
144 base::Time time;
145 // A string representation of |time|.
146 // e.g. (March 2014) or (4 March 2014).
147 std::string timeRepresentation;
148 };
149
150 // Given the nodes in |vector|, segregates them by some time property into
151 // NodesSections.
152 // Automatically clears, populates and sorts |nodesSectionVector|.
153 // This method is not thread safe - it should only be called from the ui thread.
154 void segregateNodes(const NodeVector& vector,
155 ScopedVector<NodesSection>& nodesSectionVector);
156
157 #pragma mark - Useful bookmark manipulation.
158
159 // Sorts a vector full of folders by title.
160 void SortFolders(NodeVector* vector);
161
162 // Returns a vector of root level folders and all their folder descendants,
163 // sorted depth-first, then alphabetically. The returned nodes are visible, and
164 // are guaranteed to not be descendants of any nodes in |obstructions|.
165 NodeVector VisibleNonDescendantNodes(const NodeSet& obstructions,
166 bookmarks::BookmarkModel* model);
167
168 // Whether |vector1| contains only elements of |vector2| in the same order.
169 BOOL IsSubvectorOfNodes(const NodeVector& vector1, const NodeVector& vector2);
170
171 // Returns the indices in |vector2| of the items in |vector2| that are not
172 // present in |vector1|.
173 // |vector1| MUST be a subvector of |vector2| in the sense of |IsSubvector|.
174 std::vector<NodeVector::size_type> MissingNodesIndices(
175 const NodeVector& vector1,
176 const NodeVector& vector2);
177
178 #pragma mark - Cache position in collection view.
179
180 // Caches the active menu item, and the position in the collection view.
181 void CachePosition(CGFloat position, BookmarkMenuItem* item);
182 // Returns YES if a valid cache exists.
183 // |model| must be loaded.
184 // |item| and |position| are out variables, only populated if the return is YES.
185 BOOL GetPositionCache(bookmarks::BookmarkModel* model,
186 BookmarkMenuItem** item,
187 CGFloat* position);
188 // Method exists for testing.
189 void ClearPositionCache();
190
191 } // namespace bookmark_utils_ios
192
193 #endif // IOS_CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_UTILS_IOS_H_
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/bookmarks/bookmark_promo_controller.mm ('k') | ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698