| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/ui/android/autofill/autofill_popup_view_android.h" | 5 #include "chrome/browser/ui/android/autofill/autofill_popup_view_android.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "chrome/browser/ui/android/window_android_helper.h" | 9 #include "chrome/browser/ui/android/window_android_helper.h" |
| 10 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" | 10 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" |
| 11 #include "content/public/browser/android/content_view_core.h" | 11 #include "content/public/browser/android/content_view_core.h" |
| 12 #include "jni/AutofillPopupGlue_jni.h" | 12 #include "jni/AutofillPopupGlue_jni.h" |
| 13 #include "ui/android/view_android.h" |
| 13 #include "ui/android/window_android.h" | 14 #include "ui/android/window_android.h" |
| 14 #include "ui/gfx/rect.h" | 15 #include "ui/gfx/rect.h" |
| 15 | 16 |
| 16 using base::android::MethodID; | |
| 17 | |
| 18 namespace autofill { | 17 namespace autofill { |
| 19 | 18 |
| 20 AutofillPopupViewAndroid::AutofillPopupViewAndroid( | 19 AutofillPopupViewAndroid::AutofillPopupViewAndroid( |
| 21 AutofillPopupController* controller) | 20 AutofillPopupController* controller) |
| 22 : controller_(controller) {} | 21 : controller_(controller) {} |
| 23 | 22 |
| 24 AutofillPopupViewAndroid::~AutofillPopupViewAndroid() {} | 23 AutofillPopupViewAndroid::~AutofillPopupViewAndroid() {} |
| 25 | 24 |
| 26 void AutofillPopupViewAndroid::Show() { | 25 void AutofillPopupViewAndroid::Show() { |
| 27 JNIEnv* env = base::android::AttachCurrentThread(); | 26 JNIEnv* env = base::android::AttachCurrentThread(); |
| 28 content::ContentViewCore* content_view_core = controller_->container_view(); | 27 ui::ViewAndroid* view_android = controller_->container_view(); |
| 28 |
| 29 DCHECK(view_android); |
| 29 | 30 |
| 30 java_object_.Reset(Java_AutofillPopupGlue_create( | 31 java_object_.Reset(Java_AutofillPopupGlue_create( |
| 31 env, | 32 env, |
| 32 reinterpret_cast<jint>(this), | 33 reinterpret_cast<jint>(this), |
| 33 content_view_core->GetWindowAndroid()->GetJavaObject().obj(), | 34 view_android->GetWindowAndroid()->GetJavaObject().obj(), |
| 34 content_view_core->GetContainerViewDelegate().obj())); | 35 view_android->GetJavaObject().obj())); |
| 35 | 36 |
| 36 UpdateBoundsAndRedrawPopup(); | 37 UpdateBoundsAndRedrawPopup(); |
| 37 } | 38 } |
| 38 | 39 |
| 39 void AutofillPopupViewAndroid::Hide() { | 40 void AutofillPopupViewAndroid::Hide() { |
| 40 AutofillPopupView::Hide(); | 41 AutofillPopupView::Hide(); |
| 41 | 42 |
| 42 JNIEnv* env = base::android::AttachCurrentThread(); | 43 JNIEnv* env = base::android::AttachCurrentThread(); |
| 43 Java_AutofillPopupGlue_hide(env, java_object_.obj()); | 44 Java_AutofillPopupGlue_hide(env, java_object_.obj()); |
| 44 delete this; | 45 delete this; |
| 45 } | 46 } |
| 46 | 47 |
| 47 void AutofillPopupViewAndroid::UpdateBoundsAndRedrawPopup() { | 48 void AutofillPopupViewAndroid::UpdateBoundsAndRedrawPopup() { |
| 48 JNIEnv* env = base::android::AttachCurrentThread(); | 49 JNIEnv* env = base::android::AttachCurrentThread(); |
| 49 Java_AutofillPopupGlue_setAnchorRect(env, | 50 Java_AutofillPopupGlue_setAnchorRect(env, |
| 50 java_object_.obj(), | 51 java_object_.obj(), |
| 51 controller_->element_bounds().x(), | 52 controller_->element_bounds().x(), |
| 52 controller_->element_bounds().y(), | 53 controller_->element_bounds().y(), |
| 53 controller_->element_bounds().width(), | 54 controller_->element_bounds().width(), |
| 54 controller_->element_bounds().height()); | 55 controller_->element_bounds().height()); |
| 55 | 56 |
| 56 // We need an array of AutofillSuggestion. | 57 // We need an array of AutofillSuggestion. |
| 57 ScopedJavaLocalRef<jclass> autofill_suggestion_clazz = | 58 size_t count = controller_->names().size(); |
| 58 base::android::GetClass(env, | 59 |
| 59 "org/chromium/chrome/browser/autofill/AutofillSuggestion"); | 60 ScopedJavaLocalRef<jobjectArray> data_array = |
| 60 ScopedJavaLocalRef<jobjectArray> data_array(env, | 61 Java_AutofillPopupGlue_createAutofillSuggestionArray(env, count); |
| 61 env->NewObjectArray(controller_->names().size(), | 62 |
| 62 autofill_suggestion_clazz.obj(), NULL)); | 63 for (size_t i = 0; i < count; ++i) { |
| 63 base::android::CheckException(env); | |
| 64 for (size_t i = 0; i < controller_->names().size(); ++i) { | |
| 65 ScopedJavaLocalRef<jstring> name = | 64 ScopedJavaLocalRef<jstring> name = |
| 66 base::android::ConvertUTF16ToJavaString( | 65 base::android::ConvertUTF16ToJavaString(env, controller_->names()[i]); |
| 67 env, controller_->names()[i]); | |
| 68 ScopedJavaLocalRef<jstring> subtext = | 66 ScopedJavaLocalRef<jstring> subtext = |
| 69 base::android::ConvertUTF16ToJavaString( | 67 base::android::ConvertUTF16ToJavaString(env, |
| 70 env, controller_->subtexts()[i]); | 68 controller_->subtexts()[i]); |
| 71 int identifier = controller_->identifiers()[i]; | 69 Java_AutofillPopupGlue_addToAutofillSuggestionArray( |
| 72 ScopedJavaLocalRef<jobject> data = | 70 env, |
| 73 Java_AutofillPopupGlue_createAutofillSuggestion(env, | 71 data_array.obj(), |
| 74 name.obj(), | 72 i, |
| 75 subtext.obj(), | 73 name.obj(), |
| 76 identifier); | 74 subtext.obj(), |
| 77 env->SetObjectArrayElement(data_array.obj(), i, data.obj()); | 75 controller_->identifiers()[i]); |
| 78 base::android::CheckException(env); | |
| 79 } | 76 } |
| 80 | 77 |
| 81 Java_AutofillPopupGlue_show(env, java_object_.obj(), data_array.obj()); | 78 Java_AutofillPopupGlue_show(env, java_object_.obj(), data_array.obj()); |
| 82 } | 79 } |
| 83 | 80 |
| 84 void AutofillPopupViewAndroid::SuggestionSelected(JNIEnv* env, | 81 void AutofillPopupViewAndroid::SuggestionSelected(JNIEnv* env, |
| 85 jobject obj, | 82 jobject obj, |
| 86 jint list_index) { | 83 jint list_index) { |
| 87 controller_->AcceptSuggestion(list_index); | 84 controller_->AcceptSuggestion(list_index); |
| 88 } | 85 } |
| 89 | 86 |
| 90 void AutofillPopupViewAndroid::RequestHide(JNIEnv* env, jobject obj) { | 87 void AutofillPopupViewAndroid::RequestHide(JNIEnv* env, jobject obj) { |
| 91 controller_->Hide(); | 88 controller_->Hide(); |
| 92 } | 89 } |
| 93 | 90 |
| 94 void AutofillPopupViewAndroid::InvalidateRow(size_t) {} | 91 void AutofillPopupViewAndroid::InvalidateRow(size_t) {} |
| 95 | 92 |
| 96 // static | 93 // static |
| 97 bool AutofillPopupViewAndroid::RegisterAutofillPopupViewAndroid(JNIEnv* env) { | 94 bool AutofillPopupViewAndroid::RegisterAutofillPopupViewAndroid(JNIEnv* env) { |
| 98 return RegisterNativesImpl(env); | 95 return RegisterNativesImpl(env); |
| 99 } | 96 } |
| 100 | 97 |
| 101 // static | 98 // static |
| 102 AutofillPopupView* AutofillPopupView::Create( | 99 AutofillPopupView* AutofillPopupView::Create( |
| 103 AutofillPopupController* controller) { | 100 AutofillPopupController* controller) { |
| 104 return new AutofillPopupViewAndroid(controller); | 101 return new AutofillPopupViewAndroid(controller); |
| 105 } | 102 } |
| 106 | 103 |
| 107 } // namespace autofill | 104 } // namespace autofill |
| OLD | NEW |