summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/autocomplete_text_field.mm
diff options
context:
space:
mode:
authorshess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-26 20:28:10 +0000
committershess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-26 20:28:10 +0000
commit998cd412ba2635c1d4b14c4eb56d83168a709e1c (patch)
tree586c427c0b4e08ea1535382cd6b67b6bee634ec2 /chrome/browser/cocoa/autocomplete_text_field.mm
parentd51eb48985356adc40a55d678b14f0c0a5870ffb (diff)
downloadchromium_src-998cd412ba2635c1d4b14c4eb56d83168a709e1c.zip
chromium_src-998cd412ba2635c1d4b14c4eb56d83168a709e1c.tar.gz
chromium_src-998cd412ba2635c1d4b14c4eb56d83168a709e1c.tar.bz2
[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
Diffstat (limited to 'chrome/browser/cocoa/autocomplete_text_field.mm')
-rw-r--r--chrome/browser/cocoa/autocomplete_text_field.mm33
1 files changed, 20 insertions, 13 deletions
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