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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
159 - (void)processedWheelEvent:(const blink::WebMouseWheelEvent&)event | 159 - (void)processedWheelEvent:(const blink::WebMouseWheelEvent&)event |
160 consumed:(BOOL)consumed; | 160 consumed:(BOOL)consumed; |
161 | 161 |
162 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv; | 162 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv; |
163 - (void)windowDidChangeBackingProperties:(NSNotification*)notification; | 163 - (void)windowDidChangeBackingProperties:(NSNotification*)notification; |
164 - (void)windowChangedGlobalFrame:(NSNotification*)notification; | 164 - (void)windowChangedGlobalFrame:(NSNotification*)notification; |
165 - (void)checkForPluginImeCancellation; | 165 - (void)checkForPluginImeCancellation; |
166 - (void)updateScreenProperties; | 166 - (void)updateScreenProperties; |
167 - (void)setResponderDelegate: | 167 - (void)setResponderDelegate: |
168 (NSObject<RenderWidgetHostViewMacDelegate>*)delegate; | 168 (NSObject<RenderWidgetHostViewMacDelegate>*)delegate; |
169 - (void)speakText:(NSString*)text; | |
169 @end | 170 @end |
170 | 171 |
171 // A window subclass that allows the fullscreen window to become main and gain | 172 // A window subclass that allows the fullscreen window to become main and gain |
172 // keyboard focus. This is only used for pepper flash. Normal fullscreen is | 173 // keyboard focus. This is only used for pepper flash. Normal fullscreen is |
173 // handled by the browser. | 174 // handled by the browser. |
174 @interface PepperFlashFullscreenWindow : UnderlayOpenGLHostingWindow | 175 @interface PepperFlashFullscreenWindow : UnderlayOpenGLHostingWindow |
175 @end | 176 @end |
176 | 177 |
177 @implementation PepperFlashFullscreenWindow | 178 @implementation PepperFlashFullscreenWindow |
178 | 179 |
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
727 DestroyCompositedIOSurfaceLayer(kRemoveLayerFromHierarchy); | 728 DestroyCompositedIOSurfaceLayer(kRemoveLayerFromHierarchy); |
728 compositing_iosurface_ = NULL; | 729 compositing_iosurface_ = NULL; |
729 compositing_iosurface_context_ = NULL; | 730 compositing_iosurface_context_ = NULL; |
730 } | 731 } |
731 | 732 |
732 bool RenderWidgetHostViewMac::OnMessageReceived(const IPC::Message& message) { | 733 bool RenderWidgetHostViewMac::OnMessageReceived(const IPC::Message& message) { |
733 bool handled = true; | 734 bool handled = true; |
734 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewMac, message) | 735 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewMac, message) |
735 IPC_MESSAGE_HANDLER(ViewHostMsg_PluginFocusChanged, OnPluginFocusChanged) | 736 IPC_MESSAGE_HANDLER(ViewHostMsg_PluginFocusChanged, OnPluginFocusChanged) |
736 IPC_MESSAGE_HANDLER(ViewHostMsg_StartPluginIme, OnStartPluginIme) | 737 IPC_MESSAGE_HANDLER(ViewHostMsg_StartPluginIme, OnStartPluginIme) |
738 IPC_MESSAGE_HANDLER(ViewMsg_GetRenderedTextCompleted, | |
739 OnGetRenderedTextCompleted) | |
737 IPC_MESSAGE_UNHANDLED(handled = false) | 740 IPC_MESSAGE_UNHANDLED(handled = false) |
738 IPC_END_MESSAGE_MAP() | 741 IPC_END_MESSAGE_MAP() |
739 return handled; | 742 return handled; |
740 } | 743 } |
741 | 744 |
742 void RenderWidgetHostViewMac::InitAsChild( | 745 void RenderWidgetHostViewMac::InitAsChild( |
743 gfx::NativeView parent_view) { | 746 gfx::NativeView parent_view) { |
744 } | 747 } |
745 | 748 |
746 void RenderWidgetHostViewMac::InitAsPopup( | 749 void RenderWidgetHostViewMac::InitAsPopup( |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1176 [cocoa_view_ setToolTipAtMousePoint:tooltip_nsstring]; | 1179 [cocoa_view_ setToolTipAtMousePoint:tooltip_nsstring]; |
1177 } | 1180 } |
1178 } | 1181 } |
1179 | 1182 |
1180 bool RenderWidgetHostViewMac::SupportsSpeech() const { | 1183 bool RenderWidgetHostViewMac::SupportsSpeech() const { |
1181 return [NSApp respondsToSelector:@selector(speakString:)] && | 1184 return [NSApp respondsToSelector:@selector(speakString:)] && |
1182 [NSApp respondsToSelector:@selector(stopSpeaking:)]; | 1185 [NSApp respondsToSelector:@selector(stopSpeaking:)]; |
1183 } | 1186 } |
1184 | 1187 |
1185 void RenderWidgetHostViewMac::SpeakSelection() { | 1188 void RenderWidgetHostViewMac::SpeakSelection() { |
1186 if ([NSApp respondsToSelector:@selector(speakString:)]) | 1189 if (![NSApp respondsToSelector:@selector(speakString:)]) |
1187 [NSApp speakString:base::SysUTF8ToNSString(selected_text_)]; | 1190 return; |
1191 | |
1192 if (selected_text_.empty() && render_widget_host_) { | |
1193 // If there's no selection, speak all text. Send an asynchronous IPC | |
1194 // request for all the text in the webcontents. | |
1195 // ViewMsg_GetRenderedTextCompleted is sent back to IPC Message receiver. | |
1196 render_widget_host_->Send(new ViewMsg_GetRenderedText( | |
1197 render_widget_host_->GetRoutingID())); | |
1198 return; | |
1199 } | |
1200 | |
1201 [cocoa_view_ speakText:base::SysUTF8ToNSString(selected_text_)]; | |
1188 } | 1202 } |
1189 | 1203 |
1190 bool RenderWidgetHostViewMac::IsSpeaking() const { | 1204 bool RenderWidgetHostViewMac::IsSpeaking() const { |
1191 return [NSApp respondsToSelector:@selector(isSpeaking)] && | 1205 return [NSApp respondsToSelector:@selector(isSpeaking)] && |
1192 [NSApp isSpeaking]; | 1206 [NSApp isSpeaking]; |
1193 } | 1207 } |
1194 | 1208 |
1195 void RenderWidgetHostViewMac::StopSpeaking() { | 1209 void RenderWidgetHostViewMac::StopSpeaking() { |
1196 if ([NSApp respondsToSelector:@selector(stopSpeaking:)]) | 1210 if ([NSApp respondsToSelector:@selector(stopSpeaking:)]) |
1197 [NSApp stopSpeaking:cocoa_view_]; | 1211 [NSApp stopSpeaking:cocoa_view_]; |
(...skipping 955 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2153 | 2167 |
2154 void RenderWidgetHostViewMac::OnPluginFocusChanged(bool focused, | 2168 void RenderWidgetHostViewMac::OnPluginFocusChanged(bool focused, |
2155 int plugin_id) { | 2169 int plugin_id) { |
2156 [cocoa_view_ pluginFocusChanged:(focused ? YES : NO) forPlugin:plugin_id]; | 2170 [cocoa_view_ pluginFocusChanged:(focused ? YES : NO) forPlugin:plugin_id]; |
2157 } | 2171 } |
2158 | 2172 |
2159 void RenderWidgetHostViewMac::OnStartPluginIme() { | 2173 void RenderWidgetHostViewMac::OnStartPluginIme() { |
2160 [cocoa_view_ setPluginImeActive:YES]; | 2174 [cocoa_view_ setPluginImeActive:YES]; |
2161 } | 2175 } |
2162 | 2176 |
2177 void RenderWidgetHostViewMac::OnGetRenderedTextCompleted( | |
2178 const std::string& text) { | |
2179 [cocoa_view_ speakText:base::SysUTF8ToNSString(text)]; | |
2180 } | |
2181 | |
2163 gfx::Rect RenderWidgetHostViewMac::GetScaledOpenGLPixelRect( | 2182 gfx::Rect RenderWidgetHostViewMac::GetScaledOpenGLPixelRect( |
2164 const gfx::Rect& rect) { | 2183 const gfx::Rect& rect) { |
2165 gfx::Rect src_gl_subrect = rect; | 2184 gfx::Rect src_gl_subrect = rect; |
2166 src_gl_subrect.set_y(GetViewBounds().height() - rect.bottom()); | 2185 src_gl_subrect.set_y(GetViewBounds().height() - rect.bottom()); |
2167 | 2186 |
2168 return gfx::ToEnclosingRect(gfx::ScaleRect(src_gl_subrect, | 2187 return gfx::ToEnclosingRect(gfx::ScaleRect(src_gl_subrect, |
2169 ViewScaleFactor())); | 2188 ViewScaleFactor())); |
2170 } | 2189 } |
2171 | 2190 |
2172 void RenderWidgetHostViewMac::AddPendingLatencyInfo( | 2191 void RenderWidgetHostViewMac::AddPendingLatencyInfo( |
(...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3020 // Note that we don't attempt to bracket these by GesturePinchBegin/End (or | 3039 // Note that we don't attempt to bracket these by GesturePinchBegin/End (or |
3021 // GestureSrollBegin/End) as is done for touchscreen. Keeping track of when | 3040 // GestureSrollBegin/End) as is done for touchscreen. Keeping track of when |
3022 // a pinch is active would take a little more work here, and we don't need | 3041 // a pinch is active would take a little more work here, and we don't need |
3023 // it for anything yet. | 3042 // it for anything yet. |
3024 const WebGestureEvent& webEvent = | 3043 const WebGestureEvent& webEvent = |
3025 WebInputEventFactory::gestureEvent(event, self); | 3044 WebInputEventFactory::gestureEvent(event, self); |
3026 renderWidgetHostView_->render_widget_host_->ForwardGestureEvent(webEvent); | 3045 renderWidgetHostView_->render_widget_host_->ForwardGestureEvent(webEvent); |
3027 } | 3046 } |
3028 } | 3047 } |
3029 | 3048 |
3049 - (void)speakText:(NSString*) text { | |
dcheng
2014/08/12 20:55:27
Nit: not really sure why this is currently it's ow
sarka
2014/08/12 21:03:16
I think [NSApp speakString] is decided at runtime
| |
3050 [NSApp speakString:text]; | |
3051 } | |
3052 | |
3030 - (void)viewWillMoveToWindow:(NSWindow*)newWindow { | 3053 - (void)viewWillMoveToWindow:(NSWindow*)newWindow { |
3031 NSWindow* oldWindow = [self window]; | 3054 NSWindow* oldWindow = [self window]; |
3032 | 3055 |
3033 NSNotificationCenter* notificationCenter = | 3056 NSNotificationCenter* notificationCenter = |
3034 [NSNotificationCenter defaultCenter]; | 3057 [NSNotificationCenter defaultCenter]; |
3035 | 3058 |
3036 // Backing property notifications crash on 10.6 when building with the 10.7 | 3059 // Backing property notifications crash on 10.6 when building with the 10.7 |
3037 // SDK, see http://crbug.com/260595. | 3060 // SDK, see http://crbug.com/260595. |
3038 static BOOL supportsBackingPropertiesNotification = | 3061 static BOOL supportsBackingPropertiesNotification = |
3039 SupportsBackingPropertiesChangedNotification(); | 3062 SupportsBackingPropertiesChangedNotification(); |
(...skipping 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4063 | 4086 |
4064 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 4087 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
4065 // regions that are not draggable. (See ControlRegionView in | 4088 // regions that are not draggable. (See ControlRegionView in |
4066 // native_app_window_cocoa.mm). This requires the render host view to be | 4089 // native_app_window_cocoa.mm). This requires the render host view to be |
4067 // draggable by default. | 4090 // draggable by default. |
4068 - (BOOL)mouseDownCanMoveWindow { | 4091 - (BOOL)mouseDownCanMoveWindow { |
4069 return YES; | 4092 return YES; |
4070 } | 4093 } |
4071 | 4094 |
4072 @end | 4095 @end |
OLD | NEW |