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
This commit is contained in:
@@ -448,8 +448,13 @@ import java.util.ArrayList;
|
|||||||
int initialScrollX = Touch.getInitialScrollX(this, buffer);
|
int initialScrollX = Touch.getInitialScrollX(this, buffer);
|
||||||
int initialScrollY = Touch.getInitialScrollY(this, buffer);
|
int initialScrollY = Touch.getInitialScrollY(this, buffer);
|
||||||
super.onTouchEvent(event);
|
super.onTouchEvent(event);
|
||||||
if (Math.abs(mScrollX - initialScrollX) > slop
|
int dx = Math.abs(mScrollX - initialScrollX);
|
||||||
|| Math.abs(mScrollY - initialScrollY) > slop) {
|
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) {
|
if (mWebView != null) {
|
||||||
mWebView.scrollFocusedTextInput(mScrollX, mScrollY);
|
mWebView.scrollFocusedTextInput(mScrollX, mScrollY);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1781,13 +1781,23 @@ public class WebView extends AbsoluteLayout
|
|||||||
mTitleBar = v;
|
mTitleBar = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
* 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
|
* may be used for absolute heights (such as for the WebTextView's
|
||||||
* textSize, which is unaffected by the height of the title bar).
|
* textSize, which is unaffected by the height of the title bar).
|
||||||
*/
|
*/
|
||||||
/*package*/ int viewToContentX(int x) {
|
/*package*/ int viewToContentX(int x) {
|
||||||
return Math.round(x * mInvActualScale);
|
return viewToContentDimension(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1796,7 +1806,7 @@ public class WebView extends AbsoluteLayout
|
|||||||
* embedded into the WebView.
|
* embedded into the WebView.
|
||||||
*/
|
*/
|
||||||
/*package*/ int viewToContentY(int y) {
|
/*package*/ int viewToContentY(int y) {
|
||||||
return viewToContentX(y - getTitleHeight());
|
return viewToContentDimension(y - getTitleHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1811,7 +1821,7 @@ public class WebView extends AbsoluteLayout
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Given an x coordinate in content space, convert it to view
|
* Given an x coordinate in content space, convert it to view
|
||||||
* space. Also used for absolute heights.
|
* space.
|
||||||
*/
|
*/
|
||||||
/*package*/ int contentToViewX(int x) {
|
/*package*/ int contentToViewX(int x) {
|
||||||
return contentToViewDimension(x);
|
return contentToViewDimension(x);
|
||||||
@@ -4445,7 +4455,10 @@ public class WebView extends AbsoluteLayout
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mWebViewCore.sendMessage(EventHub.SCROLL_TEXT_INPUT, viewToContentX(x),
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user