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 | 39 popup_view_.Reset(view_android->AcquireAnchorView()); |
| 40 java_object_.Reset(Java_AutofillPopupBridge_create( | 40 java_object_.Reset(Java_AutofillPopupBridge_create( |
| 41 env, reinterpret_cast<intptr_t>(this), | 41 env, popup_view_.obj(), controller_->element_bounds().width(), |
| 42 view_android->GetWindowAndroid()->GetJavaObject().obj(), | 42 reinterpret_cast<intptr_t>(this), |
| 43 view_android->GetViewAndroidDelegate().obj())); | 43 view_android->GetWindowAndroid()->GetJavaObject().obj())); |
| 44 | 44 |
| 45 UpdateBoundsAndRedrawPopup(); | 45 UpdateBoundsAndRedrawPopup(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void AutofillPopupViewAndroid::Hide() { | 48 void AutofillPopupViewAndroid::Hide() { |
| 49 controller_ = NULL; | 49 controller_ = NULL; |
|
no sievers
2016/07/14 23:14:31
need to remove anchor view from hierarchy here als
Jinsuk Kim
2016/07/15 05:46:26
Done.
| |
| 50 JNIEnv* env = base::android::AttachCurrentThread(); | 50 JNIEnv* env = base::android::AttachCurrentThread(); |
| 51 Java_AutofillPopupBridge_dismiss(env, java_object_.obj()); | 51 Java_AutofillPopupBridge_dismiss(env, java_object_.obj()); |
| 52 } | 52 } |
| 53 | 53 |
| 54 void AutofillPopupViewAndroid::UpdateBoundsAndRedrawPopup() { | 54 void AutofillPopupViewAndroid::UpdateBoundsAndRedrawPopup() { |
| 55 ui::ViewAndroid* view_android = controller_->container_view(); | |
| 56 | |
| 57 DCHECK(view_android); | |
| 58 view_android->SetAnchorRect(popup_view_.obj(), controller_->element_bounds()); | |
| 59 | |
| 55 JNIEnv* env = base::android::AttachCurrentThread(); | 60 JNIEnv* env = base::android::AttachCurrentThread(); |
| 56 Java_AutofillPopupBridge_setAnchorRect( | |
| 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 | |
| 64 size_t count = controller_->GetLineCount(); | 61 size_t count = controller_->GetLineCount(); |
| 65 ScopedJavaLocalRef<jobjectArray> data_array = | 62 ScopedJavaLocalRef<jobjectArray> data_array = |
| 66 Java_AutofillPopupBridge_createAutofillSuggestionArray(env, count); | 63 Java_AutofillPopupBridge_createAutofillSuggestionArray(env, count); |
| 67 | 64 |
| 68 for (size_t i = 0; i < count; ++i) { | 65 for (size_t i = 0; i < count; ++i) { |
| 69 ScopedJavaLocalRef<jstring> value = base::android::ConvertUTF16ToJavaString( | 66 ScopedJavaLocalRef<jstring> value = base::android::ConvertUTF16ToJavaString( |
| 70 env, controller_->GetElidedValueAt(i)); | 67 env, controller_->GetElidedValueAt(i)); |
| 71 ScopedJavaLocalRef<jstring> label = | 68 ScopedJavaLocalRef<jstring> label = |
| 72 base::android::ConvertUTF16ToJavaString( | 69 base::android::ConvertUTF16ToJavaString( |
| 73 env, controller_->GetElidedLabelAt(i)); | 70 env, controller_->GetElidedLabelAt(i)); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 if (!controller_) | 127 if (!controller_) |
| 131 return; | 128 return; |
| 132 | 129 |
| 133 CHECK_GE(deleting_index_, 0); | 130 CHECK_GE(deleting_index_, 0); |
| 134 controller_->RemoveSuggestion(deleting_index_); | 131 controller_->RemoveSuggestion(deleting_index_); |
| 135 } | 132 } |
| 136 | 133 |
| 137 void AutofillPopupViewAndroid::PopupDismissed( | 134 void AutofillPopupViewAndroid::PopupDismissed( |
| 138 JNIEnv* env, | 135 JNIEnv* env, |
| 139 const JavaParamRef<jobject>& obj) { | 136 const JavaParamRef<jobject>& obj) { |
| 140 if (controller_) | 137 if (controller_) { |
| 138 ui::ViewAndroid* view_android = controller_->container_view(); | |
| 139 | |
| 140 DCHECK(view_android); | |
| 141 view_android->RemoveAnchorView(popup_view_.obj()); | |
| 141 controller_->ViewDestroyed(); | 142 controller_->ViewDestroyed(); |
| 143 } | |
| 142 | 144 |
| 143 delete this; | 145 delete this; |
| 144 } | 146 } |
| 145 | 147 |
| 146 void AutofillPopupViewAndroid::InvalidateRow(size_t) {} | 148 void AutofillPopupViewAndroid::InvalidateRow(size_t) {} |
| 147 | 149 |
| 148 // static | 150 // static |
| 149 bool AutofillPopupViewAndroid::RegisterAutofillPopupViewAndroid(JNIEnv* env) { | 151 bool AutofillPopupViewAndroid::RegisterAutofillPopupViewAndroid(JNIEnv* env) { |
| 150 return RegisterNativesImpl(env); | 152 return RegisterNativesImpl(env); |
| 151 } | 153 } |
| 152 | 154 |
| 153 // static | 155 // static |
| 154 AutofillPopupView* AutofillPopupView::Create( | 156 AutofillPopupView* AutofillPopupView::Create( |
| 155 AutofillPopupController* controller) { | 157 AutofillPopupController* controller) { |
| 156 if (IsKeyboardAccessoryEnabled()) | 158 if (IsKeyboardAccessoryEnabled()) |
| 157 return new AutofillKeyboardAccessoryView(controller); | 159 return new AutofillKeyboardAccessoryView(controller); |
| 158 | 160 |
| 159 return new AutofillPopupViewAndroid(controller); | 161 return new AutofillPopupViewAndroid(controller); |
| 160 } | 162 } |
| 161 | 163 |
| 162 } // namespace autofill | 164 } // namespace autofill |
| OLD | NEW |