| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/autofill_popup_view_android.h" | 5 #include "chrome/browser/ui/android/autofill/autofill_popup_view_android.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "chrome/browser/android/resource_mapper.h" | 10 #include "chrome/browser/android/resource_mapper.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 AutofillPopupController* controller) | 32 AutofillPopupController* controller) |
| 33 : controller_(controller), deleting_index_(-1) {} | 33 : controller_(controller), deleting_index_(-1) {} |
| 34 | 34 |
| 35 AutofillPopupViewAndroid::~AutofillPopupViewAndroid() {} | 35 AutofillPopupViewAndroid::~AutofillPopupViewAndroid() {} |
| 36 | 36 |
| 37 void AutofillPopupViewAndroid::Show() { | 37 void AutofillPopupViewAndroid::Show() { |
| 38 JNIEnv* env = base::android::AttachCurrentThread(); | 38 JNIEnv* env = base::android::AttachCurrentThread(); |
| 39 ui::ViewAndroid* view_android = controller_->container_view(); | 39 ui::ViewAndroid* view_android = controller_->container_view(); |
| 40 | 40 |
| 41 DCHECK(view_android); | 41 DCHECK(view_android); |
| 42 popup_view_ = view_android->AcquireAnchorView(); |
| 43 const ScopedJavaLocalRef<jobject> view = popup_view_.view(); |
| 44 if (view.is_null()) |
| 45 return; |
| 42 | 46 |
| 43 java_object_.Reset(Java_AutofillPopupBridge_create( | 47 java_object_.Reset(Java_AutofillPopupBridge_create( |
| 44 env, reinterpret_cast<intptr_t>(this), | 48 env, view.obj(), reinterpret_cast<intptr_t>(this), |
| 45 view_android->GetWindowAndroid()->GetJavaObject().obj(), | 49 view_android->GetWindowAndroid()->GetJavaObject().obj())); |
| 46 view_android->GetViewAndroidDelegate().obj())); | |
| 47 | 50 |
| 48 UpdateBoundsAndRedrawPopup(); | 51 UpdateBoundsAndRedrawPopup(); |
| 49 } | 52 } |
| 50 | 53 |
| 51 void AutofillPopupViewAndroid::Hide() { | 54 void AutofillPopupViewAndroid::Hide() { |
| 52 controller_ = NULL; | 55 controller_ = NULL; |
| 53 JNIEnv* env = base::android::AttachCurrentThread(); | 56 JNIEnv* env = base::android::AttachCurrentThread(); |
| 54 Java_AutofillPopupBridge_dismiss(env, java_object_.obj()); | 57 if (!java_object_.is_null()) { |
| 58 Java_AutofillPopupBridge_dismiss(env, java_object_.obj()); |
| 59 } else { |
| 60 // Hide() should delete |this| either via Java dismiss or directly. |
| 61 delete this; |
| 62 } |
| 55 } | 63 } |
| 56 | 64 |
| 57 void AutofillPopupViewAndroid::UpdateBoundsAndRedrawPopup() { | 65 void AutofillPopupViewAndroid::UpdateBoundsAndRedrawPopup() { |
| 66 if (java_object_.is_null()) |
| 67 return; |
| 68 |
| 69 const ScopedJavaLocalRef<jobject> view = popup_view_.view(); |
| 70 if (view.is_null()) |
| 71 return; |
| 72 |
| 73 ui::ViewAndroid* view_android = controller_->container_view(); |
| 74 |
| 75 DCHECK(view_android); |
| 58 JNIEnv* env = base::android::AttachCurrentThread(); | 76 JNIEnv* env = base::android::AttachCurrentThread(); |
| 59 Java_AutofillPopupBridge_setAnchorRect( | 77 view_android->SetAnchorRect(view, controller_->element_bounds()); |
| 60 env, | |
| 61 java_object_.obj(), | |
| 62 controller_->element_bounds().x(), | |
| 63 controller_->element_bounds().y(), | |
| 64 controller_->element_bounds().width(), | |
| 65 controller_->element_bounds().height()); | |
| 66 | 78 |
| 67 size_t count = controller_->GetLineCount(); | 79 size_t count = controller_->GetLineCount(); |
| 68 ScopedJavaLocalRef<jobjectArray> data_array = | 80 ScopedJavaLocalRef<jobjectArray> data_array = |
| 69 Java_AutofillPopupBridge_createAutofillSuggestionArray(env, count); | 81 Java_AutofillPopupBridge_createAutofillSuggestionArray(env, count); |
| 70 | 82 |
| 71 for (size_t i = 0; i < count; ++i) { | 83 for (size_t i = 0; i < count; ++i) { |
| 72 ScopedJavaLocalRef<jstring> value = base::android::ConvertUTF16ToJavaString( | 84 ScopedJavaLocalRef<jstring> value = base::android::ConvertUTF16ToJavaString( |
| 73 env, controller_->GetElidedValueAt(i)); | 85 env, controller_->GetElidedValueAt(i)); |
| 74 ScopedJavaLocalRef<jstring> label = | 86 ScopedJavaLocalRef<jstring> label = |
| 75 base::android::ConvertUTF16ToJavaString( | 87 base::android::ConvertUTF16ToJavaString( |
| (...skipping 26 matching lines...) Expand all Loading... |
| 102 jint list_index) { | 114 jint list_index) { |
| 103 // Race: Hide() may have already run. | 115 // Race: Hide() may have already run. |
| 104 if (controller_) | 116 if (controller_) |
| 105 controller_->AcceptSuggestion(list_index); | 117 controller_->AcceptSuggestion(list_index); |
| 106 } | 118 } |
| 107 | 119 |
| 108 void AutofillPopupViewAndroid::DeletionRequested( | 120 void AutofillPopupViewAndroid::DeletionRequested( |
| 109 JNIEnv* env, | 121 JNIEnv* env, |
| 110 const JavaParamRef<jobject>& obj, | 122 const JavaParamRef<jobject>& obj, |
| 111 jint list_index) { | 123 jint list_index) { |
| 112 if (!controller_) | 124 if (!controller_ || java_object_.is_null()) |
| 113 return; | 125 return; |
| 114 | 126 |
| 115 base::string16 confirmation_title, confirmation_body; | 127 base::string16 confirmation_title, confirmation_body; |
| 116 if (!controller_->GetRemovalConfirmationText(list_index, &confirmation_title, | 128 if (!controller_->GetRemovalConfirmationText(list_index, &confirmation_title, |
| 117 &confirmation_body)) { | 129 &confirmation_body)) { |
| 118 return; | 130 return; |
| 119 } | 131 } |
| 120 | 132 |
| 121 deleting_index_ = list_index; | 133 deleting_index_ = list_index; |
| 122 Java_AutofillPopupBridge_confirmDeletion( | 134 Java_AutofillPopupBridge_confirmDeletion( |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 // static | 169 // static |
| 158 AutofillPopupView* AutofillPopupView::Create( | 170 AutofillPopupView* AutofillPopupView::Create( |
| 159 AutofillPopupController* controller) { | 171 AutofillPopupController* controller) { |
| 160 if (IsKeyboardAccessoryEnabled()) | 172 if (IsKeyboardAccessoryEnabled()) |
| 161 return new AutofillKeyboardAccessoryView(controller); | 173 return new AutofillKeyboardAccessoryView(controller); |
| 162 | 174 |
| 163 return new AutofillPopupViewAndroid(controller); | 175 return new AutofillPopupViewAndroid(controller); |
| 164 } | 176 } |
| 165 | 177 |
| 166 } // namespace autofill | 178 } // namespace autofill |
| OLD | NEW |