float Axis::AdjustDisplacement(float aDisplacement, float& aOverscrollAmountOut, bool aScrollingDisabled) { if (mAxisLocked) { aOverscrollAmountOut = 0; return 0; } if (aScrollingDisabled) { // Scrolling is disabled on this axis, stop scrolling. aOverscrollAmountOut = aDisplacement; return 0; } float displacement = aDisplacement; // If this displacement will cause an overscroll, throttle it. Can potentially // bring it to 0 even if the velocity is high. if (DisplacementWillOverscroll(displacement) != OVERSCROLL_NONE) { // No need to have a velocity along this axis anymore; it won't take us // anywhere, so we're just spinning needlessly. mVelocity = 0.0f; aOverscrollAmountOut = DisplacementWillOverscrollAmount(displacement); displacement -= aOverscrollAmountOut; } return displacement; }
bool Axis::AdjustDisplacement(CSSCoord aDisplacement, CSSCoord& aDisplacementOut, CSSCoord& aOverscrollAmountOut) { if (mAxisLocked) { aOverscrollAmountOut = 0; aDisplacementOut = 0; return false; } CSSCoord displacement = aDisplacement; // First consume any overscroll in the opposite direction along this axis. CSSCoord consumedOverscroll = 0; if (mOverscroll > 0 && aDisplacement < 0) { consumedOverscroll = std::min(mOverscroll, -aDisplacement); } else if (mOverscroll < 0 && aDisplacement > 0) { consumedOverscroll = 0.f - std::min(-mOverscroll, aDisplacement); } mOverscroll -= consumedOverscroll; displacement += consumedOverscroll; // Split the requested displacement into an allowed displacement that does // not overscroll, and an overscroll amount. if (DisplacementWillOverscroll(displacement) != OVERSCROLL_NONE) { // No need to have a velocity along this axis anymore; it won't take us // anywhere, so we're just spinning needlessly. mVelocity = 0.0f; aOverscrollAmountOut = DisplacementWillOverscrollAmount(displacement); displacement -= aOverscrollAmountOut; } aDisplacementOut = displacement; return fabsf(consumedOverscroll) > EPSILON; }
float Axis::DisplacementWillOverscrollAmount(int32_t aDisplacement) { switch (DisplacementWillOverscroll(aDisplacement)) { case OVERSCROLL_MINUS: return (GetOrigin() + aDisplacement) - GetPageStart(); case OVERSCROLL_PLUS: return (GetCompositionEnd() + aDisplacement) - GetPageEnd(); // Don't handle overscrolled in both directions; a displacement can't cause // this, it must have already been zoomed out too far. default: return 0; } }
float Axis::GetDisplacementForDuration(float aScale, const TimeDuration& aDelta) { if (fabsf(mVelocity) < gVelocityThreshold) { mAcceleration = 0; } float accelerationFactor = GetAccelerationFactor(); float displacement = mVelocity * aScale * aDelta.ToMilliseconds() * accelerationFactor; // If this displacement will cause an overscroll, throttle it. Can potentially // bring it to 0 even if the velocity is high. if (DisplacementWillOverscroll(displacement) != OVERSCROLL_NONE) { // No need to have a velocity along this axis anymore; it won't take us // anywhere, so we're just spinning needlessly. mVelocity = 0.0f; mAcceleration = 0; displacement -= DisplacementWillOverscrollAmount(displacement); } return displacement; }