Bug 1046993 - Use floating-point coordinates throughout in Axis. r=kats

This commit is contained in:
Botond Ballo 2014-08-20 17:39:45 -04:00
parent 83273ef37c
commit 1ab1bfa3d8
4 changed files with 25 additions and 26 deletions

View File

@ -1020,7 +1020,7 @@ nsEventStatus AsyncPanZoomController::HandleGestureEvent(const InputData& aEvent
nsEventStatus AsyncPanZoomController::OnTouchStart(const MultiTouchInput& aEvent) {
APZC_LOG("%p got a touch-start in state %d\n", this, mState);
mPanDirRestricted = false;
ScreenIntPoint point = GetFirstTouchScreenPoint(aEvent);
ScreenPoint point = GetFirstTouchScreenPoint(aEvent);
switch (mState) {
case FLING:
@ -1351,8 +1351,8 @@ AsyncPanZoomController::ConvertToGecko(const ScreenPoint& aPoint, CSSPoint* aOut
nsEventStatus AsyncPanZoomController::OnPanMayBegin(const PanGestureInput& aEvent) {
APZC_LOG("%p got a pan-maybegin in state %d\n", this, mState);
mX.StartTouch(aEvent.mPanStartPoint.x.Truncated(), aEvent.mTime);
mY.StartTouch(aEvent.mPanStartPoint.y.Truncated(), aEvent.mTime);
mX.StartTouch(aEvent.mPanStartPoint.x, aEvent.mTime);
mY.StartTouch(aEvent.mPanStartPoint.y, aEvent.mTime);
if (mPanGestureState) {
mPanGestureState->GetOverscrollHandoffChain()->CancelAnimations();
} else {
@ -1377,8 +1377,8 @@ nsEventStatus AsyncPanZoomController::OnPanBegin(const PanGestureInput& aEvent)
mPanGestureState = MakeUnique<InputBlockState>(BuildOverscrollHandoffChain());
mX.StartTouch(aEvent.mPanStartPoint.x.Truncated(), aEvent.mTime);
mY.StartTouch(aEvent.mPanStartPoint.y.Truncated(), aEvent.mTime);
mX.StartTouch(aEvent.mPanStartPoint.x, aEvent.mTime);
mY.StartTouch(aEvent.mPanStartPoint.y, aEvent.mTime);
if (GetAxisLockMode() == FREE) {
SetState(PANNING);
@ -1401,8 +1401,8 @@ nsEventStatus AsyncPanZoomController::OnPan(const PanGestureInput& aEvent, bool
// size and position. We need to do so even if this is a momentum pan (i.e.
// aFingersOnTouchpad == false); in that case the "with touch" part is not
// really appropriate, so we may want to rethink this at some point.
mX.UpdateWithTouchAtDevicePoint(aEvent.mPanStartPoint.x.Truncated(), aEvent.mTime);
mY.UpdateWithTouchAtDevicePoint(aEvent.mPanStartPoint.y.Truncated(), aEvent.mTime);
mX.UpdateWithTouchAtDevicePoint(aEvent.mPanStartPoint.x, aEvent.mTime);
mY.UpdateWithTouchAtDevicePoint(aEvent.mPanStartPoint.y, aEvent.mTime);
HandlePanningUpdate(aEvent.mPanDisplacement.x, aEvent.mPanDisplacement.y);
@ -1652,7 +1652,7 @@ void AsyncPanZoomController::HandlePanningUpdate(float aDX, float aDY) {
nsEventStatus AsyncPanZoomController::StartPanning(const MultiTouchInput& aEvent) {
ReentrantMonitorAutoEnter lock(mMonitor);
ScreenIntPoint point = GetFirstTouchScreenPoint(aEvent);
ScreenPoint point = GetFirstTouchScreenPoint(aEvent);
float dx = mX.PanDistance(point.x);
float dy = mY.PanDistance(point.y);
@ -1685,7 +1685,7 @@ nsEventStatus AsyncPanZoomController::StartPanning(const MultiTouchInput& aEvent
}
void AsyncPanZoomController::UpdateWithTouchAtDevicePoint(const MultiTouchInput& aEvent) {
ScreenIntPoint point = GetFirstTouchScreenPoint(aEvent);
ScreenPoint point = GetFirstTouchScreenPoint(aEvent);
mX.UpdateWithTouchAtDevicePoint(point.x, aEvent.mTime);
mY.UpdateWithTouchAtDevicePoint(point.y, aEvent.mTime);
}
@ -1854,8 +1854,8 @@ bool AsyncPanZoomController::CallDispatchScroll(const ScreenPoint& aStartPoint,
}
void AsyncPanZoomController::TrackTouch(const MultiTouchInput& aEvent) {
ScreenIntPoint prevTouchPoint(mX.GetPos(), mY.GetPos());
ScreenIntPoint touchPoint = GetFirstTouchScreenPoint(aEvent);
ScreenPoint prevTouchPoint(mX.GetPos(), mY.GetPos());
ScreenPoint touchPoint = GetFirstTouchScreenPoint(aEvent);
float dx = mX.PanDistance(touchPoint.x);
float dy = mY.PanDistance(touchPoint.y);
@ -1869,7 +1869,7 @@ void AsyncPanZoomController::TrackTouch(const MultiTouchInput& aEvent) {
}
}
ScreenIntPoint& AsyncPanZoomController::GetFirstTouchScreenPoint(const MultiTouchInput& aEvent) {
ScreenPoint AsyncPanZoomController::GetFirstTouchScreenPoint(const MultiTouchInput& aEvent) {
return ((SingleTouchData&)aEvent.mTouches[0]).mScreenPoint;
}

View File

@ -467,11 +467,10 @@ protected:
const ScreenPoint GetVelocityVector();
/**
* Gets a reference to the first touch point from a MultiTouchInput. This
* gets only the first one and assumes the rest are either missing or not
* relevant.
* Gets the first touch point from a MultiTouchInput. This gets only
* the first one and assumes the rest are either missing or not relevant.
*/
ScreenIntPoint& GetFirstTouchScreenPoint(const MultiTouchInput& aEvent);
ScreenPoint GetFirstTouchScreenPoint(const MultiTouchInput& aEvent);
/**
* Sets the panning state basing on the pan direction angle and current touch-action value.

View File

@ -33,7 +33,7 @@ Axis::Axis(AsyncPanZoomController* aAsyncPanZoomController)
{
}
void Axis::UpdateWithTouchAtDevicePoint(ScreenIntCoord aPos, uint32_t aTimestampMs) {
void Axis::UpdateWithTouchAtDevicePoint(ScreenCoord aPos, uint32_t aTimestampMs) {
// mVelocityQueue is controller-thread only
AsyncPanZoomController::AssertOnControllerThread();
@ -46,7 +46,7 @@ void Axis::UpdateWithTouchAtDevicePoint(ScreenIntCoord aPos, uint32_t aTimestamp
return;
}
float newVelocity = mAxisLocked ? 0 : (float)(mPos - aPos) / (float)(aTimestampMs - mPosTimeMs);
float newVelocity = mAxisLocked ? 0.0f : (float)(mPos - aPos) / (float)(aTimestampMs - mPosTimeMs);
if (gfxPrefs::APZMaxVelocity() > 0.0f) {
newVelocity = std::min(newVelocity, gfxPrefs::APZMaxVelocity() * APZCTreeManager::GetDPI());
}
@ -62,7 +62,7 @@ void Axis::UpdateWithTouchAtDevicePoint(ScreenIntCoord aPos, uint32_t aTimestamp
}
}
void Axis::StartTouch(ScreenIntCoord aPos, uint32_t aTimestampMs) {
void Axis::StartTouch(ScreenCoord aPos, uint32_t aTimestampMs) {
mStartPos = aPos;
mPos = aPos;
mPosTimeMs = aTimestampMs;
@ -196,7 +196,7 @@ float Axis::PanDistance() {
return fabsf((mPos - mStartPos).value);
}
float Axis::PanDistance(ScreenIntCoord aPos) {
float Axis::PanDistance(ScreenCoord aPos) {
return fabsf((aPos - mStartPos).value);
}

View File

@ -55,13 +55,13 @@ public:
* Notify this Axis that a new touch has been received, including a timestamp
* for when the touch was received. This triggers a recalculation of velocity.
*/
void UpdateWithTouchAtDevicePoint(ScreenIntCoord aPos, uint32_t aTimestampMs);
void UpdateWithTouchAtDevicePoint(ScreenCoord aPos, uint32_t aTimestampMs);
/**
* Notify this Axis that a touch has begun, i.e. the user has put their finger
* on the screen but has not yet tried to pan.
*/
void StartTouch(ScreenIntCoord aPos, uint32_t aTimestampMs);
void StartTouch(ScreenCoord aPos, uint32_t aTimestampMs);
/**
* Notify this Axis that a touch has ended gracefully. This may perform
@ -129,7 +129,7 @@ public:
* Gets the distance between the starting position of the touch supplied in
* startTouch() and the supplied position.
*/
float PanDistance(ScreenIntCoord aPos);
float PanDistance(ScreenCoord aPos);
/**
* Applies friction during a fling, or cancels the fling if the velocity is
@ -211,16 +211,16 @@ public:
CSSCoord GetCompositionEnd() const;
CSSCoord GetPageEnd() const;
ScreenIntCoord GetPos() const { return mPos; }
ScreenCoord GetPos() const { return mPos; }
virtual CSSCoord GetPointOffset(const CSSPoint& aPoint) const = 0;
virtual CSSCoord GetRectLength(const CSSRect& aRect) const = 0;
virtual CSSCoord GetRectOffset(const CSSRect& aRect) const = 0;
protected:
ScreenIntCoord mPos;
ScreenCoord mPos;
uint32_t mPosTimeMs;
ScreenIntCoord mStartPos;
ScreenCoord mStartPos;
float mVelocity;
bool mAxisLocked; // Whether movement on this axis is locked.
AsyncPanZoomController* mAsyncPanZoomController;