Bug 783553 - Disable overscroll in webapps. r=kats

This commit is contained in:
Wes Johnston 2012-09-12 13:36:36 -07:00
parent c3d35a8f18
commit 33b6a66339
5 changed files with 65 additions and 6 deletions

View File

@ -2494,7 +2494,7 @@ abstract public class GeckoApp
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Update:CheckResult", result ? "true" : "false"));
}
private void connectGeckoLayerClient() {
protected void connectGeckoLayerClient() {
mLayerView.getLayerClient().notifyGeckoReady();
mLayerView.getTouchEventHandler().setOnTouchListener(new ContentTouchListener() {

View File

@ -146,5 +146,10 @@ public class WebApp extends GeckoApp {
}
super.onTabChanged(tab, msg, data);
}
protected void connectGeckoLayerClient() {
super.connectGeckoLayerClient();
getLayerView().setOverScrollMode(View.OVER_SCROLL_NEVER);
}
};

View File

@ -382,4 +382,18 @@ public class LayerView extends FrameLayout {
}
}
@Override
public void setOverScrollMode(int overscrollMode) {
super.setOverScrollMode(overscrollMode);
if (mLayerClient != null)
mLayerClient.getPanZoomController().setOverScrollMode(overscrollMode);
}
@Override
public int getOverScrollMode() {
if (mLayerClient != null)
return mLayerClient.getPanZoomController().getOverScrollMode();
return super.getOverScrollMode();
}
}

View File

@ -10,6 +10,7 @@ import org.mozilla.gecko.util.FloatUtils;
import org.json.JSONArray;
import android.util.Log;
import android.view.View;
import java.util.Map;
@ -105,6 +106,7 @@ abstract class Axis {
private final SubdocumentScrollHelper mSubscroller;
private int mOverscrollMode; /* Default to only overscrolling if we're allowed to scroll in a direction */
private float mFirstTouchPos; /* Position of the first touch event on the current drag. */
private float mTouchPos; /* Position of the most recent touch event on the current drag. */
private float mLastTouchPos; /* Position of the touch event before touchPos. */
@ -122,6 +124,15 @@ abstract class Axis {
Axis(SubdocumentScrollHelper subscroller) {
mSubscroller = subscroller;
mOverscrollMode = View.OVER_SCROLL_IF_CONTENT_SCROLLS;
}
public void setOverScrollMode(int overscrollMode) {
mOverscrollMode = overscrollMode;
}
public int getOverScrollMode() {
return mOverscrollMode;
}
private float getViewportEnd() {
@ -206,10 +217,17 @@ abstract class Axis {
// apply to the top-level document) and only take into account axis locking.
if (mSubscroller.scrolling()) {
return !mScrollingDisabled;
} else {
return getViewportLength() <= getPageLength() - MIN_SCROLLABLE_DISTANCE &&
!mScrollingDisabled;
}
// if we are axis locked, return false
if (mScrollingDisabled) {
return false;
}
// there is scrollable space, and we're not disabled, or the document fits the viewport
// but we always allow overscroll anyway
return getViewportLength() <= getPageLength() - MIN_SCROLLABLE_DISTANCE ||
getOverScrollMode() == View.OVER_SCROLL_ALWAYS;
}
/*
@ -294,14 +312,27 @@ abstract class Axis {
// Performs displacement of the viewport position according to the current velocity.
void displace() {
if (!scrollable()) {
// if this isn't scrollable just return
if (!scrollable())
return;
}
if (mFlingState == FlingStates.PANNING)
mDisplacement += (mLastTouchPos - mTouchPos) * getEdgeResistance(false);
else
mDisplacement += mVelocity;
// if overscroll is disabled and we're trying to overscroll, reset the displacement
// to remove any excess. Using getExcess alone isn't enough here since it relies on
// getOverscroll which doesn't take into account any new displacment being applied
if (getOverScrollMode() == View.OVER_SCROLL_NEVER) {
if (mDisplacement + getOrigin() < getPageStart()) {
mDisplacement = getPageStart() - getOrigin();
stopFling();
} else if (mDisplacement + getViewportEnd() > getPageEnd()) {
mDisplacement = getPageEnd() - getViewportEnd();
stopFling();
}
}
}
float resetDisplacement() {

View File

@ -1112,4 +1112,13 @@ public class PanZoomController
checkMainThread();
bounce();
}
public void setOverScrollMode(int overscrollMode) {
mX.setOverScrollMode(overscrollMode);
mY.setOverScrollMode(overscrollMode);
}
public int getOverScrollMode() {
return mX.getOverScrollMode();
}
}