Exemple #1
0
  boolean checkCompositionQueueAndCallNative(String text, int newCursorPosition, boolean isCommit) {
    if (mNativeImeAdapterAndroid == 0) return false;

    // Committing an empty string finishes the current composition.
    boolean isFinish = text.isEmpty();
    mViewEmbedder.onImeEvent(isFinish);
    int keyCode = shouldSendKeyEventWithKeyCode(text);
    long timeStampMs = System.currentTimeMillis();

    if (keyCode != COMPOSITION_KEY_CODE) {
      sendKeyEventWithKeyCode(keyCode, KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE);
    } else {
      nativeSendSyntheticKeyEvent(
          mNativeImeAdapterAndroid, sEventTypeRawKeyDown, timeStampMs, keyCode, 0);
      if (isCommit) {
        nativeCommitText(mNativeImeAdapterAndroid, text);
      } else {
        nativeSetComposingText(mNativeImeAdapterAndroid, text, newCursorPosition);
      }
      nativeSendSyntheticKeyEvent(
          mNativeImeAdapterAndroid, sEventTypeKeyUp, timeStampMs, keyCode, 0);
    }

    return true;
  }
  boolean sendCompositionToNative(CharSequence text, int newCursorPosition, boolean isCommit) {
    if (mNativeImeAdapterAndroid == 0) return false;
    mViewEmbedder.onImeEvent();

    long timestampMs = SystemClock.uptimeMillis();
    nativeSendSyntheticKeyEvent(
        mNativeImeAdapterAndroid,
        WebInputEventType.RawKeyDown,
        timestampMs,
        COMPOSITION_KEY_CODE,
        0,
        0);

    if (isCommit) {
      nativeCommitText(mNativeImeAdapterAndroid, text.toString());
    } else {
      nativeSetComposingText(mNativeImeAdapterAndroid, text, text.toString(), newCursorPosition);
    }

    nativeSendSyntheticKeyEvent(
        mNativeImeAdapterAndroid, WebInputEventType.KeyUp, timestampMs, COMPOSITION_KEY_CODE, 0, 0);
    return true;
  }