2014-10-31 12:17:05 -06:00
|
|
|
// Copyright (c) 2014 GitHub, Inc.
|
2014-07-30 22:22:29 -06:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2021-11-22 00:34:31 -07:00
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_API_ELECTRON_API_GLOBAL_SHORTCUT_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_API_ELECTRON_API_GLOBAL_SHORTCUT_H_
|
2014-07-30 22:22:29 -06:00
|
|
|
|
|
|
|
#include <map>
|
2018-11-07 10:40:38 -07:00
|
|
|
#include <vector>
|
2014-07-30 22:22:29 -06:00
|
|
|
|
2023-02-03 04:43:42 -07:00
|
|
|
#include "base/functional/callback.h"
|
2014-07-30 22:22:29 -06:00
|
|
|
#include "chrome/browser/extensions/global_shortcut_listener.h"
|
2019-10-25 07:03:28 -06:00
|
|
|
#include "gin/handle.h"
|
2020-03-19 15:33:45 -06:00
|
|
|
#include "gin/wrappable.h"
|
2014-07-30 22:22:29 -06:00
|
|
|
#include "ui/base/accelerators/accelerator.h"
|
|
|
|
|
2022-06-29 13:55:47 -06:00
|
|
|
namespace electron::api {
|
2014-07-30 22:22:29 -06:00
|
|
|
|
2024-05-21 13:21:31 -06:00
|
|
|
class GlobalShortcut : private extensions::GlobalShortcutListener::Observer,
|
2020-03-19 15:33:45 -06:00
|
|
|
public gin::Wrappable<GlobalShortcut> {
|
2014-07-30 22:22:29 -06:00
|
|
|
public:
|
2019-10-25 07:03:28 -06:00
|
|
|
static gin::Handle<GlobalShortcut> Create(v8::Isolate* isolate);
|
2014-07-30 22:22:29 -06:00
|
|
|
|
2020-03-19 15:33:45 -06:00
|
|
|
// gin::Wrappable
|
|
|
|
static gin::WrapperInfo kWrapperInfo;
|
|
|
|
gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
|
|
|
|
v8::Isolate* isolate) override;
|
|
|
|
const char* GetTypeName() override;
|
2016-04-24 19:17:54 -06:00
|
|
|
|
2021-11-03 05:41:45 -06:00
|
|
|
// disable copy
|
|
|
|
GlobalShortcut(const GlobalShortcut&) = delete;
|
|
|
|
GlobalShortcut& operator=(const GlobalShortcut&) = delete;
|
|
|
|
|
2014-07-30 22:22:29 -06:00
|
|
|
protected:
|
2016-04-24 19:17:54 -06:00
|
|
|
explicit GlobalShortcut(v8::Isolate* isolate);
|
2015-11-04 03:21:03 -07:00
|
|
|
~GlobalShortcut() override;
|
|
|
|
|
2014-07-30 22:22:29 -06:00
|
|
|
private:
|
2021-05-06 16:01:04 -06:00
|
|
|
typedef std::map<ui::Accelerator, base::RepeatingClosure>
|
|
|
|
AcceleratorCallbackMap;
|
2014-07-30 22:22:29 -06:00
|
|
|
|
2018-11-07 10:40:38 -07:00
|
|
|
bool RegisterAll(const std::vector<ui::Accelerator>& accelerators,
|
2021-05-06 16:01:04 -06:00
|
|
|
const base::RepeatingClosure& callback);
|
2014-08-04 10:00:39 -06:00
|
|
|
bool Register(const ui::Accelerator& accelerator,
|
2021-05-06 16:01:04 -06:00
|
|
|
const base::RepeatingClosure& callback);
|
2014-08-04 10:00:39 -06:00
|
|
|
bool IsRegistered(const ui::Accelerator& accelerator);
|
|
|
|
void Unregister(const ui::Accelerator& accelerator);
|
2018-11-07 10:40:38 -07:00
|
|
|
void UnregisterSome(const std::vector<ui::Accelerator>& accelerators);
|
2014-07-30 22:22:29 -06:00
|
|
|
void UnregisterAll();
|
|
|
|
|
|
|
|
// GlobalShortcutListener::Observer implementation.
|
2015-01-09 18:24:36 -07:00
|
|
|
void OnKeyPressed(const ui::Accelerator& accelerator) override;
|
2014-07-30 22:22:29 -06:00
|
|
|
|
|
|
|
AcceleratorCallbackMap accelerator_callback_map_;
|
|
|
|
};
|
|
|
|
|
2022-06-29 13:55:47 -06:00
|
|
|
} // namespace electron::api
|
2014-07-30 22:22:29 -06:00
|
|
|
|
2021-11-22 00:34:31 -07:00
|
|
|
#endif // ELECTRON_SHELL_BROWSER_API_ELECTRON_API_GLOBAL_SHORTCUT_H_
|