OLD | NEW |
---|---|
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 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
481 fullscreen_parent_host_view_(NULL), | 481 fullscreen_parent_host_view_(NULL), |
482 overlay_view_weak_factory_(this), | 482 overlay_view_weak_factory_(this), |
483 software_frame_weak_ptr_factory_(this) { | 483 software_frame_weak_ptr_factory_(this) { |
484 software_frame_manager_.reset(new SoftwareFrameManager( | 484 software_frame_manager_.reset(new SoftwareFrameManager( |
485 software_frame_weak_ptr_factory_.GetWeakPtr())); | 485 software_frame_weak_ptr_factory_.GetWeakPtr())); |
486 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| | 486 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| |
487 // goes away. Since we autorelease it, our caller must put | 487 // goes away. Since we autorelease it, our caller must put |
488 // |GetNativeView()| into the view hierarchy right after calling us. | 488 // |GetNativeView()| into the view hierarchy right after calling us. |
489 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc] | 489 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc] |
490 initWithRenderWidgetHostViewMac:this] autorelease]; | 490 initWithRenderWidgetHostViewMac:this] autorelease]; |
491 | |
Alexei Svitkine (slow)
2014/06/27 13:01:33
You still have an unnecessary whitespace diff here
| |
492 background_layer_.reset([[CALayer alloc] init]); | 491 background_layer_.reset([[CALayer alloc] init]); |
493 [background_layer_ | 492 [background_layer_ |
494 setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)]; | 493 setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)]; |
495 [background_layer_ setGeometryFlipped:YES]; | 494 [background_layer_ setGeometryFlipped:YES]; |
496 [background_layer_ setContentsGravity:kCAGravityTopLeft]; | 495 [background_layer_ setContentsGravity:kCAGravityTopLeft]; |
497 [cocoa_view_ setLayer:background_layer_]; | 496 [cocoa_view_ setLayer:background_layer_]; |
498 [cocoa_view_ setWantsLayer:YES]; | 497 [cocoa_view_ setWantsLayer:YES]; |
499 | 498 |
500 render_widget_host_->SetView(this); | 499 render_widget_host_->SetView(this); |
501 } | 500 } |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
647 DestroyCompositedIOSurfaceLayer(kRemoveLayerFromHierarchy); | 646 DestroyCompositedIOSurfaceLayer(kRemoveLayerFromHierarchy); |
648 compositing_iosurface_ = NULL; | 647 compositing_iosurface_ = NULL; |
649 compositing_iosurface_context_ = NULL; | 648 compositing_iosurface_context_ = NULL; |
650 } | 649 } |
651 | 650 |
652 bool RenderWidgetHostViewMac::OnMessageReceived(const IPC::Message& message) { | 651 bool RenderWidgetHostViewMac::OnMessageReceived(const IPC::Message& message) { |
653 bool handled = true; | 652 bool handled = true; |
654 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewMac, message) | 653 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewMac, message) |
655 IPC_MESSAGE_HANDLER(ViewHostMsg_PluginFocusChanged, OnPluginFocusChanged) | 654 IPC_MESSAGE_HANDLER(ViewHostMsg_PluginFocusChanged, OnPluginFocusChanged) |
656 IPC_MESSAGE_HANDLER(ViewHostMsg_StartPluginIme, OnStartPluginIme) | 655 IPC_MESSAGE_HANDLER(ViewHostMsg_StartPluginIme, OnStartPluginIme) |
656 IPC_MESSAGE_HANDLER(ViewMsg_GetRenderedTextCompleted, | |
657 OnGetRenderedTextCompleted) | |
657 IPC_MESSAGE_UNHANDLED(handled = false) | 658 IPC_MESSAGE_UNHANDLED(handled = false) |
658 IPC_END_MESSAGE_MAP() | 659 IPC_END_MESSAGE_MAP() |
659 return handled; | 660 return handled; |
660 } | 661 } |
661 | 662 |
662 void RenderWidgetHostViewMac::InitAsChild( | 663 void RenderWidgetHostViewMac::InitAsChild( |
663 gfx::NativeView parent_view) { | 664 gfx::NativeView parent_view) { |
664 } | 665 } |
665 | 666 |
666 void RenderWidgetHostViewMac::InitAsPopup( | 667 void RenderWidgetHostViewMac::InitAsPopup( |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1073 [cocoa_view_ setToolTipAtMousePoint:tooltip_nsstring]; | 1074 [cocoa_view_ setToolTipAtMousePoint:tooltip_nsstring]; |
1074 } | 1075 } |
1075 } | 1076 } |
1076 | 1077 |
1077 bool RenderWidgetHostViewMac::SupportsSpeech() const { | 1078 bool RenderWidgetHostViewMac::SupportsSpeech() const { |
1078 return [NSApp respondsToSelector:@selector(speakString:)] && | 1079 return [NSApp respondsToSelector:@selector(speakString:)] && |
1079 [NSApp respondsToSelector:@selector(stopSpeaking:)]; | 1080 [NSApp respondsToSelector:@selector(stopSpeaking:)]; |
1080 } | 1081 } |
1081 | 1082 |
1082 void RenderWidgetHostViewMac::SpeakSelection() { | 1083 void RenderWidgetHostViewMac::SpeakSelection() { |
1083 if ([NSApp respondsToSelector:@selector(speakString:)]) | 1084 if (![NSApp respondsToSelector:@selector(speakString:)]) |
1084 [NSApp speakString:base::SysUTF8ToNSString(selected_text_)]; | 1085 return; |
1086 | |
1087 if (selected_text_.empty() && render_widget_host_) { | |
1088 // Route an IPC message to get content as text for a web contents. | |
1089 render_widget_host_->Send(new ViewMsg_GetRenderedText( | |
1090 render_widget_host_->GetRoutingID())); | |
1091 return; | |
Alexei Svitkine (slow)
2014/06/27 13:01:33
Indent this 2 less.
| |
1092 } | |
1093 | |
1094 [NSApp speakString:base::SysUTF8ToNSString(selected_text_)]; | |
1085 } | 1095 } |
1086 | 1096 |
1087 bool RenderWidgetHostViewMac::IsSpeaking() const { | 1097 bool RenderWidgetHostViewMac::IsSpeaking() const { |
1088 return [NSApp respondsToSelector:@selector(isSpeaking)] && | 1098 return [NSApp respondsToSelector:@selector(isSpeaking)] && |
1089 [NSApp isSpeaking]; | 1099 [NSApp isSpeaking]; |
1090 } | 1100 } |
1091 | 1101 |
1092 void RenderWidgetHostViewMac::StopSpeaking() { | 1102 void RenderWidgetHostViewMac::StopSpeaking() { |
1093 if ([NSApp respondsToSelector:@selector(stopSpeaking:)]) | 1103 if ([NSApp respondsToSelector:@selector(stopSpeaking:)]) |
1094 [NSApp stopSpeaking:cocoa_view_]; | 1104 [NSApp stopSpeaking:cocoa_view_]; |
(...skipping 999 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2094 | 2104 |
2095 void RenderWidgetHostViewMac::OnPluginFocusChanged(bool focused, | 2105 void RenderWidgetHostViewMac::OnPluginFocusChanged(bool focused, |
2096 int plugin_id) { | 2106 int plugin_id) { |
2097 [cocoa_view_ pluginFocusChanged:(focused ? YES : NO) forPlugin:plugin_id]; | 2107 [cocoa_view_ pluginFocusChanged:(focused ? YES : NO) forPlugin:plugin_id]; |
2098 } | 2108 } |
2099 | 2109 |
2100 void RenderWidgetHostViewMac::OnStartPluginIme() { | 2110 void RenderWidgetHostViewMac::OnStartPluginIme() { |
2101 [cocoa_view_ setPluginImeActive:YES]; | 2111 [cocoa_view_ setPluginImeActive:YES]; |
2102 } | 2112 } |
2103 | 2113 |
2114 void RenderWidgetHostViewMac::OnGetRenderedTextCompleted( | |
2115 const std::string& text) { | |
2116 // Let TTS speak the text returned from call back | |
2117 if (text.empty()) | |
2118 return; | |
2119 | |
2120 [NSApp speakString:base::SysUTF8ToNSString(text)]; | |
2121 } | |
2122 | |
2104 gfx::Rect RenderWidgetHostViewMac::GetScaledOpenGLPixelRect( | 2123 gfx::Rect RenderWidgetHostViewMac::GetScaledOpenGLPixelRect( |
2105 const gfx::Rect& rect) { | 2124 const gfx::Rect& rect) { |
2106 gfx::Rect src_gl_subrect = rect; | 2125 gfx::Rect src_gl_subrect = rect; |
2107 src_gl_subrect.set_y(GetViewBounds().height() - rect.bottom()); | 2126 src_gl_subrect.set_y(GetViewBounds().height() - rect.bottom()); |
2108 | 2127 |
2109 return gfx::ToEnclosingRect(gfx::ScaleRect(src_gl_subrect, | 2128 return gfx::ToEnclosingRect(gfx::ScaleRect(src_gl_subrect, |
2110 ViewScaleFactor())); | 2129 ViewScaleFactor())); |
2111 } | 2130 } |
2112 | 2131 |
2113 void RenderWidgetHostViewMac::AddPendingLatencyInfo( | 2132 void RenderWidgetHostViewMac::AddPendingLatencyInfo( |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2314 if (self) { | 2333 if (self) { |
2315 self.acceptsTouchEvents = YES; | 2334 self.acceptsTouchEvents = YES; |
2316 editCommand_helper_.reset(new RenderWidgetHostViewMacEditCommandHelper); | 2335 editCommand_helper_.reset(new RenderWidgetHostViewMacEditCommandHelper); |
2317 editCommand_helper_->AddEditingSelectorsToClass([self class]); | 2336 editCommand_helper_->AddEditingSelectorsToClass([self class]); |
2318 | 2337 |
2319 renderWidgetHostView_.reset(r); | 2338 renderWidgetHostView_.reset(r); |
2320 canBeKeyView_ = YES; | 2339 canBeKeyView_ = YES; |
2321 focusedPluginIdentifier_ = -1; | 2340 focusedPluginIdentifier_ = -1; |
2322 renderWidgetHostView_->backing_store_scale_factor_ = | 2341 renderWidgetHostView_->backing_store_scale_factor_ = |
2323 ui::GetScaleFactorForNativeView(self); | 2342 ui::GetScaleFactorForNativeView(self); |
2324 | |
Alexei Svitkine (slow)
2014/06/27 13:01:34
You still have an unnecessary whitespace diff here
| |
2325 // OpenGL support: | 2343 // OpenGL support: |
2326 if ([self respondsToSelector: | 2344 if ([self respondsToSelector: |
2327 @selector(setWantsBestResolutionOpenGLSurface:)]) { | 2345 @selector(setWantsBestResolutionOpenGLSurface:)]) { |
2328 [self setWantsBestResolutionOpenGLSurface:YES]; | 2346 [self setWantsBestResolutionOpenGLSurface:YES]; |
2329 } | 2347 } |
2330 handlingGlobalFrameDidChange_ = NO; | 2348 handlingGlobalFrameDidChange_ = NO; |
2331 [[NSNotificationCenter defaultCenter] | 2349 [[NSNotificationCenter defaultCenter] |
2332 addObserver:self | 2350 addObserver:self |
2333 selector:@selector(didChangeScreenParameters:) | 2351 selector:@selector(didChangeScreenParameters:) |
2334 name:NSApplicationDidChangeScreenParametersNotification | 2352 name:NSApplicationDidChangeScreenParametersNotification |
(...skipping 1640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3975 | 3993 |
3976 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3994 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
3977 // regions that are not draggable. (See ControlRegionView in | 3995 // regions that are not draggable. (See ControlRegionView in |
3978 // native_app_window_cocoa.mm). This requires the render host view to be | 3996 // native_app_window_cocoa.mm). This requires the render host view to be |
3979 // draggable by default. | 3997 // draggable by default. |
3980 - (BOOL)mouseDownCanMoveWindow { | 3998 - (BOOL)mouseDownCanMoveWindow { |
3981 return YES; | 3999 return YES; |
3982 } | 4000 } |
3983 | 4001 |
3984 @end | 4002 @end |
OLD | NEW |