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

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: Created 8 years, 5 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 148651)
+++ 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,10 @@
}
}
+void RenderWidgetHostViewMac::SpeakText(const string16& text) {
+ [NSApp speakString:base::SysUTF16ToNSString(text)];
Nico 2012/07/27 22:44:26 "These are not documented, so use only after check
Alexei Svitkine (slow) 2012/07/27 22:49:48 We wouldn't get here unless respondsToSelector: is
Nico 2012/07/27 22:57:56 Comment sounds good.
Alexei Svitkine (slow) 2012/07/28 15:29:12 Done.
+}
+
//
// RenderWidgetHostViewCocoa uses the stored selection text,
// which implements NSServicesRequests protocol.
@@ -2336,6 +2347,15 @@
SEL action = [item action];
+ if (action == @selector(stopSpeaking:)) {
+ return [NSApp respondsToSelector:@selector(isSpeaking)] &&
+ [NSApp isSpeaking];
+ }
+ if (action == @selector(startSpeaking:)) {
+ return [NSApp respondsToSelector:@selector(speakString:)] &&
+ renderWidgetHostView_->render_widget_host_->IsRenderView();
+ }
+
// For now, these actions are always enabled for render view,
// this is sub-optimal.
// TODO(suzhe): Plumb the "can*" methods up from WebCore.
@@ -3068,6 +3088,17 @@
}
}
+- (void)startSpeaking:(id)sender {
+ if (renderWidgetHostView_->render_widget_host_->IsRenderView()) {
+ static_cast<RenderViewHostImpl*>(
+ renderWidgetHostView_->render_widget_host_)->SpeakSelection();
+ }
+}
+
+- (void)stopSpeaking:(id)sender {
+ [NSApp stopSpeaking:sender];
Nico 2012/07/27 22:44:26 ditto
Alexei Svitkine (slow) 2012/07/27 22:49:48 same reply
+}
+
- (void)cancelComposition {
if (!hasMarkedText_)
return;

Powered by Google App Engine
This is Rietveld 408576698