DO NOT MERGE.

Couple of tweak for multi-touch in WebView.

1. If we can't zoom, don't get in multitouch mode.
   This avoid the logo in google.com looks fuzzy.
2. Reset mAnchor after sending VIEW_SIZE_CHANGED.
3. Don't call zoom when finishing multitouch unless
   zoom is called before.
4. Change the width for nativeSetSize, which was modified
   in the last check-in. The new logic should make both
   msn.com and news.google.com looks correct.
5. Use the pressure instead of distance/time to filter
   out the jitter just before lifting the finger.

Fix http://b/issue?id=2360032
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index 8308fd1..f6d6d22 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -2098,6 +2098,7 @@
             mWebViewCore.sendMessage(EventHub.VIEW_SIZE_CHANGED, data);
             mLastWidthSent = newWidth;
             mLastHeightSent = newHeight;
+            mAnchorX = mAnchorY = 0;
             return true;
         }
         return false;
@@ -3702,9 +3703,13 @@
     private static boolean mSupportMultiTouch;
 
     private double mPinchDistance;
+    private float mLastPressure;
     private int mAnchorX;
     private int mAnchorY;
 
+    private static float SCALE_INCREMENT = 0.01f;
+    private static float PRESSURE_THRESHOLD = 0.67f;
+
     private boolean doMultiTouch(MotionEvent ev) {
         int action = ev.getAction();
 
@@ -3719,28 +3724,25 @@
                 mWebTextView.setInPassword(false);
             }
             // start multi (2-pointer) touch
-            mPreviewZoomOnly = true;
             float x0 = ev.getX(0);
             float y0 = ev.getY(0);
             float x1 = ev.getX(1);
             float y1 = ev.getY(1);
-            mLastTouchTime = ev.getEventTime();
             mPinchDistance = Math.sqrt((x0 - x1) * (x0 - x1) + (y0 - y1)
                     * (y0 - y1));
-            mZoomCenterX = mZoomCenterY = 0;
         } else if ((action & 0xff) == MotionEvent.ACTION_POINTER_UP) {
-            mPreviewZoomOnly = false;
-            // for testing only, default don't reflow now
-            boolean reflowNow = !getSettings().getPluginsEnabled();
-            // force zoom after mPreviewZoomOnly is set to false so that the new
-            // view size will be passed to the WebKit
-            if (reflowNow && (mZoomCenterX != 0) && (mZoomCenterY != 0)) {
+            if (mPreviewZoomOnly) {
+                mPreviewZoomOnly = false;
                 mAnchorX = viewToContentX((int) mZoomCenterX + mScrollX);
                 mAnchorY = viewToContentY((int) mZoomCenterY + mScrollY);
+                // for testing only, default don't reflow now
+                boolean reflowNow = !getSettings().getPluginsEnabled();
+                // force zoom after mPreviewZoomOnly is set to false so that the
+                // new view size will be passed to the WebKit
+                setNewZoomScale(mActualScale, reflowNow, true);
+                // call invalidate() to draw without zoom filter
+                invalidate();
             }
-            setNewZoomScale(mActualScale, reflowNow, true);
-            // call invalidate() to draw without zoom filter
-            invalidate();
             // adjust the edit text view if needed
             if (inEditingMode()) {
                 adjustTextView(true);
@@ -3763,12 +3765,11 @@
                     * (y0 - y1));
             float scale = (float) (Math.round(distance / mPinchDistance
                     * mActualScale * 100) / 100.0);
-            long time = ev.getEventTime();
-            // add distance/time checking to avoid the minor shift right before
-            // lifting the fingers after a pause
-            if (Math.abs(scale - mActualScale) >= 0.01f
-                    && ((time - mLastTouchTime) < 300 || Math.abs(distance
-                            - mPinchDistance) > (10 * mDefaultScale))) {
+            float pressure = ev.getPressure(0) + ev.getPressure(1);
+            if (Math.abs(scale - mActualScale) >= SCALE_INCREMENT
+                    && (!mPreviewZoomOnly
+                    || (pressure / mLastPressure) > PRESSURE_THRESHOLD)) {
+                mPreviewZoomOnly = true;
                 // limit the scale change per step
                 if (scale > mActualScale) {
                     scale = Math.min(scale, mActualScale * 1.25f);
@@ -3780,7 +3781,7 @@
                 setNewZoomScale(scale, false, false);
                 invalidate();
                 mPinchDistance = distance;
-                mLastTouchTime = time;
+                mLastPressure = pressure;
             }
         } else {
             Log.w(LOGTAG, action + " should not happen during doMultiTouch");
@@ -3801,7 +3802,7 @@
         }
 
         if (mSupportMultiTouch && getSettings().supportZoom()
-                && ev.getPointerCount() > 1) {
+                && mMinZoomScale < mMaxZoomScale && ev.getPointerCount() > 1) {
             return doMultiTouch(ev);
         }
 
diff --git a/core/java/android/webkit/WebViewCore.java b/core/java/android/webkit/WebViewCore.java
index 27b67d1..c3817fb 100644
--- a/core/java/android/webkit/WebViewCore.java
+++ b/core/java/android/webkit/WebViewCore.java
@@ -1518,7 +1518,7 @@
             } else if (mViewportWidth > 0) {
                 width = Math.max(w, mViewportWidth);
             } else {
-                width = Math.max(w, nativeGetContentMinPrefWidth());
+                width = Math.max(w, textwrapWidth);
             }
         }
         nativeSetSize(width, width == w ? h : Math.round((float) width * h / w),