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

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_mac_dictionary_helper.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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #import "content/browser/renderer_host/render_widget_host_view_mac_dictionary_he lper.h" 5 #import "content/browser/renderer_host/render_widget_host_view_mac_dictionary_he lper.h"
6 6
7 #include "base/strings/sys_string_conversions.h" 7 #include "base/strings/sys_string_conversions.h"
8 #import "content/browser/renderer_host/render_widget_host_view_mac.h" 8 #import "content/browser/renderer_host/render_widget_host_view_mac.h"
9 9
10 namespace content { 10 namespace content {
11 11
12 RenderWidgetHostViewMacDictionaryHelper:: 12 RenderWidgetHostViewMacDictionaryHelper::
13 RenderWidgetHostViewMacDictionaryHelper(RenderWidgetHostView* view) 13 RenderWidgetHostViewMacDictionaryHelper(RenderWidgetHostView* view)
14 : view_(static_cast<RenderWidgetHostViewMac*>(view)), 14 : view_(static_cast<RenderWidgetHostViewMac*>(view)),
15 target_view_(static_cast<RenderWidgetHostViewMac*>(view)) { 15 target_view_(static_cast<RenderWidgetHostViewMac*>(view)) {
16 } 16 }
17 17
18 void RenderWidgetHostViewMacDictionaryHelper::SetTargetView( 18 void RenderWidgetHostViewMacDictionaryHelper::SetTargetView(
19 RenderWidgetHostView* target_view) { 19 RenderWidgetHostView* target_view) {
20 target_view_ = static_cast<RenderWidgetHostViewMac*>(target_view); 20 target_view_ = static_cast<RenderWidgetHostViewMac*>(target_view);
21 } 21 }
22 22
23 void RenderWidgetHostViewMacDictionaryHelper::ShowDefinitionForSelection() { 23 void RenderWidgetHostViewMacDictionaryHelper::ShowDefinitionForSelection() {
24 NSRange selection_range = [view_->cocoa_view() selectedRange]; 24 NSRange selection_range = [view_->cocoa_view() selectedRange];
25 NSAttributedString* attr_string = 25 [view_->cocoa_view() showLookUpDictionaryOverlayFromRange:selection_range];
26 [view_->cocoa_view() attributedSubstringForProposedRange:selection_range
27 actualRange:nil];
28 if (!attr_string) {
29 if (view_->selected_text().empty())
30 return;
31 // The PDF plugin does not support getting the attributed string. Until it
32 // does, use NSPerformService(), which opens Dictionary.app.
33 // http://crbug.com/152438
34 // TODO(asvitkine): This should be removed after the above support is added.
35 NSString* text = base::SysUTF8ToNSString(view_->selected_text());
36 NSPasteboard* pasteboard = [NSPasteboard pasteboardWithUniqueName];
37 NSArray* types = [NSArray arrayWithObject:NSStringPboardType];
38 [pasteboard declareTypes:types owner:nil];
39 if ([pasteboard setString:text forType:NSStringPboardType])
40 NSPerformService(@"Look Up in Dictionary", pasteboard);
41 return;
42 }
43
44 NSRect rect =
45 [view_->cocoa_view() firstViewRectForCharacterRange:selection_range
46 actualRange:nil];
47
48 NSDictionary* attrs = [attr_string attributesAtIndex:0 effectiveRange:nil];
49 NSFont* font = [attrs objectForKey:NSFontAttributeName];
50 rect.origin.y += NSHeight(rect) - [font ascender];
51
52 rect.origin.x += offset_.x();
53 rect.origin.y += offset_.y();
54
55 [target_view_->cocoa_view() showDefinitionForAttributedString:attr_string
56 atPoint:rect.origin];
57 } 26 }
58 27
59 } // namespace content 28 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_mac.mm ('k') | content/browser/renderer_host/text_input_client_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698