Index: chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac.mm |
diff --git a/chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac.mm b/chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac.mm |
index 6b02afd143884f37d3574a24baff44668fec413b..f60cd0e90c965011484d0d49bcf731064bc38d9a 100644 |
--- a/chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac.mm |
+++ b/chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac.mm |
@@ -75,6 +75,32 @@ void RemoveMenuItemWithTag(NSMenuItem* top_level_item, |
[submenu removeItem:nextItem]; |
} |
+// If |has_alternate| is true, the item immediately following |item_tag| is |
tapted
2015/01/30 03:06:22
keep the `// Sets the menu item with |item_tag| in
mitchellj
2015/01/30 03:24:29
Done.
|
+// assumed to be its (only) alternate. Since AppKit is unable to hide items |
+// with alternates, |has_alternate| will cause -[NSMenuItem alternate] to be |
+// removed when hiding and restored when showing. |
+void SetItemWithTagVisible(NSMenuItem* top_level_item, |
+ NSInteger item_tag, |
+ bool visible, |
+ bool has_alternate) { |
+ NSMenu* submenu = [top_level_item submenu]; |
+ NSMenuItem* menu_item = [submenu itemWithTag:item_tag]; |
+ DCHECK(menu_item); |
+ |
+ if (!has_alternate) { |
+ [menu_item setHidden:!visible]; |
+ return; |
+ } |
+ |
+ NSInteger next_index = [submenu indexOfItem:menu_item] + 1; |
+ DCHECK_LT(next_index, [submenu numberOfItems]); |
+ |
+ NSMenuItem* next_menu_item = [submenu itemAtIndex:next_index]; |
tapted
2015/01/30 03:06:22
nit: next_menu_item -> alternate_item is probably
mitchellj
2015/01/30 03:24:29
Done.
|
+ [next_menu_item setAlternate:visible]; |
+ [next_menu_item setHidden:!visible]; |
+ [menu_item setHidden:!visible]; |
+} |
+ |
} // namespace |
// Used by AppShimMenuController to manage menu items that are a copy of a |
@@ -270,14 +296,10 @@ void RemoveMenuItemWithTag(NSMenuItem* top_level_item, |
[closeWindowMenuItem setKeyEquivalent:@"w"]; |
[closeWindowMenuItem setKeyEquivalentModifierMask:NSCommandKeyMask]; |
- // Edit menu. This copies the menu entirely and removes |
- // "Paste and Match Style" and "Find". This is because the last two items, |
- // "Start Dictation" and "Special Characters" are added by OSX, so we can't |
- // copy them explicitly. |
+ // Edit menu. We copy the menu because the last two items, "Start Dictation" |
+ // and "Special Characters" are added by OSX, so we can't copy them |
+ // explicitly. |
editMenuItem_.reset([[[NSApp mainMenu] itemWithTag:IDC_EDIT_MENU] copy]); |
- RemoveMenuItemWithTag(editMenuItem_, |
- IDC_CONTENT_CONTEXT_PASTE_AND_MATCH_STYLE, NO); |
- RemoveMenuItemWithTag(editMenuItem_, IDC_FIND_MENU, NO); |
// View menu. Remove "Always Show Bookmark Bar" and separator. |
viewMenuItem_.reset([[[NSApp mainMenu] itemWithTag:IDC_VIEW_MENU] copy]); |
@@ -379,7 +401,22 @@ void RemoveMenuItemWithTag(NSMenuItem* top_level_item, |
[mainMenu addItem:appMenuItem_]; |
[mainMenu addItem:fileMenuItem_]; |
+ |
+ if (!app->is_hosted_app()) { |
+ SetItemWithTagVisible(editMenuItem_, |
+ IDC_CONTENT_CONTEXT_PASTE_AND_MATCH_STYLE, |
+ app->is_hosted_app(), true); |
+ SetItemWithTagVisible(editMenuItem_, IDC_FIND_MENU, app->is_hosted_app(), |
+ false); |
+ } else { |
tapted
2015/01/30 03:06:22
this `else` is now identical to the non-else -> no
mitchellj
2015/01/30 03:24:29
Oops, you're right.
|
+ SetItemWithTagVisible(editMenuItem_, |
+ IDC_CONTENT_CONTEXT_PASTE_AND_MATCH_STYLE, |
+ app->is_hosted_app(), true); |
+ SetItemWithTagVisible(editMenuItem_, IDC_FIND_MENU, app->is_hosted_app(), |
+ false); |
+ } |
[mainMenu addItem:editMenuItem_]; |
+ |
if (app->is_hosted_app()) { |
[mainMenu addItem:viewMenuItem_]; |
[mainMenu addItem:historyMenuItem_]; |