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.
|
|
|
|
|
2019-06-19 20:46:59 +00:00
|
|
|
#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.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"
|
2017-06-30 10:57:56 +00:00
|
|
|
#include "ui/views/button_drag_utils.h"
|
2016-07-03 05:34:35 +00:00
|
|
|
#include "ui/views/widget/widget.h"
|
2017-06-30 10:57:56 +00:00
|
|
|
#include "url/gurl.h"
|
2016-07-03 05:34:35 +00:00
|
|
|
|
2019-06-19 21:23:04 +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
|
2019-07-24 22:58:51 +00:00
|
|
|
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,
|
2019-07-24 22:58:51 +00:00
|
|
|
*views::Widget::GetTopLevelWidgetForNativeView(view), data.get());
|
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()));
|
|
|
|
}
|
2019-07-24 22:58:51 +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(
|
2019-07-24 22:58:51 +00:00
|
|
|
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
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|