scoped_drag_drop_observer.cc 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. #include "ash/drag_drop/scoped_drag_drop_observer.h"
  5. #include "ash/shell.h"
  6. #include "ash/shell_observer.h"
  7. #include "base/scoped_observation.h"
  8. namespace ui {
  9. class DropTargetEvent;
  10. } // namespace ui
  11. namespace ash {
  12. ScopedDragDropObserver::ScopedDragDropObserver(
  13. aura::client::DragDropClient* client,
  14. base::RepeatingCallback<void(const ui::DropTargetEvent*)> event_callback)
  15. : event_callback_(std::move(event_callback)) {
  16. drag_drop_client_observer_.Observe(client);
  17. shell_observer_.Observe(ash::Shell::Get());
  18. }
  19. ScopedDragDropObserver::~ScopedDragDropObserver() = default;
  20. void ScopedDragDropObserver::OnDragUpdated(const ui::DropTargetEvent& event) {
  21. event_callback_.Run(&event);
  22. }
  23. void ScopedDragDropObserver::OnDragCompleted(const ui::DropTargetEvent& event) {
  24. event_callback_.Run(/*event=*/nullptr);
  25. }
  26. void ScopedDragDropObserver::OnDragCancelled() {
  27. event_callback_.Run(/*event=*/nullptr);
  28. }
  29. void ScopedDragDropObserver::OnShellDestroying() {
  30. drag_drop_client_observer_.Reset();
  31. }
  32. } // namespace ash