diff options
Diffstat (limited to 'chrome/browser/ui/cocoa/toolbar/toolbar_button.mm')
-rw-r--r-- | chrome/browser/ui/cocoa/toolbar/toolbar_button.mm | 77 |
1 files changed, 28 insertions, 49 deletions
diff --git a/chrome/browser/ui/cocoa/toolbar/toolbar_button.mm b/chrome/browser/ui/cocoa/toolbar/toolbar_button.mm index 517e6e5..afc3483 100644 --- a/chrome/browser/ui/cocoa/toolbar/toolbar_button.mm +++ b/chrome/browser/ui/cocoa/toolbar/toolbar_button.mm @@ -4,63 +4,42 @@ #import "chrome/browser/ui/cocoa/toolbar/toolbar_button.h" -@interface ToolbarButton (Private) -- (BOOL)updateStatus:(NSEvent*)theEvent; -@end - @implementation ToolbarButton @synthesize handleMiddleClick = handleMiddleClick_; -- (void)mouseDown:(NSEvent*)theEvent { - if (!handlingMiddleClick_) - [super mouseDown:theEvent]; -} - -- (void)mouseDragged:(NSEvent*)theEvent { - if (!handlingMiddleClick_) - [super mouseDragged:theEvent]; -} - -- (void)mouseUp:(NSEvent*)theEvent { - if (!handlingMiddleClick_) - [super mouseUp:theEvent]; -} - - (void)otherMouseDown:(NSEvent*)theEvent { - if (![self shouldHandleEvent:theEvent]) + if (![self shouldHandleEvent:theEvent]) { [super otherMouseDown:theEvent]; - else - handlingMiddleClick_ = [self updateStatus:theEvent]; -} - -- (void)otherMouseDragged:(NSEvent*)theEvent { - if (!handlingMiddleClick_ || ![self shouldHandleEvent:theEvent]) - [super otherMouseDragged:theEvent]; - else - [self updateStatus:theEvent]; -} - -- (void)otherMouseUp:(NSEvent*)theEvent { - if (!handlingMiddleClick_ || ![self shouldHandleEvent:theEvent]) { - [super otherMouseUp:theEvent]; - } else { - if ([self state] == NSOnState) - [self sendAction:[self action] to:[self target]]; - - [self setState:NSOffState]; - [self highlight:NO]; - handlingMiddleClick_ = NO; + return; } -} -- (BOOL)updateStatus:(NSEvent*)theEvent { - NSPoint mouseLoc = [self convertPoint:[theEvent locationInWindow] - fromView:nil]; - BOOL isInside = [self mouse:mouseLoc inRect:[self bounds]]; - [self setState:isInside ? NSOnState : NSOffState]; - [self highlight:isInside]; - return isInside; + NSEvent* nextEvent = theEvent; + BOOL isInside; + + // Loop until middle button is released. Also, the mouse cursor is outside of + // the button, the button should not be highlighted. + do { + NSPoint mouseLoc = [self convertPoint:[nextEvent locationInWindow] + fromView:nil]; + isInside = [self mouse:mouseLoc inRect:[self bounds]]; + [self highlight:isInside]; + [self setState:isInside ? NSOnState : NSOffState]; + + NSUInteger mask = NSOtherMouseDraggedMask | NSOtherMouseUpMask; + nextEvent = [[self window] nextEventMatchingMask:mask]; + } while (!([nextEvent buttonNumber] == 2 && + [nextEvent type] == NSOtherMouseUp)); + + // Discard the events before the middle button up event. + // If we don't discard it, the events will be re-processed later. + [[self window] discardEventsMatchingMask:NSAnyEventMask + beforeEvent:nextEvent]; + + [self highlight:NO]; + [self setState:NSOffState]; + if (isInside) + [self sendAction:[self action] to:[self target]]; } - (BOOL)shouldHandleEvent:(NSEvent*)theEvent { |