1 // Copyright (c) 2016 GitHub, Inc.
2 // Use of this source code is governed by the MIT license that can be
3 // found in the LICENSE file.
5 #include "atom/browser/ui/drag_util.h"
7 #include "ui/aura/window.h"
8 #include "ui/base/dragdrop/drag_drop_types.h"
9 #include "ui/base/dragdrop/drag_utils.h"
10 #include "ui/base/dragdrop/file_info.h"
11 #include "ui/base/dragdrop/os_exchange_data.h"
12 #include "ui/display/screen.h"
13 #include "ui/gfx/geometry/point.h"
14 #include "ui/views/widget/widget.h"
15 #include "ui/aura/client/drag_drop_client.h"
19 void DragFileItems(const std::vector<base::FilePath>& files,
20 const gfx::Image& icon,
21 gfx::NativeView view) {
22 // Set up our OLE machinery
23 ui::OSExchangeData data;
25 drag_utils::CreateDragImageForFile(files[0], icon.AsImageSkia(), &data);
27 std::vector<ui::FileInfo> file_infos;
28 for (const base::FilePath& file : files) {
29 file_infos.push_back(ui::FileInfo(file, base::FilePath()));
31 data.SetFilenames(file_infos);
33 aura::Window* root_window = view->GetRootWindow();
34 if (!root_window || !aura::client::GetDragDropClient(root_window))
37 gfx::Point location = display::Screen::GetScreen()->GetCursorScreenPoint();
38 // TODO(varunjain): Properly determine and send DRAG_EVENT_SOURCE below.
39 aura::client::GetDragDropClient(root_window)->StartDragAndDrop(
44 ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK,
45 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE);