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. 4 5 #include "chrome/browser/ui/cocoa/accelerators_cocoa.h" 6 7 #import <Cocoa/Cocoa.h> 8 9 #include "base/memory/singleton.h" 10 #include "chrome/app/chrome_command_ids.h" 11 12 namespace { 13 14 const struct AcceleratorMapping { 15 int command_id; 16 NSString* key; 17 NSUInteger modifiers; 18 } kAcceleratorMap[] = { 19 { IDC_CLEAR_BROWSING_DATA, @"\x8", NSCommandKeyMask | NSShiftKeyMask }, 20 { IDC_COPY, @"c", NSCommandKeyMask }, 21 { IDC_CUT, @"x", NSCommandKeyMask }, 22 { IDC_DEV_TOOLS, @"i", NSCommandKeyMask | NSAlternateKeyMask }, 23 { IDC_DEV_TOOLS_CONSOLE, @"j", NSCommandKeyMask | NSAlternateKeyMask }, 24 { IDC_FIND, @"f", NSCommandKeyMask }, 25 { IDC_FULLSCREEN, @"f", NSCommandKeyMask | NSShiftKeyMask }, 26 { IDC_NEW_INCOGNITO_WINDOW, @"n", NSCommandKeyMask | NSShiftKeyMask }, 27 { IDC_NEW_TAB, @"t", NSCommandKeyMask }, 28 { IDC_NEW_WINDOW, @"n", NSCommandKeyMask }, 29 { IDC_OPTIONS, @",", NSCommandKeyMask }, 30 { IDC_PASTE, @"v", NSCommandKeyMask }, 31 { IDC_PRINT, @"p", NSCommandKeyMask }, 32 { IDC_SAVE_PAGE, @"s", NSCommandKeyMask }, 33 { IDC_SHOW_BOOKMARK_BAR, @"b", NSCommandKeyMask | NSShiftKeyMask }, 34 { IDC_SHOW_BOOKMARK_MANAGER, @"b", NSCommandKeyMask | NSAlternateKeyMask }, 35 { IDC_SHOW_DOWNLOADS, @"j", NSCommandKeyMask | NSShiftKeyMask }, 36 { IDC_SHOW_HISTORY, @"y", NSCommandKeyMask }, 37 { IDC_VIEW_SOURCE, @"u", NSCommandKeyMask | NSAlternateKeyMask }, 38 { IDC_ZOOM_MINUS, @"-", NSCommandKeyMask }, 39 { IDC_ZOOM_PLUS, @"+", NSCommandKeyMask } 40 }; 41 42 } // namespace 43 44 AcceleratorsCocoa::AcceleratorsCocoa() { 45 for (size_t i = 0; i < arraysize(kAcceleratorMap); ++i) { 46 const AcceleratorMapping& entry = kAcceleratorMap[i]; 47 ui::AcceleratorCocoa accelerator(entry.key, entry.modifiers); 48 accelerators_.insert(std::make_pair(entry.command_id, accelerator)); 49 } 50 } 51 52 AcceleratorsCocoa::~AcceleratorsCocoa() {} 53 54 // static 55 AcceleratorsCocoa* AcceleratorsCocoa::GetInstance() { 56 return Singleton<AcceleratorsCocoa>::get(); 57 } 58 59 const ui::AcceleratorCocoa* AcceleratorsCocoa::GetAcceleratorForCommand( 60 int command_id) { 61 AcceleratorCocoaMap::iterator it = accelerators_.find(command_id); 62 if (it == accelerators_.end()) 63 return NULL; 64 return &it->second; 65 } 66