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

Side by Side 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, 9 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
« no previous file with comments | « no previous file | ui/base/cocoa/tracking_area.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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
15 @implementation BaseView 11 @implementation BaseView
16 12
13 - (instancetype)initWithFrame:(NSRect)frame {
14 if ((self = [super initWithFrame:frame])) {
15 [self enableTracking];
16 }
17 return self;
18 }
19
20 - (instancetype)initWithCoder:(NSCoder*)decoder {
21 if ((self = [super initWithCoder:decoder])) {
22 [self enableTracking];
23 }
24 return self;
25 }
26
17 - (void)dealloc { 27 - (void)dealloc {
18 if (trackingArea_.get()) 28 [self disableTracking];
19 [self removeTrackingArea:trackingArea_.get()];
20 trackingArea_.reset(nil);
21
22 [super dealloc]; 29 [super dealloc];
23 } 30 }
24 31
32 - (void)enableTracking {
33 if (trackingArea_.get())
34 return;
35
36 NSTrackingAreaOptions trackingOptions = NSTrackingMouseEnteredAndExited |
37 NSTrackingMouseMoved |
38 NSTrackingActiveAlways |
39 NSTrackingInVisibleRect;
40 trackingArea_.reset([[CrTrackingArea alloc] initWithRect:NSZeroRect
41 options:trackingOptions
42 owner:self
43 userInfo:nil]);
44 [self addTrackingArea:trackingArea_.get()];
45 }
46
47 - (void)disableTracking {
48 if (trackingArea_.get()) {
49 [self removeTrackingArea:trackingArea_.get()];
50 trackingArea_.reset();
51 }
52 }
53
54 - (void)viewDidEndLiveResize {
55 [super viewDidEndLiveResize];
56
57 // NSTrackingInVisibleRect doesn't work correctly with Lion's window resizing,
58 // http://crbug.com/176725 / http://openradar.appspot.com/radar?id=2773401 .
59 // Work around it by reinstalling the tracking area after window resize.
60 [self disableTracking];
61 [self enableTracking];
62 }
63
25 - (void)mouseEvent:(NSEvent*)theEvent { 64 - (void)mouseEvent:(NSEvent*)theEvent {
26 // This method left intentionally blank. 65 // This method left intentionally blank.
27 } 66 }
28 67
29 - (EventHandled)keyEvent:(NSEvent*)theEvent { 68 - (EventHandled)keyEvent:(NSEvent*)theEvent {
30 // The default implementation of this method does not handle any key events. 69 // The default implementation of this method does not handle any key events.
31 // Derived classes should return kEventHandled if they handled an event, 70 // Derived classes should return kEventHandled if they handled an event,
32 // otherwise it will be forwarded on to |super|. 71 // otherwise it will be forwarded on to |super|.
33 return kEventNotHandled; 72 return kEventNotHandled;
34 } 73 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 new_rect.set_y(NSHeight([self bounds]) - new_rect.bottom()); 170 new_rect.set_y(NSHeight([self bounds]) - new_rect.bottom());
132 return new_rect; 171 return new_rect;
133 } 172 }
134 173
135 - (NSRect)flipRectToNSRect:(gfx::Rect)rect { 174 - (NSRect)flipRectToNSRect:(gfx::Rect)rect {
136 NSRect new_rect(NSRectFromCGRect(rect.ToCGRect())); 175 NSRect new_rect(NSRectFromCGRect(rect.ToCGRect()));
137 new_rect.origin.y = NSHeight([self bounds]) - NSMaxY(new_rect); 176 new_rect.origin.y = NSHeight([self bounds]) - NSMaxY(new_rect);
138 return new_rect; 177 return new_rect;
139 } 178 }
140 179
141 - (void)updateTrackingAreas {
142 [super updateTrackingAreas];
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 180 @end
OLDNEW
« 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