widget/gonk/libui/KeyLayoutMap.h

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

     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  */
    17 #ifndef _ANDROIDFW_KEY_LAYOUT_MAP_H
    18 #define _ANDROIDFW_KEY_LAYOUT_MAP_H
    20 #include <stdint.h>
    21 #include <utils/Errors.h>
    22 #include <utils/KeyedVector.h>
    23 #include "Tokenizer.h"
    24 #include <utils/RefBase.h>
    26 namespace android {
    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     };
    38     // Axis mode.
    39     Mode mode;
    41     // Axis id.
    42     // When split, this is the axis used for values smaller than the split position.
    43     int32_t axis;
    45     // When split, this is the axis used for values after higher than the split position.
    46     int32_t highAxis;
    48     // The split value, or 0 if not split.
    49     int32_t splitValue;
    51     // The flat value, or -1 if none.
    52     int32_t flatOverride;
    54     AxisInfo() : mode(MODE_NORMAL), axis(-1), highAxis(-1), splitValue(0), flatOverride(-1) {
    55     }
    56 };
    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);
    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;
    71     status_t mapAxis(int32_t scanCode, AxisInfo* outAxisInfo) const;
    73 protected:
    74     virtual ~KeyLayoutMap();
    76 private:
    77     struct Key {
    78         int32_t keyCode;
    79         uint32_t flags;
    80     };
    82     KeyedVector<int32_t, Key> mKeysByScanCode;
    83     KeyedVector<int32_t, Key> mKeysByUsageCode;
    84     KeyedVector<int32_t, AxisInfo> mAxes;
    86     KeyLayoutMap();
    88     const Key* getKey(int32_t scanCode, int32_t usageCode) const;
    90     class Parser {
    91         KeyLayoutMap* mMap;
    92         Tokenizer* mTokenizer;
    94     public:
    95         Parser(KeyLayoutMap* map, Tokenizer* tokenizer);
    96         ~Parser();
    97         status_t parse();
    99     private:
   100         status_t parseKey();
   101         status_t parseAxis();
   102     };
   103 };
   105 } // namespace android
   107 #endif // _ANDROIDFW_KEY_LAYOUT_MAP_H

mercurial