Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Unified Diff: chrome/browser/cocoa/autocomplete_text_field_editor.mm

Issue 525098: [Mac] Implements context menus for Page Actions. Introduces a reusable subcla... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Final changes before submit. Created 10 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/cocoa/autocomplete_text_field_editor.mm
===================================================================
--- chrome/browser/cocoa/autocomplete_text_field_editor.mm (revision 36013)
+++ chrome/browser/cocoa/autocomplete_text_field_editor.mm (working copy)
@@ -9,10 +9,22 @@
#include "grit/generated_resources.h"
#include "base/sys_string_conversions.h"
#include "chrome/app/chrome_dll_resource.h" // IDC_*
+#include "chrome/browser/browser_list.h"
#import "chrome/browser/cocoa/autocomplete_text_field.h"
+#import "chrome/browser/cocoa/autocomplete_text_field_cell.h"
#import "chrome/browser/cocoa/browser_window_controller.h"
+#import "chrome/browser/cocoa/extensions/extension_action_context_menu.h"
#import "chrome/browser/cocoa/toolbar_controller.h"
+#include "chrome/browser/extensions/extensions_service.h"
+#include "chrome/common/extensions/extension_action.h"
+class Extension;
+
+@interface AutocompleteTextFieldEditor(Private)
+// Returns the default context menu to be displayed on a right mouse click.
+- (NSMenu*)defaultMenuForEvent:(NSEvent*)event;
+@end
+
@implementation AutocompleteTextFieldEditor
- (id)initWithFrame:(NSRect)frameRect {
@@ -78,14 +90,42 @@
// NSTextField and NSTextView synchronize their contents. That is
// probably unavoidable because in most cases having rich text in the
// field you probably would expect it to update the font panel.
-- (void)updateFontPanel {
-}
+- (void)updateFontPanel {}
// No ruler bar, so don't update any of that state, either.
-- (void)updateRuler {
+- (void)updateRuler {}
+
+- (NSMenu*)menuForEvent:(NSEvent*)event {
+ NSPoint location = [self convertPoint:[event locationInWindow] fromView:nil];
+
+ // Was the right click within a Page Action? Show a different menu if so.
+ NSRect bounds([[self delegate] bounds]);
+ AutocompleteTextFieldCell* cell = [[self delegate] autocompleteTextFieldCell];
+ const size_t pageActionCount = [cell pageActionCount];
+ BOOL flipped = [self isFlipped];
+ Browser* browser = BrowserList::GetLastActive();
+ // GetLastActive() returns NULL during testing.
+ if (!browser)
+ return [self defaultMenuForEvent:event];
+ ExtensionsService* service = browser->profile()->GetExtensionsService();
+ for (size_t i = 0; i < pageActionCount; ++i) {
+ NSRect pageActionFrame = [cell pageActionFrameForIndex:i inFrame:bounds];
+ if (NSMouseInRect(location, pageActionFrame, flipped)) {
+ Extension* extension = service->GetExtensionById(
+ [cell pageActionForIndex:i]->extension_id(), false);
+ DCHECK(extension);
+ if (!extension)
+ break;
+ return [[[ExtensionActionContextMenu alloc] initWithExtension:extension]
+ autorelease];
+ }
+ }
+
+ // Otherwise, simply return the default menu for this instance.
+ return [self defaultMenuForEvent:event];
}
-- (NSMenu*)menuForEvent:(NSEvent*)event {
+- (NSMenu*)defaultMenuForEvent:(NSEvent*)event {
NSMenu* menu = [[[NSMenu alloc] initWithTitle:@"TITLE"] autorelease];
[menu addItemWithTitle:l10n_util::GetNSStringWithFixup(IDS_CUT)
action:@selector(cut:)
« no previous file with comments | « chrome/browser/cocoa/autocomplete_text_field_cell.mm ('k') | chrome/browser/cocoa/extensions/browser_actions_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698