fix: don't append Shift modifier text twice to accelerators (#15400)

* fix: don't append Shift modifier text twice to accelerators

* style: use the new way of creating patches

* test: add menu item accelerator display tests

* fix: allocate accelerator on the stack

* fix: adjust tests to match expected behavior on mac
This commit is contained in:
Heilig Benedek 2018-10-31 15:13:44 +01:00 committed by John Kleinschmidt
parent 1d81d1a706
commit aa6f7a5d9f
4 changed files with 78 additions and 27 deletions

View file

@ -5,7 +5,7 @@ Subject: accelerator.patch
diff --git a/ui/base/accelerators/accelerator.cc b/ui/base/accelerators/accelerator.cc
index 7e55ef366ac8320f730cdcb268453b1fa2710887..c3fb98b426cd7c12f66eaaf358f4ff184628bba1 100644
index 7e55ef366ac8320f730cdcb268453b1fa2710887..9b000ab1dfb85c097e879eacbfe69dc052960766 100644
--- a/ui/base/accelerators/accelerator.cc
+++ b/ui/base/accelerators/accelerator.cc
@@ -11,6 +11,7 @@
@ -42,7 +42,7 @@ index 7e55ef366ac8320f730cdcb268453b1fa2710887..c3fb98b426cd7c12f66eaaf358f4ff18
#if defined(OS_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
@@ -148,17 +155,20 @@ base::string16 Accelerator::GetShortcutText() const {
@@ -148,18 +155,14 @@ base::string16 Accelerator::GetShortcutText() const {
// accent' for '0'). For display in the menu (e.g. Ctrl-0 for the
// default zoom level), we leave VK_[0-9] alone without translation.
wchar_t key;
@ -60,20 +60,14 @@ index 7e55ef366ac8320f730cdcb268453b1fa2710887..c3fb98b426cd7c12f66eaaf358f4ff18
- static_cast<base::string16::value_type>(base::ToUpperASCII(c));
+ shortcut = key;
+ }
+#endif
#endif
+ if (key_code_ > VKEY_F1 && key_code_ <= VKEY_F24)
+ shortcut = base::UTF8ToUTF16(
+ base::StringPrintf("F%d", key_code_ - VKEY_F1 + 1));
+ } else if (IsShiftDown()) {
+#if defined(OS_MACOSX)
+ const base::char16 kShiftSymbol[] = {0x21e7, 0};
+ shortcut = kShiftSymbol;
+#else
+ shortcut = l10n_util::GetStringFUTF16(IDS_APP_SHIFT_MODIFIER, shortcut);
#endif
}
@@ -223,7 +233,7 @@ base::string16 Accelerator::ApplyLongFormModifiers(
// Checking whether the character used for the accelerator is alphanumeric.
@@ -223,7 +226,7 @@ base::string16 Accelerator::ApplyLongFormModifiers(
// more information.
if (IsCtrlDown())
shortcut = l10n_util::GetStringFUTF16(IDS_APP_CONTROL_MODIFIER, shortcut);
@ -82,18 +76,3 @@ index 7e55ef366ac8320f730cdcb268453b1fa2710887..c3fb98b426cd7c12f66eaaf358f4ff18
shortcut = l10n_util::GetStringFUTF16(IDS_APP_ALT_MODIFIER, shortcut);
if (IsCmdDown()) {
@@ -243,14 +253,12 @@ base::string16 Accelerator::ApplyShortFormModifiers(
base::string16 shortcut) const {
const base::char16 kCommandSymbol[] = {0x2318, 0};
const base::char16 kCtrlSymbol[] = {0x2303, 0};
- const base::char16 kShiftSymbol[] = {0x21e7, 0};
const base::char16 kOptionSymbol[] = {0x2325, 0};
const base::char16 kNoSymbol[] = {0};
std::vector<base::string16> parts;
parts.push_back(base::string16(IsCtrlDown() ? kCtrlSymbol : kNoSymbol));
parts.push_back(base::string16(IsAltDown() ? kOptionSymbol : kNoSymbol));
- parts.push_back(base::string16(IsShiftDown() ? kShiftSymbol : kNoSymbol));
parts.push_back(base::string16(IsCmdDown() ? kCommandSymbol : kNoSymbol));
parts.push_back(shortcut);
return base::StrCat(parts);