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

Side by Side Diff: chrome/browser/cocoa/autocomplete_text_field_editor.mm

Issue 600133: Mac: Content blocked icons. (Closed)
Patch Set: comments andybons Created 10 years, 10 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #include "chrome/browser/browser_list.h"
13 #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" 14 #import "chrome/browser/cocoa/autocomplete_text_field_cell.h"
15 #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"
17 #import "chrome/browser/cocoa/toolbar_controller.h" 16 #import "chrome/browser/cocoa/toolbar_controller.h"
18 #include "chrome/browser/extensions/extensions_service.h" 17 #include "chrome/browser/extensions/extensions_service.h"
19 #include "chrome/common/extensions/extension_action.h" 18 #include "chrome/common/extensions/extension_action.h"
20 #include "chrome/browser/profile.h" 19 #include "chrome/browser/profile.h"
21 20
22 class Extension; 21 class Extension;
23 22
24 @interface AutocompleteTextFieldEditor(Private) 23 @interface AutocompleteTextFieldEditor(Private)
25 // Returns the default context menu to be displayed on a right mouse click. 24 // Returns the default context menu to be displayed on a right mouse click.
26 - (NSMenu*)defaultMenuForEvent:(NSEvent*)event; 25 - (NSMenu*)defaultMenuForEvent:(NSEvent*)event;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 // No ruler bar, so don't update any of that state, either. 88 // No ruler bar, so don't update any of that state, either.
90 - (void)updateRuler {} 89 - (void)updateRuler {}
91 90
92 - (NSMenu*)menuForEvent:(NSEvent*)event { 91 - (NSMenu*)menuForEvent:(NSEvent*)event {
93 NSPoint location = [self convertPoint:[event locationInWindow] fromView:nil]; 92 NSPoint location = [self convertPoint:[event locationInWindow] fromView:nil];
94 93
95 // Was the right click within a Page Action? Show a different menu if so. 94 // Was the right click within a Page Action? Show a different menu if so.
96 AutocompleteTextField* field = (AutocompleteTextField*)[self delegate]; 95 AutocompleteTextField* field = (AutocompleteTextField*)[self delegate];
97 NSRect bounds([field bounds]); 96 NSRect bounds([field bounds]);
98 AutocompleteTextFieldCell* cell = [field autocompleteTextFieldCell]; 97 AutocompleteTextFieldCell* cell = [field autocompleteTextFieldCell];
99 const size_t pageActionCount = [cell pageActionCount];
100 BOOL flipped = [self isFlipped]; 98 BOOL flipped = [self isFlipped];
101 if (!profile_)
102 return [self defaultMenuForEvent:event];
103 99
104 ExtensionsService* service = profile_->GetExtensionsService(); 100 for (AutocompleteTextFieldIcon* icon in [cell layedOutIcons:bounds]) {
105 if (!service) 101 if (NSMouseInRect(location, [icon rect], flipped)) {
106 return [self defaultMenuForEvent:event]; 102 NSMenu* menu = [icon view]->GetMenu();
107 103 if (menu)
108 for (size_t i = 0; i < pageActionCount; ++i) { 104 return menu;
109 NSRect pageActionFrame = [cell pageActionFrameForIndex:i inFrame:bounds];
110 if (NSMouseInRect(location, pageActionFrame, flipped)) {
111 Extension* extension = service->GetExtensionById(
112 [cell pageActionForIndex:i]->extension_id(), false);
113 DCHECK(extension);
114 if (!extension)
115 break;
116 return [[[ExtensionActionContextMenu alloc]
117 initWithExtension:extension profile:profile_] autorelease];
118 } 105 }
119 } 106 }
120 107
121 // Otherwise, simply return the default menu for this instance. 108 // Otherwise, simply return the default menu for this instance.
122 return [self defaultMenuForEvent:event]; 109 return [self defaultMenuForEvent:event];
123 } 110 }
124 111
125 - (NSMenu*)defaultMenuForEvent:(NSEvent*)event { 112 - (NSMenu*)defaultMenuForEvent:(NSEvent*)event {
126 NSMenu* menu = [[[NSMenu alloc] initWithTitle:@"TITLE"] autorelease]; 113 NSMenu* menu = [[[NSMenu alloc] initWithTitle:@"TITLE"] autorelease];
127 [menu addItemWithTitle:l10n_util::GetNSStringWithFixup(IDS_CUT) 114 [menu addItemWithTitle:l10n_util::GetNSStringWithFixup(IDS_CUT)
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 - (void)draggingExited:(id<NSDraggingInfo>)sender { 209 - (void)draggingExited:(id<NSDraggingInfo>)sender {
223 return [dropHandler_ draggingExited:sender]; 210 return [dropHandler_ draggingExited:sender];
224 } 211 }
225 212
226 // (URLDropTarget protocol) 213 // (URLDropTarget protocol)
227 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender { 214 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender {
228 return [dropHandler_ performDragOperation:sender]; 215 return [dropHandler_ performDragOperation:sender];
229 } 216 }
230 217
231 @end 218 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698