Chromium Code Reviews| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 owner:(id)owner | 72 proxiedOwner:(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 = static_cast<id>([super initWithRect:rect |
|
Nico
2011/02/15 13:57:51
you could have a TODO to remove this static_cast a
| |
| 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 | |
| 85 - (void)dealloc { | 94 - (void)dealloc { |
| 86 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 95 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 87 [super dealloc]; | 96 [super dealloc]; |
| 88 } | 97 } |
| 89 | 98 |
| 90 - (void)clearOwner { | 99 - (void)clearOwner { |
| 91 [ownerProxy_ setAlive:NO]; | 100 [ownerProxy_ setAlive:NO]; |
| 92 } | 101 } |
| 93 | 102 |
| 94 - (void)clearOwnerWhenWindowWillClose:(NSWindow*)window { | 103 - (void)clearOwnerWhenWindowWillClose:(NSWindow*)window { |
| 95 DCHECK(window); | 104 DCHECK(window); |
| 96 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; | 105 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; |
| 97 [center addObserver:self | 106 [center addObserver:self |
| 98 selector:@selector(windowWillClose:) | 107 selector:@selector(windowWillClose:) |
| 99 name:NSWindowWillCloseNotification | 108 name:NSWindowWillCloseNotification |
| 100 object:window]; | 109 object:window]; |
| 101 } | 110 } |
| 102 | 111 |
| 103 - (void)windowWillClose:(NSNotification*)notif { | 112 - (void)windowWillClose:(NSNotification*)notif { |
| 104 [self clearOwner]; | 113 [self clearOwner]; |
| 105 } | 114 } |
| 106 | 115 |
| 107 @end | 116 @end |
| OLD | NEW |