Commit 735343e6 authored by Tao Bai's avatar Tao Bai Committed by Commit Bot

Populate the datalists to Java

Bug: 949555
Change-Id: I515e93c8394b00d135d36e4b02487b0cbf8315c4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2212673Reviewed-by: default avatarDominic Battré <battre@chromium.org>
Reviewed-by: default avatarTao Bai <michaelbai@chromium.org>
Reviewed-by: default avatarChangwan Ryu <changwan@chromium.org>
Commit-Queue: Tao Bai <michaelbai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#771914}
parent 903e198d
...@@ -50,6 +50,10 @@ ScopedJavaLocalRef<jobject> FormFieldDataAndroid::GetJavaPeer() { ...@@ -50,6 +50,10 @@ ScopedJavaLocalRef<jobject> FormFieldDataAndroid::GetJavaPeer() {
if (!heuristic_type_.IsUnknown()) if (!heuristic_type_.IsUnknown())
jheuristic_type = jheuristic_type =
ConvertUTF8ToJavaString(env, heuristic_type_.ToString()); ConvertUTF8ToJavaString(env, heuristic_type_.ToString());
ScopedJavaLocalRef<jobjectArray> jdatalist_values =
ToJavaArrayOfStrings(env, field_ptr_->datalist_values);
ScopedJavaLocalRef<jobjectArray> jdatalist_labels =
ToJavaArrayOfStrings(env, field_ptr_->datalist_labels);
obj = Java_FormFieldData_createFormFieldData( obj = Java_FormFieldData_createFormFieldData(
env, jname, jlabel, jvalue, jautocomplete_attr, env, jname, jlabel, jvalue, jautocomplete_attr,
...@@ -57,7 +61,8 @@ ScopedJavaLocalRef<jobject> FormFieldDataAndroid::GetJavaPeer() { ...@@ -57,7 +61,8 @@ ScopedJavaLocalRef<jobject> FormFieldDataAndroid::GetJavaPeer() {
joption_values, joption_contents, IsCheckable(field_ptr_->check_status), joption_values, joption_contents, IsCheckable(field_ptr_->check_status),
IsChecked(field_ptr_->check_status), field_ptr_->max_length, IsChecked(field_ptr_->check_status), field_ptr_->max_length,
jheuristic_type, field_ptr_->bounds.x(), field_ptr_->bounds.y(), jheuristic_type, field_ptr_->bounds.x(), field_ptr_->bounds.y(),
field_ptr_->bounds.right(), field_ptr_->bounds.bottom()); field_ptr_->bounds.right(), field_ptr_->bounds.bottom(),
jdatalist_values, jdatalist_labels);
java_ref_ = JavaObjectWeakGlobalRef(env, obj); java_ref_ = JavaObjectWeakGlobalRef(env, obj);
} }
return obj; return obj;
......
...@@ -22,13 +22,17 @@ import java.lang.annotation.RetentionPolicy; ...@@ -22,13 +22,17 @@ import java.lang.annotation.RetentionPolicy;
public class FormFieldData { public class FormFieldData {
/** /**
* Define the control types supported by android.view.autofill.AutofillValue. * Define the control types supported by android.view.autofill.AutofillValue.
*
* Android doesn't have DATALIST control, it is sent to the Autofill service as
* View.AUTOFILL_TYPE_TEXT with AutofillOptions.
*/ */
@IntDef({ControlType.TEXT, ControlType.TOGGLE, ControlType.LIST}) @IntDef({ControlType.TEXT, ControlType.TOGGLE, ControlType.LIST, ControlType.DATALIST})
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
public @interface ControlType { public @interface ControlType {
int TEXT = 0; int TEXT = 0;
int TOGGLE = 1; int TOGGLE = 1;
int LIST = 2; int LIST = 2;
int DATALIST = 3;
} }
public final String mLabel; public final String mLabel;
...@@ -43,6 +47,9 @@ public class FormFieldData { ...@@ -43,6 +47,9 @@ public class FormFieldData {
public final @ControlType int mControlType; public final @ControlType int mControlType;
public final int mMaxLength; public final int mMaxLength;
public final String mHeuristicType; public final String mHeuristicType;
public final String[] mDatalistValues;
public final String[] mDatalistLabels;
// The bounds in the viewport's coordinates // The bounds in the viewport's coordinates
private final RectF mBounds; private final RectF mBounds;
// The bounds in the container view's coordinates. // The bounds in the container view's coordinates.
...@@ -58,7 +65,8 @@ public class FormFieldData { ...@@ -58,7 +65,8 @@ public class FormFieldData {
private FormFieldData(String name, String label, String value, String autocompleteAttr, private FormFieldData(String name, String label, String value, String autocompleteAttr,
boolean shouldAutocomplete, String placeholder, String type, String id, boolean shouldAutocomplete, String placeholder, String type, String id,
String[] optionValues, String[] optionContents, boolean isCheckField, boolean isChecked, String[] optionValues, String[] optionContents, boolean isCheckField, boolean isChecked,
int maxLength, String heuristicType, float left, float top, float right, float bottom) { int maxLength, String heuristicType, float left, float top, float right, float bottom,
String[] datalistValues, String[] datalistLabels) {
mName = name; mName = name;
mLabel = label; mLabel = label;
mValue = value; mValue = value;
...@@ -70,8 +78,12 @@ public class FormFieldData { ...@@ -70,8 +78,12 @@ public class FormFieldData {
mOptionValues = optionValues; mOptionValues = optionValues;
mOptionContents = optionContents; mOptionContents = optionContents;
mIsChecked = isChecked; mIsChecked = isChecked;
mDatalistLabels = datalistLabels;
mDatalistValues = datalistValues;
if (mOptionValues != null && mOptionValues.length != 0) { if (mOptionValues != null && mOptionValues.length != 0) {
mControlType = ControlType.LIST; mControlType = ControlType.LIST;
} else if (mDatalistValues != null && mDatalistValues.length != 0) {
mControlType = ControlType.DATALIST;
} else if (isCheckField) { } else if (isCheckField) {
mControlType = ControlType.TOGGLE; mControlType = ControlType.TOGGLE;
} else { } else {
...@@ -142,9 +154,9 @@ public class FormFieldData { ...@@ -142,9 +154,9 @@ public class FormFieldData {
String autocompleteAttr, boolean shouldAutocomplete, String placeholder, String type, String autocompleteAttr, boolean shouldAutocomplete, String placeholder, String type,
String id, String[] optionValues, String[] optionContents, boolean isCheckField, String id, String[] optionValues, String[] optionContents, boolean isCheckField,
boolean isChecked, int maxLength, String heuristicType, float left, float top, boolean isChecked, int maxLength, String heuristicType, float left, float top,
float right, float bottom) { float right, float bottom, String[] datalistValues, String[] datalistLabels) {
return new FormFieldData(name, label, value, autocompleteAttr, shouldAutocomplete, return new FormFieldData(name, label, value, autocompleteAttr, shouldAutocomplete,
placeholder, type, id, optionValues, optionContents, isCheckField, isChecked, placeholder, type, id, optionValues, optionContents, isCheckField, isChecked,
maxLength, heuristicType, left, top, right, bottom); maxLength, heuristicType, left, top, right, bottom, datalistValues, datalistLabels);
} }
} }
...@@ -85,10 +85,10 @@ public class AutofillProviderImplTest { ...@@ -85,10 +85,10 @@ public class AutofillProviderImplTest {
ArrayList<FormFieldData> fields = new ArrayList<FormFieldData>(1); ArrayList<FormFieldData> fields = new ArrayList<FormFieldData>(1);
fields.add(FormFieldData.createFormFieldData(null, null, null, null, false, null, null, fields.add(FormFieldData.createFormFieldData(null, null, null, null, false, null, null,
null, null, null, false, false, 0, null, 10 /* left */, 20 /* top */, null, null, null, false, false, 0, null, 10 /* left */, 20 /* top */,
300 /* right */, 60 /*bottom*/)); 300 /* right */, 60 /*bottom*/, null, null));
fields.add(FormFieldData.createFormFieldData(null, null, null, null, false, null, null, fields.add(FormFieldData.createFormFieldData(null, null, null, null, false, null, null,
null, null, null, false, false, 0, null, 20 /* left */, 100 /* top */, null, null, null, false, false, 0, null, 20 /* left */, 100 /* top */,
400 /* right */, 200 /*bottom*/)); 400 /* right */, 200 /*bottom*/, null, null));
FormData formData = new FormData(null, null, fields); FormData formData = new FormData(null, null, fields);
mAutofillProvider.transformFormFieldToContainViewCoordinates(formData); mAutofillProvider.transformFormFieldToContainViewCoordinates(formData);
RectF result = formData.mFields.get(0).getBoundsInContainerViewCoordinates(); RectF result = formData.mFields.get(0).getBoundsInContainerViewCoordinates();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment