Index: content/browser/renderer_host/render_widget_host_view_mac.mm |
diff --git a/content/browser/renderer_host/render_widget_host_view_mac.mm b/content/browser/renderer_host/render_widget_host_view_mac.mm |
index ff4d50fc1a755720dea34bb841a7d9e28bba64d2..8a400e7e51592edd8c77caea38e224b25c4ce06a 100644 |
--- a/content/browser/renderer_host/render_widget_host_view_mac.mm |
+++ b/content/browser/renderer_host/render_widget_host_view_mac.mm |
@@ -2373,14 +2373,34 @@ void RenderWidgetHostViewMac::OnDisplayMetricsChanged( |
- (void)showLookUpDictionaryOverlayFromRange:(NSRange)range |
targetView:(NSView*)targetView { |
+ RenderWidgetHostImpl* widgetHost = renderWidgetHostView_->render_widget_host_; |
+ if (!widgetHost || !widgetHost->delegate()) |
+ return; |
+ widgetHost = widgetHost->delegate()->GetFocusedRenderWidgetHost(widgetHost); |
+ |
+ if (!widgetHost) |
+ return; |
+ |
+ // TODO(ekaramad): The position reported by the renderer is with respect to |
+ // |widgetHost|'s coordinate space with y-axis inverted to conform to AppKit |
+ // coordinate system. The point will need to be transformed into root view's |
+ // coordinate system (RenderWidgetHostViewMac in this case). However, since |
+ // the callback is invoked on IO thread it will require some thread hopping to |
+ // do so. For this reason, for now, we accept this non-ideal way of fixing the |
+ // point offset manually from the view bounds. This should be revisited when |
+ // fixing issues in TextInputClientMac (https://crbug.com/643233). |
+ gfx::Rect root_box = renderWidgetHostView_->GetViewBounds(); |
+ gfx::Rect view_box = widgetHost->GetView()->GetViewBounds(); |
+ |
TextInputClientMac::GetInstance()->GetStringFromRange( |
- renderWidgetHostView_->render_widget_host_, range, |
- ^(NSAttributedString* string, NSPoint baselinePoint) { |
+ widgetHost, range, ^(NSAttributedString* string, NSPoint baselinePoint) { |
+ baselinePoint.x += view_box.origin().x() - root_box.origin().x(); |
+ baselinePoint.y += |
+ root_box.bottom_left().y() - view_box.bottom_left().y(); |
[self showLookUpDictionaryOverlayInternal:string |
baselinePoint:baselinePoint |
targetView:targetView]; |
- } |
- ); |
+ }); |
} |
- (void)showLookUpDictionaryOverlayAtPoint:(NSPoint)point { |