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

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

Issue 2650113004: [WIP] Add support for Android SuggestionSpans when editing text (Closed)
Patch Set: Remove logging statements, fix copyright years in new files Created 3 years, 11 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 df58b85a1caa6589cebf562a34cb16f6ee454732..dea27752b54a65194628757281476908645b8485 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
@@ -12,6 +12,7 @@ import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.BackgroundColorSpan;
import android.text.style.CharacterStyle;
+import android.text.style.SuggestionSpan;
import android.text.style.UnderlineSpan;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
@@ -57,6 +58,8 @@ public class ImeAdapter {
private static final String TAG = "cr_Ime";
private static final boolean DEBUG_LOGS = false;
+ private static final int SUGGESTION_SPAN_UNDERLINE_COLOR = 0x88C8C8C8;
+
public static final int COMPOSITION_KEY_CODE = 229;
/**
@@ -104,6 +107,8 @@ public class ImeAdapter {
// re-created, the monitoring status will be reset.
private final CursorAnchorInfoController mCursorAnchorInfoController;
+ private SuggestionsPopupWindow mSuggestionsPopupWindow;
+
private int mTextInputType = TextInputType.NONE;
private int mTextInputFlags;
private int mTextInputMode = WebTextInputMode.kDefault;
@@ -128,10 +133,10 @@ public class ImeAdapter {
// Deep copy newConfig so that we can notice the difference.
mCurrentConfig = new Configuration(
mViewEmbedder.getAttachedView().getResources().getConfiguration());
- // CursorAnchroInfo is supported only after L.
+ // CursorAnchorInfo is supported only after L.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- mCursorAnchorInfoController = CursorAnchorInfoController.create(wrapper,
- new CursorAnchorInfoController.ComposingTextDelegate() {
+ mCursorAnchorInfoController = CursorAnchorInfoController.create(
+ wrapper, new CursorAnchorInfoController.ComposingTextDelegate() {
@Override
public CharSequence getText() {
return mLastText;
@@ -731,7 +736,7 @@ public class ImeAdapter {
}
if (!(text instanceof SpannableString)) return;
- SpannableString spannableString = ((SpannableString) text);
+ SpannableString spannableString = (SpannableString) text;
CharacterStyle spans[] =
spannableString.getSpans(0, text.length(), CharacterStyle.class);
for (CharacterStyle span : spans) {
@@ -739,6 +744,17 @@ public class ImeAdapter {
nativeAppendBackgroundColorSpan(underlines, spannableString.getSpanStart(span),
spannableString.getSpanEnd(span),
((BackgroundColorSpan) span).getBackgroundColor());
+ } else if (span instanceof SuggestionSpan) {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
+ // The suggestion menu is only supported on Lollipop and newer
+ continue;
+ }
+
+ SuggestionSpan suggestionSpan = (SuggestionSpan) span;
+ nativeAppendSuggestionSpan(underlines, spannableString.getSpanStart(suggestionSpan),
+ spannableString.getSpanEnd(suggestionSpan), SUGGESTION_SPAN_UNDERLINE_COLOR,
+ suggestionSpan.getFlags(), suggestionSpan.getSuggestions());
+
} else if (span instanceof UnderlineSpan) {
nativeAppendUnderlineSpan(underlines, spannableString.getSpanStart(span),
spannableString.getSpanEnd(span));
@@ -760,6 +776,31 @@ public class ImeAdapter {
}
@CalledByNative
+ private void showSuggestionMenu(SuggestionInfo[] suggestionInfos) {
+ if (mSuggestionsPopupWindow == null) {
+ mSuggestionsPopupWindow =
+ new SuggestionsPopupWindow(mInputMethodManagerWrapper.getContext(), this,
+ mViewEmbedder.getAttachedView(), mCursorAnchorInfoController);
+ }
+
+ mSuggestionsPopupWindow.setSuggestionInfos(suggestionInfos);
+ mSuggestionsPopupWindow.show();
+ }
+
+ public void applySuggestionReplacement(int documentMarkerID, int suggestionIndex) {
+ nativeApplySuggestionReplacement(
+ mNativeImeAdapterAndroid, documentMarkerID, suggestionIndex);
+ }
+
+ public void deleteSuggestionHighlight() {
+ nativeDeleteSuggestionHighlight(mNativeImeAdapterAndroid);
+ }
+
+ public void suggestionMenuClosed() {
+ nativeSuggestionMenuClosed(mNativeImeAdapterAndroid);
+ }
+
+ @CalledByNative
private void detach() {
if (DEBUG_LOGS) Log.w(TAG, "detach");
mNativeImeAdapterAndroid = 0;
@@ -771,9 +812,11 @@ public class ImeAdapter {
private native boolean nativeSendKeyEvent(long nativeImeAdapterAndroid, KeyEvent event,
int type, int modifiers, long timestampMs, int keyCode, int scanCode,
boolean isSystemKey, int unicodeChar);
- 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 static native void nativeAppendSuggestionSpan(long underlinePtr, int start, int end,
+ int underlineColor, int flags, String[] suggestions);
+ private static native void nativeAppendUnderlineSpan(long underlinePtr, int start, int end);
private native void nativeSetComposingText(long nativeImeAdapterAndroid, CharSequence text,
String textStr, int newCursorPosition);
private native void nativeCommitText(
@@ -789,4 +832,8 @@ public class ImeAdapter {
private native boolean nativeRequestTextInputStateUpdate(long nativeImeAdapterAndroid);
private native void nativeRequestCursorUpdate(long nativeImeAdapterAndroid,
boolean immediateRequest, boolean monitorRequest);
+ private native void nativeApplySuggestionReplacement(
+ long nativeImeAdapterAndroid, int documentMarkerID, int suggestionIndex);
+ private native void nativeDeleteSuggestionHighlight(long nativeImeAdapterAndroid);
+ private native void nativeSuggestionMenuClosed(long nativeImeAdapterAndroid);
}

Powered by Google App Engine
This is Rietveld 408576698