2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2014 GitHub, Inc.
|
2014-07-31 04:22:29 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
#ifndef SHELL_BROWSER_API_ELECTRON_API_GLOBAL_SHORTCUT_H_
|
|
|
|
#define SHELL_BROWSER_API_ELECTRON_API_GLOBAL_SHORTCUT_H_
|
2014-07-31 04:22:29 +00:00
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
2018-11-07 17:40:38 +00:00
|
|
|
#include <vector>
|
2014-07-31 04:22:29 +00:00
|
|
|
|
|
|
|
#include "base/callback.h"
|
|
|
|
#include "chrome/browser/extensions/global_shortcut_listener.h"
|
2019-10-25 13:03:28 +00:00
|
|
|
#include "gin/handle.h"
|
|
|
|
#include "shell/common/gin_helper/trackable_object.h"
|
2014-07-31 04:22:29 +00:00
|
|
|
#include "ui/base/accelerators/accelerator.h"
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2014-07-31 04:22:29 +00:00
|
|
|
|
|
|
|
namespace api {
|
|
|
|
|
|
|
|
class GlobalShortcut : public extensions::GlobalShortcutListener::Observer,
|
2019-10-25 13:03:28 +00:00
|
|
|
public gin_helper::TrackableObject<GlobalShortcut> {
|
2014-07-31 04:22:29 +00:00
|
|
|
public:
|
2019-10-25 13:03:28 +00:00
|
|
|
static gin::Handle<GlobalShortcut> Create(v8::Isolate* isolate);
|
2014-07-31 04:22:29 +00:00
|
|
|
|
2016-04-25 01:17:54 +00:00
|
|
|
static void BuildPrototype(v8::Isolate* isolate,
|
2016-08-02 09:08:12 +00:00
|
|
|
v8::Local<v8::FunctionTemplate> prototype);
|
2016-04-25 01:17:54 +00:00
|
|
|
|
2014-07-31 04:22:29 +00:00
|
|
|
protected:
|
2016-04-25 01:17:54 +00:00
|
|
|
explicit GlobalShortcut(v8::Isolate* isolate);
|
2015-11-04 10:21:03 +00:00
|
|
|
~GlobalShortcut() override;
|
|
|
|
|
2014-07-31 04:22:29 +00:00
|
|
|
private:
|
|
|
|
typedef std::map<ui::Accelerator, base::Closure> AcceleratorCallbackMap;
|
|
|
|
|
2018-11-07 17:40:38 +00:00
|
|
|
bool RegisterAll(const std::vector<ui::Accelerator>& accelerators,
|
|
|
|
const base::Closure& callback);
|
2014-08-04 16:00:39 +00:00
|
|
|
bool Register(const ui::Accelerator& accelerator,
|
|
|
|
const base::Closure& callback);
|
|
|
|
bool IsRegistered(const ui::Accelerator& accelerator);
|
|
|
|
void Unregister(const ui::Accelerator& accelerator);
|
2018-11-07 17:40:38 +00:00
|
|
|
void UnregisterSome(const std::vector<ui::Accelerator>& accelerators);
|
2014-07-31 04:22:29 +00:00
|
|
|
void UnregisterAll();
|
|
|
|
|
|
|
|
// GlobalShortcutListener::Observer implementation.
|
2015-01-10 01:24:36 +00:00
|
|
|
void OnKeyPressed(const ui::Accelerator& accelerator) override;
|
2014-07-31 04:22:29 +00:00
|
|
|
|
|
|
|
AcceleratorCallbackMap accelerator_callback_map_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(GlobalShortcut);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|
2014-07-31 04:22:29 +00:00
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
#endif // SHELL_BROWSER_API_ELECTRON_API_GLOBAL_SHORTCUT_H_
|