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

Side by Side Diff: blimp/client/app/android/web_input_box.cc

Issue 1779673003: Added network components for blimp text input feature (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added unit tests and addressed comments Created 4 years, 9 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 "base/android/jni_string.h" 5 #include "base/android/jni_string.h"
6 #include "blimp/client/app/android/blimp_client_session_android.h" 6 #include "blimp/client/app/android/blimp_client_session_android.h"
7 #include "blimp/client/app/android/web_input_box.h" 7 #include "blimp/client/app/android/web_input_box.h"
8 #include "blimp/client/feature/ime_feature.h"
8 #include "jni/WebInputBox_jni.h" 9 #include "jni/WebInputBox_jni.h"
10 #include "ui/base/ime/text_input_type.h"
9 11
10 namespace blimp { 12 namespace blimp {
11 namespace client { 13 namespace client {
12 14
13 static jlong Init(JNIEnv* env, 15 static jlong Init(JNIEnv* env,
14 const JavaParamRef<jobject>& jobj, 16 const JavaParamRef<jobject>& jobj,
15 const JavaParamRef<jobject>& blimp_client_session) { 17 const JavaParamRef<jobject>& blimp_client_session) {
16 return reinterpret_cast<intptr_t>(new WebInputBox(env, jobj)); 18 BlimpClientSession* client_session =
19 BlimpClientSessionAndroid::FromJavaObject(env,
20 blimp_client_session.obj());
21 return reinterpret_cast<intptr_t>(
Wez 2016/03/18 20:51:27 Why are you reinterpret_cast<>ing to intptr_t rath
shaktisahu 2016/03/22 19:44:19 reinterpret_cast to intptr_t is quite standard in
Wez 2016/03/22 21:43:37 Huh... apparently it's about ensuring that the con
22 new WebInputBox(env, jobj, client_session->GetImeFeature()));
17 } 23 }
18 24
19 // static 25 // static
20 bool WebInputBox::RegisterJni(JNIEnv* env) { 26 bool WebInputBox::RegisterJni(JNIEnv* env) {
21 return RegisterNativesImpl(env); 27 return RegisterNativesImpl(env);
22 } 28 }
23 29
24 WebInputBox::WebInputBox(JNIEnv* env, 30 WebInputBox::WebInputBox(JNIEnv* env,
25 const base::android::JavaParamRef<jobject>& jobj) { 31 const base::android::JavaParamRef<jobject>& jobj,
32 ImeFeature* ime_feature) {
26 java_obj_.Reset(env, jobj); 33 java_obj_.Reset(env, jobj);
34 ime_feature_ = ime_feature;
35 ime_feature_->SetDelegate(this);
27 } 36 }
28 37
29 WebInputBox::~WebInputBox() {} 38 WebInputBox::~WebInputBox() {
39 ime_feature_->SetDelegate(nullptr);
40 }
30 41
31 void WebInputBox::Destroy(JNIEnv* env, const JavaParamRef<jobject>& jobj) { 42 void WebInputBox::Destroy(JNIEnv* env, const JavaParamRef<jobject>& jobj) {
32 delete this; 43 delete this;
33 } 44 }
34 45
35 void WebInputBox::OnImeRequested(bool show) { 46 void WebInputBox::OnShowImeRequested(ui::TextInputType input_type,
47 const std::string& text) {
36 JNIEnv* env = base::android::AttachCurrentThread(); 48 JNIEnv* env = base::android::AttachCurrentThread();
37 Java_WebInputBox_onImeRequested(env, java_obj_.obj(), show); 49 Java_WebInputBox_onShowImeRequested(
50 env, java_obj_.obj(), input_type,
Wez 2016/03/18 20:51:27 nit: It looks a little strange to have |env| need
shaktisahu 2016/03/22 19:44:19 OnShowImeRequested() is a native-to-Java call wher
Wez 2016/03/22 21:43:37 Acknowledged.
51 base::android::ConvertUTF8ToJavaString(env, text).obj());
52 }
53
54 void WebInputBox::OnHideImeRequested() {
55 JNIEnv* env = base::android::AttachCurrentThread();
56 Java_WebInputBox_onHideImeRequested(env, java_obj_.obj());
38 } 57 }
39 58
40 void WebInputBox::OnImeTextEntered(JNIEnv* env, 59 void WebInputBox::OnImeTextEntered(JNIEnv* env,
41 const JavaParamRef<jobject>& jobj, 60 const JavaParamRef<jobject>& jobj,
42 const JavaParamRef<jstring>& text) { 61 const JavaParamRef<jstring>& text) {
43 // TODO(shaktisahu): Send text to browser. 62 std::string textInput = base::android::ConvertJavaStringToUTF8(env, text);
63 ime_feature_->SendImeTextToEngine(textInput);
44 } 64 }
45 65
46 } // namespace client 66 } // namespace client
47 } // namespace blimp 67 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698