Commit 8273a338 authored by siashah's avatar siashah Committed by Commit Bot

Add item tag to autofill dropdrown item

This change is no-op as we are always creating the autofill suggestion
setting the itemTag to an empty string which'd result in the itemTag
text view's visibility to be set to GONE.

In a follow-up CL, we'll add the itemTag parameter to the
AutofillPopupBridge and populate the autofill suggestion with it. This
will be used to display the offer text in the autofill dropdown.

Bug: 1112095
Change-Id: Idbbc08565a4911d76264f3fc33e688228601e5b7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2350147Reviewed-by: default avatarBo <boliu@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Reviewed-by: default avatarDominic Battré <battre@chromium.org>
Reviewed-by: default avatarFriedrich [CET] <fhorschig@chromium.org>
Reviewed-by: default avatarJared Saul <jsaul@google.com>
Commit-Queue: Siddharth Shah <siashah@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798306}
parent 77c5e475
......@@ -99,7 +99,7 @@ public class AwAutofillClient {
@CalledByNative
private static void addToAutofillSuggestionArray(AutofillSuggestion[] array, int index,
String name, String label, int uniqueId) {
array[index] = new AutofillSuggestion(name, label, DropdownItem.NO_ICON,
array[index] = new AutofillSuggestion(name, label, /* itemTag= */ "", DropdownItem.NO_ICON,
false /* isIconAtLeft */, uniqueId, false /* isDeletable */,
false /* isMultilineLabel */, false /* isBoldLabel */);
}
......
......@@ -154,7 +154,7 @@ public class AutofillKeyboardAccessoryViewBridge
private static void addToAutofillSuggestionArray(AutofillSuggestion[] array, int index,
String label, String sublabel, int iconId, int suggestionId, boolean isDeletable) {
int drawableId = iconId == 0 ? DropdownItem.NO_ICON : iconId;
array[index] = new AutofillSuggestion(label, sublabel, drawableId,
array[index] = new AutofillSuggestion(label, sublabel, /* itemTag= */ "", drawableId,
false /* isIconAtStart */, suggestionId, isDeletable, false /* isMultilineLabel */,
false /* isBoldLabel */);
}
......
......@@ -248,7 +248,7 @@ public class KeyboardAccessoryModernViewTest {
@MediumTest
public void testDismissesPasswordEducationBubbleOnFilling() {
AutofillBarItem itemWithIPH =
new AutofillBarItem(new AutofillSuggestion("Johnathan", "Smith",
new AutofillBarItem(new AutofillSuggestion("Johnathan", "Smith", /*itemTag=*/"",
DropdownItem.NO_ICON, false, -2, false, false, false),
new KeyboardAccessoryData.Action("", AUTOFILL_SUGGESTION, unused -> {}));
itemWithIPH.setFeatureForIPH(FeatureConstants.KEYBOARD_ACCESSORY_PASSWORD_FILLING_FEATURE);
......@@ -276,7 +276,7 @@ public class KeyboardAccessoryModernViewTest {
@MediumTest
public void testDismissesAddressEducationBubbleOnFilling() {
AutofillBarItem itemWithIPH =
new AutofillBarItem(new AutofillSuggestion("Johnathan", "Smith",
new AutofillBarItem(new AutofillSuggestion("Johnathan", "Smith", /*itemTag=*/"",
DropdownItem.NO_ICON, false, 1, false, false, false),
new KeyboardAccessoryData.Action("", AUTOFILL_SUGGESTION, unused -> {}));
itemWithIPH.setFeatureForIPH(FeatureConstants.KEYBOARD_ACCESSORY_ADDRESS_FILL_FEATURE);
......@@ -302,8 +302,8 @@ public class KeyboardAccessoryModernViewTest {
@MediumTest
public void testDismissesPaymentEducationBubbleOnFilling() {
AutofillBarItem itemWithIPH = new AutofillBarItem(
new AutofillSuggestion("Johnathan", "Smith", DropdownItem.NO_ICON, false, 70000,
false, false, false),
new AutofillSuggestion("Johnathan", "Smith", /*itemTag=*/"", DropdownItem.NO_ICON,
false, 70000, false, false, false),
new KeyboardAccessoryData.Action("", AUTOFILL_SUGGESTION, unused -> {}));
itemWithIPH.setFeatureForIPH(FeatureConstants.KEYBOARD_ACCESSORY_PAYMENT_FILLING_FEATURE);
......@@ -358,8 +358,8 @@ public class KeyboardAccessoryModernViewTest {
private BarItem[] createAutofillChipAndTab(String label, Callback<Action> chipCallback) {
return new BarItem[] {
new AutofillBarItem(new AutofillSuggestion(label, "Smith", DropdownItem.NO_ICON,
false, 1, false, false, false),
new AutofillBarItem(new AutofillSuggestion(label, "Smith", /*itemTag=*/"",
DropdownItem.NO_ICON, false, 1, false, false, false),
new KeyboardAccessoryData.Action(
"Unused", AUTOFILL_SUGGESTION, chipCallback)),
createTabs()};
......
......@@ -246,10 +246,10 @@ public class KeyboardAccessoryControllerTest {
mCoordinator.registerActionProvider(generationProvider);
mCoordinator.registerAutofillProvider(autofillSuggestionProvider, mMockAutofillDelegate);
AutofillSuggestion suggestion1 =
new AutofillSuggestion("FirstSuggestion", "", 0, false, 0, false, false, false);
AutofillSuggestion suggestion2 =
new AutofillSuggestion("SecondSuggestion", "", 0, false, 0, false, false, false);
AutofillSuggestion suggestion1 = new AutofillSuggestion(
"FirstSuggestion", "", /* itemTag= */ "", 0, false, 0, false, false, false);
AutofillSuggestion suggestion2 = new AutofillSuggestion(
"SecondSuggestion", "", /* itemTag= */ "", 0, false, 0, false, false, false);
Action generationAction = new Action("Generate", GENERATE_PASSWORD_AUTOMATIC, (a) -> {});
autofillSuggestionProvider.notifyObservers(
new AutofillSuggestion[] {suggestion1, suggestion2});
......@@ -301,8 +301,8 @@ public class KeyboardAccessoryControllerTest {
mCoordinator.registerActionProvider(generationProvider);
mCoordinator.registerAutofillProvider(autofillSuggestionProvider, mMockAutofillDelegate);
AutofillSuggestion suggestion =
new AutofillSuggestion("Suggestion", "", 0, false, 0, false, false, false);
AutofillSuggestion suggestion = new AutofillSuggestion(
"Suggestion", "", /* itemTag= */ "", 0, false, 0, false, false, false);
Action generationAction = new Action("Generate", GENERATE_PASSWORD_AUTOMATIC, (a) -> {});
autofillSuggestionProvider.notifyObservers(
new AutofillSuggestion[] {suggestion, suggestion});
......@@ -355,7 +355,7 @@ public class KeyboardAccessoryControllerTest {
new PropertyProvider<>(AUTOFILL_SUGGESTION);
int suggestionId = 0x1; // The address ID is located in the least 16 bit.
AutofillSuggestion addressSuggestion = new AutofillSuggestion(
"John", "Main Str", 0, false, suggestionId, false, false, false);
"John", "Main Str", /* itemTag= */ "", 0, false, suggestionId, false, false, false);
mCoordinator.registerAutofillProvider(autofillSuggestionProvider, mMockAutofillDelegate);
autofillSuggestionProvider.notifyObservers(
new AutofillSuggestion[] {addressSuggestion, addressSuggestion, addressSuggestion});
......@@ -373,8 +373,8 @@ public class KeyboardAccessoryControllerTest {
PropertyProvider<AutofillSuggestion[]> autofillSuggestionProvider =
new PropertyProvider<>(AUTOFILL_SUGGESTION);
int suggestionId = 0x10000; // The payment ID is located in the higher 16 bit.
AutofillSuggestion paymentSuggestion = new AutofillSuggestion(
"John", "4828 ****", 0, false, suggestionId, false, false, false);
AutofillSuggestion paymentSuggestion = new AutofillSuggestion("John", "4828 ****",
/* itemTag= */ "", 0, false, suggestionId, false, false, false);
mCoordinator.registerAutofillProvider(autofillSuggestionProvider, mMockAutofillDelegate);
autofillSuggestionProvider.notifyObservers(
new AutofillSuggestion[] {paymentSuggestion, paymentSuggestion, paymentSuggestion});
......@@ -391,10 +391,12 @@ public class KeyboardAccessoryControllerTest {
public void testCreatesIPHForSecondPasswordItem() {
PropertyProvider<AutofillSuggestion[]> autofillSuggestionProvider =
new PropertyProvider<>(AUTOFILL_SUGGESTION);
AutofillSuggestion passwordSuggestion1 = new AutofillSuggestion(
"John", "****", 0, false, PopupItemId.ITEM_ID_USERNAME_ENTRY, false, false, false);
AutofillSuggestion passwordSuggestion2 = new AutofillSuggestion("Eva", "*******", 0, false,
PopupItemId.ITEM_ID_PASSWORD_ENTRY, false, false, false);
AutofillSuggestion passwordSuggestion1 =
new AutofillSuggestion("John", "****", /* itemTg= */ "", 0, false,
PopupItemId.ITEM_ID_USERNAME_ENTRY, false, false, false);
AutofillSuggestion passwordSuggestion2 =
new AutofillSuggestion("Eva", "*******", /* itemTag= */ "", 0, false,
PopupItemId.ITEM_ID_PASSWORD_ENTRY, false, false, false);
mCoordinator.registerAutofillProvider(autofillSuggestionProvider, mMockAutofillDelegate);
autofillSuggestionProvider.notifyObservers(new AutofillSuggestion[] {
passwordSuggestion1, passwordSuggestion2, passwordSuggestion2});
......@@ -443,8 +445,8 @@ public class KeyboardAccessoryControllerTest {
mCoordinator.dismiss(); // Hide, so it's brought up again.
PropertyProvider<AutofillSuggestion[]> autofillSuggestionProvider =
new PropertyProvider<>(AUTOFILL_SUGGESTION);
AutofillSuggestion suggestion =
new AutofillSuggestion("Label", "sublabel", 0, false, 0, false, false, false);
AutofillSuggestion suggestion = new AutofillSuggestion(
"Label", "sublabel", /* itemTag= */ "", 0, false, 0, false, false, false);
mCoordinator.registerAutofillProvider(autofillSuggestionProvider, mMockAutofillDelegate);
autofillSuggestionProvider.notifyObservers(new AutofillSuggestion[] {suggestion});
mCoordinator.show();
......@@ -487,8 +489,8 @@ public class KeyboardAccessoryControllerTest {
PropertyProvider<AutofillSuggestion[]> autofillSuggestionProvider =
new PropertyProvider<>(AUTOFILL_SUGGESTION);
AutofillSuggestion suggestion =
new AutofillSuggestion("Label", "sublabel", 0, false, 0, false, false, false);
AutofillSuggestion suggestion = new AutofillSuggestion(
"Label", "sublabel", /* itemTag= */ "", 0, false, 0, false, false, false);
mCoordinator.registerAutofillProvider(autofillSuggestionProvider, mMockAutofillDelegate);
autofillSuggestionProvider.notifyObservers(new AutofillSuggestion[] {suggestion});
assertThat(getShownMetricsCount(AccessoryBarContents.WITH_AUTOFILL_SUGGESTIONS), is(1));
......
......@@ -173,8 +173,8 @@ public class AutofillPopupBridge implements AutofillDelegate, DialogInterface.On
String label, String sublabel, int iconId, boolean isIconAtStart,
int suggestionId, boolean isDeletable, boolean isLabelMultiline, boolean isLabelBold) {
int drawableId = iconId == 0 ? DropdownItem.NO_ICON : iconId;
array[index] = new AutofillSuggestion(label, sublabel, drawableId, isIconAtStart,
suggestionId, isDeletable, isLabelMultiline, isLabelBold);
array[index] = new AutofillSuggestion(label, sublabel, /*itemTag= */ "", drawableId,
isIconAtStart, suggestionId, isDeletable, isLabelMultiline, isLabelBold);
}
@NativeMethods
......
......@@ -103,24 +103,24 @@ public class AutofillTest {
private AutofillSuggestion[] createTwoAutofillSuggestionArray() {
return new AutofillSuggestion[] {
new AutofillSuggestion("Sherlock Holmes", "221B Baker Street", DropdownItem.NO_ICON,
false, 42, false, false, false),
new AutofillSuggestion("Arthur Dent", "West Country", DropdownItem.NO_ICON,
false, 43, false, false, false),
new AutofillSuggestion("Sherlock Holmes", "221B Baker Street", /*itemTag=*/"",
DropdownItem.NO_ICON, false, 42, false, false, false),
new AutofillSuggestion("Arthur Dent", "West Country", /*itemTag=*/"",
DropdownItem.NO_ICON, false, 43, false, false, false),
};
}
private AutofillSuggestion[] createFiveAutofillSuggestionArray() {
return new AutofillSuggestion[] {
new AutofillSuggestion("Sherlock Holmes", "221B Baker Street", DropdownItem.NO_ICON,
false, 42, false, false, false),
new AutofillSuggestion("Arthur Dent", "West Country", DropdownItem.NO_ICON,
false, 43, false, false, false),
new AutofillSuggestion("Arthos", "France", DropdownItem.NO_ICON,
new AutofillSuggestion("Sherlock Holmes", "221B Baker Street", /*itemTag=*/"",
DropdownItem.NO_ICON, false, 42, false, false, false),
new AutofillSuggestion("Arthur Dent", "West Country", /*itemTag=*/"",
DropdownItem.NO_ICON, false, 43, false, false, false),
new AutofillSuggestion("Arthos", "France", /*itemTag=*/"", DropdownItem.NO_ICON,
false, 44, false, false, false),
new AutofillSuggestion("Porthos", "France", DropdownItem.NO_ICON,
new AutofillSuggestion("Porthos", "France", /*itemTag=*/"", DropdownItem.NO_ICON,
false, 45, false, false, false),
new AutofillSuggestion("Aramis", "France", DropdownItem.NO_ICON,
new AutofillSuggestion("Aramis", "France", /*itemTag=*/"", DropdownItem.NO_ICON,
false, 46, false, false, false),
};
}
......
......@@ -52,6 +52,18 @@
android:singleLine="true"
android:textAlignment="viewStart"
android:textAppearance="@style/TextAppearance.TextSmall.Secondary" />
<TextView
android:id="@+id/dropdown_item_tag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/autofill_dropdown_item_label_margin"
android:layout_marginStart="@dimen/autofill_dropdown_item_label_margin"
android:ellipsize="end"
android:includeFontPadding="false"
android:singleLine="true"
android:textAlignment="viewStart"
android:textAppearance="@style/TextAppearance.TextSmall.Secondary" />
</LinearLayout>
<ImageView
......
......@@ -45,6 +45,16 @@
android:singleLine="true"
android:textAlignment="viewStart"
android:textAppearance="@style/TextAppearance.TextSmall.Secondary" />
<TextView
android:id="@+id/dropdown_item_tag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:includeFontPadding="false"
android:singleLine="true"
android:textAlignment="viewStart"
android:textAppearance="@style/TextAppearance.TextSmall.Secondary" />
</LinearLayout>
<ImageView
......
......@@ -8,6 +8,7 @@
<!-- Dimens for legacy UI
TODO(crbug.com/874077): Remove once refresh UI is fully rolled out. -->
<dimen name="autofill_dropdown_item_height">50dp</dimen>
<dimen name="autofill_dropdown_item_tag_height">16dp</dimen>
<dimen name="autofill_dropdown_item_divider_height">1dp</dimen>
<dimen name="autofill_dropdown_item_label_margin">10dp</dimen>
<dimen name="autofill_dropdown_icon_margin">8dp</dimen>
......
......@@ -86,6 +86,9 @@ public class AutofillDropdownAdapter extends ArrayAdapter<DropdownItem> {
if (mIsRefresh) {
TextView labelView = populateLabelView(item, layout);
populateSublabelView(item, layout);
// For refreshed layout, ignore the return value as we don't need to adjust the height
// of the view.
populateItemTagView(item, layout);
ImageView iconView =
populateIconView((ImageView) layout.findViewById(R.id.end_dropdown_icon), item);
if (iconView != null) {
......@@ -133,6 +136,16 @@ public class AutofillDropdownAdapter extends ArrayAdapter<DropdownItem> {
divider.setDividerColor(dividerColor);
}
// Layout of the item tag view, which has a smaller font and sits below the sub
// label.
TextView itemTagView = populateItemTagView(item, layout);
if (itemTagView != null) {
itemTagView.setTextSize(TypedValue.COMPLEX_UNIT_PX,
mContext.getResources().getDimension(item.getSublabelFontSizeResId()));
height += mContext.getResources().getDimensionPixelSize(
R.dimen.autofill_dropdown_item_tag_height);
}
// Note: trying to set the height of the root LinearLayout breaks accessibility,
// so we have to adjust the height of this LinearLayout that wraps the TextViews
// instead. If you need to modify this layout, don't forget to test it with TalkBack and
......@@ -234,6 +247,26 @@ public class AutofillDropdownAdapter extends ArrayAdapter<DropdownItem> {
return sublabelView;
}
/**
* Sets the text of the itemTag's View if such text exists; otherwise, sets the View's
* visibility to GONE.
* @param item the DropdownItem for this row.
* @param layout the View in which the label can be found.
* @return the View if it has been set to be visible; null otherwise. This view is already part
* of the view hierarchy, thus no need to explicitly add it.
*/
private TextView populateItemTagView(DropdownItem item, View layout) {
TextView itemTagView = (TextView) layout.findViewById(R.id.dropdown_item_tag);
CharSequence itemTag = item.getItemTag();
if (TextUtils.isEmpty(itemTag)) {
itemTagView.setVisibility(View.GONE);
return null;
}
itemTagView.setText(itemTag);
itemTagView.setVisibility(View.VISIBLE);
return itemTagView;
}
/**
* Sets the drawable in the given ImageView to the resource identified in the item, or sets
* iconView to visibility GONE if no icon is given.
......
......@@ -12,6 +12,7 @@ import org.chromium.ui.DropdownItemBase;
public class AutofillSuggestion extends DropdownItemBase {
private final String mLabel;
private final String mSublabel;
private final String mItemTag;
private final int mIconId;
private final boolean mIsIconAtStart;
private final int mSuggestionId;
......@@ -24,6 +25,7 @@ public class AutofillSuggestion extends DropdownItemBase {
*
* @param label The main label of the Autofill suggestion.
* @param sublabel The describing sublabel of the Autofill suggestion.
* @param itemTag The tag for the autofill suggestion.
* @param iconId The resource ID for the icon associated with the suggestion, or
* {@code DropdownItem.NO_ICON} for no icon.
* @param isIconAtStart {@code true} if {@code iconId} is displayed before {@code label}.
......@@ -32,10 +34,12 @@ public class AutofillSuggestion extends DropdownItemBase {
* @param isMultilineLabel Whether the label is displayed over multiple lines.
* @param isBoldLabel Whether the label is displayed in {@code Typeface.BOLD}.
*/
public AutofillSuggestion(String label, String sublabel, int iconId, boolean isIconAtStart,
int suggestionId, boolean isDeletable, boolean isMultilineLabel, boolean isBoldLabel) {
public AutofillSuggestion(String label, String sublabel, String itemTag, int iconId,
boolean isIconAtStart, int suggestionId, boolean isDeletable, boolean isMultilineLabel,
boolean isBoldLabel) {
mLabel = label;
mSublabel = sublabel;
mItemTag = itemTag;
mIconId = iconId;
mIsIconAtStart = isIconAtStart;
mSuggestionId = suggestionId;
......@@ -54,6 +58,11 @@ public class AutofillSuggestion extends DropdownItemBase {
return mSublabel;
}
@Override
public String getItemTag() {
return mItemTag;
}
@Override
public int getIconId() {
return mIconId;
......
......@@ -603,8 +603,8 @@ public class AutofillProvider {
final AutofillSuggestion[] suggestions = new AutofillSuggestion[datalistValues.length];
for (int i = 0; i < suggestions.length; i++) {
suggestions[i] = new AutofillSuggestion(datalistValues[i], datalistLabels[i],
DropdownItem.NO_ICON, false /* isIconAtLeft */, i, false /* isDeletable */,
false /* isMultilineLabel */, false /* isBoldLabel */);
/* itemTag= */ "", DropdownItem.NO_ICON, false /* isIconAtLeft */, i,
false /* isDeletable */, false /* isMultilineLabel */, false /* isBoldLabel */);
}
if (mWebContentsAccessibility == null) {
mWebContentsAccessibility = WebContentsAccessibility.fromWebContents(mWebContents);
......
......@@ -19,6 +19,10 @@ public interface DropdownItem {
* Returns the sublabel that should be shown in the dropdown.
*/
String getSublabel();
/**
* Returns the item tag that should be shown in the dropdown.
*/
String getItemTag();
/**
* Returns the drawable id of the icon that should be shown in the dropdown, or NO_ICON.
*/
......
......@@ -19,6 +19,11 @@ public class DropdownItemBase implements DropdownItem {
return null;
}
@Override
public String getItemTag() {
return null;
}
@Override
public int getIconId() {
return NO_ICON;
......
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