scoped_drag_drop_observer.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright 2021 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 ASH_DRAG_DROP_SCOPED_DRAG_DROP_OBSERVER_H_
  5. #define ASH_DRAG_DROP_SCOPED_DRAG_DROP_OBSERVER_H_
  6. #include "ash/shell.h"
  7. #include "ash/shell_observer.h"
  8. #include "base/scoped_observation.h"
  9. #include "ui/aura/client/drag_drop_client.h"
  10. #include "ui/aura/client/drag_drop_client_observer.h"
  11. namespace ui {
  12. class DropTargetEvent;
  13. } // namespace ui
  14. namespace ash {
  15. // A class which observes an `aura::client::DragDropClient` for the scope of its
  16. // existence. Drag events are passed to a callback supplied in the constructor.
  17. class ASH_EXPORT ScopedDragDropObserver
  18. : public aura::client::DragDropClientObserver,
  19. public ShellObserver {
  20. public:
  21. ScopedDragDropObserver(
  22. aura::client::DragDropClient* client,
  23. base::RepeatingCallback<void(const ui::DropTargetEvent*)> event_callback);
  24. ScopedDragDropObserver(const ScopedDragDropObserver&) = delete;
  25. ScopedDragDropObserver& operator=(const ScopedDragDropObserver&) = delete;
  26. ~ScopedDragDropObserver() override;
  27. private:
  28. // aura::client::DragDropClientObserver:
  29. void OnDragUpdated(const ui::DropTargetEvent& event) override;
  30. void OnDragCompleted(const ui::DropTargetEvent& event) override;
  31. void OnDragCancelled() override;
  32. // ShellObserver:
  33. void OnShellDestroying() override;
  34. base::RepeatingCallback<void(const ui::DropTargetEvent*)> event_callback_;
  35. base::ScopedObservation<aura::client::DragDropClient,
  36. aura::client::DragDropClientObserver>
  37. drag_drop_client_observer_{this};
  38. base::ScopedObservation<Shell,
  39. ShellObserver,
  40. &Shell::AddShellObserver,
  41. &Shell::RemoveShellObserver>
  42. shell_observer_{this};
  43. };
  44. } // namespace ash
  45. #endif // ASH_DRAG_DROP_SCOPED_DRAG_DROP_OBSERVER_H_