Commit 3ba3595e authored by tkent@chromium.org's avatar tkent@chromium.org

Added "Look Up in Dictionary" item to context menu for Mac.

BUG=46153
TEST=manual

Patch by morrita@google
Original code review: http://codereview.chromium.org/3139007/show

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57025 0039d316-1c4b-4281-b951-d872f2087c98
parent e21ac2e9
......@@ -311,6 +311,7 @@
#define IDC_CONTENT_CONTEXT_INSPECTELEMENT 50151
#define IDC_CONTENT_CONTEXT_VIEWPAGEINFO 50152
#define IDC_CONTENT_CONTEXT_LANGUAGE_SETTINGS 50153
#define IDC_CONTENT_CONTEXT_LOOK_UP_IN_DICTIONARY 50154
// Frame items.
#define IDC_CONTENT_CONTEXT_RELOADFRAME 50160
#define IDC_CONTENT_CONTEXT_OPENFRAMENEWTAB 50161
......
......@@ -309,6 +309,9 @@ each locale. -->
<message name="IDS_CONTENT_CONTEXT_WRITING_DIRECTION_RTL" desc="The name of the 'Right to Left' item from the Writing Direction submenu in the content area context menu. To translate, launch /Applications/Textedit.app in an appropriately localized version of OS X, right-click on the text entry area and use the translation from there.">
Right to Left
</message>
<message name="IDS_CONTENT_CONTEXT_LOOK_UP_IN_DICTIONARY" desc="The name of the 'Look Up in Dictionary' item in the content area context menu. To translate, launch /Applications/Textedit.app in an appropriately localized version of OS X, right-click on the text entry area and use the translation from there.">
Look Up in Dictionary
</message>
</if>
<if expr="not pp_ifdef('use_titlecase')">
<message name="IDS_CONTENT_CONTEXT_BACK" desc="The name of the Back command in the content area context menu">
......
......@@ -400,6 +400,11 @@ void RenderViewContextMenu::InitMenu() {
AppendDeveloperItems();
}
void RenderViewContextMenu::LookUpInDictionary() {
// Used only in the Mac port.
NOTREACHED();
}
bool RenderViewContextMenu::AppendCustomItems() {
std::vector<WebMenuItem>& custom_items = params_.custom_items;
for (size_t i = 0; i < custom_items.size(); ++i) {
......@@ -935,6 +940,10 @@ bool RenderViewContextMenu::IsCommandIdEnabled(int id) const {
WebContextMenuData::CheckableMenuItemEnabled;
case IDC_WRITING_DIRECTION_MENU:
return true;
case IDC_CONTENT_CONTEXT_LOOK_UP_IN_DICTIONARY:
// This is OK because the menu is not shown when it isn't
// appropriate.
return true;
#elif defined(OS_POSIX)
// TODO(suzhe): this should not be enabled for password fields.
case IDC_INPUT_METHODS_MENU:
......@@ -981,6 +990,8 @@ bool RenderViewContextMenu::IsCommandIdChecked(int id) const {
if (id == IDC_WRITING_DIRECTION_LTR)
return params_.writing_direction_left_to_right &
WebContextMenuData::CheckableMenuItemChecked;
if (id == IDC_CONTENT_CONTEXT_LOOK_UP_IN_DICTIONARY)
return false;
#endif // OS_MACOSX
// Check box for 'Check the Spelling of this field'.
......@@ -1323,6 +1334,9 @@ void RenderViewContextMenu::ExecuteCommand(int id) {
source_tab_contents_->render_view_host()->NotifyTextDirection();
break;
}
case IDC_CONTENT_CONTEXT_LOOK_UP_IN_DICTIONARY:
LookUpInDictionary();
break;
#endif // OS_MACOSX
default:
......
......@@ -56,6 +56,7 @@ class RenderViewContextMenu : public menus::SimpleMenuModel::Delegate {
virtual bool GetAcceleratorForCommandId(
int command_id,
menus::Accelerator* accelerator) = 0;
virtual void LookUpInDictionary();
// Attempts to get an ExtensionMenuItem given the id of a context menu item.
ExtensionMenuItem* GetExtensionMenuItem(int id) const;
......
......@@ -33,6 +33,9 @@ class RenderViewContextMenuMac : public RenderViewContextMenu {
return false;
}
virtual void LookUpInDictionary();
void InitPlatformMenu();
private:
scoped_nsobject<MenuController> menuController_;
NSView* parent_view_; // parent view
......
......@@ -7,7 +7,10 @@
#include "base/compiler_specific.h"
#include "base/message_loop.h"
#include "base/scoped_nsobject.h"
#include "base/sys_string_conversions.h"
#include "chrome/app/chrome_dll_resource.h"
#import "chrome/browser/cocoa/menu_controller.h"
#include "grit/generated_resources.h"
// Obj-C bridge class that is the target of all items in the context menu.
// Relies on the tag being set to the command id.
......@@ -24,6 +27,7 @@ RenderViewContextMenuMac::~RenderViewContextMenuMac() {
}
void RenderViewContextMenuMac::PlatformInit() {
InitPlatformMenu();
menuController_.reset(
[[MenuController alloc] initWithModel:&menu_model_
useWithPopUpButtonCell:NO]);
......@@ -54,3 +58,26 @@ void RenderViewContextMenuMac::PlatformInit() {
forView:parent_view_];
}
}
void RenderViewContextMenuMac::InitPlatformMenu() {
bool has_selection = !params_.selection_text.empty();
if (has_selection) {
menu_model_.AddSeparator();
menu_model_.AddItemWithStringId(
IDC_CONTENT_CONTEXT_LOOK_UP_IN_DICTIONARY,
IDS_CONTENT_CONTEXT_LOOK_UP_IN_DICTIONARY);
}
}
void RenderViewContextMenuMac::LookUpInDictionary() {
// TODO(morrita): On Safari, A dictionary panel could be shown
// based on a preference setting of Dictionary.app. We currently
// don't support it: http://crbug.com/17951
NSString* text = base::SysWideToNSString(params_.selection_text);
NSPasteboard* pboard = [NSPasteboard pasteboardWithUniqueName];
BOOL ok = [pboard setString:text forType:NSStringPboardType];
if (ok)
NSPerformService(@"Look Up in Dictionary", pboard);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment