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

Unified Diff: ui/base/cocoa/base_view.mm

Issue 941543002: Mac: Speculative fix for tracking area crashes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bgv
Patch Set: Fix for shess Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ui/base/cocoa/tracking_area.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/cocoa/base_view.mm
diff --git a/ui/base/cocoa/base_view.mm b/ui/base/cocoa/base_view.mm
index b37b6789435d8a6da2698e72d63b1779adba2957..6f7b540aa739ce3ce81cedcf43ef513b33681edf 100644
--- a/ui/base/cocoa/base_view.mm
+++ b/ui/base/cocoa/base_view.mm
@@ -8,18 +8,57 @@ NSString* kViewDidBecomeFirstResponder =
@"Chromium.kViewDidBecomeFirstResponder";
NSString* kSelectionDirection = @"Chromium.kSelectionDirection";
-const int kTrackingOptions = NSTrackingMouseMoved |
- NSTrackingMouseEnteredAndExited |
- NSTrackingActiveAlways;
-
@implementation BaseView
+- (instancetype)initWithFrame:(NSRect)frame {
+ if ((self = [super initWithFrame:frame])) {
+ [self enableTracking];
+ }
+ return self;
+}
+
+- (instancetype)initWithCoder:(NSCoder*)decoder {
+ if ((self = [super initWithCoder:decoder])) {
+ [self enableTracking];
+ }
+ return self;
+}
+
- (void)dealloc {
+ [self disableTracking];
+ [super dealloc];
+}
+
+- (void)enableTracking {
if (trackingArea_.get())
+ return;
+
+ NSTrackingAreaOptions trackingOptions = NSTrackingMouseEnteredAndExited |
+ NSTrackingMouseMoved |
+ NSTrackingActiveAlways |
+ NSTrackingInVisibleRect;
+ trackingArea_.reset([[CrTrackingArea alloc] initWithRect:NSZeroRect
+ options:trackingOptions
+ owner:self
+ userInfo:nil]);
+ [self addTrackingArea:trackingArea_.get()];
+}
+
+- (void)disableTracking {
+ if (trackingArea_.get()) {
[self removeTrackingArea:trackingArea_.get()];
- trackingArea_.reset(nil);
+ trackingArea_.reset();
+ }
+}
- [super dealloc];
+- (void)viewDidEndLiveResize {
+ [super viewDidEndLiveResize];
+
+ // NSTrackingInVisibleRect doesn't work correctly with Lion's window resizing,
+ // http://crbug.com/176725 / http://openradar.appspot.com/radar?id=2773401 .
+ // Work around it by reinstalling the tracking area after window resize.
+ [self disableTracking];
+ [self enableTracking];
}
- (void)mouseEvent:(NSEvent*)theEvent {
@@ -138,19 +177,4 @@ const int kTrackingOptions = NSTrackingMouseMoved |
return new_rect;
}
-- (void)updateTrackingAreas {
- [super updateTrackingAreas];
-
- // NSTrackingInVisibleRect doesn't work correctly with Lion's window resizing,
- // http://crbug.com/176725 / http://openradar.appspot.com/radar?id=2773401 .
- // Tear down old tracking area and create a new one as workaround.
- if (trackingArea_.get())
- [self removeTrackingArea:trackingArea_.get()];
- trackingArea_.reset([[CrTrackingArea alloc] initWithRect:[self bounds]
- options:kTrackingOptions
- owner:self
- userInfo:nil]);
- [self addTrackingArea:trackingArea_.get()];
-}
-
@end
« no previous file with comments | « no previous file | ui/base/cocoa/tracking_area.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698