OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ui/bookmarks/bookmark_drag_drop.h" | 5 #include "chrome/browser/ui/bookmarks/bookmark_drag_drop.h" |
6 | 6 |
7 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 7 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/undo/bookmark_undo_service_factory.h" | 9 #include "chrome/browser/undo/bookmark_undo_service_factory.h" |
10 #include "components/bookmarks/browser/bookmark_client.h" | |
11 #include "components/bookmarks/browser/bookmark_model.h" | 10 #include "components/bookmarks/browser/bookmark_model.h" |
12 #include "components/bookmarks/browser/bookmark_node_data.h" | 11 #include "components/bookmarks/browser/bookmark_node_data.h" |
13 #include "components/bookmarks/browser/bookmark_utils.h" | 12 #include "components/bookmarks/browser/bookmark_utils.h" |
14 #include "components/bookmarks/browser/scoped_group_bookmark_actions.h" | 13 #include "components/bookmarks/browser/scoped_group_bookmark_actions.h" |
15 #include "components/undo/bookmark_undo_service.h" | 14 #include "components/undo/bookmark_undo_service.h" |
16 #include "ui/base/dragdrop/drag_drop_types.h" | 15 #include "ui/base/dragdrop/drag_drop_types.h" |
17 | 16 |
18 using bookmarks::BookmarkModel; | 17 using bookmarks::BookmarkModel; |
19 using bookmarks::BookmarkNode; | 18 using bookmarks::BookmarkNode; |
20 using bookmarks::BookmarkNodeData; | 19 using bookmarks::BookmarkNodeData; |
21 | 20 |
22 namespace chrome { | 21 namespace chrome { |
23 | 22 |
24 int DropBookmarks(Profile* profile, | 23 int DropBookmarks(Profile* profile, |
25 const BookmarkNodeData& data, | 24 const BookmarkNodeData& data, |
26 const BookmarkNode* parent_node, | 25 const BookmarkNode* parent_node, |
27 int index, | 26 int index, |
28 bool copy) { | 27 bool copy) { |
29 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile); | 28 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile); |
30 #if !defined(OS_ANDROID) | 29 #if !defined(OS_ANDROID) |
31 bookmarks::ScopedGroupBookmarkActions group_drops(model); | 30 bookmarks::ScopedGroupBookmarkActions group_drops(model); |
32 #endif | 31 #endif |
33 if (data.IsFromProfilePath(profile->GetPath())) { | 32 if (data.IsFromProfilePath(profile->GetPath())) { |
34 const std::vector<const BookmarkNode*> dragged_nodes = | 33 const std::vector<const BookmarkNode*> dragged_nodes = |
35 data.GetNodes(model, profile->GetPath()); | 34 data.GetNodes(model, profile->GetPath()); |
36 DCHECK(model->client()->CanBeEditedByUser(parent_node)); | 35 DCHECK(model->CanBeEditedByUser(parent_node)); |
37 DCHECK(copy || | 36 DCHECK(copy || bookmarks::CanAllBeEditedByUser(model, dragged_nodes)); |
38 bookmarks::CanAllBeEditedByUser(model->client(), dragged_nodes)); | |
39 if (!dragged_nodes.empty()) { | 37 if (!dragged_nodes.empty()) { |
40 // Drag from same profile. Copy or move nodes. | 38 // Drag from same profile. Copy or move nodes. |
41 for (size_t i = 0; i < dragged_nodes.size(); ++i) { | 39 for (size_t i = 0; i < dragged_nodes.size(); ++i) { |
42 if (copy) { | 40 if (copy) { |
43 model->Copy(dragged_nodes[i], parent_node, index); | 41 model->Copy(dragged_nodes[i], parent_node, index); |
44 } else { | 42 } else { |
45 model->Move(dragged_nodes[i], parent_node, index); | 43 model->Move(dragged_nodes[i], parent_node, index); |
46 } | 44 } |
47 index = parent_node->GetIndexOf(dragged_nodes[i]) + 1; | 45 index = parent_node->GetIndexOf(dragged_nodes[i]) + 1; |
48 } | 46 } |
49 return copy ? ui::DragDropTypes::DRAG_COPY : ui::DragDropTypes::DRAG_MOVE; | 47 return copy ? ui::DragDropTypes::DRAG_COPY : ui::DragDropTypes::DRAG_MOVE; |
50 } | 48 } |
51 return ui::DragDropTypes::DRAG_NONE; | 49 return ui::DragDropTypes::DRAG_NONE; |
52 } | 50 } |
53 // Dropping a folder from different profile. Always accept. | 51 // Dropping a folder from different profile. Always accept. |
54 bookmarks::CloneBookmarkNode(model, data.elements, parent_node, index, true); | 52 bookmarks::CloneBookmarkNode(model, data.elements, parent_node, index, true); |
55 return ui::DragDropTypes::DRAG_COPY; | 53 return ui::DragDropTypes::DRAG_COPY; |
56 } | 54 } |
57 | 55 |
58 } // namespace chrome | 56 } // namespace chrome |
OLD | NEW |