| 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/gfx/android/window_android.h" | 14 #include "ui/gfx/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(); |
| 29 | 28 |
| 30 java_object_.Reset(Java_AutofillPopupGlue_create( | 29 java_object_.Reset(Java_AutofillPopupGlue_create( |
| 31 env, | 30 env, |
| 32 reinterpret_cast<jint>(this), | 31 reinterpret_cast<jint>(this), |
| 33 content_view_core->GetWindowAndroid()->GetJavaObject().obj(), | 32 view_android->GetWindowAndroid()->GetJavaObject().obj(), |
| 34 content_view_core->GetContainerViewDelegate().obj())); | 33 view_android->GetJavaObject().obj())); |
| 35 | 34 |
| 36 UpdateBoundsAndRedrawPopup(); | 35 UpdateBoundsAndRedrawPopup(); |
| 37 } | 36 } |
| 38 | 37 |
| 39 void AutofillPopupViewAndroid::Hide() { | 38 void AutofillPopupViewAndroid::Hide() { |
| 40 AutofillPopupView::Hide(); | 39 AutofillPopupView::Hide(); |
| 41 | 40 |
| 42 JNIEnv* env = base::android::AttachCurrentThread(); | 41 JNIEnv* env = base::android::AttachCurrentThread(); |
| 43 Java_AutofillPopupGlue_hide(env, java_object_.obj()); | 42 Java_AutofillPopupGlue_hide(env, java_object_.obj()); |
| 44 delete this; | 43 delete this; |
| 45 } | 44 } |
| 46 | 45 |
| 47 void AutofillPopupViewAndroid::UpdateBoundsAndRedrawPopup() { | 46 void AutofillPopupViewAndroid::UpdateBoundsAndRedrawPopup() { |
| 48 JNIEnv* env = base::android::AttachCurrentThread(); | 47 JNIEnv* env = base::android::AttachCurrentThread(); |
| 49 Java_AutofillPopupGlue_setAnchorRect(env, | 48 Java_AutofillPopupGlue_setAnchorRect(env, |
| 50 java_object_.obj(), | 49 java_object_.obj(), |
| 51 controller_->element_bounds().x(), | 50 controller_->element_bounds().x(), |
| 52 controller_->element_bounds().y(), | 51 controller_->element_bounds().y(), |
| 53 controller_->element_bounds().width(), | 52 controller_->element_bounds().width(), |
| 54 controller_->element_bounds().height()); | 53 controller_->element_bounds().height()); |
| 55 | 54 |
| 56 // We need an array of AutofillSuggestion. | 55 // We need an array of AutofillSuggestion. |
| 57 ScopedJavaLocalRef<jclass> autofill_suggestion_clazz = | 56 size_t count = controller_->names().size(); |
| 58 base::android::GetClass(env, | 57 |
| 59 "org/chromium/chrome/browser/autofill/AutofillSuggestion"); | 58 ScopedJavaLocalRef<jobjectArray> data_array = |
| 60 ScopedJavaLocalRef<jobjectArray> data_array(env, | 59 Java_AutofillPopupGlue_createAutofillSuggestionArray(env, count); |
| 61 env->NewObjectArray(controller_->names().size(), | 60 |
| 62 autofill_suggestion_clazz.obj(), NULL)); | 61 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 = | 62 ScopedJavaLocalRef<jstring> name = |
| 66 base::android::ConvertUTF16ToJavaString( | 63 base::android::ConvertUTF16ToJavaString(env, controller_->names()[i]); |
| 67 env, controller_->names()[i]); | |
| 68 ScopedJavaLocalRef<jstring> subtext = | 64 ScopedJavaLocalRef<jstring> subtext = |
| 69 base::android::ConvertUTF16ToJavaString( | 65 base::android::ConvertUTF16ToJavaString(env, |
| 70 env, controller_->subtexts()[i]); | 66 controller_->subtexts()[i]); |
| 71 int identifier = controller_->identifiers()[i]; | 67 Java_AutofillPopupGlue_addToAutofillSuggestionArray( |
| 72 ScopedJavaLocalRef<jobject> data = | 68 env, |
| 73 Java_AutofillPopupGlue_createAutofillSuggestion(env, | 69 data_array.obj(), |
| 74 name.obj(), | 70 i, |
| 75 subtext.obj(), | 71 name.obj(), |
| 76 identifier); | 72 subtext.obj(), |
| 77 env->SetObjectArrayElement(data_array.obj(), i, data.obj()); | 73 controller_->identifiers()[i]); |
| 78 base::android::CheckException(env); | |
| 79 } | 74 } |
| 80 | 75 |
| 81 Java_AutofillPopupGlue_show(env, java_object_.obj(), data_array.obj()); | 76 Java_AutofillPopupGlue_show(env, java_object_.obj(), data_array.obj()); |
| 82 } | 77 } |
| 83 | 78 |
| 84 void AutofillPopupViewAndroid::SuggestionSelected(JNIEnv* env, | 79 void AutofillPopupViewAndroid::SuggestionSelected(JNIEnv* env, |
| 85 jobject obj, | 80 jobject obj, |
| 86 jint list_index) { | 81 jint list_index) { |
| 87 controller_->AcceptSuggestion(list_index); | 82 controller_->AcceptSuggestion(list_index); |
| 88 } | 83 } |
| 89 | 84 |
| 90 void AutofillPopupViewAndroid::RequestHide(JNIEnv* env, jobject obj) { | 85 void AutofillPopupViewAndroid::RequestHide(JNIEnv* env, jobject obj) { |
| 91 controller_->Hide(); | 86 controller_->Hide(); |
| 92 } | 87 } |
| 93 | 88 |
| 94 void AutofillPopupViewAndroid::InvalidateRow(size_t) {} | 89 void AutofillPopupViewAndroid::InvalidateRow(size_t) {} |
| 95 | 90 |
| 96 // static | 91 // static |
| 97 bool AutofillPopupViewAndroid::RegisterAutofillPopupViewAndroid(JNIEnv* env) { | 92 bool AutofillPopupViewAndroid::RegisterAutofillPopupViewAndroid(JNIEnv* env) { |
| 98 return RegisterNativesImpl(env); | 93 return RegisterNativesImpl(env); |
| 99 } | 94 } |
| 100 | 95 |
| 101 // static | 96 // static |
| 102 AutofillPopupView* AutofillPopupView::Create( | 97 AutofillPopupView* AutofillPopupView::Create( |
| 103 AutofillPopupController* controller) { | 98 AutofillPopupController* controller) { |
| 104 return new AutofillPopupViewAndroid(controller); | 99 return new AutofillPopupViewAndroid(controller); |
| 105 } | 100 } |
| 106 | 101 |
| 107 } // namespace autofill | 102 } // namespace autofill |
| OLD | NEW |