Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1304)

Unified Diff: content/public/android/java/src/org/chromium/content/browser/input/ImeAdapter.java

Issue 313053007: Passing BackgroundColorSpan and UnderlineSpan from Clank to Blink. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changing early-exit in populateUnderlinesFromSpans() to if{}. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..0eda6a99b26d24012055f946bfdc3636121eee3b 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;
@@ -328,14 +334,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 +352,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 +527,26 @@ public class ImeAdapter {
}
@CalledByNative
+ private void populateUnderlinesFromSpans(CharSequence text, long underlines) {
+ String textStr = text.toString();
Ted C 2014/06/10 20:47:33 You don't need textStr do you? CharSequence has .
huangs 2014/06/11 02:41:01 Done.
+ if (text instanceof SpannableString) {
Ted C 2014/06/10 20:47:33 Even if we don't add the assert, I think we should
huangs 2014/06/11 02:41:01 Done.
+ SpannableString spannableString = ((SpannableString) text);
+ CharacterStyle spans[] =
+ spannableString.getSpans(0, textStr.length(), CharacterStyle.class);
+ for (CharacterStyle span : spans) {
+ if (span instanceof BackgroundColorSpan) {
+ nativeAppendBackgroundColorSpan(underlines, spannableString.getSpanStart(span),
+ spannableString.getSpanEnd(span),
Ted C 2014/06/10 20:47:33 +4 indent on these two lines (same for the line be
huangs 2014/06/11 02:41:01 Done.
+ ((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();
}
@@ -538,10 +565,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);

Powered by Google App Engine
This is Rietveld 408576698