![electron-roller[bot]](/assets/img/avatar_default.png)
* chore: bump chromium in DEPS to 137.0.7142.0
* chore: bump chromium in DEPS to 137.0.7143.0
* Add accelerator API to get shortcut vector representation
Refs 6442193
* chore: update patches
---------
Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
Co-authored-by: deepak1556 <hop2deep@gmail.com>
75 lines
2.8 KiB
Diff
75 lines
2.8 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Cheng Zhao <zcbenz@gmail.com>
|
|
Date: Thu, 4 Oct 2018 14:57:02 -0700
|
|
Subject: fix: improve shortcut text of Accelerator
|
|
|
|
This patch makes three changes to Accelerator::GetShortcutText to improve shortcut display text in menus:
|
|
|
|
1. F2-F24 accelerators show up as such
|
|
2. Ctrl-Shift-= and Ctrl-Plus show up as such
|
|
|
|
diff --git a/ui/base/accelerators/accelerator.cc b/ui/base/accelerators/accelerator.cc
|
|
index 7eb75d87dd3ed03fc6da738a8b397d4d52f5b5ce..8db9f17c2bdcf5378f9a3f3165956c8f1d1c8d61 100644
|
|
--- a/ui/base/accelerators/accelerator.cc
|
|
+++ b/ui/base/accelerators/accelerator.cc
|
|
@@ -12,6 +12,7 @@
|
|
#include "base/i18n/rtl.h"
|
|
#include "base/notreached.h"
|
|
#include "base/strings/string_util.h"
|
|
+#include "base/strings/stringprintf.h"
|
|
#include "base/strings/utf_string_conversions.h"
|
|
#include "base/types/cxx23_to_underlying.h"
|
|
#include "build/build_config.h"
|
|
@@ -160,6 +161,11 @@ std::u16string Accelerator::GetKeyCodeStringForShortcut() const {
|
|
#endif
|
|
|
|
if (key_string.empty()) {
|
|
+ // When a shifted char is explicitly specified, for example Ctrl+Plus,
|
|
+ // use the shifted char directly.
|
|
+ if (shifted_char) {
|
|
+ key_string += *shifted_char;
|
|
+ } else {
|
|
#if BUILDFLAG(IS_WIN)
|
|
// Our fallback is to try translate the key code to a regular character
|
|
// unless it is one of digits (VK_0 to VK_9). Some keyboard
|
|
@@ -186,6 +192,10 @@ std::u16string Accelerator::GetKeyCodeStringForShortcut() const {
|
|
static_cast<std::u16string::value_type>(base::ToUpperASCII(c));
|
|
}
|
|
#endif
|
|
+ }
|
|
+ if (key_code_ > VKEY_F1 && key_code_ <= VKEY_F24)
|
|
+ key_string = base::UTF8ToUTF16(
|
|
+ base::StringPrintf("F%d", key_code_ - VKEY_F1 + 1));
|
|
}
|
|
|
|
return key_string;
|
|
@@ -346,7 +356,7 @@ std::vector<std::u16string> Accelerator::GetLongFormModifiers() const {
|
|
modifiers.push_back(l10n_util::GetStringUTF16(IDS_APP_CTRL_KEY));
|
|
}
|
|
|
|
- if (IsShiftDown()) {
|
|
+ if (!shifted_char && IsShiftDown()) {
|
|
modifiers.push_back(l10n_util::GetStringUTF16(IDS_APP_SHIFT_KEY));
|
|
}
|
|
|
|
diff --git a/ui/base/accelerators/accelerator.h b/ui/base/accelerators/accelerator.h
|
|
index e7d5adfac920c97df8bab9bf4ed69a835ee314a9..9aeea7cb4c48d1ccc27304fa99238151b2811c87 100644
|
|
--- a/ui/base/accelerators/accelerator.h
|
|
+++ b/ui/base/accelerators/accelerator.h
|
|
@@ -18,6 +18,7 @@
|
|
#include <vector>
|
|
|
|
#include "base/component_export.h"
|
|
+#include "third_party/abseil-cpp/absl/types/optional.h"
|
|
#include "base/time/time.h"
|
|
#include "build/blink_buildflags.h"
|
|
#include "build/build_config.h"
|
|
@@ -189,6 +190,8 @@ class COMPONENT_EXPORT(UI_BASE) Accelerator {
|
|
return interrupted_by_mouse_event_;
|
|
}
|
|
|
|
+ absl::optional<char16_t> shifted_char;
|
|
+
|
|
private:
|
|
friend class AcceleratorTestMac;
|
|
std::vector<std::u16string> GetLongFormModifiers() const;
|