Chromium Code Reviews| 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 #import <Cocoa/Cocoa.h> | |
|
Robert Sesek
2014/02/11 16:19:48
nit: blank line after, to separate C and C++ inclu
erikchen
2014/02/11 19:42:27
Done.
| |
| 8 #include <map> | 9 #include <map> |
| 10 #include <vector> | |
| 9 | 11 |
| 12 #include "base/gtest_prod_util.h" | |
| 10 #include "ui/base/accelerators/accelerator.h" | 13 #include "ui/base/accelerators/accelerator.h" |
| 11 | 14 |
| 12 template <typename T> struct DefaultSingletonTraits; | 15 template <typename T> struct DefaultSingletonTraits; |
| 13 | 16 |
| 14 // This class maintains a map of command_ids to Accelerator objects (see | 17 // 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 | 18 // chrome/app/chrome_command_ids.h). Currently, this only lists the commands |
| 16 // that are used in the Wrench menu. | 19 // that are used in the Wrench menu. |
| 17 // | 20 // |
| 18 // It is recommended that this class be used as a singleton so that the key map | 21 // It is recommended that this class be used as a singleton so that the key map |
| 19 // isn't created multiple places. | 22 // isn't created multiple places. |
| 20 // | 23 // |
| 21 // #import "base/memory/singleton.h" | 24 // #import "base/memory/singleton.h" |
| 22 // ... | 25 // ... |
| 23 // AcceleratorsCocoa* keymap = AcceleratorsCocoa::GetInstance(); | 26 // AcceleratorsCocoa* keymap = AcceleratorsCocoa::GetInstance(); |
| 24 // return keymap->GetAcceleratorForCommand(IDC_COPY); | 27 // return keymap->GetAcceleratorForCommand(IDC_COPY); |
| 25 // | 28 // |
| 26 class AcceleratorsCocoa { | 29 class AcceleratorsCocoa { |
| 27 public: | 30 public: |
| 28 typedef std::map<int, ui::Accelerator> AcceleratorMap; | 31 typedef std::map<int, ui::Accelerator> AcceleratorMap; |
| 32 typedef std::vector<ui::Accelerator> AcceleratorVector; | |
| 29 typedef AcceleratorMap::const_iterator const_iterator; | 33 typedef AcceleratorMap::const_iterator const_iterator; |
| 30 | 34 |
| 31 const_iterator const begin() { return accelerators_.begin(); } | 35 const_iterator const begin() { return accelerators_.begin(); } |
| 32 const_iterator const end() { return accelerators_.end(); } | 36 const_iterator const end() { return accelerators_.end(); } |
| 33 | 37 |
| 34 // Returns NULL if there is no accelerator for the command. | 38 // Returns NULL if there is no accelerator for the command. |
| 35 const ui::Accelerator* GetAcceleratorForCommand(int command_id); | 39 const ui::Accelerator* GetAcceleratorForCommand(int command_id); |
| 40 // Searches the list of accelerators without a command_id for an accelerator | |
| 41 // that matches the given |keyEquivalent| and |modifiers|. | |
| 42 const ui::Accelerator* GetAcceleratorForHotKey( | |
|
Robert Sesek
2014/02/11 16:19:48
Can this method be const, too?
erikchen
2014/02/11 19:42:27
Done.
| |
| 43 NSString* keyEquivalent, NSUInteger modifiers); | |
|
Robert Sesek
2014/02/11 16:19:48
naming: key_equivalent (and in the comment).
erikchen
2014/02/11 19:42:27
Done.
| |
| 36 | 44 |
| 37 // Returns the singleton instance. | 45 // Returns the singleton instance. |
| 38 static AcceleratorsCocoa* GetInstance(); | 46 static AcceleratorsCocoa* GetInstance(); |
| 39 | 47 |
| 40 private: | 48 private: |
| 41 friend struct DefaultSingletonTraits<AcceleratorsCocoa>; | 49 friend struct DefaultSingletonTraits<AcceleratorsCocoa>; |
| 50 FRIEND_TEST_ALL_PREFIXES(AcceleratorsCocoaBrowsertest, | |
| 51 MappingAcceleratorsInMainMenu); | |
| 42 | 52 |
| 43 AcceleratorsCocoa(); | 53 AcceleratorsCocoa(); |
| 44 ~AcceleratorsCocoa(); | 54 ~AcceleratorsCocoa(); |
| 45 | 55 |
| 56 // A map from command_id to Accelerator. The accelerator is fully filled out, | |
| 57 // and its platform_accelerator is also fully filled out. | |
| 58 // Contains accelerators from both the wrench menu and the main menu. | |
| 46 AcceleratorMap accelerators_; | 59 AcceleratorMap accelerators_; |
| 60 // A list of accelerators used in the main menu that have no associated | |
| 61 // command_id. The accelerator is fully filled out, and its | |
| 62 // platform_accelerator is also fully filled out. | |
| 63 AcceleratorVector acceleratorVector_; | |
|
Robert Sesek
2014/02/11 16:19:48
naming: accelerator_vector_
erikchen
2014/02/11 19:42:27
Done.
| |
| 47 | 64 |
| 48 DISALLOW_COPY_AND_ASSIGN(AcceleratorsCocoa); | 65 DISALLOW_COPY_AND_ASSIGN(AcceleratorsCocoa); |
| 49 }; | 66 }; |
| 50 | 67 |
| 51 #endif // CHROME_BROWSER_UI_COCOA_ACCELERATORS_COCOA_H_ | 68 #endif // CHROME_BROWSER_UI_COCOA_ACCELERATORS_COCOA_H_ |
| OLD | NEW |