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..59023171c600ac152b6da15aa51374651d80ec1f 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,9 @@ 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.UnderlineSpan; |
import android.view.KeyCharacterMap; |
import android.view.KeyEvent; |
import android.view.View; |
@@ -15,6 +18,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 +333,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 +351,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 +526,25 @@ public class ImeAdapter { |
} |
@CalledByNative |
+ private void populateUnderlinesFromSpans(CharSequence text, long underlines) { |
+ String textStr = text.toString(); |
+ if (!(text instanceof SpannableString)) |
+ return; |
+ |
+ SpannableString ss = ((SpannableString) text); |
aurimas (slooooooooow)
2014/06/10 18:36:18
According to the style guide [1] you should not be
huangs
2014/06/10 19:54:53
Done.
|
+ for (Object sObj : ss.getSpans(0, textStr.length(), Object.class)) { |
aurimas (slooooooooow)
2014/06/10 18:36:18
Both BackgroundColorSpan and UnderlineSpan extend
huangs
2014/06/10 19:54:53
Done.
|
+ if (sObj instanceof BackgroundColorSpan) { |
+ BackgroundColorSpan s = (BackgroundColorSpan) sObj; |
+ nativeAppendBackgroundColorSpan(underlines, ss.getSpanStart(s), ss.getSpanEnd(s), |
+ s.getBackgroundColor()); |
+ } else if (sObj instanceof UnderlineSpan) { |
+ UnderlineSpan s = (UnderlineSpan) sObj; |
+ nativeAppendUnderlineSpan(underlines, ss.getSpanStart(s), ss.getSpanEnd(s)); |
+ } |
+ } |
+ } |
+ |
+ @CalledByNative |
private void cancelComposition() { |
if (mInputConnection != null) mInputConnection.restartInput(); |
} |
@@ -538,10 +563,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); |