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; |