Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright (C) 2010 The Android Open Source Project |
michael@0 | 3 | * |
michael@0 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
michael@0 | 5 | * you may not use this file except in compliance with the License. |
michael@0 | 6 | * You may obtain a copy of the License at |
michael@0 | 7 | * |
michael@0 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
michael@0 | 9 | * |
michael@0 | 10 | * Unless required by applicable law or agreed to in writing, software |
michael@0 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
michael@0 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
michael@0 | 13 | * See the License for the specific language governing permissions and |
michael@0 | 14 | * limitations under the License. |
michael@0 | 15 | */ |
michael@0 | 16 | |
michael@0 | 17 | #ifndef _ANDROIDFW_INPUT_H |
michael@0 | 18 | #define _ANDROIDFW_INPUT_H |
michael@0 | 19 | |
michael@0 | 20 | /** |
michael@0 | 21 | * Native input event structures. |
michael@0 | 22 | */ |
michael@0 | 23 | |
michael@0 | 24 | #include "android_input.h" |
michael@0 | 25 | #include <utils/Vector.h> |
michael@0 | 26 | #include <utils/KeyedVector.h> |
michael@0 | 27 | #include <utils/Timers.h> |
michael@0 | 28 | #include <utils/RefBase.h> |
michael@0 | 29 | #include <utils/String8.h> |
michael@0 | 30 | |
michael@0 | 31 | #ifdef HAVE_ANDROID_OS |
michael@0 | 32 | class SkMatrix; |
michael@0 | 33 | #endif |
michael@0 | 34 | |
michael@0 | 35 | /* |
michael@0 | 36 | * Additional private constants not defined in ndk/ui/input.h. |
michael@0 | 37 | */ |
michael@0 | 38 | enum { |
michael@0 | 39 | /* Signifies that the key is being predispatched */ |
michael@0 | 40 | AKEY_EVENT_FLAG_PREDISPATCH = 0x20000000, |
michael@0 | 41 | |
michael@0 | 42 | /* Private control to determine when an app is tracking a key sequence. */ |
michael@0 | 43 | AKEY_EVENT_FLAG_START_TRACKING = 0x40000000, |
michael@0 | 44 | |
michael@0 | 45 | /* Key event is inconsistent with previously sent key events. */ |
michael@0 | 46 | AKEY_EVENT_FLAG_TAINTED = 0x80000000, |
michael@0 | 47 | }; |
michael@0 | 48 | |
michael@0 | 49 | enum { |
michael@0 | 50 | /* Motion event is inconsistent with previously sent motion events. */ |
michael@0 | 51 | AMOTION_EVENT_FLAG_TAINTED = 0x80000000, |
michael@0 | 52 | }; |
michael@0 | 53 | |
michael@0 | 54 | enum { |
michael@0 | 55 | /* Used when a motion event is not associated with any display. |
michael@0 | 56 | * Typically used for non-pointer events. */ |
michael@0 | 57 | ADISPLAY_ID_NONE = -1, |
michael@0 | 58 | |
michael@0 | 59 | /* The default display id. */ |
michael@0 | 60 | ADISPLAY_ID_DEFAULT = 0, |
michael@0 | 61 | }; |
michael@0 | 62 | |
michael@0 | 63 | enum { |
michael@0 | 64 | /* |
michael@0 | 65 | * Indicates that an input device has switches. |
michael@0 | 66 | * This input source flag is hidden from the API because switches are only used by the system |
michael@0 | 67 | * and applications have no way to interact with them. |
michael@0 | 68 | */ |
michael@0 | 69 | AINPUT_SOURCE_SWITCH = 0x80000000, |
michael@0 | 70 | }; |
michael@0 | 71 | |
michael@0 | 72 | /* |
michael@0 | 73 | * SystemUiVisibility constants from View. |
michael@0 | 74 | */ |
michael@0 | 75 | enum { |
michael@0 | 76 | ASYSTEM_UI_VISIBILITY_STATUS_BAR_VISIBLE = 0, |
michael@0 | 77 | ASYSTEM_UI_VISIBILITY_STATUS_BAR_HIDDEN = 0x00000001, |
michael@0 | 78 | }; |
michael@0 | 79 | |
michael@0 | 80 | /* |
michael@0 | 81 | * Maximum number of pointers supported per motion event. |
michael@0 | 82 | * Smallest number of pointers is 1. |
michael@0 | 83 | * (We want at least 10 but some touch controllers obstensibly configured for 10 pointers |
michael@0 | 84 | * will occasionally emit 11. There is not much harm making this constant bigger.) |
michael@0 | 85 | */ |
michael@0 | 86 | #define MAX_POINTERS 16 |
michael@0 | 87 | |
michael@0 | 88 | /* |
michael@0 | 89 | * Maximum pointer id value supported in a motion event. |
michael@0 | 90 | * Smallest pointer id is 0. |
michael@0 | 91 | * (This is limited by our use of BitSet32 to track pointer assignments.) |
michael@0 | 92 | */ |
michael@0 | 93 | #define MAX_POINTER_ID 31 |
michael@0 | 94 | |
michael@0 | 95 | /* |
michael@0 | 96 | * Declare a concrete type for the NDK's input event forward declaration. |
michael@0 | 97 | */ |
michael@0 | 98 | struct AInputEvent { |
michael@0 | 99 | virtual ~AInputEvent() { } |
michael@0 | 100 | }; |
michael@0 | 101 | |
michael@0 | 102 | /* |
michael@0 | 103 | * Declare a concrete type for the NDK's input device forward declaration. |
michael@0 | 104 | */ |
michael@0 | 105 | struct AInputDevice { |
michael@0 | 106 | virtual ~AInputDevice() { } |
michael@0 | 107 | }; |
michael@0 | 108 | |
michael@0 | 109 | |
michael@0 | 110 | namespace android { |
michael@0 | 111 | |
michael@0 | 112 | #ifdef HAVE_ANDROID_OS |
michael@0 | 113 | class Parcel; |
michael@0 | 114 | #endif |
michael@0 | 115 | |
michael@0 | 116 | /* |
michael@0 | 117 | * Flags that flow alongside events in the input dispatch system to help with certain |
michael@0 | 118 | * policy decisions such as waking from device sleep. |
michael@0 | 119 | * |
michael@0 | 120 | * These flags are also defined in frameworks/base/core/java/android/view/WindowManagerPolicy.java. |
michael@0 | 121 | */ |
michael@0 | 122 | enum { |
michael@0 | 123 | /* These flags originate in RawEvents and are generally set in the key map. |
michael@0 | 124 | * NOTE: If you edit these flags, also edit labels in KeycodeLabels.h. */ |
michael@0 | 125 | |
michael@0 | 126 | POLICY_FLAG_WAKE = 0x00000001, |
michael@0 | 127 | POLICY_FLAG_WAKE_DROPPED = 0x00000002, |
michael@0 | 128 | POLICY_FLAG_SHIFT = 0x00000004, |
michael@0 | 129 | POLICY_FLAG_CAPS_LOCK = 0x00000008, |
michael@0 | 130 | POLICY_FLAG_ALT = 0x00000010, |
michael@0 | 131 | POLICY_FLAG_ALT_GR = 0x00000020, |
michael@0 | 132 | POLICY_FLAG_MENU = 0x00000040, |
michael@0 | 133 | POLICY_FLAG_LAUNCHER = 0x00000080, |
michael@0 | 134 | POLICY_FLAG_VIRTUAL = 0x00000100, |
michael@0 | 135 | POLICY_FLAG_FUNCTION = 0x00000200, |
michael@0 | 136 | |
michael@0 | 137 | POLICY_FLAG_RAW_MASK = 0x0000ffff, |
michael@0 | 138 | |
michael@0 | 139 | /* These flags are set by the input dispatcher. */ |
michael@0 | 140 | |
michael@0 | 141 | // Indicates that the input event was injected. |
michael@0 | 142 | POLICY_FLAG_INJECTED = 0x01000000, |
michael@0 | 143 | |
michael@0 | 144 | // Indicates that the input event is from a trusted source such as a directly attached |
michael@0 | 145 | // input device or an application with system-wide event injection permission. |
michael@0 | 146 | POLICY_FLAG_TRUSTED = 0x02000000, |
michael@0 | 147 | |
michael@0 | 148 | // Indicates that the input event has passed through an input filter. |
michael@0 | 149 | POLICY_FLAG_FILTERED = 0x04000000, |
michael@0 | 150 | |
michael@0 | 151 | // Disables automatic key repeating behavior. |
michael@0 | 152 | POLICY_FLAG_DISABLE_KEY_REPEAT = 0x08000000, |
michael@0 | 153 | |
michael@0 | 154 | /* These flags are set by the input reader policy as it intercepts each event. */ |
michael@0 | 155 | |
michael@0 | 156 | // Indicates that the screen was off when the event was received and the event |
michael@0 | 157 | // should wake the device. |
michael@0 | 158 | POLICY_FLAG_WOKE_HERE = 0x10000000, |
michael@0 | 159 | |
michael@0 | 160 | // Indicates that the screen was dim when the event was received and the event |
michael@0 | 161 | // should brighten the device. |
michael@0 | 162 | POLICY_FLAG_BRIGHT_HERE = 0x20000000, |
michael@0 | 163 | |
michael@0 | 164 | // Indicates that the event should be dispatched to applications. |
michael@0 | 165 | // The input event should still be sent to the InputDispatcher so that it can see all |
michael@0 | 166 | // input events received include those that it will not deliver. |
michael@0 | 167 | POLICY_FLAG_PASS_TO_USER = 0x40000000, |
michael@0 | 168 | }; |
michael@0 | 169 | |
michael@0 | 170 | /* |
michael@0 | 171 | * Pointer coordinate data. |
michael@0 | 172 | */ |
michael@0 | 173 | struct PointerCoords { |
michael@0 | 174 | enum { MAX_AXES = 14 }; // 14 so that sizeof(PointerCoords) == 64 |
michael@0 | 175 | |
michael@0 | 176 | // Bitfield of axes that are present in this structure. |
michael@0 | 177 | uint64_t bits; |
michael@0 | 178 | |
michael@0 | 179 | // Values of axes that are stored in this structure packed in order by axis id |
michael@0 | 180 | // for each axis that is present in the structure according to 'bits'. |
michael@0 | 181 | float values[MAX_AXES]; |
michael@0 | 182 | |
michael@0 | 183 | inline void clear() { |
michael@0 | 184 | bits = 0; |
michael@0 | 185 | } |
michael@0 | 186 | |
michael@0 | 187 | float getAxisValue(int32_t axis) const; |
michael@0 | 188 | status_t setAxisValue(int32_t axis, float value); |
michael@0 | 189 | |
michael@0 | 190 | void scale(float scale); |
michael@0 | 191 | |
michael@0 | 192 | inline float getX() const { |
michael@0 | 193 | return getAxisValue(AMOTION_EVENT_AXIS_X); |
michael@0 | 194 | } |
michael@0 | 195 | |
michael@0 | 196 | inline float getY() const { |
michael@0 | 197 | return getAxisValue(AMOTION_EVENT_AXIS_Y); |
michael@0 | 198 | } |
michael@0 | 199 | |
michael@0 | 200 | #ifdef HAVE_ANDROID_OS |
michael@0 | 201 | status_t readFromParcel(Parcel* parcel); |
michael@0 | 202 | status_t writeToParcel(Parcel* parcel) const; |
michael@0 | 203 | #endif |
michael@0 | 204 | |
michael@0 | 205 | bool operator==(const PointerCoords& other) const; |
michael@0 | 206 | inline bool operator!=(const PointerCoords& other) const { |
michael@0 | 207 | return !(*this == other); |
michael@0 | 208 | } |
michael@0 | 209 | |
michael@0 | 210 | void copyFrom(const PointerCoords& other); |
michael@0 | 211 | |
michael@0 | 212 | private: |
michael@0 | 213 | void tooManyAxes(int axis); |
michael@0 | 214 | }; |
michael@0 | 215 | |
michael@0 | 216 | /* |
michael@0 | 217 | * Pointer property data. |
michael@0 | 218 | */ |
michael@0 | 219 | struct PointerProperties { |
michael@0 | 220 | // The id of the pointer. |
michael@0 | 221 | int32_t id; |
michael@0 | 222 | |
michael@0 | 223 | // The pointer tool type. |
michael@0 | 224 | int32_t toolType; |
michael@0 | 225 | |
michael@0 | 226 | inline void clear() { |
michael@0 | 227 | id = -1; |
michael@0 | 228 | toolType = 0; |
michael@0 | 229 | } |
michael@0 | 230 | |
michael@0 | 231 | bool operator==(const PointerProperties& other) const; |
michael@0 | 232 | inline bool operator!=(const PointerProperties& other) const { |
michael@0 | 233 | return !(*this == other); |
michael@0 | 234 | } |
michael@0 | 235 | |
michael@0 | 236 | void copyFrom(const PointerProperties& other); |
michael@0 | 237 | }; |
michael@0 | 238 | |
michael@0 | 239 | /* |
michael@0 | 240 | * Input events. |
michael@0 | 241 | */ |
michael@0 | 242 | class InputEvent : public AInputEvent { |
michael@0 | 243 | public: |
michael@0 | 244 | virtual ~InputEvent() { } |
michael@0 | 245 | |
michael@0 | 246 | virtual int32_t getType() const = 0; |
michael@0 | 247 | |
michael@0 | 248 | inline int32_t getDeviceId() const { return mDeviceId; } |
michael@0 | 249 | |
michael@0 | 250 | inline int32_t getSource() const { return mSource; } |
michael@0 | 251 | |
michael@0 | 252 | inline void setSource(int32_t source) { mSource = source; } |
michael@0 | 253 | |
michael@0 | 254 | protected: |
michael@0 | 255 | void initialize(int32_t deviceId, int32_t source); |
michael@0 | 256 | void initialize(const InputEvent& from); |
michael@0 | 257 | |
michael@0 | 258 | int32_t mDeviceId; |
michael@0 | 259 | int32_t mSource; |
michael@0 | 260 | }; |
michael@0 | 261 | |
michael@0 | 262 | /* |
michael@0 | 263 | * Key events. |
michael@0 | 264 | */ |
michael@0 | 265 | class KeyEvent : public InputEvent { |
michael@0 | 266 | public: |
michael@0 | 267 | virtual ~KeyEvent() { } |
michael@0 | 268 | |
michael@0 | 269 | virtual int32_t getType() const { return AINPUT_EVENT_TYPE_KEY; } |
michael@0 | 270 | |
michael@0 | 271 | inline int32_t getAction() const { return mAction; } |
michael@0 | 272 | |
michael@0 | 273 | inline int32_t getFlags() const { return mFlags; } |
michael@0 | 274 | |
michael@0 | 275 | inline void setFlags(int32_t flags) { mFlags = flags; } |
michael@0 | 276 | |
michael@0 | 277 | inline int32_t getKeyCode() const { return mKeyCode; } |
michael@0 | 278 | |
michael@0 | 279 | inline int32_t getScanCode() const { return mScanCode; } |
michael@0 | 280 | |
michael@0 | 281 | inline int32_t getMetaState() const { return mMetaState; } |
michael@0 | 282 | |
michael@0 | 283 | inline int32_t getRepeatCount() const { return mRepeatCount; } |
michael@0 | 284 | |
michael@0 | 285 | inline nsecs_t getDownTime() const { return mDownTime; } |
michael@0 | 286 | |
michael@0 | 287 | inline nsecs_t getEventTime() const { return mEventTime; } |
michael@0 | 288 | |
michael@0 | 289 | // Return true if this event may have a default action implementation. |
michael@0 | 290 | static bool hasDefaultAction(int32_t keyCode); |
michael@0 | 291 | bool hasDefaultAction() const; |
michael@0 | 292 | |
michael@0 | 293 | // Return true if this event represents a system key. |
michael@0 | 294 | static bool isSystemKey(int32_t keyCode); |
michael@0 | 295 | bool isSystemKey() const; |
michael@0 | 296 | |
michael@0 | 297 | void initialize( |
michael@0 | 298 | int32_t deviceId, |
michael@0 | 299 | int32_t source, |
michael@0 | 300 | int32_t action, |
michael@0 | 301 | int32_t flags, |
michael@0 | 302 | int32_t keyCode, |
michael@0 | 303 | int32_t scanCode, |
michael@0 | 304 | int32_t metaState, |
michael@0 | 305 | int32_t repeatCount, |
michael@0 | 306 | nsecs_t downTime, |
michael@0 | 307 | nsecs_t eventTime); |
michael@0 | 308 | void initialize(const KeyEvent& from); |
michael@0 | 309 | |
michael@0 | 310 | protected: |
michael@0 | 311 | int32_t mAction; |
michael@0 | 312 | int32_t mFlags; |
michael@0 | 313 | int32_t mKeyCode; |
michael@0 | 314 | int32_t mScanCode; |
michael@0 | 315 | int32_t mMetaState; |
michael@0 | 316 | int32_t mRepeatCount; |
michael@0 | 317 | nsecs_t mDownTime; |
michael@0 | 318 | nsecs_t mEventTime; |
michael@0 | 319 | }; |
michael@0 | 320 | |
michael@0 | 321 | /* |
michael@0 | 322 | * Motion events. |
michael@0 | 323 | */ |
michael@0 | 324 | class MotionEvent : public InputEvent { |
michael@0 | 325 | public: |
michael@0 | 326 | virtual ~MotionEvent() { } |
michael@0 | 327 | |
michael@0 | 328 | virtual int32_t getType() const { return AINPUT_EVENT_TYPE_MOTION; } |
michael@0 | 329 | |
michael@0 | 330 | inline int32_t getAction() const { return mAction; } |
michael@0 | 331 | |
michael@0 | 332 | inline int32_t getActionMasked() const { return mAction & AMOTION_EVENT_ACTION_MASK; } |
michael@0 | 333 | |
michael@0 | 334 | inline int32_t getActionIndex() const { |
michael@0 | 335 | return (mAction & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) |
michael@0 | 336 | >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; |
michael@0 | 337 | } |
michael@0 | 338 | |
michael@0 | 339 | inline void setAction(int32_t action) { mAction = action; } |
michael@0 | 340 | |
michael@0 | 341 | inline int32_t getFlags() const { return mFlags; } |
michael@0 | 342 | |
michael@0 | 343 | inline void setFlags(int32_t flags) { mFlags = flags; } |
michael@0 | 344 | |
michael@0 | 345 | inline int32_t getEdgeFlags() const { return mEdgeFlags; } |
michael@0 | 346 | |
michael@0 | 347 | inline void setEdgeFlags(int32_t edgeFlags) { mEdgeFlags = edgeFlags; } |
michael@0 | 348 | |
michael@0 | 349 | inline int32_t getMetaState() const { return mMetaState; } |
michael@0 | 350 | |
michael@0 | 351 | inline void setMetaState(int32_t metaState) { mMetaState = metaState; } |
michael@0 | 352 | |
michael@0 | 353 | inline int32_t getButtonState() const { return mButtonState; } |
michael@0 | 354 | |
michael@0 | 355 | inline float getXOffset() const { return mXOffset; } |
michael@0 | 356 | |
michael@0 | 357 | inline float getYOffset() const { return mYOffset; } |
michael@0 | 358 | |
michael@0 | 359 | inline float getXPrecision() const { return mXPrecision; } |
michael@0 | 360 | |
michael@0 | 361 | inline float getYPrecision() const { return mYPrecision; } |
michael@0 | 362 | |
michael@0 | 363 | inline nsecs_t getDownTime() const { return mDownTime; } |
michael@0 | 364 | |
michael@0 | 365 | inline void setDownTime(nsecs_t downTime) { mDownTime = downTime; } |
michael@0 | 366 | |
michael@0 | 367 | inline size_t getPointerCount() const { return mPointerProperties.size(); } |
michael@0 | 368 | |
michael@0 | 369 | inline const PointerProperties* getPointerProperties(size_t pointerIndex) const { |
michael@0 | 370 | return &mPointerProperties[pointerIndex]; |
michael@0 | 371 | } |
michael@0 | 372 | |
michael@0 | 373 | inline int32_t getPointerId(size_t pointerIndex) const { |
michael@0 | 374 | return mPointerProperties[pointerIndex].id; |
michael@0 | 375 | } |
michael@0 | 376 | |
michael@0 | 377 | inline int32_t getToolType(size_t pointerIndex) const { |
michael@0 | 378 | return mPointerProperties[pointerIndex].toolType; |
michael@0 | 379 | } |
michael@0 | 380 | |
michael@0 | 381 | inline nsecs_t getEventTime() const { return mSampleEventTimes[getHistorySize()]; } |
michael@0 | 382 | |
michael@0 | 383 | const PointerCoords* getRawPointerCoords(size_t pointerIndex) const; |
michael@0 | 384 | |
michael@0 | 385 | float getRawAxisValue(int32_t axis, size_t pointerIndex) const; |
michael@0 | 386 | |
michael@0 | 387 | inline float getRawX(size_t pointerIndex) const { |
michael@0 | 388 | return getRawAxisValue(AMOTION_EVENT_AXIS_X, pointerIndex); |
michael@0 | 389 | } |
michael@0 | 390 | |
michael@0 | 391 | inline float getRawY(size_t pointerIndex) const { |
michael@0 | 392 | return getRawAxisValue(AMOTION_EVENT_AXIS_Y, pointerIndex); |
michael@0 | 393 | } |
michael@0 | 394 | |
michael@0 | 395 | float getAxisValue(int32_t axis, size_t pointerIndex) const; |
michael@0 | 396 | |
michael@0 | 397 | inline float getX(size_t pointerIndex) const { |
michael@0 | 398 | return getAxisValue(AMOTION_EVENT_AXIS_X, pointerIndex); |
michael@0 | 399 | } |
michael@0 | 400 | |
michael@0 | 401 | inline float getY(size_t pointerIndex) const { |
michael@0 | 402 | return getAxisValue(AMOTION_EVENT_AXIS_Y, pointerIndex); |
michael@0 | 403 | } |
michael@0 | 404 | |
michael@0 | 405 | inline float getPressure(size_t pointerIndex) const { |
michael@0 | 406 | return getAxisValue(AMOTION_EVENT_AXIS_PRESSURE, pointerIndex); |
michael@0 | 407 | } |
michael@0 | 408 | |
michael@0 | 409 | inline float getSize(size_t pointerIndex) const { |
michael@0 | 410 | return getAxisValue(AMOTION_EVENT_AXIS_SIZE, pointerIndex); |
michael@0 | 411 | } |
michael@0 | 412 | |
michael@0 | 413 | inline float getTouchMajor(size_t pointerIndex) const { |
michael@0 | 414 | return getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, pointerIndex); |
michael@0 | 415 | } |
michael@0 | 416 | |
michael@0 | 417 | inline float getTouchMinor(size_t pointerIndex) const { |
michael@0 | 418 | return getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, pointerIndex); |
michael@0 | 419 | } |
michael@0 | 420 | |
michael@0 | 421 | inline float getToolMajor(size_t pointerIndex) const { |
michael@0 | 422 | return getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, pointerIndex); |
michael@0 | 423 | } |
michael@0 | 424 | |
michael@0 | 425 | inline float getToolMinor(size_t pointerIndex) const { |
michael@0 | 426 | return getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR, pointerIndex); |
michael@0 | 427 | } |
michael@0 | 428 | |
michael@0 | 429 | inline float getOrientation(size_t pointerIndex) const { |
michael@0 | 430 | return getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, pointerIndex); |
michael@0 | 431 | } |
michael@0 | 432 | |
michael@0 | 433 | inline size_t getHistorySize() const { return mSampleEventTimes.size() - 1; } |
michael@0 | 434 | |
michael@0 | 435 | inline nsecs_t getHistoricalEventTime(size_t historicalIndex) const { |
michael@0 | 436 | return mSampleEventTimes[historicalIndex]; |
michael@0 | 437 | } |
michael@0 | 438 | |
michael@0 | 439 | const PointerCoords* getHistoricalRawPointerCoords( |
michael@0 | 440 | size_t pointerIndex, size_t historicalIndex) const; |
michael@0 | 441 | |
michael@0 | 442 | float getHistoricalRawAxisValue(int32_t axis, size_t pointerIndex, |
michael@0 | 443 | size_t historicalIndex) const; |
michael@0 | 444 | |
michael@0 | 445 | inline float getHistoricalRawX(size_t pointerIndex, size_t historicalIndex) const { |
michael@0 | 446 | return getHistoricalRawAxisValue( |
michael@0 | 447 | AMOTION_EVENT_AXIS_X, pointerIndex, historicalIndex); |
michael@0 | 448 | } |
michael@0 | 449 | |
michael@0 | 450 | inline float getHistoricalRawY(size_t pointerIndex, size_t historicalIndex) const { |
michael@0 | 451 | return getHistoricalRawAxisValue( |
michael@0 | 452 | AMOTION_EVENT_AXIS_Y, pointerIndex, historicalIndex); |
michael@0 | 453 | } |
michael@0 | 454 | |
michael@0 | 455 | float getHistoricalAxisValue(int32_t axis, size_t pointerIndex, size_t historicalIndex) const; |
michael@0 | 456 | |
michael@0 | 457 | inline float getHistoricalX(size_t pointerIndex, size_t historicalIndex) const { |
michael@0 | 458 | return getHistoricalAxisValue( |
michael@0 | 459 | AMOTION_EVENT_AXIS_X, pointerIndex, historicalIndex); |
michael@0 | 460 | } |
michael@0 | 461 | |
michael@0 | 462 | inline float getHistoricalY(size_t pointerIndex, size_t historicalIndex) const { |
michael@0 | 463 | return getHistoricalAxisValue( |
michael@0 | 464 | AMOTION_EVENT_AXIS_Y, pointerIndex, historicalIndex); |
michael@0 | 465 | } |
michael@0 | 466 | |
michael@0 | 467 | inline float getHistoricalPressure(size_t pointerIndex, size_t historicalIndex) const { |
michael@0 | 468 | return getHistoricalAxisValue( |
michael@0 | 469 | AMOTION_EVENT_AXIS_PRESSURE, pointerIndex, historicalIndex); |
michael@0 | 470 | } |
michael@0 | 471 | |
michael@0 | 472 | inline float getHistoricalSize(size_t pointerIndex, size_t historicalIndex) const { |
michael@0 | 473 | return getHistoricalAxisValue( |
michael@0 | 474 | AMOTION_EVENT_AXIS_SIZE, pointerIndex, historicalIndex); |
michael@0 | 475 | } |
michael@0 | 476 | |
michael@0 | 477 | inline float getHistoricalTouchMajor(size_t pointerIndex, size_t historicalIndex) const { |
michael@0 | 478 | return getHistoricalAxisValue( |
michael@0 | 479 | AMOTION_EVENT_AXIS_TOUCH_MAJOR, pointerIndex, historicalIndex); |
michael@0 | 480 | } |
michael@0 | 481 | |
michael@0 | 482 | inline float getHistoricalTouchMinor(size_t pointerIndex, size_t historicalIndex) const { |
michael@0 | 483 | return getHistoricalAxisValue( |
michael@0 | 484 | AMOTION_EVENT_AXIS_TOUCH_MINOR, pointerIndex, historicalIndex); |
michael@0 | 485 | } |
michael@0 | 486 | |
michael@0 | 487 | inline float getHistoricalToolMajor(size_t pointerIndex, size_t historicalIndex) const { |
michael@0 | 488 | return getHistoricalAxisValue( |
michael@0 | 489 | AMOTION_EVENT_AXIS_TOOL_MAJOR, pointerIndex, historicalIndex); |
michael@0 | 490 | } |
michael@0 | 491 | |
michael@0 | 492 | inline float getHistoricalToolMinor(size_t pointerIndex, size_t historicalIndex) const { |
michael@0 | 493 | return getHistoricalAxisValue( |
michael@0 | 494 | AMOTION_EVENT_AXIS_TOOL_MINOR, pointerIndex, historicalIndex); |
michael@0 | 495 | } |
michael@0 | 496 | |
michael@0 | 497 | inline float getHistoricalOrientation(size_t pointerIndex, size_t historicalIndex) const { |
michael@0 | 498 | return getHistoricalAxisValue( |
michael@0 | 499 | AMOTION_EVENT_AXIS_ORIENTATION, pointerIndex, historicalIndex); |
michael@0 | 500 | } |
michael@0 | 501 | |
michael@0 | 502 | ssize_t findPointerIndex(int32_t pointerId) const; |
michael@0 | 503 | |
michael@0 | 504 | void initialize( |
michael@0 | 505 | int32_t deviceId, |
michael@0 | 506 | int32_t source, |
michael@0 | 507 | int32_t action, |
michael@0 | 508 | int32_t flags, |
michael@0 | 509 | int32_t edgeFlags, |
michael@0 | 510 | int32_t metaState, |
michael@0 | 511 | int32_t buttonState, |
michael@0 | 512 | float xOffset, |
michael@0 | 513 | float yOffset, |
michael@0 | 514 | float xPrecision, |
michael@0 | 515 | float yPrecision, |
michael@0 | 516 | nsecs_t downTime, |
michael@0 | 517 | nsecs_t eventTime, |
michael@0 | 518 | size_t pointerCount, |
michael@0 | 519 | const PointerProperties* pointerProperties, |
michael@0 | 520 | const PointerCoords* pointerCoords); |
michael@0 | 521 | |
michael@0 | 522 | void copyFrom(const MotionEvent* other, bool keepHistory); |
michael@0 | 523 | |
michael@0 | 524 | void addSample( |
michael@0 | 525 | nsecs_t eventTime, |
michael@0 | 526 | const PointerCoords* pointerCoords); |
michael@0 | 527 | |
michael@0 | 528 | void offsetLocation(float xOffset, float yOffset); |
michael@0 | 529 | |
michael@0 | 530 | void scale(float scaleFactor); |
michael@0 | 531 | |
michael@0 | 532 | #ifdef HAVE_ANDROID_OS |
michael@0 | 533 | void transform(const SkMatrix* matrix); |
michael@0 | 534 | |
michael@0 | 535 | status_t readFromParcel(Parcel* parcel); |
michael@0 | 536 | status_t writeToParcel(Parcel* parcel) const; |
michael@0 | 537 | #endif |
michael@0 | 538 | |
michael@0 | 539 | static bool isTouchEvent(int32_t source, int32_t action); |
michael@0 | 540 | inline bool isTouchEvent() const { |
michael@0 | 541 | return isTouchEvent(mSource, mAction); |
michael@0 | 542 | } |
michael@0 | 543 | |
michael@0 | 544 | // Low-level accessors. |
michael@0 | 545 | inline const PointerProperties* getPointerProperties() const { |
michael@0 | 546 | return mPointerProperties.array(); |
michael@0 | 547 | } |
michael@0 | 548 | inline const nsecs_t* getSampleEventTimes() const { return mSampleEventTimes.array(); } |
michael@0 | 549 | inline const PointerCoords* getSamplePointerCoords() const { |
michael@0 | 550 | return mSamplePointerCoords.array(); |
michael@0 | 551 | } |
michael@0 | 552 | |
michael@0 | 553 | protected: |
michael@0 | 554 | int32_t mAction; |
michael@0 | 555 | int32_t mFlags; |
michael@0 | 556 | int32_t mEdgeFlags; |
michael@0 | 557 | int32_t mMetaState; |
michael@0 | 558 | int32_t mButtonState; |
michael@0 | 559 | float mXOffset; |
michael@0 | 560 | float mYOffset; |
michael@0 | 561 | float mXPrecision; |
michael@0 | 562 | float mYPrecision; |
michael@0 | 563 | nsecs_t mDownTime; |
michael@0 | 564 | Vector<PointerProperties> mPointerProperties; |
michael@0 | 565 | Vector<nsecs_t> mSampleEventTimes; |
michael@0 | 566 | Vector<PointerCoords> mSamplePointerCoords; |
michael@0 | 567 | }; |
michael@0 | 568 | |
michael@0 | 569 | /* |
michael@0 | 570 | * Input event factory. |
michael@0 | 571 | */ |
michael@0 | 572 | class InputEventFactoryInterface { |
michael@0 | 573 | protected: |
michael@0 | 574 | virtual ~InputEventFactoryInterface() { } |
michael@0 | 575 | |
michael@0 | 576 | public: |
michael@0 | 577 | InputEventFactoryInterface() { } |
michael@0 | 578 | |
michael@0 | 579 | virtual KeyEvent* createKeyEvent() = 0; |
michael@0 | 580 | virtual MotionEvent* createMotionEvent() = 0; |
michael@0 | 581 | }; |
michael@0 | 582 | |
michael@0 | 583 | /* |
michael@0 | 584 | * A simple input event factory implementation that uses a single preallocated instance |
michael@0 | 585 | * of each type of input event that are reused for each request. |
michael@0 | 586 | */ |
michael@0 | 587 | class PreallocatedInputEventFactory : public InputEventFactoryInterface { |
michael@0 | 588 | public: |
michael@0 | 589 | PreallocatedInputEventFactory() { } |
michael@0 | 590 | virtual ~PreallocatedInputEventFactory() { } |
michael@0 | 591 | |
michael@0 | 592 | virtual KeyEvent* createKeyEvent() { return & mKeyEvent; } |
michael@0 | 593 | virtual MotionEvent* createMotionEvent() { return & mMotionEvent; } |
michael@0 | 594 | |
michael@0 | 595 | private: |
michael@0 | 596 | KeyEvent mKeyEvent; |
michael@0 | 597 | MotionEvent mMotionEvent; |
michael@0 | 598 | }; |
michael@0 | 599 | |
michael@0 | 600 | /* |
michael@0 | 601 | * An input event factory implementation that maintains a pool of input events. |
michael@0 | 602 | */ |
michael@0 | 603 | class PooledInputEventFactory : public InputEventFactoryInterface { |
michael@0 | 604 | public: |
michael@0 | 605 | PooledInputEventFactory(size_t maxPoolSize = 20); |
michael@0 | 606 | virtual ~PooledInputEventFactory(); |
michael@0 | 607 | |
michael@0 | 608 | virtual KeyEvent* createKeyEvent(); |
michael@0 | 609 | virtual MotionEvent* createMotionEvent(); |
michael@0 | 610 | |
michael@0 | 611 | void recycle(InputEvent* event); |
michael@0 | 612 | |
michael@0 | 613 | private: |
michael@0 | 614 | const size_t mMaxPoolSize; |
michael@0 | 615 | |
michael@0 | 616 | Vector<KeyEvent*> mKeyEventPool; |
michael@0 | 617 | Vector<MotionEvent*> mMotionEventPool; |
michael@0 | 618 | }; |
michael@0 | 619 | |
michael@0 | 620 | } // namespace android |
michael@0 | 621 | |
michael@0 | 622 | #endif // _ANDROIDFW_INPUT_H |