1 // Copyright (c) 2011 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_BASE_COCOA_TRACKING_AREA_H_
6 #define UI_BASE_COCOA_TRACKING_AREA_H_
8 #import <AppKit/AppKit.h>
10 #include "base/mac/scoped_nsobject.h"
11 #include "ui/base/ui_base_export.h"
13 @
class CrTrackingAreaOwnerProxy
;
15 // The CrTrackingArea can be used in place of an NSTrackingArea to shut off
16 // messaging to the |owner| at a specific point in time.
18 @interface CrTrackingArea
: NSTrackingArea
{
20 base::scoped_nsobject
<CrTrackingAreaOwnerProxy
> ownerProxy_
;
23 // Designated initializer. Forwards all arguments to the superclass, but wraps
24 // |owner| in a proxy object.
25 - (id
)initWithRect
:(NSRect
)rect
26 options
:(NSTrackingAreaOptions
)options
28 userInfo
:(NSDictionary
*)userInfo
;
30 // Prevents any future messages from being delivered to the |owner|.
33 // Watches |window| for its NSWindowWillCloseNotification and calls
34 // |-clearOwner| when the notification is observed.
35 - (void)clearOwnerWhenWindowWillClose
:(NSWindow
*)window
;
39 // Scoper //////////////////////////////////////////////////////////////////////
43 // Use an instance of this class to call |-clearOwner| on the |tracking_area_|
44 // when this goes out of scope.
45 class UI_BASE_EXPORT ScopedCrTrackingArea
{
47 // Takes ownership of |tracking_area| without retaining it.
48 explicit ScopedCrTrackingArea(CrTrackingArea
* tracking_area
= nil
);
49 ~ScopedCrTrackingArea();
51 // This will call |scoped_nsobject<>::reset()| to take ownership of the new
52 // tracking area. Note that -clearOwner is NOT called on the existing
54 void reset(CrTrackingArea
* tracking_area
= nil
);
56 CrTrackingArea
* get() const;
59 base::scoped_nsobject
<CrTrackingArea
> tracking_area_
;
60 DISALLOW_COPY_AND_ASSIGN(ScopedCrTrackingArea
);
65 #endif // UI_BASE_COCOA_TRACKING_AREA_H_