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