 Chromium Code Reviews
 Chromium Code Reviews Issue 313053007:
  Passing BackgroundColorSpan and UnderlineSpan from Clank to Blink.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 313053007:
  Passing BackgroundColorSpan and UnderlineSpan from Clank to Blink.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| 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..b23836dc92ef6b2446760d81f8611a71d53f14d5 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,31 @@ bool RegisterImeAdapter(JNIEnv* env) { | 
| return true; | 
| } | 
| +void AppendBackgroundColorSpan(JNIEnv*, | 
| 
aurimas (slooooooooow)
2014/06/10 18:36:18
Please add comments explaining what these function
 
huangs
2014/06/10 19:54:53
Done.
 | 
| + jclass, | 
| + jlong underlines_ptr, | 
| + jint start, | 
| + 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)); | 
| +} | 
| + | 
| +void AppendUnderlineSpan(JNIEnv*, | 
| + jclass, | 
| + jlong underlines_ptr, | 
| + jint start, | 
| + 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 +165,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 +201,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 +258,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)); |