window_move_loop.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 COMPONENTS_REMOTE_COCOA_APP_SHIM_WINDOW_MOVE_LOOP_H_
  5. #define COMPONENTS_REMOTE_COCOA_APP_SHIM_WINDOW_MOVE_LOOP_H_
  6. #include "base/memory/raw_ptr.h"
  7. #import <Cocoa/Cocoa.h>
  8. #include "base/callback.h"
  9. #include "base/memory/weak_ptr.h"
  10. #include "ui/gfx/mac/scoped_cocoa_disable_screen_updates.h"
  11. namespace remote_cocoa {
  12. class NativeWidgetNSWindowBridge;
  13. // Used by NativeWidgetNSWindowBridge when dragging detached tabs.
  14. class CocoaWindowMoveLoop {
  15. public:
  16. CocoaWindowMoveLoop(NativeWidgetNSWindowBridge* owner,
  17. const NSPoint& initial_mouse_in_screen);
  18. CocoaWindowMoveLoop(const CocoaWindowMoveLoop&) = delete;
  19. CocoaWindowMoveLoop& operator=(const CocoaWindowMoveLoop&) = delete;
  20. ~CocoaWindowMoveLoop();
  21. // Initiates the drag until a mouse up event is observed, or End() is called.
  22. // Returns true if a mouse up event ended the loop.
  23. bool Run();
  24. void End();
  25. private:
  26. enum LoopExitReason {
  27. ENDED_EXTERNALLY,
  28. MOUSE_UP,
  29. WINDOW_DESTROYED,
  30. };
  31. raw_ptr<NativeWidgetNSWindowBridge> owner_; // Weak. Owns this.
  32. // Initial mouse location at the time before the CocoaWindowMoveLoop is
  33. // created.
  34. NSPoint initial_mouse_in_screen_;
  35. // Pointer to a stack variable holding the exit reason.
  36. raw_ptr<LoopExitReason> exit_reason_ref_ = nullptr;
  37. base::OnceClosure quit_closure_;
  38. std::unique_ptr<gfx::ScopedCocoaDisableScreenUpdates> screen_disabler_;
  39. // WeakPtrFactory for event monitor safety.
  40. base::WeakPtrFactory<CocoaWindowMoveLoop> weak_factory_;
  41. };
  42. } // namespace remote_cocoa
  43. #endif // COMPONENTS_REMOTE_COCOA_APP_SHIM_WINDOW_MOVE_LOOP_H_