diff --git a/gfx/layers/apz/src/AsyncPanZoomController.cpp b/gfx/layers/apz/src/AsyncPanZoomController.cpp index 0bbe763793a6..3b04e7e2a0be 100644 --- a/gfx/layers/apz/src/AsyncPanZoomController.cpp +++ b/gfx/layers/apz/src/AsyncPanZoomController.cpp @@ -1828,8 +1828,16 @@ nsEventStatus AsyncPanZoomController::OnPan(const PanGestureInput& aEvent, bool *CurrentPanGestureBlock()->GetOverscrollHandoffChain(), panDistance, ScrollSource::Wheel); + + // Create fake "touch" positions that will result in the desired scroll motion. + // Note that the pan displacement describes the change in scroll position: + // positive displacement values mean that the scroll position increases. + // However, an increase in scroll position means that the scrolled contents + // are moved to the left / upwards. Since our simulated "touches" determine + // the motion of the scrolled contents, not of the scroll position, they need + // to move in the opposite direction of the pan displacement. ParentLayerPoint startPoint = aEvent.mLocalPanStartPoint; - ParentLayerPoint endPoint = aEvent.mLocalPanStartPoint + aEvent.mLocalPanDisplacement; + ParentLayerPoint endPoint = aEvent.mLocalPanStartPoint - aEvent.mLocalPanDisplacement; CallDispatchScroll(startPoint, endPoint, handoffState); return nsEventStatus_eConsumeNoDefault; diff --git a/gfx/layers/apz/src/Axis.cpp b/gfx/layers/apz/src/Axis.cpp index 1684016125d4..5a38852dc4b5 100644 --- a/gfx/layers/apz/src/Axis.cpp +++ b/gfx/layers/apz/src/Axis.cpp @@ -76,7 +76,7 @@ void Axis::UpdateWithTouchAtDevicePoint(ParentLayerCoord aPos, ParentLayerCoord return; } - float newVelocity = mAxisLocked ? 0.0f : (float)(mPos - aPos + aAdditionalDelta) / (float)(aTimestampMs - mPosTimeMs); + float newVelocity = mAxisLocked ? 0.0f : (float)(mPos - aPos - aAdditionalDelta) / (float)(aTimestampMs - mPosTimeMs); if (gfxPrefs::APZMaxVelocity() > 0.0f) { bool velocityIsNegative = (newVelocity < 0); newVelocity = fabs(newVelocity); diff --git a/gfx/layers/apz/src/Axis.h b/gfx/layers/apz/src/Axis.h index 2294510f7b36..1da9dcf3e42c 100644 --- a/gfx/layers/apz/src/Axis.h +++ b/gfx/layers/apz/src/Axis.h @@ -43,6 +43,9 @@ 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. + * This can also used for pan gesture events. For those events, the "touch" + * location is stationary and the scroll displacement is passed in as + * aAdditionalDelta. */ void UpdateWithTouchAtDevicePoint(ParentLayerCoord aPos, ParentLayerCoord aAdditionalDelta, uint32_t aTimestampMs); diff --git a/layout/base/UnitTransforms.h b/layout/base/UnitTransforms.h index 6d162f307fac..c952c839e590 100644 --- a/layout/base/UnitTransforms.h +++ b/layout/base/UnitTransforms.h @@ -217,7 +217,7 @@ static Maybe> UntransformVector(const gfx::Matrix4x if (!projectedAnchor.HasPositiveWCoord() || !projectedTarget.HasPositiveWCoord()){ return Nothing(); } - return Some(ViewAs(projectedAnchor.As2DPoint() - projectedTarget.As2DPoint())); + return Some(ViewAs(projectedTarget.As2DPoint() - projectedAnchor.As2DPoint())); } } // namespace mozilla