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