Index: chrome/browser/ui/views/payments/editor_view_controller.cc |
diff --git a/chrome/browser/ui/views/payments/editor_view_controller.cc b/chrome/browser/ui/views/payments/editor_view_controller.cc |
index a6e926ebae2399c4a477f373a0abcaa98d0b1d44..44ac42a67589145a6fecc7b587880fd6f0c87a24 100644 |
--- a/chrome/browser/ui/views/payments/editor_view_controller.cc |
+++ b/chrome/browser/ui/views/payments/editor_view_controller.cc |
@@ -106,6 +106,11 @@ std::unique_ptr<views::View> EditorViewController::CreateCustomFieldView( |
return nullptr; |
} |
+std::unique_ptr<views::View> EditorViewController::CreateExtraViewForField( |
+ autofill::ServerFieldType type) { |
+ return nullptr; |
+} |
+ |
std::unique_ptr<views::Button> EditorViewController::CreatePrimaryButton() { |
std::unique_ptr<views::Button> button( |
views::MdTextButton::CreateSecondaryUiBlueButton( |
@@ -205,28 +210,79 @@ std::unique_ptr<views::View> EditorViewController::CreateEditorView() { |
text_fields_.clear(); |
comboboxes_.clear(); |
- std::unique_ptr<views::GridLayout> editor_layout = |
- base::MakeUnique<views::GridLayout>(editor_view.get()); |
- |
// The editor view is padded horizontally. |
editor_view->SetBorder(views::CreateEmptyBorder( |
0, payments::kPaymentRequestRowHorizontalInsets, 0, |
payments::kPaymentRequestRowHorizontalInsets)); |
- views::ColumnSet* columns = editor_layout->AddColumnSet(0); |
- columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0, |
- views::GridLayout::USE_PREF, 0, 0); |
- |
- // This is the horizontal padding between the label and the input field. |
+ // All views have fixed size except the Field which stretches. The fixed |
+ // padding at the end is computed so that Field views have a minimum of |
+ // 176/272dp (short/long fields) as per spec. |
+ // ___________________________________________________________________________ |
+ // |Label | 16dp pad | Field (flex) | 8dp pad | Extra View | Computed Padding| |
+ // |______|__________|______________|_________|____________|_________________| |
+ constexpr int kLabelWidth = 140; |
+ // This is the horizontal padding between the label and the field. |
constexpr int kLabelInputFieldHorizontalPadding = 16; |
- columns->AddPaddingColumn(0, kLabelInputFieldHorizontalPadding); |
+ // This is the horizontal padding between the field and the extra view. |
+ constexpr int kFieldExtraViewHorizontalPadding = 8; |
+ constexpr int kShortFieldMinimumWidth = 176; |
+ constexpr int kLongFieldMinimumWidth = 272; |
- columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0, |
- views::GridLayout::USE_PREF, 0, 0); |
+ std::unique_ptr<views::GridLayout> editor_layout = |
+ base::MakeUnique<views::GridLayout>(editor_view.get()); |
+ // Column set for short fields. |
+ views::ColumnSet* columns_short = editor_layout->AddColumnSet(0); |
+ columns_short->AddColumn(views::GridLayout::LEADING, |
+ views::GridLayout::CENTER, 0, |
+ views::GridLayout::FIXED, kLabelWidth, 0); |
+ columns_short->AddPaddingColumn(0, kLabelInputFieldHorizontalPadding); |
+ // The field view column stretches. |
+ columns_short->AddColumn(views::GridLayout::LEADING, |
+ views::GridLayout::CENTER, 1, |
+ views::GridLayout::USE_PREF, 0, 0); |
+ columns_short->AddPaddingColumn(0, kFieldExtraViewHorizontalPadding); |
+ // The extra field view column is fixed size, computed from the largest |
+ // extra view. |
+ int short_extra_view_width = |
+ ComputeWidestExtraViewWidth(EditorField::LengthHint::HINT_SHORT); |
+ columns_short->AddColumn(views::GridLayout::LEADING, |
+ views::GridLayout::CENTER, 0, |
+ views::GridLayout::FIXED, short_extra_view_width, 0); |
+ // The padding at the end is fixed, computed to make sure the short field |
+ // maintains its minimum width. |
+ int short_padding = kDialogMinWidth - kShortFieldMinimumWidth - kLabelWidth - |
+ (2 * kPaymentRequestRowHorizontalInsets) - |
+ kLabelInputFieldHorizontalPadding - |
+ kFieldExtraViewHorizontalPadding - short_extra_view_width; |
+ columns_short->AddPaddingColumn(0, short_padding); |
+ |
+ // Column set for long fields. |
+ views::ColumnSet* columns_long = editor_layout->AddColumnSet(1); |
+ columns_long->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, |
+ 0, views::GridLayout::FIXED, kLabelWidth, 0); |
+ columns_long->AddPaddingColumn(0, kLabelInputFieldHorizontalPadding); |
+ // The field view column stretches. |
+ columns_long->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, |
+ 1, views::GridLayout::USE_PREF, 0, 0); |
+ columns_long->AddPaddingColumn(0, kFieldExtraViewHorizontalPadding); |
+ // The extra field view column is fixed size, computed from the largest |
+ // extra view. |
+ int long_extra_view_width = |
+ ComputeWidestExtraViewWidth(EditorField::LengthHint::HINT_LONG); |
+ columns_long->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, |
+ 0, views::GridLayout::FIXED, long_extra_view_width, |
+ 0); |
+ // The padding at the end is fixed, computed to make sure the long field |
+ // maintains its minimum width. |
+ int long_padding = kDialogMinWidth - kLongFieldMinimumWidth - kLabelWidth - |
+ (2 * kPaymentRequestRowHorizontalInsets) - |
+ kLabelInputFieldHorizontalPadding - |
+ kFieldExtraViewHorizontalPadding - long_extra_view_width; |
+ columns_long->AddPaddingColumn(0, long_padding); |
editor_view->SetLayoutManager(editor_layout.release()); |
- std::vector<EditorField> fields = GetFieldDefinitions(); |
- for (const auto& field : fields) { |
+ for (const auto& field : GetFieldDefinitions()) { |
CreateInputField( |
static_cast<views::GridLayout*>(editor_view->GetLayoutManager()), |
field); |
@@ -243,15 +299,17 @@ std::unique_ptr<views::View> EditorViewController::CreateEditorView() { |
// +----------------------------------------------------------+ |
void EditorViewController::CreateInputField(views::GridLayout* layout, |
const EditorField& field) { |
+ int column_set = |
+ field.length_hint == EditorField::LengthHint::HINT_SHORT ? 0 : 1; |
+ |
// This is the top padding for every row. |
constexpr int kInputRowSpacing = 6; |
- layout->StartRowWithPadding(0, 0, 0, kInputRowSpacing); |
+ layout->StartRowWithPadding(0, column_set, 0, kInputRowSpacing); |
std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>( |
field.required ? field.label + base::ASCIIToUTF16("*") : field.label); |
label->SetMultiLine(true); |
- label->SetMaximumWidth(kMaximumLabelWidth); |
layout->AddView(label.release()); |
constexpr int kInputFieldHeight = 28; |
@@ -275,8 +333,10 @@ void EditorViewController::CreateInputField(views::GridLayout* layout, |
} else if (field.control_type == EditorField::ControlType::COMBOBOX) { |
ValidatingCombobox* combobox = new ValidatingCombobox( |
GetComboboxModelForType(field.type), CreateValidationDelegate(field)); |
- combobox->SelectValue(GetInitialValueForType(field.type)); |
- // Using autofill field type as a view ID (for testing). |
+ base::string16 initial_value = GetInitialValueForType(field.type); |
+ if (!initial_value.empty()) |
+ combobox->SelectValue(initial_value); |
+ // Using autofill field type as a view ID. |
combobox->set_id(static_cast<int>(field.type)); |
combobox->set_listener(this); |
comboboxes_.insert(std::make_pair(combobox, field)); |
@@ -290,10 +350,18 @@ void EditorViewController::CreateInputField(views::GridLayout* layout, |
} else { |
// Custom field view will now be owned by |row|. And it must be valid since |
// the derived class specified a custom view for this field. |
- layout->AddView(CreateCustomFieldView(field.type).release()); |
+ std::unique_ptr<views::View> field_view = CreateCustomFieldView(field.type); |
+ DCHECK(field_view); |
+ layout->AddView(field_view.release()); |
} |
- layout->StartRow(0, 0); |
+ // If an extra view needs to go alongside the input field view, add it to the |
+ // last column. |
+ std::unique_ptr<views::View> extra_view = CreateExtraViewForField(field.type); |
+ if (extra_view) |
+ layout->AddView(extra_view.release()); |
+ |
+ layout->StartRow(0, column_set); |
layout->SkipColumns(1); |
std::unique_ptr<views::View> error_label_view = |
base::MakeUnique<views::View>(); |
@@ -305,4 +373,22 @@ void EditorViewController::CreateInputField(views::GridLayout* layout, |
layout->AddPaddingRow(0, kInputRowSpacing); |
} |
+int EditorViewController::ComputeWidestExtraViewWidth( |
+ EditorField::LengthHint size) { |
+ int widest_column_width = 0; |
+ |
+ for (const auto& field : GetFieldDefinitions()) { |
+ if (field.length_hint != size) |
+ continue; |
+ |
+ std::unique_ptr<views::View> extra_view = |
+ CreateExtraViewForField(field.type); |
+ if (!extra_view) |
+ continue; |
+ widest_column_width = |
+ std::max(extra_view->GetPreferredSize().width(), widest_column_width); |
+ } |
+ return widest_column_width; |
+} |
+ |
} // namespace payments |