diff --git a/gfx/layers/apz/src/APZUtils.cpp b/gfx/layers/apz/src/APZUtils.cpp index 564160b47059..25cc1f536d82 100644 --- a/gfx/layers/apz/src/APZUtils.cpp +++ b/gfx/layers/apz/src/APZUtils.cpp @@ -40,6 +40,18 @@ CalculatePendingDisplayPort(const FrameMetrics& aFrameMetrics, aFrameMetrics, aVelocity); } +/*static*/ bool +IsCloseToHorizontal(float aAngle, float aThreshold) +{ + return (aAngle < aThreshold || aAngle > (M_PI - aThreshold)); +} + +/*static*/ bool +IsCloseToVertical(float aAngle, float aThreshold) +{ + return (fabs(aAngle - (M_PI / 2)) < aThreshold); +} + } // namespace apz } // namespace layers } // namespace mozilla diff --git a/gfx/layers/apz/src/APZUtils.h b/gfx/layers/apz/src/APZUtils.h index bf5bf7ee26b0..0d07602dd6ff 100644 --- a/gfx/layers/apz/src/APZUtils.h +++ b/gfx/layers/apz/src/APZUtils.h @@ -131,6 +131,16 @@ void InitializeGlobalState(); const ScreenMargin CalculatePendingDisplayPort(const FrameMetrics& aFrameMetrics, const ParentLayerPoint& aVelocity); +/** + * Is aAngle within the given threshold of the horizontal axis? + * @param aAngle an angle in radians in the range [0, pi] + * @param aThreshold an angle in radians in the range [0, pi/2] + */ +bool IsCloseToHorizontal(float aAngle, float aThreshold); + +// As above, but for the vertical axis. +bool IsCloseToVertical(float aAngle, float aThreshold); + } // namespace apz } // namespace layers diff --git a/gfx/layers/apz/src/AsyncPanZoomController.cpp b/gfx/layers/apz/src/AsyncPanZoomController.cpp index 8d28ebb377c1..4afd1b4c0dd7 100644 --- a/gfx/layers/apz/src/AsyncPanZoomController.cpp +++ b/gfx/layers/apz/src/AsyncPanZoomController.cpp @@ -524,22 +524,6 @@ static bool IsHighMemSystem() return gIsHighMemSystem; } -/** - * Is aAngle within the given threshold of the horizontal axis? - * @param aAngle an angle in radians in the range [0, pi] - * @param aThreshold an angle in radians in the range [0, pi/2] - */ -static bool IsCloseToHorizontal(float aAngle, float aThreshold) -{ - return (aAngle < aThreshold || aAngle > (M_PI - aThreshold)); -} - -// As above, but for the vertical axis. -static bool IsCloseToVertical(float aAngle, float aThreshold) -{ - return (fabs(aAngle - (M_PI / 2)) < aThreshold); -} - // Counter used to give each APZC a unique id static uint32_t sAsyncPanZoomControllerCount = 0; @@ -2765,10 +2749,10 @@ void AsyncPanZoomController::HandlePanningWithTouchAction(double aAngle) { overscrollHandoffChain->CanScrollInDirection(this, ScrollDirection::eVertical); if (GetCurrentTouchBlock()->TouchActionAllowsPanningXY()) { if (canScrollHorizontal && canScrollVertical) { - if (IsCloseToHorizontal(aAngle, gfxPrefs::APZAxisLockAngle())) { + if (apz::IsCloseToHorizontal(aAngle, gfxPrefs::APZAxisLockAngle())) { mY.SetAxisLocked(true); SetState(PANNING_LOCKED_X); - } else if (IsCloseToVertical(aAngle, gfxPrefs::APZAxisLockAngle())) { + } else if (apz::IsCloseToVertical(aAngle, gfxPrefs::APZAxisLockAngle())) { mX.SetAxisLocked(true); SetState(PANNING_LOCKED_Y); } else { @@ -2782,7 +2766,7 @@ void AsyncPanZoomController::HandlePanningWithTouchAction(double aAngle) { } else if (GetCurrentTouchBlock()->TouchActionAllowsPanningX()) { // Using bigger angle for panning to keep behavior consistent // with IE. - if (IsCloseToHorizontal(aAngle, gfxPrefs::APZAllowedDirectPanAngle())) { + if (apz::IsCloseToHorizontal(aAngle, gfxPrefs::APZAllowedDirectPanAngle())) { mY.SetAxisLocked(true); SetState(PANNING_LOCKED_X); mPanDirRestricted = true; @@ -2792,7 +2776,7 @@ void AsyncPanZoomController::HandlePanningWithTouchAction(double aAngle) { SetState(NOTHING); } } else if (GetCurrentTouchBlock()->TouchActionAllowsPanningY()) { - if (IsCloseToVertical(aAngle, gfxPrefs::APZAllowedDirectPanAngle())) { + if (apz::IsCloseToVertical(aAngle, gfxPrefs::APZAllowedDirectPanAngle())) { mX.SetAxisLocked(true); SetState(PANNING_LOCKED_Y); mPanDirRestricted = true; @@ -2823,12 +2807,12 @@ void AsyncPanZoomController::HandlePanning(double aAngle) { if (!canScrollHorizontal || !canScrollVertical) { SetState(PANNING); - } else if (IsCloseToHorizontal(aAngle, gfxPrefs::APZAxisLockAngle())) { + } else if (apz::IsCloseToHorizontal(aAngle, gfxPrefs::APZAxisLockAngle())) { mY.SetAxisLocked(true); if (canScrollHorizontal) { SetState(PANNING_LOCKED_X); } - } else if (IsCloseToVertical(aAngle, gfxPrefs::APZAxisLockAngle())) { + } else if (apz::IsCloseToVertical(aAngle, gfxPrefs::APZAxisLockAngle())) { mX.SetAxisLocked(true); if (canScrollVertical) { SetState(PANNING_LOCKED_Y); @@ -2849,12 +2833,12 @@ void AsyncPanZoomController::HandlePanningUpdate(const ScreenPoint& aPanDistance if (fabs(aPanDistance.x) > breakThreshold || fabs(aPanDistance.y) > breakThreshold) { if (mState == PANNING_LOCKED_X) { - if (!IsCloseToHorizontal(angle, gfxPrefs::APZAxisBreakoutAngle())) { + if (!apz::IsCloseToHorizontal(angle, gfxPrefs::APZAxisBreakoutAngle())) { mY.SetAxisLocked(false); SetState(PANNING); } } else if (mState == PANNING_LOCKED_Y) { - if (!IsCloseToVertical(angle, gfxPrefs::APZAxisBreakoutAngle())) { + if (!apz::IsCloseToVertical(angle, gfxPrefs::APZAxisBreakoutAngle())) { mX.SetAxisLocked(false); SetState(PANNING); }