diff options
author | kpschoedel <kpschoedel@chromium.org> | 2015-08-28 08:29:35 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-08-28 15:30:16 +0000 |
commit | 51d2e327f7a4ff8347867713e098ea81fd601df7 (patch) | |
tree | dfcedf30dd25be910012bc0e6e2c320fb9aeeb55 /ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.cc | |
parent | 4ec68d9ad2d3e0c74967a17946c8bf7ed4450f73 (diff) | |
download | chromium_src-51d2e327f7a4ff8347867713e098ea81fd601df7.zip chromium_src-51d2e327f7a4ff8347867713e098ea81fd601df7.tar.gz chromium_src-51d2e327f7a4ff8347867713e098ea81fd601df7.tar.bz2 |
Revise ui::DomKey to unify character and non-character codes.
DomKey becomes a single integer value corresponding to the DOM
UI Events KeyboardEvent.key string; it can represent either a
Unicode code point or one of the defined non-printable values from
<https://w3c.github.io/DOM-Level-3-Events-key/>.
In the previous representation, ui::DomKey enumerated only the non-
printable values and had a sentinel to indicated that a character value
was held separately. Much of this CL therefore merely replaces
|key, character| pairs with a single |key| value. The most substantial
changes are to
ui/events/keycodes/dom/dom_key.h
ui/events/keycodes/dom/keycode_converter.h
ui/events/event.h
and associated implementations.
BUG=227231
Review URL: https://codereview.chromium.org/1284433002
Cr-Commit-Position: refs/heads/master@{#346152}
Diffstat (limited to 'ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.cc')
-rw-r--r-- | ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.cc | 39 |
1 files changed, 16 insertions, 23 deletions
diff --git a/ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.cc b/ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.cc index 3e393dc8..5307f73 100644 --- a/ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.cc +++ b/ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.cc @@ -19,7 +19,6 @@ #include "ui/events/keycodes/dom/keycode_converter.h" #include "ui/events/keycodes/keyboard_code_conversion.h" #include "ui/events/keycodes/keyboard_code_conversion_xkb.h" -#include "ui/events/ozone/layout/xkb/xkb_keyboard_code_conversion.h" namespace ui { @@ -716,9 +715,8 @@ bool XkbKeyboardLayoutEngine::UsesAltGr() const { bool XkbKeyboardLayoutEngine::Lookup(DomCode dom_code, int flags, DomKey* dom_key, - base::char16* character, KeyboardCode* key_code, - uint32* platform_keycode) const { + uint32_t* platform_keycode) const { if (dom_code == DomCode::NONE) return false; // Convert DOM physical key to XKB representation. @@ -732,30 +730,26 @@ bool XkbKeyboardLayoutEngine::Lookup(DomCode dom_code, xkb_mod_mask_t xkb_flags = EventFlagsToXkbFlags(flags); // Obtain keysym and character. xkb_keysym_t xkb_keysym; - if (!XkbLookup(xkb_keycode, xkb_flags, &xkb_keysym, character)) + uint32_t character = 0; + if (!XkbLookup(xkb_keycode, xkb_flags, &xkb_keysym, &character)) return false; *platform_keycode = xkb_keysym; // Classify the keysym and convert to DOM and VKEY representations. *dom_key = NonPrintableXKeySymToDomKey(xkb_keysym); if (*dom_key == DomKey::NONE) { - *dom_key = CharacterToDomKey(*character); - *key_code = AlphanumericKeyboardCode(*character); + *dom_key = DomKey::FromCharacter(character); + *key_code = AlphanumericKeyboardCode(character); if (*key_code == VKEY_UNKNOWN) { *key_code = DifficultKeyboardCode(dom_code, flags, xkb_keycode, xkb_flags, - xkb_keysym, *dom_key, *character); - if (*key_code == VKEY_UNKNOWN) { + xkb_keysym, character); + if (*key_code == VKEY_UNKNOWN) *key_code = LocatedToNonLocatedKeyboardCode( DomCodeToUsLayoutKeyboardCode(dom_code)); - } } // If the Control key is down, only allow ASCII control characters to be // returned, regardless of the key layout. crbug.com/450849 - if ((flags & EF_CONTROL_DOWN) && (*character >= 0x20)) - *character = 0; - } else if (*dom_key == DomKey::DEAD) { - *character = DeadXkbKeySymToCombiningCharacter(xkb_keysym); - *key_code = LocatedToNonLocatedKeyboardCode( - DomCodeToUsLayoutKeyboardCode(dom_code)); + if ((flags & EF_CONTROL_DOWN) && (character >= 0x20)) + *dom_key = DomKey::UNIDENTIFIED; } else { *key_code = NonPrintableDomKeyToKeyboardCode(*dom_key); if (*key_code == VKEY_UNKNOWN) { @@ -815,7 +809,7 @@ xkb_mod_mask_t XkbKeyboardLayoutEngine::EventFlagsToXkbFlags( bool XkbKeyboardLayoutEngine::XkbLookup(xkb_keycode_t xkb_keycode, xkb_mod_mask_t xkb_flags, xkb_keysym_t* xkb_keysym, - base::char16* character) const { + uint32_t* character) const { if (!xkb_state_) { LOG(ERROR) << "No current XKB state"; return false; @@ -824,9 +818,9 @@ bool XkbKeyboardLayoutEngine::XkbLookup(xkb_keycode_t xkb_keycode, *xkb_keysym = xkb_state_key_get_one_sym(xkb_state_.get(), xkb_keycode); if (*xkb_keysym == XKB_KEY_NoSymbol) return false; - uint32_t c = xkb_state_key_get_utf32(xkb_state_.get(), xkb_keycode); - DLOG_IF(ERROR, c != (c & 0xFFFF)) << "Non-BMP character:" << c; - *character = static_cast<base::char16>(c); + *character = xkb_state_key_get_utf32(xkb_state_.get(), xkb_keycode); + DLOG_IF(ERROR, *character != (*character & 0xFFFF)) + << "Non-BMP character:" << *character; return true; } @@ -836,19 +830,18 @@ KeyboardCode XkbKeyboardLayoutEngine::DifficultKeyboardCode( xkb_keycode_t xkb_keycode, xkb_mod_mask_t xkb_flags, xkb_keysym_t xkb_keysym, - DomKey dom_key, base::char16 character) const { // Get the layout interpretation without modifiers, so that // e.g. Ctrl+D correctly generates VKEY_D. xkb_keysym_t plain_keysym; - base::char16 plain_character; + uint32_t plain_character; if (!XkbLookup(xkb_keycode, 0, &plain_keysym, &plain_character)) return VKEY_UNKNOWN; // If the plain key is non-printable, that determines the VKEY. DomKey plain_key = NonPrintableXKeySymToDomKey(plain_keysym); if (plain_key != ui::DomKey::NONE) - return NonPrintableDomKeyToKeyboardCode(dom_key); + return NonPrintableDomKeyToKeyboardCode(plain_key); // Plain ASCII letters and digits map directly to VKEY values. KeyboardCode key_code = AlphanumericKeyboardCode(plain_character); @@ -911,7 +904,7 @@ base::char16 XkbKeyboardLayoutEngine::XkbSubCharacter( if (flags == base_flags) return base_character; xkb_keysym_t keysym; - base::char16 character = 0; + uint32_t character = 0; if (!XkbLookup(xkb_keycode, flags, &keysym, &character)) character = kNone; return character; |