diff options
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/webkit/WebTextView.java | 16 | ||||
| -rw-r--r-- | core/java/android/webkit/WebView.java | 91 | ||||
| -rw-r--r-- | core/java/android/webkit/WebViewCore.java | 27 |
3 files changed, 113 insertions, 21 deletions
diff --git a/core/java/android/webkit/WebTextView.java b/core/java/android/webkit/WebTextView.java index 2b59b80cd889..510c1685bcae 100644 --- a/core/java/android/webkit/WebTextView.java +++ b/core/java/android/webkit/WebTextView.java @@ -160,14 +160,14 @@ import java.util.ArrayList; private MyResultReceiver mReceiver; // Types used with setType. Keep in sync with CachedInput.h - private static final int NORMAL_TEXT_FIELD = 0; - private static final int TEXT_AREA = 1; - private static final int PASSWORD = 2; - private static final int SEARCH = 3; - private static final int EMAIL = 4; - private static final int NUMBER = 5; - private static final int TELEPHONE = 6; - private static final int URL = 7; + static final int NORMAL_TEXT_FIELD = 0; + static final int TEXT_AREA = 1; + static final int PASSWORD = 2; + static final int SEARCH = 3; + static final int EMAIL = 4; + static final int NUMBER = 5; + static final int TELEPHONE = 6; + static final int URL = 7; private static final int AUTOFILL_FORM = 100; private Handler mHandler; diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java index 3dbe66d3127a..6dc3be540f0e 100644 --- a/core/java/android/webkit/WebView.java +++ b/core/java/android/webkit/WebView.java @@ -98,6 +98,7 @@ import android.view.inputmethod.InputMethodManager; import android.webkit.WebTextView.AutoCompleteAdapter; import android.webkit.WebViewCore.DrawData; import android.webkit.WebViewCore.EventHub; +import android.webkit.WebViewCore.TextFieldInitData; import android.webkit.WebViewCore.TouchEventData; import android.webkit.WebViewCore.TouchHighlightData; import android.webkit.WebViewCore.WebKitHitTest; @@ -371,6 +372,9 @@ public class WebView extends AbsoluteLayout // Used for mapping characters to keys typed. private KeyCharacterMap mKeyCharacterMap; private boolean mIsKeySentByMe; + private int mInputType; + private int mImeOptions; + private String mHint; public WebViewInputConnection() { super(WebView.this, true); @@ -452,6 +456,77 @@ public class WebView extends AbsoluteLayout return super.deleteSurroundingText(leftLength, rightLength); } + public void initEditorInfo(WebViewCore.TextFieldInitData initData) { + int type = initData.mType; + int inputType = InputType.TYPE_CLASS_TEXT + | InputType.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT; + int imeOptions = EditorInfo.IME_FLAG_NO_EXTRACT_UI + | EditorInfo.IME_FLAG_NO_FULLSCREEN; + if (!initData.mIsSpellCheckEnabled) { + inputType |= InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS; + } + if (WebTextView.TEXT_AREA != type + && initData.mIsTextFieldNext) { + imeOptions |= EditorInfo.IME_FLAG_NAVIGATE_NEXT; + } + switch (type) { + case WebTextView.NORMAL_TEXT_FIELD: + imeOptions |= EditorInfo.IME_ACTION_GO; + break; + case WebTextView.TEXT_AREA: + inputType |= InputType.TYPE_TEXT_FLAG_MULTI_LINE + | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES + | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT; + imeOptions |= EditorInfo.IME_ACTION_NONE; + break; + case WebTextView.PASSWORD: + inputType |= EditorInfo.TYPE_TEXT_VARIATION_WEB_PASSWORD; + imeOptions |= EditorInfo.IME_ACTION_GO; + break; + case WebTextView.SEARCH: + imeOptions |= EditorInfo.IME_ACTION_SEARCH; + break; + case WebTextView.EMAIL: + // inputType needs to be overwritten because of the different text variation. + inputType = InputType.TYPE_CLASS_TEXT + | InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS; + imeOptions |= EditorInfo.IME_ACTION_GO; + break; + case WebTextView.NUMBER: + // inputType needs to be overwritten because of the different class. + inputType = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_NORMAL + | InputType.TYPE_NUMBER_FLAG_SIGNED | InputType.TYPE_NUMBER_FLAG_DECIMAL; + // Number and telephone do not have both a Tab key and an + // action, so set the action to NEXT + imeOptions |= EditorInfo.IME_ACTION_NEXT; + break; + case WebTextView.TELEPHONE: + // inputType needs to be overwritten because of the different class. + inputType = InputType.TYPE_CLASS_PHONE; + imeOptions |= EditorInfo.IME_ACTION_NEXT; + break; + case WebTextView.URL: + // TYPE_TEXT_VARIATION_URI prevents Tab key from showing, so + // exclude it for now. + imeOptions |= EditorInfo.IME_ACTION_GO; + inputType |= InputType.TYPE_TEXT_VARIATION_URI; + break; + default: + imeOptions |= EditorInfo.IME_ACTION_GO; + break; + } + mHint = initData.mLabel; + mInputType = inputType; + mImeOptions = imeOptions; + } + + public void setupEditorInfo(EditorInfo outAttrs) { + outAttrs.inputType = mInputType; + outAttrs.imeOptions = mImeOptions; + outAttrs.hintText = mHint; + outAttrs.initialCapsMode = getCursorCapsMode(InputType.TYPE_CLASS_TEXT); + } + /** * Sends a text change to webkit indirectly. If it is a single- * character add or delete, it sends it as a key stroke. If it cannot @@ -5159,18 +5234,10 @@ public class WebView extends AbsoluteLayout @Override public InputConnection onCreateInputConnection(EditorInfo outAttrs) { - outAttrs.inputType = EditorInfo.IME_FLAG_NO_FULLSCREEN - | EditorInfo.TYPE_CLASS_TEXT - | EditorInfo.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT - | EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE - | EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT - | EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES; - outAttrs.imeOptions = EditorInfo.IME_ACTION_NONE; - if (mInputConnection == null) { mInputConnection = new WebViewInputConnection(); } - outAttrs.initialCapsMode = mInputConnection.getCursorCapsMode(InputType.TYPE_CLASS_TEXT); + mInputConnection.setupEditorInfo(outAttrs); return mInputConnection; } @@ -9081,9 +9148,11 @@ public class WebView extends AbsoluteLayout case INIT_EDIT_FIELD: if (mInputConnection != null) { + TextFieldInitData initData = (TextFieldInitData) msg.obj; mTextGeneration = 0; - mFieldPointer = msg.arg1; - mInputConnection.setTextAndKeepSelection((String) msg.obj); + mFieldPointer = initData.mFieldPointer; + mInputConnection.initEditorInfo(initData); + mInputConnection.setTextAndKeepSelection(initData.mText); } break; diff --git a/core/java/android/webkit/WebViewCore.java b/core/java/android/webkit/WebViewCore.java index ee27dd4b67ac..84f0b9c845e5 100644 --- a/core/java/android/webkit/WebViewCore.java +++ b/core/java/android/webkit/WebViewCore.java @@ -919,6 +919,25 @@ public final class WebViewCore { private String mPreview; } + static class TextFieldInitData { + public TextFieldInitData(int fieldPointer, + String text, int type, boolean isSpellCheckEnabled, + boolean isTextFieldNext, String label) { + mFieldPointer = fieldPointer; + mText = text; + mType = type; + mIsSpellCheckEnabled = isSpellCheckEnabled; + mIsTextFieldNext = isTextFieldNext; + mLabel = label; + } + int mFieldPointer; + String mText; + int mType; + boolean mIsSpellCheckEnabled; + boolean mIsTextFieldNext; + String mLabel; + } + // mAction of TouchEventData can be MotionEvent.getAction() which uses the // last two bytes or one of the following values static final int ACTION_LONGPRESS = 0x100; @@ -2813,12 +2832,16 @@ public final class WebViewCore { } // called by JNI - private void initEditField(int pointer, String text, int start, int end) { + private void initEditField(int pointer, String text, int inputType, + boolean isSpellCheckEnabled, boolean nextFieldIsText, + String label, int start, int end) { if (mWebView == null) { return; } + TextFieldInitData initData = new TextFieldInitData(pointer, + text, inputType, isSpellCheckEnabled, nextFieldIsText, label); Message.obtain(mWebView.mPrivateHandler, - WebView.INIT_EDIT_FIELD, pointer, 0, text).sendToTarget(); + WebView.INIT_EDIT_FIELD, initData).sendToTarget(); Message.obtain(mWebView.mPrivateHandler, WebView.REQUEST_KEYBOARD_WITH_SELECTION_MSG_ID, pointer, 0, new TextSelectionData(start, end, 0)) |
