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/window_android_helper.h" | 12 #include "chrome/browser/ui/android/window_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_switches.h" | 15 #include "components/autofill/core/common/autofill_switches.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.h" | 22 #include "ui/gfx/geometry/rect.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 : controller_(controller), |
| 29 deleting_index_(-1) {} |
29 | 30 |
30 AutofillPopupViewAndroid::~AutofillPopupViewAndroid() {} | 31 AutofillPopupViewAndroid::~AutofillPopupViewAndroid() {} |
31 | 32 |
32 void AutofillPopupViewAndroid::Show() { | 33 void AutofillPopupViewAndroid::Show() { |
33 JNIEnv* env = base::android::AttachCurrentThread(); | 34 JNIEnv* env = base::android::AttachCurrentThread(); |
34 ui::ViewAndroid* view_android = controller_->container_view(); | 35 ui::ViewAndroid* view_android = controller_->container_view(); |
35 | 36 |
36 DCHECK(view_android); | 37 DCHECK(view_android); |
37 | 38 |
38 java_object_.Reset(Java_AutofillPopupBridge_create( | 39 java_object_.Reset(Java_AutofillPopupBridge_create( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 base::android::ConvertUTF16ToJavaString( | 71 base::android::ConvertUTF16ToJavaString( |
71 env, controller_->GetElidedLabelAt(i)); | 72 env, controller_->GetElidedLabelAt(i)); |
72 int android_icon_id = 0; | 73 int android_icon_id = 0; |
73 | 74 |
74 const autofill::Suggestion& suggestion = controller_->GetSuggestionAt(i); | 75 const autofill::Suggestion& suggestion = controller_->GetSuggestionAt(i); |
75 if (!suggestion.icon.empty()) { | 76 if (!suggestion.icon.empty()) { |
76 android_icon_id = ResourceMapper::MapFromChromiumId( | 77 android_icon_id = ResourceMapper::MapFromChromiumId( |
77 controller_->GetIconResourceID(suggestion.icon)); | 78 controller_->GetIconResourceID(suggestion.icon)); |
78 } | 79 } |
79 | 80 |
| 81 bool deletable = |
| 82 controller_->GetRemovalConfirmationText(i, nullptr, nullptr); |
80 Java_AutofillPopupBridge_addToAutofillSuggestionArray( | 83 Java_AutofillPopupBridge_addToAutofillSuggestionArray( |
81 env, | 84 env, |
82 data_array.obj(), | 85 data_array.obj(), |
83 i, | 86 i, |
84 value.obj(), | 87 value.obj(), |
85 label.obj(), | 88 label.obj(), |
86 android_icon_id, | 89 android_icon_id, |
87 suggestion.frontend_id); | 90 suggestion.frontend_id, |
| 91 deletable); |
88 } | 92 } |
89 | 93 |
90 Java_AutofillPopupBridge_show( | 94 Java_AutofillPopupBridge_show( |
91 env, java_object_.obj(), data_array.obj(), controller_->IsRTL()); | 95 env, java_object_.obj(), data_array.obj(), controller_->IsRTL()); |
92 } | 96 } |
93 | 97 |
94 void AutofillPopupViewAndroid::SuggestionSelected(JNIEnv* env, | 98 void AutofillPopupViewAndroid::SuggestionSelected(JNIEnv* env, |
95 jobject obj, | 99 jobject obj, |
96 jint list_index) { | 100 jint list_index) { |
97 // Race: Hide() may have already run. | 101 // Race: Hide() may have already run. |
98 if (controller_) | 102 if (controller_) |
99 controller_->AcceptSuggestion(list_index); | 103 controller_->AcceptSuggestion(list_index); |
100 } | 104 } |
101 | 105 |
| 106 void AutofillPopupViewAndroid::DeletionRequested(JNIEnv* env, |
| 107 jobject obj, |
| 108 jint list_index) { |
| 109 if (!controller_) |
| 110 return; |
| 111 |
| 112 base::string16 confirmation_title, confirmation_body; |
| 113 if (!controller_->GetRemovalConfirmationText(list_index, &confirmation_title, |
| 114 &confirmation_body)) { |
| 115 return; |
| 116 } |
| 117 |
| 118 deleting_index_ = list_index; |
| 119 Java_AutofillPopupBridge_confirmDeletion( |
| 120 env, |
| 121 java_object_.obj(), |
| 122 base::android::ConvertUTF16ToJavaString( |
| 123 env, confirmation_title).obj(), |
| 124 base::android::ConvertUTF16ToJavaString( |
| 125 env, confirmation_body).obj()); |
| 126 } |
| 127 |
| 128 void AutofillPopupViewAndroid::DeletionConfirmed(JNIEnv* env, |
| 129 jobject obj) { |
| 130 if (!controller_) |
| 131 return; |
| 132 |
| 133 CHECK_GE(deleting_index_, 0); |
| 134 controller_->RemoveSuggestion(deleting_index_); |
| 135 } |
| 136 |
102 void AutofillPopupViewAndroid::PopupDismissed(JNIEnv* env, jobject obj) { | 137 void AutofillPopupViewAndroid::PopupDismissed(JNIEnv* env, jobject obj) { |
103 if (controller_) | 138 if (controller_) |
104 controller_->ViewDestroyed(); | 139 controller_->ViewDestroyed(); |
105 | 140 |
106 delete this; | 141 delete this; |
107 } | 142 } |
108 | 143 |
109 void AutofillPopupViewAndroid::InvalidateRow(size_t) {} | 144 void AutofillPopupViewAndroid::InvalidateRow(size_t) {} |
110 | 145 |
111 // static | 146 // static |
112 bool AutofillPopupViewAndroid::RegisterAutofillPopupViewAndroid(JNIEnv* env) { | 147 bool AutofillPopupViewAndroid::RegisterAutofillPopupViewAndroid(JNIEnv* env) { |
113 return RegisterNativesImpl(env); | 148 return RegisterNativesImpl(env); |
114 } | 149 } |
115 | 150 |
116 // static | 151 // static |
117 AutofillPopupView* AutofillPopupView::Create( | 152 AutofillPopupView* AutofillPopupView::Create( |
118 AutofillPopupController* controller) { | 153 AutofillPopupController* controller) { |
119 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 154 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
120 switches::kEnableAccessorySuggestionView)) { | 155 switches::kEnableAccessorySuggestionView)) { |
121 return new AutofillKeyboardAccessoryView(controller); | 156 return new AutofillKeyboardAccessoryView(controller); |
122 } | 157 } |
123 | 158 |
124 return new AutofillPopupViewAndroid(controller); | 159 return new AutofillPopupViewAndroid(controller); |
125 } | 160 } |
126 | 161 |
127 } // namespace autofill | 162 } // namespace autofill |
OLD | NEW |