[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 | |
| 10 | #include "chrome/browser/bookmarks/bookmark_drag_data.h" |
[email protected] | 9333f18 | 2008-12-09 17:34:17 | [diff] [blame] | 11 | #include "chrome/browser/history/snippet.h" |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 12 | #include "webkit/glue/window_open_disposition.h" |
| 13 | |
[email protected] | 9333f18 | 2008-12-09 17:34:17 | [diff] [blame] | 14 | class BookmarkModel; |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 15 | class BookmarkNode; |
| 16 | class PageNavigator; |
| 17 | class Profile; |
| 18 | |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 19 | // A collection of bookmark utility functions used by various parts of the UI |
| 20 | // that show bookmarks: bookmark manager, bookmark bar view ... |
| 21 | namespace bookmark_utils { |
| 22 | |
[email protected] | f28cbb7 | 2008-11-04 19:29:08 | [diff] [blame] | 23 | // Calculates the drop operation given |source_operations| and the ideal |
| 24 | // set of drop operations (|operations|). This prefers the following ordering: |
| 25 | // COPY, LINK then MOVE. |
| 26 | int PreferredDropOperation(int source_operations, int operations); |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 27 | |
| 28 | // Returns true if the bookmark data can be dropped on |drop_parent| at |
| 29 | // |index|. A drop from a separate profile is always allowed, where as |
| 30 | // a drop from the same profile is only allowed if none of the nodes in |
| 31 | // |data| are an ancestor of |drop_parent| and one of the nodes isn't already |
| 32 | // a child of |drop_parent| at |index|. |
| 33 | bool IsValidDropLocation(Profile* profile, |
| 34 | const BookmarkDragData& data, |
| 35 | BookmarkNode* drop_parent, |
| 36 | int index); |
| 37 | |
| 38 | // Clones drag data, adding newly created nodes to |parent| starting at |
| 39 | // |index_to_add_at|. |
| 40 | void CloneDragData(BookmarkModel* model, |
| 41 | const std::vector<BookmarkDragData::Element>& elements, |
| 42 | BookmarkNode* parent, |
| 43 | int index_to_add_at); |
| 44 | |
| 45 | // Recursively opens all bookmarks. |initial_disposition| dictates how the |
| 46 | // first URL is opened, all subsequent URLs are opened as background tabs. |
| 47 | // |navigator| is used to open the URLs. If |navigator| is NULL the last |
| 48 | // tabbed browser with the profile |profile| is used. If there is no browser |
| 49 | // with the specified profile a new one is created. |
| 50 | void OpenAll(HWND parent, |
| 51 | Profile* profile, |
| 52 | PageNavigator* navigator, |
| 53 | const std::vector<BookmarkNode*>& nodes, |
| 54 | WindowOpenDisposition initial_disposition); |
| 55 | |
| 56 | // Convenience for opening a single BookmarkNode. |
| 57 | void OpenAll(HWND parent, |
| 58 | Profile* profile, |
| 59 | PageNavigator* navigator, |
| 60 | BookmarkNode* node, |
| 61 | WindowOpenDisposition initial_disposition); |
| 62 | |
[email protected] | fafc8a42 | 2008-11-07 17:53:09 | [diff] [blame] | 63 | // Copies nodes onto the clipboard. If |remove_nodes| is true the nodes are |
| 64 | // removed after copied to the clipboard. The nodes are copied in such a way |
| 65 | // that if pasted again copies are made. |
| 66 | void CopyToClipboard(BookmarkModel* model, |
| 67 | const std::vector<BookmarkNode*>& nodes, |
| 68 | bool remove_nodes); |
| 69 | |
| 70 | // Pastes from the clipboard. The new nodes are added to |parent|, unless |
| 71 | // |parent| is null in which case this does nothing. The nodes are inserted |
| 72 | // at |index|. If |index| is -1 the nodes are added to the end. |
| 73 | void PasteFromClipboard(BookmarkModel* model, |
| 74 | BookmarkNode* parent, |
| 75 | int index); |
| 76 | |
| 77 | // Returns true if the user can copy from the pasteboard. |
| 78 | bool CanPasteFromClipboard(BookmarkNode* node); |
| 79 | |
[email protected] | 9333f18 | 2008-12-09 17:34:17 | [diff] [blame] | 80 | // Returns a vector containing up to |max_count| of the most recently modified |
| 81 | // groups. This never returns an empty vector. |
| 82 | std::vector<BookmarkNode*> GetMostRecentlyModifiedGroups(BookmarkModel* model, |
| 83 | size_t max_count); |
| 84 | |
| 85 | // Returns the most recently added bookmarks. This does not return groups, |
| 86 | // only nodes of type url. |
| 87 | void GetMostRecentlyAddedEntries(BookmarkModel* model, |
| 88 | size_t count, |
| 89 | std::vector<BookmarkNode*>* nodes); |
| 90 | |
| 91 | // Used by GetBookmarksMatchingText to return a matching node and the location |
| 92 | // of the match in the title. |
| 93 | struct TitleMatch { |
| 94 | BookmarkNode* node; |
| 95 | |
| 96 | // Location of the matching words in the title of the node. |
| 97 | Snippet::MatchPositions match_positions; |
| 98 | }; |
| 99 | |
| 100 | // Returns the bookmarks whose title contains text. At most |max_count| |
| 101 | // matches are returned in |matches|. |
| 102 | void GetBookmarksMatchingText(BookmarkModel* model, |
| 103 | const std::wstring& text, |
| 104 | size_t max_count, |
| 105 | std::vector<TitleMatch>* matches); |
| 106 | |
[email protected] | 9333f18 | 2008-12-09 17:34:17 | [diff] [blame] | 107 | // Returns true if |n1| was added more recently than |n2|. |
| 108 | bool MoreRecentlyAdded(BookmarkNode* n1, BookmarkNode* n2); |
| 109 | |
[email protected] | cb362ccc | 2008-12-10 17:22:32 | [diff] [blame^] | 110 | // Returns up to |max_count| bookmarks from |model| whose url or title contains |
| 111 | // the text |text|. |
| 112 | void GetBookmarksContainingText(BookmarkModel* model, |
| 113 | const std::wstring& text, |
| 114 | size_t max_count, |
| 115 | std::vector<BookmarkNode*>* nodes); |
| 116 | |
| 117 | // Returns true if |node|'s url or title contains the string |text|. |
| 118 | bool DoesBookmarkContainText(BookmarkNode* node, const std::wstring& text); |
| 119 | |
[email protected] | f785ad1 | 2008-11-19 23:01:28 | [diff] [blame] | 120 | // Number of bookmarks we'll open before prompting the user to see if they |
| 121 | // really want to open all. |
| 122 | // |
| 123 | // NOTE: treat this as a const. It is not const as various tests change the |
| 124 | // value. |
| 125 | extern int num_urls_before_prompting; |
| 126 | |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 127 | } // namespace bookmark_utils |
| 128 | |
| 129 | #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_UTILS_H_ |