drag_source_win.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright (c) 2011 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_BASE_DRAGDROP_DRAG_SOURCE_WIN_H_
  5. #define UI_BASE_DRAGDROP_DRAG_SOURCE_WIN_H_
  6. #include <objidl.h>
  7. #include <wrl/implements.h>
  8. #include "base/component_export.h"
  9. #include "base/memory/raw_ptr.h"
  10. #include "base/memory/ref_counted.h"
  11. namespace ui {
  12. class OSExchangeData;
  13. // A base IDropSource implementation. Handles notifications sent by an active
  14. // drag-drop operation as the user mouses over other drop targets on their
  15. // system. This object tells Windows whether or not the drag should continue,
  16. // and supplies the appropriate cursors.
  17. class DragSourceWin
  18. : public Microsoft::WRL::RuntimeClass<
  19. Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::ClassicCom>,
  20. IDropSource> {
  21. public:
  22. // Factory method to avoid exporting the class and all it derives from.
  23. static COMPONENT_EXPORT(
  24. UI_BASE) Microsoft::WRL::ComPtr<DragSourceWin> Create();
  25. // Use Create() to construct these objects. Direct calls to the constructor
  26. // are an error - it is only public because a WRL helper function creates the
  27. // objects.
  28. DragSourceWin();
  29. DragSourceWin(const DragSourceWin&) = delete;
  30. DragSourceWin& operator=(const DragSourceWin&) = delete;
  31. ~DragSourceWin() override = default;
  32. // Stop the drag operation at the next chance we get. This doesn't
  33. // synchronously stop the drag (since Windows is controlling that),
  34. // but lets us tell Windows to cancel the drag the next chance we get.
  35. void CancelDrag() {
  36. cancel_drag_ = true;
  37. }
  38. // IDropSource implementation:
  39. HRESULT __stdcall QueryContinueDrag(BOOL escape_pressed,
  40. DWORD key_state) override;
  41. HRESULT __stdcall GiveFeedback(DWORD effect) override;
  42. // Used to set the active data object for the current drag operation. The
  43. // caller must ensure that |data| is not destroyed before the nested drag loop
  44. // terminates.
  45. void set_data(const OSExchangeData* data) { data_ = data; }
  46. protected:
  47. virtual void OnDragSourceCancel() {}
  48. virtual void OnDragSourceDrop();
  49. virtual void OnDragSourceMove() {}
  50. private:
  51. // Set to true if we want to cancel the drag operation.
  52. bool cancel_drag_;
  53. raw_ptr<const OSExchangeData> data_;
  54. };
  55. } // namespace ui
  56. #endif // UI_BASE_DRAGDROP_DRAG_SOURCE_WIN_H_