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

Commit 6761e85d authored by Android (Google) Code Review's avatar Android (Google) Code Review
Browse files

Merge change Idff5eb2a into eclair-mr2

* changes:
  Set InputType of WebTextView according to <input> field's type.
parents ddcea3d2 aa7b9d78
Loading
Loading
Loading
Loading
+85 −39
Original line number Diff line number Diff line
@@ -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,16 +806,78 @@ 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.
     */
    /* 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).
     */
    public void setSingleLine(boolean single) {
    /* 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
@@ -828,33 +891,16 @@ import java.util.ArrayList;
                    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;
        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);
    }

    /**
+28 −29
Original line number Diff line number Diff line
@@ -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();