| Index: content/public/android/java/src/org/chromium/content/browser/input/ImeAdapter.java
|
| diff --git a/content/public/android/java/src/org/chromium/content/browser/input/ImeAdapter.java b/content/public/android/java/src/org/chromium/content/browser/input/ImeAdapter.java
|
| index cffc903183d58c4ed76675642a306f50251500bf..1126a8040b0798b581ada643248e9ef4208629d0 100644
|
| --- a/content/public/android/java/src/org/chromium/content/browser/input/ImeAdapter.java
|
| +++ b/content/public/android/java/src/org/chromium/content/browser/input/ImeAdapter.java
|
| @@ -8,6 +8,10 @@ import android.os.Handler;
|
| import android.os.ResultReceiver;
|
| import android.os.SystemClock;
|
| import android.text.Editable;
|
| +import android.text.SpannableString;
|
| +import android.text.style.BackgroundColorSpan;
|
| +import android.text.style.CharacterStyle;
|
| +import android.text.style.UnderlineSpan;
|
| import android.view.KeyCharacterMap;
|
| import android.view.KeyEvent;
|
| import android.view.View;
|
| @@ -15,6 +19,8 @@ import android.view.inputmethod.EditorInfo;
|
|
|
| import com.google.common.annotations.VisibleForTesting;
|
|
|
| +import java.lang.CharSequence;
|
| +
|
| import org.chromium.base.CalledByNative;
|
| import org.chromium.base.JNINamespace;
|
|
|
| @@ -325,14 +331,15 @@ public class ImeAdapter {
|
|
|
| // Calls from Java to C++
|
|
|
| - boolean checkCompositionQueueAndCallNative(String text, int newCursorPosition,
|
| + boolean checkCompositionQueueAndCallNative(CharSequence text, int newCursorPosition,
|
| boolean isCommit) {
|
| if (mNativeImeAdapterAndroid == 0) return false;
|
| + String textStr = text.toString();
|
|
|
| // Committing an empty string finishes the current composition.
|
| - boolean isFinish = text.isEmpty();
|
| + boolean isFinish = textStr.isEmpty();
|
| mViewEmbedder.onImeEvent(isFinish);
|
| - int keyCode = shouldSendKeyEventWithKeyCode(text);
|
| + int keyCode = shouldSendKeyEventWithKeyCode(textStr);
|
| long timeStampMs = SystemClock.uptimeMillis();
|
|
|
| if (keyCode != COMPOSITION_KEY_CODE) {
|
| @@ -342,9 +349,9 @@ public class ImeAdapter {
|
| nativeSendSyntheticKeyEvent(mNativeImeAdapterAndroid, sEventTypeRawKeyDown,
|
| timeStampMs, keyCode, 0);
|
| if (isCommit) {
|
| - nativeCommitText(mNativeImeAdapterAndroid, text);
|
| + nativeCommitText(mNativeImeAdapterAndroid, textStr);
|
| } else {
|
| - nativeSetComposingText(mNativeImeAdapterAndroid, text, newCursorPosition);
|
| + nativeSetComposingText(mNativeImeAdapterAndroid, text, textStr, newCursorPosition);
|
| }
|
| nativeSendSyntheticKeyEvent(mNativeImeAdapterAndroid, sEventTypeKeyUp,
|
| timeStampMs, keyCode, 0);
|
| @@ -517,6 +524,25 @@ public class ImeAdapter {
|
| }
|
|
|
| @CalledByNative
|
| + private void populateUnderlinesFromSpans(CharSequence text, long underlines) {
|
| + if (!(text instanceof SpannableString)) return;
|
| +
|
| + SpannableString spannableString = ((SpannableString) text);
|
| + CharacterStyle spans[] =
|
| + spannableString.getSpans(0, text.length(), CharacterStyle.class);
|
| + for (CharacterStyle span : spans) {
|
| + if (span instanceof BackgroundColorSpan) {
|
| + nativeAppendBackgroundColorSpan(underlines, spannableString.getSpanStart(span),
|
| + spannableString.getSpanEnd(span),
|
| + ((BackgroundColorSpan) span).getBackgroundColor());
|
| + } else if (span instanceof UnderlineSpan) {
|
| + nativeAppendUnderlineSpan(underlines, spannableString.getSpanStart(span),
|
| + spannableString.getSpanEnd(span));
|
| + }
|
| + }
|
| + }
|
| +
|
| + @CalledByNative
|
| private void cancelComposition() {
|
| if (mInputConnection != null) mInputConnection.restartInput();
|
| }
|
| @@ -535,10 +561,15 @@ public class ImeAdapter {
|
| int action, int modifiers, long timestampMs, int keyCode, boolean isSystemKey,
|
| int unicodeChar);
|
|
|
| - private native void nativeSetComposingText(long nativeImeAdapterAndroid, String text,
|
| - int newCursorPosition);
|
| + private static native void nativeAppendUnderlineSpan(long underlinePtr, int start, int end);
|
| +
|
| + private static native void nativeAppendBackgroundColorSpan(long underlinePtr, int start,
|
| + int end, int backgroundColor);
|
| +
|
| + private native void nativeSetComposingText(long nativeImeAdapterAndroid, CharSequence text,
|
| + String textStr, int newCursorPosition);
|
|
|
| - private native void nativeCommitText(long nativeImeAdapterAndroid, String text);
|
| + private native void nativeCommitText(long nativeImeAdapterAndroid, String textStr);
|
|
|
| private native void nativeFinishComposingText(long nativeImeAdapterAndroid);
|
|
|
|
|