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 46b49a484fc7d42facf494733ca21e451fc54e25..eb4c80a0b788ac046bcfdb54ae85eaaef90cd76b 100644
--- a/ui/base/accelerators/accelerator.cc
+++ b/ui/base/accelerators/accelerator.cc
@@ -13,6 +13,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 "build/build_config.h"
 #include "ui/base/l10n/l10n_util.h"
@@ -164,6 +165,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
@@ -190,6 +196,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;
@@ -350,7 +360,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 666ecbc118bec6d51465644ae4e573846c33610b..5f578ea153477379bac69e48fbd4f41a9a24885e 100644
--- a/ui/base/accelerators/accelerator.h
+++ b/ui/base/accelerators/accelerator.h
@@ -21,6 +21,7 @@
 #include "base/time/time.h"
 #include "build/blink_buildflags.h"
 #include "build/build_config.h"
+#include "third_party/abseil-cpp/absl/types/optional.h"
 #include "ui/events/event_constants.h"
 #include "ui/events/keycodes/keyboard_codes.h"
 
@@ -199,6 +200,8 @@ class COMPONENT_EXPORT(UI_BASE) Accelerator {
               << 18);  // masked to 6 bits
   }
 
+  absl::optional<char16_t> shifted_char;
+
  private:
   friend class AcceleratorTestMac;
   std::vector<std::u16string> GetLongFormModifiers() const;
