Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / accelerators_cocoa.mm
blob154be6f91bda7a0fc604d4a68d84a687ebd5fdfc
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/cocoa/accelerators_cocoa.h"
7 #import <Cocoa/Cocoa.h>
9 #include "base/memory/singleton.h"
10 #include "chrome/app/chrome_command_ids.h"
11 #import "ui/base/accelerators/platform_accelerator_cocoa.h"
13 namespace {
15 const struct AcceleratorMapping {
16   int command_id;
17   NSString* key;
18   NSUInteger modifiers;
19 } kAcceleratorMap[] = {
20   { IDC_CLEAR_BROWSING_DATA, @"\x8", NSCommandKeyMask | NSShiftKeyMask },
21   { IDC_COPY, @"c", NSCommandKeyMask },
22   { IDC_CUT, @"x", NSCommandKeyMask },
23   { IDC_DEV_TOOLS, @"i", NSCommandKeyMask | NSAlternateKeyMask },
24   { IDC_DEV_TOOLS_CONSOLE, @"j", NSCommandKeyMask | NSAlternateKeyMask },
25   { IDC_FIND, @"f", NSCommandKeyMask },
26   { IDC_FULLSCREEN, @"f", NSCommandKeyMask | NSShiftKeyMask },
27   { IDC_NEW_INCOGNITO_WINDOW, @"n", NSCommandKeyMask | NSShiftKeyMask },
28   { IDC_NEW_TAB, @"t", NSCommandKeyMask },
29   { IDC_NEW_WINDOW, @"n", NSCommandKeyMask },
30   { IDC_OPTIONS, @",", NSCommandKeyMask },
31   { IDC_PASTE, @"v", NSCommandKeyMask },
32   { IDC_PRINT, @"p", NSCommandKeyMask },
33   { IDC_RESTORE_TAB, @"t", NSCommandKeyMask | NSShiftKeyMask },
34   { IDC_SAVE_PAGE, @"s", NSCommandKeyMask },
35   { IDC_SHOW_BOOKMARK_BAR, @"b", NSCommandKeyMask | NSShiftKeyMask },
36   { IDC_SHOW_BOOKMARK_MANAGER, @"b", NSCommandKeyMask | NSAlternateKeyMask },
37   { IDC_BOOKMARK_PAGE, @"d", NSCommandKeyMask },
38   { IDC_SHOW_DOWNLOADS, @"j", NSCommandKeyMask | NSShiftKeyMask },
39   { IDC_SHOW_HISTORY, @"y", NSCommandKeyMask },
40   { IDC_VIEW_SOURCE, @"u", NSCommandKeyMask | NSAlternateKeyMask },
41   { IDC_ZOOM_MINUS, @"-", NSCommandKeyMask },
42   { IDC_ZOOM_PLUS, @"+", NSCommandKeyMask }
45 }  // namespace
47 AcceleratorsCocoa::AcceleratorsCocoa() {
48   for (size_t i = 0; i < arraysize(kAcceleratorMap); ++i) {
49     const AcceleratorMapping& entry = kAcceleratorMap[i];
50     ui::Accelerator accelerator(ui::VKEY_UNKNOWN, 0);
51     scoped_ptr<ui::PlatformAccelerator> platform_accelerator(
52         new ui::PlatformAcceleratorCocoa(entry.key, entry.modifiers));
53     accelerator.set_platform_accelerator(platform_accelerator.Pass());
54     accelerators_.insert(std::make_pair(entry.command_id, accelerator));
55   }
58 AcceleratorsCocoa::~AcceleratorsCocoa() {}
60 // static
61 AcceleratorsCocoa* AcceleratorsCocoa::GetInstance() {
62   return Singleton<AcceleratorsCocoa>::get();
65 const ui::Accelerator* AcceleratorsCocoa::GetAcceleratorForCommand(
66     int command_id) {
67   AcceleratorMap::iterator it = accelerators_.find(command_id);
68   if (it == accelerators_.end())
69     return NULL;
70   return &it->second;