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() { ...@@ -107,7 +107,7 @@ void AutofillPopupViewAndroid::OnSuggestionsChanged() {
Java_AutofillPopupBridge_addToAutofillSuggestionArray( Java_AutofillPopupBridge_addToAutofillSuggestionArray(
env, data_array, i, value, label, android_icon_id, env, data_array, i, value, label, android_icon_id,
/*icon_at_start=*/false, suggestion.frontend_id, is_deletable, /*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, Java_AutofillPopupBridge_show(env, java_object_, data_array,
......
...@@ -166,8 +166,8 @@ class AutofillPopupItemView : public AutofillPopupRowView { ...@@ -166,8 +166,8 @@ class AutofillPopupItemView : public AutofillPopupRowView {
// The description view can be nullptr. // The description view can be nullptr.
virtual views::View* CreateDescriptionLabel(); virtual views::View* CreateDescriptionLabel();
// Creates a description label iff the description text isn't empty. // Creates a label matching the style of the description label.
views::Label* CreateDescriptionLabelInternal() const; views::Label* CreateSecondaryLabel(const base::string16& text) const;
private: private:
void AddIcon(gfx::ImageSkia icon); void AddIcon(gfx::ImageSkia icon);
...@@ -405,6 +405,12 @@ void AutofillPopupItemView::RefreshStyle() { ...@@ -405,6 +405,12 @@ void AutofillPopupItemView::RefreshStyle() {
views::View* AutofillPopupItemView::CreateValueLabel() { views::View* AutofillPopupItemView::CreateValueLabel() {
// TODO(crbug.com/831603): Remove elision responsibilities from controller. // 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( views::Label* text_label = new views::Label(
popup_view_->controller()->GetElidedValueAt(line_number_), popup_view_->controller()->GetElidedValueAt(line_number_),
{views::style::GetFont(ChromeTextContext::CONTEXT_BODY_TEXT_LARGE, {views::style::GetFont(ChromeTextContext::CONTEXT_BODY_TEXT_LARGE,
...@@ -416,24 +422,21 @@ views::View* AutofillPopupItemView::CreateValueLabel() { ...@@ -416,24 +422,21 @@ views::View* AutofillPopupItemView::CreateValueLabel() {
} }
views::View* AutofillPopupItemView::CreateDescriptionLabel() { 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 { views::Label* AutofillPopupItemView::CreateSecondaryLabel(
const base::string16& description_text = const base::string16& text) const {
popup_view_->controller()->GetElidedLabelAt(line_number_); views::Label* subtext_label = new views::Label(
if (!description_text.empty()) { text, {views::style::GetFont(ChromeTextContext::CONTEXT_BODY_TEXT_LARGE,
views::Label* subtext_label = new views::Label( ChromeTextStyle::STYLE_SECONDARY)});
description_text, subtext_label->SetEnabledColor(
{views::style::GetFont(ChromeTextContext::CONTEXT_BODY_TEXT_LARGE, views::style::GetColor(*this, ChromeTextContext::CONTEXT_BODY_TEXT_LARGE,
ChromeTextStyle::STYLE_SECONDARY)}); ChromeTextStyle::STYLE_SECONDARY));
subtext_label->SetEnabledColor(views::style::GetColor(
*this, ChromeTextContext::CONTEXT_BODY_TEXT_LARGE, return subtext_label;
ChromeTextStyle::STYLE_SECONDARY));
return subtext_label;
}
return nullptr;
} }
void AutofillPopupItemView::AddIcon(gfx::ImageSkia icon) { void AutofillPopupItemView::AddIcon(gfx::ImageSkia icon) {
...@@ -496,14 +499,22 @@ PasswordPopupSuggestionView* PasswordPopupSuggestionView::Create( ...@@ -496,14 +499,22 @@ PasswordPopupSuggestionView* PasswordPopupSuggestionView::Create(
views::View* PasswordPopupSuggestionView::CreateValueLabel() { views::View* PasswordPopupSuggestionView::CreateValueLabel() {
views::View* label = AutofillPopupSuggestionView::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); return new ConstrainedWidthView(label, kAutofillPopupUsernameMaxWidth);
} }
views::View* PasswordPopupSuggestionView::CreateDescriptionLabel() { views::View* PasswordPopupSuggestionView::CreateDescriptionLabel() {
views::Label* label = CreateDescriptionLabelInternal(); base::string16 text =
if (!label) popup_view_->controller()->GetElidedLabelAt(line_number_);
if (text.empty())
return nullptr; return nullptr;
views::Label* label = CreateSecondaryLabel(text);
label->SetElideBehavior(gfx::TRUNCATE); label->SetElideBehavior(gfx::TRUNCATE);
return new ConstrainedWidthView(label, kAutofillPopupPasswordMaxWidth); return new ConstrainedWidthView(label, kAutofillPopupPasswordMaxWidth);
} }
......
...@@ -9,10 +9,7 @@ ...@@ -9,10 +9,7 @@
namespace autofill { namespace autofill {
Suggestion::Suggestion() Suggestion::Suggestion()
: frontend_id(0), : frontend_id(0), match(PREFIX_MATCH), is_value_secondary(false) {}
match(PREFIX_MATCH),
is_value_bold(false) {
}
Suggestion::Suggestion(const Suggestion& other) Suggestion::Suggestion(const Suggestion& other)
: backend_id(other.backend_id), : backend_id(other.backend_id),
...@@ -22,14 +19,13 @@ Suggestion::Suggestion(const Suggestion& other) ...@@ -22,14 +19,13 @@ Suggestion::Suggestion(const Suggestion& other)
custom_icon(other.custom_icon), custom_icon(other.custom_icon),
icon(other.icon), icon(other.icon),
match(other.match), match(other.match),
is_value_bold(other.is_value_bold) {} is_value_secondary(other.is_value_secondary) {}
Suggestion::Suggestion(const base::string16& v) Suggestion::Suggestion(const base::string16& v)
: frontend_id(0), : frontend_id(0),
value(v), value(v),
match(PREFIX_MATCH), match(PREFIX_MATCH),
is_value_bold(false) { is_value_secondary(false) {}
}
Suggestion::Suggestion(const std::string& v, Suggestion::Suggestion(const std::string& v,
const std::string& l, const std::string& l,
...@@ -40,8 +36,7 @@ Suggestion::Suggestion(const std::string& v, ...@@ -40,8 +36,7 @@ Suggestion::Suggestion(const std::string& v,
label(base::UTF8ToUTF16(l)), label(base::UTF8ToUTF16(l)),
icon(base::UTF8ToUTF16(i)), icon(base::UTF8ToUTF16(i)),
match(PREFIX_MATCH), match(PREFIX_MATCH),
is_value_bold(false) { is_value_secondary(false) {}
}
Suggestion::~Suggestion() = default; Suggestion::~Suggestion() = default;
......
...@@ -51,7 +51,7 @@ struct Suggestion { ...@@ -51,7 +51,7 @@ struct Suggestion {
// If |custom_icon| is empty, the name of the fallback built-in icon. // If |custom_icon| is empty, the name of the fallback built-in icon.
base::string16 icon; base::string16 icon;
MatchMode match; 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 } // namespace autofill
......
...@@ -50,8 +50,10 @@ constexpr base::char16 kPasswordReplacementChar = 0x2022; ...@@ -50,8 +50,10 @@ constexpr base::char16 kPasswordReplacementChar = 0x2022;
// Returns |username| unless it is empty. For an empty |username| returns a // Returns |username| unless it is empty. For an empty |username| returns a
// localised string saying this username is empty. Use this for displaying the // localised string saying this username is empty. Use this for displaying the
// usernames to the user. // usernames to the user. |replaced| is set to true iff |username| is empty.
base::string16 ReplaceEmptyUsername(const base::string16& username) { base::string16 ReplaceEmptyUsername(const base::string16& username,
bool* replaced) {
*replaced = username.empty();
if (username.empty()) if (username.empty())
return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_EMPTY_LOGIN); return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_EMPTY_LOGIN);
return username; return username;
...@@ -92,7 +94,10 @@ void AppendSuggestionIfMatching( ...@@ -92,7 +94,10 @@ void AppendSuggestionIfMatching(
base::string16 lower_contents = base::i18n::ToLower(field_contents); base::string16 lower_contents = base::i18n::ToLower(field_contents);
if (show_all || autofill::FieldIsSuggestionSubstringStartingOnTokenBoundary( if (show_all || autofill::FieldIsSuggestionSubstringStartingOnTokenBoundary(
lower_suggestion, lower_contents, true)) { 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 = suggestion.label =
signon_realm.empty() signon_realm.empty()
? base::string16(password_length, kPasswordReplacementChar) ? 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