Bug 1117712 - Refactor some code to transform input events. r=botond

This commit is contained in:
Kartikaya Gupta 2015-01-09 13:39:08 -05:00
parent ebbb7a3a7d
commit a57c0aa1f1
3 changed files with 54 additions and 15 deletions

View File

@ -575,8 +575,7 @@ APZCTreeManager::ReceiveInputEvent(InputData& aEvent,
MOZ_ASSERT(hitResult == ApzcHitRegion || hitResult == ApzcContentRegion);
transformToApzc = GetScreenToApzcTransform(apzc);
wheelInput.mLocalOrigin =
TransformTo<ParentLayerPixel>(transformToApzc, wheelInput.mOrigin);
wheelInput.TransformToLocal(transformToApzc);
result = mInputQueue->ReceiveInputEvent(
apzc,
@ -597,10 +596,7 @@ APZCTreeManager::ReceiveInputEvent(InputData& aEvent,
if (apzc) {
MOZ_ASSERT(hitResult == ApzcHitRegion || hitResult == ApzcContentRegion);
transformToApzc = GetScreenToApzcTransform(apzc);
panInput.mLocalPanStartPoint = TransformTo<ParentLayerPixel>(
transformToApzc, panInput.mPanStartPoint);
panInput.mLocalPanDisplacement = TransformVector<ParentLayerPixel>(
transformToApzc, panInput.mPanDisplacement, panInput.mPanStartPoint);
panInput.TransformToLocal(transformToApzc);
result = mInputQueue->ReceiveInputEvent(
apzc,
/* aTargetConfirmed = */ hitResult == ApzcHitRegion,
@ -622,8 +618,7 @@ APZCTreeManager::ReceiveInputEvent(InputData& aEvent,
if (apzc) {
MOZ_ASSERT(hitResult == ApzcHitRegion || hitResult == ApzcContentRegion);
transformToApzc = GetScreenToApzcTransform(apzc);
pinchInput.mLocalFocusPoint = TransformTo<ParentLayerPixel>(
transformToApzc, pinchInput.mFocusPoint);
pinchInput.TransformToLocal(transformToApzc);
result = mInputQueue->ReceiveInputEvent(
apzc,
/* aTargetConfirmed = */ hitResult == ApzcHitRegion,
@ -643,8 +638,7 @@ APZCTreeManager::ReceiveInputEvent(InputData& aEvent,
if (apzc) {
MOZ_ASSERT(hitResult == ApzcHitRegion || hitResult == ApzcContentRegion);
transformToApzc = GetScreenToApzcTransform(apzc);
tapInput.mLocalPoint = TransformTo<ParentLayerPixel>(
transformToApzc, tapInput.mPoint);
tapInput.TransformToLocal(transformToApzc);
result = mInputQueue->ReceiveInputEvent(
apzc,
/* aTargetConfirmed = */ hitResult == ApzcHitRegion,
@ -776,11 +770,7 @@ APZCTreeManager::ProcessTouchInput(MultiTouchInput& aInput,
// This ensures that the sequence of touch points an APZC sees in an
// input block are all in the same coordinate space.
Matrix4x4 transformToApzc = mCachedTransformToApzcForInputBlock;
for (size_t i = 0; i < aInput.mTouches.Length(); i++) {
SingleTouchData& touchData = aInput.mTouches[i];
touchData.mLocalScreenPoint = TransformTo<ParentLayerPixel>(
transformToApzc, ScreenPoint(touchData.mScreenPoint));
}
aInput.TransformToLocal(transformToApzc);
result = mInputQueue->ReceiveInputEvent(mApzcForInputBlock,
/* aTargetConfirmed = */ mHitResultForInputBlock == ApzcHitRegion,
aInput, aOutInputBlockId);

View File

@ -10,6 +10,7 @@
#include "nsThreadUtils.h"
#include "mozilla/MouseEvents.h"
#include "mozilla/TouchEvents.h"
#include "UnitTransforms.h"
namespace mozilla {
@ -199,4 +200,38 @@ MultiTouchInput::MultiTouchInput(const WidgetMouseEvent& aMouseEvent)
180.0f,
1.0f));
}
void
MultiTouchInput::TransformToLocal(const gfx::Matrix4x4& aTransform)
{
for (size_t i = 0; i < mTouches.Length(); i++) {
mTouches[i].mLocalScreenPoint = TransformTo<ParentLayerPixel>(aTransform, ScreenPoint(mTouches[i].mScreenPoint));
}
}
void
PanGestureInput::TransformToLocal(const gfx::Matrix4x4& aTransform)
{
mLocalPanStartPoint = TransformTo<ParentLayerPixel>(aTransform, mPanStartPoint);
mLocalPanDisplacement = TransformVector<ParentLayerPixel>(aTransform, mPanDisplacement, mPanStartPoint);
}
void
PinchGestureInput::TransformToLocal(const gfx::Matrix4x4& aTransform)
{
mLocalFocusPoint = TransformTo<ParentLayerPixel>(aTransform, mFocusPoint);
}
void
TapGestureInput::TransformToLocal(const gfx::Matrix4x4& aTransform)
{
mLocalPoint = TransformTo<ParentLayerPixel>(aTransform, mPoint);
}
void
ScrollWheelInput::TransformToLocal(const gfx::Matrix4x4& aTransform)
{
mLocalOrigin = TransformTo<ParentLayerPixel>(aTransform, mOrigin);
}
} // namespace mozilla

View File

@ -22,6 +22,10 @@ namespace dom {
class Touch;
}
namespace gfx {
class Matrix4x4;
}
enum InputType
{
MULTITOUCH_INPUT,
@ -226,6 +230,8 @@ public:
// and rotation angle.
explicit MultiTouchInput(const WidgetMouseEvent& aMouseEvent);
void TransformToLocal(const gfx::Matrix4x4& aTransform);
MultiTouchType mType;
nsTArray<SingleTouchData> mTouches;
};
@ -296,6 +302,8 @@ public:
{
}
void TransformToLocal(const gfx::Matrix4x4& aTransform);
PanGestureType mType;
ScreenPoint mPanStartPoint;
@ -357,6 +365,8 @@ public:
{
}
void TransformToLocal(const gfx::Matrix4x4& aTransform);
PinchGestureType mType;
// Center point of the pinch gesture. That is, if there are two fingers on the
@ -425,6 +435,8 @@ public:
{
}
void TransformToLocal(const gfx::Matrix4x4& aTransform);
TapGestureType mType;
// The location of the tap in screen pixels.
@ -470,6 +482,8 @@ public:
mDeltaY(aDeltaY)
{}
void TransformToLocal(const gfx::Matrix4x4& aTransform);
ScrollDeltaType mDeltaType;
ScrollMode mScrollMode;
ScreenPoint mOrigin;