blob: 0bea122fa6eddaed96c1c9ff5c07134aa872b926 [file] [log] [blame]
[email protected]7f856be2008-10-29 23:38:061// 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
[email protected]903e7a82009-07-28 00:45:358#include <string>
[email protected]7f856be2008-10-29 23:38:069#include <vector>
10
[email protected]010ea08a2009-10-11 20:21:3211#include "app/gfx/native_widget_types.h"
[email protected]7f856be2008-10-29 23:38:0612#include "chrome/browser/bookmarks/bookmark_drag_data.h"
[email protected]140aea052009-05-05 00:35:0913#include "chrome/browser/bookmarks/bookmark_editor.h"
[email protected]9333f182008-12-09 17:34:1714#include "chrome/browser/history/snippet.h"
[email protected]7f856be2008-10-29 23:38:0615#include "webkit/glue/window_open_disposition.h"
16
[email protected]9333f182008-12-09 17:34:1717class BookmarkModel;
[email protected]7f856be2008-10-29 23:38:0618class BookmarkNode;
[email protected]b3ac5c82009-10-08 20:56:5419class Browser;
[email protected]7f856be2008-10-29 23:38:0620class PageNavigator;
[email protected]44b2c8852009-03-18 00:57:4921class PrefService;
[email protected]7f856be2008-10-29 23:38:0622class Profile;
[email protected]b3ac5c82009-10-08 20:56:5423class TabContents;
[email protected]7f856be2008-10-29 23:38:0624
[email protected]7aa4c002009-03-12 19:10:2225namespace views {
26class DropTargetEvent;
27}
28
[email protected]7f856be2008-10-29 23:38:0629// A collection of bookmark utility functions used by various parts of the UI
30// that show bookmarks: bookmark manager, bookmark bar view ...
31namespace bookmark_utils {
32
[email protected]f28cbb72008-11-04 19:29:0833// Calculates the drop operation given |source_operations| and the ideal
34// set of drop operations (|operations|). This prefers the following ordering:
35// COPY, LINK then MOVE.
36int PreferredDropOperation(int source_operations, int operations);
[email protected]7f856be2008-10-29 23:38:0637
[email protected]7aa4c002009-03-12 19:10:2238// Returns the drag operations for the specified node.
[email protected]b3c33d462009-06-26 22:29:2039int BookmarkDragOperation(const BookmarkNode* node);
[email protected]7aa4c002009-03-12 19:10:2240
41// Returns the preferred drop operation on a bookmark menu/bar.
42// |parent| is the parent node the drop is to occur on and |index| the index the
43// drop is over.
44int BookmarkDropOperation(Profile* profile,
[email protected]fa5dfaf2009-06-02 22:12:0645 const views::DropTargetEvent& event,
46 const BookmarkDragData& data,
[email protected]b3c33d462009-06-26 22:29:2047 const BookmarkNode* parent,
[email protected]fa5dfaf2009-06-02 22:12:0648 int index);
[email protected]7aa4c002009-03-12 19:10:2249
50// Performs a drop of bookmark data onto |parent_node| at |index|. Returns the
51// type of drop the resulted.
52int PerformBookmarkDrop(Profile* profile,
[email protected]fa5dfaf2009-06-02 22:12:0653 const BookmarkDragData& data,
[email protected]b3c33d462009-06-26 22:29:2054 const BookmarkNode* parent_node,
[email protected]fa5dfaf2009-06-02 22:12:0655 int index);
[email protected]7aa4c002009-03-12 19:10:2256
[email protected]7f856be2008-10-29 23:38:0657// Returns true if the bookmark data can be dropped on |drop_parent| at
58// |index|. A drop from a separate profile is always allowed, where as
59// a drop from the same profile is only allowed if none of the nodes in
60// |data| are an ancestor of |drop_parent| and one of the nodes isn't already
61// a child of |drop_parent| at |index|.
62bool IsValidDropLocation(Profile* profile,
63 const BookmarkDragData& data,
[email protected]b3c33d462009-06-26 22:29:2064 const BookmarkNode* drop_parent,
[email protected]7f856be2008-10-29 23:38:0665 int index);
66
67// Clones drag data, adding newly created nodes to |parent| starting at
68// |index_to_add_at|.
69void CloneDragData(BookmarkModel* model,
70 const std::vector<BookmarkDragData::Element>& elements,
[email protected]b3c33d462009-06-26 22:29:2071 const BookmarkNode* parent,
[email protected]7f856be2008-10-29 23:38:0672 int index_to_add_at);
73
74// Recursively opens all bookmarks. |initial_disposition| dictates how the
75// first URL is opened, all subsequent URLs are opened as background tabs.
76// |navigator| is used to open the URLs. If |navigator| is NULL the last
77// tabbed browser with the profile |profile| is used. If there is no browser
78// with the specified profile a new one is created.
[email protected]d6d6d582009-10-12 19:22:2679void OpenAll(gfx::NativeWindow parent,
[email protected]7f856be2008-10-29 23:38:0680 Profile* profile,
81 PageNavigator* navigator,
[email protected]b3c33d462009-06-26 22:29:2082 const std::vector<const BookmarkNode*>& nodes,
[email protected]7f856be2008-10-29 23:38:0683 WindowOpenDisposition initial_disposition);
84
85// Convenience for opening a single BookmarkNode.
[email protected]d6d6d582009-10-12 19:22:2686void OpenAll(gfx::NativeWindow parent,
[email protected]7f856be2008-10-29 23:38:0687 Profile* profile,
88 PageNavigator* navigator,
[email protected]b3c33d462009-06-26 22:29:2089 const BookmarkNode* node,
[email protected]7f856be2008-10-29 23:38:0690 WindowOpenDisposition initial_disposition);
91
[email protected]fafc8a422008-11-07 17:53:0992// Copies nodes onto the clipboard. If |remove_nodes| is true the nodes are
93// removed after copied to the clipboard. The nodes are copied in such a way
94// that if pasted again copies are made.
95void CopyToClipboard(BookmarkModel* model,
[email protected]b3c33d462009-06-26 22:29:2096 const std::vector<const BookmarkNode*>& nodes,
[email protected]fafc8a422008-11-07 17:53:0997 bool remove_nodes);
98
99// Pastes from the clipboard. The new nodes are added to |parent|, unless
100// |parent| is null in which case this does nothing. The nodes are inserted
101// at |index|. If |index| is -1 the nodes are added to the end.
102void PasteFromClipboard(BookmarkModel* model,
[email protected]b3c33d462009-06-26 22:29:20103 const BookmarkNode* parent,
[email protected]fafc8a422008-11-07 17:53:09104 int index);
105
106// Returns true if the user can copy from the pasteboard.
[email protected]b3c33d462009-06-26 22:29:20107bool CanPasteFromClipboard(const BookmarkNode* node);
[email protected]fafc8a422008-11-07 17:53:09108
[email protected]903e7a82009-07-28 00:45:35109// Returns a name for the given URL. Used for drags into bookmark areas when
110// the source doesn't specify a title.
111std::string GetNameForURL(const GURL& url);
112
[email protected]9333f182008-12-09 17:34:17113// Returns a vector containing up to |max_count| of the most recently modified
114// groups. This never returns an empty vector.
[email protected]b3c33d462009-06-26 22:29:20115std::vector<const BookmarkNode*> GetMostRecentlyModifiedGroups(
116 BookmarkModel* model, size_t max_count);
[email protected]9333f182008-12-09 17:34:17117
118// Returns the most recently added bookmarks. This does not return groups,
119// only nodes of type url.
120void GetMostRecentlyAddedEntries(BookmarkModel* model,
121 size_t count,
[email protected]b3c33d462009-06-26 22:29:20122 std::vector<const BookmarkNode*>* nodes);
[email protected]9333f182008-12-09 17:34:17123
124// Used by GetBookmarksMatchingText to return a matching node and the location
125// of the match in the title.
126struct TitleMatch {
[email protected]b3c33d462009-06-26 22:29:20127 const BookmarkNode* node;
[email protected]9333f182008-12-09 17:34:17128
129 // Location of the matching words in the title of the node.
130 Snippet::MatchPositions match_positions;
131};
132
[email protected]9333f182008-12-09 17:34:17133// Returns true if |n1| was added more recently than |n2|.
[email protected]b3c33d462009-06-26 22:29:20134bool MoreRecentlyAdded(const BookmarkNode* n1, const BookmarkNode* n2);
[email protected]9333f182008-12-09 17:34:17135
[email protected]cb362ccc2008-12-10 17:22:32136// Returns up to |max_count| bookmarks from |model| whose url or title contains
[email protected]fa5dfaf2009-06-02 22:12:06137// the text |text|. |languages| is user's accept-language setting to decode
138// IDN.
[email protected]cb362ccc2008-12-10 17:22:32139void GetBookmarksContainingText(BookmarkModel* model,
140 const std::wstring& text,
141 size_t max_count,
[email protected]fa5dfaf2009-06-02 22:12:06142 const std::wstring& languages,
[email protected]b3c33d462009-06-26 22:29:20143 std::vector<const BookmarkNode*>* nodes);
[email protected]cb362ccc2008-12-10 17:22:32144
145// Returns true if |node|'s url or title contains the string |text|.
[email protected]fa5dfaf2009-06-02 22:12:06146// |languages| is user's accept-language setting to decode IDN.
[email protected]b3c33d462009-06-26 22:29:20147bool DoesBookmarkContainText(const BookmarkNode* node,
[email protected]fa5dfaf2009-06-02 22:12:06148 const std::wstring& text,
149 const std::wstring& languages);
[email protected]cb362ccc2008-12-10 17:22:32150
[email protected]140aea052009-05-05 00:35:09151// Modifies a bookmark node (assuming that there's no magic that needs to be
[email protected]e5486602010-02-09 21:27:55152// done regarding moving from one folder to another). If a new node is
153// explicitly being added, returns a pointer to the new node that was created.
154// Otherwise the return value is identically |node|.
[email protected]a8d71b02009-07-07 00:36:34155const BookmarkNode* ApplyEditsWithNoGroupChange(
156 BookmarkModel* model,
157 const BookmarkNode* parent,
[email protected]ec12ffe2009-10-16 22:28:44158 const BookmarkEditor::EditDetails& details,
[email protected]a8d71b02009-07-07 00:36:34159 const std::wstring& new_title,
160 const GURL& new_url,
161 BookmarkEditor::Handler* handler);
[email protected]140aea052009-05-05 00:35:09162
163// Modifies a bookmark node assuming that the parent of the node may have
[email protected]e5486602010-02-09 21:27:55164// changed and the node will need to be removed and reinserted. If a new node
165// is explicitly being added, returns a pointer to the new node that was
166// created. Otherwise the return value is identically |node|.
[email protected]a8d71b02009-07-07 00:36:34167const BookmarkNode* ApplyEditsWithPossibleGroupChange(
168 BookmarkModel* model,
169 const BookmarkNode* new_parent,
[email protected]ec12ffe2009-10-16 22:28:44170 const BookmarkEditor::EditDetails& details,
[email protected]a8d71b02009-07-07 00:36:34171 const std::wstring& new_title,
172 const GURL& new_url,
173 BookmarkEditor::Handler* handler);
[email protected]140aea052009-05-05 00:35:09174
[email protected]44b2c8852009-03-18 00:57:49175// Toggles whether the bookmark bar is shown only on the new tab page or on
176// all tabs. This is a preference modifier, not a visual modifier.
177void ToggleWhenVisible(Profile* profile);
178
[email protected]1e7bab72009-06-03 17:23:36179// Register local state prefs for bookmark bar view.
180void RegisterPrefs(PrefService* prefs);
181
[email protected]44b2c8852009-03-18 00:57:49182// Register user prefs for BookmarkBar, BookmarkView, ...
183void RegisterUserPrefs(PrefService* prefs);
184
[email protected]76624fde2009-10-09 18:13:23185// Fills in the URL and title for a bookmark of |tab_contents|.
186void GetURLAndTitleToBookmark(TabContents* tab_contents,
[email protected]b3ac5c82009-10-08 20:56:54187 GURL* url,
188 std::wstring* title);
189
[email protected]ec12ffe2009-10-16 22:28:44190// Returns, by reference in |urls|, the url and title pairs for each open
191// tab in browser.
192void GetURLsForOpenTabs(Browser* browser,
193 std::vector<std::pair<GURL, std::wstring> >* urls);
[email protected]b3ac5c82009-10-08 20:56:54194
[email protected]f785ad12008-11-19 23:01:28195// Number of bookmarks we'll open before prompting the user to see if they
196// really want to open all.
197//
198// NOTE: treat this as a const. It is not const as various tests change the
199// value.
200extern int num_urls_before_prompting;
201
[email protected]7f856be2008-10-29 23:38:06202} // namespace bookmark_utils
203
204#endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_UTILS_H_