Bug 1235994 - Extract a helper function to request a snap to the predicted destination. r?botond
--- a/gfx/layers/apz/src/AsyncPanZoomController.cpp
+++ b/gfx/layers/apz/src/AsyncPanZoomController.cpp
@@ -2424,16 +2424,24 @@ void AsyncPanZoomController::AcceptFling
mY.SetVelocity(mY.GetVelocity() + aHandoffState.mVelocity.y);
aHandoffState.mVelocity.y = 0;
}
SetState(FLING);
FlingAnimation *fling = new FlingAnimation(*this,
aHandoffState.mChain,
!aHandoffState.mIsHandoff, // only apply acceleration if this is an initial fling
aHandoffState.mScrolledApzc);
+ RequestSnapToDestination();
+ StartAnimation(fling);
+}
+
+void
+AsyncPanZoomController::RequestSnapToDestination()
+{
+ ReentrantMonitorAutoEnter lock(mMonitor);
float friction = gfxPrefs::APZFlingFriction();
ParentLayerPoint velocity(mX.GetVelocity(), mY.GetVelocity());
ParentLayerPoint predictedDelta;
// "-velocity / log(1.0 - friction)" is the integral of the deceleration
// curve modeled for flings in the "Axis" class.
if (velocity.x != 0.0f) {
predictedDelta.x = -velocity.x / log(1.0 - friction);
@@ -2457,18 +2465,16 @@ void AsyncPanZoomController::AcceptFling
this, friction, velocity.x, velocity.y, (float)predictedDelta.x,
(float)predictedDelta.y, (float)mFrameMetrics.GetScrollOffset().x,
(float)mFrameMetrics.GetScrollOffset().y,
(float)predictedDestination.x, (float)predictedDestination.y);
controller->RequestFlingSnap(mFrameMetrics.GetScrollId(),
predictedDestination);
}
}
-
- StartAnimation(fling);
}
bool AsyncPanZoomController::AttemptFling(FlingHandoffState& aHandoffState) {
// If we are pannable, take over the fling ourselves.
if (IsPannable()) {
AcceptFling(aHandoffState);
return true;
}
--- a/gfx/layers/apz/src/AsyncPanZoomController.h
+++ b/gfx/layers/apz/src/AsyncPanZoomController.h
@@ -635,16 +635,19 @@ protected:
// Common processing at the end of a touch block.
void OnTouchEndOrCancel();
// This is called to request that the main thread snap the scroll position
// to a nearby snap position if appropriate. The current scroll position is
// used as the final destination.
void RequestSnap();
+ // Same as above, but takes into account the current velocity to find a
+ // predicted destination.
+ void RequestSnapToDestination();
uint64_t mLayersId;
RefPtr<CompositorParent> mCompositorParent;
/* Access to the following two fields is protected by the mRefPtrMonitor,
since they are accessed on the UI thread but can be cleared on the
compositor thread. */
RefPtr<GeckoContentController> mGeckoContentController;