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 a19e7f44e2cbca612142ae59f0ee3fe84fe622c2..959e60bb510ad48d7e81a38f84bd43272e4c630b 100644 |
| --- a/content/browser/renderer_host/ime_adapter_android.cc |
| +++ b/content/browser/renderer_host/ime_adapter_android.cc |
| @@ -4,7 +4,9 @@ |
| #include "content/browser/renderer_host/ime_adapter_android.h" |
| +#include <algorithm> |
| #include <android/input.h> |
| +#include <vector> |
| #include "base/android/jni_android.h" |
| #include "base/android/jni_string.h" |
| @@ -87,6 +89,35 @@ bool RegisterImeAdapter(JNIEnv* env) { |
| return true; |
| } |
| +// Callback from Java to convert BackgroundColorSpan data to a |
| +// blink::WebCompositionUnderline instance, and append it to |underlines_ptr|. |
| +void AppendBackgroundColorSpan(JNIEnv*, |
| + jclass, |
| + jlong underlines_ptr, |
| + jint start, |
|
palmer
2014/06/10 20:32:23
I'm not sure, but should |start| and |end| be jlon
huangs
2014/06/11 02:41:01
SpannableString.getSpanStart(), SpannableString.ge
|
| + jint end, |
| + jint background_color) { |
| + std::vector<blink::WebCompositionUnderline>* underlines = |
| + reinterpret_cast<std::vector<blink::WebCompositionUnderline>*>( |
| + underlines_ptr); |
| + underlines->push_back(blink::WebCompositionUnderline( |
| + start, end, SK_ColorTRANSPARENT, false, background_color)); |
| +} |
| + |
| +// Callback from Java to convert UnderlineSpan data to a |
| +// blink::WebCompositionUnderline instance, and append it to |underlines_ptr|. |
| +void AppendUnderlineSpan(JNIEnv*, |
| + jclass, |
| + jlong underlines_ptr, |
| + jint start, |
|
palmer
2014/06/10 20:32:23
Same thing here. (I could be wrong.)
huangs
2014/06/11 02:41:01
Same thing.
|
| + jint end) { |
| + std::vector<blink::WebCompositionUnderline>* underlines = |
| + reinterpret_cast<std::vector<blink::WebCompositionUnderline>*>( |
| + underlines_ptr); |
| + underlines->push_back(blink::WebCompositionUnderline( |
| + start, end, SK_ColorBLACK, false, SK_ColorTRANSPARENT)); |
| +} |
| + |
| ImeAdapterAndroid::ImeAdapterAndroid(RenderWidgetHostViewAndroid* rwhva) |
| : rwhva_(rwhva) { |
| } |
| @@ -138,17 +169,33 @@ bool ImeAdapterAndroid::SendKeyEvent(JNIEnv* env, jobject, |
| return true; |
| } |
| -void ImeAdapterAndroid::SetComposingText(JNIEnv* env, jobject, jstring text, |
| +void ImeAdapterAndroid::SetComposingText(JNIEnv* env, |
| + jobject obj, |
| + jobject text, |
| + jstring text_str, |
| int new_cursor_pos) { |
| RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); |
| if (!rwhi) |
| return; |
| - base::string16 text16 = ConvertJavaStringToUTF16(env, text); |
| + base::string16 text16 = ConvertJavaStringToUTF16(env, text_str); |
| + |
| std::vector<blink::WebCompositionUnderline> underlines; |
| - underlines.push_back( |
| - blink::WebCompositionUnderline(0, text16.length(), SK_ColorBLACK, |
| - false)); |
| + // 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()); |
| + |
| // new_cursor_position is as described in the Android API for |
| // InputConnection#setComposingText, whereas the parameters for |
| // ImeSetComposition are relative to the start of the composition. |
| @@ -158,12 +205,12 @@ void ImeAdapterAndroid::SetComposingText(JNIEnv* env, jobject, jstring text, |
| rwhi->ImeSetComposition(text16, underlines, new_cursor_pos, new_cursor_pos); |
| } |
| -void ImeAdapterAndroid::CommitText(JNIEnv* env, jobject, jstring text) { |
| +void ImeAdapterAndroid::CommitText(JNIEnv* env, jobject, jstring text_str) { |
| RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); |
| if (!rwhi) |
| return; |
| - base::string16 text16 = ConvertJavaStringToUTF16(env, text); |
| + base::string16 text16 = ConvertJavaStringToUTF16(env, text_str); |
| rwhi->ImeConfirmComposition(text16, gfx::Range::InvalidRange(), false); |
| } |
| @@ -215,7 +262,8 @@ void ImeAdapterAndroid::SetComposingRegion(JNIEnv*, jobject, |
| std::vector<blink::WebCompositionUnderline> underlines; |
| underlines.push_back( |
| - blink::WebCompositionUnderline(0, end - start, SK_ColorBLACK, false)); |
| + blink::WebCompositionUnderline(0, end - start, SK_ColorBLACK, false, |
| + SK_ColorTRANSPARENT)); |
| rfh->Send(new FrameMsg_SetCompositionFromExistingText( |
| rfh->GetRoutingID(), start, end, underlines)); |