Commit 62796f0b authored by Vasilii Sukhanov's avatar Vasilii Sukhanov Committed by Commit Bot

Limit sizes of the password and username label in the password dropdown.

The spec specifies max width for labels in the password dropdown.

Bug: 868020
Change-Id: I112c0866e7f0f0165b82f72bdc55c21a25c6c09f
Reviewed-on: https://chromium-review.googlesource.com/1151637
Commit-Queue: Vasilii Sukhanov <vasilii@chromium.org>
Reviewed-by: default avatarTommy Martino <tmartino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#578583}
parent b2d6acbd
...@@ -41,9 +41,13 @@ namespace { ...@@ -41,9 +41,13 @@ namespace {
// By spec, dropdowns should have a min width of 64, a max width of 456, and // By spec, dropdowns should have a min width of 64, a max width of 456, and
// should always have a width which is a multiple of 12. // should always have a width which is a multiple of 12.
const int kAutofillPopupWidthMultiple = 12; constexpr int kAutofillPopupWidthMultiple = 12;
const int kAutofillPopupMinWidth = 64; constexpr int kAutofillPopupMinWidth = 64;
const int kAutofillPopupMaxWidth = 456; constexpr int kAutofillPopupMaxWidth = 456;
// Max width for the username and masked password.
constexpr int kAutofillPopupUsernameMaxWidth = 272;
constexpr int kAutofillPopupPasswordMaxWidth = 108;
// A space between the input element and the dropdown, so that the dropdown's // A space between the input element and the dropdown, so that the dropdown's
// border doesn't look too close to the element. // border doesn't look too close to the element.
...@@ -65,6 +69,35 @@ namespace autofill { ...@@ -65,6 +69,35 @@ namespace autofill {
namespace { namespace {
// Container view that holds one child view and limits its width to the
// specified maximum.
class ConstrainedWidthView : public views::View {
public:
ConstrainedWidthView(views::View* child, int max_width);
~ConstrainedWidthView() override = default;
private:
// views::View:
gfx::Size CalculatePreferredSize() const override;
int max_width_;
DISALLOW_COPY_AND_ASSIGN(ConstrainedWidthView);
};
ConstrainedWidthView::ConstrainedWidthView(views::View* child, int max_width)
: max_width_(max_width) {
SetLayoutManager(std::make_unique<views::FillLayout>());
AddChildView(child);
}
gfx::Size ConstrainedWidthView::CalculatePreferredSize() const {
gfx::Size size = View::CalculatePreferredSize();
if (size.width() <= max_width_)
return size;
return gfx::Size(max_width_, GetHeightForWidth(max_width_));
}
// This represents a single selectable item. Subclasses distinguish between // This represents a single selectable item. Subclasses distinguish between
// footer and suggestion rows, which are structurally similar but have // footer and suggestion rows, which are structurally similar but have
// distinct styling. // distinct styling.
...@@ -91,6 +124,9 @@ class AutofillPopupItemView : public AutofillPopupRowView { ...@@ -91,6 +124,9 @@ class AutofillPopupItemView : public AutofillPopupRowView {
protected: protected:
virtual int GetPrimaryTextStyle() = 0; virtual int GetPrimaryTextStyle() = 0;
virtual views::View* CreateValueLabel();
// The description view can be nullptr.
virtual views::View* CreateDescriptionLabel();
private: private:
void AddSpacerWithSize(int spacer_width, void AddSpacerWithSize(int spacer_width,
...@@ -117,13 +153,33 @@ class AutofillPopupSuggestionView : public AutofillPopupItemView { ...@@ -117,13 +153,33 @@ class AutofillPopupSuggestionView : public AutofillPopupItemView {
std::unique_ptr<views::Background> CreateBackground() override; std::unique_ptr<views::Background> CreateBackground() override;
int GetPrimaryTextStyle() override; int GetPrimaryTextStyle() override;
private:
AutofillPopupSuggestionView(AutofillPopupViewNativeViews* popup_view, AutofillPopupSuggestionView(AutofillPopupViewNativeViews* popup_view,
int line_number); int line_number);
DISALLOW_COPY_AND_ASSIGN(AutofillPopupSuggestionView); DISALLOW_COPY_AND_ASSIGN(AutofillPopupSuggestionView);
}; };
// This represents a password suggestion row; i.e., a username and password.
class PasswordPopupSuggestionView : public AutofillPopupSuggestionView {
public:
~PasswordPopupSuggestionView() override = default;
static PasswordPopupSuggestionView* Create(
AutofillPopupViewNativeViews* popup_view,
int line_number);
protected:
// AutofillPopupItemView:
views::View* CreateValueLabel() override;
views::View* CreateDescriptionLabel() override;
private:
PasswordPopupSuggestionView(AutofillPopupViewNativeViews* popup_view,
int line_number);
DISALLOW_COPY_AND_ASSIGN(PasswordPopupSuggestionView);
};
// This represents an option which appears in the footer of the dropdown, such // This represents an option which appears in the footer of the dropdown, such
// as a row which will open the Autofill settings page when selected. // as a row which will open the Autofill settings page when selected.
class AutofillPopupFooterView : public AutofillPopupItemView { class AutofillPopupFooterView : public AutofillPopupItemView {
...@@ -205,6 +261,8 @@ class AutofillPopupWarningView : public AutofillPopupRowView { ...@@ -205,6 +261,8 @@ class AutofillPopupWarningView : public AutofillPopupRowView {
DISALLOW_COPY_AND_ASSIGN(AutofillPopupWarningView); DISALLOW_COPY_AND_ASSIGN(AutofillPopupWarningView);
}; };
/************** AutofillPopupItemView **************/
void AutofillPopupItemView::GetAccessibleNodeData(ui::AXNodeData* node_data) { void AutofillPopupItemView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
AutofillPopupController* controller = popup_view_->controller(); AutofillPopupController* controller = popup_view_->controller();
auto suggestion = controller->GetSuggestionAt(line_number_); auto suggestion = controller->GetSuggestionAt(line_number_);
...@@ -272,33 +330,14 @@ void AutofillPopupItemView::CreateContent() { ...@@ -272,33 +330,14 @@ void AutofillPopupItemView::CreateContent() {
layout->set_minimum_cross_axis_size( layout->set_minimum_cross_axis_size(
views::MenuConfig::instance().touchable_menu_height + extra_height_); views::MenuConfig::instance().touchable_menu_height + extra_height_);
// TODO(crbug.com/831603): Remove elision responsibilities from controller. AddChildView(CreateValueLabel());
views::Label* text_label = new views::Label(
controller->GetElidedValueAt(line_number_),
{views::style::GetFont(ChromeTextContext::CONTEXT_BODY_TEXT_LARGE,
GetPrimaryTextStyle())});
text_label->SetEnabledColor(
views::style::GetColor(*this, ChromeTextContext::CONTEXT_BODY_TEXT_LARGE,
GetPrimaryTextStyle()));
AddChildView(text_label);
AddSpacerWithSize(views::MenuConfig::instance().item_horizontal_padding, AddSpacerWithSize(views::MenuConfig::instance().item_horizontal_padding,
/*resize=*/true, layout); /*resize=*/true, layout);
const base::string16& description_text = views::View* description_label = CreateDescriptionLabel();
controller->GetElidedLabelAt(line_number_); if (description_label)
if (!description_text.empty()) { AddChildView(description_label);
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));
AddChildView(subtext_label);
}
const gfx::ImageSkia icon = const gfx::ImageSkia icon =
controller->layout_model().GetIconImage(line_number_); controller->layout_model().GetIconImage(line_number_);
...@@ -318,6 +357,35 @@ void AutofillPopupItemView::RefreshStyle() { ...@@ -318,6 +357,35 @@ void AutofillPopupItemView::RefreshStyle() {
SchedulePaint(); SchedulePaint();
} }
views::View* AutofillPopupItemView::CreateValueLabel() {
// TODO(crbug.com/831603): Remove elision responsibilities from controller.
views::Label* text_label = new views::Label(
popup_view_->controller()->GetElidedValueAt(line_number_),
{views::style::GetFont(ChromeTextContext::CONTEXT_BODY_TEXT_LARGE,
GetPrimaryTextStyle())});
text_label->SetEnabledColor(
views::style::GetColor(*this, ChromeTextContext::CONTEXT_BODY_TEXT_LARGE,
GetPrimaryTextStyle()));
return text_label;
}
views::View* AutofillPopupItemView::CreateDescriptionLabel() {
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;
}
void AutofillPopupItemView::AddSpacerWithSize(int spacer_width, void AutofillPopupItemView::AddSpacerWithSize(int spacer_width,
bool resize, bool resize,
views::BoxLayout* layout) { views::BoxLayout* layout) {
...@@ -327,6 +395,8 @@ void AutofillPopupItemView::AddSpacerWithSize(int spacer_width, ...@@ -327,6 +395,8 @@ void AutofillPopupItemView::AddSpacerWithSize(int spacer_width,
layout->SetFlexForView(spacer, /*flex=*/resize ? 1 : 0); layout->SetFlexForView(spacer, /*flex=*/resize ? 1 : 0);
} }
/************** AutofillPopupSuggestionView **************/
// static // static
AutofillPopupSuggestionView* AutofillPopupSuggestionView::Create( AutofillPopupSuggestionView* AutofillPopupSuggestionView::Create(
AutofillPopupViewNativeViews* popup_view, AutofillPopupViewNativeViews* popup_view,
...@@ -355,6 +425,35 @@ AutofillPopupSuggestionView::AutofillPopupSuggestionView( ...@@ -355,6 +425,35 @@ AutofillPopupSuggestionView::AutofillPopupSuggestionView(
SetFocusBehavior(FocusBehavior::ALWAYS); SetFocusBehavior(FocusBehavior::ALWAYS);
} }
/************** PasswordPopupSuggestionView **************/
PasswordPopupSuggestionView* PasswordPopupSuggestionView::Create(
AutofillPopupViewNativeViews* popup_view,
int line_number) {
PasswordPopupSuggestionView* result =
new PasswordPopupSuggestionView(popup_view, line_number);
result->Init();
return result;
}
views::View* PasswordPopupSuggestionView::CreateValueLabel() {
views::View* label = AutofillPopupSuggestionView::CreateValueLabel();
return new ConstrainedWidthView(label, kAutofillPopupUsernameMaxWidth);
}
views::View* PasswordPopupSuggestionView::CreateDescriptionLabel() {
views::View* label = AutofillPopupSuggestionView::CreateDescriptionLabel();
return label ? new ConstrainedWidthView(label, kAutofillPopupPasswordMaxWidth)
: nullptr;
}
PasswordPopupSuggestionView::PasswordPopupSuggestionView(
AutofillPopupViewNativeViews* popup_view,
int line_number)
: AutofillPopupSuggestionView(popup_view, line_number) {}
/************** AutofillPopupFooterView **************/
// static // static
AutofillPopupFooterView* AutofillPopupFooterView::Create( AutofillPopupFooterView* AutofillPopupFooterView::Create(
AutofillPopupViewNativeViews* popup_view, AutofillPopupViewNativeViews* popup_view,
...@@ -394,6 +493,8 @@ AutofillPopupFooterView::AutofillPopupFooterView( ...@@ -394,6 +493,8 @@ AutofillPopupFooterView::AutofillPopupFooterView(
SetFocusBehavior(FocusBehavior::ALWAYS); SetFocusBehavior(FocusBehavior::ALWAYS);
} }
/************** AutofillPopupSeparatorView **************/
// static // static
AutofillPopupSeparatorView* AutofillPopupSeparatorView::Create( AutofillPopupSeparatorView* AutofillPopupSeparatorView::Create(
AutofillPopupViewNativeViews* popup_view, AutofillPopupViewNativeViews* popup_view,
...@@ -444,6 +545,8 @@ AutofillPopupSeparatorView::AutofillPopupSeparatorView( ...@@ -444,6 +545,8 @@ AutofillPopupSeparatorView::AutofillPopupSeparatorView(
SetFocusBehavior(FocusBehavior::NEVER); SetFocusBehavior(FocusBehavior::NEVER);
} }
/************** AutofillPopupWarningView **************/
// static // static
AutofillPopupWarningView* AutofillPopupWarningView::Create( AutofillPopupWarningView* AutofillPopupWarningView::Create(
AutofillPopupViewNativeViews* popup_view, AutofillPopupViewNativeViews* popup_view,
...@@ -499,6 +602,8 @@ AutofillPopupWarningView::CreateBackground() { ...@@ -499,6 +602,8 @@ AutofillPopupWarningView::CreateBackground() {
} // namespace } // namespace
/************** AutofillPopupRowView **************/
void AutofillPopupRowView::SetSelected(bool is_selected) { void AutofillPopupRowView::SetSelected(bool is_selected) {
if (is_selected == is_selected_) if (is_selected == is_selected_)
return; return;
...@@ -628,6 +733,11 @@ void AutofillPopupViewNativeViews::CreateChildViews() { ...@@ -628,6 +733,11 @@ void AutofillPopupViewNativeViews::CreateChildViews() {
rows_.push_back(AutofillPopupWarningView::Create(this, line_number)); rows_.push_back(AutofillPopupWarningView::Create(this, line_number));
break; break;
case autofill::PopupItemId::POPUP_ITEM_ID_USERNAME_ENTRY:
case autofill::PopupItemId::POPUP_ITEM_ID_PASSWORD_ENTRY:
rows_.push_back(PasswordPopupSuggestionView::Create(this, line_number));
break;
default: default:
rows_.push_back(AutofillPopupSuggestionView::Create(this, line_number)); rows_.push_back(AutofillPopupSuggestionView::Create(this, line_number));
} }
......
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