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 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
463 fullscreen_parent_host_view_(NULL), | 463 fullscreen_parent_host_view_(NULL), |
464 overlay_view_weak_factory_(this), | 464 overlay_view_weak_factory_(this), |
465 software_frame_weak_ptr_factory_(this) { | 465 software_frame_weak_ptr_factory_(this) { |
466 software_frame_manager_.reset(new SoftwareFrameManager( | 466 software_frame_manager_.reset(new SoftwareFrameManager( |
467 software_frame_weak_ptr_factory_.GetWeakPtr())); | 467 software_frame_weak_ptr_factory_.GetWeakPtr())); |
468 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| | 468 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| |
469 // goes away. Since we autorelease it, our caller must put | 469 // goes away. Since we autorelease it, our caller must put |
470 // |GetNativeView()| into the view hierarchy right after calling us. | 470 // |GetNativeView()| into the view hierarchy right after calling us. |
471 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc] | 471 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc] |
472 initWithRenderWidgetHostViewMac:this] autorelease]; | 472 initWithRenderWidgetHostViewMac:this] autorelease]; |
473 | |
474 background_layer_.reset([[CALayer alloc] init]); | 473 background_layer_.reset([[CALayer alloc] init]); |
475 [background_layer_ | 474 [background_layer_ |
476 setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)]; | 475 setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)]; |
477 [cocoa_view_ setLayer:background_layer_]; | 476 [cocoa_view_ setLayer:background_layer_]; |
478 [cocoa_view_ setWantsLayer:YES]; | 477 [cocoa_view_ setWantsLayer:YES]; |
479 | 478 |
480 render_widget_host_->SetView(this); | 479 render_widget_host_->SetView(this); |
481 } | 480 } |
482 | 481 |
483 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() { | 482 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() { |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
627 DestroyCompositedIOSurfaceLayer(kRemoveLayerFromHierarchy); | 626 DestroyCompositedIOSurfaceLayer(kRemoveLayerFromHierarchy); |
628 compositing_iosurface_ = NULL; | 627 compositing_iosurface_ = NULL; |
629 compositing_iosurface_context_ = NULL; | 628 compositing_iosurface_context_ = NULL; |
630 } | 629 } |
631 | 630 |
632 bool RenderWidgetHostViewMac::OnMessageReceived(const IPC::Message& message) { | 631 bool RenderWidgetHostViewMac::OnMessageReceived(const IPC::Message& message) { |
633 bool handled = true; | 632 bool handled = true; |
634 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewMac, message) | 633 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewMac, message) |
635 IPC_MESSAGE_HANDLER(ViewHostMsg_PluginFocusChanged, OnPluginFocusChanged) | 634 IPC_MESSAGE_HANDLER(ViewHostMsg_PluginFocusChanged, OnPluginFocusChanged) |
636 IPC_MESSAGE_HANDLER(ViewHostMsg_StartPluginIme, OnStartPluginIme) | 635 IPC_MESSAGE_HANDLER(ViewHostMsg_StartPluginIme, OnStartPluginIme) |
636 IPC_MESSAGE_HANDLER(ViewMsg_GetRenderedTextCompleted, | |
637 OnGetRenderedTextCompleted) | |
Alexei Svitkine (slow)
2014/06/23 14:35:15
Nit: Align.
sarka
2014/06/25 05:16:47
Done.
| |
637 IPC_MESSAGE_UNHANDLED(handled = false) | 638 IPC_MESSAGE_UNHANDLED(handled = false) |
638 IPC_END_MESSAGE_MAP() | 639 IPC_END_MESSAGE_MAP() |
639 return handled; | 640 return handled; |
640 } | 641 } |
641 | 642 |
642 void RenderWidgetHostViewMac::InitAsChild( | 643 void RenderWidgetHostViewMac::InitAsChild( |
643 gfx::NativeView parent_view) { | 644 gfx::NativeView parent_view) { |
644 } | 645 } |
645 | 646 |
646 void RenderWidgetHostViewMac::InitAsPopup( | 647 void RenderWidgetHostViewMac::InitAsPopup( |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1053 [cocoa_view_ setToolTipAtMousePoint:tooltip_nsstring]; | 1054 [cocoa_view_ setToolTipAtMousePoint:tooltip_nsstring]; |
1054 } | 1055 } |
1055 } | 1056 } |
1056 | 1057 |
1057 bool RenderWidgetHostViewMac::SupportsSpeech() const { | 1058 bool RenderWidgetHostViewMac::SupportsSpeech() const { |
1058 return [NSApp respondsToSelector:@selector(speakString:)] && | 1059 return [NSApp respondsToSelector:@selector(speakString:)] && |
1059 [NSApp respondsToSelector:@selector(stopSpeaking:)]; | 1060 [NSApp respondsToSelector:@selector(stopSpeaking:)]; |
1060 } | 1061 } |
1061 | 1062 |
1062 void RenderWidgetHostViewMac::SpeakSelection() { | 1063 void RenderWidgetHostViewMac::SpeakSelection() { |
1064 if (selected_text_.empty()) { | |
1065 if (render_widget_host_) { | |
Alexei Svitkine (slow)
2014/06/23 14:35:15
Nit: Combine with previous if.
sarka
2014/06/25 05:16:47
Done.
| |
1066 // Route an IPC message to get content as text for a web contents. | |
1067 render_widget_host_->Send(new ViewMsg_GetRenderedText( | |
1068 render_widget_host_->GetRoutingID())); | |
1069 return; | |
1070 } | |
1071 } | |
1063 if ([NSApp respondsToSelector:@selector(speakString:)]) | 1072 if ([NSApp respondsToSelector:@selector(speakString:)]) |
1064 [NSApp speakString:base::SysUTF8ToNSString(selected_text_)]; | 1073 [NSApp speakString:base::SysUTF8ToNSString(selected_text_)]; |
1065 } | 1074 } |
1066 | 1075 |
1067 bool RenderWidgetHostViewMac::IsSpeaking() const { | 1076 bool RenderWidgetHostViewMac::IsSpeaking() const { |
1068 return [NSApp respondsToSelector:@selector(isSpeaking)] && | 1077 return [NSApp respondsToSelector:@selector(isSpeaking)] && |
1069 [NSApp isSpeaking]; | 1078 [NSApp isSpeaking]; |
1070 } | 1079 } |
1071 | 1080 |
1072 void RenderWidgetHostViewMac::StopSpeaking() { | 1081 void RenderWidgetHostViewMac::StopSpeaking() { |
1082 // Clear selected text when StopSpeaking is called | |
Alexei Svitkine (slow)
2014/06/23 14:35:16
Why? |selected_text_| is supposed to be tracking w
sarka
2014/06/25 05:16:47
Done.
| |
1083 if (selected_text_.size()) | |
1084 selected_text_.clear(); | |
1073 if ([NSApp respondsToSelector:@selector(stopSpeaking:)]) | 1085 if ([NSApp respondsToSelector:@selector(stopSpeaking:)]) |
1074 [NSApp stopSpeaking:cocoa_view_]; | 1086 [NSApp stopSpeaking:cocoa_view_]; |
1075 } | 1087 } |
1076 | 1088 |
1077 // | 1089 // |
1078 // RenderWidgetHostViewCocoa uses the stored selection text, | 1090 // RenderWidgetHostViewCocoa uses the stored selection text, |
1079 // which implements NSServicesRequests protocol. | 1091 // which implements NSServicesRequests protocol. |
1080 // | 1092 // |
1081 void RenderWidgetHostViewMac::SelectionChanged(const base::string16& text, | 1093 void RenderWidgetHostViewMac::SelectionChanged(const base::string16& text, |
1082 size_t offset, | 1094 size_t offset, |
(...skipping 961 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2044 | 2056 |
2045 void RenderWidgetHostViewMac::OnPluginFocusChanged(bool focused, | 2057 void RenderWidgetHostViewMac::OnPluginFocusChanged(bool focused, |
2046 int plugin_id) { | 2058 int plugin_id) { |
2047 [cocoa_view_ pluginFocusChanged:(focused ? YES : NO) forPlugin:plugin_id]; | 2059 [cocoa_view_ pluginFocusChanged:(focused ? YES : NO) forPlugin:plugin_id]; |
2048 } | 2060 } |
2049 | 2061 |
2050 void RenderWidgetHostViewMac::OnStartPluginIme() { | 2062 void RenderWidgetHostViewMac::OnStartPluginIme() { |
2051 [cocoa_view_ setPluginImeActive:YES]; | 2063 [cocoa_view_ setPluginImeActive:YES]; |
2052 } | 2064 } |
2053 | 2065 |
2066 void RenderWidgetHostViewMac::OnGetRenderedTextCompleted(const std::string& text ) { | |
Alexei Svitkine (slow)
2014/06/23 14:35:15
Nit: This is over 80 chars, wrap at the (
sarka
2014/06/25 05:16:48
Done.
| |
2067 // Let TTS speak the text returned from call back | |
2068 if (text.empty()) | |
2069 return; | |
2070 | |
2071 if ([NSApp respondsToSelector:@selector(speakString:)]) | |
2072 [NSApp speakString:base::SysUTF8ToNSString(text)]; | |
Alexei Svitkine (slow)
2014/06/23 14:35:15
Nit: Indent 2 less.
sarka
2014/06/25 05:16:47
Done.
| |
2073 | |
Alexei Svitkine (slow)
2014/06/23 14:35:15
Nit: Remove empty line.
sarka
2014/06/25 05:16:47
Done.
| |
2074 } | |
2075 | |
2054 gfx::Rect RenderWidgetHostViewMac::GetScaledOpenGLPixelRect( | 2076 gfx::Rect RenderWidgetHostViewMac::GetScaledOpenGLPixelRect( |
2055 const gfx::Rect& rect) { | 2077 const gfx::Rect& rect) { |
2056 gfx::Rect src_gl_subrect = rect; | 2078 gfx::Rect src_gl_subrect = rect; |
2057 src_gl_subrect.set_y(GetViewBounds().height() - rect.bottom()); | 2079 src_gl_subrect.set_y(GetViewBounds().height() - rect.bottom()); |
2058 | 2080 |
2059 return gfx::ToEnclosingRect(gfx::ScaleRect(src_gl_subrect, | 2081 return gfx::ToEnclosingRect(gfx::ScaleRect(src_gl_subrect, |
2060 ViewScaleFactor())); | 2082 ViewScaleFactor())); |
2061 } | 2083 } |
2062 | 2084 |
2063 void RenderWidgetHostViewMac::AddPendingLatencyInfo( | 2085 void RenderWidgetHostViewMac::AddPendingLatencyInfo( |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2272 if (self) { | 2294 if (self) { |
2273 self.acceptsTouchEvents = YES; | 2295 self.acceptsTouchEvents = YES; |
2274 editCommand_helper_.reset(new RenderWidgetHostViewMacEditCommandHelper); | 2296 editCommand_helper_.reset(new RenderWidgetHostViewMacEditCommandHelper); |
2275 editCommand_helper_->AddEditingSelectorsToClass([self class]); | 2297 editCommand_helper_->AddEditingSelectorsToClass([self class]); |
2276 | 2298 |
2277 renderWidgetHostView_.reset(r); | 2299 renderWidgetHostView_.reset(r); |
2278 canBeKeyView_ = YES; | 2300 canBeKeyView_ = YES; |
2279 focusedPluginIdentifier_ = -1; | 2301 focusedPluginIdentifier_ = -1; |
2280 renderWidgetHostView_->backing_store_scale_factor_ = | 2302 renderWidgetHostView_->backing_store_scale_factor_ = |
2281 ui::GetScaleFactorForNativeView(self); | 2303 ui::GetScaleFactorForNativeView(self); |
2282 | |
Alexei Svitkine (slow)
2014/06/23 14:35:15
Nit: Revert unnecessary whitespace change.
sarka
2014/06/25 05:16:47
Done.
| |
2283 // OpenGL support: | 2304 // OpenGL support: |
2284 if ([self respondsToSelector: | 2305 if ([self respondsToSelector: |
2285 @selector(setWantsBestResolutionOpenGLSurface:)]) { | 2306 @selector(setWantsBestResolutionOpenGLSurface:)]) { |
2286 [self setWantsBestResolutionOpenGLSurface:YES]; | 2307 [self setWantsBestResolutionOpenGLSurface:YES]; |
2287 } | 2308 } |
2288 handlingGlobalFrameDidChange_ = NO; | 2309 handlingGlobalFrameDidChange_ = NO; |
2289 [[NSNotificationCenter defaultCenter] | 2310 [[NSNotificationCenter defaultCenter] |
2290 addObserver:self | 2311 addObserver:self |
2291 selector:@selector(didChangeScreenParameters:) | 2312 selector:@selector(didChangeScreenParameters:) |
2292 name:NSApplicationDidChangeScreenParametersNotification | 2313 name:NSApplicationDidChangeScreenParametersNotification |
(...skipping 1640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3933 | 3954 |
3934 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3955 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
3935 // regions that are not draggable. (See ControlRegionView in | 3956 // regions that are not draggable. (See ControlRegionView in |
3936 // native_app_window_cocoa.mm). This requires the render host view to be | 3957 // native_app_window_cocoa.mm). This requires the render host view to be |
3937 // draggable by default. | 3958 // draggable by default. |
3938 - (BOOL)mouseDownCanMoveWindow { | 3959 - (BOOL)mouseDownCanMoveWindow { |
3939 return YES; | 3960 return YES; |
3940 } | 3961 } |
3941 | 3962 |
3942 @end | 3963 @end |
OLD | NEW |