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

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: Created 6 years, 6 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 <QuartzCore/QuartzCore.h> 8 #include <QuartzCore/QuartzCore.h>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 fullscreen_parent_host_view_(NULL), 458 fullscreen_parent_host_view_(NULL),
459 overlay_view_weak_factory_(this), 459 overlay_view_weak_factory_(this),
460 software_frame_weak_ptr_factory_(this) { 460 software_frame_weak_ptr_factory_(this) {
461 software_frame_manager_.reset(new SoftwareFrameManager( 461 software_frame_manager_.reset(new SoftwareFrameManager(
462 software_frame_weak_ptr_factory_.GetWeakPtr())); 462 software_frame_weak_ptr_factory_.GetWeakPtr()));
463 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| 463 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_|
464 // goes away. Since we autorelease it, our caller must put 464 // goes away. Since we autorelease it, our caller must put
465 // |GetNativeView()| into the view hierarchy right after calling us. 465 // |GetNativeView()| into the view hierarchy right after calling us.
466 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc] 466 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc]
467 initWithRenderWidgetHostViewMac:this] autorelease]; 467 initWithRenderWidgetHostViewMac:this] autorelease];
468
469 background_layer_.reset([[CALayer alloc] init]); 468 background_layer_.reset([[CALayer alloc] init]);
470 [background_layer_ 469 [background_layer_
471 setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)]; 470 setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)];
472 [cocoa_view_ setLayer:background_layer_]; 471 [cocoa_view_ setLayer:background_layer_];
473 [cocoa_view_ setWantsLayer:YES]; 472 [cocoa_view_ setWantsLayer:YES];
474 473
475 render_widget_host_->SetView(this); 474 render_widget_host_->SetView(this);
476 } 475 }
477 476
478 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() { 477 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() {
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 DestroyCompositedIOSurfaceLayer(kRemoveLayerFromHierarchy); 621 DestroyCompositedIOSurfaceLayer(kRemoveLayerFromHierarchy);
623 compositing_iosurface_ = NULL; 622 compositing_iosurface_ = NULL;
624 compositing_iosurface_context_ = NULL; 623 compositing_iosurface_context_ = NULL;
625 } 624 }
626 625
627 bool RenderWidgetHostViewMac::OnMessageReceived(const IPC::Message& message) { 626 bool RenderWidgetHostViewMac::OnMessageReceived(const IPC::Message& message) {
628 bool handled = true; 627 bool handled = true;
629 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewMac, message) 628 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewMac, message)
630 IPC_MESSAGE_HANDLER(ViewHostMsg_PluginFocusChanged, OnPluginFocusChanged) 629 IPC_MESSAGE_HANDLER(ViewHostMsg_PluginFocusChanged, OnPluginFocusChanged)
631 IPC_MESSAGE_HANDLER(ViewHostMsg_StartPluginIme, OnStartPluginIme) 630 IPC_MESSAGE_HANDLER(ViewHostMsg_StartPluginIme, OnStartPluginIme)
631 IPC_MESSAGE_HANDLER(ViewMsg_ExtractedDataFromRect, OnExtractedDataFromRect)
632 IPC_MESSAGE_UNHANDLED(handled = false) 632 IPC_MESSAGE_UNHANDLED(handled = false)
633 IPC_END_MESSAGE_MAP() 633 IPC_END_MESSAGE_MAP()
634 return handled; 634 return handled;
635 } 635 }
636 636
637 void RenderWidgetHostViewMac::InitAsChild( 637 void RenderWidgetHostViewMac::InitAsChild(
638 gfx::NativeView parent_view) { 638 gfx::NativeView parent_view) {
639 } 639 }
640 640
641 void RenderWidgetHostViewMac::InitAsPopup( 641 void RenderWidgetHostViewMac::InitAsPopup(
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
1048 [cocoa_view_ setToolTipAtMousePoint:tooltip_nsstring]; 1048 [cocoa_view_ setToolTipAtMousePoint:tooltip_nsstring];
1049 } 1049 }
1050 } 1050 }
1051 1051
1052 bool RenderWidgetHostViewMac::SupportsSpeech() const { 1052 bool RenderWidgetHostViewMac::SupportsSpeech() const {
1053 return [NSApp respondsToSelector:@selector(speakString:)] && 1053 return [NSApp respondsToSelector:@selector(speakString:)] &&
1054 [NSApp respondsToSelector:@selector(stopSpeaking:)]; 1054 [NSApp respondsToSelector:@selector(stopSpeaking:)];
1055 } 1055 }
1056 1056
1057 void RenderWidgetHostViewMac::SpeakSelection() { 1057 void RenderWidgetHostViewMac::SpeakSelection() {
1058 if (!selected_text_.size()) {
Alexei Svitkine (slow) 2014/06/19 14:55:09 empty()
1059 if (render_widget_host_) {
1060 // Route an IPC message to get SmartClipData from Rect
1061 gfx::Rect rect(0, 0, GetViewBounds().width(), GetViewBounds().height());
1062 render_widget_host_->Send(new ViewMsg_GetSmartClipDataFromRect(
1063 render_widget_host_->GetRoutingID(), rect));
1064 return;
1065 }
1066 }
1058 if ([NSApp respondsToSelector:@selector(speakString:)]) 1067 if ([NSApp respondsToSelector:@selector(speakString:)])
1059 [NSApp speakString:base::SysUTF8ToNSString(selected_text_)]; 1068 [NSApp speakString:base::SysUTF8ToNSString(selected_text_)];
1060 } 1069 }
1061 1070
1062 bool RenderWidgetHostViewMac::IsSpeaking() const { 1071 bool RenderWidgetHostViewMac::IsSpeaking() const {
1063 return [NSApp respondsToSelector:@selector(isSpeaking)] && 1072 return [NSApp respondsToSelector:@selector(isSpeaking)] &&
1064 [NSApp isSpeaking]; 1073 [NSApp isSpeaking];
1065 } 1074 }
1066 1075
1067 void RenderWidgetHostViewMac::StopSpeaking() { 1076 void RenderWidgetHostViewMac::StopSpeaking() {
1077 // Clear selected text when StopSpeaking is called
1078 if (selected_text_.size())
1079 selected_text_.clear();
1068 if ([NSApp respondsToSelector:@selector(stopSpeaking:)]) 1080 if ([NSApp respondsToSelector:@selector(stopSpeaking:)])
1069 [NSApp stopSpeaking:cocoa_view_]; 1081 [NSApp stopSpeaking:cocoa_view_];
1070 } 1082 }
1071 1083
1072 // 1084 //
1073 // RenderWidgetHostViewCocoa uses the stored selection text, 1085 // RenderWidgetHostViewCocoa uses the stored selection text,
1074 // which implements NSServicesRequests protocol. 1086 // which implements NSServicesRequests protocol.
1075 // 1087 //
1076 void RenderWidgetHostViewMac::SelectionChanged(const base::string16& text, 1088 void RenderWidgetHostViewMac::SelectionChanged(const base::string16& text,
1077 size_t offset, 1089 size_t offset,
(...skipping 957 matching lines...) Expand 10 before | Expand all | Expand 10 after
2035 2047
2036 void RenderWidgetHostViewMac::OnPluginFocusChanged(bool focused, 2048 void RenderWidgetHostViewMac::OnPluginFocusChanged(bool focused,
2037 int plugin_id) { 2049 int plugin_id) {
2038 [cocoa_view_ pluginFocusChanged:(focused ? YES : NO) forPlugin:plugin_id]; 2050 [cocoa_view_ pluginFocusChanged:(focused ? YES : NO) forPlugin:plugin_id];
2039 } 2051 }
2040 2052
2041 void RenderWidgetHostViewMac::OnStartPluginIme() { 2053 void RenderWidgetHostViewMac::OnStartPluginIme() {
2042 [cocoa_view_ setPluginImeActive:YES]; 2054 [cocoa_view_ setPluginImeActive:YES];
2043 } 2055 }
2044 2056
2057 void RenderWidgetHostViewMac::OnExtractedDataFromRect(const std::string& text) {
2058 // Let TTS speak the text returned from call back
2059 if (text.size()) {
Alexei Svitkine (slow) 2014/06/19 14:55:09 !empty()
2060 if ([NSApp respondsToSelector:@selector(speakString:)])
2061 [NSApp speakString:base::SysUTF8ToNSString(text)];
2062 }
2063 }
2064
2045 gfx::Rect RenderWidgetHostViewMac::GetScaledOpenGLPixelRect( 2065 gfx::Rect RenderWidgetHostViewMac::GetScaledOpenGLPixelRect(
2046 const gfx::Rect& rect) { 2066 const gfx::Rect& rect) {
2047 gfx::Rect src_gl_subrect = rect; 2067 gfx::Rect src_gl_subrect = rect;
2048 src_gl_subrect.set_y(GetViewBounds().height() - rect.bottom()); 2068 src_gl_subrect.set_y(GetViewBounds().height() - rect.bottom());
2049 2069
2050 return gfx::ToEnclosingRect(gfx::ScaleRect(src_gl_subrect, 2070 return gfx::ToEnclosingRect(gfx::ScaleRect(src_gl_subrect,
2051 ViewScaleFactor())); 2071 ViewScaleFactor()));
2052 } 2072 }
2053 2073
2054 void RenderWidgetHostViewMac::AddPendingLatencyInfo( 2074 void RenderWidgetHostViewMac::AddPendingLatencyInfo(
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
2263 if (self) { 2283 if (self) {
2264 self.acceptsTouchEvents = YES; 2284 self.acceptsTouchEvents = YES;
2265 editCommand_helper_.reset(new RenderWidgetHostViewMacEditCommandHelper); 2285 editCommand_helper_.reset(new RenderWidgetHostViewMacEditCommandHelper);
2266 editCommand_helper_->AddEditingSelectorsToClass([self class]); 2286 editCommand_helper_->AddEditingSelectorsToClass([self class]);
2267 2287
2268 renderWidgetHostView_.reset(r); 2288 renderWidgetHostView_.reset(r);
2269 canBeKeyView_ = YES; 2289 canBeKeyView_ = YES;
2270 focusedPluginIdentifier_ = -1; 2290 focusedPluginIdentifier_ = -1;
2271 renderWidgetHostView_->backing_store_scale_factor_ = 2291 renderWidgetHostView_->backing_store_scale_factor_ =
2272 ui::GetScaleFactorForNativeView(self); 2292 ui::GetScaleFactorForNativeView(self);
2273
Alexei Svitkine (slow) 2014/06/19 14:55:09 Nit: Remove superflous change
2274 // OpenGL support: 2293 // OpenGL support:
2275 if ([self respondsToSelector: 2294 if ([self respondsToSelector:
2276 @selector(setWantsBestResolutionOpenGLSurface:)]) { 2295 @selector(setWantsBestResolutionOpenGLSurface:)]) {
2277 [self setWantsBestResolutionOpenGLSurface:YES]; 2296 [self setWantsBestResolutionOpenGLSurface:YES];
2278 } 2297 }
2279 handlingGlobalFrameDidChange_ = NO; 2298 handlingGlobalFrameDidChange_ = NO;
2280 [[NSNotificationCenter defaultCenter] 2299 [[NSNotificationCenter defaultCenter]
2281 addObserver:self 2300 addObserver:self
2282 selector:@selector(didChangeScreenParameters:) 2301 selector:@selector(didChangeScreenParameters:)
2283 name:NSApplicationDidChangeScreenParametersNotification 2302 name:NSApplicationDidChangeScreenParametersNotification
(...skipping 1604 matching lines...) Expand 10 before | Expand all | Expand 10 after
3888 renderWidgetHostView_->KillSelf(); 3907 renderWidgetHostView_->KillSelf();
3889 } 3908 }
3890 3909
3891 @end 3910 @end
3892 3911
3893 // 3912 //
3894 // Supporting application services 3913 // Supporting application services
3895 // 3914 //
3896 @implementation RenderWidgetHostViewCocoa(NSServicesRequests) 3915 @implementation RenderWidgetHostViewCocoa(NSServicesRequests)
3897 3916
3917
Alexei Svitkine (slow) 2014/06/19 14:55:09 Nit: Remove superflous change
3898 - (BOOL)writeSelectionToPasteboard:(NSPasteboard*)pboard 3918 - (BOOL)writeSelectionToPasteboard:(NSPasteboard*)pboard
3899 types:(NSArray*)types { 3919 types:(NSArray*)types {
3900 const std::string& str = renderWidgetHostView_->selected_text(); 3920 const std::string& str = renderWidgetHostView_->selected_text();
3901 if (![types containsObject:NSStringPboardType] || str.empty()) return NO; 3921 if (![types containsObject:NSStringPboardType] || str.empty()) return NO;
3902 3922
3903 base::scoped_nsobject<NSString> text( 3923 base::scoped_nsobject<NSString> text(
3904 [[NSString alloc] initWithUTF8String:str.c_str()]); 3924 [[NSString alloc] initWithUTF8String:str.c_str()]);
3905 NSArray* toDeclare = [NSArray arrayWithObject:NSStringPboardType]; 3925 NSArray* toDeclare = [NSArray arrayWithObject:NSStringPboardType];
3906 [pboard declareTypes:toDeclare owner:nil]; 3926 [pboard declareTypes:toDeclare owner:nil];
3907 return [pboard setString:text forType:NSStringPboardType]; 3927 return [pboard setString:text forType:NSStringPboardType];
(...skipping 16 matching lines...) Expand all
3924 3944
3925 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding 3945 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding
3926 // regions that are not draggable. (See ControlRegionView in 3946 // regions that are not draggable. (See ControlRegionView in
3927 // native_app_window_cocoa.mm). This requires the render host view to be 3947 // native_app_window_cocoa.mm). This requires the render host view to be
3928 // draggable by default. 3948 // draggable by default.
3929 - (BOOL)mouseDownCanMoveWindow { 3949 - (BOOL)mouseDownCanMoveWindow {
3930 return YES; 3950 return YES;
3931 } 3951 }
3932 3952
3933 @end 3953 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698