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 bfc8ea5b419112ed1af2c03d68581aa3ce044af8..0bbf8e431b40f868c197f011220299957b5d97d7 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,8 @@ 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.view.KeyCharacterMap; |
import android.view.KeyEvent; |
import android.view.View; |
@@ -328,14 +330,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) { |
@@ -345,9 +348,17 @@ public class ImeAdapter { |
nativeSendSyntheticKeyEvent(mNativeImeAdapterAndroid, sEventTypeRawKeyDown, |
timeStampMs, keyCode, 0); |
if (isCommit) { |
- nativeCommitText(mNativeImeAdapterAndroid, text); |
+ nativeCommitText(mNativeImeAdapterAndroid, textStr); |
} else { |
- nativeSetComposingText(mNativeImeAdapterAndroid, text, newCursorPosition); |
+ SpannableString ss = null; |
+ Object[] spans = null; |
+ if (text instanceof SpannableString) { |
+ ss = ((SpannableString) text); |
+ // Retrieves spans since it's much easier here than using JNI. |
+ spans = ss.getSpans(0, textStr.length(), Object.class); |
+ } |
+ nativeSetComposingText(mNativeImeAdapterAndroid, textStr, newCursorPosition, |
+ ss, spans); |
} |
nativeSendSyntheticKeyEvent(mNativeImeAdapterAndroid, sEventTypeKeyUp, |
timeStampMs, keyCode, 0); |
@@ -539,7 +550,7 @@ public class ImeAdapter { |
int unicodeChar); |
private native void nativeSetComposingText(long nativeImeAdapterAndroid, String text, |
- int newCursorPosition); |
+ int newCursorPosition, SpannableString spannableString, Object[] spanObjArray); |
private native void nativeCommitText(long nativeImeAdapterAndroid, String text); |