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

Unified Diff: chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac.mm

Issue 864153003: Added 'Find'/'Paste and Match Style' menu items for hosted apps on Mac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added test Created 5 years, 11 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/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..2d50926cdbffc948559b639644c2218e8660db5d 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,29 @@ void RemoveMenuItemWithTag(NSMenuItem* top_level_item,
[submenu removeItem:nextItem];
}
+// Sets the menu item with |item_tag| in |top_level_item| visible.
+// Assumes that the menu item only has exactly one alternate, since AppKit
tapted 2015/01/30 00:52:48 I think it needs to say If |has_alternate| is tru
mitchellj 2015/01/30 02:53:38 Done.
+// requires that alternate menu items are hidden first.
+void SetItemWithTagVisible(NSMenuItem* top_level_item,
+ NSInteger item_tag,
+ bool visible,
+ bool has_alternate) {
+ NSMenu* submenu = [top_level_item submenu];
+ NSMenuItem* menuItem = [submenu itemWithTag:item_tag];
tapted 2015/01/30 00:52:48 itemWithTag returns `nil` if the tag isn't found.
tapted 2015/01/30 00:52:48 Since it's not an objective-C method, hacker_style
mitchellj 2015/01/30 02:53:38 Done.
mitchellj 2015/01/30 02:53:38 Done.
+ NSInteger nextIndex = [submenu indexOfItem:menuItem] + 1;
+
+ // If no menu item follows the current one, then set visibility and return.
+ if (!has_alternate || nextIndex >= [submenu numberOfItems]) {
tapted 2015/01/30 00:52:48 I think `nextIndex >= [submenu numberOfItems]` is
mitchellj 2015/01/30 02:53:38 Done.
+ [menuItem setHidden:!visible];
+ return;
+ }
+
+ NSMenuItem* nextMenuItem = [submenu itemAtIndex:nextIndex];
+ [nextMenuItem setAlternate:visible];
+ [nextMenuItem setHidden:!visible];
+ [menuItem setHidden:!visible];
+}
+
} // namespace
// Used by AppShimMenuController to manage menu items that are a copy of a
@@ -270,14 +293,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 +398,18 @@ 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, false, true);
tapted 2015/01/30 00:52:48 how about SetItemWithTagVisible( editMenu
mitchellj 2015/01/30 02:53:38 Done.
+ SetItemWithTagVisible(editMenuItem_, IDC_FIND_MENU, false, false);
+ } else {
+ SetItemWithTagVisible(
+ editMenuItem_, IDC_CONTENT_CONTEXT_PASTE_AND_MATCH_STYLE, true, true);
+ SetItemWithTagVisible(editMenuItem_, IDC_FIND_MENU, true, false);
+ }
[mainMenu addItem:editMenuItem_];
+
if (app->is_hosted_app()) {
[mainMenu addItem:viewMenuItem_];
[mainMenu addItem:historyMenuItem_];

Powered by Google App Engine
This is Rietveld 408576698