diff options
| author | Leon Scroggins <scroggo@google.com> | 2009-08-12 18:48:10 -0400 |
|---|---|---|
| committer | Leon Scroggins <scroggo@google.com> | 2009-08-13 14:21:24 -0400 |
| commit | 6679f2f70813eb93bf88297dc2de5e56bc7d7ca0 (patch) | |
| tree | c360a87363680a06eb68aa15aa6b17d59d2ee1b2 /core/java/android/webkit/WebTextView.java | |
| parent | da83f4674a564007baac03db062a289c8158d940 (diff) | |
Pass clicks to webkit's textfield to determine the new selection.
Requires a corresponding change to external/webkit. We were previously
letting WebTextView handle clicks, determine the change in selection,
and pass that down to webkit. This sometimes resulted in a different
placement of the caret if the WebTextView and the webkit-rendered
textfield did not line up exactly. Now, we pass the click directly
to webkit, which determines the new selection and passes that info
back to the WebTextView. This also has the benefit of letting
the WebTextView reflect changes in the selection that originated from
webkit. Also remove some unused parameters.
Diffstat (limited to 'core/java/android/webkit/WebTextView.java')
| -rw-r--r-- | core/java/android/webkit/WebTextView.java | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/core/java/android/webkit/WebTextView.java b/core/java/android/webkit/WebTextView.java index f22adb764df8..a1f2223412e7 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. |
