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 3a7d18b94da7ce41b8a4981e98e7d87b3eda70cc..64d75c0497131d71f611c524f274d9e4252292c2 100644 |
--- a/content/browser/renderer_host/ime_adapter_android.cc |
+++ b/content/browser/renderer_host/ime_adapter_android.cc |
@@ -30,10 +30,15 @@ |
#include "third_party/WebKit/public/platform/WebInputEvent.h" |
#include "third_party/WebKit/public/platform/WebTextInputType.h" |
#include "third_party/WebKit/public/web/WebCompositionUnderline.h" |
+#include "third_party/WebKit/public/web/WebTextSuggestionInfo.h" |
using base::android::AttachCurrentThread; |
using base::android::ConvertJavaStringToUTF16; |
+using base::android::ConvertUTF8ToJavaString; |
+using base::android::GetClass; |
+using base::android::MethodID; |
using base::android::JavaParamRef; |
+using base::android::ScopedJavaLocalRef; |
namespace content { |
namespace { |
@@ -88,6 +93,31 @@ void AppendBackgroundColorSpan(JNIEnv*, |
static_cast<unsigned>(background_color))); |
} |
+// Callback from Java to convert SuggestionSpan data to a |
+// blink::WebCompositionUnderline instance, and append it to |underlines_ptr|. |
+void AppendSuggestionSpan(JNIEnv* env, |
+ const JavaParamRef<jclass>&, |
+ jlong underlines_ptr, |
+ jint start, |
+ jint end, |
+ jint underline_color, |
+ jint flags, |
+ const JavaParamRef<jobjectArray>& suggestions) { |
+ DCHECK_GE(start, 0); |
+ DCHECK_GE(end, 0); |
+ std::vector<blink::WebCompositionUnderline>* underlines = |
+ reinterpret_cast<std::vector<blink::WebCompositionUnderline>*>( |
+ underlines_ptr); |
+ |
+ std::vector<std::string> suggestions_vec; |
+ AppendJavaStringArrayToStringVector(env, suggestions, &suggestions_vec); |
+ |
+ underlines->push_back(blink::WebCompositionUnderline( |
+ static_cast<unsigned>(start), static_cast<unsigned>(end), |
+ static_cast<unsigned>(underline_color), true, SK_ColorTRANSPARENT, |
+ suggestions_vec)); |
+} |
+ |
// Callback from Java to convert UnderlineSpan data to a |
// blink::WebCompositionUnderline instance, and append it to |underlines_ptr|. |
void AppendUnderlineSpan(JNIEnv*, |
@@ -259,6 +289,36 @@ void ImeAdapterAndroid::SetCharacterBounds( |
coordinates_array_size)); |
} |
+void ImeAdapterAndroid::ShowTextSuggestionMenu( |
+ const std::vector<blink::WebTextSuggestionInfo>& suggestion_infos) { |
+ JNIEnv* env = AttachCurrentThread(); |
+ ScopedJavaLocalRef<jobject> obj = java_ime_adapter_.get(env); |
+ |
+ ScopedJavaLocalRef<jclass> clazz = |
+ GetClass(env, "org/chromium/content/browser/input/SuggestionInfo"); |
+ jmethodID constructor = MethodID::Get<MethodID::TYPE_INSTANCE>( |
+ env, clazz.obj(), "<init>", |
+ "(IILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"); |
+ ScopedJavaLocalRef<jobjectArray> suggestion_infos_for_java( |
+ env, env->NewObjectArray(suggestion_infos.size(), clazz.obj(), nullptr)); |
+ |
+ for (size_t i = 0; i < suggestion_infos.size(); i++) { |
+ const blink::WebTextSuggestionInfo& suggestion_info = suggestion_infos[i]; |
+ ScopedJavaLocalRef<jobject> suggestion_info_for_java( |
+ env, |
+ env->NewObject( |
+ clazz.obj(), constructor, suggestion_info.documentMarkerID, |
+ suggestion_info.suggestionIndex, |
+ ConvertUTF8ToJavaString(env, suggestion_info.prefix).obj(), |
+ ConvertUTF8ToJavaString(env, suggestion_info.suggestion).obj(), |
+ ConvertUTF8ToJavaString(env, suggestion_info.suffix).obj())); |
+ env->SetObjectArrayElement(suggestion_infos_for_java.obj(), i, |
+ suggestion_info_for_java.obj()); |
+ } |
+ |
+ Java_ImeAdapter_showSuggestionMenu(env, obj, suggestion_infos_for_java.obj()); |
+} |
+ |
void ImeAdapterAndroid::SetComposingRegion(JNIEnv*, |
const JavaParamRef<jobject>&, |
int start, |
@@ -307,6 +367,36 @@ void ImeAdapterAndroid::RequestCursorUpdate( |
rwhi->GetRoutingID(), immediate_request, monitor_request)); |
} |
+void ImeAdapterAndroid::ApplySuggestionReplacement(JNIEnv*, |
+ const JavaParamRef<jobject>&, |
+ int documentMarkerID, |
+ int suggestionIndex) { |
+ RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); |
+ if (!rwhi) |
+ return; |
+ |
+ rwhi->ApplySuggestionReplacement(documentMarkerID, suggestionIndex); |
+} |
+ |
+void ImeAdapterAndroid::DeleteSuggestionHighlight( |
+ JNIEnv*, |
+ const JavaParamRef<jobject>&) { |
+ RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); |
+ if (!rwhi) |
+ return; |
+ |
+ rwhi->DeleteSuggestionHighlight(); |
+} |
+ |
+void ImeAdapterAndroid::SuggestionMenuClosed(JNIEnv*, |
+ const JavaParamRef<jobject>&) { |
+ RenderWidgetHostImpl* rwhi = GetRenderWidgetHostImpl(); |
+ if (!rwhi) |
+ return; |
+ |
+ rwhi->SuggestionMenuClosed(); |
+} |
+ |
void ImeAdapterAndroid::ResetImeAdapter(JNIEnv* env, |
const JavaParamRef<jobject>&) { |
java_ime_adapter_.reset(); |