drag_drop_delegate.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Copyright (c) 2012 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 UI_AURA_CLIENT_DRAG_DROP_DELEGATE_H_
  5. #define UI_AURA_CLIENT_DRAG_DROP_DELEGATE_H_
  6. #include <memory>
  7. #include "base/callback.h"
  8. #include "ui/aura/aura_export.h"
  9. #include "ui/aura/window.h"
  10. #include "ui/base/data_transfer_policy/data_transfer_endpoint.h"
  11. #include "ui/base/dragdrop/drag_drop_types.h"
  12. #include "ui/base/dragdrop/mojom/drag_drop_types.mojom-forward.h"
  13. #include "ui/base/dragdrop/os_exchange_data.h"
  14. namespace ui {
  15. class DropTargetEvent;
  16. }
  17. namespace aura {
  18. class Window;
  19. namespace client {
  20. struct AURA_EXPORT DragUpdateInfo {
  21. DragUpdateInfo();
  22. DragUpdateInfo(int op, ui::DataTransferEndpoint endpoint);
  23. DragUpdateInfo(const DragUpdateInfo& update_info);
  24. DragUpdateInfo& operator=(const DragUpdateInfo& update_info);
  25. // A bitmask of the DragDropTypes::DragOperation supported.
  26. int drag_operation = ui::DragDropTypes::DRAG_NONE;
  27. // An object representing the destination window.
  28. ui::DataTransferEndpoint data_endpoint{ui::EndpointType::kDefault};
  29. };
  30. // Delegate interface for drag and drop actions on aura::Window.
  31. class AURA_EXPORT DragDropDelegate {
  32. public:
  33. // Callback emitted by GetDropCallback used to handle deferred drop events.
  34. // Note that it does not contain a location. If implementers need a location,
  35. // they should bind it in GetDropCallback. See crbug.com/1289902.
  36. using DropCallback =
  37. base::OnceCallback<void(std::unique_ptr<ui::OSExchangeData> data,
  38. ui::mojom::DragOperation& output_drag_op)>;
  39. // OnDragEntered is invoked when the mouse enters this window during a drag &
  40. // drop session. This is immediately followed by an invocation of
  41. // OnDragUpdated, and eventually one of OnDragExited, or GetDropCallback.
  42. virtual void OnDragEntered(const ui::DropTargetEvent& event) = 0;
  43. // Invoked during a drag and drop session while the mouse is over the window.
  44. // This should return DragUpdateInfo object based on the location of the
  45. // event.
  46. virtual DragUpdateInfo OnDragUpdated(const ui::DropTargetEvent& event) = 0;
  47. // Invoked during a drag and drop session when the mouse exits the window, or
  48. // when the drag session was canceled and the mouse was over the window.
  49. virtual void OnDragExited() = 0;
  50. // Invoked during a drag and drop session when the user release the mouse, but
  51. // the drop is held because of the DataTransferPolicyController.
  52. // The returned callback may be NullCallback if there's nothing to do and the
  53. // drop event is ignored.
  54. virtual DropCallback GetDropCallback(const ui::DropTargetEvent& event) = 0;
  55. protected:
  56. virtual ~DragDropDelegate() {}
  57. };
  58. AURA_EXPORT void SetDragDropDelegate(Window* window,
  59. DragDropDelegate* delegate);
  60. AURA_EXPORT DragDropDelegate* GetDragDropDelegate(Window* window);
  61. AURA_EXPORT extern const WindowProperty<DragDropDelegate*>* const
  62. kDragDropDelegateKey;
  63. } // namespace client
  64. } // namespace aura
  65. #endif // UI_AURA_CLIENT_DRAG_DROP_DELEGATE_H_