diff options
-rw-r--r-- | core/java/android/webkit/WebTextView.java | 25 | ||||
-rw-r--r-- | core/java/android/webkit/WebView.java | 49 | ||||
-rw-r--r-- | core/java/android/webkit/WebViewCore.java | 39 |
3 files changed, 83 insertions, 30 deletions
diff --git a/core/java/android/webkit/WebTextView.java b/core/java/android/webkit/WebTextView.java index f22adb7..a1f2223 100644 --- a/core/java/android/webkit/WebTextView.java +++ b/core/java/android/webkit/WebTextView.java @@ -85,6 +85,10 @@ import java.util.ArrayList; // happens, the next time the user hits a key it is okay for the focus // pointer to not match the WebTextView's node pointer private boolean mOkayForFocusNotToMatch; + // Whether or not a selection change was generated from webkit. If it was, + // we do not need to pass the selection back to webkit. + private boolean mFromWebKit; + private boolean mGotTouchDown; // Array to store the final character added in onTextChanged, so that its // KeyEvents may be determined. private char[] mCharacter = new char[1]; @@ -342,7 +346,7 @@ import java.util.ArrayList; @Override protected void onSelectionChanged(int selStart, int selEnd) { - if (mWebView != null) { + if (!mFromWebKit && mWebView != null) { if (DebugFlags.WEB_TEXT_VIEW) { Log.v(LOGTAG, "onSelectionChanged selStart=" + selStart + " selEnd=" + selEnd); @@ -423,6 +427,7 @@ import java.util.ArrayList; mDragStartTime = event.getEventTime(); mDragSent = false; mScrolled = false; + mGotTouchDown = true; break; case MotionEvent.ACTION_MOVE: Spannable buffer = getText(); @@ -456,14 +461,17 @@ import java.util.ArrayList; case MotionEvent.ACTION_CANCEL: if (!mScrolled) { // If the page scrolled, or the TextView scrolled, we do not - // want to change the selection, and the long press has already - // been canceled, so there is no need to call into super. - super.onTouchEvent(event); + // want to change the selection + cancelLongPress(); + if (mGotTouchDown && mWebView != null) { + mWebView.touchUpOnTextField(event); + } } // Necessary for the WebView to reset its state if (mWebView != null && mDragSent) { mWebView.onTouchEvent(event); } + mGotTouchDown = false; break; default: break; @@ -686,6 +694,15 @@ import java.util.ArrayList; } /** + * Set the selection, and disable our onSelectionChanged action. + */ + /* package */ void setSelectionFromWebKit(int start, int end) { + mFromWebKit = true; + Selection.setSelection((Spannable) getText(), start, end); + mFromWebKit = false; + } + + /** * Set whether this is a single-line textfield or a multi-line textarea. * Textfields scroll horizontally, and do not handle the enter key. * Textareas behave oppositely. diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java index 41ef31c..28e9b6d 100644 --- a/core/java/android/webkit/WebView.java +++ b/core/java/android/webkit/WebView.java @@ -466,7 +466,7 @@ public class WebView extends AbsoluteLayout static final int UPDATE_TEXTFIELD_TEXT_MSG_ID = 17; static final int MOVE_OUT_OF_PLUGIN = 19; static final int CLEAR_TEXT_ENTRY = 20; - + static final int UPDATE_TEXT_SELECTION_MSG_ID = 21; static final int UPDATE_CLIPBOARD = 22; static final int LONG_PRESS_CENTER = 23; static final int PREVENT_TOUCH_ID = 24; @@ -496,7 +496,7 @@ public class WebView extends AbsoluteLayout "18", // = 18; "MOVE_OUT_OF_PLUGIN", // = 19; "CLEAR_TEXT_ENTRY", // = 20; - "21", // = 21; + "UPDATE_TEXT_SELECTION_MSG_ID", // = 21; "UPDATE_CLIPBOARD", // = 22; "LONG_PRESS_CENTER", // = 23; "PREVENT_TOUCH_ID", // = 24; @@ -3065,12 +3065,10 @@ public class WebView extends AbsoluteLayout */ /* package */ void deleteSelection(int start, int end) { mTextGeneration++; - WebViewCore.DeleteSelectionData data - = new WebViewCore.DeleteSelectionData(); - data.mStart = start; - data.mEnd = end; - data.mTextGeneration = mTextGeneration; - mWebViewCore.sendMessage(EventHub.DELETE_SELECTION, data); + WebViewCore.TextSelectionData data + = new WebViewCore.TextSelectionData(start, end); + mWebViewCore.sendMessage(EventHub.DELETE_SELECTION, mTextGeneration, 0, + data); } /** @@ -4632,12 +4630,26 @@ public class WebView extends AbsoluteLayout return result; } + /** + * Do a touch up from a WebTextView. This will be handled by webkit to + * change the selection. + * @param event MotionEvent in the WebTextView's coordinates. + */ + /*package*/ void touchUpOnTextField(MotionEvent event) { + if (!inEditingMode()) { + return; + } + int x = viewToContent((int) event.getX() + mWebTextView.getLeft()); + int y = viewToContent((int) event.getY() + mWebTextView.getTop()); + nativeTextInputMotionUp(x, y); + } + /*package*/ void shortPressOnTextField() { if (inEditingMode()) { View v = mWebTextView; int x = viewToContent((v.getLeft() + v.getRight()) >> 1); int y = viewToContent((v.getTop() + v.getBottom()) >> 1); - nativeMotionUp(x, y, mNavSlop); + nativeTextInputMotionUp(x, y); } } @@ -5085,6 +5097,16 @@ public class WebView extends AbsoluteLayout } } break; + case UPDATE_TEXT_SELECTION_MSG_ID: + if (inEditingMode() + && mWebTextView.isSameTextField(msg.arg1) + && msg.arg2 == mTextGeneration) { + WebViewCore.TextSelectionData tData + = (WebViewCore.TextSelectionData) msg.obj; + mWebTextView.setSelectionFromWebKit(tData.mStart, + tData.mEnd); + } + break; case MOVE_OUT_OF_PLUGIN: if (nativePluginEatsNavKey()) { navHandledKey(msg.arg1, 1, false, 0, true); @@ -5449,10 +5471,9 @@ public class WebView extends AbsoluteLayout // called by JNI private void sendMotionUp(int touchGeneration, - int frame, int node, int x, int y, int size) { + int frame, int node, int x, int y) { WebViewCore.TouchUpData touchUpData = new WebViewCore.TouchUpData(); touchUpData.mMoveGeneration = touchGeneration; - touchUpData.mSize = size; touchUpData.mFrame = frame; touchUpData.mNode = node; touchUpData.mX = x; @@ -5651,6 +5672,12 @@ public class WebView extends AbsoluteLayout private native void nativeSetHeightCanMeasure(boolean measure); // Returns a value corresponding to CachedFrame::ImeAction /* package */ native int nativeTextFieldAction(); + /** + * Perform a click on a currently focused text input. Since it is already + * focused, there is no need to go through the nativeMotionUp code, which + * may change the Cursor. + */ + private native void nativeTextInputMotionUp(int x, int y); private native int nativeTextGeneration(); // Never call this version except by updateCachedTextfield(String) - // we always want to pass in our generation number. diff --git a/core/java/android/webkit/WebViewCore.java b/core/java/android/webkit/WebViewCore.java index 05464b5..0720beb 100644 --- a/core/java/android/webkit/WebViewCore.java +++ b/core/java/android/webkit/WebViewCore.java @@ -440,8 +440,7 @@ final class WebViewCore { private native String nativeRetrieveHref(int framePtr, int nodePtr); private native void nativeTouchUp(int touchGeneration, - int framePtr, int nodePtr, int x, int y, - int size); + int framePtr, int nodePtr, int x, int y); private native boolean nativeHandleTouchEvent(int action, int x, int y); @@ -611,12 +610,6 @@ final class WebViewCore { byte[] mPostData; } - static class DeleteSelectionData { - int mStart; - int mEnd; - int mTextGeneration; - } - static class ReplaceTextData { String mReplace; int mNewStart; @@ -624,13 +617,21 @@ final class WebViewCore { int mTextGeneration; } + static class TextSelectionData { + public TextSelectionData(int start, int end) { + mStart = start; + mEnd = end; + } + int mStart; + int mEnd; + } + static class TouchUpData { int mMoveGeneration; int mFrame; int mNode; int mX; int mY; - int mSize; } static class TouchEventData { @@ -1045,8 +1046,7 @@ final class WebViewCore { TouchUpData touchUpData = (TouchUpData) msg.obj; nativeTouchUp(touchUpData.mMoveGeneration, touchUpData.mFrame, touchUpData.mNode, - touchUpData.mX, touchUpData.mY, - touchUpData.mSize); + touchUpData.mX, touchUpData.mY); break; case TOUCH_EVENT: { @@ -1116,11 +1116,10 @@ final class WebViewCore { break; case DELETE_SELECTION: - DeleteSelectionData deleteSelectionData - = (DeleteSelectionData) msg.obj; + TextSelectionData deleteSelectionData + = (TextSelectionData) msg.obj; nativeDeleteSelection(deleteSelectionData.mStart, - deleteSelectionData.mEnd, - deleteSelectionData.mTextGeneration); + deleteSelectionData.mEnd, msg.arg1); break; case SET_SELECTION: @@ -1946,6 +1945,16 @@ final class WebViewCore { } // called by JNI + private void updateTextSelection(int pointer, int start, int end, + int textGeneration) { + if (mWebView != null) { + Message.obtain(mWebView.mPrivateHandler, + WebView.UPDATE_TEXT_SELECTION_MSG_ID, pointer, textGeneration, + new TextSelectionData(start, end)).sendToTarget(); + } + } + + // called by JNI private void clearTextEntry() { if (mWebView == null) return; Message.obtain(mWebView.mPrivateHandler, |