| 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 using base::android::JavaParamRef; |
| 13 |
| 14 namespace blimp { |
| 15 namespace client { |
| 16 |
| 17 // static |
| 18 bool ImeHelperDialog::RegisterJni(JNIEnv* env) { |
| 19 return RegisterNativesImpl(env); |
| 20 } |
| 21 |
| 22 ImeHelperDialog::ImeHelperDialog(ui::WindowAndroid* window) { |
| 23 JNIEnv* env = base::android::AttachCurrentThread(); |
| 24 java_obj_.Reset(Java_ImeHelperDialog_create( |
| 25 env, reinterpret_cast<intptr_t>(this), window->GetJavaObject())); |
| 26 } |
| 27 |
| 28 ImeHelperDialog::~ImeHelperDialog() { |
| 29 Java_ImeHelperDialog_clearNativePtr(base::android::AttachCurrentThread(), |
| 30 java_obj_); |
| 31 } |
| 32 |
| 33 void ImeHelperDialog::OnShowImeRequested( |
| 34 ui::TextInputType input_type, |
| 35 const std::string& text, |
| 36 const ImeFeature::ShowImeCallback& callback) { |
| 37 text_submit_callback_ = callback; |
| 38 |
| 39 JNIEnv* env = base::android::AttachCurrentThread(); |
| 40 DCHECK_NE(ui::TEXT_INPUT_TYPE_NONE, input_type); |
| 41 Java_ImeHelperDialog_onShowImeRequested( |
| 42 env, java_obj_, input_type, |
| 43 base::android::ConvertUTF8ToJavaString(env, text)); |
| 44 } |
| 45 |
| 46 void ImeHelperDialog::OnHideImeRequested() { |
| 47 JNIEnv* env = base::android::AttachCurrentThread(); |
| 48 Java_ImeHelperDialog_onHideImeRequested(env, java_obj_); |
| 49 } |
| 50 |
| 51 void ImeHelperDialog::OnImeTextEntered(JNIEnv* env, |
| 52 const JavaParamRef<jobject>& jobj, |
| 53 const JavaParamRef<jstring>& text) { |
| 54 std::string text_input = base::android::ConvertJavaStringToUTF8(env, text); |
| 55 base::ResetAndReturn(&text_submit_callback_).Run(text_input); |
| 56 } |
| 57 |
| 58 } // namespace client |
| 59 } // namespace blimp |
| OLD | NEW |