| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 - (NSTrackingArea*)initWithRect:(NSRect)rect | 85 - (NSTrackingArea*)initWithRect:(NSRect)rect |
| 86 options:(NSTrackingAreaOptions)options | 86 options:(NSTrackingAreaOptions)options |
| 87 owner:(id)owner | 87 owner:(id)owner |
| 88 userInfo:(NSDictionary*)userInfo { | 88 userInfo:(NSDictionary*)userInfo { |
| 89 [NSException raise:@"org.chromium.CrTrackingArea" | 89 [NSException raise:@"org.chromium.CrTrackingArea" |
| 90 format:@"Cannot init a CrTrackingArea with NSTrackingArea's initializer"]; | 90 format:@"Cannot init a CrTrackingArea with NSTrackingArea's initializer"]; |
| 91 return nil; | 91 return nil; |
| 92 } | 92 } |
| 93 | 93 |
| 94 - (void)dealloc { | 94 - (void)dealloc { |
| 95 [self clearOwner]; |
| 95 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 96 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 96 [super dealloc]; | 97 [super dealloc]; |
| 97 } | 98 } |
| 98 | 99 |
| 99 - (void)clearOwner { | 100 - (void)clearOwner { |
| 100 [ownerProxy_ setAlive:NO]; | 101 [ownerProxy_ setAlive:NO]; |
| 101 } | 102 } |
| 102 | 103 |
| 103 - (void)clearOwnerWhenWindowWillClose:(NSWindow*)window { | 104 - (void)clearOwnerWhenWindowWillClose:(NSWindow*)window { |
| 104 DCHECK(window); | 105 DCHECK(window); |
| 105 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; | 106 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; |
| 106 [center addObserver:self | 107 [center addObserver:self |
| 107 selector:@selector(windowWillClose:) | 108 selector:@selector(windowWillClose:) |
| 108 name:NSWindowWillCloseNotification | 109 name:NSWindowWillCloseNotification |
| 109 object:window]; | 110 object:window]; |
| 110 } | 111 } |
| 111 | 112 |
| 112 - (void)windowWillClose:(NSNotification*)notif { | 113 - (void)windowWillClose:(NSNotification*)notif { |
| 113 [self clearOwner]; | 114 [self clearOwner]; |
| 114 } | 115 } |
| 115 | 116 |
| 116 @end | 117 @end |
| 118 |
| 119 // Scoper ////////////////////////////////////////////////////////////////////// |
| 120 |
| 121 ScopedCrTrackingArea::ScopedCrTrackingArea(CrTrackingArea* tracking_area) |
| 122 : tracking_area_(tracking_area) { |
| 123 } |
| 124 |
| 125 ScopedCrTrackingArea::~ScopedCrTrackingArea() { |
| 126 [tracking_area_ clearOwner]; |
| 127 } |
| 128 |
| 129 void ScopedCrTrackingArea::reset(CrTrackingArea* tracking_area) { |
| 130 tracking_area_.reset(tracking_area); |
| 131 } |
| 132 |
| 133 CrTrackingArea* ScopedCrTrackingArea::get() const { |
| 134 return tracking_area_.get(); |
| 135 } |
| OLD | NEW |