Chromium Code Reviews| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 } | 49 } |
| 50 | 50 |
| 51 // static | 51 // static |
| 52 bool PasswordGenerationPopupViewAndroid::Register(JNIEnv* env) { | 52 bool PasswordGenerationPopupViewAndroid::Register(JNIEnv* env) { |
| 53 return RegisterNativesImpl(env); | 53 return RegisterNativesImpl(env); |
| 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(); | |
| 60 ui::ViewAndroid* view_android = controller_->container_view(); | 59 ui::ViewAndroid* view_android = controller_->container_view(); |
| 61 | 60 |
| 62 DCHECK(view_android); | 61 DCHECK(view_android); |
| 63 | 62 |
| 63 popup_ = view_android->AcquireAnchorView(); | |
| 64 const ScopedJavaLocalRef<jobject>& view = popup_.view(); | |
|
boliu
2016/07/29 20:05:15
ditto
Jinsuk Kim
2016/08/01 02:02:47
Done.
| |
| 65 if (view.is_null()) | |
| 66 return; | |
| 67 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 64 java_object_.Reset(Java_PasswordGenerationPopupBridge_create( | 68 java_object_.Reset(Java_PasswordGenerationPopupBridge_create( |
| 65 env, reinterpret_cast<intptr_t>(this), | 69 env, view.obj(), controller_->element_bounds().width(), |
| 66 view_android->GetWindowAndroid()->GetJavaObject().obj(), | 70 reinterpret_cast<intptr_t>(this), |
| 67 view_android->GetViewAndroidDelegate().obj())); | 71 view_android->GetWindowAndroid()->GetJavaObject().obj())); |
| 68 | 72 |
| 69 UpdateBoundsAndRedrawPopup(); | 73 UpdateBoundsAndRedrawPopup(); |
| 70 } | 74 } |
| 71 | 75 |
| 72 void PasswordGenerationPopupViewAndroid::Hide() { | 76 void PasswordGenerationPopupViewAndroid::Hide() { |
| 73 controller_ = NULL; | 77 controller_ = NULL; |
| 74 JNIEnv* env = base::android::AttachCurrentThread(); | 78 JNIEnv* env = base::android::AttachCurrentThread(); |
| 75 Java_PasswordGenerationPopupBridge_hide(env, java_object_.obj()); | 79 if (!java_object_.is_null()) { |
| 80 Java_PasswordGenerationPopupBridge_hide(env, java_object_.obj()); | |
| 81 } else { | |
| 82 // Hide() should delete |this| either via Java dismiss or directly. | |
| 83 delete this; | |
| 84 } | |
| 76 } | 85 } |
| 77 | 86 |
| 78 gfx::Size PasswordGenerationPopupViewAndroid::GetPreferredSizeOfPasswordView() { | 87 gfx::Size PasswordGenerationPopupViewAndroid::GetPreferredSizeOfPasswordView() { |
| 79 static const int kUnusedSize = 0; | 88 static const int kUnusedSize = 0; |
| 80 return gfx::Size(kUnusedSize, kUnusedSize); | 89 return gfx::Size(kUnusedSize, kUnusedSize); |
| 81 } | 90 } |
| 82 | 91 |
| 83 void PasswordGenerationPopupViewAndroid::UpdateBoundsAndRedrawPopup() { | 92 void PasswordGenerationPopupViewAndroid::UpdateBoundsAndRedrawPopup() { |
| 93 if (java_object_.is_null()) | |
| 94 return; | |
| 95 | |
| 96 const ScopedJavaLocalRef<jobject>& view = popup_.view(); | |
| 97 if (view.is_null()) | |
| 98 return; | |
| 99 | |
| 100 ui::ViewAndroid* view_android = controller_->container_view(); | |
| 101 | |
| 102 DCHECK(view_android); | |
| 103 view_android->SetAnchorRect(view, controller_->element_bounds()); | |
| 84 JNIEnv* env = base::android::AttachCurrentThread(); | 104 JNIEnv* env = base::android::AttachCurrentThread(); |
| 85 Java_PasswordGenerationPopupBridge_setAnchorRect( | |
| 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 | |
| 93 ScopedJavaLocalRef<jstring> password = | 105 ScopedJavaLocalRef<jstring> password = |
| 94 base::android::ConvertUTF16ToJavaString(env, controller_->password()); | 106 base::android::ConvertUTF16ToJavaString(env, controller_->password()); |
| 95 ScopedJavaLocalRef<jstring> suggestion = | 107 ScopedJavaLocalRef<jstring> suggestion = |
| 96 base::android::ConvertUTF16ToJavaString( | 108 base::android::ConvertUTF16ToJavaString( |
| 97 env, controller_->SuggestedText()); | 109 env, controller_->SuggestedText()); |
| 98 ScopedJavaLocalRef<jstring> help = | 110 ScopedJavaLocalRef<jstring> help = |
| 99 base::android::ConvertUTF16ToJavaString(env, controller_->HelpText()); | 111 base::android::ConvertUTF16ToJavaString(env, controller_->HelpText()); |
| 100 | 112 |
| 101 Java_PasswordGenerationPopupBridge_show( | 113 Java_PasswordGenerationPopupBridge_show( |
| 102 env, | 114 env, |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 118 return false; | 130 return false; |
| 119 } | 131 } |
| 120 | 132 |
| 121 // static | 133 // static |
| 122 PasswordGenerationPopupView* PasswordGenerationPopupView::Create( | 134 PasswordGenerationPopupView* PasswordGenerationPopupView::Create( |
| 123 PasswordGenerationPopupController* controller) { | 135 PasswordGenerationPopupController* controller) { |
| 124 return new PasswordGenerationPopupViewAndroid(controller); | 136 return new PasswordGenerationPopupViewAndroid(controller); |
| 125 } | 137 } |
| 126 | 138 |
| 127 } // namespace autofill | 139 } // namespace autofill |
| OLD | NEW |