widget/gonk/libui/KeyLayoutMap.h

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:5a3fea9f356b
1 /*
2 * Copyright (C) 2008 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 */
16
17 #ifndef _ANDROIDFW_KEY_LAYOUT_MAP_H
18 #define _ANDROIDFW_KEY_LAYOUT_MAP_H
19
20 #include <stdint.h>
21 #include <utils/Errors.h>
22 #include <utils/KeyedVector.h>
23 #include "Tokenizer.h"
24 #include <utils/RefBase.h>
25
26 namespace android {
27
28 struct AxisInfo {
29 enum Mode {
30 // Axis value is reported directly.
31 MODE_NORMAL = 0,
32 // Axis value should be inverted before reporting.
33 MODE_INVERT = 1,
34 // Axis value should be split into two axes
35 MODE_SPLIT = 2,
36 };
37
38 // Axis mode.
39 Mode mode;
40
41 // Axis id.
42 // When split, this is the axis used for values smaller than the split position.
43 int32_t axis;
44
45 // When split, this is the axis used for values after higher than the split position.
46 int32_t highAxis;
47
48 // The split value, or 0 if not split.
49 int32_t splitValue;
50
51 // The flat value, or -1 if none.
52 int32_t flatOverride;
53
54 AxisInfo() : mode(MODE_NORMAL), axis(-1), highAxis(-1), splitValue(0), flatOverride(-1) {
55 }
56 };
57
58 /**
59 * Describes a mapping from keyboard scan codes and joystick axes to Android key codes and axes.
60 *
61 * This object is immutable after it has been loaded.
62 */
63 class KeyLayoutMap : public RefBase {
64 public:
65 static status_t load(const String8& filename, sp<KeyLayoutMap>* outMap);
66
67 status_t mapKey(int32_t scanCode, int32_t usageCode,
68 int32_t* outKeyCode, uint32_t* outFlags) const;
69 status_t findScanCodesForKey(int32_t keyCode, Vector<int32_t>* outScanCodes) const;
70
71 status_t mapAxis(int32_t scanCode, AxisInfo* outAxisInfo) const;
72
73 protected:
74 virtual ~KeyLayoutMap();
75
76 private:
77 struct Key {
78 int32_t keyCode;
79 uint32_t flags;
80 };
81
82 KeyedVector<int32_t, Key> mKeysByScanCode;
83 KeyedVector<int32_t, Key> mKeysByUsageCode;
84 KeyedVector<int32_t, AxisInfo> mAxes;
85
86 KeyLayoutMap();
87
88 const Key* getKey(int32_t scanCode, int32_t usageCode) const;
89
90 class Parser {
91 KeyLayoutMap* mMap;
92 Tokenizer* mTokenizer;
93
94 public:
95 Parser(KeyLayoutMap* map, Tokenizer* tokenizer);
96 ~Parser();
97 status_t parse();
98
99 private:
100 status_t parseKey();
101 status_t parseAxis();
102 };
103 };
104
105 } // namespace android
106
107 #endif // _ANDROIDFW_KEY_LAYOUT_MAP_H

mercurial