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 | |
Alexei Svitkine (slow)
2014/06/25 13:58:29
Nit: Revert this whitespace change.
| |
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) | |
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() && render_widget_host_) { | |
1065 // Route an IPC message to get content as text for a web contents. | |
Alexei Svitkine (slow)
2014/06/25 13:58:29
Nit: Indent 2 less.
| |
1066 render_widget_host_->Send(new ViewMsg_GetRenderedText( | |
1067 render_widget_host_->GetRoutingID())); | |
1068 return; | |
1069 } | |
1063 if ([NSApp respondsToSelector:@selector(speakString:)]) | 1070 if ([NSApp respondsToSelector:@selector(speakString:)]) |
Alexei Svitkine (slow)
2014/06/25 13:58:29
Nit: Do an early return at the top of the function
| |
1064 [NSApp speakString:base::SysUTF8ToNSString(selected_text_)]; | 1071 [NSApp speakString:base::SysUTF8ToNSString(selected_text_)]; |
1065 } | 1072 } |
1066 | 1073 |
1067 bool RenderWidgetHostViewMac::IsSpeaking() const { | 1074 bool RenderWidgetHostViewMac::IsSpeaking() const { |
1068 return [NSApp respondsToSelector:@selector(isSpeaking)] && | 1075 return [NSApp respondsToSelector:@selector(isSpeaking)] && |
1069 [NSApp isSpeaking]; | 1076 [NSApp isSpeaking]; |
1070 } | 1077 } |
1071 | 1078 |
1072 void RenderWidgetHostViewMac::StopSpeaking() { | 1079 void RenderWidgetHostViewMac::StopSpeaking() { |
1073 if ([NSApp respondsToSelector:@selector(stopSpeaking:)]) | 1080 if ([NSApp respondsToSelector:@selector(stopSpeaking:)]) |
(...skipping 970 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2044 | 2051 |
2045 void RenderWidgetHostViewMac::OnPluginFocusChanged(bool focused, | 2052 void RenderWidgetHostViewMac::OnPluginFocusChanged(bool focused, |
2046 int plugin_id) { | 2053 int plugin_id) { |
2047 [cocoa_view_ pluginFocusChanged:(focused ? YES : NO) forPlugin:plugin_id]; | 2054 [cocoa_view_ pluginFocusChanged:(focused ? YES : NO) forPlugin:plugin_id]; |
2048 } | 2055 } |
2049 | 2056 |
2050 void RenderWidgetHostViewMac::OnStartPluginIme() { | 2057 void RenderWidgetHostViewMac::OnStartPluginIme() { |
2051 [cocoa_view_ setPluginImeActive:YES]; | 2058 [cocoa_view_ setPluginImeActive:YES]; |
2052 } | 2059 } |
2053 | 2060 |
2061 void RenderWidgetHostViewMac::OnGetRenderedTextCompleted( | |
2062 const std::string& text) { | |
2063 // Let TTS speak the text returned from call back | |
2064 if (text.empty()) | |
2065 return; | |
2066 | |
2067 if ([NSApp respondsToSelector:@selector(speakString:)]) | |
2068 [NSApp speakString:base::SysUTF8ToNSString(text)]; | |
2069 } | |
2070 | |
2054 gfx::Rect RenderWidgetHostViewMac::GetScaledOpenGLPixelRect( | 2071 gfx::Rect RenderWidgetHostViewMac::GetScaledOpenGLPixelRect( |
2055 const gfx::Rect& rect) { | 2072 const gfx::Rect& rect) { |
2056 gfx::Rect src_gl_subrect = rect; | 2073 gfx::Rect src_gl_subrect = rect; |
2057 src_gl_subrect.set_y(GetViewBounds().height() - rect.bottom()); | 2074 src_gl_subrect.set_y(GetViewBounds().height() - rect.bottom()); |
2058 | 2075 |
2059 return gfx::ToEnclosingRect(gfx::ScaleRect(src_gl_subrect, | 2076 return gfx::ToEnclosingRect(gfx::ScaleRect(src_gl_subrect, |
2060 ViewScaleFactor())); | 2077 ViewScaleFactor())); |
2061 } | 2078 } |
2062 | 2079 |
2063 void RenderWidgetHostViewMac::AddPendingLatencyInfo( | 2080 void RenderWidgetHostViewMac::AddPendingLatencyInfo( |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2272 if (self) { | 2289 if (self) { |
2273 self.acceptsTouchEvents = YES; | 2290 self.acceptsTouchEvents = YES; |
2274 editCommand_helper_.reset(new RenderWidgetHostViewMacEditCommandHelper); | 2291 editCommand_helper_.reset(new RenderWidgetHostViewMacEditCommandHelper); |
2275 editCommand_helper_->AddEditingSelectorsToClass([self class]); | 2292 editCommand_helper_->AddEditingSelectorsToClass([self class]); |
2276 | 2293 |
2277 renderWidgetHostView_.reset(r); | 2294 renderWidgetHostView_.reset(r); |
2278 canBeKeyView_ = YES; | 2295 canBeKeyView_ = YES; |
2279 focusedPluginIdentifier_ = -1; | 2296 focusedPluginIdentifier_ = -1; |
2280 renderWidgetHostView_->backing_store_scale_factor_ = | 2297 renderWidgetHostView_->backing_store_scale_factor_ = |
2281 ui::GetScaleFactorForNativeView(self); | 2298 ui::GetScaleFactorForNativeView(self); |
2282 | |
Alexei Svitkine (slow)
2014/06/25 13:58:29
Nit: Revert this whitespace change.
| |
2283 // OpenGL support: | 2299 // OpenGL support: |
2284 if ([self respondsToSelector: | 2300 if ([self respondsToSelector: |
2285 @selector(setWantsBestResolutionOpenGLSurface:)]) { | 2301 @selector(setWantsBestResolutionOpenGLSurface:)]) { |
2286 [self setWantsBestResolutionOpenGLSurface:YES]; | 2302 [self setWantsBestResolutionOpenGLSurface:YES]; |
2287 } | 2303 } |
2288 handlingGlobalFrameDidChange_ = NO; | 2304 handlingGlobalFrameDidChange_ = NO; |
2289 [[NSNotificationCenter defaultCenter] | 2305 [[NSNotificationCenter defaultCenter] |
2290 addObserver:self | 2306 addObserver:self |
2291 selector:@selector(didChangeScreenParameters:) | 2307 selector:@selector(didChangeScreenParameters:) |
2292 name:NSApplicationDidChangeScreenParametersNotification | 2308 name:NSApplicationDidChangeScreenParametersNotification |
(...skipping 1640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3933 | 3949 |
3934 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3950 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
3935 // regions that are not draggable. (See ControlRegionView in | 3951 // regions that are not draggable. (See ControlRegionView in |
3936 // native_app_window_cocoa.mm). This requires the render host view to be | 3952 // native_app_window_cocoa.mm). This requires the render host view to be |
3937 // draggable by default. | 3953 // draggable by default. |
3938 - (BOOL)mouseDownCanMoveWindow { | 3954 - (BOOL)mouseDownCanMoveWindow { |
3939 return YES; | 3955 return YES; |
3940 } | 3956 } |
3941 | 3957 |
3942 @end | 3958 @end |
OLD | NEW |