Auto merge of #22178 - paulrouget:fixScroll, r=jdm

Properly cancel looping before triggering another drawing loop

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #21991 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22178)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2018-11-17 09:05:58 -05:00 committed by GitHub
commit 6da89a630f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -133,7 +133,7 @@ public class ServoView extends GLSurfaceView
public void animationStateChanged(boolean animating) {
if (!mAnimating && animating) {
post(() -> Choreographer.getInstance().postFrameCallback(ServoView.this));
post(() -> startLooping());
}
mAnimating = animating;
}
@ -182,6 +182,13 @@ public class ServoView extends GLSurfaceView
mScroller = new OverScroller(context);
}
private void startLooping() {
// In case we were already drawing.
Choreographer.getInstance().removeFrameCallback(this);
Choreographer.getInstance().postFrameCallback(this);
}
public void doFrame(long frameTimeNanos) {
if (!mRedrawing) {
mRedrawing = true;
@ -264,9 +271,10 @@ public class ServoView extends GLSurfaceView
mCurY = (int) e.getY();
mLastY = mCurY;
mScroller.forceFinished(true);
mFlinging = false;
mServo.scrollStart(0, 0, mCurX, mCurY);
mScrolling = true;
Choreographer.getInstance().postFrameCallback(this);
startLooping();
return true;
case (MotionEvent.ACTION_MOVE):
mCurX = (int) e.getX();
@ -305,7 +313,7 @@ public class ServoView extends GLSurfaceView
mZoomFactor = detector.getScaleFactor();
mZooming = true;
mServo.pinchZoomStart(mZoomFactor, 0, 0);
Choreographer.getInstance().postFrameCallback(this);
startLooping();
return true;
} else {
return false;