| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_VIEWS_COCOA_COCOA_MOUSE_CAPTURE_H_ | 5 #ifndef UI_VIEWS_COCOA_COCOA_MOUSE_CAPTURE_H_ |
| 6 #define UI_VIEWS_COCOA_COCOA_MOUSE_CAPTURE_H_ | 6 #define UI_VIEWS_COCOA_COCOA_MOUSE_CAPTURE_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "ui/views/views_export.h" | 11 #include "ui/views/views_export.h" |
| 12 | 12 |
| 13 @class NSWindow; |
| 14 |
| 13 namespace views { | 15 namespace views { |
| 14 | 16 |
| 15 class CocoaMouseCaptureDelegate; | 17 class CocoaMouseCaptureDelegate; |
| 16 | 18 |
| 17 // Basic mouse capture to simulate ::SetCapture() from Windows. This is used to | 19 // Basic mouse capture to simulate ::SetCapture() from Windows. This is used to |
| 18 // support menu widgets (e.g. on Combo boxes). Clicking anywhere other than the | 20 // support menu widgets (e.g. on Combo boxes). Clicking anywhere other than the |
| 19 // menu should dismiss the menu and "swallow" the mouse event. All events are | 21 // menu should dismiss the menu and "swallow" the mouse event. All events are |
| 20 // forwarded, but only events to the same application are "swallowed", which is | 22 // forwarded, but only events to the same application are "swallowed", which is |
| 21 // consistent with how native NSMenus behave. | 23 // consistent with how native NSMenus behave. |
| 22 class VIEWS_EXPORT CocoaMouseCapture { | 24 class VIEWS_EXPORT CocoaMouseCapture { |
| 23 public: | 25 public: |
| 24 explicit CocoaMouseCapture(CocoaMouseCaptureDelegate* delegate); | 26 explicit CocoaMouseCapture(CocoaMouseCaptureDelegate* delegate); |
| 25 ~CocoaMouseCapture(); | 27 ~CocoaMouseCapture(); |
| 26 | 28 |
| 29 // Returns the NSWindow with capture or nil if no window has capture |
| 30 // currently. |
| 31 static NSWindow* GetGlobalCaptureWindow(); |
| 32 |
| 27 // True if the event tap is active (i.e. not stolen by a later instance). | 33 // True if the event tap is active (i.e. not stolen by a later instance). |
| 28 bool IsActive() const { return !!active_handle_; } | 34 bool IsActive() const { return !!active_handle_; } |
| 29 | 35 |
| 30 private: | 36 private: |
| 31 class ActiveEventTap; | 37 class ActiveEventTap; |
| 32 | 38 |
| 33 // Deactivates the event tap if still active. | 39 // Deactivates the event tap if still active. |
| 34 void OnOtherClientGotCapture(); | 40 void OnOtherClientGotCapture(); |
| 35 | 41 |
| 36 CocoaMouseCaptureDelegate* delegate_; // Weak. Owns this. | 42 CocoaMouseCaptureDelegate* delegate_; // Weak. Owns this. |
| 37 | 43 |
| 38 // The active event tap for this capture. Owned by this, but can be cleared | 44 // The active event tap for this capture. Owned by this, but can be cleared |
| 39 // out early if another instance of CocoaMouseCapture is created. | 45 // out early if another instance of CocoaMouseCapture is created. |
| 40 std::unique_ptr<ActiveEventTap> active_handle_; | 46 std::unique_ptr<ActiveEventTap> active_handle_; |
| 41 | 47 |
| 42 DISALLOW_COPY_AND_ASSIGN(CocoaMouseCapture); | 48 DISALLOW_COPY_AND_ASSIGN(CocoaMouseCapture); |
| 43 }; | 49 }; |
| 44 | 50 |
| 45 } // namespace views | 51 } // namespace views |
| 46 | 52 |
| 47 #endif // UI_VIEWS_COCOA_COCOA_MOUSE_CAPTURE_H_ | 53 #endif // UI_VIEWS_COCOA_COCOA_MOUSE_CAPTURE_H_ |
| OLD | NEW |