data_device.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_EXO_DATA_DEVICE_H_
  5. #define COMPONENTS_EXO_DATA_DEVICE_H_
  6. #include <cstdint>
  7. #include "base/memory/weak_ptr.h"
  8. #include "components/exo/data_offer_observer.h"
  9. #include "components/exo/seat_observer.h"
  10. #include "components/exo/surface.h"
  11. #include "components/exo/surface_observer.h"
  12. #include "ui/base/clipboard/clipboard_observer.h"
  13. #include "ui/base/dragdrop/mojom/drag_drop_types.mojom-forward.h"
  14. namespace ui {
  15. class DropTargetEvent;
  16. }
  17. namespace exo {
  18. class DataDeviceDelegate;
  19. class DataOffer;
  20. class ScopedDataOffer;
  21. class DataSource;
  22. class Seat;
  23. class ScopedSurface;
  24. enum class DndAction { kNone, kCopy, kMove, kAsk };
  25. // DataDevice to start drag and drop and copy and paste oprations.
  26. class DataDevice : public WMHelper::DragDropObserver,
  27. public DataOfferObserver,
  28. public ui::ClipboardObserver,
  29. public SurfaceObserver,
  30. public SeatObserver {
  31. public:
  32. DataDevice(DataDeviceDelegate* delegate, Seat* seat);
  33. DataDevice(const DataDevice&) = delete;
  34. DataDevice& operator=(const DataDevice&) = delete;
  35. ~DataDevice() override;
  36. // Starts drag-and-drop operation.
  37. // |source| represents data comes from the client starting drag operation. Can
  38. // be null if the data will be transferred only in the client. |origin| is
  39. // the surface which starts the drag and drop operation. |icon| is the
  40. // nullable image which is rendered at the next to cursor while drag
  41. // operation.
  42. void StartDrag(DataSource* source,
  43. Surface* origin,
  44. Surface* icon,
  45. ui::mojom::DragEventSource event_source);
  46. // Sets selection data to the clipboard.
  47. // |source| represents data comes from the client.
  48. void SetSelection(DataSource* source);
  49. // Overridden from WMHelper::DragDropObserver:
  50. void OnDragEntered(const ui::DropTargetEvent& event) override;
  51. aura::client::DragUpdateInfo OnDragUpdated(
  52. const ui::DropTargetEvent& event) override;
  53. void OnDragExited() override;
  54. WMHelper::DragDropObserver::DropCallback GetDropCallback() override;
  55. // Overridden from ui::ClipboardObserver:
  56. void OnClipboardDataChanged() override;
  57. // Overridden from SeatObserver:
  58. void OnSurfaceFocused(Surface* surface,
  59. Surface* lost_focus,
  60. bool has_focused_client) override;
  61. // Overridden from DataOfferObserver:
  62. void OnDataOfferDestroying(DataOffer* data_offer) override;
  63. // Overridden from SurfaceObserver:
  64. void OnSurfaceDestroying(Surface* surface) override;
  65. DataDeviceDelegate* get_delegate() { return delegate_; }
  66. private:
  67. Surface* GetEffectiveTargetForEvent(const ui::DropTargetEvent& event) const;
  68. void SetSelectionToCurrentClipboardData();
  69. void PerformDropOrExitDrag(base::ScopedClosureRunner exit_drag,
  70. ui::mojom::DragOperation& output_drag_op);
  71. DataDeviceDelegate* const delegate_;
  72. Seat* const seat_;
  73. std::unique_ptr<ScopedDataOffer> data_offer_;
  74. std::unique_ptr<ScopedSurface> focused_surface_;
  75. base::OnceClosure quit_closure_;
  76. bool drop_succeeded_;
  77. base::WeakPtrFactory<DataDevice> drop_weak_factory_{this};
  78. base::WeakPtrFactory<DataDevice> weak_factory_{this};
  79. };
  80. } // namespace exo
  81. #endif // COMPONENTS_EXO_DATA_DEVICE_H_