From a2d806f5df8b4189ef76014c69e277bed9f849b3 Mon Sep 17 00:00:00 2001 From: "viettrungluu@chromium.org" Date: Wed, 25 Nov 2009 15:41:05 +0000 Subject: Mac: fix Esc-key cancellation of bookmark bar button drags. The drag would be cancelled after pressing Esc, but moving the mouse again would cause the bookmark bar button to see a drag again and start a new drag. This patch makes the button wait for the next mouse down. BUG=28502 TEST=Drag bookmark bar button and keep mouse button; press Esc (and see cancellation animation); move mouse again and make sure a new drag doesn't start. Review URL: http://codereview.chromium.org/437055 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33067 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/cocoa/bookmark_button.mm | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'chrome/browser/cocoa/bookmark_button.mm') diff --git a/chrome/browser/cocoa/bookmark_button.mm b/chrome/browser/cocoa/bookmark_button.mm index 40a1e0a..1fdf4a3 100644 --- a/chrome/browser/cocoa/bookmark_button.mm +++ b/chrome/browser/cocoa/bookmark_button.mm @@ -46,6 +46,9 @@ const CGFloat kDragImageOpacity = 0.8; } - (void)beginDrag:(NSEvent*)event { + // Starting drag. Never start another drag until another mouse down. + mayDragStart_ = NO; + NSSize dragOffset = NSMakeSize(0.0, 0.0); NSPasteboard* pboard = [NSPasteboard pasteboardWithName:NSDragPboard]; [pboard declareTypes:[NSArray arrayWithObject:kBookmarkButtonDragType] @@ -82,11 +85,16 @@ const CGFloat kDragImageOpacity = 0.8; } - (void)mouseUp:(NSEvent*)theEvent { + // Make sure that we can't start a drag until we see a mouse down again. + mayDragStart_ = NO; + // This conditional is never true (DnD loops in Cocoa eat the mouse // up) but I added it in case future versions of Cocoa do unexpected // things. - if (beingDragged_) + if (beingDragged_) { + NOTREACHED(); return [super mouseUp:theEvent]; + } // There are non-drag cases where a mouseUp: may happen // (e.g. mouse-down, cmd-tab to another application, move mouse, @@ -103,6 +111,7 @@ const CGFloat kDragImageOpacity = 0.8; // Mimic "begin a click" operation visually. Do NOT follow through // with normal button event handling. - (void)mouseDown:(NSEvent*)theEvent { + mayDragStart_ = YES; [[self cell] setHighlighted:YES]; initialMouseDownLocation_ = [theEvent locationInWindow]; } @@ -122,12 +131,11 @@ const CGFloat kDragImageOpacity = 0.8; } - (void)mouseDragged:(NSEvent*)theEvent { - if (beingDragged_) + if (beingDragged_) { [super mouseDragged:theEvent]; - else { - if (draggable_ && [self hasCrossedDragThreshold:theEvent]) { - [self beginDrag:theEvent]; - } + } else if (draggable_ && mayDragStart_ && + [self hasCrossedDragThreshold:theEvent]) { + [self beginDrag:theEvent]; } } -- cgit v1.1