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

Unified Diff: content/browser/renderer_host/render_widget_host_view_mac.mm

Issue 2278283002: Implement Mac Pop-up Dictionary for OOPIF. (Closed)
Patch Set: Addressing lfg@'s comment 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 side-by-side diff with in-line comments
Download patch
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 f918d1320043865700e576de13764d527da4925b..9880d16d8a2e2cd90019c4b36252092c0db8837f 100644
--- a/content/browser/renderer_host/render_widget_host_view_mac.mm
+++ b/content/browser/renderer_host/render_widget_host_view_mac.mm
@@ -60,6 +60,7 @@
#include "content/public/browser/browser_plugin_guest_manager.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/native_web_keyboard_event.h"
+#include "content/public/browser/render_widget_host.h"
Charlie Reis 2016/09/02 21:57:47 Stale? (Do we need the impl file?)
EhsanK 2016/09/08 17:10:40 impl file is already included on line 46. I think
Charlie Reis 2016/09/09 22:23:32 Ah, I missed the other uses of RenderWidgetHost in
#include "content/public/browser/render_widget_host_view_frame_subscriber.h"
#import "content/public/browser/render_widget_host_view_mac_delegate.h"
#include "content/public/browser/web_contents.h"
@@ -96,6 +97,7 @@ using content::NativeWebKeyboardEvent;
using content::RenderFrameHost;
using content::RenderViewHost;
using content::RenderViewHostImpl;
+using content::RenderWidgetHost;
Charlie Reis 2016/09/02 21:57:47 Stale?
EhsanK 2016/09/08 17:10:40 Same discussion as the .h file. For the override R
Charlie Reis 2016/09/09 22:23:32 I don't think you need this. This file is already
EhsanK 2016/09/13 18:52:15 Acknowledged.
using content::RenderWidgetHostImpl;
using content::RenderWidgetHostViewMac;
using content::RenderWidgetHostViewMacEditCommandHelper;
@@ -553,6 +555,20 @@ RenderWidgetHostImpl* RenderWidgetHostViewMac::GetActiveWidget() {
: nullptr;
}
+RenderWidgetHostImpl* RenderWidgetHostViewMac::GetRenderWidgetHostAtPoint(
+ const gfx::Point& point,
+ gfx::Point* transformed_point) {
+ if (!render_widget_host_)
+ return nullptr;
+
+ if (!render_widget_host_->delegate() ||
+ !render_widget_host_->delegate()->GetInputEventRouter())
+ return render_widget_host_;
+
+ return render_widget_host_->delegate()
+ ->GetInputEventRouter()
+ ->GetRenderWidgetHostAtPoint(this, point, transformed_point);
+}
///////////////////////////////////////////////////////////////////////////////
// RenderWidgetHostViewMac, RenderWidgetHostView implementation:
@@ -2286,15 +2302,27 @@ void RenderWidgetHostViewMac::OnDisplayMetricsChanged(
}
- (void)showLookUpDictionaryOverlayAtPoint:(NSPoint)point {
+ gfx::Point rootPoint(point.x, NSHeight([self frame]) - point.y);
+ gfx::Point transformedPoint;
+ RenderWidgetHost* widgetHost =
Charlie Reis 2016/09/02 21:57:47 RenderWidgetHostImpl
EhsanK 2016/09/08 17:10:40 Done.
+ renderWidgetHostView_->GetRenderWidgetHostAtPoint(rootPoint,
+ &transformedPoint);
+ if (!widgetHost)
+ return;
+
+ gfx::Rect root_box = renderWidgetHostView_->GetViewBounds();
+ gfx::Rect view_box = widgetHost->GetView()->GetViewBounds();
+
TextInputClientMac::GetInstance()->GetStringAtPoint(
- renderWidgetHostView_->render_widget_host_,
- gfx::Point(point.x, NSHeight([self frame]) - point.y),
+ widgetHost, transformedPoint,
^(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();
kenrb 2016/09/06 18:14:48 I don't really understand why this point gets shif
EhsanK 2016/09/08 17:10:40 The return coordinate is: 1) With respect to topmo
kenrb 2016/09/12 17:28:13 I am surprised to hear about a threading problem,
EhsanK 2016/09/13 18:52:15 Following our offline conversation, I am leaving a
[self showLookUpDictionaryOverlayInternal:string
baselinePoint:baselinePoint
targetView:self];
- }
- );
+ });
}
// This is invoked only on 10.8 or newer when the user taps a word using
@@ -2810,10 +2838,16 @@ extern NSString *NSTextInputReplacementRangeAttributeName;
thePoint = [self convertPoint:thePoint fromView:nil];
thePoint.y = NSHeight([self frame]) - thePoint.y;
+ gfx::Point transformedPoint;
+ RenderWidgetHost* widgetHost =
Charlie Reis 2016/09/02 21:57:47 RenderWidgetHostImpl
EhsanK 2016/09/08 17:10:40 Done.
+ renderWidgetHostView_->GetRenderWidgetHostAtPoint(
+ gfx::Point(thePoint.x, thePoint.y), &transformedPoint);
+ if (!widgetHost)
+ return NSNotFound;
+
NSUInteger index =
TextInputClientMac::GetInstance()->GetCharacterIndexAtPoint(
- renderWidgetHostView_->render_widget_host_,
- gfx::Point(thePoint.x, thePoint.y));
+ widgetHost, transformedPoint);
return index;
}

Powered by Google App Engine
This is Rietveld 408576698