Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(351)

Side by Side Diff: chrome/browser/ui/cocoa/tracking_area.mm

Issue 6480067: [Mac] Placate Clang's (pedantic) warning about CrTrackingArea's initializer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698