Commit 1ae73afd authored by Anton Permyakov's avatar Anton Permyakov Committed by Commit Bot

Fixes accelerator shortcut text for unknown keys

For unknown key codes presenting in an accelerator 0 is added
to the shortcut text. This results in unprintable character to be used
on extensions shortcuts settings page.

Bug: 936812
Change-Id: I5301660d8110defd908146862a230666af09a07d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1497072
Commit-Queue: Alexander Yashkin <a-v-y@yandex-team.ru>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Cr-Commit-Position: refs/heads/master@{#638507}
parent d11651f1
...@@ -161,7 +161,10 @@ base::string16 Accelerator::GetShortcutText() const { ...@@ -161,7 +161,10 @@ base::string16 Accelerator::GetShortcutText() const {
key = static_cast<wchar_t>(key_code_); key = static_cast<wchar_t>(key_code_);
else else
key = LOWORD(::MapVirtualKeyW(key_code_, MAPVK_VK_TO_CHAR)); key = LOWORD(::MapVirtualKeyW(key_code_, MAPVK_VK_TO_CHAR));
shortcut += key; // If there is no translation for the given |key_code_| (e.g.
// VKEY_UNKNOWN), |::MapVirtualKeyW| returns 0.
if (key != 0)
shortcut += key;
#elif defined(USE_AURA) || defined(OS_MACOSX) || defined(OS_ANDROID) #elif defined(USE_AURA) || defined(OS_MACOSX) || defined(OS_ANDROID)
const uint16_t c = DomCodeToUsLayoutCharacter( const uint16_t c = DomCodeToUsLayoutCharacter(
UsLayoutKeyboardCodeToDomCode(key_code_), false); UsLayoutKeyboardCodeToDomCode(key_code_), false);
......
...@@ -62,4 +62,9 @@ TEST(AcceleratorTest, GetShortcutText) { ...@@ -62,4 +62,9 @@ TEST(AcceleratorTest, GetShortcutText) {
} }
} }
TEST(AcceleratorTest, ShortcutTextForUnknownKey) {
const Accelerator accelerator(VKEY_UNKNOWN, EF_NONE);
EXPECT_EQ(base::string16(), accelerator.GetShortcutText());
}
} // namespace ui } // namespace ui
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment