Bug 1186164 - When clearing the overscroll animation state, make sure GetOverscroll() continues to reflect the correct direction of overscroll. r=Cwiiis
authorBotond Ballo <botond@mozilla.com>
Wed, 22 Jul 2015 18:55:55 -0400
changeset 286908 d13b99696fc447001750d416305811576735d180
parent 286907 c9822fda68ff0212b8ec811c4f4f524268274751
child 286909 4ea079f8d4b8ac643e38ed4c67be1a3e4466fe25
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersCwiiis
bugs1186164
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1186164 - When clearing the overscroll animation state, make sure GetOverscroll() continues to reflect the correct direction of overscroll. r=Cwiiis
gfx/layers/apz/src/Axis.cpp
gfx/layers/apz/src/Axis.h
--- a/gfx/layers/apz/src/Axis.cpp
+++ b/gfx/layers/apz/src/Axis.cpp
@@ -134,17 +134,17 @@ bool Axis::AdjustDisplacement(ParentLaye
     return false;
   }
   if (aForceOverscroll) {
     aOverscrollAmountOut = aDisplacement;
     aDisplacementOut = 0;
     return false;
   }
 
-  ClearOverscrollAnimationState();
+  EndOverscrollAnimation();
 
   ParentLayerCoord displacement = aDisplacement;
 
   // First consume any overscroll in the opposite direction along this axis.
   ParentLayerCoord consumedOverscroll = 0;
   if (mOverscroll > 0 && aDisplacement < 0) {
     consumedOverscroll = std::min(mOverscroll, -aDisplacement);
   } else if (mOverscroll < 0 && aDisplacement > 0) {
@@ -181,17 +181,17 @@ ParentLayerCoord Axis::ApplyResistance(P
 
 void Axis::OverscrollBy(ParentLayerCoord aOverscroll) {
   MOZ_ASSERT(CanScroll());
   // We can get some spurious calls to OverscrollBy() with near-zero values
   // due to rounding error. Ignore those (they might trip the asserts below.)
   if (FuzzyEqualsAdditive(aOverscroll.value, 0.0f, COORDINATE_EPSILON)) {
     return;
   }
-  ClearOverscrollAnimationState();
+  EndOverscrollAnimation();
   aOverscroll = ApplyResistance(aOverscroll);
   if (aOverscroll > 0) {
 #ifdef DEBUG
     if (!FuzzyEqualsCoordinate(GetCompositionEnd().value, GetPageEnd().value)) {
       nsPrintfCString message("composition end (%f) is not equal (within error) to page end (%f)\n",
                               GetCompositionEnd().value, GetPageEnd().value);
       NS_ASSERTION(false, message.get());
       MOZ_CRASH();
@@ -233,23 +233,21 @@ void Axis::StartOverscrollAnimation(floa
   MOZ_ASSERT(mFirstOverscrollAnimationSample == 0 &&
              mLastOverscrollPeak == 0 &&
              mOverscrollScale == 1);
 
   SetVelocity(aVelocity);
 }
 
 void Axis::EndOverscrollAnimation() {
-  ClearOverscrollAnimationState();
-}
-
-void Axis::ClearOverscrollAnimationState() {
+  ParentLayerCoord overscroll = GetOverscroll();
   mFirstOverscrollAnimationSample = 0;
   mLastOverscrollPeak = 0;
   mOverscrollScale = 1.0f;
+  mOverscroll = overscroll;
 }
 
 void Axis::StepOverscrollAnimation(double aStepDurationMilliseconds) {
   // Apply spring physics to the overscroll as time goes on.
   // Note: this method of sampling isn't perfectly smooth, as it assumes
   // a constant velocity over 'aDelta', instead of an accelerating velocity.
   // (The way we applying friction to flings has the same issue.)
   // Hooke's law with damping:
@@ -359,17 +357,17 @@ bool Axis::SampleOverscrollAnimation(con
   return true;
 }
 
 bool Axis::IsOverscrolled() const {
   return mOverscroll != 0.f;
 }
 
 void Axis::ClearOverscroll() {
-  ClearOverscrollAnimationState();
+  EndOverscrollAnimation();
   mOverscroll = 0;
 }
 
 ParentLayerCoord Axis::PanStart() const {
   return mStartPos;
 }
 
 ParentLayerCoord Axis::PanDistance() const {
--- a/gfx/layers/apz/src/Axis.h
+++ b/gfx/layers/apz/src/Axis.h
@@ -273,19 +273,16 @@ protected:
   nsTArray<std::pair<uint32_t, float> > mVelocityQueue;
 
   const FrameMetrics& GetFrameMetrics() const;
 
   // Adjust a requested overscroll amount for resistance, yielding a smaller
   // actual overscroll amount.
   ParentLayerCoord ApplyResistance(ParentLayerCoord aOverscroll) const;
 
-  // Clear the state associated with an overscroll animation.
-  void ClearOverscrollAnimationState();
-
   // Helper function for SampleOverscrollAnimation().
   void StepOverscrollAnimation(double aStepDurationMilliseconds);
 
   // Convert a velocity from global inches/ms into ParentLayerCoords/ms.
   float ToLocalVelocity(float aVelocityInchesPerMs) const;
 };
 
 class AxisX : public Axis {