Chromium Code Reviews
Help | Chromium Project | Sign in
(2)

Side by Side Diff: chrome/browser/tab_contents/render_view_context_menu_mac.mm

Issue 3139007: Added "Look Up in Dictionary" item to context menu for Mac. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: morrita@google.com Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/tab_contents/render_view_context_menu_mac.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #include "chrome/browser/tab_contents/render_view_context_menu_mac.h" 5 #include "chrome/browser/tab_contents/render_view_context_menu_mac.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/scoped_nsobject.h" 9 #include "base/scoped_nsobject.h"
10 #include "base/sys_string_conversions.h"
11 #include "chrome/app/chrome_dll_resource.h"
10 #import "chrome/browser/cocoa/menu_controller.h" 12 #import "chrome/browser/cocoa/menu_controller.h"
13 #include "grit/generated_resources.h"
11 14
12 // Obj-C bridge class that is the target of all items in the context menu. 15 // Obj-C bridge class that is the target of all items in the context menu.
13 // Relies on the tag being set to the command id. 16 // Relies on the tag being set to the command id.
14 17
15 RenderViewContextMenuMac::RenderViewContextMenuMac( 18 RenderViewContextMenuMac::RenderViewContextMenuMac(
16 TabContents* web_contents, 19 TabContents* web_contents,
17 const ContextMenuParams& params, 20 const ContextMenuParams& params,
18 NSView* parent_view) 21 NSView* parent_view)
19 : RenderViewContextMenu(web_contents, params), 22 : RenderViewContextMenu(web_contents, params),
20 parent_view_(parent_view) { 23 parent_view_(parent_view) {
21 } 24 }
22 25
23 RenderViewContextMenuMac::~RenderViewContextMenuMac() { 26 RenderViewContextMenuMac::~RenderViewContextMenuMac() {
24 } 27 }
25 28
26 void RenderViewContextMenuMac::PlatformInit() { 29 void RenderViewContextMenuMac::PlatformInit() {
30 InitPlatformMenu();
27 menuController_.reset( 31 menuController_.reset(
28 [[MenuController alloc] initWithModel:&menu_model_ 32 [[MenuController alloc] initWithModel:&menu_model_
29 useWithPopUpButtonCell:NO]); 33 useWithPopUpButtonCell:NO]);
30 34
31 // Synthesize an event for the click, as there is no certainty that 35 // Synthesize an event for the click, as there is no certainty that
32 // [NSApp currentEvent] will return a valid event. 36 // [NSApp currentEvent] will return a valid event.
33 NSEvent* currentEvent = [NSApp currentEvent]; 37 NSEvent* currentEvent = [NSApp currentEvent];
34 NSWindow* window = [parent_view_ window]; 38 NSWindow* window = [parent_view_ window];
35 NSPoint position = [window mouseLocationOutsideOfEventStream]; 39 NSPoint position = [window mouseLocationOutsideOfEventStream];
36 NSTimeInterval eventTime = [currentEvent timestamp]; 40 NSTimeInterval eventTime = [currentEvent timestamp];
(...skipping 10 matching lines...) Expand all
47 { 51 {
48 // Make sure events can be pumped while the menu is up. 52 // Make sure events can be pumped while the menu is up.
49 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); 53 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current());
50 54
51 // Show the menu. 55 // Show the menu.
52 [NSMenu popUpContextMenu:[menuController_ menu] 56 [NSMenu popUpContextMenu:[menuController_ menu]
53 withEvent:clickEvent 57 withEvent:clickEvent
54 forView:parent_view_]; 58 forView:parent_view_];
55 } 59 }
56 } 60 }
61
62 void RenderViewContextMenuMac::InitPlatformMenu() {
63 bool has_selection = !params_.selection_text.empty();
64
65 if (has_selection) {
66 menu_model_.AddSeparator();
67 menu_model_.AddItemWithStringId(
68 IDC_CONTENT_CONTEXT_LOOK_UP_IN_DICTIONARY,
69 IDS_CONTENT_CONTEXT_LOOK_UP_IN_DICTIONARY);
70 }
71
72 }
73
74 void RenderViewContextMenuMac::LookUpInDictionary() {
75 // TODO(morrita): On Safari, A dictionary panel could be shown
76 // based on a preference setting of Dictionary.app. We currently
77 // don't support it: http://crbug.com/17951
78 NSString* text = base::SysWideToNSString(params_.selection_text);
79 NSPasteboard* pboard = [NSPasteboard pasteboardWithUniqueName];
80 BOOL ok = [pboard setString:text forType:NSStringPboardType];
81 if (ok)
82 NSPerformService(@"Look Up in Dictionary", pboard);
83 }
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/render_view_context_menu_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld 1280:2d3e6564b7b6