command.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright (c) 2012 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. #ifndef EXTENSIONS_COMMON_COMMAND_H_
  5. #define EXTENSIONS_COMMON_COMMAND_H_
  6. #include <map>
  7. #include <string>
  8. #include "ui/base/accelerators/accelerator.h"
  9. namespace base {
  10. class DictionaryValue;
  11. }
  12. namespace extensions {
  13. class Command {
  14. public:
  15. Command();
  16. Command(const std::string& command_name,
  17. const std::u16string& description,
  18. const std::string& accelerator,
  19. bool global);
  20. Command(const Command& other);
  21. ~Command();
  22. // The platform value for the Command.
  23. static std::string CommandPlatform();
  24. // Parse a string as an accelerator. If the accelerator is unparsable then
  25. // a generic ui::Accelerator object will be returns (with key_code Unknown).
  26. static ui::Accelerator StringToAccelerator(const std::string& accelerator,
  27. const std::string& command_name);
  28. // Returns the string representation of an accelerator without localizing the
  29. // shortcut text (like accelerator::GetShortcutText() does).
  30. static std::string AcceleratorToString(const ui::Accelerator& accelerator);
  31. // Return true if the specified accelerator is one of the following multimedia
  32. // keys: Next Track key, Previous Track key, Stop Media key, Play/Pause Media
  33. // key, without any modifiers.
  34. static bool IsMediaKey(const ui::Accelerator& accelerator);
  35. // Parse the command.
  36. bool Parse(const base::DictionaryValue* command,
  37. const std::string& command_name,
  38. int index,
  39. std::u16string* error);
  40. // Accessors:
  41. const std::string& command_name() const { return command_name_; }
  42. const ui::Accelerator& accelerator() const { return accelerator_; }
  43. const std::u16string& description() const { return description_; }
  44. bool global() const { return global_; }
  45. // Setter:
  46. void set_accelerator(const ui::Accelerator& accelerator) {
  47. accelerator_ = accelerator;
  48. }
  49. void set_global(bool global) { global_ = global; }
  50. private:
  51. std::string command_name_;
  52. ui::Accelerator accelerator_;
  53. std::u16string description_;
  54. bool global_;
  55. };
  56. // A mapping of command name (std::string) to a command object.
  57. typedef std::map<std::string, Command> CommandMap;
  58. } // namespace extensions
  59. #endif // EXTENSIONS_COMMON_COMMAND_H_