OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/bookmarks/browser/bookmark_utils.h" | 5 #include "components/bookmarks/browser/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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 // Create array of selected nodes with descendants filtered out. | 171 // Create array of selected nodes with descendants filtered out. |
172 std::vector<const BookmarkNode*> filtered_nodes; | 172 std::vector<const BookmarkNode*> filtered_nodes; |
173 for (size_t i = 0; i < nodes.size(); ++i) | 173 for (size_t i = 0; i < nodes.size(); ++i) |
174 if (!HasSelectedAncestor(model, nodes, nodes[i]->parent())) | 174 if (!HasSelectedAncestor(model, nodes, nodes[i]->parent())) |
175 filtered_nodes.push_back(nodes[i]); | 175 filtered_nodes.push_back(nodes[i]); |
176 | 176 |
177 BookmarkNodeData(filtered_nodes). | 177 BookmarkNodeData(filtered_nodes). |
178 WriteToClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE); | 178 WriteToClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE); |
179 | 179 |
180 if (remove_nodes) { | 180 if (remove_nodes) { |
181 ScopedGroupBookmarkActions group_cut(model); | 181 bookmarks::ScopedGroupBookmarkActions group_cut(model); |
182 for (size_t i = 0; i < filtered_nodes.size(); ++i) { | 182 for (size_t i = 0; i < filtered_nodes.size(); ++i) { |
183 int index = filtered_nodes[i]->parent()->GetIndexOf(filtered_nodes[i]); | 183 int index = filtered_nodes[i]->parent()->GetIndexOf(filtered_nodes[i]); |
184 if (index > -1) | 184 if (index > -1) |
185 model->Remove(filtered_nodes[i]->parent(), index); | 185 model->Remove(filtered_nodes[i]->parent(), index); |
186 } | 186 } |
187 } | 187 } |
188 } | 188 } |
189 | 189 |
190 void PasteFromClipboard(BookmarkModel* model, | 190 void PasteFromClipboard(BookmarkModel* model, |
191 const BookmarkNode* parent, | 191 const BookmarkNode* parent, |
192 int index) { | 192 int index) { |
193 if (!parent) | 193 if (!parent) |
194 return; | 194 return; |
195 | 195 |
196 BookmarkNodeData bookmark_data; | 196 BookmarkNodeData bookmark_data; |
197 if (!bookmark_data.ReadFromClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE)) | 197 if (!bookmark_data.ReadFromClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE)) |
198 return; | 198 return; |
199 | 199 |
200 if (index == -1) | 200 if (index == -1) |
201 index = parent->child_count(); | 201 index = parent->child_count(); |
202 ScopedGroupBookmarkActions group_paste(model); | 202 bookmarks::ScopedGroupBookmarkActions group_paste(model); |
203 CloneBookmarkNode(model, bookmark_data.elements, parent, index, true); | 203 CloneBookmarkNode(model, bookmark_data.elements, parent, index, true); |
204 } | 204 } |
205 | 205 |
206 bool CanPasteFromClipboard(const BookmarkNode* node) { | 206 bool CanPasteFromClipboard(const BookmarkNode* node) { |
207 if (!node) | 207 if (!node) |
208 return false; | 208 return false; |
209 return BookmarkNodeData::ClipboardContainsBookmarks(); | 209 return BookmarkNodeData::ClipboardContainsBookmarks(); |
210 } | 210 } |
211 | 211 |
212 std::vector<const BookmarkNode*> GetMostRecentlyModifiedFolders( | 212 std::vector<const BookmarkNode*> GetMostRecentlyModifiedFolders( |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 base::string16 CleanUpTitleForMatching(const base::string16& title) { | 414 base::string16 CleanUpTitleForMatching(const base::string16& title) { |
415 return base::i18n::ToLower(title.substr(0u, kCleanedUpTitleMaxLength)); | 415 return base::i18n::ToLower(title.substr(0u, kCleanedUpTitleMaxLength)); |
416 } | 416 } |
417 | 417 |
418 } // namespace bookmark_utils | 418 } // namespace bookmark_utils |
419 | 419 |
420 const BookmarkNode* GetBookmarkNodeByID(const BookmarkModel* model, int64 id) { | 420 const BookmarkNode* GetBookmarkNodeByID(const BookmarkModel* model, int64 id) { |
421 // TODO(sky): TreeNode needs a method that visits all nodes using a predicate. | 421 // TODO(sky): TreeNode needs a method that visits all nodes using a predicate. |
422 return GetNodeByID(model->root_node(), id); | 422 return GetNodeByID(model->root_node(), id); |
423 } | 423 } |
OLD | NEW |