From 998cd412ba2635c1d4b14c4eb56d83168a709e1c Mon Sep 17 00:00:00 2001 From: "shess@chromium.org" Date: Fri, 26 Mar 2010 20:28:10 +0000 Subject: [Mac] Refactor page-action context menus. Push the code to handle finding menus into the cell, which knows most about page actions. Also more thoroughly work around issues with Control-click context menus. BUG=none TEST=Right-click and Control-click work the same in the Omnibox proper. TEST=Right-click and control-click bring up appropriate menu on page actions. Review URL: http://codereview.chromium.org/1431001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42814 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/cocoa/autocomplete_text_field.mm | 33 +++++++++++++++---------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'chrome/browser/cocoa/autocomplete_text_field.mm') diff --git a/chrome/browser/cocoa/autocomplete_text_field.mm b/chrome/browser/cocoa/autocomplete_text_field.mm index de04957..60d3507 100644 --- a/chrome/browser/cocoa/autocomplete_text_field.mm +++ b/chrome/browser/cocoa/autocomplete_text_field.mm @@ -70,6 +70,16 @@ // a decoration area and get the expected selection behaviour, // likewise for multiple clicks in those areas. - (void)mouseDown:(NSEvent*)theEvent { + // If the click was a Control-click, bring up the context menu. + // |NSTextField| handles these cases inconsistently if the field is + // not already first responder. + if (([theEvent modifierFlags] & NSControlKeyMask) != 0) { + NSText* editor = [self currentEditor]; + NSMenu* menu = [editor menuForEvent:theEvent]; + [NSMenu popUpContextMenu:menu withEvent:theEvent forView:editor]; + return; + } + const NSPoint location = [self convertPoint:[theEvent locationInWindow] fromView:nil]; const NSRect bounds([self bounds]); @@ -114,20 +124,12 @@ return; } - // If the user clicked on one of the icons (security icon, Page Actions, etc), - // let the icon handle the click. - const BOOL ctrlKey = ([theEvent modifierFlags] & NSControlKeyMask) != 0; + // If the user clicked on one of the icons (security icon, Page + // Actions, etc), let the icon handle the click. for (AutocompleteTextFieldIcon* icon in [cell layedOutIcons:bounds]) { - if (NSMouseInRect(location, [icon rect], flipped)) { - if (ctrlKey) { - // If the click was a Ctrl+Click, then imitate a right click and open - // the contextual menu. - NSText* editor = [self currentEditor]; - NSMenu* menu = [editor menuForEvent:theEvent]; - [NSMenu popUpContextMenu:menu withEvent:theEvent forView:editor]; - } else { - [icon view]->OnMousePressed([icon rect]); - } + const NSRect iconRect = [icon rect]; + if (NSMouseInRect(location, iconRect, flipped)) { + [icon view]->OnMousePressed(iconRect); return; } } @@ -364,4 +366,9 @@ return [dropHandler_ performDragOperation:sender]; } +- (NSMenu*)actionMenuForEvent:(NSEvent*)event { + return [[self autocompleteTextFieldCell] + actionMenuForEvent:event inRect:[self bounds] ofView:self]; +} + @end -- cgit v1.1