electron/shell/browser/ui/accelerator_util.h
trop[bot] 3da65aa53e
perf: prefer base::SplitStringPiece() over base::SplitString() (#45946)
* perf: use base::SplitStringPiece() in SetNodeOptions()

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* perf: use base::SplitStringPiece() in StringToAccelerator()

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: StringToAccelerator() now takes a std::string_view

Co-authored-by: Charles Kerr <charles@charleskerr.com>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
2025-03-10 09:49:53 -05:00

37 lines
1.2 KiB
C++

// Copyright (c) 2013 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_UI_ACCELERATOR_UTIL_H_
#define ELECTRON_SHELL_BROWSER_UI_ACCELERATOR_UTIL_H_
#include <map>
#include <string_view>
#include "base/memory/raw_ptr.h"
#include "shell/browser/ui/electron_menu_model.h"
#include "ui/base/accelerators/accelerator.h"
namespace accelerator_util {
typedef struct {
size_t position;
raw_ptr<electron::ElectronMenuModel> model;
} MenuItem;
typedef std::map<ui::Accelerator, MenuItem> AcceleratorTable;
// Parse a string as an accelerator.
bool StringToAccelerator(std::string_view shortcut,
ui::Accelerator* accelerator);
// Generate a table that contains menu model's accelerators and command ids.
void GenerateAcceleratorTable(AcceleratorTable* table,
electron::ElectronMenuModel* model);
// Trigger command from the accelerators table.
bool TriggerAcceleratorTableCommand(AcceleratorTable* table,
const ui::Accelerator& accelerator);
} // namespace accelerator_util
#endif // ELECTRON_SHELL_BROWSER_UI_ACCELERATOR_UTIL_H_