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

Side by Side Diff: chrome/browser/cocoa/tab_view.mm

Issue 242139: Mac: Fix crash while dragging a tab alone in a window. (Closed)
Patch Set: Unconditionally clear tab controller's target. Created 11 years, 2 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 | « chrome/browser/cocoa/tab_strip_controller.mm ('k') | no next file » | 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/cocoa/tab_view.h" 5 #import "chrome/browser/cocoa/tab_view.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "chrome/browser/cocoa/nsimage_cache.h" 8 #include "chrome/browser/cocoa/nsimage_cache.h"
9 #import "chrome/browser/cocoa/tab_controller.h" 9 #import "chrome/browser/cocoa/tab_controller.h"
10 #import "chrome/browser/cocoa/tab_window_controller.h" 10 #import "chrome/browser/cocoa/tab_window_controller.h"
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 while (1) { 246 while (1) {
247 theEvent = 247 theEvent =
248 [NSApp nextEventMatchingMask:NSLeftMouseUpMask | NSLeftMouseDraggedMask 248 [NSApp nextEventMatchingMask:NSLeftMouseUpMask | NSLeftMouseDraggedMask
249 untilDate:[NSDate distantFuture] 249 untilDate:[NSDate distantFuture]
250 inMode:NSDefaultRunLoopMode dequeue:YES]; 250 inMode:NSDefaultRunLoopMode dequeue:YES];
251 NSPoint thisPoint = [NSEvent mouseLocation]; 251 NSPoint thisPoint = [NSEvent mouseLocation];
252 252
253 NSEventType type = [theEvent type]; 253 NSEventType type = [theEvent type];
254 if (type == NSLeftMouseDragged) { 254 if (type == NSLeftMouseDragged) {
255 [self mouseDragged:theEvent]; 255 [self mouseDragged:theEvent];
256 } else { // Mouse Up 256 } else if (type == NSLeftMouseUp) {
257 NSPoint upLocation = [theEvent locationInWindow]; 257 NSPoint upLocation = [theEvent locationInWindow];
258 CGFloat dx = upLocation.x - downLocation.x; 258 CGFloat dx = upLocation.x - downLocation.x;
259 CGFloat dy = upLocation.y - downLocation.y; 259 CGFloat dy = upLocation.y - downLocation.y;
260 260
261 // During rapid tab closure (mashing tab close buttons), we may get hit 261 // During rapid tab closure (mashing tab close buttons), we may get hit
262 // with a mouse down. As long as the mouse up is over the close button, 262 // with a mouse down. As long as the mouse up is over the close button,
263 // and the mouse hasn't moved too much, we close the tab. 263 // and the mouse hasn't moved too much, we close the tab.
264 if ((dx*dx + dy*dy) <= kRapidCloseDist*kRapidCloseDist && 264 if ((dx*dx + dy*dy) <= kRapidCloseDist*kRapidCloseDist &&
265 [controller_ inRapidClosureMode]) { 265 [controller_ inRapidClosureMode]) {
266 NSPoint hitLocation = 266 NSPoint hitLocation =
267 [[self superview] convertPoint:[theEvent locationInWindow] 267 [[self superview] convertPoint:[theEvent locationInWindow]
268 fromView:nil]; 268 fromView:nil];
269 if ([self hitTest:hitLocation] == closeButton_) { 269 if ([self hitTest:hitLocation] == closeButton_) {
270 [controller_ closeTab:self]; 270 [controller_ closeTab:self];
271 break; 271 break;
272 } 272 }
273 } 273 }
274 274
275 [self mouseUp:theEvent]; 275 [self mouseUp:theEvent];
276 break; 276 break;
277 } else {
278 // TODO(viettrungluu): [crbug.com/23830] We can receive right-mouse-ups
279 // (and maybe even others?) for reasons I don't understand. So we
280 // explicitly check for both events we're expecting, and log others. We
281 // should figure out what's going on.
282 LOG(WARNING) << "Spurious event received of type " << type << ".";
277 } 283 }
278 } 284 }
279 } 285 }
280 286
281 - (void)mouseDragged:(NSEvent *)theEvent { 287 - (void)mouseDragged:(NSEvent *)theEvent {
282 // Special-case this to keep the logic below simpler. 288 // Special-case this to keep the logic below simpler.
283 if (moveWindowOnDrag_) { 289 if (moveWindowOnDrag_) {
284 NSPoint thisPoint = [NSEvent mouseLocation]; 290 NSPoint thisPoint = [NSEvent mouseLocation];
285 NSPoint origin = sourceWindowFrame_.origin; 291 NSPoint origin = sourceWindowFrame_.origin;
286 origin.x += (thisPoint.x - dragOrigin_.x); 292 origin.x += (thisPoint.x - dragOrigin_.x);
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 [[NSGraphicsContext currentContext] restoreGraphicsState]; 709 [[NSGraphicsContext currentContext] restoreGraphicsState];
704 } 710 }
705 711
706 // Called when the user hits the right mouse button (or control-clicks) to 712 // Called when the user hits the right mouse button (or control-clicks) to
707 // show a context menu. 713 // show a context menu.
708 - (void)rightMouseDown:(NSEvent*)theEvent { 714 - (void)rightMouseDown:(NSEvent*)theEvent {
709 [NSMenu popUpContextMenu:[self menu] withEvent:theEvent forView:self]; 715 [NSMenu popUpContextMenu:[self menu] withEvent:theEvent forView:self];
710 } 716 }
711 717
712 @end 718 @end
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/tab_strip_controller.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698