accelerator.patch 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Cheng Zhao <[email protected]>
  3. Date: Thu, 4 Oct 2018 14:57:02 -0700
  4. Subject: accelerator.patch
  5. This patch makes three changes to Accelerator::GetShortcutText to improve shortcut display text in menus:
  6. 1. Ctrl-Alt-<Key> accelerators show as Ctrl-Alt-<Key> instead of as Ctrl-<Key>
  7. 2. F2-F24 accelerators show up as such
  8. 3. Ctrl-Shift-= should show as Ctrl-+
  9. diff --git a/ui/base/accelerators/accelerator.cc b/ui/base/accelerators/accelerator.cc
  10. index 7f26ef86fe967663a50bb556b49a37e1d10d5462..c83431034b9ddf0084f2ee2fc2538e4fb5aa0f0c 100644
  11. --- a/ui/base/accelerators/accelerator.cc
  12. +++ b/ui/base/accelerators/accelerator.cc
  13. @@ -12,6 +12,7 @@
  14. #include "base/notreached.h"
  15. #include "base/strings/strcat.h"
  16. #include "base/strings/string_util.h"
  17. +#include "base/strings/stringprintf.h"
  18. #include "base/strings/utf_string_conversions.h"
  19. #include "build/build_config.h"
  20. #include "ui/base/l10n/l10n_util.h"
  21. @@ -23,9 +24,7 @@
  22. #include <windows.h>
  23. #endif
  24. -#if !defined(OS_WIN) && (defined(USE_AURA) || defined(OS_MACOSX))
  25. #include "ui/events/keycodes/keyboard_code_conversion.h"
  26. -#endif
  27. #if defined(OS_CHROMEOS)
  28. #include "ui/base/ui_base_features.h"
  29. @@ -204,7 +203,15 @@ base::string16 Accelerator::GetShortcutText() const {
  30. shortcut = KeyCodeToName();
  31. #endif
  32. + unsigned int flags = 0;
  33. if (shortcut.empty()) {
  34. + const uint16_t c = DomCodeToUsLayoutCharacter(
  35. + UsLayoutKeyboardCodeToDomCode(key_code_), flags);
  36. + if (c != 0) {
  37. + shortcut =
  38. + static_cast<base::string16::value_type>(
  39. + base::ToUpperASCII(static_cast<base::char16>(c)));
  40. + }
  41. #if defined(OS_WIN)
  42. // Our fallback is to try translate the key code to a regular character
  43. // unless it is one of digits (VK_0 to VK_9). Some keyboard
  44. @@ -213,21 +220,14 @@ base::string16 Accelerator::GetShortcutText() const {
  45. // accent' for '0'). For display in the menu (e.g. Ctrl-0 for the
  46. // default zoom level), we leave VK_[0-9] alone without translation.
  47. wchar_t key;
  48. - if (base::IsAsciiDigit(key_code_))
  49. + if (base::IsAsciiDigit(key_code_)) {
  50. key = static_cast<wchar_t>(key_code_);
  51. - else
  52. - key = LOWORD(::MapVirtualKeyW(key_code_, MAPVK_VK_TO_CHAR));
  53. - // If there is no translation for the given |key_code_| (e.g.
  54. - // VKEY_UNKNOWN), |::MapVirtualKeyW| returns 0.
  55. - if (key != 0)
  56. - shortcut += key;
  57. -#elif defined(USE_AURA) || defined(OS_MACOSX) || defined(OS_ANDROID)
  58. - const uint16_t c = DomCodeToUsLayoutCharacter(
  59. - UsLayoutKeyboardCodeToDomCode(key_code_), false);
  60. - if (c != 0)
  61. - shortcut +=
  62. - static_cast<base::string16::value_type>(base::ToUpperASCII(c));
  63. + shortcut = key;
  64. + }
  65. #endif
  66. + if (key_code_ > VKEY_F1 && key_code_ <= VKEY_F24)
  67. + shortcut = base::UTF8ToUTF16(
  68. + base::StringPrintf("F%d", key_code_ - VKEY_F1 + 1));
  69. }
  70. #if defined(OS_MACOSX)
  71. @@ -410,7 +410,7 @@ base::string16 Accelerator::ApplyLongFormModifiers(
  72. // more information.
  73. if (IsCtrlDown())
  74. shortcut = ApplyModifierToAcceleratorString(shortcut, IDS_APP_CTRL_KEY);
  75. - else if (IsAltDown())
  76. + if (IsAltDown())
  77. shortcut = ApplyModifierToAcceleratorString(shortcut, IDS_APP_ALT_KEY);
  78. if (IsCmdDown()) {