Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 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 | */ |
| 16 | |
| 17 | #ifndef _UI_INPUT_H |
| 18 | #define _UI_INPUT_H |
| 19 | |
| 20 | /** |
| 21 | * Native input event structures. |
| 22 | */ |
| 23 | |
| 24 | #include <android/input.h> |
| 25 | #include <utils/Vector.h> |
Jeff Brown | e57e895 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 26 | #include <utils/KeyedVector.h> |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 27 | #include <utils/Timers.h> |
Jeff Brown | e57e895 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 28 | #include <utils/RefBase.h> |
| 29 | #include <utils/String8.h> |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 30 | |
| 31 | /* |
| 32 | * Additional private constants not defined in ndk/ui/input.h. |
| 33 | */ |
| 34 | enum { |
| 35 | /* |
| 36 | * Private control to determine when an app is tracking a key sequence. |
| 37 | */ |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 38 | AKEY_EVENT_FLAG_START_TRACKING = 0x40000000 |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | /* |
| 42 | * Maximum number of pointers supported per motion event. |
Jeff Brown | d1b0a2b | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 43 | * Smallest number of pointers is 1. |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 44 | */ |
| 45 | #define MAX_POINTERS 10 |
| 46 | |
Dianne Hackborn | 4d96bb6 | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 47 | /* |
Jeff Brown | d1b0a2b | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 48 | * Maximum pointer id value supported in a motion event. |
| 49 | * Smallest pointer id is 0. |
| 50 | * (This is limited by our use of BitSet32 to track pointer assignments.) |
| 51 | */ |
| 52 | #define MAX_POINTER_ID 31 |
| 53 | |
| 54 | /* |
Dianne Hackborn | 4d96bb6 | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 55 | * Declare a concrete type for the NDK's input event forward declaration. |
| 56 | */ |
Dianne Hackborn | ce838a2 | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 57 | struct AInputEvent { |
| 58 | virtual ~AInputEvent() { } |
| 59 | }; |
Dianne Hackborn | 4d96bb6 | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 60 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 61 | /* |
Jeff Brown | e57e895 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 62 | * Declare a concrete type for the NDK's input device forward declaration. |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 63 | */ |
Jeff Brown | e57e895 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 64 | struct AInputDevice { |
| 65 | virtual ~AInputDevice() { } |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 66 | }; |
| 67 | |
Jeff Brown | e57e895 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 68 | |
| 69 | namespace android { |
| 70 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 71 | /* |
| 72 | * Flags that flow alongside events in the input dispatch system to help with certain |
| 73 | * policy decisions such as waking from device sleep. |
Jeff Brown | 90f0cee | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 74 | * |
| 75 | * These flags are also defined in frameworks/base/core/java/android/view/WindowManagerPolicy.java. |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 76 | */ |
| 77 | enum { |
Jeff Brown | 956c0fb | 2010-10-01 14:55:30 -0700 | [diff] [blame] | 78 | /* These flags originate in RawEvents and are generally set in the key map. |
| 79 | * See also labels for policy flags in KeycodeLabels.h. */ |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 80 | |
| 81 | POLICY_FLAG_WAKE = 0x00000001, |
| 82 | POLICY_FLAG_WAKE_DROPPED = 0x00000002, |
| 83 | POLICY_FLAG_SHIFT = 0x00000004, |
| 84 | POLICY_FLAG_CAPS_LOCK = 0x00000008, |
| 85 | POLICY_FLAG_ALT = 0x00000010, |
| 86 | POLICY_FLAG_ALT_GR = 0x00000020, |
| 87 | POLICY_FLAG_MENU = 0x00000040, |
| 88 | POLICY_FLAG_LAUNCHER = 0x00000080, |
Jeff Brown | 956c0fb | 2010-10-01 14:55:30 -0700 | [diff] [blame] | 89 | POLICY_FLAG_VIRTUAL = 0x00000100, |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 90 | |
Jeff Brown | 51d45a7 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 91 | POLICY_FLAG_RAW_MASK = 0x0000ffff, |
| 92 | |
Jeff Brown | af30ff6 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 93 | /* These flags are set by the input dispatcher. */ |
| 94 | |
| 95 | // Indicates that the input event was injected. |
| 96 | POLICY_FLAG_INJECTED = 0x01000000, |
| 97 | |
Jeff Brown | 33d54ce | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 98 | // Indicates that the input event is from a trusted source such as a directly attached |
| 99 | // input device or an application with system-wide event injection permission. |
| 100 | POLICY_FLAG_TRUSTED = 0x02000000, |
| 101 | |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 102 | /* These flags are set by the input reader policy as it intercepts each event. */ |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 103 | |
| 104 | // Indicates that the screen was off when the event was received and the event |
| 105 | // should wake the device. |
| 106 | POLICY_FLAG_WOKE_HERE = 0x10000000, |
| 107 | |
| 108 | // Indicates that the screen was dim when the event was received and the event |
| 109 | // should brighten the device. |
| 110 | POLICY_FLAG_BRIGHT_HERE = 0x20000000, |
Jeff Brown | 90f0cee | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 111 | |
| 112 | // Indicates that the event should be dispatched to applications. |
| 113 | // The input event should still be sent to the InputDispatcher so that it can see all |
| 114 | // input events received include those that it will not deliver. |
| 115 | POLICY_FLAG_PASS_TO_USER = 0x40000000, |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | /* |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 119 | * Describes the basic configuration of input devices that are present. |
| 120 | */ |
| 121 | struct InputConfiguration { |
| 122 | enum { |
| 123 | TOUCHSCREEN_UNDEFINED = 0, |
| 124 | TOUCHSCREEN_NOTOUCH = 1, |
| 125 | TOUCHSCREEN_STYLUS = 2, |
| 126 | TOUCHSCREEN_FINGER = 3 |
| 127 | }; |
| 128 | |
| 129 | enum { |
| 130 | KEYBOARD_UNDEFINED = 0, |
| 131 | KEYBOARD_NOKEYS = 1, |
| 132 | KEYBOARD_QWERTY = 2, |
| 133 | KEYBOARD_12KEY = 3 |
| 134 | }; |
| 135 | |
| 136 | enum { |
| 137 | NAVIGATION_UNDEFINED = 0, |
| 138 | NAVIGATION_NONAV = 1, |
| 139 | NAVIGATION_DPAD = 2, |
| 140 | NAVIGATION_TRACKBALL = 3, |
| 141 | NAVIGATION_WHEEL = 4 |
| 142 | }; |
| 143 | |
| 144 | int32_t touchScreen; |
| 145 | int32_t keyboard; |
| 146 | int32_t navigation; |
| 147 | }; |
| 148 | |
| 149 | /* |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 150 | * Pointer coordinate data. |
| 151 | */ |
| 152 | struct PointerCoords { |
| 153 | float x; |
| 154 | float y; |
| 155 | float pressure; |
| 156 | float size; |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 157 | float touchMajor; |
| 158 | float touchMinor; |
| 159 | float toolMajor; |
| 160 | float toolMinor; |
| 161 | float orientation; |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 162 | }; |
| 163 | |
| 164 | /* |
| 165 | * Input events. |
| 166 | */ |
Dianne Hackborn | 9c7f818 | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 167 | class InputEvent : public AInputEvent { |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 168 | public: |
| 169 | virtual ~InputEvent() { } |
| 170 | |
| 171 | virtual int32_t getType() const = 0; |
| 172 | |
| 173 | inline int32_t getDeviceId() const { return mDeviceId; } |
| 174 | |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 175 | inline int32_t getSource() const { return mSource; } |
Dianne Hackborn | 189ed23 | 2010-06-29 19:20:40 -0700 | [diff] [blame] | 176 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 177 | protected: |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 178 | void initialize(int32_t deviceId, int32_t source); |
Dianne Hackborn | 0e88527 | 2010-07-15 17:44:53 -0700 | [diff] [blame] | 179 | void initialize(const InputEvent& from); |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 180 | |
| 181 | private: |
| 182 | int32_t mDeviceId; |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 183 | int32_t mSource; |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 184 | }; |
| 185 | |
Jeff Brown | f4a4ec2 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 186 | /* |
| 187 | * Key events. |
| 188 | */ |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 189 | class KeyEvent : public InputEvent { |
| 190 | public: |
| 191 | virtual ~KeyEvent() { } |
| 192 | |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 193 | virtual int32_t getType() const { return AINPUT_EVENT_TYPE_KEY; } |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 194 | |
| 195 | inline int32_t getAction() const { return mAction; } |
| 196 | |
| 197 | inline int32_t getFlags() const { return mFlags; } |
| 198 | |
| 199 | inline int32_t getKeyCode() const { return mKeyCode; } |
| 200 | |
| 201 | inline int32_t getScanCode() const { return mScanCode; } |
| 202 | |
| 203 | inline int32_t getMetaState() const { return mMetaState; } |
| 204 | |
| 205 | inline int32_t getRepeatCount() const { return mRepeatCount; } |
| 206 | |
| 207 | inline nsecs_t getDownTime() const { return mDownTime; } |
| 208 | |
| 209 | inline nsecs_t getEventTime() const { return mEventTime; } |
| 210 | |
Dianne Hackborn | 189ed23 | 2010-06-29 19:20:40 -0700 | [diff] [blame] | 211 | // Return true if this event may have a default action implementation. |
| 212 | static bool hasDefaultAction(int32_t keyCode); |
| 213 | bool hasDefaultAction() const; |
| 214 | |
| 215 | // Return true if this event represents a system key. |
| 216 | static bool isSystemKey(int32_t keyCode); |
| 217 | bool isSystemKey() const; |
| 218 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 219 | void initialize( |
| 220 | int32_t deviceId, |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 221 | int32_t source, |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 222 | int32_t action, |
| 223 | int32_t flags, |
| 224 | int32_t keyCode, |
| 225 | int32_t scanCode, |
| 226 | int32_t metaState, |
| 227 | int32_t repeatCount, |
| 228 | nsecs_t downTime, |
| 229 | nsecs_t eventTime); |
Dianne Hackborn | 0e88527 | 2010-07-15 17:44:53 -0700 | [diff] [blame] | 230 | void initialize(const KeyEvent& from); |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 231 | |
| 232 | private: |
| 233 | int32_t mAction; |
| 234 | int32_t mFlags; |
| 235 | int32_t mKeyCode; |
| 236 | int32_t mScanCode; |
| 237 | int32_t mMetaState; |
| 238 | int32_t mRepeatCount; |
| 239 | nsecs_t mDownTime; |
| 240 | nsecs_t mEventTime; |
| 241 | }; |
| 242 | |
Jeff Brown | f4a4ec2 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 243 | /* |
| 244 | * Motion events. |
| 245 | */ |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 246 | class MotionEvent : public InputEvent { |
| 247 | public: |
| 248 | virtual ~MotionEvent() { } |
| 249 | |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 250 | virtual int32_t getType() const { return AINPUT_EVENT_TYPE_MOTION; } |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 251 | |
| 252 | inline int32_t getAction() const { return mAction; } |
| 253 | |
Jeff Brown | af30ff6 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 254 | inline int32_t getFlags() const { return mFlags; } |
| 255 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 256 | inline int32_t getEdgeFlags() const { return mEdgeFlags; } |
| 257 | |
| 258 | inline int32_t getMetaState() const { return mMetaState; } |
| 259 | |
Jeff Brown | f4a4ec2 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 260 | inline float getXOffset() const { return mXOffset; } |
| 261 | |
| 262 | inline float getYOffset() const { return mYOffset; } |
| 263 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 264 | inline float getXPrecision() const { return mXPrecision; } |
| 265 | |
| 266 | inline float getYPrecision() const { return mYPrecision; } |
| 267 | |
| 268 | inline nsecs_t getDownTime() const { return mDownTime; } |
| 269 | |
| 270 | inline size_t getPointerCount() const { return mPointerIds.size(); } |
| 271 | |
| 272 | inline int32_t getPointerId(size_t pointerIndex) const { return mPointerIds[pointerIndex]; } |
| 273 | |
| 274 | inline nsecs_t getEventTime() const { return mSampleEventTimes[getHistorySize()]; } |
| 275 | |
Jeff Brown | f4a4ec2 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 276 | inline float getRawX(size_t pointerIndex) const { |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 277 | return getCurrentPointerCoords(pointerIndex).x; |
| 278 | } |
| 279 | |
Jeff Brown | f4a4ec2 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 280 | inline float getRawY(size_t pointerIndex) const { |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 281 | return getCurrentPointerCoords(pointerIndex).y; |
| 282 | } |
| 283 | |
Jeff Brown | f4a4ec2 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 284 | inline float getX(size_t pointerIndex) const { |
| 285 | return getRawX(pointerIndex) + mXOffset; |
| 286 | } |
| 287 | |
| 288 | inline float getY(size_t pointerIndex) const { |
| 289 | return getRawY(pointerIndex) + mYOffset; |
| 290 | } |
| 291 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 292 | inline float getPressure(size_t pointerIndex) const { |
| 293 | return getCurrentPointerCoords(pointerIndex).pressure; |
| 294 | } |
| 295 | |
| 296 | inline float getSize(size_t pointerIndex) const { |
| 297 | return getCurrentPointerCoords(pointerIndex).size; |
| 298 | } |
| 299 | |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 300 | inline float getTouchMajor(size_t pointerIndex) const { |
| 301 | return getCurrentPointerCoords(pointerIndex).touchMajor; |
| 302 | } |
| 303 | |
| 304 | inline float getTouchMinor(size_t pointerIndex) const { |
| 305 | return getCurrentPointerCoords(pointerIndex).touchMinor; |
| 306 | } |
| 307 | |
| 308 | inline float getToolMajor(size_t pointerIndex) const { |
| 309 | return getCurrentPointerCoords(pointerIndex).toolMajor; |
| 310 | } |
| 311 | |
| 312 | inline float getToolMinor(size_t pointerIndex) const { |
| 313 | return getCurrentPointerCoords(pointerIndex).toolMinor; |
| 314 | } |
| 315 | |
| 316 | inline float getOrientation(size_t pointerIndex) const { |
| 317 | return getCurrentPointerCoords(pointerIndex).orientation; |
| 318 | } |
| 319 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 320 | inline size_t getHistorySize() const { return mSampleEventTimes.size() - 1; } |
| 321 | |
| 322 | inline nsecs_t getHistoricalEventTime(size_t historicalIndex) const { |
| 323 | return mSampleEventTimes[historicalIndex]; |
| 324 | } |
| 325 | |
Jeff Brown | f4a4ec2 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 326 | inline float getHistoricalRawX(size_t pointerIndex, size_t historicalIndex) const { |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 327 | return getHistoricalPointerCoords(pointerIndex, historicalIndex).x; |
| 328 | } |
| 329 | |
Jeff Brown | f4a4ec2 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 330 | inline float getHistoricalRawY(size_t pointerIndex, size_t historicalIndex) const { |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 331 | return getHistoricalPointerCoords(pointerIndex, historicalIndex).y; |
| 332 | } |
| 333 | |
Jeff Brown | f4a4ec2 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 334 | inline float getHistoricalX(size_t pointerIndex, size_t historicalIndex) const { |
| 335 | return getHistoricalRawX(pointerIndex, historicalIndex) + mXOffset; |
| 336 | } |
| 337 | |
| 338 | inline float getHistoricalY(size_t pointerIndex, size_t historicalIndex) const { |
| 339 | return getHistoricalRawY(pointerIndex, historicalIndex) + mYOffset; |
| 340 | } |
| 341 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 342 | inline float getHistoricalPressure(size_t pointerIndex, size_t historicalIndex) const { |
| 343 | return getHistoricalPointerCoords(pointerIndex, historicalIndex).pressure; |
| 344 | } |
| 345 | |
| 346 | inline float getHistoricalSize(size_t pointerIndex, size_t historicalIndex) const { |
| 347 | return getHistoricalPointerCoords(pointerIndex, historicalIndex).size; |
| 348 | } |
| 349 | |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 350 | inline float getHistoricalTouchMajor(size_t pointerIndex, size_t historicalIndex) const { |
| 351 | return getHistoricalPointerCoords(pointerIndex, historicalIndex).touchMajor; |
| 352 | } |
| 353 | |
| 354 | inline float getHistoricalTouchMinor(size_t pointerIndex, size_t historicalIndex) const { |
| 355 | return getHistoricalPointerCoords(pointerIndex, historicalIndex).touchMinor; |
| 356 | } |
| 357 | |
| 358 | inline float getHistoricalToolMajor(size_t pointerIndex, size_t historicalIndex) const { |
| 359 | return getHistoricalPointerCoords(pointerIndex, historicalIndex).toolMajor; |
| 360 | } |
| 361 | |
| 362 | inline float getHistoricalToolMinor(size_t pointerIndex, size_t historicalIndex) const { |
| 363 | return getHistoricalPointerCoords(pointerIndex, historicalIndex).toolMinor; |
| 364 | } |
| 365 | |
| 366 | inline float getHistoricalOrientation(size_t pointerIndex, size_t historicalIndex) const { |
| 367 | return getHistoricalPointerCoords(pointerIndex, historicalIndex).orientation; |
| 368 | } |
| 369 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 370 | void initialize( |
| 371 | int32_t deviceId, |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 372 | int32_t source, |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 373 | int32_t action, |
Jeff Brown | af30ff6 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 374 | int32_t flags, |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 375 | int32_t edgeFlags, |
| 376 | int32_t metaState, |
Jeff Brown | f4a4ec2 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 377 | float xOffset, |
| 378 | float yOffset, |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 379 | float xPrecision, |
| 380 | float yPrecision, |
| 381 | nsecs_t downTime, |
| 382 | nsecs_t eventTime, |
| 383 | size_t pointerCount, |
| 384 | const int32_t* pointerIds, |
| 385 | const PointerCoords* pointerCoords); |
| 386 | |
| 387 | void addSample( |
| 388 | nsecs_t eventTime, |
| 389 | const PointerCoords* pointerCoords); |
| 390 | |
| 391 | void offsetLocation(float xOffset, float yOffset); |
| 392 | |
Jeff Brown | f4a4ec2 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 393 | // Low-level accessors. |
| 394 | inline const int32_t* getPointerIds() const { return mPointerIds.array(); } |
| 395 | inline const nsecs_t* getSampleEventTimes() const { return mSampleEventTimes.array(); } |
| 396 | inline const PointerCoords* getSamplePointerCoords() const { |
| 397 | return mSamplePointerCoords.array(); |
| 398 | } |
| 399 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 400 | private: |
| 401 | int32_t mAction; |
Jeff Brown | af30ff6 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 402 | int32_t mFlags; |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 403 | int32_t mEdgeFlags; |
| 404 | int32_t mMetaState; |
Jeff Brown | f4a4ec2 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 405 | float mXOffset; |
| 406 | float mYOffset; |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 407 | float mXPrecision; |
| 408 | float mYPrecision; |
| 409 | nsecs_t mDownTime; |
| 410 | Vector<int32_t> mPointerIds; |
| 411 | Vector<nsecs_t> mSampleEventTimes; |
| 412 | Vector<PointerCoords> mSamplePointerCoords; |
| 413 | |
| 414 | inline const PointerCoords& getCurrentPointerCoords(size_t pointerIndex) const { |
| 415 | return mSamplePointerCoords[getHistorySize() * getPointerCount() + pointerIndex]; |
| 416 | } |
| 417 | |
| 418 | inline const PointerCoords& getHistoricalPointerCoords( |
| 419 | size_t pointerIndex, size_t historicalIndex) const { |
| 420 | return mSamplePointerCoords[historicalIndex * getPointerCount() + pointerIndex]; |
| 421 | } |
| 422 | }; |
| 423 | |
| 424 | /* |
| 425 | * Input event factory. |
| 426 | */ |
| 427 | class InputEventFactoryInterface { |
| 428 | protected: |
| 429 | virtual ~InputEventFactoryInterface() { } |
| 430 | |
| 431 | public: |
| 432 | InputEventFactoryInterface() { } |
| 433 | |
| 434 | virtual KeyEvent* createKeyEvent() = 0; |
| 435 | virtual MotionEvent* createMotionEvent() = 0; |
| 436 | }; |
| 437 | |
| 438 | /* |
| 439 | * A simple input event factory implementation that uses a single preallocated instance |
| 440 | * of each type of input event that are reused for each request. |
| 441 | */ |
| 442 | class PreallocatedInputEventFactory : public InputEventFactoryInterface { |
| 443 | public: |
| 444 | PreallocatedInputEventFactory() { } |
| 445 | virtual ~PreallocatedInputEventFactory() { } |
| 446 | |
| 447 | virtual KeyEvent* createKeyEvent() { return & mKeyEvent; } |
| 448 | virtual MotionEvent* createMotionEvent() { return & mMotionEvent; } |
| 449 | |
| 450 | private: |
| 451 | KeyEvent mKeyEvent; |
| 452 | MotionEvent mMotionEvent; |
| 453 | }; |
| 454 | |
Jeff Brown | e57e895 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 455 | /* |
| 456 | * Describes the characteristics and capabilities of an input device. |
| 457 | */ |
| 458 | class InputDeviceInfo { |
| 459 | public: |
| 460 | InputDeviceInfo(); |
| 461 | InputDeviceInfo(const InputDeviceInfo& other); |
| 462 | ~InputDeviceInfo(); |
| 463 | |
| 464 | struct MotionRange { |
| 465 | float min; |
| 466 | float max; |
| 467 | float flat; |
| 468 | float fuzz; |
| 469 | }; |
| 470 | |
| 471 | void initialize(int32_t id, const String8& name); |
| 472 | |
| 473 | inline int32_t getId() const { return mId; } |
| 474 | inline const String8 getName() const { return mName; } |
| 475 | inline uint32_t getSources() const { return mSources; } |
| 476 | |
| 477 | const MotionRange* getMotionRange(int32_t rangeType) const; |
| 478 | |
| 479 | void addSource(uint32_t source); |
| 480 | void addMotionRange(int32_t rangeType, float min, float max, float flat, float fuzz); |
| 481 | void addMotionRange(int32_t rangeType, const MotionRange& range); |
| 482 | |
| 483 | inline void setKeyboardType(int32_t keyboardType) { mKeyboardType = keyboardType; } |
| 484 | inline int32_t getKeyboardType() const { return mKeyboardType; } |
| 485 | |
Jeff Brown | 38a7fab | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 486 | inline const KeyedVector<int32_t, MotionRange> getMotionRanges() const { |
| 487 | return mMotionRanges; |
| 488 | } |
| 489 | |
Jeff Brown | e57e895 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 490 | private: |
| 491 | int32_t mId; |
| 492 | String8 mName; |
| 493 | uint32_t mSources; |
| 494 | int32_t mKeyboardType; |
| 495 | |
| 496 | KeyedVector<int32_t, MotionRange> mMotionRanges; |
| 497 | }; |
| 498 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 499 | |
| 500 | } // namespace android |
| 501 | |
| 502 | #endif // _UI_INPUT_H |