Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4601)

Unified Diff: chrome/browser/ui/views/payments/editor_view_controller.cc

Issue 2881643002: Focus first invalid field of payment request editor (Closed)
Patch Set: Rebase Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 5252645cf78a668e946e8be883c40930c3c589e7..01655de7900e50f8a8f63b62f411599850f917c3 100644
--- a/chrome/browser/ui/views/payments/editor_view_controller.cc
+++ b/chrome/browser/ui/views/payments/editor_view_controller.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/ui/views/payments/editor_view_controller.h"
+#include <algorithm>
#include <map>
#include <memory>
#include <utility>
@@ -102,7 +103,8 @@ std::unique_ptr<views::View> EditorViewController::CreateHeaderView() {
}
std::unique_ptr<views::View> EditorViewController::CreateCustomFieldView(
- autofill::ServerFieldType type) {
+ autofill::ServerFieldType type,
+ views::View** focusable_field) {
return nullptr;
}
@@ -144,8 +146,6 @@ base::string16 EditorViewController::GetSecondaryButtonLabel() {
void EditorViewController::UpdateEditorView() {
UpdateContentView();
- // TODO(crbug.com/704254): Find how to update the parent view bounds so that
- // the vertical scrollbar size gets updated.
dialog()->EditorViewUpdated();
}
@@ -189,6 +189,7 @@ std::unique_ptr<views::View> EditorViewController::CreateEditorView() {
std::unique_ptr<views::View> editor_view = base::MakeUnique<views::View>();
text_fields_.clear();
comboboxes_.clear();
+ first_field_view_ = nullptr;
// The editor view is padded horizontally.
editor_view->SetBorder(views::CreateEmptyBorder(
@@ -280,6 +281,17 @@ std::unique_ptr<views::View> EditorViewController::CreateEditorView() {
editor_layout->AddView(required_field.release());
editor_view->SetLayoutManager(editor_layout.release());
+ views::View* potential_first_field_view = nullptr;
anthonyvd 2017/05/12 14:19:44 I'm confused: we seem to be creating the fields bo
MAD 2017/05/18 16:01:44 Oups, yes, merge fluke... Sorry about that... :-(
+ for (const auto& field : GetFieldDefinitions()) {
+ views::View* focusable_field = CreateInputField(
+ static_cast<views::GridLayout*>(editor_view->GetLayoutManager()),
+ field);
+ if (!potential_first_field_view)
+ potential_first_field_view = focusable_field;
+ }
+
+ if (!first_field_view_)
+ first_field_view_ = potential_first_field_view;
return editor_view;
}
@@ -290,8 +302,8 @@ std::unique_ptr<views::View> EditorViewController::CreateEditorView() {
// |_______________________|__________________________________|
// | (empty) | Error label |
// +----------------------------------------------------------+
-void EditorViewController::CreateInputField(views::GridLayout* layout,
- const EditorField& field) {
+views::View* EditorViewController::CreateInputField(views::GridLayout* layout,
+ const EditorField& field) {
int column_set =
field.length_hint == EditorField::LengthHint::HINT_SHORT ? 0 : 1;
@@ -305,6 +317,8 @@ void EditorViewController::CreateInputField(views::GridLayout* layout,
label->SetMultiLine(true);
layout->AddView(label.release());
+ views::View* focusable_field = nullptr;
+
constexpr int kInputFieldHeight = 28;
if (field.control_type == EditorField::ControlType::TEXTFIELD) {
ValidatingTextfield* text_field =
@@ -314,11 +328,13 @@ void EditorViewController::CreateInputField(views::GridLayout* layout,
// Using autofill field type as a view ID (for testing).
text_field->set_id(static_cast<int>(field.type));
text_fields_.insert(std::make_pair(text_field, field));
-
- // TODO(crbug.com/718582): Make the initial focus the first incomplete/empty
- // field.
- if (!first_field_view_)
- first_field_view_ = text_field;
+ focusable_field = text_field;
+ if (!first_field_view_) {
+ text_field->Validate(/*display_error=*/false);
+ if (text_field->invalid()) {
+ first_field_view_ = text_field;
+ }
+ }
// |text_field| will now be owned by |row|.
layout->AddView(text_field, 1, 1, views::GridLayout::FILL,
@@ -333,9 +349,13 @@ void EditorViewController::CreateInputField(views::GridLayout* layout,
combobox->set_id(static_cast<int>(field.type));
combobox->set_listener(this);
comboboxes_.insert(std::make_pair(combobox, field));
-
- if (!first_field_view_)
- first_field_view_ = combobox;
+ focusable_field = combobox;
+ if (!first_field_view_) {
+ combobox->Validate(/*display_error=*/false);
+ if (combobox->invalid()) {
+ first_field_view_ = combobox;
+ }
+ }
// |combobox| will now be owned by |row|.
layout->AddView(combobox, 1, 1, views::GridLayout::FILL,
@@ -343,7 +363,8 @@ 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.
- std::unique_ptr<views::View> field_view = CreateCustomFieldView(field.type);
+ std::unique_ptr<views::View> field_view =
+ CreateCustomFieldView(field.type, &focusable_field);
DCHECK(field_view);
layout->AddView(field_view.release());
}
@@ -364,6 +385,7 @@ void EditorViewController::CreateInputField(views::GridLayout* layout,
// Bottom padding for the row.
layout->AddPaddingRow(0, kInputRowSpacing);
+ return focusable_field;
}
int EditorViewController::ComputeWidestExtraViewWidth(

Powered by Google App Engine
This is Rietveld 408576698