Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
|
David Trainor- moved to gerrit
2015/04/20 23:29:43
2015?
Evan Stade
2015/04/21 00:48:51
Done.
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/android/autofill/autofill_keyboard_accessory_view.h" | |
| 6 | |
| 7 #include "base/android/jni_android.h" | |
| 8 #include "base/android/jni_string.h" | |
| 9 #include "chrome/browser/android/resource_mapper.h" | |
| 10 #include "chrome/browser/ui/android/window_android_helper.h" | |
| 11 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" | |
| 12 #include "components/autofill/core/browser/suggestion.h" | |
| 13 #include "jni/AutofillKeyboardAccessoryBridge_jni.h" | |
| 14 #include "ui/android/view_android.h" | |
| 15 #include "ui/android/window_android.h" | |
| 16 #include "ui/base/resource/resource_bundle.h" | |
| 17 #include "ui/gfx/geometry/rect.h" | |
| 18 | |
| 19 namespace autofill { | |
| 20 | |
| 21 AutofillKeyboardAccessoryView::AutofillKeyboardAccessoryView( | |
| 22 AutofillPopupController* controller) | |
| 23 : controller_(controller) { | |
| 24 } | |
| 25 | |
| 26 AutofillKeyboardAccessoryView::~AutofillKeyboardAccessoryView() { | |
|
David Trainor- moved to gerrit
2015/04/20 23:29:43
Should we be clearing Java's native pointer of thi
Evan Stade
2015/04/21 00:48:51
I copied this pattern from AutofillPopupBridge/Aut
David Trainor- moved to gerrit
2015/04/21 06:55:47
I might be misunderstanding the lifecycle of this
Evan Stade
2015/04/21 18:10:30
No, but if it comes from a pattern that's existed
David Trainor- moved to gerrit
2015/04/21 21:02:31
I don't think that's a valid argument for proving
Evan Stade
2015/04/23 01:21:09
Done. Thanks for explanation.
| |
| 27 } | |
| 28 | |
| 29 void AutofillKeyboardAccessoryView::Show() { | |
| 30 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 31 ui::ViewAndroid* view_android = controller_->container_view(); | |
| 32 DCHECK(view_android); | |
| 33 | |
| 34 java_object_.Reset(Java_AutofillKeyboardAccessoryBridge_create( | |
| 35 env, reinterpret_cast<intptr_t>(this), | |
| 36 view_android->GetWindowAndroid()->GetJavaObject().obj())); | |
| 37 | |
| 38 UpdateBoundsAndRedrawPopup(); | |
| 39 } | |
| 40 | |
| 41 void AutofillKeyboardAccessoryView::Hide() { | |
| 42 controller_ = NULL; | |
|
David Trainor- moved to gerrit
2015/04/20 23:29:43
nullptr
Evan Stade
2015/04/21 00:48:51
Done.
| |
| 43 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 44 Java_AutofillKeyboardAccessoryBridge_dismiss(env, java_object_.obj()); | |
| 45 } | |
| 46 | |
| 47 void AutofillKeyboardAccessoryView::UpdateBoundsAndRedrawPopup() { | |
| 48 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 49 size_t count = controller_->GetLineCount(); | |
| 50 ScopedJavaLocalRef<jobjectArray> data_array = | |
| 51 Java_AutofillKeyboardAccessoryBridge_createAutofillSuggestionArray(env, | |
| 52 count); | |
| 53 | |
| 54 for (size_t i = 0; i < count; ++i) { | |
| 55 ScopedJavaLocalRef<jstring> value = base::android::ConvertUTF16ToJavaString( | |
| 56 env, controller_->GetElidedValueAt(i)); | |
| 57 ScopedJavaLocalRef<jstring> label = base::android::ConvertUTF16ToJavaString( | |
| 58 env, controller_->GetElidedLabelAt(i)); | |
| 59 int android_icon_id = 0; | |
| 60 | |
| 61 const autofill::Suggestion& suggestion = controller_->GetSuggestionAt(i); | |
| 62 if (!suggestion.icon.empty()) { | |
| 63 android_icon_id = ResourceMapper::MapFromChromiumId( | |
| 64 controller_->GetIconResourceID(suggestion.icon)); | |
| 65 } | |
| 66 | |
| 67 Java_AutofillKeyboardAccessoryBridge_addToAutofillSuggestionArray( | |
| 68 env, data_array.obj(), i, value.obj(), label.obj(), android_icon_id, | |
| 69 suggestion.frontend_id); | |
| 70 } | |
| 71 | |
| 72 Java_AutofillKeyboardAccessoryBridge_show( | |
| 73 env, java_object_.obj(), data_array.obj(), controller_->IsRTL()); | |
| 74 } | |
| 75 | |
| 76 void AutofillKeyboardAccessoryView::SuggestionSelected(JNIEnv* env, | |
| 77 jobject obj, | |
| 78 jint list_index) { | |
| 79 // Race: Hide() may have already run. | |
| 80 if (controller_) | |
| 81 controller_->AcceptSuggestion(list_index); | |
| 82 } | |
| 83 | |
| 84 void AutofillKeyboardAccessoryView::ViewDismissed(JNIEnv* env, jobject obj) { | |
| 85 if (controller_) | |
| 86 controller_->ViewDestroyed(); | |
| 87 | |
| 88 delete this; | |
| 89 } | |
| 90 | |
| 91 void AutofillKeyboardAccessoryView::InvalidateRow(size_t) { | |
| 92 } | |
| 93 | |
| 94 // static | |
| 95 bool AutofillKeyboardAccessoryView::RegisterAutofillKeyboardAccessoryView( | |
| 96 JNIEnv* env) { | |
| 97 return RegisterNativesImpl(env); | |
| 98 } | |
| 99 | |
| 100 } // namespace autofill | |
| OLD | NEW |