drag_drop_client_mac.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Copyright 2016 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_VIEWS_COCOA_DRAG_DROP_CLIENT_MAC_H_
  5. #define UI_VIEWS_COCOA_DRAG_DROP_CLIENT_MAC_H_
  6. #import <Cocoa/Cocoa.h>
  7. #include <memory>
  8. #include "base/callback.h"
  9. #include "base/memory/raw_ptr.h"
  10. #include "components/remote_cocoa/app_shim/drag_drop_client.h"
  11. #include "ui/base/dragdrop/mojom/drag_drop_types.mojom-forward.h"
  12. #include "ui/base/dragdrop/os_exchange_data.h"
  13. #include "ui/views/views_export.h"
  14. #include "ui/views/widget/drop_helper.h"
  15. namespace gfx {
  16. class Point;
  17. } // namespace gfx
  18. namespace remote_cocoa {
  19. class NativeWidgetNSWindowBridge;
  20. } // namespace remote_cocoa
  21. namespace views {
  22. namespace test {
  23. class DragDropClientMacTest;
  24. } // namespace test
  25. class View;
  26. // Implements drag and drop on MacViews. This class acts as a bridge between
  27. // the Views and native system's drag and drop. This class mimics
  28. // DesktopDragDropClientAuraX11.
  29. class VIEWS_EXPORT DragDropClientMac : public remote_cocoa::DragDropClient {
  30. public:
  31. DragDropClientMac(remote_cocoa::NativeWidgetNSWindowBridge* bridge,
  32. View* root_view);
  33. DragDropClientMac(const DragDropClientMac&) = delete;
  34. DragDropClientMac& operator=(const DragDropClientMac&) = delete;
  35. ~DragDropClientMac() override;
  36. // Initiates a drag and drop session. Returns the drag operation that was
  37. // applied at the end of the drag drop session.
  38. void StartDragAndDrop(View* view,
  39. std::unique_ptr<ui::OSExchangeData> data,
  40. int operation,
  41. ui::mojom::DragEventSource source);
  42. DropHelper* drop_helper() { return &drop_helper_; }
  43. // remote_cocoa::DragDropClient:
  44. NSDragOperation DragUpdate(id<NSDraggingInfo>) override;
  45. NSDragOperation Drop(id<NSDraggingInfo> sender) override;
  46. void EndDrag() override;
  47. void DragExit() override;
  48. private:
  49. friend class test::DragDropClientMacTest;
  50. // Converts the given NSPoint to the coordinate system in Views.
  51. gfx::Point LocationInView(NSPoint point) const;
  52. // Provides the data for the drag and drop session.
  53. std::unique_ptr<ui::OSExchangeData> exchange_data_;
  54. // Used to handle drag and drop with Views.
  55. DropHelper drop_helper_;
  56. // The drag and drop operation.
  57. int source_operation_ = 0;
  58. int last_operation_ = 0;
  59. // The bridge between the content view and the drag drop client.
  60. raw_ptr<remote_cocoa::NativeWidgetNSWindowBridge>
  61. bridge_; // Weak. Owns |this|.
  62. // The closure for the drag and drop's run loop.
  63. base::OnceClosure quit_closure_;
  64. // Whether |this| is the source of current dragging session.
  65. bool is_drag_source_ = false;
  66. };
  67. } // namespace views
  68. #endif // UI_VIEWS_COCOA_DRAG_DROP_CLIENT_MAC_H_