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. Ctrl-Alt-<Key> accelerators show as Ctrl-Alt-<Key> instead of as Ctrl-<Key>
2. F2-F24 accelerators show up as such
3. Ctrl-Shift-= and Ctrl-Plus show up as such

diff --git a/ui/base/accelerators/accelerator.cc b/ui/base/accelerators/accelerator.cc
index 17e1739c12ee38864e735130792321adadb43f08..df75c885e702e6b92ce0441f1a85ddddb9aa70b6 100644
--- a/ui/base/accelerators/accelerator.cc
+++ b/ui/base/accelerators/accelerator.cc
@@ -12,6 +12,7 @@
 #include "base/notreached.h"
 #include "base/strings/strcat.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 "build/chromeos_buildflags.h"
@@ -206,6 +207,11 @@ base::string16 Accelerator::GetShortcutText() const {
 #endif
 
   if (shortcut.empty()) {
+    // When a shifted char is explicitly specified, for example Ctrl+Plus,
+    // use the shifted char directly.
+    if (shifted_char) {
+      shortcut += *shifted_char;
+    } else {
 #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
@@ -229,6 +235,10 @@ base::string16 Accelerator::GetShortcutText() const {
       shortcut +=
           static_cast<base::string16::value_type>(base::ToUpperASCII(c));
 #endif
+    }
+    if (key_code_ > VKEY_F1 && key_code_ <= VKEY_F24)
+      shortcut = base::UTF8ToUTF16(
+          base::StringPrintf("F%d", key_code_ - VKEY_F1 + 1));
   }
 
 #if defined(OS_APPLE)
@@ -403,7 +413,7 @@ base::string16 Accelerator::KeyCodeToName() const {
 
 base::string16 Accelerator::ApplyLongFormModifiers(
     base::string16 shortcut) const {
-  if (IsShiftDown())
+  if (!shifted_char && IsShiftDown())
     shortcut = ApplyModifierToAcceleratorString(shortcut, IDS_APP_SHIFT_KEY);
 
   // Note that we use 'else-if' in order to avoid using Ctrl+Alt as a shortcut.
@@ -411,7 +421,7 @@ base::string16 Accelerator::ApplyLongFormModifiers(
   // more information.
   if (IsCtrlDown())
     shortcut = ApplyModifierToAcceleratorString(shortcut, IDS_APP_CTRL_KEY);
-  else if (IsAltDown())
+  if (IsAltDown())
     shortcut = ApplyModifierToAcceleratorString(shortcut, IDS_APP_ALT_KEY);
 
   if (IsCmdDown()) {
diff --git a/ui/base/accelerators/accelerator.h b/ui/base/accelerators/accelerator.h
index 35a9bb01aef4b3fea34caf06f97944405a0212fe..45f07a97c834d6716210aadb1e8f3f83aa08b5e9 100644
--- a/ui/base/accelerators/accelerator.h
+++ b/ui/base/accelerators/accelerator.h
@@ -15,6 +15,7 @@
 #include <utility>
 
 #include "base/component_export.h"
+#include "base/optional.h"
 #include "base/strings/string16.h"
 #include "base/time/time.h"
 #include "build/build_config.h"
@@ -100,6 +101,8 @@ class COMPONENT_EXPORT(UI_BASE) Accelerator {
     return interrupted_by_mouse_event_;
   }
 
+  base::Optional<base::char16> shifted_char;
+
  private:
   base::string16 ApplyLongFormModifiers(base::string16 shortcut) const;
   base::string16 ApplyShortFormModifiers(base::string16 shortcut) const;
