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 #ifndef CHROME_BROWSER_UI_COCOA_ACCELERATORS_COCOA_H_ | 5 #ifndef CHROME_BROWSER_UI_COCOA_ACCELERATORS_COCOA_H_ |
6 #define CHROME_BROWSER_UI_COCOA_ACCELERATORS_COCOA_H_ | 6 #define CHROME_BROWSER_UI_COCOA_ACCELERATORS_COCOA_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 | 10 |
11 #include "app/menus/accelerator_cocoa.h" | 11 #include "app/menus/accelerator_cocoa.h" |
12 | 12 |
| 13 template <typename T> struct DefaultSingletonTraits; |
| 14 |
13 // This class maintains a map of command_ids to AcceleratorCocoa objects (see | 15 // This class maintains a map of command_ids to AcceleratorCocoa objects (see |
14 // chrome/app/chrome_command_ids.h). Currently, this only lists the commands | 16 // chrome/app/chrome_command_ids.h). Currently, this only lists the commands |
15 // that are used in the Wrench menu. | 17 // that are used in the Wrench menu. |
16 // | 18 // |
17 // It is recommended that this class be used as a singleton so that the key map | 19 // It is recommended that this class be used as a singleton so that the key map |
18 // isn't created multiple places. | 20 // isn't created multiple places. |
19 // | 21 // |
20 // #import "base/singleton.h" | 22 // #import "base/singleton.h" |
21 // ... | 23 // ... |
22 // AcceleratorsCocoa* keymap = Singleton<AcceleratorsCocoa>::get(); | 24 // AcceleratorsCocoa* keymap = AcceleratorsCocoa::GetInstance(); |
23 // return keymap->GetAcceleratorForCommand(IDC_COPY); | 25 // return keymap->GetAcceleratorForCommand(IDC_COPY); |
24 // | 26 // |
25 class AcceleratorsCocoa { | 27 class AcceleratorsCocoa { |
26 public: | 28 public: |
27 AcceleratorsCocoa(); | |
28 ~AcceleratorsCocoa() {} | |
29 | |
30 typedef std::map<int, menus::AcceleratorCocoa> AcceleratorCocoaMap; | 29 typedef std::map<int, menus::AcceleratorCocoa> AcceleratorCocoaMap; |
31 | 30 |
32 // Returns NULL if there is no accelerator for the command. | 31 // Returns NULL if there is no accelerator for the command. |
33 const menus::AcceleratorCocoa* GetAcceleratorForCommand(int command_id); | 32 const menus::AcceleratorCocoa* GetAcceleratorForCommand(int command_id); |
34 | 33 |
| 34 // Returns the singleton instance. |
| 35 static AcceleratorsCocoa* GetInstance(); |
| 36 |
35 private: | 37 private: |
| 38 friend struct DefaultSingletonTraits<AcceleratorsCocoa>; |
| 39 |
| 40 AcceleratorsCocoa(); |
| 41 ~AcceleratorsCocoa() {} |
| 42 |
36 AcceleratorCocoaMap accelerators_; | 43 AcceleratorCocoaMap accelerators_; |
37 | 44 |
38 DISALLOW_COPY_AND_ASSIGN(AcceleratorsCocoa); | 45 DISALLOW_COPY_AND_ASSIGN(AcceleratorsCocoa); |
39 }; | 46 }; |
40 | 47 |
41 #endif // CHROME_BROWSER_UI_COCOA_ACCELERATORS_COCOA_H_ | 48 #endif // CHROME_BROWSER_UI_COCOA_ACCELERATORS_COCOA_H_ |
OLD | NEW |