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.
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_API_ELECTRON_API_GLOBAL_SHORTCUT_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_API_ELECTRON_API_GLOBAL_SHORTCUT_H_
|
2014-07-31 04:22:29 +00:00
|
|
|
|
|
|
|
#include <map>
|
2018-11-07 17:40:38 +00:00
|
|
|
#include <vector>
|
2014-07-31 04:22:29 +00:00
|
|
|
|
2023-02-03 11:43:42 +00:00
|
|
|
#include "base/functional/callback.h"
|
2014-07-31 04:22:29 +00:00
|
|
|
#include "chrome/browser/extensions/global_shortcut_listener.h"
|
2019-10-25 13:03:28 +00:00
|
|
|
#include "gin/handle.h"
|
2020-03-19 21:33:45 +00:00
|
|
|
#include "gin/wrappable.h"
|
2014-07-31 04:22:29 +00:00
|
|
|
#include "ui/base/accelerators/accelerator.h"
|
|
|
|
|
2022-06-29 19:55:47 +00:00
|
|
|
namespace electron::api {
|
2014-07-31 04:22:29 +00:00
|
|
|
|
|
|
|
class GlobalShortcut : public extensions::GlobalShortcutListener::Observer,
|
2020-03-19 21:33:45 +00:00
|
|
|
public gin::Wrappable<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
|
|
|
|
2020-03-19 21:33:45 +00:00
|
|
|
// gin::Wrappable
|
|
|
|
static gin::WrapperInfo kWrapperInfo;
|
|
|
|
gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
|
|
|
|
v8::Isolate* isolate) override;
|
|
|
|
const char* GetTypeName() override;
|
2016-04-25 01:17:54 +00:00
|
|
|
|
2021-11-03 11:41:45 +00:00
|
|
|
// disable copy
|
|
|
|
GlobalShortcut(const GlobalShortcut&) = delete;
|
|
|
|
GlobalShortcut& operator=(const GlobalShortcut&) = delete;
|
|
|
|
|
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:
|
2021-05-06 22:01:04 +00:00
|
|
|
typedef std::map<ui::Accelerator, base::RepeatingClosure>
|
|
|
|
AcceleratorCallbackMap;
|
2014-07-31 04:22:29 +00:00
|
|
|
|
2018-11-07 17:40:38 +00:00
|
|
|
bool RegisterAll(const std::vector<ui::Accelerator>& accelerators,
|
2021-05-06 22:01:04 +00:00
|
|
|
const base::RepeatingClosure& callback);
|
2014-08-04 16:00:39 +00:00
|
|
|
bool Register(const ui::Accelerator& accelerator,
|
2021-05-06 22:01:04 +00:00
|
|
|
const base::RepeatingClosure& callback);
|
2014-08-04 16:00:39 +00:00
|
|
|
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_;
|
|
|
|
};
|
|
|
|
|
2022-06-29 19:55:47 +00:00
|
|
|
} // namespace electron::api
|
2014-07-31 04:22:29 +00:00
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#endif // ELECTRON_SHELL_BROWSER_API_ELECTRON_API_GLOBAL_SHORTCUT_H_
|