| 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,26 @@
|
| }
|
| }
|
|
|
| +bool RenderWidgetHostViewMac::SupportsSpeech() const {
|
| + return [NSApp respondsToSelector:@selector(speakString:)] &&
|
| + [NSApp respondsToSelector:@selector(stopSpeaking:)];
|
| +}
|
| +
|
| +void RenderWidgetHostViewMac::SpeakSelection() {
|
| + if ([NSApp respondsToSelector:@selector(speakString:)])
|
| + [NSApp speakString:base::SysUTF8ToNSString(selected_text_)];
|
| +}
|
| +
|
| +bool RenderWidgetHostViewMac::IsSpeaking() const {
|
| + return [NSApp respondsToSelector:@selector(isSpeaking)] &&
|
| + [NSApp isSpeaking];
|
| +}
|
| +
|
| +void RenderWidgetHostViewMac::StopSpeaking() {
|
| + if ([NSApp respondsToSelector:@selector(stopSpeaking:)])
|
| + [NSApp stopSpeaking:cocoa_view_];
|
| +}
|
| +
|
| //
|
| // RenderWidgetHostViewCocoa uses the stored selection text,
|
| // which implements NSServicesRequests protocol.
|
| @@ -2340,6 +2367,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 +3107,14 @@
|
| }
|
| }
|
|
|
| +- (void)startSpeaking:(id)sender {
|
| + renderWidgetHostView_->SpeakSelection();
|
| +}
|
| +
|
| +- (void)stopSpeaking:(id)sender {
|
| + renderWidgetHostView_->StopSpeaking();
|
| +}
|
| +
|
| - (void)cancelComposition {
|
| if (!hasMarkedText_)
|
| return;
|
|
|