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