summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
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
commitaa7b9d78262b1df07a98bcf725958d418ff12ede (patch)
treeb47404aaa1cbc8576023d472945a4665e0aa021f
parent14467eb2eea119b4d71dd7dd149479aa092e6de2 (diff)
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.
-rw-r--r--core/java/android/webkit/WebTextView.java124
-rw-r--r--core/java/android/webkit/WebView.java57
2 files changed, 113 insertions, 68 deletions
diff --git a/core/java/android/webkit/WebTextView.java b/core/java/android/webkit/WebTextView.java
index 99b3f21b7af9..924398eba84f 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);
}
/**
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index 7885b8ac39b4..3be6a3fdc9b2 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -3236,34 +3236,10 @@ public class WebView extends AbsoluteLayout
vBox.height());
mWebTextView.setGravity(nativeFocusCandidateIsRtlText() ?
Gravity.RIGHT : Gravity.NO_GRAVITY);
- // this needs to be called before update adapter thread starts to
- // ensure the mWebTextView has the same node pointer
+ // This needs to be called before setType, which may call
+ // requestFormData, and it needs to have the correct nodePointer.
mWebTextView.setNodePointer(nodePointer);
- int maxLength = -1;
- boolean isTextField = nativeFocusCandidateIsTextField();
- boolean isPassword;
- if (isTextField) {
- maxLength = nativeFocusCandidateMaxLength();
- String name = nativeFocusCandidateName();
- isPassword = nativeFocusCandidateIsPassword();
- if (!isPassword && mWebViewCore.getSettings().getSaveFormData()
- && name != null && name.length() > 0) {
- Message update = mPrivateHandler.obtainMessage(
- REQUEST_FORM_DATA);
- update.arg1 = nodePointer;
- RequestFormData updater = new RequestFormData(name,
- getUrl(), update);
- Thread t = new Thread(updater);
- t.start();
- }
- } else {
- isPassword = false;
- }
- mWebTextView.setMaxLength(maxLength);
- AutoCompleteAdapter adapter = null;
- mWebTextView.setAdapterCustom(adapter);
- mWebTextView.setSingleLine(isTextField);
- mWebTextView.setInPassword(isPassword);
+ mWebTextView.setType(nativeFocusCandidateType());
if (null == text) {
if (DebugFlags.WEB_VIEW) {
Log.v(LOGTAG, "rebuildWebTextView null == text");
@@ -3275,6 +3251,25 @@ public class WebView extends AbsoluteLayout
}
}
+ /**
+ * Called by WebTextView to find saved form data associated with the
+ * textfield
+ * @param name Name of the textfield.
+ * @param nodePointer Pointer to the node of the textfield, so it can be
+ * compared to the currently focused textfield when the data is
+ * retrieved.
+ */
+ /* package */ void requestFormData(String name, int nodePointer) {
+ if (mWebViewCore.getSettings().getSaveFormData()) {
+ Message update = mPrivateHandler.obtainMessage(REQUEST_FORM_DATA);
+ update.arg1 = nodePointer;
+ RequestFormData updater = new RequestFormData(name, getUrl(),
+ update);
+ Thread t = new Thread(updater);
+ t.start();
+ }
+ }
+
/*
* This class requests an Adapter for the WebTextView which shows past
* entries stored in the database. It is a Runnable so that it can be done
@@ -5914,14 +5909,18 @@ public class WebView extends AbsoluteLayout
private native boolean nativeFocusCandidateIsPassword();
private native boolean nativeFocusCandidateIsPlugin();
private native boolean nativeFocusCandidateIsRtlText();
- private native boolean nativeFocusCandidateIsTextField();
private native boolean nativeFocusCandidateIsTextInput();
- private native int nativeFocusCandidateMaxLength();
+ /* package */ native int nativeFocusCandidateMaxLength();
/* package */ native String nativeFocusCandidateName();
private native Rect nativeFocusCandidateNodeBounds();
/* package */ native int nativeFocusCandidatePointer();
private native String nativeFocusCandidateText();
private native int nativeFocusCandidateTextSize();
+ /**
+ * Returns an integer corresponding to WebView.cpp::type.
+ * See WebTextView.setType()
+ */
+ private native int nativeFocusCandidateType();
private native boolean nativeFocusIsPlugin();
/* package */ native int nativeFocusNodePointer();
private native Rect nativeGetCursorRingBounds();