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

Unified Diff: content/browser/renderer_host/render_widget_host_view_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: sp 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
Index: content/browser/renderer_host/render_widget_host_view_mac.mm
===================================================================
--- content/browser/renderer_host/render_widget_host_view_mac.mm (revision 149502)
+++ content/browser/renderer_host/render_widget_host_view_mac.mm (working copy)
@@ -65,6 +65,13 @@
using WebKit::WebMouseWheelEvent;
using WebKit::WebGestureEvent;
+// These are not documented, so use only after checking -respondsToSelector:.
+@interface NSApplication (UndocumentedSpeechMethods)
+- (void)speakString:(NSString*)string;
+- (void)stopSpeaking:(id)sender;
+- (BOOL)isSpeaking;
+@end
+
// Declare things that are part of the 10.7 SDK.
#if !defined(MAC_OS_X_VERSION_10_7) || \
MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7
@@ -746,6 +753,28 @@
}
}
+bool RenderWidgetHostViewMac::SupportsSpeech() const {
+ return [NSApp respondsToSelector:@selector(speakString:)] &&
+ [NSApp respondsToSelector:@selector(stopSpeaking:)];
+}
+
+void RenderWidgetHostViewMac::SpeakSelection() {
+ // No need to check -respondsToSelect: because -validateUserInterfaceItem:
+ // validates this before enabling the item.
+ [NSApp speakString:base::SysUTF8ToNSString(selected_text_)];
+}
+
+bool RenderWidgetHostViewMac::IsSpeaking() const {
+ return [NSApp respondsToSelector:@selector(isSpeaking)] &&
+ [NSApp isSpeaking];
+}
+
+void RenderWidgetHostViewMac::StopSpeaking() {
+ // No need to check -respondsToSelect: because -validateUserInterfaceItem:
+ // validates this before enabling the item.
Nico 2012/08/06 15:47:31 With this now being a public method, you probably
Alexei Svitkine (slow) 2012/08/06 16:30:42 Done.
+ [NSApp stopSpeaking:cocoa_view_];
+}
+
//
// RenderWidgetHostViewCocoa uses the stored selection text,
// which implements NSServicesRequests protocol.
@@ -2340,6 +2369,15 @@
SEL action = [item action];
+ if (action == @selector(stopSpeaking:)) {
+ return renderWidgetHostView_->render_widget_host_->IsRenderView() &&
+ renderWidgetHostView_->IsSpeaking();
+ }
+ if (action == @selector(startSpeaking:)) {
+ return renderWidgetHostView_->render_widget_host_->IsRenderView() &&
+ renderWidgetHostView_->SupportsSpeech();
+ }
+
// For now, these actions are always enabled for render view,
// this is sub-optimal.
// TODO(suzhe): Plumb the "can*" methods up from WebCore.
@@ -3071,6 +3109,14 @@
}
}
+- (void)startSpeaking:(id)sender {
+ renderWidgetHostView_->SpeakSelection();
+}
+
+- (void)stopSpeaking:(id)sender {
+ renderWidgetHostView_->StopSpeaking();
+}
+
- (void)cancelComposition {
if (!hasMarkedText_)
return;
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_mac.h ('k') | content/browser/renderer_host/test_render_view_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698