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.
5 #ifndef UI_VIEWS_COCOA_COCOA_MOUSE_CAPTURE_H_
6 #define UI_VIEWS_COCOA_COCOA_MOUSE_CAPTURE_H_
8 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "ui/views/views_export.h"
14 class CocoaMouseCaptureDelegate
;
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
{
23 explicit CocoaMouseCapture(CocoaMouseCaptureDelegate
* delegate
);
26 // True if the event tap is active (i.e. not stolen by a later instance).
27 bool IsActive() const { return active_handle_
; }
32 // Deactivates the event tap if still active.
33 void OnOtherClientGotCapture();
35 CocoaMouseCaptureDelegate
* delegate_
; // Weak. Owns this.
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_
;
41 DISALLOW_COPY_AND_ASSIGN(CocoaMouseCapture
);
46 #endif // UI_VIEWS_COCOA_COCOA_MOUSE_CAPTURE_H_