diff options
| author | Leon Scroggins <scroggo@google.com> | 2009-12-07 13:38:07 -0500 |
|---|---|---|
| committer | Leon Scroggins <scroggo@google.com> | 2009-12-07 16:36:34 -0500 |
| commit | aa7b9d78262b1df07a98bcf725958d418ff12ede (patch) | |
| tree | b47404aaa1cbc8576023d472945a4665e0aa021f /core/java/android/webkit/WebTextView.java | |
| parent | 14467eb2eea119b4d71dd7dd149479aa092e6de2 (diff) | |
| download | frameworks_base-aa7b9d78262b1df07a98bcf725958d418ff12ede.zip frameworks_base-aa7b9d78262b1df07a98bcf725958d418ff12ede.tar.gz frameworks_base-aa7b9d78262b1df07a98bcf725958d418ff12ede.tar.bz2 | |
Set InputType of WebTextView according to <input> field's type.
Help fix http://b/issue?id=2150538 and http://b/issue?id=1890360
Use the <input type> information to set the InputType, so that
the IME can show the correct options. Also consolidate setup
of WebTextView into setType().
Requires a change in external/webkit.
Diffstat (limited to 'core/java/android/webkit/WebTextView.java')
| -rw-r--r-- | core/java/android/webkit/WebTextView.java | 124 |
1 files changed, 85 insertions, 39 deletions
diff --git a/core/java/android/webkit/WebTextView.java b/core/java/android/webkit/WebTextView.java index 99b3f21..924398e 100644 --- a/core/java/android/webkit/WebTextView.java +++ b/core/java/android/webkit/WebTextView.java @@ -599,7 +599,8 @@ import java.util.ArrayList; */ public void setAdapterCustom(AutoCompleteAdapter adapter) { if (adapter != null) { - setInputType(EditorInfo.TYPE_TEXT_FLAG_AUTO_COMPLETE); + setInputType(getInputType() + | EditorInfo.TYPE_TEXT_FLAG_AUTO_COMPLETE); adapter.setTextView(this); } super.setAdapter(adapter); @@ -740,7 +741,7 @@ import java.util.ArrayList; mFromSetInputType = false; } - /* package */ void setMaxLength(int maxLength) { + private void setMaxLength(int maxLength) { mMaxLength = maxLength; if (-1 == maxLength) { setFilters(NO_FILTERS); @@ -805,56 +806,101 @@ import java.util.ArrayList; } /** - * 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. - * Do NOT call this after calling setInPassword(true). This will result in - * removing the password input type. + * Set the text to the new string, but use the old selection, making sure + * to keep it within the new string. + * @param text The new text to place in the textfield. */ - public void setSingleLine(boolean single) { + /* package */ void setTextAndKeepSelection(String text) { + mPreChange = text.toString(); + Editable edit = (Editable) getText(); + mInSetTextAndKeepSelection = true; + edit.replace(0, edit.length(), text); + mInSetTextAndKeepSelection = false; + updateCachedTextfield(); + } + + /** + * Called by WebView.rebuildWebTextView(). Based on the type of the <input> + * element, set up the WebTextView, its InputType, and IME Options properly. + * @param type int corresponding to enum "type" defined in WebView.cpp. + * Does not correspond to HTMLInputElement::InputType so this + * is unaffected if that changes, and also because that has no + * type corresponding to textarea (which is its own tag). + */ + /* package */ void setType(int type) { + if (mWebView == null) return; + boolean single = true; + boolean inPassword = false; + int maxLength = -1; int inputType = EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT; - 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); + switch (type) { + case 1: // TEXT_AREA + single = false; + inputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE + | EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES + | EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT; + setImeOptions(EditorInfo.IME_ACTION_NONE); break; - case -1: // FAILURE - case 2: // DONE - setImeOptions(EditorInfo.IME_ACTION_DONE); + case 2: // PASSWORD + inPassword = true; break; case 3: // SEARCH setImeOptions(EditorInfo.IME_ACTION_SEARCH); break; + case 4: // EMAIL + // TYPE_TEXT_VARIATION_WEB_EDIT_TEXT prevents EMAIL_ADDRESS + // from working, so exclude it for now. + inputType = EditorInfo.TYPE_CLASS_TEXT + | EditorInfo.TYPE_TEXT_VARIATION_EMAIL_ADDRESS; + break; + case 5: // NUMBER + inputType = EditorInfo.TYPE_CLASS_NUMBER; + break; + case 6: // TELEPHONE + inputType = EditorInfo.TYPE_CLASS_PHONE; + break; + case 7: // URL + // TYPE_TEXT_VARIATION_WEB_EDIT_TEXT prevents URI + // from working, so exclude it for now. + inputType = EditorInfo.TYPE_CLASS_TEXT + | EditorInfo.TYPE_TEXT_VARIATION_URI; + break; + default: + break; + } + if (single) { + maxLength = mWebView.nativeFocusCandidateMaxLength(); + if (type != 2 /* PASSWORD */) { + String name = mWebView.nativeFocusCandidateName(); + if (name != null && name.length() > 0) { + mWebView.requestFormData(name, mNodePointer); + } + } + if (type != 3 /* SEARCH */) { + 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; + setMaxLength(maxLength); setHorizontallyScrolling(single); setInputType(inputType); - } - - /** - * Set the text to the new string, but use the old selection, making sure - * to keep it within the new string. - * @param text The new text to place in the textfield. - */ - /* package */ void setTextAndKeepSelection(String text) { - mPreChange = text.toString(); - Editable edit = (Editable) getText(); - mInSetTextAndKeepSelection = true; - edit.replace(0, edit.length(), text); - mInSetTextAndKeepSelection = false; - updateCachedTextfield(); + setInPassword(inPassword); + AutoCompleteAdapter adapter = null; + setAdapterCustom(adapter); } /** |
