diff options
| author | Leon Scroggins <scroggo@google.com> | 2009-07-30 16:33:56 -0400 |
|---|---|---|
| committer | Leon Scroggins <scroggo@google.com> | 2009-07-31 10:54:38 -0400 |
| commit | 010582885cbd5e1becadd6c53816c399465b459d (patch) | |
| tree | 244f84ea4be91fc1af3f380c281502baf56d2426 /core/java/android/webkit/WebTextView.java | |
| parent | ed9584068144adedfdd6d119e2f928da595a1953 (diff) | |
Allow the user to jump to the next textfield.
Requires a change to external/webkit. Set ImeActions for textfields,
depending on the existence of other textfields on the page, and
react accordingly.
Diffstat (limited to 'core/java/android/webkit/WebTextView.java')
| -rw-r--r-- | core/java/android/webkit/WebTextView.java | 60 |
1 files changed, 56 insertions, 4 deletions
diff --git a/core/java/android/webkit/WebTextView.java b/core/java/android/webkit/WebTextView.java index 7bc154b68857..f22adb764df8 100644 --- a/core/java/android/webkit/WebTextView.java +++ b/core/java/android/webkit/WebTextView.java @@ -81,6 +81,10 @@ import java.util.ArrayList; // True if the most recent drag event has caused either the TextView to // scroll or the web page to scroll. Gets reset after a touch down. private boolean mScrolled; + // Gets set to true when the the IME jumps to the next textfield. When this + // 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; // Array to store the final character added in onTextChanged, so that its // KeyEvents may be determined. private char[] mCharacter = new char[1]; @@ -99,7 +103,6 @@ import java.util.ArrayList; super(context); mWebView = webView; mMaxLength = -1; - setImeOptions(EditorInfo.IME_ACTION_NONE); } @Override @@ -125,8 +128,8 @@ import java.util.ArrayList; isArrowKey = true; break; } - - if (!isArrowKey && mWebView.nativeFocusNodePointer() != mNodePointer) { + if (!isArrowKey && !mOkayForFocusNotToMatch + && mWebView.nativeFocusNodePointer() != mNodePointer) { mWebView.nativeClearCursor(); // Do not call remove() here, which hides the soft keyboard. If // the soft keyboard is being displayed, the user will still want @@ -135,6 +138,9 @@ import java.util.ArrayList; mWebView.requestFocus(); return mWebView.dispatchKeyEvent(event); } + // After a jump to next textfield and the first key press, the cursor + // and focus will once again match, so reset this value. + mOkayForFocusNotToMatch = false; Spannable text = (Spannable) getText(); int oldLength = text.length(); @@ -305,6 +311,36 @@ import java.util.ArrayList; } @Override + public void onEditorAction(int actionCode) { + switch (actionCode) { + case EditorInfo.IME_ACTION_NEXT: + mWebView.nativeMoveCursorToNextTextInput(); + // Preemptively rebuild the WebTextView, so that the action will + // be set properly. + mWebView.rebuildWebTextView(); + // Since the cursor will no longer be in the same place as the + // focus, set the focus controller back to inactive + mWebView.setFocusControllerInactive(); + mOkayForFocusNotToMatch = true; + break; + case EditorInfo.IME_ACTION_DONE: + super.onEditorAction(actionCode); + break; + case EditorInfo.IME_ACTION_GO: + // Send an enter and hide the soft keyboard + InputMethodManager.getInstance(mContext) + .hideSoftInputFromWindow(getWindowToken(), 0); + sendDomEvent(new KeyEvent(KeyEvent.ACTION_DOWN, + KeyEvent.KEYCODE_ENTER)); + sendDomEvent(new KeyEvent(KeyEvent.ACTION_UP, + KeyEvent.KEYCODE_ENTER)); + + default: + break; + } + } + + @Override protected void onSelectionChanged(int selStart, int selEnd) { if (mWebView != null) { if (DebugFlags.WEB_TEXT_VIEW) { @@ -659,10 +695,26 @@ import java.util.ArrayList; public void setSingleLine(boolean single) { int inputType = EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT; - if (!single) { + if (single) { + int action = mWebView.nativeTextFieldAction(); + switch (action) { + // Keep in sync with CachedRoot::ImeAction + case 0: // NEXT + setImeOptions(EditorInfo.IME_ACTION_NEXT); + break; + case 1: // GO + setImeOptions(EditorInfo.IME_ACTION_GO); + break; + case -1: // FAILURE + case 2: // DONE + setImeOptions(EditorInfo.IME_ACTION_DONE); + break; + } + } else { inputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE | EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES | EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT; + setImeOptions(EditorInfo.IME_ACTION_NONE); } mSingle = single; setHorizontallyScrolling(single); |
