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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/bookmarks/bookmark_drag_drop.h"
7 #include "chrome/browser/bookmarks/bookmark_model.h"
8 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
9 #include "chrome/browser/bookmarks/bookmark_node_data.h"
10 #include "chrome/browser/bookmarks/bookmark_utils.h"
11 #include "chrome/browser/undo/bookmark_undo_service.h"
12 #include "chrome/browser/undo/bookmark_undo_service_factory.h"
13 #include "chrome/browser/undo/undo_manager_utils.h"
14 #include "ui/base/dragdrop/drag_drop_types.h"
18 int DropBookmarks(Profile
* profile
,
19 const BookmarkNodeData
& data
,
20 const BookmarkNode
* parent_node
,
22 #if !defined(OS_ANDROID)
23 ScopedGroupingAction
group_drops(
24 BookmarkUndoServiceFactory::GetForProfile(profile
)->undo_manager());
26 BookmarkModel
* model
= BookmarkModelFactory::GetForProfile(profile
);
27 if (data
.IsFromProfile(profile
)) {
28 const std::vector
<const BookmarkNode
*> dragged_nodes
=
29 data
.GetNodes(profile
);
30 if (!dragged_nodes
.empty()) {
31 // Drag from same profile. Move nodes.
32 for (size_t i
= 0; i
< dragged_nodes
.size(); ++i
) {
33 model
->Move(dragged_nodes
[i
], parent_node
, index
);
34 index
= parent_node
->GetIndexOf(dragged_nodes
[i
]) + 1;
36 return ui::DragDropTypes::DRAG_MOVE
;
38 return ui::DragDropTypes::DRAG_NONE
;
40 // Dropping a folder from different profile. Always accept.
41 bookmark_utils::CloneBookmarkNode(model
, data
.elements
, parent_node
,
43 return ui::DragDropTypes::DRAG_COPY
;