[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 1 | // Copyright (c) 2006-2008 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 CHROME_BROWSER_BOOKMARKS_BOOKMARK_UTILS_H_ |
| 6 | #define CHROME_BROWSER_BOOKMARKS_BOOKMARK_UTILS_H_ |
| 7 | |
| 8 | #include <vector> |
| 9 | |
[email protected] | d7e85c5 | 2009-02-25 17:28:30 | [diff] [blame] | 10 | #include "base/gfx/native_widget_types.h" |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 11 | #include "chrome/browser/bookmarks/bookmark_drag_data.h" |
[email protected] | 140aea05 | 2009-05-05 00:35:09 | [diff] [blame] | 12 | #include "chrome/browser/bookmarks/bookmark_editor.h" |
[email protected] | 9333f18 | 2008-12-09 17:34:17 | [diff] [blame] | 13 | #include "chrome/browser/history/snippet.h" |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 14 | #include "webkit/glue/window_open_disposition.h" |
| 15 | |
[email protected] | 9333f18 | 2008-12-09 17:34:17 | [diff] [blame] | 16 | class BookmarkModel; |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 17 | class BookmarkNode; |
| 18 | class PageNavigator; |
[email protected] | 44b2c885 | 2009-03-18 00:57:49 | [diff] [blame] | 19 | class PrefService; |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 20 | class Profile; |
| 21 | |
[email protected] | 7aa4c00 | 2009-03-12 19:10:22 | [diff] [blame] | 22 | namespace views { |
| 23 | class DropTargetEvent; |
| 24 | } |
| 25 | |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 26 | // A collection of bookmark utility functions used by various parts of the UI |
| 27 | // that show bookmarks: bookmark manager, bookmark bar view ... |
| 28 | namespace bookmark_utils { |
| 29 | |
[email protected] | f28cbb7 | 2008-11-04 19:29:08 | [diff] [blame] | 30 | // Calculates the drop operation given |source_operations| and the ideal |
| 31 | // set of drop operations (|operations|). This prefers the following ordering: |
| 32 | // COPY, LINK then MOVE. |
| 33 | int PreferredDropOperation(int source_operations, int operations); |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 34 | |
[email protected] | 7aa4c00 | 2009-03-12 19:10:22 | [diff] [blame] | 35 | // Returns the drag operations for the specified node. |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame^] | 36 | int BookmarkDragOperation(const BookmarkNode* node); |
[email protected] | 7aa4c00 | 2009-03-12 19:10:22 | [diff] [blame] | 37 | |
| 38 | // Returns the preferred drop operation on a bookmark menu/bar. |
| 39 | // |parent| is the parent node the drop is to occur on and |index| the index the |
| 40 | // drop is over. |
| 41 | int BookmarkDropOperation(Profile* profile, |
[email protected] | fa5dfaf | 2009-06-02 22:12:06 | [diff] [blame] | 42 | const views::DropTargetEvent& event, |
| 43 | const BookmarkDragData& data, |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame^] | 44 | const BookmarkNode* parent, |
[email protected] | fa5dfaf | 2009-06-02 22:12:06 | [diff] [blame] | 45 | int index); |
[email protected] | 7aa4c00 | 2009-03-12 19:10:22 | [diff] [blame] | 46 | |
| 47 | // Performs a drop of bookmark data onto |parent_node| at |index|. Returns the |
| 48 | // type of drop the resulted. |
| 49 | int PerformBookmarkDrop(Profile* profile, |
[email protected] | fa5dfaf | 2009-06-02 22:12:06 | [diff] [blame] | 50 | const BookmarkDragData& data, |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame^] | 51 | const BookmarkNode* parent_node, |
[email protected] | fa5dfaf | 2009-06-02 22:12:06 | [diff] [blame] | 52 | int index); |
[email protected] | 7aa4c00 | 2009-03-12 19:10:22 | [diff] [blame] | 53 | |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 54 | // Returns true if the bookmark data can be dropped on |drop_parent| at |
| 55 | // |index|. A drop from a separate profile is always allowed, where as |
| 56 | // a drop from the same profile is only allowed if none of the nodes in |
| 57 | // |data| are an ancestor of |drop_parent| and one of the nodes isn't already |
| 58 | // a child of |drop_parent| at |index|. |
| 59 | bool IsValidDropLocation(Profile* profile, |
| 60 | const BookmarkDragData& data, |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame^] | 61 | const BookmarkNode* drop_parent, |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 62 | int index); |
| 63 | |
| 64 | // Clones drag data, adding newly created nodes to |parent| starting at |
| 65 | // |index_to_add_at|. |
| 66 | void CloneDragData(BookmarkModel* model, |
| 67 | const std::vector<BookmarkDragData::Element>& elements, |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame^] | 68 | const BookmarkNode* parent, |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 69 | int index_to_add_at); |
| 70 | |
| 71 | // Recursively opens all bookmarks. |initial_disposition| dictates how the |
| 72 | // first URL is opened, all subsequent URLs are opened as background tabs. |
| 73 | // |navigator| is used to open the URLs. If |navigator| is NULL the last |
| 74 | // tabbed browser with the profile |profile| is used. If there is no browser |
| 75 | // with the specified profile a new one is created. |
[email protected] | 6128eae | 2009-05-27 22:00:39 | [diff] [blame] | 76 | void OpenAll(gfx::NativeView parent, |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 77 | Profile* profile, |
| 78 | PageNavigator* navigator, |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame^] | 79 | const std::vector<const BookmarkNode*>& nodes, |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 80 | WindowOpenDisposition initial_disposition); |
| 81 | |
| 82 | // Convenience for opening a single BookmarkNode. |
[email protected] | 6128eae | 2009-05-27 22:00:39 | [diff] [blame] | 83 | void OpenAll(gfx::NativeView parent, |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 84 | Profile* profile, |
| 85 | PageNavigator* navigator, |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame^] | 86 | const BookmarkNode* node, |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 87 | WindowOpenDisposition initial_disposition); |
| 88 | |
[email protected] | fafc8a42 | 2008-11-07 17:53:09 | [diff] [blame] | 89 | // Copies nodes onto the clipboard. If |remove_nodes| is true the nodes are |
| 90 | // removed after copied to the clipboard. The nodes are copied in such a way |
| 91 | // that if pasted again copies are made. |
| 92 | void CopyToClipboard(BookmarkModel* model, |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame^] | 93 | const std::vector<const BookmarkNode*>& nodes, |
[email protected] | fafc8a42 | 2008-11-07 17:53:09 | [diff] [blame] | 94 | bool remove_nodes); |
| 95 | |
| 96 | // Pastes from the clipboard. The new nodes are added to |parent|, unless |
| 97 | // |parent| is null in which case this does nothing. The nodes are inserted |
| 98 | // at |index|. If |index| is -1 the nodes are added to the end. |
| 99 | void PasteFromClipboard(BookmarkModel* model, |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame^] | 100 | const BookmarkNode* parent, |
[email protected] | fafc8a42 | 2008-11-07 17:53:09 | [diff] [blame] | 101 | int index); |
| 102 | |
| 103 | // Returns true if the user can copy from the pasteboard. |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame^] | 104 | bool CanPasteFromClipboard(const BookmarkNode* node); |
[email protected] | fafc8a42 | 2008-11-07 17:53:09 | [diff] [blame] | 105 | |
[email protected] | 9333f18 | 2008-12-09 17:34:17 | [diff] [blame] | 106 | // Returns a vector containing up to |max_count| of the most recently modified |
| 107 | // groups. This never returns an empty vector. |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame^] | 108 | std::vector<const BookmarkNode*> GetMostRecentlyModifiedGroups( |
| 109 | BookmarkModel* model, size_t max_count); |
[email protected] | 9333f18 | 2008-12-09 17:34:17 | [diff] [blame] | 110 | |
| 111 | // Returns the most recently added bookmarks. This does not return groups, |
| 112 | // only nodes of type url. |
| 113 | void GetMostRecentlyAddedEntries(BookmarkModel* model, |
| 114 | size_t count, |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame^] | 115 | std::vector<const BookmarkNode*>* nodes); |
[email protected] | 9333f18 | 2008-12-09 17:34:17 | [diff] [blame] | 116 | |
| 117 | // Used by GetBookmarksMatchingText to return a matching node and the location |
| 118 | // of the match in the title. |
| 119 | struct TitleMatch { |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame^] | 120 | const BookmarkNode* node; |
[email protected] | 9333f18 | 2008-12-09 17:34:17 | [diff] [blame] | 121 | |
| 122 | // Location of the matching words in the title of the node. |
| 123 | Snippet::MatchPositions match_positions; |
| 124 | }; |
| 125 | |
[email protected] | 9333f18 | 2008-12-09 17:34:17 | [diff] [blame] | 126 | // Returns true if |n1| was added more recently than |n2|. |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame^] | 127 | bool MoreRecentlyAdded(const BookmarkNode* n1, const BookmarkNode* n2); |
[email protected] | 9333f18 | 2008-12-09 17:34:17 | [diff] [blame] | 128 | |
[email protected] | cb362ccc | 2008-12-10 17:22:32 | [diff] [blame] | 129 | // Returns up to |max_count| bookmarks from |model| whose url or title contains |
[email protected] | fa5dfaf | 2009-06-02 22:12:06 | [diff] [blame] | 130 | // the text |text|. |languages| is user's accept-language setting to decode |
| 131 | // IDN. |
[email protected] | cb362ccc | 2008-12-10 17:22:32 | [diff] [blame] | 132 | void GetBookmarksContainingText(BookmarkModel* model, |
| 133 | const std::wstring& text, |
| 134 | size_t max_count, |
[email protected] | fa5dfaf | 2009-06-02 22:12:06 | [diff] [blame] | 135 | const std::wstring& languages, |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame^] | 136 | std::vector<const BookmarkNode*>* nodes); |
[email protected] | cb362ccc | 2008-12-10 17:22:32 | [diff] [blame] | 137 | |
| 138 | // Returns true if |node|'s url or title contains the string |text|. |
[email protected] | fa5dfaf | 2009-06-02 22:12:06 | [diff] [blame] | 139 | // |languages| is user's accept-language setting to decode IDN. |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame^] | 140 | bool DoesBookmarkContainText(const BookmarkNode* node, |
[email protected] | fa5dfaf | 2009-06-02 22:12:06 | [diff] [blame] | 141 | const std::wstring& text, |
| 142 | const std::wstring& languages); |
[email protected] | cb362ccc | 2008-12-10 17:22:32 | [diff] [blame] | 143 | |
[email protected] | 140aea05 | 2009-05-05 00:35:09 | [diff] [blame] | 144 | // Modifies a bookmark node (assuming that there's no magic that needs to be |
| 145 | // done regarding moving from one folder to another). |
| 146 | void ApplyEditsWithNoGroupChange(BookmarkModel* model, |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame^] | 147 | const BookmarkNode* parent, |
| 148 | const BookmarkNode* node, |
[email protected] | 140aea05 | 2009-05-05 00:35:09 | [diff] [blame] | 149 | const std::wstring& new_title, |
| 150 | const GURL& new_url, |
| 151 | BookmarkEditor::Handler* handler); |
| 152 | |
| 153 | // Modifies a bookmark node assuming that the parent of the node may have |
| 154 | // changed and the node will need to be removed and reinserted. |
| 155 | void ApplyEditsWithPossibleGroupChange(BookmarkModel* model, |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame^] | 156 | const BookmarkNode* new_parent, |
| 157 | const BookmarkNode* node, |
[email protected] | 140aea05 | 2009-05-05 00:35:09 | [diff] [blame] | 158 | const std::wstring& new_title, |
| 159 | const GURL& new_url, |
| 160 | BookmarkEditor::Handler* handler); |
| 161 | |
[email protected] | 44b2c885 | 2009-03-18 00:57:49 | [diff] [blame] | 162 | // Toggles whether the bookmark bar is shown only on the new tab page or on |
| 163 | // all tabs. This is a preference modifier, not a visual modifier. |
| 164 | void ToggleWhenVisible(Profile* profile); |
| 165 | |
[email protected] | 1e7bab7 | 2009-06-03 17:23:36 | [diff] [blame] | 166 | // Register local state prefs for bookmark bar view. |
| 167 | void RegisterPrefs(PrefService* prefs); |
| 168 | |
[email protected] | 44b2c885 | 2009-03-18 00:57:49 | [diff] [blame] | 169 | // Register user prefs for BookmarkBar, BookmarkView, ... |
| 170 | void RegisterUserPrefs(PrefService* prefs); |
| 171 | |
[email protected] | f785ad1 | 2008-11-19 23:01:28 | [diff] [blame] | 172 | // Number of bookmarks we'll open before prompting the user to see if they |
| 173 | // really want to open all. |
| 174 | // |
| 175 | // NOTE: treat this as a const. It is not const as various tests change the |
| 176 | // value. |
| 177 | extern int num_urls_before_prompting; |
| 178 | |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 179 | } // namespace bookmark_utils |
| 180 | |
| 181 | #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_UTILS_H_ |