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