electron/shell/browser/ui/drag_util_views.cc

51 lines
1.7 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 "shell/browser/ui/drag_util.h"
2016-07-03 03:26:43 +00:00
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/file_info.h"
2016-07-03 05:34:35 +00:00
#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
namespace electron {
2016-07-03 03:26:43 +00:00
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
auto data = std::make_unique<ui::OSExchangeData>();
2016-07-03 05:34:35 +00:00
2018-04-18 01:55:30 +00:00
button_drag_utils::SetDragImage(
GURL(), files[0].LossyDisplayName(), icon.AsImageSkia(), nullptr,
*views::Widget::GetTopLevelWidgetForNativeView(view), data.get());
2016-07-03 05:34:35 +00:00
std::vector<ui::FileInfo> file_infos;
file_infos.reserve(files.size());
2016-07-03 05:34:35 +00:00
for (const base::FilePath& file : files) {
file_infos.emplace_back(file, base::FilePath());
2016-07-03 05:34:35 +00:00
}
data->SetFilenames(file_infos);
2016-07-03 05:34:35 +00:00
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(
std::move(data), root_window, view, location,
2018-04-18 01:55:30 +00:00
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 electron