am 6761e85d: Merge change Idff5eb2a into eclair-mr2

Merge commit '6761e85d41dedf4e783217922a5fedac2b7a654d' into eclair-mr2-plus-aosp

* commit '6761e85d41dedf4e783217922a5fedac2b7a654d':
  Set InputType of WebTextView according to <input> field's type.
This commit is contained in:
Leon Scroggins
2009-12-07 13:40:59 -08:00
committed by Android Git Automerger
2 changed files with 115 additions and 70 deletions

View File

@@ -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);
@@ -804,45 +805,6 @@ import java.util.ArrayList;
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.
* Do NOT call this after calling setInPassword(true). This will result in
* removing the password input type.
*/
public void setSingleLine(boolean single) {
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);
break;
case -1: // FAILURE
case 2: // DONE
setImeOptions(EditorInfo.IME_ACTION_DONE);
break;
case 3: // SEARCH
setImeOptions(EditorInfo.IME_ACTION_SEARCH);
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);
setInputType(inputType);
}
/**
* Set the text to the new string, but use the old selection, making sure
* to keep it within the new string.
@@ -857,6 +819,90 @@ import java.util.ArrayList;
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;
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 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;
}
}
}
mSingle = single;
setMaxLength(maxLength);
setHorizontallyScrolling(single);
setInputType(inputType);
setInPassword(inPassword);
AutoCompleteAdapter adapter = null;
setAdapterCustom(adapter);
}
/**
* Update the cache to reflect the current text.
*/

View File

@@ -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();