Roll src/third_party/WebKit 4526c29:30f3df0 (svn 190187:190189)
[chromium-blink-merge.git] / ui / base / cocoa / tracking_area.h
blobdf37686bd970b7c91ea4dc81ecbc37c4c3907e24
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.
17 UI_BASE_EXPORT
18 @interface CrTrackingArea : NSTrackingArea {
19 @private
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
27 owner:(id)owner
28 userInfo:(NSDictionary*)userInfo;
30 // Prevents any future messages from being delivered to the |owner|.
31 - (void)clearOwner;
33 // Watches |window| for its NSWindowWillCloseNotification and calls
34 // |-clearOwner| when the notification is observed.
35 - (void)clearOwnerWhenWindowWillClose:(NSWindow*)window;
37 @end
39 // Scoper //////////////////////////////////////////////////////////////////////
41 namespace ui {
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 {
46 public:
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
53 // tracking area.
54 void reset(CrTrackingArea* tracking_area = nil);
56 CrTrackingArea* get() const;
58 private:
59 base::scoped_nsobject<CrTrackingArea> tracking_area_;
60 DISALLOW_COPY_AND_ASSIGN(ScopedCrTrackingArea);
63 } // namespace ui
65 #endif // UI_BASE_COCOA_TRACKING_AREA_H_