| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/password_generation_popup_view_andr
oid.h" | 5 #include "chrome/browser/ui/android/autofill/password_generation_popup_view_andr
oid.h" |
| 6 | 6 |
| 7 #include <jni.h> | 7 #include <jni.h> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 } | 54 } |
| 55 | 55 |
| 56 PasswordGenerationPopupViewAndroid::~PasswordGenerationPopupViewAndroid() {} | 56 PasswordGenerationPopupViewAndroid::~PasswordGenerationPopupViewAndroid() {} |
| 57 | 57 |
| 58 void PasswordGenerationPopupViewAndroid::Show() { | 58 void PasswordGenerationPopupViewAndroid::Show() { |
| 59 JNIEnv* env = base::android::AttachCurrentThread(); | 59 JNIEnv* env = base::android::AttachCurrentThread(); |
| 60 ui::ViewAndroid* view_android = controller_->container_view(); | 60 ui::ViewAndroid* view_android = controller_->container_view(); |
| 61 | 61 |
| 62 DCHECK(view_android); | 62 DCHECK(view_android); |
| 63 | 63 |
| 64 popup_ = view_android->AcquireAnchorView(); |
| 65 if (popup_.is_null()) |
| 66 return; |
| 64 java_object_.Reset(Java_PasswordGenerationPopupBridge_create( | 67 java_object_.Reset(Java_PasswordGenerationPopupBridge_create( |
| 65 env, reinterpret_cast<intptr_t>(this), | 68 env, popup_.view().obj(), controller_->element_bounds().width(), |
| 66 view_android->GetWindowAndroid()->GetJavaObject().obj(), | 69 reinterpret_cast<intptr_t>(this), |
| 67 view_android->GetViewAndroidDelegate().obj())); | 70 view_android->GetWindowAndroid()->GetJavaObject().obj())); |
| 68 | 71 |
| 69 UpdateBoundsAndRedrawPopup(); | 72 UpdateBoundsAndRedrawPopup(); |
| 70 } | 73 } |
| 71 | 74 |
| 72 void PasswordGenerationPopupViewAndroid::Hide() { | 75 void PasswordGenerationPopupViewAndroid::Hide() { |
| 73 controller_ = NULL; | 76 controller_ = NULL; |
| 74 JNIEnv* env = base::android::AttachCurrentThread(); | 77 JNIEnv* env = base::android::AttachCurrentThread(); |
| 75 Java_PasswordGenerationPopupBridge_hide(env, java_object_.obj()); | 78 if (!java_object_.is_null()) { |
| 79 Java_PasswordGenerationPopupBridge_hide(env, java_object_.obj()); |
| 80 } else { |
| 81 // Hide() should delete |this| either via Java dismiss or directly. |
| 82 delete this; |
| 83 } |
| 76 } | 84 } |
| 77 | 85 |
| 78 gfx::Size PasswordGenerationPopupViewAndroid::GetPreferredSizeOfPasswordView() { | 86 gfx::Size PasswordGenerationPopupViewAndroid::GetPreferredSizeOfPasswordView() { |
| 79 static const int kUnusedSize = 0; | 87 static const int kUnusedSize = 0; |
| 80 return gfx::Size(kUnusedSize, kUnusedSize); | 88 return gfx::Size(kUnusedSize, kUnusedSize); |
| 81 } | 89 } |
| 82 | 90 |
| 83 void PasswordGenerationPopupViewAndroid::UpdateBoundsAndRedrawPopup() { | 91 void PasswordGenerationPopupViewAndroid::UpdateBoundsAndRedrawPopup() { |
| 92 if (java_object_.is_null()) |
| 93 return; |
| 94 |
| 84 JNIEnv* env = base::android::AttachCurrentThread(); | 95 JNIEnv* env = base::android::AttachCurrentThread(); |
| 85 Java_PasswordGenerationPopupBridge_setAnchorRect( | 96 ui::ViewAndroid* view_android = controller_->container_view(); |
| 86 env, | |
| 87 java_object_.obj(), | |
| 88 controller_->element_bounds().x(), | |
| 89 controller_->element_bounds().y(), | |
| 90 controller_->element_bounds().width(), | |
| 91 controller_->element_bounds().height()); | |
| 92 | 97 |
| 98 DCHECK(view_android); |
| 99 view_android->SetAnchorRect(popup_.view(), controller_->element_bounds()); |
| 93 ScopedJavaLocalRef<jstring> password = | 100 ScopedJavaLocalRef<jstring> password = |
| 94 base::android::ConvertUTF16ToJavaString(env, controller_->password()); | 101 base::android::ConvertUTF16ToJavaString(env, controller_->password()); |
| 95 ScopedJavaLocalRef<jstring> suggestion = | 102 ScopedJavaLocalRef<jstring> suggestion = |
| 96 base::android::ConvertUTF16ToJavaString( | 103 base::android::ConvertUTF16ToJavaString( |
| 97 env, controller_->SuggestedText()); | 104 env, controller_->SuggestedText()); |
| 98 ScopedJavaLocalRef<jstring> help = | 105 ScopedJavaLocalRef<jstring> help = |
| 99 base::android::ConvertUTF16ToJavaString(env, controller_->HelpText()); | 106 base::android::ConvertUTF16ToJavaString(env, controller_->HelpText()); |
| 100 | 107 |
| 101 Java_PasswordGenerationPopupBridge_show( | 108 Java_PasswordGenerationPopupBridge_show( |
| 102 env, | 109 env, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 118 return false; | 125 return false; |
| 119 } | 126 } |
| 120 | 127 |
| 121 // static | 128 // static |
| 122 PasswordGenerationPopupView* PasswordGenerationPopupView::Create( | 129 PasswordGenerationPopupView* PasswordGenerationPopupView::Create( |
| 123 PasswordGenerationPopupController* controller) { | 130 PasswordGenerationPopupController* controller) { |
| 124 return new PasswordGenerationPopupViewAndroid(controller); | 131 return new PasswordGenerationPopupViewAndroid(controller); |
| 125 } | 132 } |
| 126 | 133 |
| 127 } // namespace autofill | 134 } // namespace autofill |
| OLD | NEW |