Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: chrome/browser/ui/android/autofill/autofill_keyboard_accessory_view.cc

Issue 2874933008: Adds animation as feature variation to keyboard accessory. (Closed)
Patch Set: Switch to base/metrics/field_trial_params.h API from variations:: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 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_keyboard_accessory_view.h" 5 #include "chrome/browser/ui/android/autofill/autofill_keyboard_accessory_view.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 "chrome/browser/android/resource_mapper.h" 9 #include "chrome/browser/android/resource_mapper.h"
10 #include "chrome/browser/ui/android/view_android_helper.h" 10 #include "chrome/browser/ui/android/view_android_helper.h"
(...skipping 27 matching lines...) Expand all
38 Java_AutofillKeyboardAccessoryBridge_addToAutofillSuggestionArray( 38 Java_AutofillKeyboardAccessoryBridge_addToAutofillSuggestionArray(
39 env, data_array, position, 39 env, data_array, position,
40 base::android::ConvertUTF16ToJavaString(env, suggestion.value), 40 base::android::ConvertUTF16ToJavaString(env, suggestion.value),
41 base::android::ConvertUTF16ToJavaString(env, suggestion.label), 41 base::android::ConvertUTF16ToJavaString(env, suggestion.label),
42 android_icon_id, suggestion.frontend_id, deletable); 42 android_icon_id, suggestion.frontend_id, deletable);
43 } 43 }
44 44
45 } // namespace 45 } // namespace
46 46
47 AutofillKeyboardAccessoryView::AutofillKeyboardAccessoryView( 47 AutofillKeyboardAccessoryView::AutofillKeyboardAccessoryView(
48 AutofillPopupController* controller) 48 AutofillPopupController* controller,
49 : controller_(controller), deleting_index_(-1) { 49 unsigned int animation_duration_millis,
50 bool should_limit_label_width)
51 : controller_(controller),
52 animation_duration_millis_(animation_duration_millis),
53 should_limit_label_width_(should_limit_label_width),
54 deleting_index_(-1) {
50 JNIEnv* env = base::android::AttachCurrentThread(); 55 JNIEnv* env = base::android::AttachCurrentThread();
51 java_object_.Reset(Java_AutofillKeyboardAccessoryBridge_create(env)); 56 java_object_.Reset(Java_AutofillKeyboardAccessoryBridge_create(env));
52 } 57 }
53 58
54 AutofillKeyboardAccessoryView::~AutofillKeyboardAccessoryView() { 59 AutofillKeyboardAccessoryView::~AutofillKeyboardAccessoryView() {
55 JNIEnv* env = base::android::AttachCurrentThread(); 60 JNIEnv* env = base::android::AttachCurrentThread();
56 Java_AutofillKeyboardAccessoryBridge_resetNativeViewPointer(env, 61 Java_AutofillKeyboardAccessoryBridge_resetNativeViewPointer(env,
57 java_object_); 62 java_object_);
58 } 63 }
59 64
60 void AutofillKeyboardAccessoryView::Show() { 65 void AutofillKeyboardAccessoryView::Show() {
61 JNIEnv* env = base::android::AttachCurrentThread(); 66 JNIEnv* env = base::android::AttachCurrentThread();
62 ui::ViewAndroid* view_android = controller_->container_view(); 67 ui::ViewAndroid* view_android = controller_->container_view();
63 DCHECK(view_android); 68 DCHECK(view_android);
64 Java_AutofillKeyboardAccessoryBridge_init( 69 Java_AutofillKeyboardAccessoryBridge_init(
65 env, java_object_, reinterpret_cast<intptr_t>(this), 70 env, java_object_, reinterpret_cast<intptr_t>(this),
66 view_android->GetWindowAndroid()->GetJavaObject()); 71 view_android->GetWindowAndroid()->GetJavaObject(),
72 animation_duration_millis_, should_limit_label_width_);
67 73
68 OnSuggestionsChanged(); 74 OnSuggestionsChanged();
69 } 75 }
70 76
71 void AutofillKeyboardAccessoryView::Hide() { 77 void AutofillKeyboardAccessoryView::Hide() {
72 controller_ = nullptr; 78 controller_ = nullptr;
73 JNIEnv* env = base::android::AttachCurrentThread(); 79 JNIEnv* env = base::android::AttachCurrentThread();
74 Java_AutofillKeyboardAccessoryBridge_dismiss(env, java_object_); 80 Java_AutofillKeyboardAccessoryBridge_dismiss(env, java_object_);
75 } 81 }
76 82
77 void AutofillKeyboardAccessoryView::OnSelectedRowChanged( 83 void AutofillKeyboardAccessoryView::OnSelectedRowChanged(
78 base::Optional<int> previous_row_selection, 84 base::Optional<int> previous_row_selection,
79 base::Optional<int> current_row_selection) {} 85 base::Optional<int> current_row_selection) {}
80 86
81 void AutofillKeyboardAccessoryView::OnSuggestionsChanged() { 87 void AutofillKeyboardAccessoryView::OnSuggestionsChanged() {
82 JNIEnv* env = base::android::AttachCurrentThread(); 88 JNIEnv* env = base::android::AttachCurrentThread();
83 size_t count = controller_->GetLineCount(); 89 size_t count = controller_->GetLineCount();
84 ScopedJavaLocalRef<jobjectArray> data_array = 90 ScopedJavaLocalRef<jobjectArray> data_array =
85 Java_AutofillKeyboardAccessoryBridge_createAutofillSuggestionArray(env, 91 Java_AutofillKeyboardAccessoryBridge_createAutofillSuggestionArray(env,
86 count); 92 count);
87 positions_.resize(count); 93 positions_.resize(count);
88 size_t position = 0; 94 size_t position = 0;
89 95
90 // Place "CLEAR FORM" item first in the list. 96 // Place "CLEAR FORM" and "CREATE HINT" items first in the list.
97 // Both "CLEAR FORM" and "CREATE HINT" cannot be present in the list.
91 for (size_t i = 0; i < count; ++i) { 98 for (size_t i = 0; i < count; ++i) {
92 const Suggestion& suggestion = controller_->GetSuggestionAt(i); 99 const Suggestion& suggestion = controller_->GetSuggestionAt(i);
93 if (suggestion.frontend_id == POPUP_ITEM_ID_CLEAR_FORM) { 100 if (suggestion.frontend_id == POPUP_ITEM_ID_CLEAR_FORM ||
94 AddToJavaArray(suggestion, controller_->layout_model().GetIconResourceID( 101 suggestion.frontend_id == POPUP_ITEM_ID_CREATE_HINT) {
95 suggestion.icon), 102 AddToJavaArray(
96 env, data_array.obj(), position, false); 103 suggestion,
104 controller_->layout_model().GetIconResourceID(suggestion.icon), env,
105 data_array.obj(), position, false);
97 positions_[position++] = i; 106 positions_[position++] = i;
98 } 107 }
99 } 108 }
100 109
110 DCHECK_LT(position, 2U);
111
101 for (size_t i = 0; i < count; ++i) { 112 for (size_t i = 0; i < count; ++i) {
102 const Suggestion& suggestion = controller_->GetSuggestionAt(i); 113 const Suggestion& suggestion = controller_->GetSuggestionAt(i);
103 if (suggestion.frontend_id != POPUP_ITEM_ID_CLEAR_FORM) { 114 if (suggestion.frontend_id != POPUP_ITEM_ID_CLEAR_FORM &&
115 suggestion.frontend_id != POPUP_ITEM_ID_CREATE_HINT) {
104 bool deletable = 116 bool deletable =
105 controller_->GetRemovalConfirmationText(i, nullptr, nullptr); 117 controller_->GetRemovalConfirmationText(i, nullptr, nullptr);
106 AddToJavaArray(suggestion, controller_->layout_model().GetIconResourceID( 118 AddToJavaArray(suggestion, controller_->layout_model().GetIconResourceID(
107 suggestion.icon), 119 suggestion.icon),
108 env, data_array.obj(), position, deletable); 120 env, data_array.obj(), position, deletable);
109 positions_[position++] = i; 121 positions_[position++] = i;
110 } 122 }
111 } 123 }
112 124
113 Java_AutofillKeyboardAccessoryBridge_show(env, java_object_, data_array, 125 Java_AutofillKeyboardAccessoryBridge_show(env, java_object_, data_array,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 delete this; 174 delete this;
163 } 175 }
164 176
165 // static 177 // static
166 bool AutofillKeyboardAccessoryView::RegisterAutofillKeyboardAccessoryView( 178 bool AutofillKeyboardAccessoryView::RegisterAutofillKeyboardAccessoryView(
167 JNIEnv* env) { 179 JNIEnv* env) {
168 return RegisterNativesImpl(env); 180 return RegisterNativesImpl(env);
169 } 181 }
170 182
171 } // namespace autofill 183 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698