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 2209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2282 renderWidgetHostView_->render_widget_host_, range, | 2283 renderWidgetHostView_->render_widget_host_, range, |
2283 ^(NSAttributedString* string, NSPoint baselinePoint) { | 2284 ^(NSAttributedString* string, NSPoint baselinePoint) { |
2284 [self showLookUpDictionaryOverlayInternal:string | 2285 [self showLookUpDictionaryOverlayInternal:string |
2285 baselinePoint:baselinePoint | 2286 baselinePoint:baselinePoint |
2286 targetView:targetView]; | 2287 targetView:targetView]; |
2287 } | 2288 } |
2288 ); | 2289 ); |
2289 } | 2290 } |
2290 | 2291 |
2291 - (void)showLookUpDictionaryOverlayAtPoint:(NSPoint)point { | 2292 - (void)showLookUpDictionaryOverlayAtPoint:(NSPoint)point { |
| 2293 gfx::Point rootPoint(point.x, NSHeight([self frame]) - point.y); |
| 2294 gfx::Point transformedPoint; |
| 2295 if (!renderWidgetHostView_->render_widget_host_ || |
| 2296 !renderWidgetHostView_->render_widget_host_->delegate() || |
| 2297 !renderWidgetHostView_->render_widget_host_->delegate() |
| 2298 ->GetInputEventRouter()) |
| 2299 return; |
| 2300 |
| 2301 RenderWidgetHostImpl* widgetHost = |
| 2302 renderWidgetHostView_->render_widget_host_->delegate() |
| 2303 ->GetInputEventRouter() |
| 2304 ->GetRenderWidgetHostAtPoint(renderWidgetHostView_.get(), rootPoint, |
| 2305 &transformedPoint); |
| 2306 if (!widgetHost) |
| 2307 return; |
| 2308 |
| 2309 // TODO(ekaramad): The position reported by the renderer is with respect to |
| 2310 // |widgetHost|'s coordinate space with y-axis inverted to conform to AppKit |
| 2311 // coordinate system. The point will need to be transformed into root view's |
| 2312 // coordinate system (RenderWidgetHostViewMac in this case). However, since |
| 2313 // the callback is invoked on IO thread it will require some thread hopping to |
| 2314 // do so. For this reason, for now, we accept this non-ideal way of fixing the |
| 2315 // point offset manually from the view bounds. This should be revisited when |
| 2316 // fixing issues in TextInputClientMac (https://crbug.com/643233). |
| 2317 gfx::Rect root_box = renderWidgetHostView_->GetViewBounds(); |
| 2318 gfx::Rect view_box = widgetHost->GetView()->GetViewBounds(); |
| 2319 |
2292 TextInputClientMac::GetInstance()->GetStringAtPoint( | 2320 TextInputClientMac::GetInstance()->GetStringAtPoint( |
2293 renderWidgetHostView_->render_widget_host_, | 2321 widgetHost, transformedPoint, |
2294 gfx::Point(point.x, NSHeight([self frame]) - point.y), | |
2295 ^(NSAttributedString* string, NSPoint baselinePoint) { | 2322 ^(NSAttributedString* string, NSPoint baselinePoint) { |
| 2323 baselinePoint.x += view_box.origin().x() - root_box.origin().x(); |
| 2324 baselinePoint.y += |
| 2325 root_box.bottom_left().y() - view_box.bottom_left().y(); |
2296 [self showLookUpDictionaryOverlayInternal:string | 2326 [self showLookUpDictionaryOverlayInternal:string |
2297 baselinePoint:baselinePoint | 2327 baselinePoint:baselinePoint |
2298 targetView:self]; | 2328 targetView:self]; |
2299 } | 2329 }); |
2300 ); | |
2301 } | 2330 } |
2302 | 2331 |
2303 // This is invoked only on 10.8 or newer when the user taps a word using | 2332 // This is invoked only on 10.8 or newer when the user taps a word using |
2304 // three fingers. | 2333 // three fingers. |
2305 - (void)quickLookWithEvent:(NSEvent*)event { | 2334 - (void)quickLookWithEvent:(NSEvent*)event { |
2306 NSPoint point = [self convertPoint:[event locationInWindow] fromView:nil]; | 2335 NSPoint point = [self convertPoint:[event locationInWindow] fromView:nil]; |
2307 [self showLookUpDictionaryOverlayAtPoint:point]; | 2336 [self showLookUpDictionaryOverlayAtPoint:point]; |
2308 } | 2337 } |
2309 | 2338 |
2310 // This method handles 2 different types of hardware events. | 2339 // This method handles 2 different types of hardware events. |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2807 | 2836 |
2808 - (NSUInteger)characterIndexForPoint:(NSPoint)thePoint { | 2837 - (NSUInteger)characterIndexForPoint:(NSPoint)thePoint { |
2809 DCHECK([self window]); | 2838 DCHECK([self window]); |
2810 // |thePoint| is in screen coordinates, but needs to be converted to WebKit | 2839 // |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 | 2840 // coordinates (upper left origin). Scroll offsets will be taken care of in |
2812 // the renderer. | 2841 // the renderer. |
2813 thePoint = ui::ConvertPointFromScreenToWindow([self window], thePoint); | 2842 thePoint = ui::ConvertPointFromScreenToWindow([self window], thePoint); |
2814 thePoint = [self convertPoint:thePoint fromView:nil]; | 2843 thePoint = [self convertPoint:thePoint fromView:nil]; |
2815 thePoint.y = NSHeight([self frame]) - thePoint.y; | 2844 thePoint.y = NSHeight([self frame]) - thePoint.y; |
2816 | 2845 |
| 2846 if (!renderWidgetHostView_->render_widget_host_ || |
| 2847 !renderWidgetHostView_->render_widget_host_->delegate() || |
| 2848 !renderWidgetHostView_->render_widget_host_->delegate() |
| 2849 ->GetInputEventRouter()) |
| 2850 return NSNotFound; |
| 2851 |
| 2852 gfx::Point rootPoint(thePoint.x, thePoint.y); |
| 2853 gfx::Point transformedPoint; |
| 2854 RenderWidgetHostImpl* widgetHost = |
| 2855 renderWidgetHostView_->render_widget_host_->delegate() |
| 2856 ->GetInputEventRouter() |
| 2857 ->GetRenderWidgetHostAtPoint(renderWidgetHostView_.get(), rootPoint, |
| 2858 &transformedPoint); |
| 2859 if (!widgetHost) |
| 2860 return NSNotFound; |
| 2861 |
2817 NSUInteger index = | 2862 NSUInteger index = |
2818 TextInputClientMac::GetInstance()->GetCharacterIndexAtPoint( | 2863 TextInputClientMac::GetInstance()->GetCharacterIndexAtPoint( |
2819 renderWidgetHostView_->render_widget_host_, | 2864 widgetHost, transformedPoint); |
2820 gfx::Point(thePoint.x, thePoint.y)); | |
2821 return index; | 2865 return index; |
2822 } | 2866 } |
2823 | 2867 |
2824 - (NSRect)firstViewRectForCharacterRange:(NSRange)theRange | 2868 - (NSRect)firstViewRectForCharacterRange:(NSRange)theRange |
2825 actualRange:(NSRangePointer)actualRange { | 2869 actualRange:(NSRangePointer)actualRange { |
2826 NSRect rect; | 2870 NSRect rect; |
2827 if (!renderWidgetHostView_->GetCachedFirstRectForCharacterRange( | 2871 if (!renderWidgetHostView_->GetCachedFirstRectForCharacterRange( |
2828 theRange, | 2872 theRange, |
2829 &rect, | 2873 &rect, |
2830 actualRange)) { | 2874 actualRange)) { |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3267 | 3311 |
3268 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3312 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
3269 // regions that are not draggable. (See ControlRegionView in | 3313 // regions that are not draggable. (See ControlRegionView in |
3270 // native_app_window_cocoa.mm). This requires the render host view to be | 3314 // native_app_window_cocoa.mm). This requires the render host view to be |
3271 // draggable by default. | 3315 // draggable by default. |
3272 - (BOOL)mouseDownCanMoveWindow { | 3316 - (BOOL)mouseDownCanMoveWindow { |
3273 return YES; | 3317 return YES; |
3274 } | 3318 } |
3275 | 3319 |
3276 @end | 3320 @end |
OLD | NEW |