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 #include <stdint.h> | 10 #include <stdint.h> |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 #include "content/common/accessibility_messages.h" | 53 #include "content/common/accessibility_messages.h" |
54 #include "content/common/edit_command.h" | 54 #include "content/common/edit_command.h" |
55 #include "content/common/input_messages.h" | 55 #include "content/common/input_messages.h" |
56 #include "content/common/site_isolation_policy.h" | 56 #include "content/common/site_isolation_policy.h" |
57 #include "content/common/text_input_state.h" | 57 #include "content/common/text_input_state.h" |
58 #include "content/common/view_messages.h" | 58 #include "content/common/view_messages.h" |
59 #include "content/public/browser/browser_context.h" | 59 #include "content/public/browser/browser_context.h" |
60 #include "content/public/browser/browser_plugin_guest_manager.h" | 60 #include "content/public/browser/browser_plugin_guest_manager.h" |
61 #include "content/public/browser/browser_thread.h" | 61 #include "content/public/browser/browser_thread.h" |
62 #include "content/public/browser/native_web_keyboard_event.h" | 62 #include "content/public/browser/native_web_keyboard_event.h" |
| 63 #include "content/public/browser/render_widget_host.h" |
63 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" | 64 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" |
64 #import "content/public/browser/render_widget_host_view_mac_delegate.h" | 65 #import "content/public/browser/render_widget_host_view_mac_delegate.h" |
65 #include "content/public/browser/web_contents.h" | 66 #include "content/public/browser/web_contents.h" |
66 #include "gpu/ipc/common/gpu_messages.h" | 67 #include "gpu/ipc/common/gpu_messages.h" |
67 #include "skia/ext/platform_canvas.h" | 68 #include "skia/ext/platform_canvas.h" |
68 #include "skia/ext/skia_utils_mac.h" | 69 #include "skia/ext/skia_utils_mac.h" |
69 #include "third_party/WebKit/public/web/WebInputEvent.h" | 70 #include "third_party/WebKit/public/web/WebInputEvent.h" |
70 #import "ui/base/clipboard/clipboard_util_mac.h" | 71 #import "ui/base/clipboard/clipboard_util_mac.h" |
71 #include "ui/base/cocoa/animation_utils.h" | 72 #include "ui/base/cocoa/animation_utils.h" |
72 #import "ui/base/cocoa/appkit_utils.h" | 73 #import "ui/base/cocoa/appkit_utils.h" |
(...skipping 15 matching lines...) Expand all Loading... |
88 #include "ui/gl/gl_switches.h" | 89 #include "ui/gl/gl_switches.h" |
89 | 90 |
90 using content::BrowserAccessibility; | 91 using content::BrowserAccessibility; |
91 using content::BrowserAccessibilityManager; | 92 using content::BrowserAccessibilityManager; |
92 using content::EditCommand; | 93 using content::EditCommand; |
93 using content::FrameTreeNode; | 94 using content::FrameTreeNode; |
94 using content::NativeWebKeyboardEvent; | 95 using content::NativeWebKeyboardEvent; |
95 using content::RenderFrameHost; | 96 using content::RenderFrameHost; |
96 using content::RenderViewHost; | 97 using content::RenderViewHost; |
97 using content::RenderViewHostImpl; | 98 using content::RenderViewHostImpl; |
| 99 using content::RenderWidgetHost; |
98 using content::RenderWidgetHostImpl; | 100 using content::RenderWidgetHostImpl; |
99 using content::RenderWidgetHostViewMac; | 101 using content::RenderWidgetHostViewMac; |
100 using content::RenderWidgetHostViewMacEditCommandHelper; | 102 using content::RenderWidgetHostViewMacEditCommandHelper; |
101 using content::TextInputClientMac; | 103 using content::TextInputClientMac; |
102 using content::WebContents; | 104 using content::WebContents; |
103 using content::WebGestureEventBuilder; | 105 using content::WebGestureEventBuilder; |
104 using content::WebMouseEventBuilder; | 106 using content::WebMouseEventBuilder; |
105 using content::WebMouseWheelEventBuilder; | 107 using content::WebMouseWheelEventBuilder; |
106 using blink::WebInputEvent; | 108 using blink::WebInputEvent; |
107 using blink::WebMouseEvent; | 109 using blink::WebMouseEvent; |
(...skipping 2174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2282 renderWidgetHostView_->render_widget_host_, range, | 2284 renderWidgetHostView_->render_widget_host_, range, |
2283 ^(NSAttributedString* string, NSPoint baselinePoint) { | 2285 ^(NSAttributedString* string, NSPoint baselinePoint) { |
2284 [self showLookUpDictionaryOverlayInternal:string | 2286 [self showLookUpDictionaryOverlayInternal:string |
2285 baselinePoint:baselinePoint | 2287 baselinePoint:baselinePoint |
2286 targetView:targetView]; | 2288 targetView:targetView]; |
2287 } | 2289 } |
2288 ); | 2290 ); |
2289 } | 2291 } |
2290 | 2292 |
2291 - (void)showLookUpDictionaryOverlayAtPoint:(NSPoint)point { | 2293 - (void)showLookUpDictionaryOverlayAtPoint:(NSPoint)point { |
| 2294 gfx::Point rootPoint(point.x, NSHeight([self frame]) - point.y); |
| 2295 gfx::Point transformedPoint; |
| 2296 if (!renderWidgetHostView_->render_widget_host_ || |
| 2297 !renderWidgetHostView_->render_widget_host_->delegate() || |
| 2298 !renderWidgetHostView_->render_widget_host_->delegate() |
| 2299 ->GetInputEventRouter()) |
| 2300 return; |
| 2301 |
| 2302 RenderWidgetHostImpl* widgetHost = |
| 2303 renderWidgetHostView_->render_widget_host_->delegate() |
| 2304 ->GetInputEventRouter() |
| 2305 ->GetRenderWidgetHostAtPoint(renderWidgetHostView_.get(), rootPoint, |
| 2306 &transformedPoint); |
| 2307 if (!widgetHost) |
| 2308 return; |
| 2309 |
| 2310 // TODO(ekaramad): The position reported by the renderer is with respect to |
| 2311 // |widgetHost|'s coordinate space with y-axis inverted to conform to AppKit |
| 2312 // coordinate system. The point will need to be transformed into root view's |
| 2313 // coordinate system (RenderWidgetHostViewMac in this case). However, since |
| 2314 // the callback is invoked on IO thread it will require some thread hopping to |
| 2315 // do so. For this reason, for now, we accept this non-ideal way of fixing the |
| 2316 // point offset manually from the view bounds. This should be revisited when |
| 2317 // fixing issues in TextInputClientMac (https://crbug.com/643233). |
| 2318 gfx::Rect root_box = renderWidgetHostView_->GetViewBounds(); |
| 2319 gfx::Rect view_box = widgetHost->GetView()->GetViewBounds(); |
| 2320 |
2292 TextInputClientMac::GetInstance()->GetStringAtPoint( | 2321 TextInputClientMac::GetInstance()->GetStringAtPoint( |
2293 renderWidgetHostView_->render_widget_host_, | 2322 widgetHost, transformedPoint, |
2294 gfx::Point(point.x, NSHeight([self frame]) - point.y), | |
2295 ^(NSAttributedString* string, NSPoint baselinePoint) { | 2323 ^(NSAttributedString* string, NSPoint baselinePoint) { |
| 2324 baselinePoint.x += view_box.origin().x() - root_box.origin().x(); |
| 2325 baselinePoint.y += |
| 2326 root_box.bottom_left().y() - view_box.bottom_left().y(); |
2296 [self showLookUpDictionaryOverlayInternal:string | 2327 [self showLookUpDictionaryOverlayInternal:string |
2297 baselinePoint:baselinePoint | 2328 baselinePoint:baselinePoint |
2298 targetView:self]; | 2329 targetView:self]; |
2299 } | 2330 }); |
2300 ); | |
2301 } | 2331 } |
2302 | 2332 |
2303 // This is invoked only on 10.8 or newer when the user taps a word using | 2333 // This is invoked only on 10.8 or newer when the user taps a word using |
2304 // three fingers. | 2334 // three fingers. |
2305 - (void)quickLookWithEvent:(NSEvent*)event { | 2335 - (void)quickLookWithEvent:(NSEvent*)event { |
2306 NSPoint point = [self convertPoint:[event locationInWindow] fromView:nil]; | 2336 NSPoint point = [self convertPoint:[event locationInWindow] fromView:nil]; |
2307 [self showLookUpDictionaryOverlayAtPoint:point]; | 2337 [self showLookUpDictionaryOverlayAtPoint:point]; |
2308 } | 2338 } |
2309 | 2339 |
2310 // This method handles 2 different types of hardware events. | 2340 // This method handles 2 different types of hardware events. |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2807 | 2837 |
2808 - (NSUInteger)characterIndexForPoint:(NSPoint)thePoint { | 2838 - (NSUInteger)characterIndexForPoint:(NSPoint)thePoint { |
2809 DCHECK([self window]); | 2839 DCHECK([self window]); |
2810 // |thePoint| is in screen coordinates, but needs to be converted to WebKit | 2840 // |thePoint| is in screen coordinates, but needs to be converted to WebKit |
2811 // coordinates (upper left origin). Scroll offsets will be taken care of in | 2841 // coordinates (upper left origin). Scroll offsets will be taken care of in |
2812 // the renderer. | 2842 // the renderer. |
2813 thePoint = ui::ConvertPointFromScreenToWindow([self window], thePoint); | 2843 thePoint = ui::ConvertPointFromScreenToWindow([self window], thePoint); |
2814 thePoint = [self convertPoint:thePoint fromView:nil]; | 2844 thePoint = [self convertPoint:thePoint fromView:nil]; |
2815 thePoint.y = NSHeight([self frame]) - thePoint.y; | 2845 thePoint.y = NSHeight([self frame]) - thePoint.y; |
2816 | 2846 |
| 2847 if (!renderWidgetHostView_->render_widget_host_ || |
| 2848 !renderWidgetHostView_->render_widget_host_->delegate() || |
| 2849 !renderWidgetHostView_->render_widget_host_->delegate() |
| 2850 ->GetInputEventRouter()) |
| 2851 return NSNotFound; |
| 2852 |
| 2853 gfx::Point rootPoint(thePoint.x, thePoint.y); |
| 2854 gfx::Point transformedPoint; |
| 2855 RenderWidgetHostImpl* widgetHost = |
| 2856 renderWidgetHostView_->render_widget_host_->delegate() |
| 2857 ->GetInputEventRouter() |
| 2858 ->GetRenderWidgetHostAtPoint(renderWidgetHostView_.get(), rootPoint, |
| 2859 &transformedPoint); |
| 2860 if (!widgetHost) |
| 2861 return NSNotFound; |
| 2862 |
2817 NSUInteger index = | 2863 NSUInteger index = |
2818 TextInputClientMac::GetInstance()->GetCharacterIndexAtPoint( | 2864 TextInputClientMac::GetInstance()->GetCharacterIndexAtPoint( |
2819 renderWidgetHostView_->render_widget_host_, | 2865 widgetHost, transformedPoint); |
2820 gfx::Point(thePoint.x, thePoint.y)); | |
2821 return index; | 2866 return index; |
2822 } | 2867 } |
2823 | 2868 |
2824 - (NSRect)firstViewRectForCharacterRange:(NSRange)theRange | 2869 - (NSRect)firstViewRectForCharacterRange:(NSRange)theRange |
2825 actualRange:(NSRangePointer)actualRange { | 2870 actualRange:(NSRangePointer)actualRange { |
2826 NSRect rect; | 2871 NSRect rect; |
2827 if (!renderWidgetHostView_->GetCachedFirstRectForCharacterRange( | 2872 if (!renderWidgetHostView_->GetCachedFirstRectForCharacterRange( |
2828 theRange, | 2873 theRange, |
2829 &rect, | 2874 &rect, |
2830 actualRange)) { | 2875 actualRange)) { |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3267 | 3312 |
3268 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3313 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
3269 // regions that are not draggable. (See ControlRegionView in | 3314 // regions that are not draggable. (See ControlRegionView in |
3270 // native_app_window_cocoa.mm). This requires the render host view to be | 3315 // native_app_window_cocoa.mm). This requires the render host view to be |
3271 // draggable by default. | 3316 // draggable by default. |
3272 - (BOOL)mouseDownCanMoveWindow { | 3317 - (BOOL)mouseDownCanMoveWindow { |
3273 return YES; | 3318 return YES; |
3274 } | 3319 } |
3275 | 3320 |
3276 @end | 3321 @end |
OLD | NEW |