Chromium Code Reviews| 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; |