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/android/resource_mapper.h" | 9 #include "chrome/browser/android/resource_mapper.h" |
10 #include "chrome/browser/ui/android/window_android_helper.h" | 10 #include "chrome/browser/ui/android/window_android_helper.h" |
11 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" | 11 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" |
| 12 #include "components/autofill/core/browser/suggestion.h" |
12 #include "content/public/browser/android/content_view_core.h" | 13 #include "content/public/browser/android/content_view_core.h" |
13 #include "jni/AutofillPopupBridge_jni.h" | 14 #include "jni/AutofillPopupBridge_jni.h" |
14 #include "ui/base/android/view_android.h" | 15 #include "ui/base/android/view_android.h" |
15 #include "ui/base/android/window_android.h" | 16 #include "ui/base/android/window_android.h" |
16 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
17 #include "ui/gfx/android/java_bitmap.h" | 18 #include "ui/gfx/android/java_bitmap.h" |
18 #include "ui/gfx/rect.h" | 19 #include "ui/gfx/rect.h" |
19 | 20 |
20 namespace autofill { | 21 namespace autofill { |
21 | 22 |
(...skipping 27 matching lines...) Expand all Loading... |
49 void AutofillPopupViewAndroid::UpdateBoundsAndRedrawPopup() { | 50 void AutofillPopupViewAndroid::UpdateBoundsAndRedrawPopup() { |
50 JNIEnv* env = base::android::AttachCurrentThread(); | 51 JNIEnv* env = base::android::AttachCurrentThread(); |
51 Java_AutofillPopupBridge_setAnchorRect( | 52 Java_AutofillPopupBridge_setAnchorRect( |
52 env, | 53 env, |
53 java_object_.obj(), | 54 java_object_.obj(), |
54 controller_->element_bounds().x(), | 55 controller_->element_bounds().x(), |
55 controller_->element_bounds().y(), | 56 controller_->element_bounds().y(), |
56 controller_->element_bounds().width(), | 57 controller_->element_bounds().width(), |
57 controller_->element_bounds().height()); | 58 controller_->element_bounds().height()); |
58 | 59 |
59 // We need an array of AutofillSuggestion. | 60 size_t count = controller_->GetLineCount(); |
60 size_t count = controller_->names().size(); | |
61 | |
62 ScopedJavaLocalRef<jobjectArray> data_array = | 61 ScopedJavaLocalRef<jobjectArray> data_array = |
63 Java_AutofillPopupBridge_createAutofillSuggestionArray(env, count); | 62 Java_AutofillPopupBridge_createAutofillSuggestionArray(env, count); |
64 | 63 |
65 for (size_t i = 0; i < count; ++i) { | 64 for (size_t i = 0; i < count; ++i) { |
66 ScopedJavaLocalRef<jstring> name = | 65 ScopedJavaLocalRef<jstring> value = base::android::ConvertUTF16ToJavaString( |
67 base::android::ConvertUTF16ToJavaString(env, controller_->names()[i]); | 66 env, controller_->GetElidedValueAt(i)); |
68 ScopedJavaLocalRef<jstring> subtext = | 67 ScopedJavaLocalRef<jstring> label = |
69 base::android::ConvertUTF16ToJavaString(env, | 68 base::android::ConvertUTF16ToJavaString( |
70 controller_->subtexts()[i]); | 69 env, controller_->GetElidedLabelAt(i)); |
71 int android_icon_id = 0; | 70 int android_icon_id = 0; |
72 if (!controller_->icons()[i].empty()) { | 71 |
| 72 const autofill::Suggestion& suggestion = controller_->GetSuggestionAt(i); |
| 73 if (!suggestion.icon.empty()) { |
73 android_icon_id = ResourceMapper::MapFromChromiumId( | 74 android_icon_id = ResourceMapper::MapFromChromiumId( |
74 controller_->GetIconResourceID(controller_->icons()[i])); | 75 controller_->GetIconResourceID(suggestion.icon)); |
75 } | 76 } |
76 | 77 |
77 Java_AutofillPopupBridge_addToAutofillSuggestionArray( | 78 Java_AutofillPopupBridge_addToAutofillSuggestionArray( |
78 env, | 79 env, |
79 data_array.obj(), | 80 data_array.obj(), |
80 i, | 81 i, |
81 name.obj(), | 82 value.obj(), |
82 subtext.obj(), | 83 label.obj(), |
83 android_icon_id, | 84 android_icon_id, |
84 controller_->identifiers()[i]); | 85 suggestion.frontend_id); |
85 } | 86 } |
86 | 87 |
87 Java_AutofillPopupBridge_show( | 88 Java_AutofillPopupBridge_show( |
88 env, java_object_.obj(), data_array.obj(), controller_->IsRTL()); | 89 env, java_object_.obj(), data_array.obj(), controller_->IsRTL()); |
89 } | 90 } |
90 | 91 |
91 void AutofillPopupViewAndroid::SuggestionSelected(JNIEnv* env, | 92 void AutofillPopupViewAndroid::SuggestionSelected(JNIEnv* env, |
92 jobject obj, | 93 jobject obj, |
93 jint list_index) { | 94 jint list_index) { |
94 // Race: Hide() may have already run. | 95 // Race: Hide() may have already run. |
(...skipping 15 matching lines...) Expand all Loading... |
110 return RegisterNativesImpl(env); | 111 return RegisterNativesImpl(env); |
111 } | 112 } |
112 | 113 |
113 // static | 114 // static |
114 AutofillPopupView* AutofillPopupView::Create( | 115 AutofillPopupView* AutofillPopupView::Create( |
115 AutofillPopupController* controller) { | 116 AutofillPopupController* controller) { |
116 return new AutofillPopupViewAndroid(controller); | 117 return new AutofillPopupViewAndroid(controller); |
117 } | 118 } |
118 | 119 |
119 } // namespace autofill | 120 } // namespace autofill |
OLD | NEW |