drag_util_views.cc 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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.
  4. #include "atom/browser/ui/drag_util.h"
  5. #include "ui/aura/client/drag_drop_client.h"
  6. #include "ui/aura/window.h"
  7. #include "ui/base/dragdrop/drag_drop_types.h"
  8. #include "ui/base/dragdrop/file_info.h"
  9. #include "ui/base/dragdrop/os_exchange_data.h"
  10. #include "ui/display/screen.h"
  11. #include "ui/gfx/geometry/point.h"
  12. #include "ui/views/button_drag_utils.h"
  13. #include "ui/views/widget/widget.h"
  14. #include "url/gurl.h"
  15. namespace atom {
  16. void DragFileItems(const std::vector<base::FilePath>& files,
  17. const gfx::Image& icon,
  18. gfx::NativeView view) {
  19. // Set up our OLE machinery
  20. ui::OSExchangeData data;
  21. button_drag_utils::SetDragImage(
  22. GURL(), files[0].LossyDisplayName(), icon.AsImageSkia(), nullptr,
  23. *views::Widget::GetTopLevelWidgetForNativeView(view), &data);
  24. std::vector<ui::FileInfo> file_infos;
  25. for (const base::FilePath& file : files) {
  26. file_infos.push_back(ui::FileInfo(file, base::FilePath()));
  27. }
  28. data.SetFilenames(file_infos);
  29. aura::Window* root_window = view->GetRootWindow();
  30. if (!root_window || !aura::client::GetDragDropClient(root_window))
  31. return;
  32. gfx::Point location = display::Screen::GetScreen()->GetCursorScreenPoint();
  33. // TODO(varunjain): Properly determine and send DRAG_EVENT_SOURCE below.
  34. aura::client::GetDragDropClient(root_window)
  35. ->StartDragAndDrop(
  36. data, root_window, view, location,
  37. ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK,
  38. ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE);
  39. }
  40. } // namespace atom