Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(607)

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_mac.mm

Issue 2278283002: Implement Mac Pop-up Dictionary for OOPIF. (Closed)
Patch Set: Moved ownership of TextInputClientObserver to RenderWidget Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 2173 matching lines...) Expand 10 before | Expand all | Expand 10 after
2281 renderWidgetHostView_->render_widget_host_, range, 2283 renderWidgetHostView_->render_widget_host_, range,
2282 ^(NSAttributedString* string, NSPoint baselinePoint) { 2284 ^(NSAttributedString* string, NSPoint baselinePoint) {
2283 [self showLookUpDictionaryOverlayInternal:string 2285 [self showLookUpDictionaryOverlayInternal:string
2284 baselinePoint:baselinePoint 2286 baselinePoint:baselinePoint
2285 targetView:targetView]; 2287 targetView:targetView];
2286 } 2288 }
2287 ); 2289 );
2288 } 2290 }
2289 2291
2290 - (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
2291 TextInputClientMac::GetInstance()->GetStringAtPoint( 2320 TextInputClientMac::GetInstance()->GetStringAtPoint(
2292 renderWidgetHostView_->render_widget_host_, 2321 widgetHost, transformedPoint,
2293 gfx::Point(point.x, NSHeight([self frame]) - point.y),
2294 ^(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();
2295 [self showLookUpDictionaryOverlayInternal:string 2326 [self showLookUpDictionaryOverlayInternal:string
2296 baselinePoint:baselinePoint 2327 baselinePoint:baselinePoint
2297 targetView:self]; 2328 targetView:self];
2298 } 2329 });
2299 );
2300 } 2330 }
2301 2331
2302 // 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
2303 // three fingers. 2333 // three fingers.
2304 - (void)quickLookWithEvent:(NSEvent*)event { 2334 - (void)quickLookWithEvent:(NSEvent*)event {
2305 NSPoint point = [self convertPoint:[event locationInWindow] fromView:nil]; 2335 NSPoint point = [self convertPoint:[event locationInWindow] fromView:nil];
2306 [self showLookUpDictionaryOverlayAtPoint:point]; 2336 [self showLookUpDictionaryOverlayAtPoint:point];
2307 } 2337 }
2308 2338
2309 // This method handles 2 different types of hardware events. 2339 // This method handles 2 different types of hardware events.
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
2805 2835
2806 - (NSUInteger)characterIndexForPoint:(NSPoint)thePoint { 2836 - (NSUInteger)characterIndexForPoint:(NSPoint)thePoint {
2807 DCHECK([self window]); 2837 DCHECK([self window]);
2808 // |thePoint| is in screen coordinates, but needs to be converted to WebKit 2838 // |thePoint| is in screen coordinates, but needs to be converted to WebKit
2809 // coordinates (upper left origin). Scroll offsets will be taken care of in 2839 // coordinates (upper left origin). Scroll offsets will be taken care of in
2810 // the renderer. 2840 // the renderer.
2811 thePoint = ui::ConvertPointFromScreenToWindow([self window], thePoint); 2841 thePoint = ui::ConvertPointFromScreenToWindow([self window], thePoint);
2812 thePoint = [self convertPoint:thePoint fromView:nil]; 2842 thePoint = [self convertPoint:thePoint fromView:nil];
2813 thePoint.y = NSHeight([self frame]) - thePoint.y; 2843 thePoint.y = NSHeight([self frame]) - thePoint.y;
2814 2844
2845 if (!renderWidgetHostView_->render_widget_host_ ||
2846 !renderWidgetHostView_->render_widget_host_->delegate() ||
2847 !renderWidgetHostView_->render_widget_host_->delegate()
2848 ->GetInputEventRouter())
2849 return NSNotFound;
2850
2851 gfx::Point rootPoint(thePoint.x, thePoint.y);
2852 gfx::Point transformedPoint;
2853 RenderWidgetHostImpl* widgetHost =
2854 renderWidgetHostView_->render_widget_host_->delegate()
2855 ->GetInputEventRouter()
2856 ->GetRenderWidgetHostAtPoint(renderWidgetHostView_.get(), rootPoint,
2857 &transformedPoint);
2858 if (!widgetHost)
2859 return NSNotFound;
2860
2815 NSUInteger index = 2861 NSUInteger index =
2816 TextInputClientMac::GetInstance()->GetCharacterIndexAtPoint( 2862 TextInputClientMac::GetInstance()->GetCharacterIndexAtPoint(
2817 renderWidgetHostView_->render_widget_host_, 2863 widgetHost, transformedPoint);
2818 gfx::Point(thePoint.x, thePoint.y));
2819 return index; 2864 return index;
2820 } 2865 }
2821 2866
2822 - (NSRect)firstViewRectForCharacterRange:(NSRange)theRange 2867 - (NSRect)firstViewRectForCharacterRange:(NSRange)theRange
2823 actualRange:(NSRangePointer)actualRange { 2868 actualRange:(NSRangePointer)actualRange {
2824 NSRect rect; 2869 NSRect rect;
2825 if (!renderWidgetHostView_->GetCachedFirstRectForCharacterRange( 2870 if (!renderWidgetHostView_->GetCachedFirstRectForCharacterRange(
2826 theRange, 2871 theRange,
2827 &rect, 2872 &rect,
2828 actualRange)) { 2873 actualRange)) {
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
3265 3310
3266 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding 3311 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding
3267 // regions that are not draggable. (See ControlRegionView in 3312 // regions that are not draggable. (See ControlRegionView in
3268 // native_app_window_cocoa.mm). This requires the render host view to be 3313 // native_app_window_cocoa.mm). This requires the render host view to be
3269 // draggable by default. 3314 // draggable by default.
3270 - (BOOL)mouseDownCanMoveWindow { 3315 - (BOOL)mouseDownCanMoveWindow {
3271 return YES; 3316 return YES;
3272 } 3317 }
3273 3318
3274 @end 3319 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698