Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0b2cfd8c authored by George Mount's avatar George Mount
Browse files

Use input type for IME options.

 Bug 5987568
 Get the text type from webkit when initializing the field for
 text entry and use that type to specify the IME input type
 and options.
 Webkit Change: I7eceafdbede8b7b463590a2e875a237241479ad1

Change-Id: Ic8c14687a70727148dfc8115c46f09530ca0c0f6
parent d3fcaa45
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -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;
+80 −11
Original line number Diff line number Diff line
@@ -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;

+25 −2
Original line number Diff line number Diff line
@@ -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))