widget/gonk/libui/Keyboard.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /*
     2  * Copyright (C) 2010 The Android Open Source Project
     3  *
     4  * Licensed under the Apache License, Version 2.0 (the "License");
     5  * you may not use this file except in compliance with the License.
     6  * You may obtain a copy of the License at
     7  *
     8  *      http://www.apache.org/licenses/LICENSE-2.0
     9  *
    10  * Unless required by applicable law or agreed to in writing, software
    11  * distributed under the License is distributed on an "AS IS" BASIS,
    12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  * See the License for the specific language governing permissions and
    14  * limitations under the License.
    15  */
    17 #ifndef _ANDROIDFW_KEYBOARD_H
    18 #define _ANDROIDFW_KEYBOARD_H
    20 #include "Input.h"
    21 #include "InputDevice.h"
    22 #include <utils/Errors.h>
    23 #include <utils/String8.h>
    24 #include <utils/PropertyMap.h>
    26 namespace android {
    28 enum {
    29     /* Device id of the built in keyboard. */
    30     DEVICE_ID_BUILT_IN_KEYBOARD = 0,
    32     /* Device id of a generic virtual keyboard with a full layout that can be used
    33      * to synthesize key events. */
    34     DEVICE_ID_VIRTUAL_KEYBOARD = -1,
    35 };
    37 class KeyLayoutMap;
    38 class KeyCharacterMap;
    40 /**
    41  * Loads the key layout map and key character map for a keyboard device.
    42  */
    43 class KeyMap {
    44 public:
    45     String8 keyLayoutFile;
    46     sp<KeyLayoutMap> keyLayoutMap;
    48     String8 keyCharacterMapFile;
    49     sp<KeyCharacterMap> keyCharacterMap;
    51     KeyMap();
    52     ~KeyMap();
    54     status_t load(const InputDeviceIdentifier& deviceIdenfier,
    55             const PropertyMap* deviceConfiguration);
    57     inline bool haveKeyLayout() const {
    58         return !keyLayoutFile.isEmpty();
    59     }
    61     inline bool haveKeyCharacterMap() const {
    62         return !keyCharacterMapFile.isEmpty();
    63     }
    65     inline bool isComplete() const {
    66         return haveKeyLayout() && haveKeyCharacterMap();
    67     }
    69 private:
    70     bool probeKeyMap(const InputDeviceIdentifier& deviceIdentifier, const String8& name);
    71     status_t loadKeyLayout(const InputDeviceIdentifier& deviceIdentifier, const String8& name);
    72     status_t loadKeyCharacterMap(const InputDeviceIdentifier& deviceIdentifier,
    73             const String8& name);
    74     String8 getPath(const InputDeviceIdentifier& deviceIdentifier,
    75             const String8& name, InputDeviceConfigurationFileType type);
    76 };
    78 /**
    79  * Returns true if the keyboard is eligible for use as a built-in keyboard.
    80  */
    81 extern bool isEligibleBuiltInKeyboard(const InputDeviceIdentifier& deviceIdentifier,
    82         const PropertyMap* deviceConfiguration, const KeyMap* keyMap);
    84 /**
    85  * Gets a key code by its short form label, eg. "HOME".
    86  * Returns 0 if unknown.
    87  */
    88 extern int32_t getKeyCodeByLabel(const char* label);
    90 /**
    91  * Gets a key flag by its short form label, eg. "WAKE".
    92  * Returns 0 if unknown.
    93  */
    94 extern uint32_t getKeyFlagByLabel(const char* label);
    96 /**
    97  * Gets a axis by its short form label, eg. "X".
    98  * Returns -1 if unknown.
    99  */
   100 extern int32_t getAxisByLabel(const char* label);
   102 /**
   103  * Gets a axis label by its id.
   104  * Returns NULL if unknown.
   105  */
   106 extern const char* getAxisLabel(int32_t axisId);
   108 /**
   109  * Updates a meta state field when a key is pressed or released.
   110  */
   111 extern int32_t updateMetaState(int32_t keyCode, bool down, int32_t oldMetaState);
   113 /**
   114  * Returns true if a key is a meta key like ALT or CAPS_LOCK.
   115  */
   116 extern bool isMetaKey(int32_t keyCode);
   118 } // namespace android
   120 #endif // _ANDROIDFW_KEYBOARD_H

mercurial