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