electron/atom/browser/ui/drag_util_views.cc

50 lines
1.6 KiB
C++
Raw Normal View History

2016-07-03 03:26:43 +00:00
// Copyright (c) 2016 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "atom/browser/ui/drag_util.h"
2017-01-26 07:21:26 +00:00
#include "ui/aura/client/drag_drop_client.h"
2016-07-03 05:34:35 +00:00
#include "ui/aura/window.h"
#include "ui/base/dragdrop/drag_drop_types.h"
#include "ui/base/dragdrop/file_info.h"
#include "ui/base/dragdrop/os_exchange_data.h"
2016-07-04 06:08:55 +00:00
#include "ui/display/screen.h"
2016-08-26 22:30:02 +00:00
#include "ui/gfx/geometry/point.h"
#include "ui/views/button_drag_utils.h"
2016-07-03 05:34:35 +00:00
#include "ui/views/widget/widget.h"
#include "url/gurl.h"
2016-07-03 05:34:35 +00:00
2016-07-03 03:26:43 +00:00
namespace atom {
2016-07-03 05:34:35 +00:00
void DragFileItems(const std::vector<base::FilePath>& files,
const gfx::Image& icon,
gfx::NativeView view) {
// Set up our OLE machinery
ui::OSExchangeData data;
2018-04-18 01:55:30 +00:00
button_drag_utils::SetDragImage(
GURL(), files[0].LossyDisplayName(), icon.AsImageSkia(), nullptr,
*views::Widget::GetTopLevelWidgetForNativeView(view), &data);
2016-07-03 05:34:35 +00:00
std::vector<ui::FileInfo> file_infos;
for (const base::FilePath& file : files) {
file_infos.push_back(ui::FileInfo(file, base::FilePath()));
}
data.SetFilenames(file_infos);
aura::Window* root_window = view->GetRootWindow();
if (!root_window || !aura::client::GetDragDropClient(root_window))
return;
2016-07-03 03:26:43 +00:00
2016-07-04 06:08:55 +00:00
gfx::Point location = display::Screen::GetScreen()->GetCursorScreenPoint();
2016-07-03 05:34:35 +00:00
// TODO(varunjain): Properly determine and send DRAG_EVENT_SOURCE below.
2018-04-18 01:55:30 +00:00
aura::client::GetDragDropClient(root_window)
->StartDragAndDrop(
data, root_window, view, location,
ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK,
ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE);
2016-07-03 05:34:35 +00:00
}
2016-07-03 03:26:43 +00:00
} // namespace atom