atom_api_global_shortcut.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright (c) 2014 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef ATOM_BROWSER_API_ATOM_API_GLOBAL_SHORTCUT_H_
  5. #define ATOM_BROWSER_API_ATOM_API_GLOBAL_SHORTCUT_H_
  6. #include <map>
  7. #include <string>
  8. #include "atom/browser/api/trackable_object.h"
  9. #include "base/callback.h"
  10. #include "chrome/browser/extensions/global_shortcut_listener.h"
  11. #include "native_mate/handle.h"
  12. #include "ui/base/accelerators/accelerator.h"
  13. namespace atom {
  14. namespace api {
  15. class GlobalShortcut : public extensions::GlobalShortcutListener::Observer,
  16. public mate::TrackableObject<GlobalShortcut> {
  17. public:
  18. static mate::Handle<GlobalShortcut> Create(v8::Isolate* isolate);
  19. static void BuildPrototype(v8::Isolate* isolate,
  20. v8::Local<v8::FunctionTemplate> prototype);
  21. protected:
  22. explicit GlobalShortcut(v8::Isolate* isolate);
  23. ~GlobalShortcut() override;
  24. private:
  25. typedef std::map<ui::Accelerator, base::Closure> AcceleratorCallbackMap;
  26. bool Register(const ui::Accelerator& accelerator,
  27. const base::Closure& callback);
  28. bool IsRegistered(const ui::Accelerator& accelerator);
  29. void Unregister(const ui::Accelerator& accelerator);
  30. void UnregisterAll();
  31. // GlobalShortcutListener::Observer implementation.
  32. void OnKeyPressed(const ui::Accelerator& accelerator) override;
  33. AcceleratorCallbackMap accelerator_callback_map_;
  34. DISALLOW_COPY_AND_ASSIGN(GlobalShortcut);
  35. };
  36. } // namespace api
  37. } // namespace atom
  38. #endif // ATOM_BROWSER_API_ATOM_API_GLOBAL_SHORTCUT_H_