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

Side by Side Diff: chrome/browser/ui/views/payments/editor_view_controller.cc

Issue 2896263002: [Payments] Changes to validation in the Credit Card 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/payments/editor_view_controller.h" 5 #include "chrome/browser/ui/views/payments/editor_view_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 back_navigation_type_(back_navigation_type) {} 84 back_navigation_type_(back_navigation_type) {}
85 85
86 EditorViewController::~EditorViewController() {} 86 EditorViewController::~EditorViewController() {}
87 87
88 void EditorViewController::DisplayErrorMessageForField( 88 void EditorViewController::DisplayErrorMessageForField(
89 autofill::ServerFieldType type, 89 autofill::ServerFieldType type,
90 const base::string16& error_message) { 90 const base::string16& error_message) {
91 const auto& label_view_it = error_labels_.find(type); 91 const auto& label_view_it = error_labels_.find(type);
92 DCHECK(label_view_it != error_labels_.end()); 92 DCHECK(label_view_it != error_labels_.end());
93 93
94 label_view_it->second->RemoveAllChildViews(/*delete_children=*/true); 94 if (error_message.empty()) {
95 if (!error_message.empty()) { 95 label_view_it->second->RemoveAllChildViews(/*delete_children=*/true);
96 label_view_it->second->AddChildView( 96 } else {
97 CreateErrorLabelView(error_message, type).release()); 97 if (!label_view_it->second->has_children()) {
98 // If there was no error label view, add it.
99 label_view_it->second->AddChildView(
100 CreateErrorLabelView(error_message, type).release());
101 } else {
102 // The error view is the only child, and has a Label as only child itself.
103 static_cast<views::Label*>(
104 label_view_it->second->child_at(0)->child_at(0))
105 ->SetText(error_message);
106 }
98 } 107 }
99 RelayoutPane(); 108 RelayoutPane();
100 } 109 }
101 110
102 // static 111 // static
103 int EditorViewController::GetInputFieldViewId(autofill::ServerFieldType type) { 112 int EditorViewController::GetInputFieldViewId(autofill::ServerFieldType type) {
104 return static_cast<int>(DialogViewID::INPUT_FIELD_TYPE_OFFSET) + 113 return static_cast<int>(DialogViewID::INPUT_FIELD_TYPE_OFFSET) +
105 static_cast<int>(type); 114 static_cast<int>(type);
106 } 115 }
107 116
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 return initial_focus_field_view_; 189 return initial_focus_field_view_;
181 return PaymentRequestSheetController::GetFirstFocusedView(); 190 return PaymentRequestSheetController::GetFirstFocusedView();
182 } 191 }
183 192
184 std::unique_ptr<ValidatingCombobox> 193 std::unique_ptr<ValidatingCombobox>
185 EditorViewController::CreateComboboxForField(const EditorField& field) { 194 EditorViewController::CreateComboboxForField(const EditorField& field) {
186 std::unique_ptr<ValidatingCombobox> combobox = 195 std::unique_ptr<ValidatingCombobox> combobox =
187 base::MakeUnique<ValidatingCombobox>(GetComboboxModelForType(field.type), 196 base::MakeUnique<ValidatingCombobox>(GetComboboxModelForType(field.type),
188 CreateValidationDelegate(field)); 197 CreateValidationDelegate(field));
189 base::string16 initial_value = GetInitialValueForType(field.type); 198 base::string16 initial_value = GetInitialValueForType(field.type);
190 if (!initial_value.empty()) 199 if (!initial_value.empty()) {
191 combobox->SelectValue(initial_value); 200 combobox->SelectValue(initial_value);
201 combobox->SetInvalid(!combobox->IsValid());
202 }
192 // Using autofill field type as a view ID. 203 // Using autofill field type as a view ID.
193 combobox->set_id(GetInputFieldViewId(field.type)); 204 combobox->set_id(GetInputFieldViewId(field.type));
194 combobox->set_listener(this); 205 combobox->set_listener(this);
195 comboboxes_.insert(std::make_pair(combobox.get(), field)); 206 comboboxes_.insert(std::make_pair(combobox.get(), field));
196 return combobox; 207 return combobox;
197 } 208 }
198 209
199 void EditorViewController::ContentsChanged(views::Textfield* sender, 210 void EditorViewController::ContentsChanged(views::Textfield* sender,
200 const base::string16& new_contents) { 211 const base::string16& new_contents) {
201 static_cast<ValidatingTextfield*>(sender)->OnContentsChanged(); 212 static_cast<ValidatingTextfield*>(sender)->OnContentsChanged();
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 348
338 label->SetMultiLine(true); 349 label->SetMultiLine(true);
339 layout->AddView(label.release()); 350 layout->AddView(label.release());
340 351
341 views::View* focusable_field = nullptr; 352 views::View* focusable_field = nullptr;
342 constexpr int kInputFieldHeight = 28; 353 constexpr int kInputFieldHeight = 28;
343 if (field.control_type == EditorField::ControlType::TEXTFIELD || 354 if (field.control_type == EditorField::ControlType::TEXTFIELD ||
344 field.control_type == EditorField::ControlType::TEXTFIELD_NUMBER) { 355 field.control_type == EditorField::ControlType::TEXTFIELD_NUMBER) {
345 ValidatingTextfield* text_field = 356 ValidatingTextfield* text_field =
346 new ValidatingTextfield(CreateValidationDelegate(field)); 357 new ValidatingTextfield(CreateValidationDelegate(field));
347 text_field->SetText(GetInitialValueForType(field.type)); 358 // Set the initial value and validity state.
359 base::string16 initial_value = GetInitialValueForType(field.type);
360 text_field->SetText(initial_value);
361 *valid = text_field->IsValid();
362 if (!initial_value.empty())
363 text_field->SetInvalid(!(*valid));
364
348 if (field.control_type == EditorField::ControlType::TEXTFIELD_NUMBER) 365 if (field.control_type == EditorField::ControlType::TEXTFIELD_NUMBER)
349 text_field->SetTextInputType(ui::TextInputType::TEXT_INPUT_TYPE_NUMBER); 366 text_field->SetTextInputType(ui::TextInputType::TEXT_INPUT_TYPE_NUMBER);
350 text_field->set_controller(this); 367 text_field->set_controller(this);
351 // Using autofill field type as a view ID (for testing). 368 // Using autofill field type as a view ID (for testing).
352 text_field->set_id(GetInputFieldViewId(field.type)); 369 text_field->set_id(GetInputFieldViewId(field.type));
353 text_fields_.insert(std::make_pair(text_field, field)); 370 text_fields_.insert(std::make_pair(text_field, field));
354 focusable_field = text_field; 371 focusable_field = text_field;
355 *valid = text_field->IsValid();
356 372
357 // |text_field| will now be owned by |row|. 373 // |text_field| will now be owned by |row|.
358 layout->AddView(text_field, 1, 1, views::GridLayout::FILL, 374 layout->AddView(text_field, 1, 1, views::GridLayout::FILL,
359 views::GridLayout::FILL, 0, kInputFieldHeight); 375 views::GridLayout::FILL, 0, kInputFieldHeight);
360 } else if (field.control_type == EditorField::ControlType::COMBOBOX) { 376 } else if (field.control_type == EditorField::ControlType::COMBOBOX) {
361 std::unique_ptr<ValidatingCombobox> combobox = 377 std::unique_ptr<ValidatingCombobox> combobox =
362 CreateComboboxForField(field); 378 CreateComboboxForField(field);
363 379
364 focusable_field = combobox.get(); 380 focusable_field = combobox.get();
365 *valid = combobox->IsValid(); 381 *valid = combobox->IsValid();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 CreateExtraViewForField(field.type); 425 CreateExtraViewForField(field.type);
410 if (!extra_view) 426 if (!extra_view)
411 continue; 427 continue;
412 widest_column_width = 428 widest_column_width =
413 std::max(extra_view->GetPreferredSize().width(), widest_column_width); 429 std::max(extra_view->GetPreferredSize().width(), widest_column_width);
414 } 430 }
415 return widest_column_width; 431 return widest_column_width;
416 } 432 }
417 433
418 } // namespace payments 434 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698