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" |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 IDS_SPEECH_STOP_SPEAKING_MAC); | 185 IDS_SPEECH_STOP_SPEAKING_MAC); |
186 menu_model_.AddSubMenu( | 186 menu_model_.AddSubMenu( |
187 IDC_CONTENT_CONTEXT_SPEECH_MENU, | 187 IDC_CONTENT_CONTEXT_SPEECH_MENU, |
188 l10n_util::GetStringUTF16(IDS_SPEECH_MAC), | 188 l10n_util::GetStringUTF16(IDS_SPEECH_MAC), |
189 &speech_submenu_model_); | 189 &speech_submenu_model_); |
190 } | 190 } |
191 } | 191 } |
192 } | 192 } |
193 | 193 |
194 void RenderViewContextMenuMac::LookUpInDictionary() { | 194 void RenderViewContextMenuMac::LookUpInDictionary() { |
195 // TODO(morrita): On Safari, A dictionary panel could be shown | 195 content::RenderWidgetHostView* view = GetRenderViewHost()->GetView(); |
196 // based on a preference setting of Dictionary.app. We currently | 196 if (view) |
197 // don't support it: http://crbug.com/17951 | 197 view->ShowDefinitionForSelection(); |
198 NSString* text = base::SysUTF16ToNSString(params_.selection_text); | |
199 NSPasteboard* pboard = [NSPasteboard pasteboardWithUniqueName]; | |
200 // 10.5 and earlier require declareTypes before setData. | |
201 // See the documentation on [NSPasteboard declareTypes]. | |
202 NSArray* toDeclare = [NSArray arrayWithObject:NSStringPboardType]; | |
203 [pboard declareTypes:toDeclare owner:nil]; | |
204 BOOL ok = [pboard setString:text forType:NSStringPboardType]; | |
205 if (ok) | |
206 NSPerformService(@"Look Up in Dictionary", pboard); | |
207 } | 198 } |
208 | 199 |
209 void RenderViewContextMenuMac::StartSpeaking() { | 200 void RenderViewContextMenuMac::StartSpeaking() { |
210 content::RenderWidgetHostView* view = GetRenderViewHost()->GetView(); | 201 content::RenderWidgetHostView* view = GetRenderViewHost()->GetView(); |
211 if (view) | 202 if (view) |
212 view->SpeakSelection(); | 203 view->SpeakSelection(); |
213 } | 204 } |
214 | 205 |
215 void RenderViewContextMenuMac::StopSpeaking() { | 206 void RenderViewContextMenuMac::StopSpeaking() { |
216 content::RenderWidgetHostView* view = GetRenderViewHost()->GetView(); | 207 content::RenderWidgetHostView* view = GetRenderViewHost()->GetView(); |
217 if (view) | 208 if (view) |
218 view->StopSpeaking(); | 209 view->StopSpeaking(); |
219 } | 210 } |
220 | 211 |
221 void RenderViewContextMenuMac::UpdateMenuItem(int command_id, | 212 void RenderViewContextMenuMac::UpdateMenuItem(int command_id, |
222 bool enabled, | 213 bool enabled, |
223 bool hidden, | 214 bool hidden, |
224 const string16& title) { | 215 const string16& title) { |
225 NSMenuItem* item = GetMenuItemByID(&menu_model_, [menu_controller_ menu], | 216 NSMenuItem* item = GetMenuItemByID(&menu_model_, [menu_controller_ menu], |
226 command_id); | 217 command_id); |
227 if (!item) | 218 if (!item) |
228 return; | 219 return; |
229 | 220 |
230 // Update the returned NSMenuItem directly so we can update it immediately. | 221 // Update the returned NSMenuItem directly so we can update it immediately. |
231 [item setEnabled:enabled]; | 222 [item setEnabled:enabled]; |
232 [item setTitle:SysUTF16ToNSString(title)]; | 223 [item setTitle:SysUTF16ToNSString(title)]; |
233 [item setHidden:hidden]; | 224 [item setHidden:hidden]; |
234 [[item menu] itemChanged:item]; | 225 [[item menu] itemChanged:item]; |
235 } | 226 } |
OLD | NEW |