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..da34aa5fd501cb4786bafba0250ba064dfc4c111 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" |
@@ -138,17 +140,46 @@ bool ImeAdapterAndroid::SendKeyEvent(JNIEnv* env, jobject, |
return true; |
} |
-void ImeAdapterAndroid::SetComposingText(JNIEnv* env, jobject, jstring text, |
+void ImeAdapterAndroid::AppendBackgroundColorSpan(JNIEnv*, |
+ jobject, |
+ long underlines_ptr, |
+ int start, |
+ int end, |
+ int background_color) { |
+ std::vector<blink::WebCompositionUnderline>* underlines = |
+ reinterpret_cast<std::vector<blink::WebCompositionUnderline>*>( |
+ underlines_ptr); |
+ underlines->push_back(blink::WebCompositionUnderline( |
+ start, end, SK_ColorBLACK, false, background_color)); |
+} |
+ |
+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 +189,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 +246,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)); |