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

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

Issue 1318483007: Implement "Look Up In Dictionary" context menu item asynchronously. (OS X) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed review comments. Created 5 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 252250ec3781eb1d579b3ca550e1c8182145556f..8d4602ebcec6bfd62f9b2e54ee25b764fdbc8383 100644
--- a/content/browser/renderer_host/render_widget_host_view_mac.mm
+++ b/content/browser/renderer_host/render_widget_host_view_mac.mm
@@ -180,6 +180,8 @@ static BOOL SupportsBackingPropertiesChangedNotification() {
- (void)updateScreenProperties;
- (void)setResponderDelegate:
(NSObject<RenderWidgetHostViewMacDelegate>*)delegate;
+- (void)showLookUpDictionaryOverlayInternal:(NSAttributedString*) string
+ baselinePoint:(NSPoint) baselinePoint;
@end
// A window subclass that allows the fullscreen window to become main and gain
@@ -2432,24 +2434,58 @@ void RenderWidgetHostViewMac::OnDisplayMetricsChanged(
}
}
-// This is invoked only on 10.8 or newer when the user taps a word using
-// three fingers.
-- (void)quickLookWithEvent:(NSEvent*)event {
- NSPoint point = [self convertPoint:[event locationInWindow] fromView:nil];
+- (void)showLookUpDictionaryOverlayInternal:(NSAttributedString*) string
+ baselinePoint:(NSPoint) baselinePoint {
+ if ([string length] == 0) {
+ // The PDF plugin does not support getting the attributed string at point.
+ // Until it does, use NSPerformService(), which opens Dictionary.app.
+ // TODO(shuchen): Support GetStringAtPoint() & GetStringFromRange() for PDF.
+ // See crbug.com/152438.
+ NSString* text = base::SysUTF8ToNSString(
+ renderWidgetHostView_->selected_text());
+ if ([text length] == 0)
+ return;
+ NSPasteboard* pasteboard = [NSPasteboard pasteboardWithUniqueName];
+ NSArray* types = [NSArray arrayWithObject:NSStringPboardType];
+ [pasteboard declareTypes:types owner:nil];
+ if ([pasteboard setString:text forType:NSStringPboardType])
+ NSPerformService(@"Look Up in Dictionary", pasteboard);
+ return;
+ }
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [self showDefinitionForAttributedString:string
+ atPoint:baselinePoint];
+ });
+}
+
+- (void)showLookUpDictionaryOverlayFromRange:(NSRange)range {
+ TextInputClientMac::GetInstance()->GetStringFromRange(
+ renderWidgetHostView_->render_widget_host_, range,
+ ^(NSAttributedString* string, NSPoint baselinePoint) {
+ [self showLookUpDictionaryOverlayInternal:string
+ baselinePoint:baselinePoint];
+ }
+ );
+}
+
+- (void)showLookUpDictionaryOverlayAtPoint:(NSPoint)point {
TextInputClientMac::GetInstance()->GetStringAtPoint(
renderWidgetHostView_->render_widget_host_,
gfx::Point(point.x, NSHeight([self frame]) - point.y),
^(NSAttributedString* string, NSPoint baselinePoint) {
- if (string && [string length] > 0) {
- dispatch_async(dispatch_get_main_queue(), ^{
- [self showDefinitionForAttributedString:string
- atPoint:baselinePoint];
- });
- }
+ [self showLookUpDictionaryOverlayInternal:string
+ baselinePoint:baselinePoint];
}
);
}
+// This is invoked only on 10.8 or newer when the user taps a word using
+// three fingers.
+- (void)quickLookWithEvent:(NSEvent*)event {
+ NSPoint point = [self convertPoint:[event locationInWindow] fromView:nil];
+ [self showLookUpDictionaryOverlayAtPoint:point];
+}
+
// This method handles 2 different types of hardware events.
// (Apple does not distinguish between them).
// a. Scrolling the middle wheel of a mouse.

Powered by Google App Engine
This is Rietveld 408576698