diff options
Diffstat (limited to 'chrome/browser/ui/cocoa/toolbar')
4 files changed, 53 insertions, 86 deletions
diff --git a/chrome/browser/ui/cocoa/toolbar/toolbar_button.h b/chrome/browser/ui/cocoa/toolbar/toolbar_button.h index c35d1e5..3a7f1b6 100644 --- a/chrome/browser/ui/cocoa/toolbar/toolbar_button.h +++ b/chrome/browser/ui/cocoa/toolbar/toolbar_button.h @@ -14,11 +14,6 @@ @protected // YES when middle mouse clicks should be handled. BOOL handleMiddleClick_; - - // YES when a middle mouse click is being handled. This is set to YES by an - // NSOtherMouseDown event, and NO by an NSOtherMouseUp event. While this is - // YES, other mouse button events should be ignored. - BOOL handlingMiddleClick_; } // Whether or not to handle the mouse middle click events. 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 { diff --git a/chrome/browser/ui/cocoa/toolbar/toolbar_button_unittest.mm b/chrome/browser/ui/cocoa/toolbar/toolbar_button_unittest.mm index 3322267..b7907a3 100644 --- a/chrome/browser/ui/cocoa/toolbar/toolbar_button_unittest.mm +++ b/chrome/browser/ui/cocoa/toolbar/toolbar_button_unittest.mm @@ -213,9 +213,9 @@ TEST_F(ToolbarButtonTest, MouseClickInsideOnYES) { [button_ setHandleMiddleClick:YES]; // Middle button clicking in the view. + [NSApp postEvent:other_up_in_view atStart:YES]; [button_ otherMouseDown:other_down_in_view]; - EXPECT_EQ(NSOnState, [button_ state]); - [button_ otherMouseUp:other_up_in_view]; + EXPECT_EQ(NSOffState, [button_ state]); EXPECT_EQ(1, [button_ numOfClick]); EXPECT_EQ(IDC_HOME, [button_ lastCommand]); @@ -226,9 +226,9 @@ TEST_F(ToolbarButtonTest, MouseClickOutsideOnYES) { [button_ setHandleMiddleClick:YES]; // Middle button clicking outside of the view. + [NSApp postEvent:other_up_out_view atStart:YES]; [button_ otherMouseDown:other_down_out_view]; - EXPECT_EQ(NSOffState, [button_ state]); - [button_ otherMouseUp:other_up_out_view]; + EXPECT_EQ(NSOffState, [button_ state]); EXPECT_EQ(0, [button_ numOfClick]); EXPECT_EQ(IDC_STOP, [button_ lastCommand]); @@ -239,45 +239,36 @@ TEST_F(ToolbarButtonTest, MouseDraggingOnYES) { [button_ setHandleMiddleClick:YES]; // Middle button being down in the view and up outside of the view. + [NSApp postEvent:other_up_out_view atStart:YES]; + [NSApp postEvent:other_dragged_out_view atStart:YES]; [button_ otherMouseDown:other_down_in_view]; - EXPECT_EQ(NSOnState, [button_ state]); - [button_ otherMouseDragged:other_dragged_out_view]; - EXPECT_EQ(NSOffState, [button_ state]); - [button_ otherMouseUp:other_up_out_view]; + EXPECT_EQ(NSOffState, [button_ state]); EXPECT_EQ(0, [button_ numOfClick]); EXPECT_EQ(IDC_STOP, [button_ lastCommand]); // Middle button being down on the button, move to outside and move on it // again, then up on the button. + [NSApp postEvent:other_up_in_view atStart:YES]; + [NSApp postEvent:other_dragged_in_view atStart:YES]; + [NSApp postEvent:other_dragged_out_view atStart:YES]; [button_ otherMouseDown:other_down_in_view]; - EXPECT_EQ(NSOnState, [button_ state]); - [button_ otherMouseDragged:other_dragged_out_view]; - EXPECT_EQ(NSOffState, [button_ state]); - [button_ otherMouseDragged:other_dragged_in_view]; - EXPECT_EQ(NSOnState, [button_ state]); - [button_ otherMouseUp:other_up_in_view]; + EXPECT_EQ(NSOffState, [button_ state]); EXPECT_EQ(1, [button_ numOfClick]); EXPECT_EQ(IDC_HOME, [button_ lastCommand]); } -TEST_F(ToolbarButtonTest, DoesNotSwallowRightClickOnYES) { +TEST_F(ToolbarButtonTest, DoesSwallowRightClickOnYES) { // Enable middle button handling. [button_ setHandleMiddleClick:YES]; - // Middle button being down should swallow right button clicks, but - // ToolbarButton doesn't swallow it because it doesn't handle right button - // events. + // Middle button being down should swallow right button clicks. + [NSApp postEvent:other_up_in_view atStart:YES]; + [NSApp postEvent:right_up_in_view atStart:YES]; + [NSApp postEvent:right_down_in_view atStart:YES]; [button_ otherMouseDown:other_down_in_view]; - EXPECT_EQ(NSOnState, [button_ state]); - [button_ rightMouseDown:right_down_in_view]; - EXPECT_EQ(NSOnState, [button_ state]); - [button_ rightMouseUp:right_up_in_view]; - EXPECT_EQ(NSOnState, [button_ state]); - EXPECT_EQ(0, [button_ numOfClick]); - EXPECT_EQ(IDC_STOP, [button_ lastCommand]); - [button_ otherMouseUp:other_up_in_view]; + EXPECT_EQ(NSOffState, [button_ state]); EXPECT_EQ(1, [button_ numOfClick]); EXPECT_EQ(IDC_HOME, [button_ lastCommand]); @@ -288,13 +279,12 @@ TEST_F(ToolbarButtonTest, DoesSwallowLeftClickOnYES) { [button_ setHandleMiddleClick:YES]; // Middle button being down swallows left button clicks. - [button_ otherMouseDown:other_down_in_view]; - EXPECT_EQ(NSOnState, [button_ state]); + [NSApp postEvent:other_up_in_view atStart:YES]; [NSApp postEvent:left_up_in_view atStart:YES]; - [button_ mouseDown:left_down_in_view]; - EXPECT_EQ(0, [button_ numOfClick]); - EXPECT_EQ(IDC_STOP, [button_ lastCommand]); - [button_ otherMouseUp:other_up_in_view]; + [NSApp postEvent:left_down_in_view atStart:YES]; + [button_ otherMouseDown:other_down_in_view]; + + EXPECT_EQ(NSOffState, [button_ state]); EXPECT_EQ(1, [button_ numOfClick]); EXPECT_EQ(IDC_HOME, [button_ lastCommand]); } diff --git a/chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm b/chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm index 7044bcc..4d3ee82 100644 --- a/chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm +++ b/chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm @@ -265,6 +265,9 @@ class NotificationBridge : public NotificationObserver { [wrenchButton_ setOpenMenuOnClick:YES]; + [backButton_ setOpenMenuOnRightClick:YES]; + [forwardButton_ setOpenMenuOnRightClick:YES]; + [backButton_ setHandleMiddleClick:YES]; [forwardButton_ setHandleMiddleClick:YES]; [reloadButton_ setHandleMiddleClick:YES]; |