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 "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "chrome/browser/android/resource_mapper.h" | 10 #include "chrome/browser/android/resource_mapper.h" |
11 #include "chrome/browser/ui/android/autofill/autofill_keyboard_accessory_view.h" | 11 #include "chrome/browser/ui/android/autofill/autofill_keyboard_accessory_view.h" |
12 #include "chrome/browser/ui/android/view_android_helper.h" | 12 #include "chrome/browser/ui/android/view_android_helper.h" |
13 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" | 13 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" |
14 #include "components/autofill/core/browser/suggestion.h" | 14 #include "components/autofill/core/browser/suggestion.h" |
15 #include "components/autofill/core/common/autofill_util.h" | 15 #include "components/autofill/core/common/autofill_util.h" |
16 #include "content/public/browser/android/content_view_core.h" | 16 #include "content/public/browser/android/content_view_core.h" |
17 #include "jni/AutofillPopupBridge_jni.h" | 17 #include "jni/AutofillPopupBridge_jni.h" |
18 #include "ui/android/view_android.h" | 18 #include "ui/android/view_android.h" |
19 #include "ui/android/window_android.h" | 19 #include "ui/android/window_android.h" |
20 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
21 #include "ui/gfx/android/java_bitmap.h" | 21 #include "ui/gfx/android/java_bitmap.h" |
22 #include "ui/gfx/geometry/rect_f.h" | 22 #include "ui/gfx/geometry/rect_f.h" |
23 | 23 |
24 namespace autofill { | 24 namespace autofill { |
25 | 25 |
26 AutofillPopupViewAndroid::AutofillPopupViewAndroid( | 26 AutofillPopupViewAndroid::AutofillPopupViewAndroid( |
27 AutofillPopupController* controller) | 27 AutofillPopupController* controller) |
28 : controller_(controller), | 28 : view_helper_(controller), controller_(controller), deleting_index_(-1) {} |
29 deleting_index_(-1) {} | |
30 | 29 |
31 AutofillPopupViewAndroid::~AutofillPopupViewAndroid() {} | 30 AutofillPopupViewAndroid::~AutofillPopupViewAndroid() {} |
32 | 31 |
33 void AutofillPopupViewAndroid::Show() { | 32 void AutofillPopupViewAndroid::Show() { |
34 JNIEnv* env = base::android::AttachCurrentThread(); | 33 JNIEnv* env = base::android::AttachCurrentThread(); |
35 ui::ViewAndroid* view_android = controller_->container_view(); | 34 ui::ViewAndroid* view_android = controller_->container_view(); |
36 | 35 |
37 DCHECK(view_android); | 36 DCHECK(view_android); |
38 | 37 |
39 java_object_.Reset(Java_AutofillPopupBridge_create( | 38 java_object_.Reset(Java_AutofillPopupBridge_create( |
(...skipping 28 matching lines...) Expand all Loading... |
68 ScopedJavaLocalRef<jstring> value = base::android::ConvertUTF16ToJavaString( | 67 ScopedJavaLocalRef<jstring> value = base::android::ConvertUTF16ToJavaString( |
69 env, controller_->GetElidedValueAt(i)); | 68 env, controller_->GetElidedValueAt(i)); |
70 ScopedJavaLocalRef<jstring> label = | 69 ScopedJavaLocalRef<jstring> label = |
71 base::android::ConvertUTF16ToJavaString( | 70 base::android::ConvertUTF16ToJavaString( |
72 env, controller_->GetElidedLabelAt(i)); | 71 env, controller_->GetElidedLabelAt(i)); |
73 int android_icon_id = 0; | 72 int android_icon_id = 0; |
74 | 73 |
75 const autofill::Suggestion& suggestion = controller_->GetSuggestionAt(i); | 74 const autofill::Suggestion& suggestion = controller_->GetSuggestionAt(i); |
76 if (!suggestion.icon.empty()) { | 75 if (!suggestion.icon.empty()) { |
77 android_icon_id = ResourceMapper::MapFromChromiumId( | 76 android_icon_id = ResourceMapper::MapFromChromiumId( |
78 controller_->GetIconResourceID(suggestion.icon)); | 77 view_helper_.GetIconResourceID(suggestion.icon)); |
79 } | 78 } |
80 | 79 |
81 bool deletable = | 80 bool deletable = |
82 controller_->GetRemovalConfirmationText(i, nullptr, nullptr); | 81 controller_->GetRemovalConfirmationText(i, nullptr, nullptr); |
83 Java_AutofillPopupBridge_addToAutofillSuggestionArray( | 82 Java_AutofillPopupBridge_addToAutofillSuggestionArray( |
84 env, | 83 env, |
85 data_array.obj(), | 84 data_array.obj(), |
86 i, | 85 i, |
87 value.obj(), | 86 value.obj(), |
88 label.obj(), | 87 label.obj(), |
89 android_icon_id, | 88 android_icon_id, |
90 suggestion.frontend_id, | 89 suggestion.frontend_id, |
91 deletable); | 90 deletable); |
92 } | 91 } |
93 | 92 |
94 Java_AutofillPopupBridge_show( | 93 Java_AutofillPopupBridge_show( |
95 env, java_object_.obj(), data_array.obj(), controller_->IsRTL()); | 94 env, java_object_.obj(), data_array.obj(), controller_->IsRTL()); |
96 } | 95 } |
97 | 96 |
| 97 int AutofillPopupViewAndroid::LineFromY(int y) { |
| 98 return view_helper_.LineFromY(y); |
| 99 } |
| 100 |
| 101 gfx::Rect AutofillPopupViewAndroid::GetPopupBounds() { |
| 102 return view_helper_.popup_bounds(); |
| 103 } |
| 104 |
98 void AutofillPopupViewAndroid::SuggestionSelected( | 105 void AutofillPopupViewAndroid::SuggestionSelected( |
99 JNIEnv* env, | 106 JNIEnv* env, |
100 const JavaParamRef<jobject>& obj, | 107 const JavaParamRef<jobject>& obj, |
101 jint list_index) { | 108 jint list_index) { |
102 // Race: Hide() may have already run. | 109 // Race: Hide() may have already run. |
103 if (controller_) | 110 if (controller_) |
104 controller_->AcceptSuggestion(list_index); | 111 controller_->AcceptSuggestion(list_index); |
105 } | 112 } |
106 | 113 |
107 void AutofillPopupViewAndroid::DeletionRequested( | 114 void AutofillPopupViewAndroid::DeletionRequested( |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 // static | 163 // static |
157 AutofillPopupView* AutofillPopupView::Create( | 164 AutofillPopupView* AutofillPopupView::Create( |
158 AutofillPopupController* controller) { | 165 AutofillPopupController* controller) { |
159 if (IsKeyboardAccessoryEnabled()) | 166 if (IsKeyboardAccessoryEnabled()) |
160 return new AutofillKeyboardAccessoryView(controller); | 167 return new AutofillKeyboardAccessoryView(controller); |
161 | 168 |
162 return new AutofillPopupViewAndroid(controller); | 169 return new AutofillPopupViewAndroid(controller); |
163 } | 170 } |
164 | 171 |
165 } // namespace autofill | 172 } // namespace autofill |
OLD | NEW |