| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/cocoa/accelerators_cocoa.h" | 5 #include "chrome/browser/ui/cocoa/accelerators_cocoa.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include "base/singleton.h" |
| 9 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
| 10 | 11 |
| 11 namespace { | 12 namespace { |
| 12 | 13 |
| 13 const struct AcceleratorMapping { | 14 const struct AcceleratorMapping { |
| 14 int command_id; | 15 int command_id; |
| 15 NSString* key; | 16 NSString* key; |
| 16 NSUInteger modifiers; | 17 NSUInteger modifiers; |
| 17 } kAcceleratorMap[] = { | 18 } kAcceleratorMap[] = { |
| 18 { IDC_CLEAR_BROWSING_DATA, @"\x8", NSCommandKeyMask | NSShiftKeyMask }, | 19 { IDC_CLEAR_BROWSING_DATA, @"\x8", NSCommandKeyMask | NSShiftKeyMask }, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 41 } // namespace | 42 } // namespace |
| 42 | 43 |
| 43 AcceleratorsCocoa::AcceleratorsCocoa() { | 44 AcceleratorsCocoa::AcceleratorsCocoa() { |
| 44 for (size_t i = 0; i < arraysize(kAcceleratorMap); ++i) { | 45 for (size_t i = 0; i < arraysize(kAcceleratorMap); ++i) { |
| 45 const AcceleratorMapping& entry = kAcceleratorMap[i]; | 46 const AcceleratorMapping& entry = kAcceleratorMap[i]; |
| 46 menus::AcceleratorCocoa accelerator(entry.key, entry.modifiers); | 47 menus::AcceleratorCocoa accelerator(entry.key, entry.modifiers); |
| 47 accelerators_.insert(std::make_pair(entry.command_id, accelerator)); | 48 accelerators_.insert(std::make_pair(entry.command_id, accelerator)); |
| 48 } | 49 } |
| 49 } | 50 } |
| 50 | 51 |
| 52 // static |
| 53 AcceleratorsCocoa* AcceleratorsCocoa::GetInstance() { |
| 54 return Singleton<AcceleratorsCocoa>::get(); |
| 55 } |
| 56 |
| 51 const menus::AcceleratorCocoa* AcceleratorsCocoa::GetAcceleratorForCommand( | 57 const menus::AcceleratorCocoa* AcceleratorsCocoa::GetAcceleratorForCommand( |
| 52 int command_id) { | 58 int command_id) { |
| 53 AcceleratorCocoaMap::iterator it = accelerators_.find(command_id); | 59 AcceleratorCocoaMap::iterator it = accelerators_.find(command_id); |
| 54 if (it == accelerators_.end()) | 60 if (it == accelerators_.end()) |
| 55 return NULL; | 61 return NULL; |
| 56 return &it->second; | 62 return &it->second; |
| 57 } | 63 } |
| OLD | NEW |