summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions/command.h
blob: 7541cde8982dcc3a273683f02fc2aa567c4a9bfd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_COMMON_EXTENSIONS_COMMAND_H_
#define CHROME_COMMON_EXTENSIONS_COMMAND_H_

#include <map>
#include <string>

#include "base/strings/string16.h"
#include "ui/base/accelerators/accelerator.h"

namespace base {
class DictionaryValue;
}

namespace extensions {
class Extension;
}

namespace extensions {

class Command {
 public:
  Command();
  Command(const std::string& command_name,
          const base::string16& description,
          const std::string& accelerator,
          bool global);
  ~Command();

  // The platform value for the Command.
  static std::string CommandPlatform();

  // Parse a string as an accelerator. If the accelerator is unparsable then
  // a generic ui::Accelerator object will be returns (with key_code Unknown).
  static ui::Accelerator StringToAccelerator(const std::string& accelerator,
                                             const std::string& command_name);

  // Returns the string representation of an accelerator without localizing the
  // shortcut text (like accelerator::GetShortcutText() does).
  static std::string AcceleratorToString(const ui::Accelerator& accelerator);

  // Return true if the specified accelerator is one of the following multimedia
  // keys: Next Track key, Previous Track key, Stop Media key, Play/Pause Media
  // key, without any modifiers.
  static bool IsMediaKey(const ui::Accelerator& accelerator);

  // Parse the command.
  bool Parse(const base::DictionaryValue* command,
             const std::string& command_name,
             int index,
             base::string16* error);

  // Accessors:
  const std::string& command_name() const { return command_name_; }
  const ui::Accelerator& accelerator() const { return accelerator_; }
  const base::string16& description() const { return description_; }
  bool global() const { return global_; }

  // Setter:
  void set_accelerator(ui::Accelerator accelerator) {
    accelerator_ = accelerator;
  }
  void set_global(bool global) {
    global_ = global;
  }

 private:
  std::string command_name_;
  ui::Accelerator accelerator_;
  base::string16 description_;
  bool global_;
};

// A mapping of command name (std::string) to a command object.
typedef std::map<std::string, Command> CommandMap;

}  // namespace extensions

#endif  // CHROME_COMMON_EXTENSIONS_COMMAND_H_