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

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

Issue 23301018: Add quit item to app menu. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync and rebase Created 7 years, 4 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
« no previous file with comments | « chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 6ecfb4e8556f0f0cea4260ceb724bd829354988f..6cd9a1dbcceec8a81e6bedc6d3930e0be9eba355 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
@@ -8,8 +8,10 @@
#include "apps/shell_window.h"
#include "apps/shell_window_registry.h"
#include "base/strings/sys_string_conversions.h"
+#include "base/strings/utf_string_conversions.h"
#import "chrome/browser/ui/cocoa/apps/native_app_window_cocoa.h"
#include "chrome/common/extensions/extension.h"
+#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/l10n_util_mac.h"
@@ -25,6 +27,8 @@
// If the window belongs to the currently focused app, remove the menu items and
// unhide Chrome menu items.
- (void)removeMenuItems:(NSString*)appId;
+// If the currently focused window belongs to a platform app, quit the app.
+- (void)quitCurrentPlatformApp;
@end
@implementation AppShimMenuController
@@ -43,10 +47,28 @@
}
- (void)buildAppMenuItems {
+ // Find the "Quit Chrome" menu item.
+ NSMenu* chromeMenu = [[[NSApp mainMenu] itemAtIndex:0] submenu];
+ for (NSMenuItem* item in [chromeMenu itemArray]) {
+ if ([item action] == @selector(terminate:)) {
+ chromeMenuQuitItem_.reset([item retain]);
+ break;
+ }
+ }
+ DCHECK(chromeMenuQuitItem_);
+
appMenuItem_.reset([[NSMenuItem alloc] initWithTitle:@""
action:nil
keyEquivalent:@""]);
base::scoped_nsobject<NSMenu> appMenu([[NSMenu alloc] initWithTitle:@""]);
+ [appMenu setAutoenablesItems:NO];
+ NSMenuItem* appMenuQuitItem =
+ [appMenu addItemWithTitle:@""
+ action:@selector(quitCurrentPlatformApp)
+ keyEquivalent:@"q"];
+ [appMenuQuitItem setKeyEquivalentModifierMask:
+ [chromeMenuQuitItem_ keyEquivalentModifierMask]];
+ [appMenuQuitItem setTarget:self];
[appMenuItem_ setSubmenu:appMenu];
}
@@ -103,10 +125,23 @@
[self removeMenuItems:appId_];
appId_.reset([appId copy]);
+ // Hide Chrome menu items.
NSMenu* mainMenu = [NSApp mainMenu];
for (NSMenuItem* item in [mainMenu itemArray])
[item setHidden:YES];
+ NSString* localizedQuitApp =
+ l10n_util::GetNSStringF(IDS_EXIT_MAC, base::UTF8ToUTF16(app->name()));
+ NSMenuItem* appMenuQuitItem = [[[appMenuItem_ submenu] itemArray] lastObject];
+ [appMenuQuitItem 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
+ // key equivalent from the chromeMenuQuitItem and restore it later.
+ [chromeMenuQuitItem_ setKeyEquivalent:@""];
+
[appMenuItem_ setTitle:appId];
[[appMenuItem_ submenu] setTitle:title];
[mainMenu addItem:appMenuItem_];
@@ -124,6 +159,19 @@
// Restore the Chrome main menu bar.
for (NSMenuItem* item in [mainMenu itemArray])
[item setHidden:NO];
+
+ // 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.
+ [chromeMenuQuitItem_ setKeyEquivalent:@"q"];
+}
+
+- (void)quitCurrentPlatformApp {
+ apps::ShellWindow* shellWindow =
+ apps::ShellWindowRegistry::GetShellWindowForNativeWindowAnyProfile(
+ [NSApp keyWindow]);
+ if (shellWindow)
+ apps::ExtensionAppShimHandler::QuitAppForWindow(shellWindow);
}
@end
« no previous file with comments | « chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698