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

Unified Diff: chrome/browser/ui/cocoa/tab_contents/render_view_context_menu_mac.mm

Issue 10820062: [Mac]: Enable speech sub-menu under the edit menu and pipe it through to the renderer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/app/nibs/MainMenu.xib ('k') | content/browser/renderer_host/render_widget_host_view_mac.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/cocoa/tab_contents/render_view_context_menu_mac.mm
===================================================================
--- chrome/browser/ui/cocoa/tab_contents/render_view_context_menu_mac.mm (revision 149502)
+++ chrome/browser/ui/cocoa/tab_contents/render_view_context_menu_mac.mm (working copy)
@@ -12,18 +12,13 @@
#include "chrome/app/chrome_command_ids.h"
#import "chrome/browser/ui/cocoa/browser_window_controller.h"
#import "chrome/browser/ui/cocoa/menu_controller.h"
+#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/render_widget_host_view.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
using content::WebContents;
-// These are not documented, so use only after checking -respondsToSelector:.
-@interface NSApplication (UndocumentedSpeechMethods)
-- (void)speakString:(NSString*)string;
-- (void)stopSpeaking:(id)sender;
-- (BOOL)isSpeaking;
-@end
-
namespace {
// Retrieves an NSMenuItem which has the specified command_id. This function
@@ -155,9 +150,10 @@
// appropriate.
return true;
- case IDC_CONTENT_CONTEXT_SPEECH_STOP_SPEAKING:
- return [NSApp respondsToSelector:@selector(isSpeaking)] &&
- [NSApp isSpeaking];
+ case IDC_CONTENT_CONTEXT_SPEECH_STOP_SPEAKING: {
+ content::RenderWidgetHostView* view = GetRenderViewHost()->GetView();
+ return view && view->IsSpeaking();
+ }
default:
return RenderViewContextMenu::IsCommandIdEnabled(command_id);
@@ -179,18 +175,17 @@
IDC_CONTENT_CONTEXT_LOOK_UP_IN_DICTIONARY,
IDS_CONTENT_CONTEXT_LOOK_UP_IN_DICTIONARY);
- // Add speech items only if NSApp supports the private API we're using.
- if ([NSApp respondsToSelector:@selector(speakString:)] &&
- [NSApp respondsToSelector:@selector(stopSpeaking:)]) {
+ content::RenderWidgetHostView* view = GetRenderViewHost()->GetView();
+ if (view && view->SupportsSpeech()) {
speech_submenu_model_.AddItemWithStringId(
IDC_CONTENT_CONTEXT_SPEECH_START_SPEAKING,
- IDS_CONTENT_CONTEXT_SPEECH_START_SPEAKING);
+ IDS_SPEECH_START_SPEAKING_MAC);
speech_submenu_model_.AddItemWithStringId(
IDC_CONTENT_CONTEXT_SPEECH_STOP_SPEAKING,
- IDS_CONTENT_CONTEXT_SPEECH_STOP_SPEAKING);
+ IDS_SPEECH_STOP_SPEAKING_MAC);
menu_model_.AddSubMenu(
IDC_CONTENT_CONTEXT_SPEECH_MENU,
- l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPEECH_MENU),
+ l10n_util::GetStringUTF16(IDS_SPEECH_MAC),
&speech_submenu_model_);
}
}
@@ -212,12 +207,15 @@
}
void RenderViewContextMenuMac::StartSpeaking() {
- NSString* text = base::SysUTF16ToNSString(params_.selection_text);
- [NSApp speakString:text];
+ content::RenderWidgetHostView* view = GetRenderViewHost()->GetView();
+ if (view)
+ view->SpeakSelection();
}
void RenderViewContextMenuMac::StopSpeaking() {
- [NSApp stopSpeaking:menu_controller_];
+ content::RenderWidgetHostView* view = GetRenderViewHost()->GetView();
+ if (view)
+ view->StopSpeaking();
}
void RenderViewContextMenuMac::UpdateMenuItem(int command_id,
« no previous file with comments | « chrome/app/nibs/MainMenu.xib ('k') | content/browser/renderer_host/render_widget_host_view_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698