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