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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "chrome/browser/cocoa/autocomplete_text_field_editor.h" 5 #import "chrome/browser/cocoa/autocomplete_text_field_editor.h"
6 6
7 #include "app/l10n_util_mac.h" 7 #include "app/l10n_util_mac.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "grit/generated_resources.h" 9 #include "grit/generated_resources.h"
10 #include "base/sys_string_conversions.h" 10 #include "base/sys_string_conversions.h"
11 #include "chrome/app/chrome_dll_resource.h" // IDC_* 11 #include "chrome/app/chrome_dll_resource.h" // IDC_*
12 #include "chrome/browser/browser_list.h"
12 #import "chrome/browser/cocoa/autocomplete_text_field.h" 13 #import "chrome/browser/cocoa/autocomplete_text_field.h"
14 #import "chrome/browser/cocoa/autocomplete_text_field_cell.h"
13 #import "chrome/browser/cocoa/browser_window_controller.h" 15 #import "chrome/browser/cocoa/browser_window_controller.h"
16 #import "chrome/browser/cocoa/extensions/extension_action_context_menu.h"
14 #import "chrome/browser/cocoa/toolbar_controller.h" 17 #import "chrome/browser/cocoa/toolbar_controller.h"
18 #include "chrome/browser/extensions/extensions_service.h"
19 #include "chrome/common/extensions/extension_action.h"
20
21 class Extension;
22
23 @interface AutocompleteTextFieldEditor(Private)
24 // Returns the default context menu to be displayed on a right mouse click.
25 - (NSMenu*)defaultMenuForEvent:(NSEvent*)event;
26 @end
15 27
16 @implementation AutocompleteTextFieldEditor 28 @implementation AutocompleteTextFieldEditor
17 29
18 - (id)initWithFrame:(NSRect)frameRect { 30 - (id)initWithFrame:(NSRect)frameRect {
19 if ((self = [super initWithFrame:frameRect])) 31 if ((self = [super initWithFrame:frameRect]))
20 dropHandler_.reset([[URLDropTargetHandler alloc] initWithView:self]); 32 dropHandler_.reset([[URLDropTargetHandler alloc] initWithView:self]);
21 return self; 33 return self;
22 } 34 }
23 35
24 - (void)copy:(id)sender { 36 - (void)copy:(id)sender {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 observer->OnPasteAndGo(); 83 observer->OnPasteAndGo();
72 } 84 }
73 } 85 }
74 86
75 // We have rich text, but it shouldn't be modified by the user, so 87 // We have rich text, but it shouldn't be modified by the user, so
76 // don't update the font panel. In theory, -setUsesFontPanel: should 88 // don't update the font panel. In theory, -setUsesFontPanel: should
77 // accomplish this, but that gets called frequently with YES when 89 // accomplish this, but that gets called frequently with YES when
78 // NSTextField and NSTextView synchronize their contents. That is 90 // NSTextField and NSTextView synchronize their contents. That is
79 // probably unavoidable because in most cases having rich text in the 91 // probably unavoidable because in most cases having rich text in the
80 // field you probably would expect it to update the font panel. 92 // field you probably would expect it to update the font panel.
81 - (void)updateFontPanel { 93 - (void)updateFontPanel {}
94
95 // No ruler bar, so don't update any of that state, either.
96 - (void)updateRuler {}
97
98 - (NSMenu*)menuForEvent:(NSEvent*)event {
99 NSPoint location = [self convertPoint:[event locationInWindow] fromView:nil];
100
101 // Was the right click within a Page Action? Show a different menu if so.
102 NSRect bounds([[self delegate] bounds]);
103 AutocompleteTextFieldCell* cell = [[self delegate] autocompleteTextFieldCell];
104 const size_t pageActionCount = [cell pageActionCount];
105 BOOL flipped = [self isFlipped];
106 Browser* browser = BrowserList::GetLastActive();
107 // GetLastActive() returns NULL during testing.
108 if (!browser)
109 return [self defaultMenuForEvent:event];
110 ExtensionsService* service = browser->profile()->GetExtensionsService();
111 for (size_t i = 0; i < pageActionCount; ++i) {
112 NSRect pageActionFrame = [cell pageActionFrameForIndex:i inFrame:bounds];
113 if (NSMouseInRect(location, pageActionFrame, flipped)) {
114 Extension* extension = service->GetExtensionById(
115 [cell pageActionForIndex:i]->extension_id(), false);
116 DCHECK(extension);
117 if (!extension)
118 break;
119 return [[[ExtensionActionContextMenu alloc] initWithExtension:extension]
120 autorelease];
121 }
122 }
123
124 // Otherwise, simply return the default menu for this instance.
125 return [self defaultMenuForEvent:event];
82 } 126 }
83 127
84 // No ruler bar, so don't update any of that state, either. 128 - (NSMenu*)defaultMenuForEvent:(NSEvent*)event {
85 - (void)updateRuler {
86 }
87
88 - (NSMenu*)menuForEvent:(NSEvent*)event {
89 NSMenu* menu = [[[NSMenu alloc] initWithTitle:@"TITLE"] autorelease]; 129 NSMenu* menu = [[[NSMenu alloc] initWithTitle:@"TITLE"] autorelease];
90 [menu addItemWithTitle:l10n_util::GetNSStringWithFixup(IDS_CUT) 130 [menu addItemWithTitle:l10n_util::GetNSStringWithFixup(IDS_CUT)
91 action:@selector(cut:) 131 action:@selector(cut:)
92 keyEquivalent:@""]; 132 keyEquivalent:@""];
93 [menu addItemWithTitle:l10n_util::GetNSStringWithFixup(IDS_COPY) 133 [menu addItemWithTitle:l10n_util::GetNSStringWithFixup(IDS_COPY)
94 action:@selector(copy:) 134 action:@selector(copy:)
95 keyEquivalent:@""]; 135 keyEquivalent:@""];
96 [menu addItemWithTitle:l10n_util::GetNSStringWithFixup(IDS_PASTE) 136 [menu addItemWithTitle:l10n_util::GetNSStringWithFixup(IDS_PASTE)
97 action:@selector(paste:) 137 action:@selector(paste:)
98 keyEquivalent:@""]; 138 keyEquivalent:@""];
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 - (void)draggingExited:(id<NSDraggingInfo>)sender { 195 - (void)draggingExited:(id<NSDraggingInfo>)sender {
156 return [dropHandler_ draggingExited:sender]; 196 return [dropHandler_ draggingExited:sender];
157 } 197 }
158 198
159 // (URLDropTarget protocol) 199 // (URLDropTarget protocol)
160 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender { 200 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender {
161 return [dropHandler_ performDragOperation:sender]; 201 return [dropHandler_ performDragOperation:sender];
162 } 202 }
163 203
164 @end 204 @end
OLDNEW
« 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