| 
									
										
										
										
											2018-10-24 11:24:11 -07:00
										 |  |  | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | 
					
						
							| 
									
										
										
										
											2018-09-20 17:30:26 -07:00
										 |  |  | From: Cheng Zhao <zcbenz@gmail.com> | 
					
						
							|  |  |  | Date: Thu, 4 Oct 2018 14:57:02 -0700 | 
					
						
							|  |  |  | Subject: accelerator.patch | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-12 21:41:07 -07:00
										 |  |  | 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-= should show as Ctrl-+ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-13 22:02:16 -07:00
										 |  |  | diff --git a/ui/base/accelerators/accelerator.cc b/ui/base/accelerators/accelerator.cc
 | 
					
						
							| 
									
										
										
										
											2021-03-15 20:33:49 -04:00
										 |  |  | index 1a2a154b743cd4ecccf1be9971f36896e982dc6e..b5cec83c479dfa584f496f1f73a81e8b9f64d08c 100644
 | 
					
						
							| 
									
										
										
										
											2018-09-13 22:02:16 -07:00
										 |  |  | --- a/ui/base/accelerators/accelerator.cc
 | 
					
						
							|  |  |  | +++ b/ui/base/accelerators/accelerator.cc
 | 
					
						
							| 
									
										
										
										
											2020-05-26 13:06:26 -07:00
										 |  |  | @@ -12,6 +12,7 @@
 | 
					
						
							|  |  |  |  #include "base/notreached.h" | 
					
						
							| 
									
										
										
										
											2018-09-13 22:02:16 -07:00
										 |  |  |  #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" | 
					
						
							| 
									
										
										
										
											2020-12-14 10:57:36 -08:00
										 |  |  |  #include "build/chromeos_buildflags.h" | 
					
						
							|  |  |  | @@ -24,9 +25,7 @@
 | 
					
						
							| 
									
										
										
										
											2018-09-13 22:02:16 -07:00
										 |  |  |  #include <windows.h> | 
					
						
							|  |  |  |  #endif | 
					
						
							|  |  |  |   | 
					
						
							| 
									
										
										
										
											2020-08-12 11:33:58 -07:00
										 |  |  | -#if !defined(OS_WIN) && (defined(USE_AURA) || defined(OS_APPLE))
 | 
					
						
							| 
									
										
										
										
											2018-09-13 22:02:16 -07:00
										 |  |  |  #include "ui/events/keycodes/keyboard_code_conversion.h" | 
					
						
							|  |  |  | -#endif
 | 
					
						
							|  |  |  |   | 
					
						
							| 
									
										
										
										
											2020-12-14 10:57:36 -08:00
										 |  |  |  #if BUILDFLAG(IS_CHROMEOS_ASH) | 
					
						
							| 
									
										
										
										
											2020-04-13 16:39:26 -07:00
										 |  |  |  #include "ui/base/ui_base_features.h" | 
					
						
							| 
									
										
										
										
											2021-03-15 14:32:18 -04:00
										 |  |  | @@ -205,7 +204,15 @@ std::u16string Accelerator::GetShortcutText() const {
 | 
					
						
							| 
									
										
										
										
											2019-07-02 18:22:09 -07:00
										 |  |  |    shortcut = KeyCodeToName(); | 
					
						
							| 
									
										
										
										
											2018-09-13 22:02:16 -07:00
										 |  |  |  #endif | 
					
						
							|  |  |  |   | 
					
						
							|  |  |  | +  unsigned int flags = 0;
 | 
					
						
							|  |  |  |    if (shortcut.empty()) { | 
					
						
							|  |  |  | +    const uint16_t c = DomCodeToUsLayoutCharacter(
 | 
					
						
							|  |  |  | +        UsLayoutKeyboardCodeToDomCode(key_code_), flags);
 | 
					
						
							|  |  |  | +    if (c != 0) {
 | 
					
						
							|  |  |  | +      shortcut =
 | 
					
						
							|  |  |  | +          static_cast<base::string16::value_type>(
 | 
					
						
							| 
									
										
										
										
											2021-03-15 20:33:49 -04:00
										 |  |  | +              base::ToUpperASCII(static_cast<char16_t>(c)));
 | 
					
						
							| 
									
										
										
										
											2018-09-13 22:02:16 -07:00
										 |  |  | +    }
 | 
					
						
							|  |  |  |  #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 | 
					
						
							| 
									
										
										
										
											2021-03-15 14:32:18 -04:00
										 |  |  | @@ -214,21 +221,14 @@ std::u16string Accelerator::GetShortcutText() const {
 | 
					
						
							| 
									
										
										
										
											2018-09-13 22:02:16 -07:00
										 |  |  |      // 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; | 
					
						
							|  |  |  | -    if (base::IsAsciiDigit(key_code_))
 | 
					
						
							|  |  |  | +    if (base::IsAsciiDigit(key_code_)) {
 | 
					
						
							|  |  |  |        key = static_cast<wchar_t>(key_code_); | 
					
						
							|  |  |  | -    else
 | 
					
						
							|  |  |  | -      key = LOWORD(::MapVirtualKeyW(key_code_, MAPVK_VK_TO_CHAR));
 | 
					
						
							| 
									
										
										
										
											2019-03-21 08:45:22 -07:00
										 |  |  | -    // If there is no translation for the given |key_code_| (e.g.
 | 
					
						
							|  |  |  | -    // VKEY_UNKNOWN), |::MapVirtualKeyW| returns 0.
 | 
					
						
							|  |  |  | -    if (key != 0)
 | 
					
						
							|  |  |  | -      shortcut += key;
 | 
					
						
							| 
									
										
										
										
											2020-08-12 11:33:58 -07:00
										 |  |  | -#elif defined(USE_AURA) || defined(OS_APPLE) || defined(OS_ANDROID)
 | 
					
						
							| 
									
										
										
										
											2018-09-13 22:02:16 -07:00
										 |  |  | -    const uint16_t c = DomCodeToUsLayoutCharacter(
 | 
					
						
							|  |  |  | -        UsLayoutKeyboardCodeToDomCode(key_code_), false);
 | 
					
						
							|  |  |  | -    if (c != 0)
 | 
					
						
							|  |  |  | -      shortcut +=
 | 
					
						
							| 
									
										
										
										
											2021-03-15 14:32:18 -04:00
										 |  |  | -          static_cast<std::u16string::value_type>(base::ToUpperASCII(c));
 | 
					
						
							| 
									
										
										
										
											2018-09-13 22:02:16 -07:00
										 |  |  | +      shortcut = key;
 | 
					
						
							|  |  |  | +    }
 | 
					
						
							| 
									
										
										
										
											2018-10-31 15:13:44 +01:00
										 |  |  |  #endif | 
					
						
							| 
									
										
										
										
											2018-09-13 22:02:16 -07:00
										 |  |  | +    if (key_code_ > VKEY_F1 && key_code_ <= VKEY_F24)
 | 
					
						
							|  |  |  | +      shortcut = base::UTF8ToUTF16(
 | 
					
						
							|  |  |  | +          base::StringPrintf("F%d", key_code_ - VKEY_F1 + 1));
 | 
					
						
							|  |  |  |    } | 
					
						
							|  |  |  |   | 
					
						
							| 
									
										
										
										
											2020-08-12 11:33:58 -07:00
										 |  |  |  #if defined(OS_APPLE) | 
					
						
							| 
									
										
										
										
											2021-03-15 14:32:18 -04:00
										 |  |  | @@ -411,7 +411,7 @@ std::u16string Accelerator::ApplyLongFormModifiers(
 | 
					
						
							| 
									
										
										
										
											2018-09-13 22:02:16 -07:00
										 |  |  |    // more information. | 
					
						
							|  |  |  |    if (IsCtrlDown()) | 
					
						
							| 
									
										
										
										
											2018-10-24 16:25:48 -07:00
										 |  |  |      shortcut = ApplyModifierToAcceleratorString(shortcut, IDS_APP_CTRL_KEY); | 
					
						
							| 
									
										
										
										
											2018-09-13 22:02:16 -07:00
										 |  |  | -  else if (IsAltDown())
 | 
					
						
							|  |  |  | +  if (IsAltDown())
 | 
					
						
							| 
									
										
										
										
											2018-10-24 16:25:48 -07:00
										 |  |  |      shortcut = ApplyModifierToAcceleratorString(shortcut, IDS_APP_ALT_KEY); | 
					
						
							| 
									
										
										
										
											2018-09-13 22:02:16 -07:00
										 |  |  |   | 
					
						
							|  |  |  |    if (IsCmdDown()) { |