OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_COMMON_EXTENSIONS_COMMAND_H_ | 5 #ifndef CHROME_COMMON_EXTENSIONS_COMMAND_H_ |
6 #define CHROME_COMMON_EXTENSIONS_COMMAND_H_ | 6 #define CHROME_COMMON_EXTENSIONS_COMMAND_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
12 #include "ui/base/accelerators/accelerator.h" | 12 #include "ui/base/accelerators/accelerator.h" |
13 | 13 |
14 namespace base { | 14 namespace base { |
15 class DictionaryValue; | 15 class DictionaryValue; |
16 } | 16 } |
17 | 17 |
18 namespace extensions { | 18 namespace extensions { |
19 class Extension; | 19 class Extension; |
20 } | 20 } |
21 | 21 |
22 namespace extensions { | 22 namespace extensions { |
23 | 23 |
24 class Command { | 24 class Command { |
25 public: | 25 public: |
26 Command(); | 26 Command(); |
27 Command(const std::string& command_name, | 27 Command(const std::string& command_name, |
28 const string16& description, | 28 const string16& description, |
29 const std::string& accelerator); | 29 const std::string& accelerator, |
| 30 bool global); |
30 ~Command(); | 31 ~Command(); |
31 | 32 |
32 // The platform value for the Command. | 33 // The platform value for the Command. |
33 static std::string CommandPlatform(); | 34 static std::string CommandPlatform(); |
34 | 35 |
35 // Parse a string as an accelerator. If the accelerator is unparsable then | 36 // Parse a string as an accelerator. If the accelerator is unparsable then |
36 // a generic ui::Accelerator object will be returns (with key_code Unknown). | 37 // a generic ui::Accelerator object will be returns (with key_code Unknown). |
37 static ui::Accelerator StringToAccelerator(const std::string& accelerator, | 38 static ui::Accelerator StringToAccelerator(const std::string& accelerator, |
38 const std::string& command_name); | 39 const std::string& command_name); |
39 | 40 |
40 // Returns the string representation of an accelerator without localizing the | 41 // Returns the string representation of an accelerator without localizing the |
41 // shortcut text (like accelerator::GetShortcutText() does). | 42 // shortcut text (like accelerator::GetShortcutText() does). |
42 static std::string AcceleratorToString(const ui::Accelerator& accelerator); | 43 static std::string AcceleratorToString(const ui::Accelerator& accelerator); |
43 | 44 |
44 // Parse the command. | 45 // Parse the command. |
45 bool Parse(const base::DictionaryValue* command, | 46 bool Parse(const base::DictionaryValue* command, |
46 const std::string& command_name, | 47 const std::string& command_name, |
47 int index, | 48 int index, |
48 string16* error); | 49 string16* error); |
49 | 50 |
50 // Convert a Command object from |extension| to a DictionaryValue. | 51 // Convert a Command object from |extension| to a DictionaryValue. |
51 // |active| specifies whether the command is active or not. | 52 // |active| specifies whether the command is active or not. |
52 base::DictionaryValue* ToValue( | 53 base::DictionaryValue* ToValue( |
53 const Extension* extension, bool active) const; | 54 const Extension* extension, bool active) const; |
54 | 55 |
55 // Accessors: | 56 // Accessors: |
56 const std::string& command_name() const { return command_name_; } | 57 const std::string& command_name() const { return command_name_; } |
57 const ui::Accelerator& accelerator() const { return accelerator_; } | 58 const ui::Accelerator& accelerator() const { return accelerator_; } |
58 const string16& description() const { return description_; } | 59 const string16& description() const { return description_; } |
| 60 bool global() const { return global_; } |
59 | 61 |
60 // Setter: | 62 // Setter: |
61 void set_accelerator(ui::Accelerator accelerator) { | 63 void set_accelerator(ui::Accelerator accelerator) { |
62 accelerator_ = accelerator; | 64 accelerator_ = accelerator; |
63 } | 65 } |
64 | 66 |
65 private: | 67 private: |
66 std::string command_name_; | 68 std::string command_name_; |
67 ui::Accelerator accelerator_; | 69 ui::Accelerator accelerator_; |
68 string16 description_; | 70 string16 description_; |
| 71 bool global_; |
69 }; | 72 }; |
70 | 73 |
71 // A mapping of command name (std::string) to a command object. | 74 // A mapping of command name (std::string) to a command object. |
72 typedef std::map<std::string, Command> CommandMap; | 75 typedef std::map<std::string, Command> CommandMap; |
73 | 76 |
74 } // namespace extensions | 77 } // namespace extensions |
75 | 78 |
76 #endif // CHROME_COMMON_EXTENSIONS_COMMAND_H_ | 79 #endif // CHROME_COMMON_EXTENSIONS_COMMAND_H_ |
OLD | NEW |