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 | | 11 @implementation BaseView |
| 12 NSTrackingMouseEnteredAndExited | | |
| 13 NSTrackingActiveAlways; | |
| 14 | 12 |
| 15 @implementation BaseView | 13 - (instancetype)initWithFrame:(NSRect)frame { |
| 14 if ((self = [super initWithFrame:frame])) { | |
| 15 [self initBaseView]; | |
| 16 } | |
| 17 return self; | |
| 18 } | |
| 19 | |
| 20 - (instancetype)initWithCoder:(NSCoder*)decoder { | |
| 21 if ((self = [super initWithCoder:decoder])) { | |
| 22 [self initBaseView]; | |
| 23 } | |
| 24 return self; | |
| 25 } | |
| 26 | |
| 27 - (void)initBaseView { | |
| 28 trackingArea_.reset( | |
| 29 [[CrTrackingArea alloc] initWithRect:NSZeroRect | |
| 30 options:NSTrackingMouseMoved | | |
| 31 NSTrackingMouseEnteredAndExited | | |
| 32 NSTrackingActiveAlways | | |
| 33 NSTrackingInVisibleRect | |
| 34 owner:self | |
| 35 userInfo:nil]); | |
| 36 [self addTrackingArea:trackingArea_.get()]; | |
| 37 } | |
| 16 | 38 |
| 17 - (void)dealloc { | 39 - (void)dealloc { |
| 18 if (trackingArea_.get()) | 40 if (trackingArea_.get()) |
| 19 [self removeTrackingArea:trackingArea_.get()]; | 41 [self removeTrackingArea:trackingArea_.get()]; |
| 20 trackingArea_.reset(nil); | 42 trackingArea_.reset(nil); |
| 21 | 43 |
| 22 [super dealloc]; | 44 [super dealloc]; |
| 23 } | 45 } |
| 24 | 46 |
| 25 - (void)mouseEvent:(NSEvent*)theEvent { | 47 - (void)mouseEvent:(NSEvent*)theEvent { |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 new_rect.set_y(NSHeight([self bounds]) - new_rect.bottom()); | 153 new_rect.set_y(NSHeight([self bounds]) - new_rect.bottom()); |
| 132 return new_rect; | 154 return new_rect; |
| 133 } | 155 } |
| 134 | 156 |
| 135 - (NSRect)flipRectToNSRect:(gfx::Rect)rect { | 157 - (NSRect)flipRectToNSRect:(gfx::Rect)rect { |
| 136 NSRect new_rect(NSRectFromCGRect(rect.ToCGRect())); | 158 NSRect new_rect(NSRectFromCGRect(rect.ToCGRect())); |
| 137 new_rect.origin.y = NSHeight([self bounds]) - NSMaxY(new_rect); | 159 new_rect.origin.y = NSHeight([self bounds]) - NSMaxY(new_rect); |
| 138 return new_rect; | 160 return new_rect; |
| 139 } | 161 } |
| 140 | 162 |
| 141 - (void)updateTrackingAreas { | |
| 142 [super updateTrackingAreas]; | |
|
Nico
2015/02/24 21:00:18
Could we set a flag in dealloc and not add a new t
Andre
2015/02/24 21:20:46
I thought about that, but ended up not being confi
| |
| 143 | |
| 144 // NSTrackingInVisibleRect doesn't work correctly with Lion's window resizing, | |
| 145 // http://crbug.com/176725 / http://openradar.appspot.com/radar?id=2773401 . | |
| 146 // Tear down old tracking area and create a new one as workaround. | |
| 147 if (trackingArea_.get()) | |
| 148 [self removeTrackingArea:trackingArea_.get()]; | |
| 149 trackingArea_.reset([[CrTrackingArea alloc] initWithRect:[self bounds] | |
| 150 options:kTrackingOptions | |
| 151 owner:self | |
| 152 userInfo:nil]); | |
| 153 [self addTrackingArea:trackingArea_.get()]; | |
| 154 } | |
| 155 | |
| 156 @end | 163 @end |
| OLD | NEW |