1 // Copyright 2012 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 "base/message_loop/message_loop.h"
8 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "components/bookmarks/browser/bookmark_model.h"
11 #include "components/bookmarks/browser/bookmark_node_data.h"
12 #include "components/bookmarks/browser/bookmark_utils.h"
13 #include "ui/base/dragdrop/drag_drop_types.h"
14 #include "ui/base/dragdrop/os_exchange_data.h"
15 #include "ui/views/drag_utils.h"
16 #include "ui/views/widget/widget.h"
18 using bookmarks::BookmarkModel
;
19 using bookmarks::BookmarkNode
;
23 void DragBookmarks(Profile
* profile
,
24 const std::vector
<const BookmarkNode
*>& nodes
,
26 ui::DragDropTypes::DragEventSource source
) {
27 DCHECK(!nodes
.empty());
29 // Set up our OLE machinery.
30 ui::OSExchangeData data
;
31 bookmarks::BookmarkNodeData
drag_data(nodes
);
32 drag_data
.Write(profile
->GetPath(), &data
);
34 // Allow nested message loop so we get DnD events as we drag this around.
35 base::MessageLoop::ScopedNestableTaskAllower
nestable_task_allower(
36 base::MessageLoop::current());
38 int operation
= ui::DragDropTypes::DRAG_COPY
| ui::DragDropTypes::DRAG_LINK
;
39 BookmarkModel
* model
= BookmarkModelFactory::GetForProfile(profile
);
40 if (bookmarks::CanAllBeEditedByUser(model
->client(), nodes
))
41 operation
|= ui::DragDropTypes::DRAG_MOVE
;
43 views::Widget
* widget
= views::Widget::GetWidgetForNativeView(view
);
46 widget
->RunShellDrag(NULL
, data
, gfx::Point(), operation
, source
);
48 // We hit this case when we're using WebContentsViewWin or
49 // WebContentsViewAura, instead of WebContentsViewViews.
50 views::RunShellDrag(view
, data
, gfx::Point(), operation
, source
);