am d5188657: Do a better job of lining up text with page text.

* commit 'd5188657dcde0f40a6954a00d569c0575bf6095a':
  Do a better job of lining up text with page text.
This commit is contained in:
Leon Scroggins
2011-01-21 12:59:05 -08:00
committed by Android Git Automerger
4 changed files with 62 additions and 44 deletions

View File

@@ -76,24 +76,6 @@ public class Touch {
widget.scrollTo(x, y);
}
/**
* @hide
* Returns the maximum scroll value in x.
*/
public static int getMaxScrollX(TextView widget, Layout layout, int y) {
int top = layout.getLineForVertical(y);
int bottom = layout.getLineForVertical(y + widget.getHeight()
- widget.getTotalPaddingTop() -widget.getTotalPaddingBottom());
int left = Integer.MAX_VALUE;
int right = 0;
for (int i = top; i <= bottom; i++) {
left = (int) Math.min(left, layout.getLineLeft(i));
right = (int) Math.max(right, layout.getLineRight(i));
}
return right - left - widget.getWidth() - widget.getTotalPaddingLeft()
- widget.getTotalPaddingRight();
}
/**
* Handles touch events for dragging. You may want to do other actions
* like moving the cursor on touch as well.

View File

@@ -135,7 +135,6 @@ import junit.framework.Assert;
// Used to determine whether onFocusChanged was called as a result of
// calling remove().
private boolean mInsideRemove;
private boolean mInPassword;
// Types used with setType. Keep in sync with CachedInput.h
private static final int NORMAL_TEXT_FIELD = 0;
@@ -374,18 +373,24 @@ import junit.framework.Assert;
}
/**
* Ensure that the underlying textfield is lined up with the WebTextView.
* Ensure that the underlying text field/area is lined up with the WebTextView.
*/
private void lineUpScroll() {
Layout layout = getLayout();
if (mWebView != null && layout != null) {
float maxScrollX = Touch.getMaxScrollX(this, layout, mScrollY);
if (DebugFlags.WEB_TEXT_VIEW) {
Log.v(LOGTAG, "onTouchEvent x=" + mScrollX + " y="
+ mScrollY + " maxX=" + maxScrollX);
if (mSingle) {
// textfields only need to be lined up horizontally.
float maxScrollX = layout.getLineRight(0) - getWidth();
if (DebugFlags.WEB_TEXT_VIEW) {
Log.v(LOGTAG, "onTouchEvent x=" + mScrollX + " y="
+ mScrollY + " maxX=" + maxScrollX);
}
mWebView.scrollFocusedTextInputX(maxScrollX > 0 ?
mScrollX / maxScrollX : 0);
} else {
// textareas only need to be lined up vertically.
mWebView.scrollFocusedTextInputY(mScrollY);
}
mWebView.scrollFocusedTextInput(maxScrollX > 0 ?
mScrollX / maxScrollX : 0, mScrollY);
}
}
@@ -414,6 +419,7 @@ import junit.framework.Assert;
mLayout.getSpacingAdd(), false, null, ellipsisWidth,
lineHeight);
}
lineUpScroll();
}
/**
@@ -786,10 +792,8 @@ import junit.framework.Assert;
}
@Override
public boolean bringPointIntoView(int offset) {
if (mInPassword) {
return getLayout() != null && super.bringPointIntoView(offset);
}
public boolean requestRectangleOnScreen(Rect rectangle, boolean immediate) {
// Do nothing, since webkit will put the textfield on screen.
return true;
}
@@ -904,7 +908,6 @@ import junit.framework.Assert;
* @param inPassword True if the textfield is a password field.
*/
/* package */ void setInPassword(boolean inPassword) {
mInPassword = inPassword;
if (inPassword) {
setInputType(EditorInfo.TYPE_CLASS_TEXT | EditorInfo.
TYPE_TEXT_VARIATION_WEB_PASSWORD);

View File

@@ -6616,22 +6616,33 @@ public class WebView extends AbsoluteLayout
}
/**
* Scroll the focused text field/area to match the WebTextView
* Scroll the focused text field to match the WebTextView
* @param xPercent New x position of the WebTextView from 0 to 1.
* @param y New y position of the WebTextView in view coordinates
*/
/*package*/ void scrollFocusedTextInput(float xPercent, int y) {
/*package*/ void scrollFocusedTextInputX(float xPercent) {
if (!inEditingMode() || mWebViewCore == null) {
return;
}
mWebViewCore.sendMessage(EventHub.SCROLL_TEXT_INPUT,
// 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),
mWebViewCore.sendMessage(EventHub.SCROLL_TEXT_INPUT, 0,
new Float(xPercent));
}
/**
* Scroll the focused textarea vertically to match the WebTextView
* @param y New y position of the WebTextView in view coordinates
*/
/* package */ void scrollFocusedTextInputY(int y) {
if (!inEditingMode()) {
return;
}
int xPos = viewToContentX((mWebTextView.getLeft() + mWebTextView.getRight()) / 2);
int yPos = viewToContentY((mWebTextView.getTop() + mWebTextView.getBottom()) / 2);
int layer = nativeScrollableLayer(xPos, yPos, null, null);
if (layer != 0) {
nativeScrollLayer(layer, 0, viewToContentDimension(y));
}
}
/**
* Set our starting point and time for a drag from the WebTextView.
*/
@@ -7967,15 +7978,27 @@ public class WebView extends AbsoluteLayout
}
}
// called by JNI
/**
* Called by JNI to send a message to the webcore thread that the user
* touched the webpage.
* @param touchGeneration Generation number of the touch, to ignore touches
* after a new one has been generated.
* @param frame Pointer to the frame holding the node that was touched.
* @param node Pointer to the node touched.
* @param x x-position of the touch.
* @param y y-position of the touch.
* @param scrollY Only used when touching on a textarea. Otherwise, use -1.
* Tells how much the textarea is scrolled.
*/
private void sendMotionUp(int touchGeneration,
int frame, int node, int x, int y) {
int frame, int node, int x, int y, int scrollY) {
WebViewCore.TouchUpData touchUpData = new WebViewCore.TouchUpData();
touchUpData.mMoveGeneration = touchGeneration;
touchUpData.mFrame = frame;
touchUpData.mNode = node;
touchUpData.mX = x;
touchUpData.mY = y;
touchUpData.mScrollY = scrollY;
mWebViewCore.sendMessage(EventHub.TOUCH_UP, touchUpData);
}
@@ -8301,5 +8324,12 @@ public class WebView extends AbsoluteLayout
// Returns a pointer to the scrollable LayerAndroid at the given point.
private native int nativeScrollableLayer(int x, int y, Rect scrollRect,
Rect scrollBounds);
private native boolean nativeScrollLayer(int layer, int dx, int dy);
/**
* Scroll the specified layer.
* @param layer Id of the layer to scroll, as determined by nativeScrollableLayer.
* @param newX Destination x position to which to scroll.
* @param newY Destination y position to which to scroll.
* @return True if the layer is successfully scrolled.
*/
private native boolean nativeScrollLayer(int layer, int newX, int newY);
}

View File

@@ -560,7 +560,7 @@ final class WebViewCore {
private native String nativeRetrieveImageSource(int x, int y);
private native void nativeTouchUp(int touchGeneration,
int framePtr, int nodePtr, int x, int y);
int framePtr, int nodePtr, int x, int y, int scrollY);
private native boolean nativeHandleTouchEvent(int action, int[] idArray,
int[] xArray, int[] yArray, int count, int metaState);
@@ -790,6 +790,8 @@ final class WebViewCore {
int mNode;
int mX;
int mY;
// Used in the case of a scrolled textarea
int mScrollY;
}
static class TouchHighlightData {
@@ -1321,7 +1323,8 @@ final class WebViewCore {
TouchUpData touchUpData = (TouchUpData) msg.obj;
nativeTouchUp(touchUpData.mMoveGeneration,
touchUpData.mFrame, touchUpData.mNode,
touchUpData.mX, touchUpData.mY);
touchUpData.mX, touchUpData.mY,
touchUpData.mScrollY);
break;
case TOUCH_EVENT: {