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

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: Added a link to newly created defect that addresses IPC data handling capabilities 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 - (void)processedWheelEvent:(const blink::WebMouseWheelEvent&)event 144 - (void)processedWheelEvent:(const blink::WebMouseWheelEvent&)event
145 consumed:(BOOL)consumed; 145 consumed:(BOOL)consumed;
146 146
147 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv; 147 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv;
148 - (void)windowDidChangeBackingProperties:(NSNotification*)notification; 148 - (void)windowDidChangeBackingProperties:(NSNotification*)notification;
149 - (void)windowChangedGlobalFrame:(NSNotification*)notification; 149 - (void)windowChangedGlobalFrame:(NSNotification*)notification;
150 - (void)checkForPluginImeCancellation; 150 - (void)checkForPluginImeCancellation;
151 - (void)updateScreenProperties; 151 - (void)updateScreenProperties;
152 - (void)setResponderDelegate: 152 - (void)setResponderDelegate:
153 (NSObject<RenderWidgetHostViewMacDelegate>*)delegate; 153 (NSObject<RenderWidgetHostViewMacDelegate>*)delegate;
154 - (void)speakText:(NSString*)text;
154 @end 155 @end
155 156
156 // A window subclass that allows the fullscreen window to become main and gain 157 // A window subclass that allows the fullscreen window to become main and gain
157 // keyboard focus. This is only used for pepper flash. Normal fullscreen is 158 // keyboard focus. This is only used for pepper flash. Normal fullscreen is
158 // handled by the browser. 159 // handled by the browser.
159 @interface PepperFlashFullscreenWindow : UnderlayOpenGLHostingWindow 160 @interface PepperFlashFullscreenWindow : UnderlayOpenGLHostingWindow
160 @end 161 @end
161 162
162 @implementation PepperFlashFullscreenWindow 163 @implementation PepperFlashFullscreenWindow
163 164
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 DestroyCompositedIOSurfaceLayer(kRemoveLayerFromHierarchy); 648 DestroyCompositedIOSurfaceLayer(kRemoveLayerFromHierarchy);
648 compositing_iosurface_ = NULL; 649 compositing_iosurface_ = NULL;
649 compositing_iosurface_context_ = NULL; 650 compositing_iosurface_context_ = NULL;
650 } 651 }
651 652
652 bool RenderWidgetHostViewMac::OnMessageReceived(const IPC::Message& message) { 653 bool RenderWidgetHostViewMac::OnMessageReceived(const IPC::Message& message) {
653 bool handled = true; 654 bool handled = true;
654 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewMac, message) 655 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewMac, message)
655 IPC_MESSAGE_HANDLER(ViewHostMsg_PluginFocusChanged, OnPluginFocusChanged) 656 IPC_MESSAGE_HANDLER(ViewHostMsg_PluginFocusChanged, OnPluginFocusChanged)
656 IPC_MESSAGE_HANDLER(ViewHostMsg_StartPluginIme, OnStartPluginIme) 657 IPC_MESSAGE_HANDLER(ViewHostMsg_StartPluginIme, OnStartPluginIme)
658 IPC_MESSAGE_HANDLER(ViewMsg_GetRenderedTextCompleted,
659 OnGetRenderedTextCompleted)
657 IPC_MESSAGE_UNHANDLED(handled = false) 660 IPC_MESSAGE_UNHANDLED(handled = false)
658 IPC_END_MESSAGE_MAP() 661 IPC_END_MESSAGE_MAP()
659 return handled; 662 return handled;
660 } 663 }
661 664
662 void RenderWidgetHostViewMac::InitAsChild( 665 void RenderWidgetHostViewMac::InitAsChild(
663 gfx::NativeView parent_view) { 666 gfx::NativeView parent_view) {
664 } 667 }
665 668
666 void RenderWidgetHostViewMac::InitAsPopup( 669 void RenderWidgetHostViewMac::InitAsPopup(
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 [cocoa_view_ setToolTipAtMousePoint:tooltip_nsstring]; 1076 [cocoa_view_ setToolTipAtMousePoint:tooltip_nsstring];
1074 } 1077 }
1075 } 1078 }
1076 1079
1077 bool RenderWidgetHostViewMac::SupportsSpeech() const { 1080 bool RenderWidgetHostViewMac::SupportsSpeech() const {
1078 return [NSApp respondsToSelector:@selector(speakString:)] && 1081 return [NSApp respondsToSelector:@selector(speakString:)] &&
1079 [NSApp respondsToSelector:@selector(stopSpeaking:)]; 1082 [NSApp respondsToSelector:@selector(stopSpeaking:)];
1080 } 1083 }
1081 1084
1082 void RenderWidgetHostViewMac::SpeakSelection() { 1085 void RenderWidgetHostViewMac::SpeakSelection() {
1083 if ([NSApp respondsToSelector:@selector(speakString:)]) 1086 if (![NSApp respondsToSelector:@selector(speakString:)])
1084 [NSApp speakString:base::SysUTF8ToNSString(selected_text_)]; 1087 return;
1088
1089 if (selected_text_.empty() && render_widget_host_) {
1090 // If there's no selection, speak all text. Send an asynchronous IPC
1091 // request for all the text in the webcontents.
1092 // ViewMsg_GetRenderedTextCompleted is sent back to IPC Message receiver.
1093 render_widget_host_->Send(new ViewMsg_GetRenderedText(
1094 render_widget_host_->GetRoutingID()));
1095 return;
1096 }
1097
1098 [cocoa_view_ speakText:base::SysUTF8ToNSString(selected_text_)];
1085 } 1099 }
1086 1100
1087 bool RenderWidgetHostViewMac::IsSpeaking() const { 1101 bool RenderWidgetHostViewMac::IsSpeaking() const {
1088 return [NSApp respondsToSelector:@selector(isSpeaking)] && 1102 return [NSApp respondsToSelector:@selector(isSpeaking)] &&
1089 [NSApp isSpeaking]; 1103 [NSApp isSpeaking];
1090 } 1104 }
1091 1105
1092 void RenderWidgetHostViewMac::StopSpeaking() { 1106 void RenderWidgetHostViewMac::StopSpeaking() {
1093 if ([NSApp respondsToSelector:@selector(stopSpeaking:)]) 1107 if ([NSApp respondsToSelector:@selector(stopSpeaking:)])
1094 [NSApp stopSpeaking:cocoa_view_]; 1108 [NSApp stopSpeaking:cocoa_view_];
(...skipping 999 matching lines...) Expand 10 before | Expand all | Expand 10 after
2094 2108
2095 void RenderWidgetHostViewMac::OnPluginFocusChanged(bool focused, 2109 void RenderWidgetHostViewMac::OnPluginFocusChanged(bool focused,
2096 int plugin_id) { 2110 int plugin_id) {
2097 [cocoa_view_ pluginFocusChanged:(focused ? YES : NO) forPlugin:plugin_id]; 2111 [cocoa_view_ pluginFocusChanged:(focused ? YES : NO) forPlugin:plugin_id];
2098 } 2112 }
2099 2113
2100 void RenderWidgetHostViewMac::OnStartPluginIme() { 2114 void RenderWidgetHostViewMac::OnStartPluginIme() {
2101 [cocoa_view_ setPluginImeActive:YES]; 2115 [cocoa_view_ setPluginImeActive:YES];
2102 } 2116 }
2103 2117
2118 void RenderWidgetHostViewMac::OnGetRenderedTextCompleted(
2119 const std::string& text) {
2120 // Let TTS speak the text returned from call back
2121 if (text.empty())
2122 return;
2123
2124 [cocoa_view_ speakText:base::SysUTF8ToNSString(text)];
2125 }
2126
2104 gfx::Rect RenderWidgetHostViewMac::GetScaledOpenGLPixelRect( 2127 gfx::Rect RenderWidgetHostViewMac::GetScaledOpenGLPixelRect(
2105 const gfx::Rect& rect) { 2128 const gfx::Rect& rect) {
2106 gfx::Rect src_gl_subrect = rect; 2129 gfx::Rect src_gl_subrect = rect;
2107 src_gl_subrect.set_y(GetViewBounds().height() - rect.bottom()); 2130 src_gl_subrect.set_y(GetViewBounds().height() - rect.bottom());
2108 2131
2109 return gfx::ToEnclosingRect(gfx::ScaleRect(src_gl_subrect, 2132 return gfx::ToEnclosingRect(gfx::ScaleRect(src_gl_subrect,
2110 ViewScaleFactor())); 2133 ViewScaleFactor()));
2111 } 2134 }
2112 2135
2113 void RenderWidgetHostViewMac::AddPendingLatencyInfo( 2136 void RenderWidgetHostViewMac::AddPendingLatencyInfo(
(...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after
2935 // Note that we don't attempt to bracket these by GesturePinchBegin/End (or 2958 // Note that we don't attempt to bracket these by GesturePinchBegin/End (or
2936 // GestureSrollBegin/End) as is done for touchscreen. Keeping track of when 2959 // GestureSrollBegin/End) as is done for touchscreen. Keeping track of when
2937 // a pinch is active would take a little more work here, and we don't need 2960 // a pinch is active would take a little more work here, and we don't need
2938 // it for anything yet. 2961 // it for anything yet.
2939 const WebGestureEvent& webEvent = 2962 const WebGestureEvent& webEvent =
2940 WebInputEventFactory::gestureEvent(event, self); 2963 WebInputEventFactory::gestureEvent(event, self);
2941 renderWidgetHostView_->render_widget_host_->ForwardGestureEvent(webEvent); 2964 renderWidgetHostView_->render_widget_host_->ForwardGestureEvent(webEvent);
2942 } 2965 }
2943 } 2966 }
2944 2967
2968 - (void)speakText:(NSString *) text {
2969 [NSApp speakString:text];
2970 }
2971
2945 - (void)viewWillMoveToWindow:(NSWindow*)newWindow { 2972 - (void)viewWillMoveToWindow:(NSWindow*)newWindow {
2946 NSWindow* oldWindow = [self window]; 2973 NSWindow* oldWindow = [self window];
2947 2974
2948 NSNotificationCenter* notificationCenter = 2975 NSNotificationCenter* notificationCenter =
2949 [NSNotificationCenter defaultCenter]; 2976 [NSNotificationCenter defaultCenter];
2950 2977
2951 // Backing property notifications crash on 10.6 when building with the 10.7 2978 // Backing property notifications crash on 10.6 when building with the 10.7
2952 // SDK, see http://crbug.com/260595. 2979 // SDK, see http://crbug.com/260595.
2953 static BOOL supportsBackingPropertiesNotification = 2980 static BOOL supportsBackingPropertiesNotification =
2954 SupportsBackingPropertiesChangedNotification(); 2981 SupportsBackingPropertiesChangedNotification();
(...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after
3975 4002
3976 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding 4003 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding
3977 // regions that are not draggable. (See ControlRegionView in 4004 // regions that are not draggable. (See ControlRegionView in
3978 // native_app_window_cocoa.mm). This requires the render host view to be 4005 // native_app_window_cocoa.mm). This requires the render host view to be
3979 // draggable by default. 4006 // draggable by default.
3980 - (BOOL)mouseDownCanMoveWindow { 4007 - (BOOL)mouseDownCanMoveWindow {
3981 return YES; 4008 return YES;
3982 } 4009 }
3983 4010
3984 @end 4011 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698