Commit 44204c92 authored by Vasilii Sukhanov's avatar Vasilii Sukhanov Committed by Commit Bot

Render 'No username' as a secondary text in the password drop-down.

TBR=tedchoc@chromium.org

Bug: 874039
Change-Id: I183677ed1399b8dcd6b94b87e9ae88851fa4441c
Reviewed-on: https://chromium-review.googlesource.com/1181423
Commit-Queue: Vasilii Sukhanov <vasilii@chromium.org>
Reviewed-by: default avatarFabio Tirelo <ftirelo@chromium.org>
Reviewed-by: default avatarTommy Martino <tmartino@chromium.org>
Reviewed-by: default avatarVadym Doroshenko <dvadym@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585044}
parent f71fb12e
......@@ -107,7 +107,7 @@ void AutofillPopupViewAndroid::OnSuggestionsChanged() {
Java_AutofillPopupBridge_addToAutofillSuggestionArray(
env, data_array, i, value, label, android_icon_id,
/*icon_at_start=*/false, suggestion.frontend_id, is_deletable,
is_label_multiline, suggestion.is_value_bold);
is_label_multiline, /*isLabelBold*/ false);
}
Java_AutofillPopupBridge_show(env, java_object_, data_array,
......
......@@ -166,8 +166,8 @@ class AutofillPopupItemView : public AutofillPopupRowView {
// The description view can be nullptr.
virtual views::View* CreateDescriptionLabel();
// Creates a description label iff the description text isn't empty.
views::Label* CreateDescriptionLabelInternal() const;
// Creates a label matching the style of the description label.
views::Label* CreateSecondaryLabel(const base::string16& text) const;
private:
void AddIcon(gfx::ImageSkia icon);
......@@ -405,6 +405,12 @@ void AutofillPopupItemView::RefreshStyle() {
views::View* AutofillPopupItemView::CreateValueLabel() {
// TODO(crbug.com/831603): Remove elision responsibilities from controller.
base::string16 text =
popup_view_->controller()->GetElidedValueAt(line_number_);
if (popup_view_->controller()
->GetSuggestionAt(line_number_)
.is_value_secondary)
return CreateSecondaryLabel(text);
views::Label* text_label = new views::Label(
popup_view_->controller()->GetElidedValueAt(line_number_),
{views::style::GetFont(ChromeTextContext::CONTEXT_BODY_TEXT_LARGE,
......@@ -416,24 +422,21 @@ views::View* AutofillPopupItemView::CreateValueLabel() {
}
views::View* AutofillPopupItemView::CreateDescriptionLabel() {
return CreateDescriptionLabelInternal();
base::string16 text =
popup_view_->controller()->GetElidedLabelAt(line_number_);
return text.empty() ? nullptr : CreateSecondaryLabel(text);
}
views::Label* AutofillPopupItemView::CreateDescriptionLabelInternal() const {
const base::string16& description_text =
popup_view_->controller()->GetElidedLabelAt(line_number_);
if (!description_text.empty()) {
views::Label* subtext_label = new views::Label(
description_text,
{views::style::GetFont(ChromeTextContext::CONTEXT_BODY_TEXT_LARGE,
ChromeTextStyle::STYLE_SECONDARY)});
subtext_label->SetEnabledColor(views::style::GetColor(
*this, ChromeTextContext::CONTEXT_BODY_TEXT_LARGE,
ChromeTextStyle::STYLE_SECONDARY));
return subtext_label;
}
return nullptr;
views::Label* AutofillPopupItemView::CreateSecondaryLabel(
const base::string16& text) const {
views::Label* subtext_label = new views::Label(
text, {views::style::GetFont(ChromeTextContext::CONTEXT_BODY_TEXT_LARGE,
ChromeTextStyle::STYLE_SECONDARY)});
subtext_label->SetEnabledColor(
views::style::GetColor(*this, ChromeTextContext::CONTEXT_BODY_TEXT_LARGE,
ChromeTextStyle::STYLE_SECONDARY));
return subtext_label;
}
void AutofillPopupItemView::AddIcon(gfx::ImageSkia icon) {
......@@ -496,14 +499,22 @@ PasswordPopupSuggestionView* PasswordPopupSuggestionView::Create(
views::View* PasswordPopupSuggestionView::CreateValueLabel() {
views::View* label = AutofillPopupSuggestionView::CreateValueLabel();
// Empty username is rendered as a secondary text. It doesn't need to be
// truncated.
if (popup_view_->controller()
->GetSuggestionAt(line_number_)
.is_value_secondary)
return label;
return new ConstrainedWidthView(label, kAutofillPopupUsernameMaxWidth);
}
views::View* PasswordPopupSuggestionView::CreateDescriptionLabel() {
views::Label* label = CreateDescriptionLabelInternal();
if (!label)
base::string16 text =
popup_view_->controller()->GetElidedLabelAt(line_number_);
if (text.empty())
return nullptr;
views::Label* label = CreateSecondaryLabel(text);
label->SetElideBehavior(gfx::TRUNCATE);
return new ConstrainedWidthView(label, kAutofillPopupPasswordMaxWidth);
}
......
......@@ -9,10 +9,7 @@
namespace autofill {
Suggestion::Suggestion()
: frontend_id(0),
match(PREFIX_MATCH),
is_value_bold(false) {
}
: frontend_id(0), match(PREFIX_MATCH), is_value_secondary(false) {}
Suggestion::Suggestion(const Suggestion& other)
: backend_id(other.backend_id),
......@@ -22,14 +19,13 @@ Suggestion::Suggestion(const Suggestion& other)
custom_icon(other.custom_icon),
icon(other.icon),
match(other.match),
is_value_bold(other.is_value_bold) {}
is_value_secondary(other.is_value_secondary) {}
Suggestion::Suggestion(const base::string16& v)
: frontend_id(0),
value(v),
match(PREFIX_MATCH),
is_value_bold(false) {
}
is_value_secondary(false) {}
Suggestion::Suggestion(const std::string& v,
const std::string& l,
......@@ -40,8 +36,7 @@ Suggestion::Suggestion(const std::string& v,
label(base::UTF8ToUTF16(l)),
icon(base::UTF8ToUTF16(i)),
match(PREFIX_MATCH),
is_value_bold(false) {
}
is_value_secondary(false) {}
Suggestion::~Suggestion() = default;
......
......@@ -51,7 +51,7 @@ struct Suggestion {
// If |custom_icon| is empty, the name of the fallback built-in icon.
base::string16 icon;
MatchMode match;
bool is_value_bold; // true if |value| should be displayed in bold type face.
bool is_value_secondary; // |value| should be displayed as secondary text.
};
} // namespace autofill
......
......@@ -50,8 +50,10 @@ constexpr base::char16 kPasswordReplacementChar = 0x2022;
// Returns |username| unless it is empty. For an empty |username| returns a
// localised string saying this username is empty. Use this for displaying the
// usernames to the user.
base::string16 ReplaceEmptyUsername(const base::string16& username) {
// usernames to the user. |replaced| is set to true iff |username| is empty.
base::string16 ReplaceEmptyUsername(const base::string16& username,
bool* replaced) {
*replaced = username.empty();
if (username.empty())
return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_EMPTY_LOGIN);
return username;
......@@ -92,7 +94,10 @@ void AppendSuggestionIfMatching(
base::string16 lower_contents = base::i18n::ToLower(field_contents);
if (show_all || autofill::FieldIsSuggestionSubstringStartingOnTokenBoundary(
lower_suggestion, lower_contents, true)) {
autofill::Suggestion suggestion(ReplaceEmptyUsername(field_suggestion));
bool replaced_username;
autofill::Suggestion suggestion(
ReplaceEmptyUsername(field_suggestion, &replaced_username));
suggestion.is_value_secondary = replaced_username;
suggestion.label =
signon_realm.empty()
? base::string16(password_length, kPasswordReplacementChar)
......
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