| 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/app/android/ime_helper_dialog.h" | |
| 6 | |
| 7 #include "base/android/jni_string.h" | |
| 8 #include "blimp/client/app/android/blimp_client_session_android.h" | |
| 9 #include "blimp/client/core/contents/ime_feature.h" | |
| 10 #include "jni/ImeHelperDialog_jni.h" | |
| 11 #include "ui/base/ime/text_input_type.h" | |
| 12 | |
| 13 using base::android::JavaParamRef; | |
| 14 | |
| 15 namespace blimp { | |
| 16 namespace client { | |
| 17 | |
| 18 static jlong Init(JNIEnv* env, | |
| 19 const JavaParamRef<jobject>& jobj, | |
| 20 const JavaParamRef<jobject>& blimp_client_session) { | |
| 21 BlimpClientSession* client_session = | |
| 22 BlimpClientSessionAndroid::FromJavaObject(env, | |
| 23 blimp_client_session.obj()); | |
| 24 return reinterpret_cast<intptr_t>( | |
| 25 new ImeHelperDialog(env, jobj, client_session->GetImeFeature())); | |
| 26 } | |
| 27 | |
| 28 // static | |
| 29 bool ImeHelperDialog::RegisterJni(JNIEnv* env) { | |
| 30 return RegisterNativesImpl(env); | |
| 31 } | |
| 32 | |
| 33 ImeHelperDialog::ImeHelperDialog( | |
| 34 JNIEnv* env, | |
| 35 const base::android::JavaParamRef<jobject>& jobj, | |
| 36 ImeFeature* ime_feature) { | |
| 37 java_obj_.Reset(env, jobj); | |
| 38 ime_feature_ = ime_feature; | |
| 39 ime_feature_->set_delegate(this); | |
| 40 } | |
| 41 | |
| 42 ImeHelperDialog::~ImeHelperDialog() { | |
| 43 ime_feature_->set_delegate(nullptr); | |
| 44 } | |
| 45 | |
| 46 void ImeHelperDialog::Destroy(JNIEnv* env, const JavaParamRef<jobject>& jobj) { | |
| 47 delete this; | |
| 48 } | |
| 49 | |
| 50 void ImeHelperDialog::OnShowImeRequested(ui::TextInputType input_type, | |
| 51 const std::string& text) { | |
| 52 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 53 DCHECK_NE(ui::TEXT_INPUT_TYPE_NONE, input_type); | |
| 54 Java_ImeHelperDialog_onShowImeRequested( | |
| 55 env, java_obj_, input_type, | |
| 56 base::android::ConvertUTF8ToJavaString(env, text)); | |
| 57 } | |
| 58 | |
| 59 void ImeHelperDialog::OnHideImeRequested() { | |
| 60 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 61 Java_ImeHelperDialog_onHideImeRequested(env, java_obj_); | |
| 62 } | |
| 63 | |
| 64 void ImeHelperDialog::OnImeTextEntered(JNIEnv* env, | |
| 65 const JavaParamRef<jobject>& jobj, | |
| 66 const JavaParamRef<jstring>& text) { | |
| 67 std::string textInput = base::android::ConvertJavaStringToUTF8(env, text); | |
| 68 ime_feature_->OnImeTextEntered(textInput); | |
| 69 } | |
| 70 | |
| 71 } // namespace client | |
| 72 } // namespace blimp | |
| OLD | NEW |