Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / android / autofill / autofill_popup_view_android.cc
blobbe9bcc97dc929445bf69dd71895fc86929cba977
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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/android/autofill/autofill_popup_view_android.h"
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h"
9 #include "chrome/browser/ui/android/window_android_helper.h"
10 #include "chrome/browser/ui/autofill/autofill_popup_controller.h"
11 #include "content/public/browser/android/content_view_core.h"
12 #include "jni/AutofillPopupGlue_jni.h"
13 #include "ui/base/android/view_android.h"
14 #include "ui/base/android/window_android.h"
15 #include "ui/gfx/rect.h"
17 namespace autofill {
19 AutofillPopupViewAndroid::AutofillPopupViewAndroid(
20 AutofillPopupController* controller)
21 : controller_(controller) {}
23 AutofillPopupViewAndroid::~AutofillPopupViewAndroid() {}
25 void AutofillPopupViewAndroid::Show() {
26 JNIEnv* env = base::android::AttachCurrentThread();
27 ui::ViewAndroid* view_android = controller_->container_view();
29 DCHECK(view_android);
31 java_object_.Reset(Java_AutofillPopupGlue_create(
32 env,
33 reinterpret_cast<intptr_t>(this),
34 view_android->GetWindowAndroid()->GetJavaObject().obj(),
35 view_android->GetJavaObject().obj()));
37 UpdateBoundsAndRedrawPopup();
40 void AutofillPopupViewAndroid::Hide() {
41 JNIEnv* env = base::android::AttachCurrentThread();
42 Java_AutofillPopupGlue_hide(env, java_object_.obj());
43 delete this;
46 void AutofillPopupViewAndroid::UpdateBoundsAndRedrawPopup() {
47 JNIEnv* env = base::android::AttachCurrentThread();
48 Java_AutofillPopupGlue_setAnchorRect(env,
49 java_object_.obj(),
50 controller_->element_bounds().x(),
51 controller_->element_bounds().y(),
52 controller_->element_bounds().width(),
53 controller_->element_bounds().height());
55 // We need an array of AutofillSuggestion.
56 size_t count = controller_->names().size();
58 ScopedJavaLocalRef<jobjectArray> data_array =
59 Java_AutofillPopupGlue_createAutofillSuggestionArray(env, count);
61 for (size_t i = 0; i < count; ++i) {
62 ScopedJavaLocalRef<jstring> name =
63 base::android::ConvertUTF16ToJavaString(env, controller_->names()[i]);
64 ScopedJavaLocalRef<jstring> subtext =
65 base::android::ConvertUTF16ToJavaString(env,
66 controller_->subtexts()[i]);
67 Java_AutofillPopupGlue_addToAutofillSuggestionArray(
68 env,
69 data_array.obj(),
71 name.obj(),
72 subtext.obj(),
73 controller_->identifiers()[i]);
76 Java_AutofillPopupGlue_show(env, java_object_.obj(), data_array.obj());
79 void AutofillPopupViewAndroid::SuggestionSelected(JNIEnv* env,
80 jobject obj,
81 jint list_index) {
82 controller_->AcceptSuggestion(list_index);
85 void AutofillPopupViewAndroid::RequestHide(JNIEnv* env, jobject obj) {
86 controller_->Hide();
89 void AutofillPopupViewAndroid::InvalidateRow(size_t) {}
91 // static
92 bool AutofillPopupViewAndroid::RegisterAutofillPopupViewAndroid(JNIEnv* env) {
93 return RegisterNativesImpl(env);
96 // static
97 AutofillPopupView* AutofillPopupView::Create(
98 AutofillPopupController* controller) {
99 return new AutofillPopupViewAndroid(controller);
102 } // namespace autofill