OLD | NEW |
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 #include "chrome/browser/tab_contents/render_view_context_menu_mac.h" | 5 #include "chrome/browser/tab_contents/render_view_context_menu_mac.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
| 10 #import "chrome/browser/cocoa/ui_localizer.h" |
10 #include "chrome/browser/profile.h" | 11 #include "chrome/browser/profile.h" |
11 #include "grit/generated_resources.h" | 12 #include "grit/generated_resources.h" |
12 #include "base/scoped_nsobject.h" | 13 #include "base/scoped_nsobject.h" |
13 | 14 |
14 // Obj-C bridge class that is the target of all items in the context menu. | 15 // Obj-C bridge class that is the target of all items in the context menu. |
15 // Relies on the tag being set to the command id. Uses |context_| to | 16 // Relies on the tag being set to the command id. Uses |context_| to |
16 // execute the command once it is selected and determine if commands should | 17 // execute the command once it is selected and determine if commands should |
17 // be enabled or disabled. | 18 // be enabled or disabled. |
18 | 19 |
19 @interface ContextMenuTarget : NSObject { | 20 @interface ContextMenuTarget : NSObject { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 [NSMenu popUpContextMenu:menu_ | 64 [NSMenu popUpContextMenu:menu_ |
64 withEvent:[NSApp currentEvent] | 65 withEvent:[NSApp currentEvent] |
65 forView:parent_view_]; | 66 forView:parent_view_]; |
66 } | 67 } |
67 | 68 |
68 // Do things like remove the windows accelerators. | 69 // Do things like remove the windows accelerators. |
69 // TODO(pinkerton): Do we want to do anything like make a maximum string width | 70 // TODO(pinkerton): Do we want to do anything like make a maximum string width |
70 // and middle-truncate? | 71 // and middle-truncate? |
71 NSString* RenderViewContextMenuMac::PrepareLabelForDisplay( | 72 NSString* RenderViewContextMenuMac::PrepareLabelForDisplay( |
72 const string16& label) { | 73 const string16& label) { |
73 // Strip out any "&"'s that are windows accelerators and we don't use. | 74 NSString* title = ui_localizer::FixUpWindowsStyleLabel(label); |
74 NSMutableString* title = | |
75 [NSMutableString stringWithString:base::SysUTF16ToNSString(label)]; | |
76 DCHECK(title); | 75 DCHECK(title); |
77 NSRange range = NSMakeRange(0, [title length]); | |
78 [title replaceOccurrencesOfString:@"&" withString:@"" options:0 range:range]; | |
79 return title ? title : @""; | 76 return title ? title : @""; |
80 } | 77 } |
81 | 78 |
82 void RenderViewContextMenuMac::AppendMenuItem(int command_id) { | 79 void RenderViewContextMenuMac::AppendMenuItem(int command_id) { |
83 AppendMenuItem(command_id, l10n_util::GetStringUTF16(command_id)); | 80 AppendMenuItem(command_id, l10n_util::GetStringUTF16(command_id)); |
84 } | 81 } |
85 | 82 |
86 void RenderViewContextMenuMac::AppendMenuItem(int command_id, | 83 void RenderViewContextMenuMac::AppendMenuItem(int command_id, |
87 const string16& label) { | 84 const string16& label) { |
88 AppendMenuItemWithState(command_id, label, NSOffState); | 85 AppendMenuItemWithState(command_id, label, NSOffState); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 initWithTitle:PrepareLabelForDisplay(label) | 138 initWithTitle:PrepareLabelForDisplay(label) |
142 action:@selector(itemSelected:) | 139 action:@selector(itemSelected:) |
143 keyEquivalent:@""]); | 140 keyEquivalent:@""]); |
144 [item setState:state]; | 141 [item setState:state]; |
145 [item setTag:command_id]; | 142 [item setTag:command_id]; |
146 [item setTarget:target_]; | 143 [item setTarget:target_]; |
147 [item setEnabled:IsItemCommandEnabled(command_id) ? YES : NO]; | 144 [item setEnabled:IsItemCommandEnabled(command_id) ? YES : NO]; |
148 [insert_menu_ addItem:item]; | 145 [insert_menu_ addItem:item]; |
149 } | 146 } |
150 | 147 |
OLD | NEW |