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

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_mac.mm

Issue 342143004: Defect 248426: Speak rendered text when no selection is made on Mac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Uploading a clean patch Created 6 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/renderer_host/render_widget_host_view_mac.h" 5 #include "content/browser/renderer_host/render_widget_host_view_mac.h"
6 6
7 #import <objc/runtime.h> 7 #import <objc/runtime.h>
8 #include <OpenGL/gl.h> 8 #include <OpenGL/gl.h>
9 #include <QuartzCore/QuartzCore.h> 9 #include <QuartzCore/QuartzCore.h>
10 10
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 DestroyCompositedIOSurfaceLayer(kRemoveLayerFromHierarchy); 647 DestroyCompositedIOSurfaceLayer(kRemoveLayerFromHierarchy);
648 compositing_iosurface_ = NULL; 648 compositing_iosurface_ = NULL;
649 compositing_iosurface_context_ = NULL; 649 compositing_iosurface_context_ = NULL;
650 } 650 }
651 651
652 bool RenderWidgetHostViewMac::OnMessageReceived(const IPC::Message& message) { 652 bool RenderWidgetHostViewMac::OnMessageReceived(const IPC::Message& message) {
653 bool handled = true; 653 bool handled = true;
654 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewMac, message) 654 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewMac, message)
655 IPC_MESSAGE_HANDLER(ViewHostMsg_PluginFocusChanged, OnPluginFocusChanged) 655 IPC_MESSAGE_HANDLER(ViewHostMsg_PluginFocusChanged, OnPluginFocusChanged)
656 IPC_MESSAGE_HANDLER(ViewHostMsg_StartPluginIme, OnStartPluginIme) 656 IPC_MESSAGE_HANDLER(ViewHostMsg_StartPluginIme, OnStartPluginIme)
657 IPC_MESSAGE_HANDLER(ViewMsg_GetRenderedTextCompleted,
658 OnGetRenderedTextCompleted)
657 IPC_MESSAGE_UNHANDLED(handled = false) 659 IPC_MESSAGE_UNHANDLED(handled = false)
658 IPC_END_MESSAGE_MAP() 660 IPC_END_MESSAGE_MAP()
659 return handled; 661 return handled;
660 } 662 }
661 663
662 void RenderWidgetHostViewMac::InitAsChild( 664 void RenderWidgetHostViewMac::InitAsChild(
663 gfx::NativeView parent_view) { 665 gfx::NativeView parent_view) {
664 } 666 }
665 667
666 void RenderWidgetHostViewMac::InitAsPopup( 668 void RenderWidgetHostViewMac::InitAsPopup(
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 [cocoa_view_ setToolTipAtMousePoint:tooltip_nsstring]; 1075 [cocoa_view_ setToolTipAtMousePoint:tooltip_nsstring];
1074 } 1076 }
1075 } 1077 }
1076 1078
1077 bool RenderWidgetHostViewMac::SupportsSpeech() const { 1079 bool RenderWidgetHostViewMac::SupportsSpeech() const {
1078 return [NSApp respondsToSelector:@selector(speakString:)] && 1080 return [NSApp respondsToSelector:@selector(speakString:)] &&
1079 [NSApp respondsToSelector:@selector(stopSpeaking:)]; 1081 [NSApp respondsToSelector:@selector(stopSpeaking:)];
1080 } 1082 }
1081 1083
1082 void RenderWidgetHostViewMac::SpeakSelection() { 1084 void RenderWidgetHostViewMac::SpeakSelection() {
1083 if ([NSApp respondsToSelector:@selector(speakString:)]) 1085 if (![NSApp respondsToSelector:@selector(speakString:)])
1084 [NSApp speakString:base::SysUTF8ToNSString(selected_text_)]; 1086 return;
1087
1088 if (selected_text_.empty() && render_widget_host_) {
1089 // Route an IPC message to get content as text for a web contents.
jeremy 2014/06/29 11:38:55 Needs better comment, how about: // If there's no
1090 render_widget_host_->Send(new ViewMsg_GetRenderedText(
1091 render_widget_host_->GetRoutingID()));
1092 return;
1093 }
1094
1095 [NSApp speakString:base::SysUTF8ToNSString(selected_text_)];
jeremy 2014/06/29 11:38:55 My preference would be to have this moved to a pri
1085 } 1096 }
1086 1097
1087 bool RenderWidgetHostViewMac::IsSpeaking() const { 1098 bool RenderWidgetHostViewMac::IsSpeaking() const {
1088 return [NSApp respondsToSelector:@selector(isSpeaking)] && 1099 return [NSApp respondsToSelector:@selector(isSpeaking)] &&
1089 [NSApp isSpeaking]; 1100 [NSApp isSpeaking];
1090 } 1101 }
1091 1102
1092 void RenderWidgetHostViewMac::StopSpeaking() { 1103 void RenderWidgetHostViewMac::StopSpeaking() {
1093 if ([NSApp respondsToSelector:@selector(stopSpeaking:)]) 1104 if ([NSApp respondsToSelector:@selector(stopSpeaking:)])
1094 [NSApp stopSpeaking:cocoa_view_]; 1105 [NSApp stopSpeaking:cocoa_view_];
(...skipping 999 matching lines...) Expand 10 before | Expand all | Expand 10 after
2094 2105
2095 void RenderWidgetHostViewMac::OnPluginFocusChanged(bool focused, 2106 void RenderWidgetHostViewMac::OnPluginFocusChanged(bool focused,
2096 int plugin_id) { 2107 int plugin_id) {
2097 [cocoa_view_ pluginFocusChanged:(focused ? YES : NO) forPlugin:plugin_id]; 2108 [cocoa_view_ pluginFocusChanged:(focused ? YES : NO) forPlugin:plugin_id];
2098 } 2109 }
2099 2110
2100 void RenderWidgetHostViewMac::OnStartPluginIme() { 2111 void RenderWidgetHostViewMac::OnStartPluginIme() {
2101 [cocoa_view_ setPluginImeActive:YES]; 2112 [cocoa_view_ setPluginImeActive:YES];
2102 } 2113 }
2103 2114
2115 void RenderWidgetHostViewMac::OnGetRenderedTextCompleted(
2116 const std::string& text) {
2117 // Let TTS speak the text returned from call back
2118 if (text.empty())
2119 return;
jeremy 2014/06/29 11:38:55 Just thinking out loud - are we ok with a browser
sarka 2014/06/30 16:10:30 While TTS is in progress if another request is mad
2120
2121 [NSApp speakString:base::SysUTF8ToNSString(text)];
2122 }
2123
2104 gfx::Rect RenderWidgetHostViewMac::GetScaledOpenGLPixelRect( 2124 gfx::Rect RenderWidgetHostViewMac::GetScaledOpenGLPixelRect(
2105 const gfx::Rect& rect) { 2125 const gfx::Rect& rect) {
2106 gfx::Rect src_gl_subrect = rect; 2126 gfx::Rect src_gl_subrect = rect;
2107 src_gl_subrect.set_y(GetViewBounds().height() - rect.bottom()); 2127 src_gl_subrect.set_y(GetViewBounds().height() - rect.bottom());
2108 2128
2109 return gfx::ToEnclosingRect(gfx::ScaleRect(src_gl_subrect, 2129 return gfx::ToEnclosingRect(gfx::ScaleRect(src_gl_subrect,
2110 ViewScaleFactor())); 2130 ViewScaleFactor()));
2111 } 2131 }
2112 2132
2113 void RenderWidgetHostViewMac::AddPendingLatencyInfo( 2133 void RenderWidgetHostViewMac::AddPendingLatencyInfo(
(...skipping 1861 matching lines...) Expand 10 before | Expand all | Expand 10 after
3975 3995
3976 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding 3996 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding
3977 // regions that are not draggable. (See ControlRegionView in 3997 // regions that are not draggable. (See ControlRegionView in
3978 // native_app_window_cocoa.mm). This requires the render host view to be 3998 // native_app_window_cocoa.mm). This requires the render host view to be
3979 // draggable by default. 3999 // draggable by default.
3980 - (BOOL)mouseDownCanMoveWindow { 4000 - (BOOL)mouseDownCanMoveWindow {
3981 return YES; 4001 return YES;
3982 } 4002 }
3983 4003
3984 @end 4004 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698