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 #include "ui/base/cocoa/base_view.h" | 5 #include "ui/base/cocoa/base_view.h" |
| 6 | 6 |
| 7 NSString* kViewDidBecomeFirstResponder = | 7 NSString* kViewDidBecomeFirstResponder = |
| 8 @"Chromium.kViewDidBecomeFirstResponder"; | 8 @"Chromium.kViewDidBecomeFirstResponder"; |
| 9 NSString* kSelectionDirection = @"Chromium.kSelectionDirection"; | 9 NSString* kSelectionDirection = @"Chromium.kSelectionDirection"; |
| 10 | 10 |
| 11 const int kTrackingOptions = NSTrackingMouseMoved | | |
| 12 NSTrackingMouseEnteredAndExited | | |
| 13 NSTrackingActiveAlways; | |
| 14 | |
| 11 @implementation BaseView | 15 @implementation BaseView |
| 12 | 16 |
| 13 - (id)initWithFrame:(NSRect)frame { | 17 - (id)initWithFrame:(NSRect)frame { |
| 14 self = [super initWithFrame:frame]; | 18 self = [super initWithFrame:frame]; |
| 15 if (self) { | 19 if (self) { |
| 16 trackingArea_ = | 20 trackingArea_ = [[NSTrackingArea alloc] initWithRect:frame |
|
Alexei Svitkine (slow)
2013/03/14 00:42:47
Could this just call [self refreshTrackingAreaSize
| |
| 17 [[NSTrackingArea alloc] initWithRect:frame | 21 options:kTrackingOptions |
| 18 options:NSTrackingMouseMoved | | 22 owner:self |
| 19 NSTrackingMouseEnteredAndExited | | 23 userInfo:nil]; |
| 20 NSTrackingActiveInActiveApp | | |
| 21 NSTrackingInVisibleRect | |
| 22 owner:self | |
| 23 userInfo:nil]; | |
| 24 [self addTrackingArea:trackingArea_]; | 24 [self addTrackingArea:trackingArea_]; |
| 25 } | 25 } |
| 26 return self; | 26 return self; |
| 27 } | 27 } |
| 28 | 28 |
| 29 - (void)dealloc { | 29 - (void)dealloc { |
| 30 [self removeTrackingArea:trackingArea_]; | 30 [self removeTrackingArea:trackingArea_]; |
| 31 [trackingArea_ release]; | 31 [trackingArea_ release]; |
| 32 | 32 |
| 33 [super dealloc]; | 33 [super dealloc]; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 new_rect.set_y(NSHeight([self bounds]) - new_rect.bottom()); | 136 new_rect.set_y(NSHeight([self bounds]) - new_rect.bottom()); |
| 137 return new_rect; | 137 return new_rect; |
| 138 } | 138 } |
| 139 | 139 |
| 140 - (NSRect)flipRectToNSRect:(gfx::Rect)rect { | 140 - (NSRect)flipRectToNSRect:(gfx::Rect)rect { |
| 141 NSRect new_rect(NSRectFromCGRect(rect.ToCGRect())); | 141 NSRect new_rect(NSRectFromCGRect(rect.ToCGRect())); |
| 142 new_rect.origin.y = NSHeight([self bounds]) - NSMaxY(new_rect); | 142 new_rect.origin.y = NSHeight([self bounds]) - NSMaxY(new_rect); |
| 143 return new_rect; | 143 return new_rect; |
| 144 } | 144 } |
| 145 | 145 |
| 146 - (void)refreshTrackingAreaSize { | |
|
Alexei Svitkine (slow)
2013/03/14 00:42:47
Should this be called refreshTrackingAreaRect, sin
| |
| 147 // NSTrackingInVisibleRect doesn't work correctly with Lion's window resizing, | |
| 148 // http://crbug.com/176725 / http://openradar.appspot.com/radar?id=2773401 . | |
| 149 // Tear down old tracking area and create a new one as workaround. | |
| 150 [self removeTrackingArea:trackingArea_]; | |
| 151 [trackingArea_ release]; | |
| 152 trackingArea_ = [[NSTrackingArea alloc] initWithRect:[self frame] | |
| 153 options:kTrackingOptions | |
| 154 owner:self | |
| 155 userInfo:nil]; | |
| 156 [self addTrackingArea:trackingArea_]; | |
| 157 } | |
| 158 | |
| 159 - (void)setFrame:(NSRect)newRect { | |
| 160 BOOL sizeChanged = !NSEqualSizes([self frame].size, newRect.size); | |
| 161 [super setFrame:newRect]; | |
| 162 | |
| 163 // NB: -[NSView setFrame:] calls through -setFrameSize:. | |
| 164 if (!sizeChanged) | |
| 165 [self refreshTrackingAreaSize]; | |
|
Alexei Svitkine (slow)
2013/03/14 00:42:47
So this is called because -[NSView setFrame:] does
| |
| 166 } | |
| 167 | |
| 168 - (void)setFrameSize:(NSSize)newSize { | |
| 169 [super setFrameSize:newSize]; | |
| 170 [self refreshTrackingAreaSize]; | |
| 171 } | |
| 172 | |
| 146 @end | 173 @end |
| OLD | NEW |