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

Side by Side Diff: chrome/browser/bookmarks/bookmark_utils.cc

Issue 102713002: Support folders in bookmark search (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Resolve conflicts with master + .cc handling of clipboard Created 6 years, 11 months 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
« no previous file with comments | « no previous file | chrome/browser/bookmarks/bookmark_utils_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/bookmarks/bookmark_utils.h" 5 #include "chrome/browser/bookmarks/bookmark_utils.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 DoesBookmarkTextContainWords(net::FormatUrl( 88 DoesBookmarkTextContainWords(net::FormatUrl(
89 node->url(), languages, net::kFormatUrlOmitNothing, 89 node->url(), languages, net::kFormatUrlOmitNothing,
90 net::UnescapeRule::NORMAL, NULL, NULL, NULL), words); 90 net::UnescapeRule::NORMAL, NULL, NULL, NULL), words);
91 } 91 }
92 92
93 // This is used with a tree iterator to skip subtrees which are not visible. 93 // This is used with a tree iterator to skip subtrees which are not visible.
94 bool PruneInvisibleFolders(const BookmarkNode* node) { 94 bool PruneInvisibleFolders(const BookmarkNode* node) {
95 return !node->IsVisible(); 95 return !node->IsVisible();
96 } 96 }
97 97
98 // This traces parents up to root, determines if node is contained in a
99 // selected folder.
100 bool HasSelectedAncestor(BookmarkModel* model,
101 const std::vector<const BookmarkNode*>& selectedNodes,
102 const BookmarkNode* node) {
103 if (!node || model->is_permanent_node(node))
104 return false;
105
106 for (size_t i = 0; i < selectedNodes.size(); ++i)
107 if (node->id() == selectedNodes[i]->id())
108 return true;
109
110 return HasSelectedAncestor(model, selectedNodes, node->parent());
111 }
112
98 } // namespace 113 } // namespace
99 114
100 namespace bookmark_utils { 115 namespace bookmark_utils {
101 116
102 QueryFields::QueryFields() {} 117 QueryFields::QueryFields() {}
103 QueryFields::~QueryFields() {} 118 QueryFields::~QueryFields() {}
104 119
105 void CloneBookmarkNode(BookmarkModel* model, 120 void CloneBookmarkNode(BookmarkModel* model,
106 const std::vector<BookmarkNodeData::Element>& elements, 121 const std::vector<BookmarkNodeData::Element>& elements,
107 const BookmarkNode* parent, 122 const BookmarkNode* parent,
108 int index_to_add_at, 123 int index_to_add_at,
109 bool reset_node_times) { 124 bool reset_node_times) {
110 if (!parent->is_folder() || !model) { 125 if (!parent->is_folder() || !model) {
111 NOTREACHED(); 126 NOTREACHED();
112 return; 127 return;
113 } 128 }
114 for (size_t i = 0; i < elements.size(); ++i) { 129 for (size_t i = 0; i < elements.size(); ++i) {
115 CloneBookmarkNodeImpl(model, elements[i], parent, index_to_add_at + i, 130 CloneBookmarkNodeImpl(model, elements[i], parent, index_to_add_at + i,
116 reset_node_times); 131 reset_node_times);
117 } 132 }
118 } 133 }
119 134
120 void CopyToClipboard(BookmarkModel* model, 135 void CopyToClipboard(BookmarkModel* model,
121 const std::vector<const BookmarkNode*>& nodes, 136 const std::vector<const BookmarkNode*>& nodes,
122 bool remove_nodes) { 137 bool remove_nodes) {
123 if (nodes.empty()) 138 if (nodes.empty())
124 return; 139 return;
125 140
126 BookmarkNodeData(nodes).WriteToClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE); 141 // Create array of selected nodes with descendants filtered out.
142 std::vector<const BookmarkNode*> filteredNodes;
143 for (size_t i = 0; i < nodes.size(); ++i)
144 if (!HasSelectedAncestor(model, nodes, nodes[i]->parent()))
145 filteredNodes.push_back(nodes[i]);
146
147 BookmarkNodeData(filteredNodes).
148 WriteToClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE);
127 149
128 if (remove_nodes) { 150 if (remove_nodes) {
129 #if !defined(OS_ANDROID) 151 #if !defined(OS_ANDROID)
130 ScopedGroupingAction group_cut(BookmarkUndoServiceFactory::GetForProfile( 152 ScopedGroupingAction group_cut(BookmarkUndoServiceFactory::GetForProfile(
131 model->profile())->undo_manager()); 153 model->profile())->undo_manager());
132 #endif 154 #endif
133 for (size_t i = 0; i < nodes.size(); ++i) { 155 for (size_t i = 0; i < filteredNodes.size(); ++i) {
134 int index = nodes[i]->parent()->GetIndexOf(nodes[i]); 156 int index = filteredNodes[i]->parent()->GetIndexOf(filteredNodes[i]);
135 if (index > -1) 157 if (index > -1)
136 model->Remove(nodes[i]->parent(), index); 158 model->Remove(filteredNodes[i]->parent(), index);
137 } 159 }
138 } 160 }
139 } 161 }
140 162
141 void PasteFromClipboard(BookmarkModel* model, 163 void PasteFromClipboard(BookmarkModel* model,
142 const BookmarkNode* parent, 164 const BookmarkNode* parent,
143 int index) { 165 int index) {
144 if (!parent) 166 if (!parent)
145 return; 167 return;
146 168
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 std::vector<base::string16> query_words; 261 std::vector<base::string16> query_words;
240 QueryParser parser; 262 QueryParser parser;
241 if (query.word_phrase_query) { 263 if (query.word_phrase_query) {
242 parser.ParseQueryWords(base::i18n::ToLower(*query.word_phrase_query), 264 parser.ParseQueryWords(base::i18n::ToLower(*query.word_phrase_query),
243 &query_words); 265 &query_words);
244 } 266 }
245 267
246 ui::TreeNodeIterator<const BookmarkNode> iterator(model->root_node()); 268 ui::TreeNodeIterator<const BookmarkNode> iterator(model->root_node());
247 while (iterator.has_next()) { 269 while (iterator.has_next()) {
248 const BookmarkNode* node = iterator.Next(); 270 const BookmarkNode* node = iterator.Next();
249 if (!query_words.empty() && 271 if ((!query_words.empty() &&
250 !DoesBookmarkContainWords(node, query_words, languages)) { 272 !DoesBookmarkContainWords(node, query_words, languages)) ||
273 model->is_permanent_node(node)) {
251 continue; 274 continue;
252 } 275 }
253 if (query.url) { 276 if (query.url) {
254 // Check against bare url spec and IDN-decoded url. 277 // Check against bare url spec and IDN-decoded url.
255 if (!node->is_url() || 278 if (!node->is_url() ||
256 !(base::UTF8ToUTF16(node->url().spec()) == *query.url || 279 !(base::UTF8ToUTF16(node->url().spec()) == *query.url ||
257 net::FormatUrl( 280 net::FormatUrl(
258 node->url(), languages, net::kFormatUrlOmitNothing, 281 node->url(), languages, net::kFormatUrlOmitNothing,
259 net::UnescapeRule::NORMAL, NULL, NULL, NULL) == *query.url)) { 282 net::UnescapeRule::NORMAL, NULL, NULL, NULL) == *query.url)) {
260 continue; 283 continue;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 // Remove all the bookmarks. 367 // Remove all the bookmarks.
345 for (size_t i = 0; i < bookmarks.size(); ++i) { 368 for (size_t i = 0; i < bookmarks.size(); ++i) {
346 const BookmarkNode* node = bookmarks[i]; 369 const BookmarkNode* node = bookmarks[i];
347 int index = node->parent()->GetIndexOf(node); 370 int index = node->parent()->GetIndexOf(node);
348 if (index > -1) 371 if (index > -1)
349 model->Remove(node->parent(), index); 372 model->Remove(node->parent(), index);
350 } 373 }
351 } 374 }
352 375
353 } // namespace bookmark_utils 376 } // namespace bookmark_utils
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/bookmarks/bookmark_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698