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

Unified Diff: chrome/browser/tab_contents/render_view_context_menu_mac.mm

Issue 7713033: Integrate the Spelling service to Chrome. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/tab_contents/render_view_context_menu_mac.mm
===================================================================
--- chrome/browser/tab_contents/render_view_context_menu_mac.mm (revision 99616)
+++ chrome/browser/tab_contents/render_view_context_menu_mac.mm (working copy)
@@ -14,6 +14,35 @@
#import "content/common/chrome_application_mac.h"
#include "grit/generated_resources.h"
+namespace {
+
+// Retrieves an NSMenuItem which has the specified command_id. This function
+// traverses the given |model| in the depth-first order. When this function
+// finds an item whose command_id is the same as the given |command_id|, it
+// returns the NSMenuItem associated with the item. This function emulates
+// views::MenuItemViews::GetMenuItemByID() for Mac.
+NSMenuItem* GetMenuItemByID(ui::MenuModel* model,
+ NSMenu* menu,
+ int command_id) {
+ for (int i = 0; i < model->GetItemCount(); ++i) {
+ NSMenuItem* item = [menu itemAtIndex:i];
+ if (model->GetCommandIdAt(i) == command_id)
+ return item;
+
+ ui::MenuModel* submenu = model->GetSubmenuModelAt(i);
+ if (submenu && [item hasSubmenu]) {
+ NSMenuItem* subitem = GetMenuItemByID(submenu,
+ [item submenu],
+ command_id);
+ if (subitem)
+ return subitem;
+ }
+ }
+ return nil;
+}
+
+} // namespace
+
// 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.
@@ -111,3 +140,17 @@
if (ok)
NSPerformService(@"Look Up in Dictionary", pboard);
}
+
+void RenderViewContextMenuMac::UpdateMenuItem(int command_id,
+ bool enabled,
+ const string16& title) {
+ NSMenuItem* item = GetMenuItemByID(&menu_model_, [menuController_ 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 menu] itemChanged:item];
+}

Powered by Google App Engine
This is Rietveld 408576698