Chromium Code Reviews| 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 1062eaf41577c2f222388e4af621eddb2df9a6e3..4885eb3637030074a8ab58837b96c2a01428d287 100644 |
| --- a/content/browser/renderer_host/render_widget_host_view_mac.mm |
| +++ b/content/browser/renderer_host/render_widget_host_view_mac.mm |
| @@ -2429,13 +2429,9 @@ 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]; |
| - TextInputClientMac::GetInstance()->GetStringAtPoint( |
| - renderWidgetHostView_->render_widget_host_, |
| - gfx::Point(point.x, NSHeight([self frame]) - point.y), |
| +- (void)showLookUpDictionaryOverlayFromRange:(NSRange)range { |
| + TextInputClientMac::GetInstance()->GetStringFromRange( |
| + renderWidgetHostView_->render_widget_host_, range, |
| ^(NSAttributedString* string, NSPoint baselinePoint) { |
|
Alexei Svitkine (slow)
2015/09/18 16:48:43
Is there a reason this block is different than the
Shu Chen
2015/09/21 02:47:39
Done.
|
| if (string && [string length] > 0) { |
| dispatch_async(dispatch_get_main_queue(), ^{ |
| @@ -2447,6 +2443,40 @@ void RenderWidgetHostViewMac::OnDisplayMetricsChanged( |
| ); |
| } |
| +- (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) { |
|
Alexei Svitkine (slow)
2015/09/18 16:48:43
Nit: [string length] == 0 check is sufficient, bec
Shu Chen
2015/09/21 02:47:39
Done.
|
| + // The PDF plugin does not support getting the attributed string |
| + // at point. Until it does, use NSPerformService(), which opens |
| + // Dictionary.app. |
| + // TODO: support GetStringAtPoint() for PDF. See crbug.com/152438. |
|
Alexei Svitkine (slow)
2015/09/18 16:48:43
Nit: TODO()'s should have a name inside them. Sinc
Shu Chen
2015/09/21 02:47:39
Done.
|
| + NSString* text = base::SysUTF8ToNSString( |
| + renderWidgetHostView_->selected_text()); |
| + 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]; |
| + }); |
| + } |
| + ); |
| +} |
| + |
| +// 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. |