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"
|
2021-03-04 17:27:05 +00:00
|
|
|
#include "ui/base/clipboard/file_info.h"
|
2016-07-03 05:34:35 +00:00
|
|
|
#include "ui/base/dragdrop/drag_drop_types.h"
|
2020-08-12 18:33:58 +00:00
|
|
|
#include "ui/base/dragdrop/mojom/drag_drop_types.mojom-shared.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"
|
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
|
|
|
|
2016-07-03 03:26:43 +00:00
|
|
|
namespace electron {
|
|
|
|
|
2016-07-03 05:34:35 +00:00
|
|
|
void DragFileItems(const std::vector<base::FilePath>& files,
|
|
|
|
const gfx::Image& icon,
|
|
|
|
gfx::NativeView view) {
|
2023-01-09 09:00:47 +00:00
|
|
|
aura::Window* root_window = view->GetRootWindow();
|
|
|
|
if (!root_window || !aura::client::GetDragDropClient(root_window))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// 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
|
|
|
|
2021-11-24 08:45:59 +00:00
|
|
|
button_drag_utils::SetDragImage(GURL(), files[0].LossyDisplayName(),
|
|
|
|
icon.AsImageSkia(), nullptr, data.get());
|
2016-07-03 05:34:35 +00:00
|
|
|
|
|
|
|
std::vector<ui::FileInfo> file_infos;
|
2019-09-13 14:26:59 +00:00
|
|
|
file_infos.reserve(files.size());
|
2016-07-03 05:34:35 +00:00
|
|
|
for (const base::FilePath& file : files) {
|
2019-09-13 14:26:59 +00:00
|
|
|
file_infos.emplace_back(file, base::FilePath());
|
2016-07-03 05:34:35 +00:00
|
|
|
}
|
2019-07-24 22:58:51 +00:00
|
|
|
data->SetFilenames(file_infos);
|
2016-07-03 05:34:35 +00:00
|
|
|
|
2016-07-04 06:08:55 +00:00
|
|
|
gfx::Point location = display::Screen::GetScreen()->GetCursorScreenPoint();
|
2020-08-12 18:33:58 +00:00
|
|
|
// TODO(varunjain): Properly determine and send DragEventSource 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,
|
2020-08-12 18:33:58 +00:00
|
|
|
ui::mojom::DragEventSource::kMouse);
|
2016-07-03 05:34:35 +00:00
|
|
|
}
|
2016-07-03 03:26:43 +00:00
|
|
|
|
|
|
|
} // namespace electron
|