Chromium Code Reviews| Index: chrome/browser/ui/android/autofill/autofill_keyboard_accessory_view.cc |
| diff --git a/chrome/browser/ui/android/autofill/autofill_keyboard_accessory_view.cc b/chrome/browser/ui/android/autofill/autofill_keyboard_accessory_view.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0c3d306c1c37e952399c2a1ea26c21e62665d56c |
| --- /dev/null |
| +++ b/chrome/browser/ui/android/autofill/autofill_keyboard_accessory_view.cc |
| @@ -0,0 +1,100 @@ |
| +// 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.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/android/autofill/autofill_keyboard_accessory_view.h" |
| + |
| +#include "base/android/jni_android.h" |
| +#include "base/android/jni_string.h" |
| +#include "chrome/browser/android/resource_mapper.h" |
| +#include "chrome/browser/ui/android/window_android_helper.h" |
| +#include "chrome/browser/ui/autofill/autofill_popup_controller.h" |
| +#include "components/autofill/core/browser/suggestion.h" |
| +#include "jni/AutofillKeyboardAccessoryBridge_jni.h" |
| +#include "ui/android/view_android.h" |
| +#include "ui/android/window_android.h" |
| +#include "ui/base/resource/resource_bundle.h" |
| +#include "ui/gfx/geometry/rect.h" |
| + |
| +namespace autofill { |
| + |
| +AutofillKeyboardAccessoryView::AutofillKeyboardAccessoryView( |
| + AutofillPopupController* controller) |
| + : controller_(controller) { |
| +} |
| + |
| +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.
|
| +} |
| + |
| +void AutofillKeyboardAccessoryView::Show() { |
| + JNIEnv* env = base::android::AttachCurrentThread(); |
| + ui::ViewAndroid* view_android = controller_->container_view(); |
| + DCHECK(view_android); |
| + |
| + java_object_.Reset(Java_AutofillKeyboardAccessoryBridge_create( |
| + env, reinterpret_cast<intptr_t>(this), |
| + view_android->GetWindowAndroid()->GetJavaObject().obj())); |
| + |
| + UpdateBoundsAndRedrawPopup(); |
| +} |
| + |
| +void AutofillKeyboardAccessoryView::Hide() { |
| + controller_ = NULL; |
|
David Trainor- moved to gerrit
2015/04/20 23:29:43
nullptr
Evan Stade
2015/04/21 00:48:51
Done.
|
| + JNIEnv* env = base::android::AttachCurrentThread(); |
| + Java_AutofillKeyboardAccessoryBridge_dismiss(env, java_object_.obj()); |
| +} |
| + |
| +void AutofillKeyboardAccessoryView::UpdateBoundsAndRedrawPopup() { |
| + JNIEnv* env = base::android::AttachCurrentThread(); |
| + size_t count = controller_->GetLineCount(); |
| + ScopedJavaLocalRef<jobjectArray> data_array = |
| + Java_AutofillKeyboardAccessoryBridge_createAutofillSuggestionArray(env, |
| + count); |
| + |
| + for (size_t i = 0; i < count; ++i) { |
| + ScopedJavaLocalRef<jstring> value = base::android::ConvertUTF16ToJavaString( |
| + env, controller_->GetElidedValueAt(i)); |
| + ScopedJavaLocalRef<jstring> label = base::android::ConvertUTF16ToJavaString( |
| + env, controller_->GetElidedLabelAt(i)); |
| + int android_icon_id = 0; |
| + |
| + const autofill::Suggestion& suggestion = controller_->GetSuggestionAt(i); |
| + if (!suggestion.icon.empty()) { |
| + android_icon_id = ResourceMapper::MapFromChromiumId( |
| + controller_->GetIconResourceID(suggestion.icon)); |
| + } |
| + |
| + Java_AutofillKeyboardAccessoryBridge_addToAutofillSuggestionArray( |
| + env, data_array.obj(), i, value.obj(), label.obj(), android_icon_id, |
| + suggestion.frontend_id); |
| + } |
| + |
| + Java_AutofillKeyboardAccessoryBridge_show( |
| + env, java_object_.obj(), data_array.obj(), controller_->IsRTL()); |
| +} |
| + |
| +void AutofillKeyboardAccessoryView::SuggestionSelected(JNIEnv* env, |
| + jobject obj, |
| + jint list_index) { |
| + // Race: Hide() may have already run. |
| + if (controller_) |
| + controller_->AcceptSuggestion(list_index); |
| +} |
| + |
| +void AutofillKeyboardAccessoryView::ViewDismissed(JNIEnv* env, jobject obj) { |
| + if (controller_) |
| + controller_->ViewDestroyed(); |
| + |
| + delete this; |
| +} |
| + |
| +void AutofillKeyboardAccessoryView::InvalidateRow(size_t) { |
| +} |
| + |
| +// static |
| +bool AutofillKeyboardAccessoryView::RegisterAutofillKeyboardAccessoryView( |
| + JNIEnv* env) { |
| + return RegisterNativesImpl(env); |
| +} |
| + |
| +} // namespace autofill |