OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 #import "chrome/browser/ui/cocoa/tracking_area.h" | 5 #import "chrome/browser/ui/cocoa/tracking_area.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 | 8 |
9 // NSTrackingArea does not retain its |owner| so CrTrackingArea wraps the real | 9 // NSTrackingArea does not retain its |owner| so CrTrackingArea wraps the real |
10 // owner in this proxy, which can stop forwarding messages to the owner when | 10 // owner in this proxy, which can stop forwarding messages to the owner when |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 | 61 |
62 @interface CrTrackingArea (Private) | 62 @interface CrTrackingArea (Private) |
63 - (void)windowWillClose:(NSNotification*)notif; | 63 - (void)windowWillClose:(NSNotification*)notif; |
64 @end | 64 @end |
65 | 65 |
66 //////////////////////////////////////////////////////////////////////////////// | 66 //////////////////////////////////////////////////////////////////////////////// |
67 | 67 |
68 @implementation CrTrackingArea | 68 @implementation CrTrackingArea |
69 | 69 |
70 - (id)initWithRect:(NSRect)rect | 70 - (id)initWithRect:(NSRect)rect |
71 options:(NSTrackingAreaOptions)options | 71 options:(NSTrackingAreaOptions)options |
72 proxiedOwner:(id)owner | 72 owner:(id)owner |
73 userInfo:(NSDictionary*)userInfo { | 73 userInfo:(NSDictionary*)userInfo { |
74 scoped_nsobject<CrTrackingAreaOwnerProxy> ownerProxy( | 74 scoped_nsobject<CrTrackingAreaOwnerProxy> ownerProxy( |
75 [[CrTrackingAreaOwnerProxy alloc] initWithOwner:owner]); | 75 [[CrTrackingAreaOwnerProxy alloc] initWithOwner:owner]); |
76 if ((self = static_cast<id>([super initWithRect:rect | 76 if ((self = [super initWithRect:rect |
77 options:options | 77 options:options |
78 owner:ownerProxy.get() | 78 owner:ownerProxy.get() |
79 userInfo:userInfo]))) { | 79 userInfo:userInfo])) { |
80 ownerProxy_.swap(ownerProxy); | 80 ownerProxy_.swap(ownerProxy); |
81 } | 81 } |
82 return self; | 82 return self; |
83 } | 83 } |
84 | 84 |
85 - (NSTrackingArea*)initWithRect:(NSRect)rect | |
86 options:(NSTrackingAreaOptions)options | |
87 owner:(id)owner | |
88 userInfo:(NSDictionary*)userInfo { | |
89 [NSException raise:@"org.chromium.CrTrackingArea" | |
90 format:@"Cannot init a CrTrackingArea with NSTrackingArea's initializer"]; | |
91 return nil; | |
92 } | |
93 | |
94 - (void)dealloc { | 85 - (void)dealloc { |
95 [self clearOwner]; | 86 [self clearOwner]; |
96 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 87 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
97 [super dealloc]; | 88 [super dealloc]; |
98 } | 89 } |
99 | 90 |
100 - (void)clearOwner { | 91 - (void)clearOwner { |
101 [ownerProxy_ setAlive:NO]; | 92 [ownerProxy_ setAlive:NO]; |
102 } | 93 } |
103 | 94 |
(...skipping 22 matching lines...) Expand all Loading... |
126 [tracking_area_ clearOwner]; | 117 [tracking_area_ clearOwner]; |
127 } | 118 } |
128 | 119 |
129 void ScopedCrTrackingArea::reset(CrTrackingArea* tracking_area) { | 120 void ScopedCrTrackingArea::reset(CrTrackingArea* tracking_area) { |
130 tracking_area_.reset(tracking_area); | 121 tracking_area_.reset(tracking_area); |
131 } | 122 } |
132 | 123 |
133 CrTrackingArea* ScopedCrTrackingArea::get() const { | 124 CrTrackingArea* ScopedCrTrackingArea::get() const { |
134 return tracking_area_.get(); | 125 return tracking_area_.get(); |
135 } | 126 } |
OLD | NEW |