am 26cab064: Merge "Allow two finger pan and scale on touchscreens with FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT." into gingerbread

Merge commit '26cab06472badee374ac854f5a210991c37c4493' into gingerbread-plus-aosp

* commit '26cab06472badee374ac854f5a210991c37c4493':
  Allow two finger pan and scale on touchscreens with
This commit is contained in:
Adam Powell
2010-09-12 10:28:50 -07:00
committed by Android Git Automerger

View File

@@ -463,6 +463,11 @@ public class WebView extends AbsoluteLayout
private static final int TOUCH_DONE_MODE = 7; private static final int TOUCH_DONE_MODE = 7;
private static final int TOUCH_PINCH_DRAG = 8; private static final int TOUCH_PINCH_DRAG = 8;
/**
* True if we have a touch panel capable of detecting smooth pan/scale at the same time
*/
private boolean mAllowPanAndScale;
// Whether to forward the touch events to WebCore // Whether to forward the touch events to WebCore
private boolean mForwardTouchEvents = false; private boolean mForwardTouchEvents = false;
@@ -976,9 +981,11 @@ public class WebView extends AbsoluteLayout
void updateMultiTouchSupport(Context context) { void updateMultiTouchSupport(Context context) {
WebSettings settings = getSettings(); WebSettings settings = getSettings();
mSupportMultiTouch = context.getPackageManager().hasSystemFeature( final PackageManager pm = context.getPackageManager();
PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH) mSupportMultiTouch = pm.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH)
&& settings.supportZoom() && settings.getBuiltInZoomControls(); && settings.supportZoom() && settings.getBuiltInZoomControls();
mAllowPanAndScale = pm.hasSystemFeature(
PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT);
if (mSupportMultiTouch && (mScaleDetector == null)) { if (mSupportMultiTouch && (mScaleDetector == null)) {
mScaleDetector = new ScaleGestureDetector(context, mScaleDetector = new ScaleGestureDetector(context,
new ScaleDetectorListener()); new ScaleDetectorListener());
@@ -5018,11 +5025,13 @@ public class WebView extends AbsoluteLayout
// FIXME: we may consider to give WebKit an option to handle multi-touch // FIXME: we may consider to give WebKit an option to handle multi-touch
// events later. // events later.
if (mSupportMultiTouch && ev.getPointerCount() > 1) { if (mSupportMultiTouch && ev.getPointerCount() > 1) {
if (mMinZoomScale < mMaxZoomScale) { if (mAllowPanAndScale || mMinZoomScale < mMaxZoomScale) {
mScaleDetector.onTouchEvent(ev); mScaleDetector.onTouchEvent(ev);
if (mScaleDetector.isInProgress()) { if (mScaleDetector.isInProgress()) {
mLastTouchTime = eventTime; mLastTouchTime = eventTime;
return true; if (!mAllowPanAndScale) {
return true;
}
} }
x = mScaleDetector.getFocusX(); x = mScaleDetector.getFocusX();
y = mScaleDetector.getFocusY(); y = mScaleDetector.getFocusY();
@@ -5224,15 +5233,21 @@ public class WebView extends AbsoluteLayout
mLastTouchTime = eventTime; mLastTouchTime = eventTime;
break; break;
} }
// if it starts nearly horizontal or vertical, enforce it
int ax = Math.abs(deltaX); // Only lock dragging to one axis if we don't have a scale in progress.
int ay = Math.abs(deltaY); // Scaling implies free-roaming movement. Note we'll only ever get here
if (ax > MAX_SLOPE_FOR_DIAG * ay) { // if mAllowPanAndScale is true.
mSnapScrollMode = SNAP_X; if (mScaleDetector != null && !mScaleDetector.isInProgress()) {
mSnapPositive = deltaX > 0; // if it starts nearly horizontal or vertical, enforce it
} else if (ay > MAX_SLOPE_FOR_DIAG * ax) { int ax = Math.abs(deltaX);
mSnapScrollMode = SNAP_Y; int ay = Math.abs(deltaY);
mSnapPositive = deltaY > 0; if (ax > MAX_SLOPE_FOR_DIAG * ay) {
mSnapScrollMode = SNAP_X;
mSnapPositive = deltaX > 0;
} else if (ay > MAX_SLOPE_FOR_DIAG * ax) {
mSnapScrollMode = SNAP_Y;
mSnapPositive = deltaY > 0;
}
} }
mTouchMode = TOUCH_DRAG_MODE; mTouchMode = TOUCH_DRAG_MODE;