Commit 9987bfb7 authored by Gary Kacmarcik's avatar Gary Kacmarcik Committed by Commit Bot

KeyboardMap - Fix Japanese layout

Previously, the Japanese layout was not returned as the highest-prio
ASCII-capable layout because not all of the writing-system-keys produced
printable characters.  Specifically, the Backquote key is used as the
hankaku/zenkaku key to switch between half-width and full-width chars.

This cl fixes that by handling the Japanese/Backquote key as a special
case, and the keyboard map returns a descriptive string.

Bug: 891501
Change-Id: Ic473700866d711a532d3946be73ff5ec38db580a
Reviewed-on: https://chromium-review.googlesource.com/c/1340970
Commit-Queue: Gary Kacmarcik <garykac@chromium.org>
Reviewed-by: default avatarJoe Downing <joedow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609042}
parent f45c2c54
......@@ -38,6 +38,8 @@ const DomCode writing_system_key_domcodes[] = {
const size_t kWritingSystemKeyDomCodeEntries =
base::size(writing_system_key_domcodes);
const uint32_t kHankakuZenkakuPlaceholder = 0x89d2;
// Mapping from Unicode combining characters to corresponding printable
// character.
const static struct {
......@@ -81,9 +83,16 @@ base::flat_map<std::string, std::string> DomKeyboardLayout::GetMap() {
continue;
std::string key_str;
size_t len = base::WriteUnicodeCharacter(unicode, &key_str);
if (len == 0)
continue;
// Special handling for the Japanese BACKQUOTE, which is an IME key used
// to switch between half-width and full-width mode.
if (unicode == kHankakuZenkakuPlaceholder) {
// 半角/全角 = hankaku/zenkaku = halfwidth/fullwidth
key_str = "\u534a\u89d2/\u5168\u89d2";
} else {
size_t len = base::WriteUnicodeCharacter(unicode, &key_str);
if (len == 0)
continue;
}
dom_map.emplace(KeycodeConverter::DomCodeToCodeString(dom_code), key_str);
}
return dom_map;
......@@ -91,8 +100,7 @@ base::flat_map<std::string, std::string> DomKeyboardLayout::GetMap() {
bool DomKeyboardLayout::IsAsciiCapable() {
uint16_t uniA = layout_[DomCode::US_A];
uint16_t uniBackquote = layout_[DomCode::BACKQUOTE];
return uniA >= 'a' && uniA <= 'z' && uniBackquote != 0;
return uniA >= 'a' && uniA <= 'z';
}
} // namespace ui
......@@ -62,6 +62,8 @@ extern const DomCode writing_system_key_domcodes[];
extern const size_t kWritingSystemKeyDomCodeEntries;
extern const uint32_t kHankakuZenkakuPlaceholder;
} // namespace ui
#endif // UI_EVENTS_KEYCODES_DOM_DOM_KEYBOARD_LAYOUT_H_
......@@ -56,6 +56,9 @@ void DomKeyboardLayoutMapBase::PopulateLayout(uint32_t keyboard_layout_index,
unicode_value = dom_key.ToCharacter();
else if (dom_key.IsDeadKey())
unicode_value = dom_key.ToDeadKeyCombiningCharacter();
else if (dom_key == ui::DomKey::ZENKAKU_HANKAKU)
// Placeholder for hankaku/zenkaku string.
unicode_value = kHankakuZenkakuPlaceholder;
if (unicode_value != 0)
layout->AddKeyMapping(dom_code, unicode_value);
......
......@@ -107,6 +107,16 @@ ui::DomKey DomKeyboardLayoutMapWin::GetDomKeyFromDomCodeForLayout(
if (key_type == -1)
return ui::DomKey::DeadKeyFromCombiningCharacter(char_buffer[0]);
// Special case for Backquote on Japanese keyboard layout.
// Technically, this layout is not completely ASCII-capable because the
// Backquote key is used as a IME function key (hankaku/zenkaku) and is thus
// not a printable key. However, other than this key, it is a perfectly
// usable ASCII-capable layout and it matches the values printed on the
// keyboard, so we have special handling to allow this key.
if (dom_code == ui::DomCode::BACKQUOTE &&
0x04110411 == reinterpret_cast<unsigned int>(keyboard_layout))
return ui::DomKey::ZENKAKU_HANKAKU;
return ui::DomKey::NONE;
}
......
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