| 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 bcc272e0029b835baffa84ae0a3c02a9dd97575e..a6ff431dfe299f325cf47c7690862a1403b9ad2a 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
|
| @@ -67,6 +67,8 @@ void AddDuplicateItem(NSMenuItem* top_level_item,
|
| - (void)removeMenuItems:(NSString*)appId;
|
| // If the currently focused window belongs to a platform app, quit the app.
|
| - (void)quitCurrentPlatformApp;
|
| +// If the currently focused window belongs to a platform app, hide the app.
|
| +- (void)hideCurrentPlatformApp;
|
| @end
|
|
|
| @implementation AppShimMenuController
|
| @@ -85,7 +87,9 @@ void AddDuplicateItem(NSMenuItem* top_level_item,
|
| }
|
|
|
| - (void)buildAppMenuItems {
|
| - // Find the "Quit Chrome" menu item.
|
| + chromeMenuHideItem_.reset(
|
| + [GetItemByTag(IDC_CHROME_MENU, IDC_HIDE_APP) retain]);
|
| + DCHECK(chromeMenuHideItem_);
|
| chromeMenuQuitItem_.reset([GetItemByTag(IDC_CHROME_MENU, IDC_EXIT) retain]);
|
| DCHECK(chromeMenuQuitItem_);
|
|
|
| @@ -94,15 +98,24 @@ void AddDuplicateItem(NSMenuItem* top_level_item,
|
| action:nil
|
| keyEquivalent:@""]);
|
| base::scoped_nsobject<NSMenu> appMenu([[NSMenu alloc] initWithTitle:@""]);
|
| + [appMenuItem_ setSubmenu:appMenu];
|
| [appMenu setAutoenablesItems:NO];
|
| +
|
| + NSMenuItem* appMenuHideItem =
|
| + [appMenu addItemWithTitle:@""
|
| + action:@selector(hideCurrentPlatformApp)
|
| + keyEquivalent:@"h"];
|
| + [appMenuHideItem setTarget:self];
|
| + [appMenuHideItem setTag:IDC_HIDE_APP];
|
| +
|
| + [appMenu addItem:[NSMenuItem separatorItem]];
|
| +
|
| NSMenuItem* appMenuQuitItem =
|
| [appMenu addItemWithTitle:@""
|
| action:@selector(quitCurrentPlatformApp)
|
| keyEquivalent:@"q"];
|
| - [appMenuQuitItem setKeyEquivalentModifierMask:
|
| - [chromeMenuQuitItem_ keyEquivalentModifierMask]];
|
| [appMenuQuitItem setTarget:self];
|
| - [appMenuItem_ setSubmenu:appMenu];
|
| + [appMenuQuitItem setTag:IDC_EXIT];
|
|
|
| // File menu.
|
| fileMenuItem_.reset([NewTopLevelItemFrom(IDC_FILE_MENU) retain]);
|
| @@ -185,16 +198,20 @@ void AddDuplicateItem(NSMenuItem* top_level_item,
|
| for (NSMenuItem* item in [mainMenu itemArray])
|
| [item setHidden:YES];
|
|
|
| + NSString* localizedHideApp =
|
| + l10n_util::GetNSStringF(IDS_HIDE_APP_MAC, base::UTF8ToUTF16(app->name()));
|
| + [[[appMenuItem_ submenu] itemWithTag:IDC_HIDE_APP] setTitle:localizedHideApp];
|
| +
|
| NSString* localizedQuitApp =
|
| l10n_util::GetNSStringF(IDS_EXIT_MAC, base::UTF8ToUTF16(app->name()));
|
| - NSMenuItem* appMenuQuitItem = [[[appMenuItem_ submenu] itemArray] lastObject];
|
| - [appMenuQuitItem setTitle:localizedQuitApp];
|
| + [[[appMenuItem_ submenu] itemWithTag:IDC_EXIT] setTitle:localizedQuitApp];
|
|
|
| // It seems that two menu items that have the same key equivalent must also
|
| // have the same action for the keyboard shortcut to work. (This refers to the
|
| // original keyboard shortcut, regardless of any overrides set in OSX).
|
| - // In order to let the appMenuQuitItem have a different action, we remove the
|
| + // In order to let the app menu items have a different action, we remove the
|
| // key equivalent from the chromeMenuQuitItem and restore it later.
|
| + [chromeMenuHideItem_ setKeyEquivalent:@""];
|
| [chromeMenuQuitItem_ setKeyEquivalent:@""];
|
|
|
| [appMenuItem_ setTitle:appId];
|
| @@ -225,6 +242,7 @@ void AddDuplicateItem(NSMenuItem* top_level_item,
|
| // Restore the keyboard shortcut to Chrome. This just needs to be set back to
|
| // the original keyboard shortcut, regardless of any overrides in OSX. The
|
| // overrides still work as they are based on the title of the menu item.
|
| + [chromeMenuHideItem_ setKeyEquivalent:@"h"];
|
| [chromeMenuQuitItem_ setKeyEquivalent:@"q"];
|
| }
|
|
|
| @@ -236,4 +254,12 @@ void AddDuplicateItem(NSMenuItem* top_level_item,
|
| apps::ExtensionAppShimHandler::QuitAppForWindow(shellWindow);
|
| }
|
|
|
| +- (void)hideCurrentPlatformApp {
|
| + apps::ShellWindow* shellWindow =
|
| + apps::ShellWindowRegistry::GetShellWindowForNativeWindowAnyProfile(
|
| + [NSApp keyWindow]);
|
| + if (shellWindow)
|
| + apps::ExtensionAppShimHandler::HideAppForWindow(shellWindow);
|
| +}
|
| +
|
| @end
|
|
|