mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
android: Fix flinging downwards (#34584)
* android: Fix onScroll source Scrolling should be based on `e2`, the second event, since dX and dY are relative to e2 and not e1. Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com> * android: Fix flinging down on android. 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 and 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. Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com> --------- Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
This commit is contained in:
parent
84c59e09b6
commit
dfcbb18a8b
1 changed files with 12 additions and 2 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue