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 8de6adea10a9918720e32d561705eb96d057134d..d68150d3cefefb1f3dbd512ae98346b8c57cf54a 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; |
@@ -58,6 +59,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; |
/** |
@@ -105,6 +108,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; |
@@ -135,10 +140,10 @@ public class ImeAdapter { |
mViewEmbedder = embedder; |
// Deep copy newConfig so that we can notice the difference. |
mCurrentConfig = new Configuration(initialConfiguration); |
- // 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; |
@@ -744,7 +749,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) { |
@@ -752,6 +757,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)); |
@@ -780,13 +796,40 @@ public class ImeAdapter { |
resetAndHideKeyboard(); |
} |
+ @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(long suggestionMarkerID, int suggestionIndex) { |
+ nativeApplySuggestionReplacement( |
+ mNativeImeAdapterAndroid, suggestionMarkerID, suggestionIndex); |
+ } |
+ |
+ public void deleteSuggestionHighlight() { |
+ nativeDeleteSuggestionHighlight(mNativeImeAdapterAndroid); |
+ } |
+ |
+ public void suggestionMenuClosed() { |
+ nativeSuggestionMenuClosed(mNativeImeAdapterAndroid); |
+ } |
+ |
private native long nativeInit(WebContents webContents); |
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( |
@@ -802,4 +845,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, long suggestionMarkerID, int suggestionIndex); |
+ private native void nativeDeleteSuggestionHighlight(long nativeImeAdapterAndroid); |
+ private native void nativeSuggestionMenuClosed(long nativeImeAdapterAndroid); |
} |