Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: blimp/client/core/contents/android/ime_helper_dialog.cc

Issue 2292343002: Hooking up Blimp IME with BlimpContents (Closed)
Patch Set: Using Callback Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "blimp/client/app/android/ime_helper_dialog.h" 5 #include "blimp/client/core/contents/android/ime_helper_dialog.h"
6 6
7 #include "base/android/jni_string.h" 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" 8 #include "jni/ImeHelperDialog_jni.h"
11 #include "ui/base/ime/text_input_type.h" 9 #include "ui/android/window_android.h"
12 10
13 using base::android::JavaParamRef; 11 using base::android::JavaParamRef;
14 12
15 namespace blimp { 13 namespace blimp {
16 namespace client { 14 namespace client {
17 15
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 16 // static
29 bool ImeHelperDialog::RegisterJni(JNIEnv* env) { 17 bool ImeHelperDialog::RegisterJni(JNIEnv* env) {
30 return RegisterNativesImpl(env); 18 return RegisterNativesImpl(env);
31 } 19 }
32 20
33 ImeHelperDialog::ImeHelperDialog( 21 ImeHelperDialog::ImeHelperDialog(ui::WindowAndroid* window) {
34 JNIEnv* env, 22 JNIEnv* env = base::android::AttachCurrentThread();
35 const base::android::JavaParamRef<jobject>& jobj, 23 java_obj_.Reset(Java_ImeHelperDialog_create(
36 ImeFeature* ime_feature) { 24 env, reinterpret_cast<intptr_t>(this), window->GetJavaObject()));
37 java_obj_.Reset(env, jobj);
38 ime_feature_ = ime_feature;
39 ime_feature_->set_delegate(this);
40 } 25 }
41 26
42 ImeHelperDialog::~ImeHelperDialog() { 27 ImeHelperDialog::~ImeHelperDialog() {
43 ime_feature_->set_delegate(nullptr); 28 Java_ImeHelperDialog_clearNativePtr(base::android::AttachCurrentThread(),
44 } 29 java_obj_);
45
46 void ImeHelperDialog::Destroy(JNIEnv* env, const JavaParamRef<jobject>& jobj) {
47 delete this;
48 } 30 }
49 31
50 void ImeHelperDialog::OnShowImeRequested(ui::TextInputType input_type, 32 void ImeHelperDialog::OnShowImeRequested(ui::TextInputType input_type,
51 const std::string& text) { 33 const std::string& text,
34 const ShowImeCallback& callback) {
35 textSubmitCallback_ = callback;
36
52 JNIEnv* env = base::android::AttachCurrentThread(); 37 JNIEnv* env = base::android::AttachCurrentThread();
53 DCHECK_NE(ui::TEXT_INPUT_TYPE_NONE, input_type); 38 DCHECK_NE(ui::TEXT_INPUT_TYPE_NONE, input_type);
54 Java_ImeHelperDialog_onShowImeRequested( 39 Java_ImeHelperDialog_onShowImeRequested(
55 env, java_obj_, input_type, 40 env, java_obj_, input_type,
56 base::android::ConvertUTF8ToJavaString(env, text)); 41 base::android::ConvertUTF8ToJavaString(env, text));
57 } 42 }
58 43
59 void ImeHelperDialog::OnHideImeRequested() { 44 void ImeHelperDialog::OnHideImeRequested() {
60 JNIEnv* env = base::android::AttachCurrentThread(); 45 JNIEnv* env = base::android::AttachCurrentThread();
61 Java_ImeHelperDialog_onHideImeRequested(env, java_obj_); 46 Java_ImeHelperDialog_onHideImeRequested(env, java_obj_);
62 } 47 }
63 48
64 void ImeHelperDialog::OnImeTextEntered(JNIEnv* env, 49 void ImeHelperDialog::OnImeTextEntered(JNIEnv* env,
65 const JavaParamRef<jobject>& jobj, 50 const JavaParamRef<jobject>& jobj,
66 const JavaParamRef<jstring>& text) { 51 const JavaParamRef<jstring>& text) {
67 std::string textInput = base::android::ConvertJavaStringToUTF8(env, text); 52 std::string textInput = base::android::ConvertJavaStringToUTF8(env, text);
68 ime_feature_->OnImeTextEntered(textInput); 53 textSubmitCallback_.Run(textInput);
David Trainor- moved to gerrit 2016/08/31 05:59:09 Drop the callback after calling it?
shaktisahu 2016/08/31 17:28:21 Done.
69 } 54 }
70 55
71 } // namespace client 56 } // namespace client
72 } // namespace blimp 57 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698