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; ...@@ -71,6 +71,9 @@ constexpr int kAutofillPopupPasswordMaxWidth = 108;
// The additional height of the row in case it has two lines of text. // The additional height of the row in case it has two lines of text.
constexpr int kAutofillPopupAdditionalDoubleRowHeight = 22; 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. // Vertical spacing between labels in one row.
constexpr int kAdjacentLabelsVerticalSpacing = 2; constexpr int kAdjacentLabelsVerticalSpacing = 2;
...@@ -186,6 +189,17 @@ std::unique_ptr<views::ImageView> GetStoreIndicatorIconImageView( ...@@ -186,6 +189,17 @@ std::unique_ptr<views::ImageView> GetStoreIndicatorIconImageView(
return GetIconImageViewByName(suggestion.store_indicator_icon); 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
namespace autofill { namespace autofill {
...@@ -258,20 +272,9 @@ class AutofillPopupItemView : public AutofillPopupRowView { ...@@ -258,20 +272,9 @@ class AutofillPopupItemView : public AutofillPopupRowView {
// Returns a value view. The label part is optional but allow caller to keep // Returns a value view. The label part is optional but allow caller to keep
// track of all the labels for background color update. // track of all the labels for background color update.
virtual ViewWithLabel CreateValueLabel(); virtual ViewWithLabel CreateValueLabel();
// Creates an optional label below the value.
virtual ViewWithLabel CreateSubtextLabel();
// The description view can be nullptr. // The description view can be nullptr.
virtual ViewWithLabel CreateDescriptionLabel(); 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. // Returns the font weight to be applied to primary info.
virtual gfx::Font::Weight GetPrimaryTextWeight() const = 0; virtual gfx::Font::Weight GetPrimaryTextWeight() const = 0;
...@@ -285,6 +288,13 @@ class AutofillPopupItemView : public AutofillPopupRowView { ...@@ -285,6 +288,13 @@ class AutofillPopupItemView : public AutofillPopupRowView {
} }
private: 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_; const int frontend_id_;
// All the labels inside this view. // All the labels inside this view.
...@@ -306,7 +316,7 @@ class AutofillPopupSuggestionView : public AutofillPopupItemView { ...@@ -306,7 +316,7 @@ class AutofillPopupSuggestionView : public AutofillPopupItemView {
// AutofillPopupItemView: // AutofillPopupItemView:
int GetPrimaryTextStyle() override; int GetPrimaryTextStyle() override;
gfx::Font::Weight GetPrimaryTextWeight() const override; gfx::Font::Weight GetPrimaryTextWeight() const override;
ViewWithLabel CreateSubtextLabel() override; std::vector<ViewWithLabel> CreateSubtextLabels() override;
AutofillPopupSuggestionView(AutofillPopupViewNativeViews* popup_view, AutofillPopupSuggestionView(AutofillPopupViewNativeViews* popup_view,
int line_number, int line_number,
int frontend_id); int frontend_id);
...@@ -327,7 +337,7 @@ class PasswordPopupSuggestionView : public AutofillPopupSuggestionView { ...@@ -327,7 +337,7 @@ class PasswordPopupSuggestionView : public AutofillPopupSuggestionView {
protected: protected:
// AutofillPopupItemView: // AutofillPopupItemView:
ViewWithLabel CreateValueLabel() override; ViewWithLabel CreateValueLabel() override;
ViewWithLabel CreateSubtextLabel() override; std::vector<ViewWithLabel> CreateSubtextLabels() override;
ViewWithLabel CreateDescriptionLabel() override; ViewWithLabel CreateDescriptionLabel() override;
gfx::Font::Weight GetPrimaryTextWeight() const override; gfx::Font::Weight GetPrimaryTextWeight() const override;
...@@ -436,6 +446,11 @@ void AutofillPopupItemView::GetAccessibleNodeData(ui::AXNodeData* node_data) { ...@@ -436,6 +446,11 @@ void AutofillPopupItemView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
text.push_back(suggestion.label); 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()) { if (!suggestion.additional_label.empty()) {
// |additional_label| is only populated in a passwords context. // |additional_label| is only populated in a passwords context.
text.push_back(suggestion.additional_label); text.push_back(suggestion.additional_label);
...@@ -527,8 +542,8 @@ void AutofillPopupItemView::CreateContent() { ...@@ -527,8 +542,8 @@ void AutofillPopupItemView::CreateContent() {
/*resize=*/false, layout_manager); /*resize=*/false, layout_manager);
} }
ViewWithLabel lower_value_label = CreateSubtextLabel();
ViewWithLabel value_label = CreateValueLabel(); ViewWithLabel value_label = CreateValueLabel();
std::vector<ViewWithLabel> subtext_labels = CreateSubtextLabels();
ViewWithLabel description_label = CreateDescriptionLabel(); ViewWithLabel description_label = CreateDescriptionLabel();
std::unique_ptr<views::View> all_labels = std::make_unique<views::View>(); std::unique_ptr<views::View> all_labels = std::make_unique<views::View>();
...@@ -545,17 +560,12 @@ void AutofillPopupItemView::CreateContent() { ...@@ -545,17 +560,12 @@ void AutofillPopupItemView::CreateContent() {
grid_layout->SkipColumns(1); grid_layout->SkipColumns(1);
} }
const int kStandardRowHeight = UpdateLayoutSize(layout_manager, subtext_labels.size());
views::MenuConfig::instance().touchable_menu_height; for (ViewWithLabel& subtext_label : subtext_labels) {
if (lower_value_label.first) {
layout_manager->set_minimum_cross_axis_size(
kStandardRowHeight + kAutofillPopupAdditionalDoubleRowHeight);
grid_layout->StartRowWithPadding(0, 0, 0, kAdjacentLabelsVerticalSpacing); grid_layout->StartRowWithPadding(0, 0, 0, kAdjacentLabelsVerticalSpacing);
grid_layout->AddView(std::move(lower_value_label.first)); grid_layout->AddView(std::move(subtext_label.first));
KeepLabel(lower_value_label.second); KeepLabel(subtext_label.second);
grid_layout->SkipColumns(1); grid_layout->SkipColumns(1);
} else {
layout_manager->set_minimum_cross_axis_size(kStandardRowHeight);
} }
AddChildView(std::move(all_labels)); AddChildView(std::move(all_labels));
...@@ -603,7 +613,9 @@ AutofillPopupItemView::ViewWithLabel AutofillPopupItemView::CreateValueLabel() { ...@@ -603,7 +613,9 @@ AutofillPopupItemView::ViewWithLabel AutofillPopupItemView::CreateValueLabel() {
->controller() ->controller()
->GetSuggestionAt(line_number()) ->GetSuggestionAt(line_number())
.is_value_secondary) { .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.second = label.get();
view_and_label.first = std::move(label); view_and_label.first = std::move(label);
return view_and_label; return view_and_label;
...@@ -624,32 +636,34 @@ AutofillPopupItemView::ViewWithLabel AutofillPopupItemView::CreateValueLabel() { ...@@ -624,32 +636,34 @@ AutofillPopupItemView::ViewWithLabel AutofillPopupItemView::CreateValueLabel() {
return view_and_label; return view_and_label;
} }
AutofillPopupItemView::ViewWithLabel
AutofillPopupItemView::CreateSubtextLabel() {
return ViewWithLabel();
}
AutofillPopupItemView::ViewWithLabel AutofillPopupItemView::ViewWithLabel
AutofillPopupItemView::CreateDescriptionLabel() { AutofillPopupItemView::CreateDescriptionLabel() {
return ViewWithLabel(); return ViewWithLabel();
} }
std::unique_ptr<views::Label> AutofillPopupItemView::CreateSecondaryLabel( std::vector<AutofillPopupItemView::ViewWithLabel>
const base::string16& text) const { AutofillPopupItemView::CreateSubtextLabels() {
return CreateLabelWithStyleAndContext(text, return {};
views::style::CONTEXT_DIALOG_BODY_TEXT,
views::style::STYLE_SECONDARY);
} }
std::unique_ptr<views::Label> void AutofillPopupItemView::UpdateLayoutSize(views::BoxLayout* layout_manager,
AutofillPopupItemView::CreateLabelWithStyleAndContext( int64_t num_subtexts) {
const base::string16& text, const int kStandardRowHeight =
int text_context, views::MenuConfig::instance().touchable_menu_height;
int text_style) const { if (num_subtexts == 0) {
auto label = std::make_unique<views::Label>(text, text_context, text_style); layout_manager->set_minimum_cross_axis_size(kStandardRowHeight);
label->SetHorizontalAlignment(gfx::ALIGN_LEFT); } 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, void AutofillPopupItemView::AddSpacerWithSize(int spacer_width,
...@@ -691,20 +705,29 @@ AutofillPopupSuggestionView::AutofillPopupSuggestionView( ...@@ -691,20 +705,29 @@ AutofillPopupSuggestionView::AutofillPopupSuggestionView(
SetFocusBehavior(FocusBehavior::ALWAYS); SetFocusBehavior(FocusBehavior::ALWAYS);
} }
AutofillPopupItemView::ViewWithLabel std::vector<AutofillPopupItemView::ViewWithLabel>
AutofillPopupSuggestionView::CreateSubtextLabel() { AutofillPopupSuggestionView::CreateSubtextLabels() {
base::string16 label_text = const base::string16& second_row_label =
popup_view()->controller()->GetSuggestionAt(line_number()).label; popup_view()->controller()->GetSuggestionAt(line_number()).label;
if (label_text.empty()) const base::string16& third_row_label =
return ViewWithLabel(); 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( return labels;
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;
} }
/************** PasswordPopupSuggestionView **************/ /************** PasswordPopupSuggestionView **************/
...@@ -727,15 +750,19 @@ PasswordPopupSuggestionView::CreateValueLabel() { ...@@ -727,15 +750,19 @@ PasswordPopupSuggestionView::CreateValueLabel() {
return label; return label;
} }
AutofillPopupItemView::ViewWithLabel std::vector<AutofillPopupItemView::ViewWithLabel>
PasswordPopupSuggestionView::CreateSubtextLabel() { PasswordPopupSuggestionView::CreateSubtextLabels() {
auto label = CreateSecondaryLabel(masked_password_); auto label = CreateLabelWithStyleAndContext(
masked_password_, views::style::CONTEXT_DIALOG_BODY_TEXT,
views::style::STYLE_SECONDARY);
label->SetElideBehavior(gfx::TRUNCATE); label->SetElideBehavior(gfx::TRUNCATE);
ViewWithLabel result; ViewWithLabel result;
result.second = label.get(); result.second = label.get();
result.first = std::make_unique<ConstrainedWidthView>( result.first = std::make_unique<ConstrainedWidthView>(
std::move(label), kAutofillPopupPasswordMaxWidth); std::move(label), kAutofillPopupPasswordMaxWidth);
return result; std::vector<AutofillPopupItemView::ViewWithLabel> labels;
labels.emplace_back(std::move(result));
return labels;
} }
AutofillPopupItemView::ViewWithLabel AutofillPopupItemView::ViewWithLabel
...@@ -743,7 +770,9 @@ PasswordPopupSuggestionView::CreateDescriptionLabel() { ...@@ -743,7 +770,9 @@ PasswordPopupSuggestionView::CreateDescriptionLabel() {
if (origin_.empty()) if (origin_.empty())
return ViewWithLabel(); 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); label->SetElideBehavior(gfx::ELIDE_HEAD);
ViewWithLabel result; ViewWithLabel result;
result.second = label.get(); 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