Chromium Code Reviews| Index: content/browser/renderer_host/ime_adapter_android.cc |
| diff --git a/content/browser/renderer_host/ime_adapter_android.cc b/content/browser/renderer_host/ime_adapter_android.cc |
| index c28f43fbb25cc12f7e27f112c49d6d12c08a90da..582122182ec0ac880f73397bc91f77170ebbe55c 100644 |
| --- a/content/browser/renderer_host/ime_adapter_android.cc |
| +++ b/content/browser/renderer_host/ime_adapter_android.cc |
| @@ -148,20 +148,8 @@ void ImeAdapterAndroid::SetComposingText(JNIEnv* env, |
| base::string16 text16 = ConvertJavaStringToUTF16(env, text_str); |
| - std::vector<blink::WebCompositionUnderline> underlines; |
| - // Iterate over spans in |text|, dispatch those that we care about (e.g., |
| - // BackgroundColorSpan) to a matching callback (e.g., |
| - // AppendBackgroundColorSpan()), and populate |underlines|. |
| - Java_ImeAdapter_populateUnderlinesFromSpans( |
| - env, obj, text, reinterpret_cast<jlong>(&underlines)); |
| - |
| - // Default to plain underline if we didn't find any span that we care about. |
| - if (underlines.empty()) { |
| - underlines.push_back(blink::WebCompositionUnderline( |
| - 0, text16.length(), SK_ColorBLACK, false, SK_ColorTRANSPARENT)); |
| - } |
| - // Sort spans by |.startOffset|. |
| - std::sort(underlines.begin(), underlines.end()); |
| + std::vector<blink::WebCompositionUnderline> underlines = |
| + GetUnderlinesFromSpans(env, obj, text, text16); |
| // relative_cursor_pos is as described in the Android API for |
| // InputConnection#setComposingText, whereas the parameters for |
| @@ -174,7 +162,8 @@ void ImeAdapterAndroid::SetComposingText(JNIEnv* env, |
| } |
| void ImeAdapterAndroid::CommitText(JNIEnv* env, |
| - const JavaParamRef<jobject>&, |
| + const JavaParamRef<jobject>& obj, |
| + const JavaParamRef<jobject>& text, |
| const JavaParamRef<jstring>& text_str, |
| int relative_cursor_pos) { |
| RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); |
| @@ -183,6 +172,9 @@ void ImeAdapterAndroid::CommitText(JNIEnv* env, |
| base::string16 text16 = ConvertJavaStringToUTF16(env, text_str); |
| + std::vector<blink::WebCompositionUnderline> underlines = |
| + GetUnderlinesFromSpans(env, obj, text, text16); |
| + |
| // relative_cursor_pos is as described in the Android API for |
| // InputConnection#commitText, whereas the parameters for |
| // ImeConfirmComposition are relative to the end of the composition. |
| @@ -191,7 +183,8 @@ void ImeAdapterAndroid::CommitText(JNIEnv* env, |
| else |
| relative_cursor_pos -= text16.length(); |
| - rwhi->ImeCommitText(text16, gfx::Range::InvalidRange(), relative_cursor_pos); |
| + rwhi->ImeCommitText(text16, underlines, gfx::Range::InvalidRange(), |
| + relative_cursor_pos); |
| } |
| void ImeAdapterAndroid::FinishComposingText(JNIEnv* env, |
| @@ -345,4 +338,28 @@ WebContents* ImeAdapterAndroid::GetWebContents() { |
| return WebContents::FromRenderViewHost(RenderViewHost::From(rwh)); |
| } |
| +std::vector<blink::WebCompositionUnderline> |
| +ImeAdapterAndroid::GetUnderlinesFromSpans( |
| + JNIEnv* env, |
| + const base::android::JavaParamRef<jobject>& obj, |
| + const base::android::JavaParamRef<jobject>& text, |
| + const base::string16& text16) { |
| + std::vector<blink::WebCompositionUnderline> underlines; |
| + // Iterate over spans in |text|, dispatch those that we care about (e.g., |
| + // BackgroundColorSpan) to a matching callback (e.g., |
| + // AppendBackgroundColorSpan()), and populate |underlines|. |
| + Java_ImeAdapter_populateUnderlinesFromSpans( |
| + env, obj, text, reinterpret_cast<jlong>(&underlines)); |
| + |
| + // Default to plain underline if we didn't find any span that we care about. |
| + if (underlines.empty()) { |
| + underlines.push_back(blink::WebCompositionUnderline( |
|
rlanday
2016/12/14 00:04:53
Actually I think we probably don't want this for c
|
| + 0, text16.length(), SK_ColorBLACK, false, SK_ColorTRANSPARENT)); |
| + } |
| + // Sort spans by |.startOffset|. |
| + std::sort(underlines.begin(), underlines.end()); |
| + |
| + return underlines; |
| +} |
| + |
| } // namespace content |