Make scrolling textfields work better in the browser.

The touch slop seems to be too large for scrolling
a small textfield, so use a smaller number.  Also,
in WebView, create viewToContentDimension, and use
it for determining the scroll position of the text
field.

Partial fix for http://b/issue?id=2133049

Change-Id: I0ded3be264b179bad39301e6adce86851b649a42
diff --git a/core/java/android/webkit/WebTextView.java b/core/java/android/webkit/WebTextView.java
index 39a2470..1a65ce8 100644
--- a/core/java/android/webkit/WebTextView.java
+++ b/core/java/android/webkit/WebTextView.java
@@ -448,8 +448,13 @@
             int initialScrollX = Touch.getInitialScrollX(this, buffer);
             int initialScrollY = Touch.getInitialScrollY(this, buffer);
             super.onTouchEvent(event);
-            if (Math.abs(mScrollX - initialScrollX) > slop
-                    || Math.abs(mScrollY - initialScrollY) > slop) {
+            int dx = Math.abs(mScrollX - initialScrollX);
+            int dy = Math.abs(mScrollY - initialScrollY);
+            // Use a smaller slop when checking to see if we've moved far enough
+            // to scroll the text, because experimentally, slop has shown to be
+            // to big for the case of a small textfield.
+            int smallerSlop = slop/2;
+            if (dx > smallerSlop || dy > smallerSlop) {
                 if (mWebView != null) {
                     mWebView.scrollFocusedTextInput(mScrollX, mScrollY);
                 }
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index 95e2e43..eaf6c05 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -1782,12 +1782,22 @@
     }
 
     /**
+     * Given a distance in view space, convert it to content space. Note: this
+     * does not reflect translation, just scaling, so this should not be called
+     * with coordinates, but should be called for dimensions like width or
+     * height.
+     */
+    private int viewToContentDimension(int d) {
+        return Math.round(d * mInvActualScale);
+    }
+
+    /**
      * Given an x coordinate in view space, convert it to content space.  Also
      * may be used for absolute heights (such as for the WebTextView's
      * textSize, which is unaffected by the height of the title bar).
      */
     /*package*/ int viewToContentX(int x) {
-        return Math.round(x * mInvActualScale);
+        return viewToContentDimension(x);
     }
 
     /**
@@ -1796,7 +1806,7 @@
      * embedded into the WebView.
      */
     /*package*/ int viewToContentY(int y) {
-        return viewToContentX(y - getTitleHeight());
+        return viewToContentDimension(y - getTitleHeight());
     }
 
     /**
@@ -1811,7 +1821,7 @@
 
     /**
      * Given an x coordinate in content space, convert it to view
-     * space.  Also used for absolute heights.
+     * space.
      */
     /*package*/ int contentToViewX(int x) {
         return contentToViewDimension(x);
@@ -4445,7 +4455,10 @@
             return;
         }
         mWebViewCore.sendMessage(EventHub.SCROLL_TEXT_INPUT, viewToContentX(x),
-                viewToContentY(y));
+                // Since this position is relative to the top of the text input
+                // field, we do not need to take the title bar's height into
+                // consideration.
+                viewToContentDimension(y));
     }
 
     /**