Commit edf32f6b authored by Manas Verma's avatar Manas Verma Committed by Commit Bot

[Autofill] Update suggestion UI to include offer message.

Includes a third line in the autofill popup suggestion UI, which will
include credit card offer data.

Bug: 1093057
Change-Id: I26b2c647a6dbe81ec367ff75dbdcc2074375b7fe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2436849Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Reviewed-by: default avatarSiyu An <siyua@chromium.org>
Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Reviewed-by: default avatarDominic Battré <battre@chromium.org>
Commit-Queue: Manas Verma <manasverma@google.com>
Cr-Commit-Position: refs/heads/master@{#817528}
parent c8924aa9
......@@ -71,6 +71,9 @@ constexpr int kAutofillPopupPasswordMaxWidth = 108;
// The additional height of the row in case it has two lines of text.
constexpr int kAutofillPopupAdditionalDoubleRowHeight = 22;
// The additional padding of the row in case it has three lines of text.
constexpr int kAutofillPopupAdditionalPadding = 16;
// Vertical spacing between labels in one row.
constexpr int kAdjacentLabelsVerticalSpacing = 2;
......@@ -186,6 +189,17 @@ std::unique_ptr<views::ImageView> GetStoreIndicatorIconImageView(
return GetIconImageViewByName(suggestion.store_indicator_icon);
}
// Creates a label with a specific context and style.
std::unique_ptr<views::Label> CreateLabelWithStyleAndContext(
const base::string16& text,
int text_context,
int text_style) {
auto label = std::make_unique<views::Label>(text, text_context, text_style);
label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
return label;
}
} // namespace
namespace autofill {
......@@ -258,20 +272,9 @@ class AutofillPopupItemView : public AutofillPopupRowView {
// Returns a value view. The label part is optional but allow caller to keep
// track of all the labels for background color update.
virtual ViewWithLabel CreateValueLabel();
// Creates an optional label below the value.
virtual ViewWithLabel CreateSubtextLabel();
// The description view can be nullptr.
virtual ViewWithLabel CreateDescriptionLabel();
// Creates a label matching the style of the description label.
std::unique_ptr<views::Label> CreateSecondaryLabel(
const base::string16& text) const;
// Creates a label with a specific context and style.
std::unique_ptr<views::Label> CreateLabelWithStyleAndContext(
const base::string16& text,
int text_context,
int text_style) const;
// Returns the font weight to be applied to primary info.
virtual gfx::Font::Weight GetPrimaryTextWeight() const = 0;
......@@ -285,6 +288,13 @@ class AutofillPopupItemView : public AutofillPopupRowView {
}
private:
// Returns a vector of optional labels to be displayed beneath value.
virtual std::vector<ViewWithLabel> CreateSubtextLabels();
// Returns the minimum cross axis size depending on the length of
// GetSubtexts();
void UpdateLayoutSize(views::BoxLayout* layout_manager, int64_t num_subtexts);
const int frontend_id_;
// All the labels inside this view.
......@@ -306,7 +316,7 @@ class AutofillPopupSuggestionView : public AutofillPopupItemView {
// AutofillPopupItemView:
int GetPrimaryTextStyle() override;
gfx::Font::Weight GetPrimaryTextWeight() const override;
ViewWithLabel CreateSubtextLabel() override;
std::vector<ViewWithLabel> CreateSubtextLabels() override;
AutofillPopupSuggestionView(AutofillPopupViewNativeViews* popup_view,
int line_number,
int frontend_id);
......@@ -327,7 +337,7 @@ class PasswordPopupSuggestionView : public AutofillPopupSuggestionView {
protected:
// AutofillPopupItemView:
ViewWithLabel CreateValueLabel() override;
ViewWithLabel CreateSubtextLabel() override;
std::vector<ViewWithLabel> CreateSubtextLabels() override;
ViewWithLabel CreateDescriptionLabel() override;
gfx::Font::Weight GetPrimaryTextWeight() const override;
......@@ -436,6 +446,11 @@ void AutofillPopupItemView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
text.push_back(suggestion.label);
}
if (!suggestion.offer_label.empty()) {
// |offer_label| is only populated for credit card suggestions.
text.push_back(suggestion.offer_label);
}
if (!suggestion.additional_label.empty()) {
// |additional_label| is only populated in a passwords context.
text.push_back(suggestion.additional_label);
......@@ -527,8 +542,8 @@ void AutofillPopupItemView::CreateContent() {
/*resize=*/false, layout_manager);
}
ViewWithLabel lower_value_label = CreateSubtextLabel();
ViewWithLabel value_label = CreateValueLabel();
std::vector<ViewWithLabel> subtext_labels = CreateSubtextLabels();
ViewWithLabel description_label = CreateDescriptionLabel();
std::unique_ptr<views::View> all_labels = std::make_unique<views::View>();
......@@ -545,17 +560,12 @@ void AutofillPopupItemView::CreateContent() {
grid_layout->SkipColumns(1);
}
const int kStandardRowHeight =
views::MenuConfig::instance().touchable_menu_height;
if (lower_value_label.first) {
layout_manager->set_minimum_cross_axis_size(
kStandardRowHeight + kAutofillPopupAdditionalDoubleRowHeight);
UpdateLayoutSize(layout_manager, subtext_labels.size());
for (ViewWithLabel& subtext_label : subtext_labels) {
grid_layout->StartRowWithPadding(0, 0, 0, kAdjacentLabelsVerticalSpacing);
grid_layout->AddView(std::move(lower_value_label.first));
KeepLabel(lower_value_label.second);
grid_layout->AddView(std::move(subtext_label.first));
KeepLabel(subtext_label.second);
grid_layout->SkipColumns(1);
} else {
layout_manager->set_minimum_cross_axis_size(kStandardRowHeight);
}
AddChildView(std::move(all_labels));
......@@ -603,7 +613,9 @@ AutofillPopupItemView::ViewWithLabel AutofillPopupItemView::CreateValueLabel() {
->controller()
->GetSuggestionAt(line_number())
.is_value_secondary) {
std::unique_ptr<views::Label> label = CreateSecondaryLabel(text);
std::unique_ptr<views::Label> label = CreateLabelWithStyleAndContext(
text, views::style::CONTEXT_DIALOG_BODY_TEXT,
views::style::STYLE_SECONDARY);
view_and_label.second = label.get();
view_and_label.first = std::move(label);
return view_and_label;
......@@ -624,32 +636,34 @@ AutofillPopupItemView::ViewWithLabel AutofillPopupItemView::CreateValueLabel() {
return view_and_label;
}
AutofillPopupItemView::ViewWithLabel
AutofillPopupItemView::CreateSubtextLabel() {
return ViewWithLabel();
}
AutofillPopupItemView::ViewWithLabel
AutofillPopupItemView::CreateDescriptionLabel() {
return ViewWithLabel();
}
std::unique_ptr<views::Label> AutofillPopupItemView::CreateSecondaryLabel(
const base::string16& text) const {
return CreateLabelWithStyleAndContext(text,
views::style::CONTEXT_DIALOG_BODY_TEXT,
views::style::STYLE_SECONDARY);
std::vector<AutofillPopupItemView::ViewWithLabel>
AutofillPopupItemView::CreateSubtextLabels() {
return {};
}
std::unique_ptr<views::Label>
AutofillPopupItemView::CreateLabelWithStyleAndContext(
const base::string16& text,
int text_context,
int text_style) const {
auto label = std::make_unique<views::Label>(text, text_context, text_style);
label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
void AutofillPopupItemView::UpdateLayoutSize(views::BoxLayout* layout_manager,
int64_t num_subtexts) {
const int kStandardRowHeight =
views::MenuConfig::instance().touchable_menu_height;
if (num_subtexts == 0) {
layout_manager->set_minimum_cross_axis_size(kStandardRowHeight);
} else {
layout_manager->set_minimum_cross_axis_size(
kStandardRowHeight + kAutofillPopupAdditionalDoubleRowHeight);
}
return label;
// In the case that there are three rows in total, adding extra padding to
// avoid cramming.
if (num_subtexts == 2) {
layout_manager->set_inside_border_insets(
gfx::Insets(kAutofillPopupAdditionalPadding, GetHorizontalMargin(),
kAutofillPopupAdditionalPadding, GetHorizontalMargin()));
}
}
void AutofillPopupItemView::AddSpacerWithSize(int spacer_width,
......@@ -691,20 +705,29 @@ AutofillPopupSuggestionView::AutofillPopupSuggestionView(
SetFocusBehavior(FocusBehavior::ALWAYS);
}
AutofillPopupItemView::ViewWithLabel
AutofillPopupSuggestionView::CreateSubtextLabel() {
base::string16 label_text =
std::vector<AutofillPopupItemView::ViewWithLabel>
AutofillPopupSuggestionView::CreateSubtextLabels() {
const base::string16& second_row_label =
popup_view()->controller()->GetSuggestionAt(line_number()).label;
if (label_text.empty())
return ViewWithLabel();
const base::string16& third_row_label =
popup_view()->controller()->GetSuggestionAt(line_number()).offer_label;
std::vector<AutofillPopupItemView::ViewWithLabel> labels;
for (const base::string16& text : {second_row_label, third_row_label}) {
// If a row is missing, do not include any further rows.
if (text.empty())
return labels;
auto label = CreateLabelWithStyleAndContext(
text, ChromeTextContext::CONTEXT_DIALOG_BODY_TEXT_SMALL,
views::style::STYLE_SECONDARY);
ViewWithLabel result;
result.second = label.get();
result.first = std::move(label);
labels.emplace_back(std::move(result));
}
auto label = CreateLabelWithStyleAndContext(
label_text, ChromeTextContext::CONTEXT_DIALOG_BODY_TEXT_SMALL,
views::style::STYLE_SECONDARY);
ViewWithLabel result;
result.second = label.get();
result.first = std::move(label);
return result;
return labels;
}
/************** PasswordPopupSuggestionView **************/
......@@ -727,15 +750,19 @@ PasswordPopupSuggestionView::CreateValueLabel() {
return label;
}
AutofillPopupItemView::ViewWithLabel
PasswordPopupSuggestionView::CreateSubtextLabel() {
auto label = CreateSecondaryLabel(masked_password_);
std::vector<AutofillPopupItemView::ViewWithLabel>
PasswordPopupSuggestionView::CreateSubtextLabels() {
auto label = CreateLabelWithStyleAndContext(
masked_password_, views::style::CONTEXT_DIALOG_BODY_TEXT,
views::style::STYLE_SECONDARY);
label->SetElideBehavior(gfx::TRUNCATE);
ViewWithLabel result;
result.second = label.get();
result.first = std::make_unique<ConstrainedWidthView>(
std::move(label), kAutofillPopupPasswordMaxWidth);
return result;
std::vector<AutofillPopupItemView::ViewWithLabel> labels;
labels.emplace_back(std::move(result));
return labels;
}
AutofillPopupItemView::ViewWithLabel
......@@ -743,7 +770,9 @@ PasswordPopupSuggestionView::CreateDescriptionLabel() {
if (origin_.empty())
return ViewWithLabel();
auto label = CreateSecondaryLabel(origin_);
auto label = CreateLabelWithStyleAndContext(
origin_, views::style::CONTEXT_DIALOG_BODY_TEXT,
views::style::STYLE_SECONDARY);
label->SetElideBehavior(gfx::ELIDE_HEAD);
ViewWithLabel result;
result.second = label.get();
......
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