1 // Copyright 2014 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/password_generation_popup_view_android.h"
9 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h"
11 #include "base/android/scoped_java_ref.h"
12 #include "base/logging.h"
13 #include "chrome/browser/ui/android/window_android_helper.h"
14 #include "chrome/browser/ui/autofill/password_generation_popup_controller.h"
15 #include "content/public/browser/android/content_view_core.h"
16 #include "jni/PasswordGenerationPopupBridge_jni.h"
17 #include "ui/android/view_android.h"
18 #include "ui/android/window_android.h"
19 #include "ui/gfx/geometry/rect_f.h"
20 #include "ui/gfx/range/range.h"
24 PasswordGenerationPopupViewAndroid::PasswordGenerationPopupViewAndroid(
25 PasswordGenerationPopupController
* controller
)
26 : controller_(controller
) {}
28 void PasswordGenerationPopupViewAndroid::SavedPasswordsLinkClicked(
29 JNIEnv
* env
, jobject obj
) {
31 controller_
->OnSavedPasswordsLinkClicked();
34 void PasswordGenerationPopupViewAndroid::Dismissed(JNIEnv
* env
, jobject obj
) {
36 controller_
->ViewDestroyed();
41 void PasswordGenerationPopupViewAndroid::PasswordSelected(
42 JNIEnv
* env
, jobject object
) {
44 controller_
->PasswordAccepted();
48 bool PasswordGenerationPopupViewAndroid::Register(JNIEnv
* env
) {
49 return RegisterNativesImpl(env
);
52 PasswordGenerationPopupViewAndroid::~PasswordGenerationPopupViewAndroid() {}
54 void PasswordGenerationPopupViewAndroid::Show() {
55 JNIEnv
* env
= base::android::AttachCurrentThread();
56 ui::ViewAndroid
* view_android
= controller_
->container_view();
60 java_object_
.Reset(Java_PasswordGenerationPopupBridge_create(
61 env
, reinterpret_cast<intptr_t>(this),
62 view_android
->GetWindowAndroid()->GetJavaObject().obj(),
63 view_android
->GetViewAndroidDelegate().obj()));
65 UpdateBoundsAndRedrawPopup();
68 void PasswordGenerationPopupViewAndroid::Hide() {
70 JNIEnv
* env
= base::android::AttachCurrentThread();
71 Java_PasswordGenerationPopupBridge_hide(env
, java_object_
.obj());
74 gfx::Size
PasswordGenerationPopupViewAndroid::GetPreferredSizeOfPasswordView() {
75 static const int kUnusedSize
= 0;
76 return gfx::Size(kUnusedSize
, kUnusedSize
);
79 void PasswordGenerationPopupViewAndroid::UpdateBoundsAndRedrawPopup() {
80 JNIEnv
* env
= base::android::AttachCurrentThread();
81 Java_PasswordGenerationPopupBridge_setAnchorRect(
84 controller_
->element_bounds().x(),
85 controller_
->element_bounds().y(),
86 controller_
->element_bounds().width(),
87 controller_
->element_bounds().height());
89 ScopedJavaLocalRef
<jstring
> password
=
90 base::android::ConvertUTF16ToJavaString(env
, controller_
->password());
91 ScopedJavaLocalRef
<jstring
> suggestion
=
92 base::android::ConvertUTF16ToJavaString(
93 env
, controller_
->SuggestedText());
94 ScopedJavaLocalRef
<jstring
> help
=
95 base::android::ConvertUTF16ToJavaString(env
, controller_
->HelpText());
97 Java_PasswordGenerationPopupBridge_show(
100 controller_
->IsRTL(),
101 controller_
->display_password(),
105 controller_
->HelpTextLinkRange().start(),
106 controller_
->HelpTextLinkRange().end());
109 void PasswordGenerationPopupViewAndroid::PasswordSelectionUpdated() {}
111 bool PasswordGenerationPopupViewAndroid::IsPointInPasswordBounds(
112 const gfx::Point
& point
) {
118 PasswordGenerationPopupView
* PasswordGenerationPopupView::Create(
119 PasswordGenerationPopupController
* controller
) {
120 return new PasswordGenerationPopupViewAndroid(controller
);
123 } // namespace autofill