Loading include/input/Input.h +8 −6 Original line number Diff line number Diff line Loading @@ -469,14 +469,16 @@ public: inline float getYPrecision() const { return mYPrecision; } inline float getRawXCursorPosition() const { return mXCursorPosition; } inline float getRawXCursorPosition() const { return mRawXCursorPosition; } float getXCursorPosition() const; inline float getRawYCursorPosition() const { return mYCursorPosition; } inline float getRawYCursorPosition() const { return mRawYCursorPosition; } float getYCursorPosition() const; void setCursorPosition(float x, float y); static inline bool isValidCursorPosition(float x, float y) { return !isnan(x) && !isnan(y); } inline nsecs_t getDownTime() const { return mDownTime; } Loading Loading @@ -623,8 +625,8 @@ public: void initialize(int32_t deviceId, int32_t source, int32_t displayId, int32_t action, int32_t actionButton, int32_t flags, int32_t edgeFlags, int32_t metaState, int32_t buttonState, MotionClassification classification, float xOffset, float yOffset, float xPrecision, float yPrecision, float mXCursorPosition, float mYCursorPosition, nsecs_t downTime, nsecs_t eventTime, float yOffset, float xPrecision, float yPrecision, float rawXCursorPosition, float rawYCursorPosition, nsecs_t downTime, nsecs_t eventTime, size_t pointerCount, const PointerProperties* pointerProperties, const PointerCoords* pointerCoords); Loading Loading @@ -676,8 +678,8 @@ protected: float mYOffset; float mXPrecision; float mYPrecision; float mXCursorPosition; float mYCursorPosition; float mRawXCursorPosition; float mRawYCursorPosition; nsecs_t mDownTime; Vector<PointerProperties> mPointerProperties; Vector<nsecs_t> mSampleEventTimes; Loading libs/input/Input.cpp +20 −15 Original line number Diff line number Diff line Loading @@ -238,8 +238,8 @@ void MotionEvent::initialize(int32_t deviceId, int32_t source, int32_t displayId int32_t actionButton, int32_t flags, int32_t edgeFlags, int32_t metaState, int32_t buttonState, MotionClassification classification, float xOffset, float yOffset, float xPrecision, float yPrecision, float xCursorPosition, float yCursorPosition, nsecs_t downTime, nsecs_t eventTime, float xPrecision, float yPrecision, float rawXCursorPosition, float rawYCursorPosition, nsecs_t downTime, nsecs_t eventTime, size_t pointerCount, const PointerProperties* pointerProperties, const PointerCoords* pointerCoords) { InputEvent::initialize(deviceId, source, displayId); Loading @@ -254,8 +254,8 @@ void MotionEvent::initialize(int32_t deviceId, int32_t source, int32_t displayId mYOffset = yOffset; mXPrecision = xPrecision; mYPrecision = yPrecision; mXCursorPosition = xCursorPosition; mYCursorPosition = yCursorPosition; mRawXCursorPosition = rawXCursorPosition; mRawYCursorPosition = rawYCursorPosition; mDownTime = downTime; mPointerProperties.clear(); mPointerProperties.appendArray(pointerProperties, pointerCount); Loading @@ -277,8 +277,8 @@ void MotionEvent::copyFrom(const MotionEvent* other, bool keepHistory) { mYOffset = other->mYOffset; mXPrecision = other->mXPrecision; mYPrecision = other->mYPrecision; mXCursorPosition = other->mXCursorPosition; mYCursorPosition = other->mYCursorPosition; mRawXCursorPosition = other->mRawXCursorPosition; mRawYCursorPosition = other->mRawYCursorPosition; mDownTime = other->mDownTime; mPointerProperties = other->mPointerProperties; Loading Loading @@ -313,6 +313,11 @@ float MotionEvent::getYCursorPosition() const { return rawY + mYOffset; } void MotionEvent::setCursorPosition(float x, float y) { mRawXCursorPosition = x - mXOffset; mRawYCursorPosition = y - mYOffset; } const PointerCoords* MotionEvent::getRawPointerCoords(size_t pointerIndex) const { return &mSamplePointerCoords[getHistorySize() * getPointerCount() + pointerIndex]; } Loading Loading @@ -433,12 +438,12 @@ void MotionEvent::transform(const float matrix[9]) { transformPoint(matrix, 0, 0, &originX, &originY); // Apply the transformation to cursor position. if (isValidCursorPosition(mXCursorPosition, mYCursorPosition)) { float x = mXCursorPosition + oldXOffset; float y = mYCursorPosition + oldYOffset; if (isValidCursorPosition(mRawXCursorPosition, mRawYCursorPosition)) { float x = mRawXCursorPosition + oldXOffset; float y = mRawYCursorPosition + oldYOffset; transformPoint(matrix, x, y, &x, &y); mXCursorPosition = x - mXOffset; mYCursorPosition = y - mYOffset; mRawXCursorPosition = x - mXOffset; mRawYCursorPosition = y - mYOffset; } // Apply the transformation to all samples. Loading Loading @@ -480,8 +485,8 @@ status_t MotionEvent::readFromParcel(Parcel* parcel) { mYOffset = parcel->readFloat(); mXPrecision = parcel->readFloat(); mYPrecision = parcel->readFloat(); mXCursorPosition = parcel->readFloat(); mYCursorPosition = parcel->readFloat(); mRawXCursorPosition = parcel->readFloat(); mRawYCursorPosition = parcel->readFloat(); mDownTime = parcel->readInt64(); mPointerProperties.clear(); Loading Loading @@ -533,8 +538,8 @@ status_t MotionEvent::writeToParcel(Parcel* parcel) const { parcel->writeFloat(mYOffset); parcel->writeFloat(mXPrecision); parcel->writeFloat(mYPrecision); parcel->writeFloat(mXCursorPosition); parcel->writeFloat(mYCursorPosition); parcel->writeFloat(mRawXCursorPosition); parcel->writeFloat(mRawYCursorPosition); parcel->writeInt64(mDownTime); for (size_t i = 0; i < pointerCount; i++) { Loading libs/input/tests/InputEvent_test.cpp +10 −0 Original line number Diff line number Diff line Loading @@ -665,4 +665,14 @@ TEST_F(MotionEventTest, Initialize_SetsCursorPosition) { ASSERT_EQ(600, event.getYCursorPosition()); } TEST_F(MotionEventTest, SetCursorPosition) { MotionEvent event; initializeEventWithHistory(&event); event.setSource(AINPUT_SOURCE_MOUSE); event.setCursorPosition(3, 4); ASSERT_EQ(3, event.getXCursorPosition()); ASSERT_EQ(4, event.getYCursorPosition()); } } // namespace android Loading
include/input/Input.h +8 −6 Original line number Diff line number Diff line Loading @@ -469,14 +469,16 @@ public: inline float getYPrecision() const { return mYPrecision; } inline float getRawXCursorPosition() const { return mXCursorPosition; } inline float getRawXCursorPosition() const { return mRawXCursorPosition; } float getXCursorPosition() const; inline float getRawYCursorPosition() const { return mYCursorPosition; } inline float getRawYCursorPosition() const { return mRawYCursorPosition; } float getYCursorPosition() const; void setCursorPosition(float x, float y); static inline bool isValidCursorPosition(float x, float y) { return !isnan(x) && !isnan(y); } inline nsecs_t getDownTime() const { return mDownTime; } Loading Loading @@ -623,8 +625,8 @@ public: void initialize(int32_t deviceId, int32_t source, int32_t displayId, int32_t action, int32_t actionButton, int32_t flags, int32_t edgeFlags, int32_t metaState, int32_t buttonState, MotionClassification classification, float xOffset, float yOffset, float xPrecision, float yPrecision, float mXCursorPosition, float mYCursorPosition, nsecs_t downTime, nsecs_t eventTime, float yOffset, float xPrecision, float yPrecision, float rawXCursorPosition, float rawYCursorPosition, nsecs_t downTime, nsecs_t eventTime, size_t pointerCount, const PointerProperties* pointerProperties, const PointerCoords* pointerCoords); Loading Loading @@ -676,8 +678,8 @@ protected: float mYOffset; float mXPrecision; float mYPrecision; float mXCursorPosition; float mYCursorPosition; float mRawXCursorPosition; float mRawYCursorPosition; nsecs_t mDownTime; Vector<PointerProperties> mPointerProperties; Vector<nsecs_t> mSampleEventTimes; Loading
libs/input/Input.cpp +20 −15 Original line number Diff line number Diff line Loading @@ -238,8 +238,8 @@ void MotionEvent::initialize(int32_t deviceId, int32_t source, int32_t displayId int32_t actionButton, int32_t flags, int32_t edgeFlags, int32_t metaState, int32_t buttonState, MotionClassification classification, float xOffset, float yOffset, float xPrecision, float yPrecision, float xCursorPosition, float yCursorPosition, nsecs_t downTime, nsecs_t eventTime, float xPrecision, float yPrecision, float rawXCursorPosition, float rawYCursorPosition, nsecs_t downTime, nsecs_t eventTime, size_t pointerCount, const PointerProperties* pointerProperties, const PointerCoords* pointerCoords) { InputEvent::initialize(deviceId, source, displayId); Loading @@ -254,8 +254,8 @@ void MotionEvent::initialize(int32_t deviceId, int32_t source, int32_t displayId mYOffset = yOffset; mXPrecision = xPrecision; mYPrecision = yPrecision; mXCursorPosition = xCursorPosition; mYCursorPosition = yCursorPosition; mRawXCursorPosition = rawXCursorPosition; mRawYCursorPosition = rawYCursorPosition; mDownTime = downTime; mPointerProperties.clear(); mPointerProperties.appendArray(pointerProperties, pointerCount); Loading @@ -277,8 +277,8 @@ void MotionEvent::copyFrom(const MotionEvent* other, bool keepHistory) { mYOffset = other->mYOffset; mXPrecision = other->mXPrecision; mYPrecision = other->mYPrecision; mXCursorPosition = other->mXCursorPosition; mYCursorPosition = other->mYCursorPosition; mRawXCursorPosition = other->mRawXCursorPosition; mRawYCursorPosition = other->mRawYCursorPosition; mDownTime = other->mDownTime; mPointerProperties = other->mPointerProperties; Loading Loading @@ -313,6 +313,11 @@ float MotionEvent::getYCursorPosition() const { return rawY + mYOffset; } void MotionEvent::setCursorPosition(float x, float y) { mRawXCursorPosition = x - mXOffset; mRawYCursorPosition = y - mYOffset; } const PointerCoords* MotionEvent::getRawPointerCoords(size_t pointerIndex) const { return &mSamplePointerCoords[getHistorySize() * getPointerCount() + pointerIndex]; } Loading Loading @@ -433,12 +438,12 @@ void MotionEvent::transform(const float matrix[9]) { transformPoint(matrix, 0, 0, &originX, &originY); // Apply the transformation to cursor position. if (isValidCursorPosition(mXCursorPosition, mYCursorPosition)) { float x = mXCursorPosition + oldXOffset; float y = mYCursorPosition + oldYOffset; if (isValidCursorPosition(mRawXCursorPosition, mRawYCursorPosition)) { float x = mRawXCursorPosition + oldXOffset; float y = mRawYCursorPosition + oldYOffset; transformPoint(matrix, x, y, &x, &y); mXCursorPosition = x - mXOffset; mYCursorPosition = y - mYOffset; mRawXCursorPosition = x - mXOffset; mRawYCursorPosition = y - mYOffset; } // Apply the transformation to all samples. Loading Loading @@ -480,8 +485,8 @@ status_t MotionEvent::readFromParcel(Parcel* parcel) { mYOffset = parcel->readFloat(); mXPrecision = parcel->readFloat(); mYPrecision = parcel->readFloat(); mXCursorPosition = parcel->readFloat(); mYCursorPosition = parcel->readFloat(); mRawXCursorPosition = parcel->readFloat(); mRawYCursorPosition = parcel->readFloat(); mDownTime = parcel->readInt64(); mPointerProperties.clear(); Loading Loading @@ -533,8 +538,8 @@ status_t MotionEvent::writeToParcel(Parcel* parcel) const { parcel->writeFloat(mYOffset); parcel->writeFloat(mXPrecision); parcel->writeFloat(mYPrecision); parcel->writeFloat(mXCursorPosition); parcel->writeFloat(mYCursorPosition); parcel->writeFloat(mRawXCursorPosition); parcel->writeFloat(mRawYCursorPosition); parcel->writeInt64(mDownTime); for (size_t i = 0; i < pointerCount; i++) { Loading
libs/input/tests/InputEvent_test.cpp +10 −0 Original line number Diff line number Diff line Loading @@ -665,4 +665,14 @@ TEST_F(MotionEventTest, Initialize_SetsCursorPosition) { ASSERT_EQ(600, event.getYCursorPosition()); } TEST_F(MotionEventTest, SetCursorPosition) { MotionEvent event; initializeEventWithHistory(&event); event.setSource(AINPUT_SOURCE_MOUSE); event.setCursorPosition(3, 4); ASSERT_EQ(3, event.getXCursorPosition()); ASSERT_EQ(4, event.getYCursorPosition()); } } // namespace android