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..fb23145872d834fcf2fe0c0bfdc315e270e58a7b 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; |
@@ -15,6 +17,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; |
@@ -328,14 +332,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 +350,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); |
@@ -520,6 +525,22 @@ public class ImeAdapter { |
} |
@CalledByNative |
+ private void populateUnderlinesFromSpans(CharSequence text, long underlines) { |
+ String textStr = text.toString(); |
+ if (!(text instanceof SpannableString)) |
+ return; |
+ |
+ SpannableString ss = ((SpannableString) text); |
+ for (Object sObj : ss.getSpans(0, textStr.length(), Object.class)) { |
+ if (sObj instanceof BackgroundColorSpan) { |
+ BackgroundColorSpan s = (BackgroundColorSpan) sObj; |
+ nativeAppendBackgroundColorSpan(mNativeImeAdapterAndroid, underlines, |
+ ss.getSpanStart(s), ss.getSpanEnd(s), s.getBackgroundColor()); |
+ } |
+ } |
+ } |
+ |
+ @CalledByNative |
private void cancelComposition() { |
if (mInputConnection != null) mInputConnection.restartInput(); |
} |
@@ -538,10 +559,13 @@ 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 native void nativeAppendBackgroundColorSpan(long nativeImeAdapterAndroid, |
+ 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); |