diff --git a/support/android/apk/servoview/src/main/java/org/servo/servoview/ServoView.java b/support/android/apk/servoview/src/main/java/org/servo/servoview/ServoView.java index 55724dee9d6..1ee0968e899 100644 --- a/support/android/apk/servoview/src/main/java/org/servo/servoview/ServoView.java +++ b/support/android/apk/servoview/src/main/java/org/servo/servoview/ServoView.java @@ -162,7 +162,17 @@ public class ServoView extends SurfaceView boolean zoomNecessary = mZooming && mZoomFactor != 1; if (scrollNecessary) { - mServo.scroll(dx, dy, mCurX, mCurY); + // We need to ensure x and y are inside the window, otherwise servo will not scroll! + // Our fling implementation will set `mCurX` and `mCurY` to a very high initial value + // when flinging with a negative velocity, since we don't know the size of our + // content page, because the android `OverScroller` needs to know the size of the page. + // Setting the page size to a ridiculously high value ensures that flinging will + // not be cut of short, even if we fling farther then the edge of the screen, + // starting from the touch up point. + int x = Math.min(mCurX, this.getHeight()); + int y = Math.min(mCurY, this.getWidth()); + + mServo.scroll(dx, dy, x, y); } if (zoomNecessary) { @@ -299,7 +309,7 @@ public class ServoView extends SurfaceView } public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { - mServo.scroll((int) -distanceX, (int) -distanceY, (int) e1.getX(), (int) e1.getY()); + mServo.scroll((int) -distanceX, (int) -distanceY, (int) e2.getX(), (int) e2.getY()); return true; }