Chromium Code Reviews| Index: chrome/browser/ui/cocoa/renderer_context_menu/render_view_context_menu_mac.mm |
| diff --git a/chrome/browser/ui/cocoa/renderer_context_menu/render_view_context_menu_mac.mm b/chrome/browser/ui/cocoa/renderer_context_menu/render_view_context_menu_mac.mm |
| index 3a8b8f6ce842ae1dafeb837005ac5acb1d0d3675..b03a81443f3a7d27418b41c65ba359199273b0fa 100644 |
| --- a/chrome/browser/ui/cocoa/renderer_context_menu/render_view_context_menu_mac.mm |
| +++ b/chrome/browser/ui/cocoa/renderer_context_menu/render_view_context_menu_mac.mm |
| @@ -46,6 +46,35 @@ NSMenuItem* GetMenuItemByID(ui::MenuModel* model, |
| } // namespace |
| +// OSX implemenation of the ToolkitDelegate. This simply (re)delegate |
|
lazyboy
2014/07/31 18:59:04
nit: "This simply ... " starts from next line.
/s/
|
| +// calls to RVContextMenuMac because this do not have to be componentized. |
|
lazyboy
2014/07/31 18:59:04
nit: s/this/they
oshima
2014/07/31 19:51:15
Done.
|
| +class ToolkitDelegateMac : public RenderViewContextMenu::ToolkitDelegate { |
| + public: |
| + ToolkitDelegateMac(RenderViewContextMenuMac* context_menu) |
| + : context_menu_(context_menu) {} |
| + virtual ~ToolkitDelegateMac() {} |
| + |
| + private: |
| + // ToolkitDelegate: |
| + virtual void Init(ui::SimpleMenuModel* menu_model) OVERRIDE { |
| + context_menu_->InitToolkitMenu(); |
| + } |
| + virtual void Cancel() OVERRIDE{ |
| + context_menu_->CancelToolkitMenu(); |
| + } |
| + |
| + virtual void UpdateMenuItem(int command_id, |
| + bool enabled, |
| + bool hidden, |
| + const base::string16& title) OVERRIDE { |
| + context_menu_->UpdateToolkitMenuItem( |
| + command_id, enabled, hidden, title); |
| + } |
| + |
| + RenderViewContextMenuMac* context_menu_; |
| + DISALLOW_COPY_AND_ASSIGN(ToolkitDelegateMac); |
| +}; |
| + |
| // 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. |
| @@ -57,15 +86,13 @@ RenderViewContextMenuMac::RenderViewContextMenuMac( |
| speech_submenu_model_(this), |
| bidi_submenu_model_(this), |
| parent_view_(parent_view) { |
| + scoped_ptr<ToolkitDelegate> delegate(new ToolkitDelegateMac(this)); |
| + set_toolkit_delegate(delegate.Pass()); |
| } |
| RenderViewContextMenuMac::~RenderViewContextMenuMac() { |
| } |
| -void RenderViewContextMenuMac::PlatformInit() { |
| - InitPlatformMenu(); |
| -} |
| - |
| void RenderViewContextMenuMac::Show() { |
| menu_controller_.reset( |
| [[MenuController alloc] initWithModel:&menu_model_ |
| @@ -108,10 +135,6 @@ void RenderViewContextMenuMac::Show() { |
| } |
| } |
| -void RenderViewContextMenuMac::PlatformCancel() { |
| - [menu_controller_ cancel]; |
| -} |
| - |
| void RenderViewContextMenuMac::ExecuteCommand(int command_id, int event_flags) { |
| switch (command_id) { |
| case IDC_CONTENT_CONTEXT_LOOK_UP_IN_DICTIONARY: |
| @@ -210,7 +233,7 @@ void RenderViewContextMenuMac::AppendPlatformEditableItems() { |
| AppendBidiSubMenu(); |
| } |
| -void RenderViewContextMenuMac::InitPlatformMenu() { |
| +void RenderViewContextMenuMac::InitToolkitMenu() { |
| bool has_selection = !params_.selection_text.empty(); |
| if (has_selection) { |
| @@ -235,6 +258,27 @@ void RenderViewContextMenuMac::InitPlatformMenu() { |
| } |
| } |
| +void RenderViewContextMenuMac::CancelToolkitMenu() { |
| + [menu_controller_ cancel]; |
| +} |
| + |
| +void RenderViewContextMenuMac::UpdateToolkitMenuItem( |
| + int command_id, |
| + bool enabled, |
| + bool hidden, |
| + const base::string16& title) { |
| + NSMenuItem* item = GetMenuItemByID(&menu_model_, [menu_controller_ menu], |
| + command_id); |
| + if (!item) |
| + return; |
| + |
| + // Update the returned NSMenuItem directly so we can update it immediately. |
| + [item setEnabled:enabled]; |
| + [item setTitle:SysUTF16ToNSString(title)]; |
| + [item setHidden:hidden]; |
| + [[item menu] itemChanged:item]; |
| +} |
| + |
| void RenderViewContextMenuMac::AppendBidiSubMenu() { |
| bidi_submenu_model_.AddCheckItem(IDC_WRITING_DIRECTION_DEFAULT, |
| l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_DEFAULT)); |
| @@ -266,19 +310,3 @@ void RenderViewContextMenuMac::StopSpeaking() { |
| if (view) |
| view->StopSpeaking(); |
| } |
| - |
| -void RenderViewContextMenuMac::UpdateMenuItem(int command_id, |
| - bool enabled, |
| - bool hidden, |
| - const base::string16& title) { |
| - NSMenuItem* item = GetMenuItemByID(&menu_model_, [menu_controller_ menu], |
| - command_id); |
| - if (!item) |
| - return; |
| - |
| - // Update the returned NSMenuItem directly so we can update it immediately. |
| - [item setEnabled:enabled]; |
| - [item setTitle:SysUTF16ToNSString(title)]; |
| - [item setHidden:hidden]; |
| - [[item menu] itemChanged:item]; |
| -} |