diff options
author | 2012-04-18 14:09:10 -0700 | |
---|---|---|
committer | 2012-04-18 15:01:57 -0700 | |
commit | 9a2bbf680e3b5b98051b9f2913ab6bd31b77f79a (patch) | |
tree | 0e6d9dc80e52a02873462a0e051e34fd6f657bbc | |
parent | f35ea5d25b286e166bdc43a589a45b56b6358499 (diff) |
Improve handling of certain keyboard layout properties.
Automatically choose a default value for the 'number' property
based on the characters that the key can generate.
Don't generate any character when ctrl, alt or meta is
pressed unless the behavior exactly matches the modifier keys
that are pressed.
Simplified the basic keyboard layouts taking into account the
new features.
Bug: 6110399
Change-Id: Ibc0f0b50c2dcf3f962a33ac77c24d2993b77637d
-rw-r--r-- | data/keyboards/Generic.kcm | 157 | ||||
-rw-r--r-- | data/keyboards/Virtual.kcm | 290 | ||||
-rw-r--r-- | include/androidfw/KeyCharacterMap.h | 2 | ||||
-rw-r--r-- | libs/androidfw/KeyCharacterMap.cpp | 70 |
4 files changed, 281 insertions, 238 deletions
diff --git a/data/keyboards/Generic.kcm b/data/keyboards/Generic.kcm index b5f689719b32..544076f338ea 100644 --- a/data/keyboards/Generic.kcm +++ b/data/keyboards/Generic.kcm @@ -28,14 +28,12 @@ key A { label: 'A' base: 'a' shift, capslock: 'A' - ctrl, alt, meta: none } key B { label: 'B' base: 'b' shift, capslock: 'B' - ctrl, alt, meta: none } key C { @@ -44,14 +42,12 @@ key C { shift, capslock: 'C' alt: '\u00e7' shift+alt: '\u00c7' - ctrl, meta: none } key D { label: 'D' base: 'd' shift, capslock: 'D' - ctrl, alt, meta: none } key E { @@ -59,28 +55,24 @@ key E { base: 'e' shift, capslock: 'E' alt: '\u0301' - ctrl, meta: none } key F { label: 'F' base: 'f' shift, capslock: 'F' - ctrl, alt, meta: none } key G { label: 'G' base: 'g' shift, capslock: 'G' - ctrl, alt, meta: none } key H { label: 'H' base: 'h' shift, capslock: 'H' - ctrl, alt, meta: none } key I { @@ -88,35 +80,30 @@ key I { base: 'i' shift, capslock: 'I' alt: '\u0302' - ctrl, meta: none } key J { label: 'J' base: 'j' shift, capslock: 'J' - ctrl, alt, meta: none } key K { label: 'K' base: 'k' shift, capslock: 'K' - ctrl, alt, meta: none } key L { label: 'L' base: 'l' shift, capslock: 'L' - ctrl, alt, meta: none } key M { label: 'M' base: 'm' shift, capslock: 'M' - ctrl, alt, meta: none } key N { @@ -124,35 +111,30 @@ key N { base: 'n' shift, capslock: 'N' alt: '\u0303' - ctrl, meta: none } key O { label: 'O' base: 'o' shift, capslock: 'O' - ctrl, alt, meta: none } key P { label: 'P' base: 'p' shift, capslock: 'P' - ctrl, alt, meta: none } key Q { label: 'Q' base: 'q' shift, capslock: 'Q' - ctrl, alt, meta: none } key R { label: 'R' base: 'r' shift, capslock: 'R' - ctrl, alt, meta: none } key S { @@ -160,14 +142,12 @@ key S { base: 's' shift, capslock: 'S' alt: '\u00df' - ctrl, meta: none } key T { label: 'T' base: 't' shift, capslock: 'T' - ctrl, alt, meta: none } key U { @@ -175,338 +155,289 @@ key U { base: 'u' shift, capslock: 'U' alt: '\u0308' - ctrl, meta: none } key V { label: 'V' base: 'v' shift, capslock: 'V' - ctrl, alt, meta: none } key W { label: 'W' base: 'w' shift, capslock: 'W' - ctrl, alt, meta: none } key X { label: 'X' base: 'x' shift, capslock: 'X' - ctrl, alt, meta: none } key Y { label: 'Y' base: 'y' shift, capslock: 'Y' - ctrl, alt, meta: none } key Z { label: 'Z' base: 'z' shift, capslock: 'Z' - ctrl, alt, meta: none } key 0 { - label, number: '0' + label: '0' base: '0' shift: ')' - ctrl, alt, meta: none } key 1 { - label, number: '1' + label: '1' base: '1' shift: '!' - ctrl, alt, meta: none } key 2 { - label, number: '2' + label: '2' base: '2' shift: '@' - ctrl, alt, meta: none } key 3 { - label, number: '3' + label: '3' base: '3' shift: '#' - ctrl, alt, meta: none } key 4 { - label, number: '4' + label: '4' base: '4' shift: '$' - ctrl, alt, meta: none } key 5 { - label, number: '5' + label: '5' base: '5' shift: '%' - ctrl, alt, meta: none } key 6 { - label, number: '6' + label: '6' base: '6' shift: '^' - ctrl, alt, meta: none alt+shift: '\u0302' } key 7 { - label, number: '7' + label: '7' base: '7' shift: '&' - ctrl, alt, meta: none } key 8 { - label, number: '8' + label: '8' base: '8' shift: '*' - ctrl, alt, meta: none } key 9 { - label, number: '9' + label: '9' base: '9' shift: '(' - ctrl, alt, meta: none } key SPACE { label: ' ' base: ' ' - ctrl: none alt, meta: fallback SEARCH } key ENTER { label: '\n' base: '\n' - ctrl, alt, meta: none } key TAB { label: '\t' base: '\t' - ctrl, alt, meta: none } key COMMA { - label, number: ',' + label: ',' base: ',' shift: '<' - ctrl, alt, meta: none } key PERIOD { - label, number: '.' + label: '.' base: '.' shift: '>' - ctrl, alt, meta: none } key SLASH { - label, number: '/' + label: '/' base: '/' shift: '?' - ctrl, alt, meta: none } key GRAVE { - label, number: '`' + label: '`' base: '`' shift: '~' alt: '\u0300' alt+shift: '\u0303' - ctrl, meta: none } key MINUS { - label, number: '-' + label: '-' base: '-' shift: '_' - ctrl, alt, meta: none } key EQUALS { - label, number: '=' + label: '=' base: '=' shift: '+' - ctrl, alt, meta: none } key LEFT_BRACKET { - label, number: '[' + label: '[' base: '[' shift: '{' - ctrl, alt, meta: none } key RIGHT_BRACKET { - label, number: ']' + label: ']' base: ']' shift: '}' - ctrl, alt, meta: none } key BACKSLASH { - label, number: '\\' + label: '\\' base: '\\' shift: '|' - ctrl, alt, meta: none } key SEMICOLON { - label, number: ';' + label: ';' base: ';' shift: ':' - ctrl, alt, meta: none } key APOSTROPHE { - label, number: '\'' + label: '\'' base: '\'' shift: '"' - ctrl, alt, meta: none } ### Numeric keypad ### key NUMPAD_0 { - label, number: '0' + label: '0' base: fallback INSERT numlock: '0' - ctrl, alt, meta: none } key NUMPAD_1 { - label, number: '1' + label: '1' base: fallback MOVE_END numlock: '1' - ctrl, alt, meta: none } key NUMPAD_2 { - label, number: '2' + label: '2' base: fallback DPAD_DOWN numlock: '2' - ctrl, alt, meta: none } key NUMPAD_3 { - label, number: '3' + label: '3' base: fallback PAGE_DOWN numlock: '3' - ctrl, alt, meta: none } key NUMPAD_4 { - label, number: '4' + label: '4' base: fallback DPAD_LEFT numlock: '4' - ctrl, alt, meta: none } key NUMPAD_5 { - label, number: '5' + label: '5' base: fallback DPAD_CENTER numlock: '5' - ctrl, alt, meta: none } key NUMPAD_6 { - label, number: '6' + label: '6' base: fallback DPAD_RIGHT numlock: '6' - ctrl, alt, meta: none } key NUMPAD_7 { - label, number: '7' + label: '7' base: fallback MOVE_HOME numlock: '7' - ctrl, alt, meta: none } key NUMPAD_8 { - label, number: '8' + label: '8' base: fallback DPAD_UP numlock: '8' - ctrl, alt, meta: none } key NUMPAD_9 { - label, number: '9' + label: '9' base: fallback PAGE_UP numlock: '9' - ctrl, alt, meta: none } key NUMPAD_LEFT_PAREN { - label, number: '(' + label: '(' base: '(' - ctrl, alt, meta: none } key NUMPAD_RIGHT_PAREN { - label, number: ')' + label: ')' base: ')' - ctrl, alt, meta: none } key NUMPAD_DIVIDE { - label, number: '/' + label: '/' base: '/' - ctrl, alt, meta: none } key NUMPAD_MULTIPLY { - label, number: '*' + label: '*' base: '*' - ctrl, alt, meta: none } key NUMPAD_SUBTRACT { - label, number: '-' + label: '-' base: '-' - ctrl, alt, meta: none } key NUMPAD_ADD { - label, number: '+' + label: '+' base: '+' - ctrl, alt, meta: none } key NUMPAD_DOT { - label, number: '.' + label: '.' base: fallback FORWARD_DEL numlock: '.' - ctrl, alt, meta: none } key NUMPAD_COMMA { - label, number: ',' + label: ',' base: ',' - ctrl, alt, meta: none } key NUMPAD_EQUALS { - label, number: '=' + label: '=' base: '=' - ctrl, alt, meta: none } key NUMPAD_ENTER { @@ -518,22 +449,22 @@ key NUMPAD_ENTER { ### Special keys on phones ### key AT { - label, number: '@' + label: '@' base: '@' } key STAR { - label, number: '*' + label: '*' base: '*' } key POUND { - label, number: '#' + label: '#' base: '#' } key PLUS { - label, number: '+' + label: '+' base: '+' } diff --git a/data/keyboards/Virtual.kcm b/data/keyboards/Virtual.kcm index 0ce4a6816f37..e592013ae4f6 100644 --- a/data/keyboards/Virtual.kcm +++ b/data/keyboards/Virtual.kcm @@ -25,14 +25,12 @@ key A { label: 'A' base: 'a' shift, capslock: 'A' - ctrl, alt, meta: none } key B { label: 'B' base: 'b' shift, capslock: 'B' - ctrl, alt, meta: none } key C { @@ -41,14 +39,12 @@ key C { shift, capslock: 'C' alt: '\u00e7' shift+alt: '\u00c7' - ctrl, meta: none } key D { label: 'D' base: 'd' shift, capslock: 'D' - ctrl, alt, meta: none } key E { @@ -56,28 +52,24 @@ key E { base: 'e' shift, capslock: 'E' alt: '\u0301' - ctrl, meta: none } key F { label: 'F' base: 'f' shift, capslock: 'F' - ctrl, alt, meta: none } key G { label: 'G' base: 'g' shift, capslock: 'G' - ctrl, alt, meta: none } key H { label: 'H' base: 'h' shift, capslock: 'H' - ctrl, alt, meta: none } key I { @@ -85,35 +77,30 @@ key I { base: 'i' shift, capslock: 'I' alt: '\u0302' - ctrl, meta: none } key J { label: 'J' base: 'j' shift, capslock: 'J' - ctrl, alt, meta: none } key K { label: 'K' base: 'k' shift, capslock: 'K' - ctrl, alt, meta: none } key L { label: 'L' base: 'l' shift, capslock: 'L' - ctrl, alt, meta: none } key M { label: 'M' base: 'm' shift, capslock: 'M' - ctrl, alt, meta: none } key N { @@ -121,35 +108,30 @@ key N { base: 'n' shift, capslock: 'N' alt: '\u0303' - ctrl, meta: none } key O { label: 'O' base: 'o' shift, capslock: 'O' - ctrl, alt, meta: none } key P { label: 'P' base: 'p' shift, capslock: 'P' - ctrl, alt, meta: none } key Q { label: 'Q' base: 'q' shift, capslock: 'Q' - ctrl, alt, meta: none } key R { label: 'R' base: 'r' shift, capslock: 'R' - ctrl, alt, meta: none } key S { @@ -157,14 +139,12 @@ key S { base: 's' shift, capslock: 'S' alt: '\u00df' - ctrl, meta: none } key T { label: 'T' base: 't' shift, capslock: 'T' - ctrl, alt, meta: none } key U { @@ -172,339 +152,289 @@ key U { base: 'u' shift, capslock: 'U' alt: '\u0308' - ctrl, meta: none } key V { label: 'V' base: 'v' shift, capslock: 'V' - ctrl, alt, meta: none } key W { label: 'W' base: 'w' shift, capslock: 'W' - ctrl, alt, meta: none } key X { label: 'X' base: 'x' shift, capslock: 'X' - ctrl, alt, meta: none } key Y { label: 'Y' base: 'y' shift, capslock: 'Y' - ctrl, alt, meta: none } key Z { label: 'Z' base: 'z' shift, capslock: 'Z' - ctrl, alt, meta: none } key 0 { - label, number: '0' + label: '0' base: '0' shift: ')' - ctrl, alt, meta: none } key 1 { - label, number: '1' + label: '1' base: '1' shift: '!' - ctrl, alt, meta: none } key 2 { - label, number: '2' + label: '2' base: '2' shift: '@' - ctrl, alt, meta: none } key 3 { - label, number: '3' + label: '3' base: '3' shift: '#' - ctrl, alt, meta: none } key 4 { - label, number: '4' + label: '4' base: '4' shift: '$' - ctrl, alt, meta: none } key 5 { - label, number: '5' + label: '5' base: '5' shift: '%' - ctrl, alt, meta: none } key 6 { - label, number: '6' + label: '6' base: '6' shift: '^' - ctrl, alt, meta: none alt+shift: '\u0302' } key 7 { - label, number: '7' + label: '7' base: '7' shift: '&' - ctrl, alt, meta: none } key 8 { - label, number: '8' + label: '8' base: '8' shift: '*' - ctrl, alt, meta: none } key 9 { - label, number: '9' + label: '9' base: '9' shift: '(' - ctrl, alt, meta: none } key SPACE { label: ' ' base: ' ' - ctrl, alt: none - meta: fallback SEARCH + alt, meta: fallback SEARCH } key ENTER { label: '\n' base: '\n' - ctrl, alt, meta: none } key TAB { label: '\t' base: '\t' - ctrl, alt: none - meta: fallback APP_SWITCH } key COMMA { - label, number: ',' + label: ',' base: ',' shift: '<' - ctrl, alt, meta: none } key PERIOD { - label, number: '.' + label: '.' base: '.' shift: '>' - ctrl, alt, meta: none } key SLASH { - label, number: '/' + label: '/' base: '/' shift: '?' - ctrl, alt, meta: none } key GRAVE { - label, number: '`' + label: '`' base: '`' shift: '~' alt: '\u0300' alt+shift: '\u0303' - ctrl, meta: none } key MINUS { - label, number: '-' + label: '-' base: '-' shift: '_' - ctrl, alt, meta: none } key EQUALS { - label, number: '=' + label: '=' base: '=' shift: '+' - ctrl, alt, meta: none } key LEFT_BRACKET { - label, number: '[' + label: '[' base: '[' shift: '{' - ctrl, alt, meta: none } key RIGHT_BRACKET { - label, number: ']' + label: ']' base: ']' shift: '}' - ctrl, alt, meta: none } key BACKSLASH { - label, number: '\\' + label: '\\' base: '\\' shift: '|' - ctrl, alt, meta: none } key SEMICOLON { - label, number: ';' + label: ';' base: ';' shift: ':' - ctrl, alt, meta: none } key APOSTROPHE { - label, number: '\'' + label: '\'' base: '\'' shift: '"' - ctrl, alt, meta: none } ### Numeric keypad ### key NUMPAD_0 { - label, number: '0' + label: '0' base: fallback INSERT numlock: '0' - ctrl, alt, meta: none } key NUMPAD_1 { - label, number: '1' + label: '1' base: fallback MOVE_END numlock: '1' - ctrl, alt, meta: none } key NUMPAD_2 { - label, number: '2' + label: '2' base: fallback DPAD_DOWN numlock: '2' - ctrl, alt, meta: none } key NUMPAD_3 { - label, number: '3' + label: '3' base: fallback PAGE_DOWN numlock: '3' - ctrl, alt, meta: none } key NUMPAD_4 { - label, number: '4' + label: '4' base: fallback DPAD_LEFT numlock: '4' - ctrl, alt, meta: none } key NUMPAD_5 { - label, number: '5' + label: '5' base: fallback DPAD_CENTER numlock: '5' - ctrl, alt, meta: none } key NUMPAD_6 { - label, number: '6' + label: '6' base: fallback DPAD_RIGHT numlock: '6' - ctrl, alt, meta: none } key NUMPAD_7 { - label, number: '7' + label: '7' base: fallback MOVE_HOME numlock: '7' - ctrl, alt, meta: none } key NUMPAD_8 { - label, number: '8' + label: '8' base: fallback DPAD_UP numlock: '8' - ctrl, alt, meta: none } key NUMPAD_9 { - label, number: '9' + label: '9' base: fallback PAGE_UP numlock: '9' - ctrl, alt, meta: none } key NUMPAD_LEFT_PAREN { - label, number: '(' + label: '(' base: '(' - ctrl, alt, meta: none } key NUMPAD_RIGHT_PAREN { - label, number: ')' + label: ')' base: ')' - ctrl, alt, meta: none } key NUMPAD_DIVIDE { - label, number: '/' + label: '/' base: '/' - ctrl, alt, meta: none } key NUMPAD_MULTIPLY { - label, number: '*' + label: '*' base: '*' - ctrl, alt, meta: none } key NUMPAD_SUBTRACT { - label, number: '-' + label: '-' base: '-' - ctrl, alt, meta: none } key NUMPAD_ADD { - label, number: '+' + label: '+' base: '+' - ctrl, alt, meta: none } key NUMPAD_DOT { - label, number: '.' + label: '.' base: fallback FORWARD_DEL numlock: '.' - ctrl, alt, meta: none } key NUMPAD_COMMA { - label, number: ',' + label: ',' base: ',' - ctrl, alt, meta: none } key NUMPAD_EQUALS { - label, number: '=' + label: '=' base: '=' - ctrl, alt, meta: none } key NUMPAD_ENTER { @@ -516,22 +446,22 @@ key NUMPAD_ENTER { ### Special keys on phones ### key AT { - label, number: '@' + label: '@' base: '@' } key STAR { - label, number: '*' + label: '*' base: '*' } key POUND { - label, number: '#' + label: '#' base: '#' } key PLUS { - label, number: '+' + label: '+' base: '+' } @@ -539,6 +469,132 @@ key PLUS { key ESCAPE { base: fallback BACK - meta: fallback HOME - alt: fallback MENU + alt, meta: fallback HOME + ctrl: fallback MENU +} + +### Gamepad buttons ### + +key BUTTON_A { + base: fallback BACK +} + +key BUTTON_B { + base: fallback BACK +} + +key BUTTON_C { + base: fallback BACK +} + +key BUTTON_X { + base: fallback DPAD_CENTER +} + +key BUTTON_Y { + base: fallback DPAD_CENTER +} + +key BUTTON_Z { + base: fallback DPAD_CENTER +} + +key BUTTON_L1 { + base: none +} + +key BUTTON_R1 { + base: none +} + +key BUTTON_L2 { + base: none +} + +key BUTTON_R2 { + base: none +} + +key BUTTON_THUMBL { + base: fallback DPAD_CENTER +} + +key BUTTON_THUMBR { + base: fallback DPAD_CENTER +} + +key BUTTON_START { + base: fallback HOME +} + +key BUTTON_SELECT { + base: fallback MENU +} + +key BUTTON_MODE { + base: fallback MENU +} + +key BUTTON_1 { + base: fallback DPAD_CENTER +} + +key BUTTON_2 { + base: fallback DPAD_CENTER +} + +key BUTTON_3 { + base: fallback DPAD_CENTER +} + +key BUTTON_4 { + base: fallback DPAD_CENTER +} + +key BUTTON_5 { + base: fallback DPAD_CENTER +} + +key BUTTON_6 { + base: fallback DPAD_CENTER +} + +key BUTTON_7 { + base: fallback DPAD_CENTER +} + +key BUTTON_8 { + base: fallback DPAD_CENTER +} + +key BUTTON_9 { + base: fallback DPAD_CENTER +} + +key BUTTON_10 { + base: fallback DPAD_CENTER +} + +key BUTTON_11 { + base: fallback DPAD_CENTER +} + +key BUTTON_12 { + base: fallback DPAD_CENTER +} + +key BUTTON_13 { + base: fallback DPAD_CENTER +} + +key BUTTON_14 { + base: fallback DPAD_CENTER +} + +key BUTTON_15 { + base: fallback DPAD_CENTER +} + +key BUTTON_16 { + base: fallback DPAD_CENTER } diff --git a/include/androidfw/KeyCharacterMap.h b/include/androidfw/KeyCharacterMap.h index 8db578129707..06799f965842 100644 --- a/include/androidfw/KeyCharacterMap.h +++ b/include/androidfw/KeyCharacterMap.h @@ -206,6 +206,7 @@ private: status_t parseMapKey(); status_t parseKey(); status_t parseKeyProperty(); + status_t finishKey(Key* key); status_t parseModifier(const String8& token, int32_t* outMetaState); status_t parseCharacterLiteral(char16_t* outCharacter); }; @@ -224,6 +225,7 @@ private: bool getKey(int32_t keyCode, const Key** outKey) const; bool getKeyBehavior(int32_t keyCode, int32_t metaState, const Key** outKey, const Behavior** outBehavior) const; + static bool matchesMetaState(int32_t eventMetaState, int32_t behaviorMetaState); bool findKey(char16_t ch, int32_t* outKeyCode, int32_t* outMetaState) const; diff --git a/libs/androidfw/KeyCharacterMap.cpp b/libs/androidfw/KeyCharacterMap.cpp index c8f94390e4bf..2dc7507f352d 100644 --- a/libs/androidfw/KeyCharacterMap.cpp +++ b/libs/androidfw/KeyCharacterMap.cpp @@ -372,7 +372,7 @@ bool KeyCharacterMap::getKeyBehavior(int32_t keyCode, int32_t metaState, if (getKey(keyCode, &key)) { const Behavior* behavior = key->firstBehavior; while (behavior) { - if ((behavior->metaState & metaState) == behavior->metaState) { + if (matchesMetaState(metaState, behavior->metaState)) { *outKey = key; *outBehavior = behavior; return true; @@ -383,6 +383,37 @@ bool KeyCharacterMap::getKeyBehavior(int32_t keyCode, int32_t metaState, return false; } +bool KeyCharacterMap::matchesMetaState(int32_t eventMetaState, int32_t behaviorMetaState) { + // Behavior must have at least the set of meta states specified. + // And if the key event has CTRL, ALT or META then the behavior must exactly + // match those, taking into account that a behavior can specify that it handles + // one, both or either of a left/right modifier pair. + if ((eventMetaState & behaviorMetaState) == behaviorMetaState) { + const int32_t EXACT_META_STATES = + AMETA_CTRL_ON | AMETA_CTRL_LEFT_ON | AMETA_CTRL_RIGHT_ON + | AMETA_ALT_ON | AMETA_ALT_LEFT_ON | AMETA_ALT_RIGHT_ON + | AMETA_META_ON | AMETA_META_LEFT_ON | AMETA_META_RIGHT_ON; + int32_t unmatchedMetaState = eventMetaState & ~behaviorMetaState & EXACT_META_STATES; + if (behaviorMetaState & AMETA_CTRL_ON) { + unmatchedMetaState &= ~(AMETA_CTRL_LEFT_ON | AMETA_CTRL_RIGHT_ON); + } else if (behaviorMetaState & (AMETA_CTRL_LEFT_ON | AMETA_CTRL_RIGHT_ON)) { + unmatchedMetaState &= ~AMETA_CTRL_ON; + } + if (behaviorMetaState & AMETA_ALT_ON) { + unmatchedMetaState &= ~(AMETA_ALT_LEFT_ON | AMETA_ALT_RIGHT_ON); + } else if (behaviorMetaState & (AMETA_ALT_LEFT_ON | AMETA_ALT_RIGHT_ON)) { + unmatchedMetaState &= ~AMETA_ALT_ON; + } + if (behaviorMetaState & AMETA_META_ON) { + unmatchedMetaState &= ~(AMETA_META_LEFT_ON | AMETA_META_RIGHT_ON); + } else if (behaviorMetaState & (AMETA_META_LEFT_ON | AMETA_META_RIGHT_ON)) { + unmatchedMetaState &= ~AMETA_META_ON; + } + return !unmatchedMetaState; + } + return false; +} + bool KeyCharacterMap::findKey(char16_t ch, int32_t* outKeyCode, int32_t* outMetaState) const { if (!ch) { return false; @@ -699,12 +730,13 @@ status_t KeyCharacterMap::Parser::parse() { return BAD_VALUE; } + if (mMap->mType == KEYBOARD_TYPE_UNKNOWN) { + ALOGE("%s: Keyboard layout missing required keyboard 'type' declaration.", + mTokenizer->getLocation().string()); + return BAD_VALUE; + } + if (mFormat == FORMAT_BASE) { - if (mMap->mType == KEYBOARD_TYPE_UNKNOWN) { - ALOGE("%s: Base keyboard layout missing required keyboard 'type' declaration.", - mTokenizer->getLocation().string()); - return BAD_VALUE; - } if (mMap->mType == KEYBOARD_TYPE_OVERLAY) { ALOGE("%s: Base keyboard layout must specify a keyboard 'type' other than 'OVERLAY'.", mTokenizer->getLocation().string()); @@ -840,10 +872,11 @@ status_t KeyCharacterMap::Parser::parseKey() { } status_t KeyCharacterMap::Parser::parseKeyProperty() { + Key* key = mMap->mKeys.valueFor(mKeyCode); String8 token = mTokenizer->nextToken(WHITESPACE_OR_PROPERTY_DELIMITER); if (token == "}") { mState = STATE_TOP; - return NO_ERROR; + return finishKey(key); } Vector<Property> properties; @@ -943,7 +976,6 @@ status_t KeyCharacterMap::Parser::parseKeyProperty() { } while (!mTokenizer->isEol()); // Add the behavior. - Key* key = mMap->mKeys.valueFor(mKeyCode); for (size_t i = 0; i < properties.size(); i++) { const Property& property = properties.itemAt(i); switch (property.property) { @@ -992,6 +1024,28 @@ status_t KeyCharacterMap::Parser::parseKeyProperty() { return NO_ERROR; } +status_t KeyCharacterMap::Parser::finishKey(Key* key) { + // Fill in default number property. + if (!key->number) { + char16_t digit = 0; + char16_t symbol = 0; + for (Behavior* b = key->firstBehavior; b; b = b->next) { + char16_t ch = b->character; + if (ch) { + if (ch >= '0' && ch <= '9') { + digit = ch; + } else if (ch == '(' || ch == ')' || ch == '#' || ch == '*' + || ch == '-' || ch == '+' || ch == ',' || ch == '.' + || ch == '\'' || ch == ':' || ch == ';' || ch == '/') { + symbol = ch; + } + } + } + key->number = digit ? digit : symbol; + } + return NO_ERROR; +} + status_t KeyCharacterMap::Parser::parseModifier(const String8& token, int32_t* outMetaState) { if (token == "base") { *outMetaState = 0; |