| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "blimp/client/core/contents/android/ime_helper_dialog.h" | |
| 6 | |
| 7 #include "base/android/jni_string.h" | |
| 8 #include "base/callback_helpers.h" | |
| 9 #include "jni/ImeHelperDialog_jni.h" | |
| 10 #include "ui/android/window_android.h" | |
| 11 | |
| 12 namespace blimp { | |
| 13 namespace client { | |
| 14 | |
| 15 // static | |
| 16 bool ImeHelperDialog::RegisterJni(JNIEnv* env) { | |
| 17 return RegisterNativesImpl(env); | |
| 18 } | |
| 19 | |
| 20 ImeHelperDialog::ImeHelperDialog(ui::WindowAndroid* window) { | |
| 21 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 22 java_obj_.Reset(Java_ImeHelperDialog_create( | |
| 23 env, reinterpret_cast<intptr_t>(this), window->GetJavaObject())); | |
| 24 } | |
| 25 | |
| 26 ImeHelperDialog::~ImeHelperDialog() { | |
| 27 Java_ImeHelperDialog_clearNativePtr(base::android::AttachCurrentThread(), | |
| 28 java_obj_); | |
| 29 } | |
| 30 | |
| 31 void ImeHelperDialog::OnShowImeRequested( | |
| 32 const ImeFeature::WebInputRequest& request) { | |
| 33 current_request_ = request; | |
| 34 | |
| 35 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 36 DCHECK_NE(ui::TEXT_INPUT_TYPE_NONE, current_request_.input_type); | |
| 37 Java_ImeHelperDialog_onShowImeRequested( | |
| 38 env, java_obj_, current_request_.input_type, | |
| 39 base::android::ConvertUTF8ToJavaString(env, current_request_.text)); | |
| 40 } | |
| 41 | |
| 42 void ImeHelperDialog::OnHideImeRequested() { | |
| 43 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 44 Java_ImeHelperDialog_onHideImeRequested(env, java_obj_); | |
| 45 } | |
| 46 | |
| 47 void ImeHelperDialog::OnImeTextEntered( | |
| 48 JNIEnv* env, | |
| 49 const base::android::JavaParamRef<jobject>& jobj, | |
| 50 const base::android::JavaParamRef<jstring>& text, | |
| 51 jboolean submit) { | |
| 52 std::string text_input = base::android::ConvertJavaStringToUTF8(env, text); | |
| 53 | |
| 54 ImeFeature::WebInputResponse response; | |
| 55 response.text = text_input; | |
| 56 response.submit = submit; | |
| 57 | |
| 58 base::ResetAndReturn(¤t_request_.show_ime_callback).Run(response); | |
| 59 } | |
| 60 | |
| 61 } // namespace client | |
| 62 } // namespace blimp | |
| OLD | NEW |