OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/cocoa/tab_contents/render_view_context_menu_mac.h" | 5 #include "chrome/browser/ui/cocoa/tab_contents/render_view_context_menu_mac.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #import "base/mac/scoped_sending_event.h" | 8 #import "base/mac/scoped_sending_event.h" |
9 #include "base/memory/scoped_nsobject.h" | 9 #include "base/memory/scoped_nsobject.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "base/sys_string_conversions.h" | 11 #include "base/sys_string_conversions.h" |
12 #include "chrome/app/chrome_command_ids.h" | 12 #include "chrome/app/chrome_command_ids.h" |
13 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 13 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
14 #import "chrome/browser/ui/cocoa/menu_controller.h" | 14 #import "chrome/browser/ui/cocoa/menu_controller.h" |
| 15 #include "content/public/browser/render_view_host.h" |
| 16 #include "content/public/browser/render_widget_host_view.h" |
15 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
16 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
17 | 19 |
18 using content::WebContents; | 20 using content::WebContents; |
19 | 21 |
20 // These are not documented, so use only after checking -respondsToSelector:. | 22 // These are not documented, so use only after checking -respondsToSelector:. |
21 @interface NSApplication (UndocumentedSpeechMethods) | 23 @interface NSApplication (UndocumentedSpeechMethods) |
22 - (void)speakString:(NSString*)string; | 24 - (void)speakString:(NSString*)string; |
23 - (void)stopSpeaking:(id)sender; | 25 - (void)stopSpeaking:(id)sender; |
24 - (BOOL)isSpeaking; | 26 - (BOOL)isSpeaking; |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 IDS_CONTENT_CONTEXT_SPEECH_STOP_SPEAKING); | 192 IDS_CONTENT_CONTEXT_SPEECH_STOP_SPEAKING); |
191 menu_model_.AddSubMenu( | 193 menu_model_.AddSubMenu( |
192 IDC_CONTENT_CONTEXT_SPEECH_MENU, | 194 IDC_CONTENT_CONTEXT_SPEECH_MENU, |
193 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPEECH_MENU), | 195 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPEECH_MENU), |
194 &speech_submenu_model_); | 196 &speech_submenu_model_); |
195 } | 197 } |
196 } | 198 } |
197 } | 199 } |
198 | 200 |
199 void RenderViewContextMenuMac::LookUpInDictionary() { | 201 void RenderViewContextMenuMac::LookUpInDictionary() { |
200 // TODO(morrita): On Safari, A dictionary panel could be shown | 202 content::RenderWidgetHostView* view = GetRenderViewHost()->GetView(); |
201 // based on a preference setting of Dictionary.app. We currently | 203 if (view) |
202 // don't support it: http://crbug.com/17951 | 204 view->ShowDefinitionForSelection(); |
203 NSString* text = base::SysUTF16ToNSString(params_.selection_text); | |
204 NSPasteboard* pboard = [NSPasteboard pasteboardWithUniqueName]; | |
205 // 10.5 and earlier require declareTypes before setData. | |
206 // See the documentation on [NSPasteboard declareTypes]. | |
207 NSArray* toDeclare = [NSArray arrayWithObject:NSStringPboardType]; | |
208 [pboard declareTypes:toDeclare owner:nil]; | |
209 BOOL ok = [pboard setString:text forType:NSStringPboardType]; | |
210 if (ok) | |
211 NSPerformService(@"Look Up in Dictionary", pboard); | |
212 } | 205 } |
213 | 206 |
214 void RenderViewContextMenuMac::StartSpeaking() { | 207 void RenderViewContextMenuMac::StartSpeaking() { |
215 NSString* text = base::SysUTF16ToNSString(params_.selection_text); | 208 NSString* text = base::SysUTF16ToNSString(params_.selection_text); |
216 [NSApp speakString:text]; | 209 [NSApp speakString:text]; |
217 } | 210 } |
218 | 211 |
219 void RenderViewContextMenuMac::StopSpeaking() { | 212 void RenderViewContextMenuMac::StopSpeaking() { |
220 [NSApp stopSpeaking:menu_controller_]; | 213 [NSApp stopSpeaking:menu_controller_]; |
221 } | 214 } |
222 | 215 |
223 void RenderViewContextMenuMac::UpdateMenuItem(int command_id, | 216 void RenderViewContextMenuMac::UpdateMenuItem(int command_id, |
224 bool enabled, | 217 bool enabled, |
225 bool hidden, | 218 bool hidden, |
226 const string16& title) { | 219 const string16& title) { |
227 NSMenuItem* item = GetMenuItemByID(&menu_model_, [menu_controller_ menu], | 220 NSMenuItem* item = GetMenuItemByID(&menu_model_, [menu_controller_ menu], |
228 command_id); | 221 command_id); |
229 if (!item) | 222 if (!item) |
230 return; | 223 return; |
231 | 224 |
232 // Update the returned NSMenuItem directly so we can update it immediately. | 225 // Update the returned NSMenuItem directly so we can update it immediately. |
233 [item setEnabled:enabled]; | 226 [item setEnabled:enabled]; |
234 [item setTitle:SysUTF16ToNSString(title)]; | 227 [item setTitle:SysUTF16ToNSString(title)]; |
235 [item setHidden:hidden]; | 228 [item setHidden:hidden]; |
236 [[item menu] itemChanged:item]; | 229 [[item menu] itemChanged:item]; |
237 } | 230 } |
OLD | NEW |