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

Commit ff328ae7 authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Add FLAG_CURSOR_ANCHOR_INFO_IMMEDIATE support in TextView

This CL adds an initial support of
CursorAnchorInfoRequest#FLAG_CURSOR_ANCHOR_INFO_IMMEDIATE for
TextView.

This implementation is not highly optimized yet, but it just
works as it should.

BUG: 16379288
Change-Id: Iecb32b4c4dcd7db14d8b2a0d929e1d64e161bc58
parent c01bd116
Loading
Loading
Loading
Loading
+13 −6
Original line number Diff line number Diff line
@@ -435,13 +435,20 @@ public class BaseInputConnection implements InputConnection {
     * {@link CursorAnchorInfoRequest#TYPE_CURSOR_RECT}.
     */
    public int requestCursorAnchorInfo(CursorAnchorInfoRequest request) {
        if (request != null && mIMM != null &&
                request.getRequestType() == CursorAnchorInfoRequest.TYPE_CURSOR_RECT) {
            mIMM.setCursorRectMonitorMode(request.getRequestFlags());
            return CursorAnchorInfoRequest.RESULT_SCHEDULED;
        // This implementation supports TYPE_CURSOR_RECT only.
        if (request == null ||
                request.getRequestType() != CursorAnchorInfoRequest.TYPE_CURSOR_RECT) {
            return CursorAnchorInfoRequest.RESULT_NOT_HANDLED;
        }
        if (mIMM == null) {
            // In this case, TYPE_CURSOR_RECT is not handled.
            // TODO: Return some notification code for the input method that indicates
            // Cursor rect information is temporarily unavailable.
            return CursorAnchorInfoRequest.RESULT_NOT_HANDLED;
        }
        mIMM.setCursorRectMonitorMode(request.getRequestFlags());
        return CursorAnchorInfoRequest.RESULT_SCHEDULED;
    }

    /**
     * The default implementation places the given text into the editable,
+30 −8
Original line number Diff line number Diff line
@@ -190,14 +190,36 @@ public class EditableInputConnection extends BaseInputConnection {
    @Override
    public int requestCursorAnchorInfo(CursorAnchorInfoRequest request) {
        if (DEBUG) Log.v(TAG, "requestCursorAnchorInfo " + request);
        final int result = super.requestCursorAnchorInfo(request);
        if (mIMM != null && request != null && (request.getRequestType() ==
                CursorAnchorInfoRequest.TYPE_CURSOR_ANCHOR_INFO)) {
            mIMM.setCursorAnchorInfoMonitorMode(request.getRequestFlags());
            // One-shot event is not yet fully supported.
            // TODO: Support one-shot event correctly.
            return CursorAnchorInfoRequest.RESULT_SCHEDULED;

        // This implementation supports TYPE_CURSOR_ANCHOR_INFO only. Other events will be
        // delegated to the super class.
        if (request == null ||
                request.getRequestType() != CursorAnchorInfoRequest.TYPE_CURSOR_ANCHOR_INFO) {
            return super.requestCursorAnchorInfo(request);
        }
        if (mIMM == null) {
            // In this case, TYPE_CURSOR_ANCHOR_INFO is not handled.
            // TODO: Return some notification code for the input method that indicates
            // CursorAnchorInfo is temporarily unavailable.
            return CursorAnchorInfoRequest.RESULT_NOT_HANDLED;
        }
        final int flags = request.getRequestFlags();
        mIMM.setCursorAnchorInfoMonitorMode(flags);
        if ((flags & CursorAnchorInfoRequest.FLAG_CURSOR_ANCHOR_INFO_IMMEDIATE) != 0) {
            if (mTextView == null) {
                // In this case, FLAG_CURSOR_ANCHOR_INFO_IMMEDIATE is silently ignored.
                // TODO: Return some notification code for the input method that indicates
                // FLAG_CURSOR_ANCHOR_INFO_IMMEDIATE is ignored.
            } else if (mTextView.isInLayout()) {
                // In this case, the view hierarchy is currently undergoing a layout pass.
                // IMM#updateCursorAnchorInfo is supposed to be called soon after the layout
                // pass is finished.
            } else {
                // This will schedule a layout pass of the view tree, and the layout event
                // eventually triggers IMM#updateCursorAnchorInfo.
                mTextView.requestLayout();
            }
        return result;
        }
        return CursorAnchorInfoRequest.RESULT_SCHEDULED;
    }
}