electron/shell/browser/api/electron_api_global_shortcut.h
electron-roller[bot] 49078100f4
chore: bump chromium to 133.0.6943.35 (35-x-y) (#45217)
* chore: bump chromium in DEPS to 133.0.6943.16

* chore: bump chromium in DEPS to 133.0.6943.27

* chore: bump chromium in DEPS to 133.0.6943.35

* chore: bump chromium to 134.0.6968.0

cherry picked from 75eac86506da4fd87aa7ec36478d5c196b988d4f

---------

Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
2025-02-03 15:10:57 -05:00

66 lines
2.2 KiB
C++

// Copyright (c) 2014 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ELECTRON_SHELL_BROWSER_API_ELECTRON_API_GLOBAL_SHORTCUT_H_
#define ELECTRON_SHELL_BROWSER_API_ELECTRON_API_GLOBAL_SHORTCUT_H_
#include <map>
#include <vector>
#include "base/functional/callback_forward.h"
#include "extensions/common/extension_id.h"
#include "gin/wrappable.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/base/accelerators/global_accelerator_listener/global_accelerator_listener.h"
namespace gin {
template <typename T>
class Handle;
} // namespace gin
namespace electron::api {
class GlobalShortcut final : private ui::GlobalAcceleratorListener::Observer,
public gin::Wrappable<GlobalShortcut> {
public:
static gin::Handle<GlobalShortcut> Create(v8::Isolate* isolate);
// gin::Wrappable
static gin::WrapperInfo kWrapperInfo;
gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
v8::Isolate* isolate) override;
const char* GetTypeName() override;
// disable copy
GlobalShortcut(const GlobalShortcut&) = delete;
GlobalShortcut& operator=(const GlobalShortcut&) = delete;
protected:
explicit GlobalShortcut(v8::Isolate* isolate);
~GlobalShortcut() override;
private:
typedef std::map<ui::Accelerator, base::RepeatingClosure>
AcceleratorCallbackMap;
bool RegisterAll(const std::vector<ui::Accelerator>& accelerators,
const base::RepeatingClosure& callback);
bool Register(const ui::Accelerator& accelerator,
const base::RepeatingClosure& callback);
bool IsRegistered(const ui::Accelerator& accelerator);
void Unregister(const ui::Accelerator& accelerator);
void UnregisterSome(const std::vector<ui::Accelerator>& accelerators);
void UnregisterAll();
// GlobalAcceleratorListener::Observer implementation.
void OnKeyPressed(const ui::Accelerator& accelerator) override;
void ExecuteCommand(const extensions::ExtensionId& extension_id,
const std::string& command_id) override;
AcceleratorCallbackMap accelerator_callback_map_;
};
} // namespace electron::api
#endif // ELECTRON_SHELL_BROWSER_API_ELECTRON_API_GLOBAL_SHORTCUT_H_