1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/gonk/libui/KeyLayoutMap.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,107 @@ 1.4 +/* 1.5 + * Copyright (C) 2008 The Android Open Source Project 1.6 + * 1.7 + * Licensed under the Apache License, Version 2.0 (the "License"); 1.8 + * you may not use this file except in compliance with the License. 1.9 + * You may obtain a copy of the License at 1.10 + * 1.11 + * http://www.apache.org/licenses/LICENSE-2.0 1.12 + * 1.13 + * Unless required by applicable law or agreed to in writing, software 1.14 + * distributed under the License is distributed on an "AS IS" BASIS, 1.15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1.16 + * See the License for the specific language governing permissions and 1.17 + * limitations under the License. 1.18 + */ 1.19 + 1.20 +#ifndef _ANDROIDFW_KEY_LAYOUT_MAP_H 1.21 +#define _ANDROIDFW_KEY_LAYOUT_MAP_H 1.22 + 1.23 +#include <stdint.h> 1.24 +#include <utils/Errors.h> 1.25 +#include <utils/KeyedVector.h> 1.26 +#include "Tokenizer.h" 1.27 +#include <utils/RefBase.h> 1.28 + 1.29 +namespace android { 1.30 + 1.31 +struct AxisInfo { 1.32 + enum Mode { 1.33 + // Axis value is reported directly. 1.34 + MODE_NORMAL = 0, 1.35 + // Axis value should be inverted before reporting. 1.36 + MODE_INVERT = 1, 1.37 + // Axis value should be split into two axes 1.38 + MODE_SPLIT = 2, 1.39 + }; 1.40 + 1.41 + // Axis mode. 1.42 + Mode mode; 1.43 + 1.44 + // Axis id. 1.45 + // When split, this is the axis used for values smaller than the split position. 1.46 + int32_t axis; 1.47 + 1.48 + // When split, this is the axis used for values after higher than the split position. 1.49 + int32_t highAxis; 1.50 + 1.51 + // The split value, or 0 if not split. 1.52 + int32_t splitValue; 1.53 + 1.54 + // The flat value, or -1 if none. 1.55 + int32_t flatOverride; 1.56 + 1.57 + AxisInfo() : mode(MODE_NORMAL), axis(-1), highAxis(-1), splitValue(0), flatOverride(-1) { 1.58 + } 1.59 +}; 1.60 + 1.61 +/** 1.62 + * Describes a mapping from keyboard scan codes and joystick axes to Android key codes and axes. 1.63 + * 1.64 + * This object is immutable after it has been loaded. 1.65 + */ 1.66 +class KeyLayoutMap : public RefBase { 1.67 +public: 1.68 + static status_t load(const String8& filename, sp<KeyLayoutMap>* outMap); 1.69 + 1.70 + status_t mapKey(int32_t scanCode, int32_t usageCode, 1.71 + int32_t* outKeyCode, uint32_t* outFlags) const; 1.72 + status_t findScanCodesForKey(int32_t keyCode, Vector<int32_t>* outScanCodes) const; 1.73 + 1.74 + status_t mapAxis(int32_t scanCode, AxisInfo* outAxisInfo) const; 1.75 + 1.76 +protected: 1.77 + virtual ~KeyLayoutMap(); 1.78 + 1.79 +private: 1.80 + struct Key { 1.81 + int32_t keyCode; 1.82 + uint32_t flags; 1.83 + }; 1.84 + 1.85 + KeyedVector<int32_t, Key> mKeysByScanCode; 1.86 + KeyedVector<int32_t, Key> mKeysByUsageCode; 1.87 + KeyedVector<int32_t, AxisInfo> mAxes; 1.88 + 1.89 + KeyLayoutMap(); 1.90 + 1.91 + const Key* getKey(int32_t scanCode, int32_t usageCode) const; 1.92 + 1.93 + class Parser { 1.94 + KeyLayoutMap* mMap; 1.95 + Tokenizer* mTokenizer; 1.96 + 1.97 + public: 1.98 + Parser(KeyLayoutMap* map, Tokenizer* tokenizer); 1.99 + ~Parser(); 1.100 + status_t parse(); 1.101 + 1.102 + private: 1.103 + status_t parseKey(); 1.104 + status_t parseAxis(); 1.105 + }; 1.106 +}; 1.107 + 1.108 +} // namespace android 1.109 + 1.110 +#endif // _ANDROIDFW_KEY_LAYOUT_MAP_H