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

Side by Side Diff: chrome/browser/ui/views/autofill/autofill_dialog_views.cc

Issue 14425010: Handle expired Autofill credit cards in autofill dialog (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/autofill/autofill_dialog_views.h" 5 #include "chrome/browser/ui/views/autofill/autofill_dialog_views.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 ContentsPreferredSizeChanged(); 834 ContentsPreferredSizeChanged();
835 } 835 }
836 836
837 void AutofillDialogViews::UpdateProgressBar(double value) { 837 void AutofillDialogViews::UpdateProgressBar(double value) {
838 autocheckout_progress_bar_->SetValue(value); 838 autocheckout_progress_bar_->SetValue(value);
839 } 839 }
840 840
841 void AutofillDialogViews::ModelChanged() { 841 void AutofillDialogViews::ModelChanged() {
842 menu_runner_.reset(); 842 menu_runner_.reset();
843 843
844 for (DetailGroupMap::iterator iter = detail_groups_.begin(); 844 for (DetailGroupMap::const_iterator iter = detail_groups_.begin();
845 iter != detail_groups_.end(); ++iter) { 845 iter != detail_groups_.end(); ++iter) {
846 UpdateDetailsGroupState(iter->second); 846 UpdateDetailsGroupState(iter->second);
847 } 847 }
848 } 848 }
849 849
850 TestableAutofillDialogView* AutofillDialogViews::GetTestableView() { 850 TestableAutofillDialogView* AutofillDialogViews::GetTestableView() {
851 return this; 851 return this;
852 } 852 }
853 853
854 void AutofillDialogViews::SubmitForTesting() { 854 void AutofillDialogViews::SubmitForTesting() {
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 1063
1064 void AutofillDialogViews::OnDidChangeFocus( 1064 void AutofillDialogViews::OnDidChangeFocus(
1065 views::View* focused_before, 1065 views::View* focused_before,
1066 views::View* focused_now) { 1066 views::View* focused_now) {
1067 if (!focused_before) 1067 if (!focused_before)
1068 return; 1068 return;
1069 1069
1070 // If user leaves an edit-field, revalidate the group it belongs to. 1070 // If user leaves an edit-field, revalidate the group it belongs to.
1071 DetailsGroup* group = GroupForView(focused_before); 1071 DetailsGroup* group = GroupForView(focused_before);
1072 if (group && group->container->visible()) 1072 if (group && group->container->visible())
1073 ValidateGroup(group, AutofillDialogController::VALIDATE_EDIT); 1073 ValidateGroup(*group, AutofillDialogController::VALIDATE_EDIT);
1074 } 1074 }
1075 1075
1076 void AutofillDialogViews::LinkClicked(views::Link* source, int event_flags) { 1076 void AutofillDialogViews::LinkClicked(views::Link* source, int event_flags) {
1077 // Edit links. 1077 // Edit links.
1078 for (DetailGroupMap::iterator iter = detail_groups_.begin(); 1078 for (DetailGroupMap::iterator iter = detail_groups_.begin();
1079 iter != detail_groups_.end(); ++iter) { 1079 iter != detail_groups_.end(); ++iter) {
1080 if (iter->second.suggested_info->Contains(source)) { 1080 if (iter->second.suggested_info->Contains(source)) {
1081 controller_->EditClickedForSection(iter->first); 1081 controller_->EditClickedForSection(iter->first);
1082 return; 1082 return;
1083 } 1083 }
1084 } 1084 }
1085 } 1085 }
1086 1086
1087 void AutofillDialogViews::OnSelectedIndexChanged(views::Combobox* combobox) { 1087 void AutofillDialogViews::OnSelectedIndexChanged(views::Combobox* combobox) {
1088 DetailsGroup* group = GroupForView(combobox); 1088 DetailsGroup* group = GroupForView(combobox);
1089 DCHECK(group); 1089 ValidateGroup(*group, AutofillDialogController::VALIDATE_EDIT);
1090 ValidateGroup(group, AutofillDialogController::VALIDATE_EDIT);
1091 } 1090 }
1092 1091
1093 void AutofillDialogViews::StyledLabelLinkClicked(const ui::Range& range, 1092 void AutofillDialogViews::StyledLabelLinkClicked(const ui::Range& range,
1094 int event_flags) { 1093 int event_flags) {
1095 controller_->LegalDocumentLinkClicked(range); 1094 controller_->LegalDocumentLinkClicked(range);
1096 } 1095 }
1097 1096
1098 void AutofillDialogViews::InitChildViews() { 1097 void AutofillDialogViews::InitChildViews() {
1099 button_strip_extra_view_ = new views::View(); 1098 button_strip_extra_view_ = new views::View();
1100 button_strip_extra_view_->SetLayoutManager( 1099 button_strip_extra_view_->SetLayoutManager(
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
1341 for (int i = 0; i < combobox->model()->GetItemCount(); ++i) { 1340 for (int i = 0; i < combobox->model()->GetItemCount(); ++i) {
1342 if (input.initial_value == combobox->model()->GetItemAt(i)) { 1341 if (input.initial_value == combobox->model()->GetItemAt(i)) {
1343 combobox->SetSelectedIndex(i); 1342 combobox->SetSelectedIndex(i);
1344 break; 1343 break;
1345 } 1344 }
1346 } 1345 }
1347 } 1346 }
1348 } 1347 }
1349 1348
1350 UpdateDetailsGroupState(*group); 1349 UpdateDetailsGroupState(*group);
1351 if (group->container && group->container->visible())
1352 ValidateGroup(group, AutofillDialogController::VALIDATE_EDIT);
1353 } 1350 }
1354 1351
1355 void AutofillDialogViews::UpdateDetailsGroupState(const DetailsGroup& group) { 1352 void AutofillDialogViews::UpdateDetailsGroupState(const DetailsGroup& group) {
1356 const SuggestionState& suggestion_state = 1353 const SuggestionState& suggestion_state =
1357 controller_->SuggestionStateForSection(group.section); 1354 controller_->SuggestionStateForSection(group.section);
1358 bool show_suggestions = !suggestion_state.text.empty(); 1355 bool show_suggestions = !suggestion_state.text.empty();
1359 group.suggested_info->SetVisible(show_suggestions); 1356 group.suggested_info->SetVisible(show_suggestions);
1360 group.suggested_info->SetSuggestionText(suggestion_state.text, 1357 group.suggested_info->SetSuggestionText(suggestion_state.text,
1361 suggestion_state.text_style); 1358 suggestion_state.text_style);
1362 group.suggested_info->SetSuggestionIcon(suggestion_state.icon); 1359 group.suggested_info->SetSuggestionIcon(suggestion_state.icon);
(...skipping 14 matching lines...) Expand all
1377 1374
1378 const bool has_suggestions = 1375 const bool has_suggestions =
1379 controller_->MenuModelForSection(group.section)->GetItemCount() > 0; 1376 controller_->MenuModelForSection(group.section)->GetItemCount() > 0;
1380 1377
1381 if (group.suggested_button) 1378 if (group.suggested_button)
1382 group.suggested_button->SetVisible(has_suggestions); 1379 group.suggested_button->SetVisible(has_suggestions);
1383 1380
1384 if (group.container) { 1381 if (group.container) {
1385 group.container->SetForwardMouseEvents(has_suggestions && show_suggestions); 1382 group.container->SetForwardMouseEvents(has_suggestions && show_suggestions);
1386 group.container->SetVisible(controller_->SectionIsActive(group.section)); 1383 group.container->SetVisible(controller_->SectionIsActive(group.section));
1384 if (group.container->visible())
1385 ValidateGroup(group, AutofillDialogController::VALIDATE_EDIT);
1387 } 1386 }
1388 1387
1389 ContentsPreferredSizeChanged(); 1388 ContentsPreferredSizeChanged();
1390 } 1389 }
1391 1390
1392 bool AutofillDialogViews::ValidateGroup( 1391 bool AutofillDialogViews::ValidateGroup(
1393 DetailsGroup* group, 1392 const DetailsGroup& group,
1394 AutofillDialogController::ValidationType validation_type) { 1393 AutofillDialogController::ValidationType validation_type) {
1395 DCHECK(group->container->visible()); 1394 DCHECK(group.container->visible());
1396 1395
1397 scoped_ptr<DetailInput> cvc_input; 1396 scoped_ptr<DetailInput> cvc_input;
1398 DetailOutputMap detail_outputs; 1397 DetailOutputMap detail_outputs;
1399 std::map<AutofillFieldType, base::Callback<void(bool)> > field_map; 1398 std::map<AutofillFieldType, base::Callback<void(bool)> > field_map;
1400 1399
1401 if (group->manual_input->visible()) { 1400 if (group.manual_input->visible()) {
1402 for (TextfieldMap::iterator iter = group->textfields.begin(); 1401 for (TextfieldMap::const_iterator iter = group.textfields.begin();
1403 iter != group->textfields.end(); ++iter) { 1402 iter != group.textfields.end(); ++iter) {
1404 detail_outputs[iter->first] = iter->second->textfield()->text(); 1403 detail_outputs[iter->first] = iter->second->textfield()->text();
1405 field_map[iter->first->type] = 1404 field_map[iter->first->type] =
1406 base::Bind(&DecoratedTextfield::SetInvalid, 1405 base::Bind(&DecoratedTextfield::SetInvalid,
1407 base::Unretained(iter->second)); 1406 base::Unretained(iter->second));
1408 } 1407 }
1409 for (ComboboxMap::iterator iter = group->comboboxes.begin(); 1408 for (ComboboxMap::const_iterator iter = group.comboboxes.begin();
1410 iter != group->comboboxes.end(); ++iter) { 1409 iter != group.comboboxes.end(); ++iter) {
1411 views::Combobox* combobox = iter->second; 1410 views::Combobox* combobox = iter->second;
1412 string16 item = 1411 string16 item =
1413 combobox->model()->GetItemAt(combobox->selected_index()); 1412 combobox->model()->GetItemAt(combobox->selected_index());
1414 detail_outputs[iter->first] = item; 1413 detail_outputs[iter->first] = item;
1415 field_map[iter->first->type] = 1414 field_map[iter->first->type] =
1416 base::Bind(&views::Combobox::SetInvalid, 1415 base::Bind(&views::Combobox::SetInvalid,
1417 base::Unretained(iter->second)); 1416 base::Unretained(iter->second));
1418 } 1417 }
1419 } else if (group->section == SECTION_CC) { 1418 } else if (group.section == SECTION_CC) {
1420 DecoratedTextfield* decorated_cvc = 1419 DecoratedTextfield* decorated_cvc =
1421 group->suggested_info->decorated_textfield(); 1420 group.suggested_info->decorated_textfield();
1422 cvc_input.reset(new DetailInput); 1421 cvc_input.reset(new DetailInput);
1423 cvc_input->type = CREDIT_CARD_VERIFICATION_CODE; 1422 cvc_input->type = CREDIT_CARD_VERIFICATION_CODE;
1424 detail_outputs[cvc_input.get()] = decorated_cvc->textfield()->text(); 1423 detail_outputs[cvc_input.get()] = decorated_cvc->textfield()->text();
1425 field_map[cvc_input->type] = 1424 field_map[cvc_input->type] =
1426 base::Bind(&DecoratedTextfield::SetInvalid, 1425 base::Bind(&DecoratedTextfield::SetInvalid,
1427 base::Unretained(decorated_cvc)); 1426 base::Unretained(decorated_cvc));
1428 } 1427 }
1429 1428
1430 std::vector<AutofillFieldType> invalid_inputs; 1429 std::vector<AutofillFieldType> invalid_inputs;
1431 invalid_inputs = controller_->InputsAreValid(detail_outputs, validation_type); 1430 invalid_inputs = controller_->InputsAreValid(detail_outputs, validation_type);
(...skipping 10 matching lines...) Expand all
1442 iter->second.Run(false); // Calls SetInvalid(false) for this field. 1441 iter->second.Run(false); // Calls SetInvalid(false) for this field.
1443 } 1442 }
1444 1443
1445 return invalid_inputs.empty(); 1444 return invalid_inputs.empty();
1446 } 1445 }
1447 1446
1448 bool AutofillDialogViews::ValidateForm() { 1447 bool AutofillDialogViews::ValidateForm() {
1449 bool all_valid = true; 1448 bool all_valid = true;
1450 for (DetailGroupMap::iterator iter = detail_groups_.begin(); 1449 for (DetailGroupMap::iterator iter = detail_groups_.begin();
1451 iter != detail_groups_.end(); ++iter) { 1450 iter != detail_groups_.end(); ++iter) {
1452 DetailsGroup* group = &iter->second; 1451 const DetailsGroup& group = iter->second;
1453 if (!group->container->visible()) 1452 if (!group.container->visible())
1454 continue; 1453 continue;
1455 1454
1456 if (!ValidateGroup(group, AutofillDialogController::VALIDATE_FINAL)) 1455 if (!ValidateGroup(group, AutofillDialogController::VALIDATE_FINAL))
1457 all_valid = false; 1456 all_valid = false;
1458 } 1457 }
1459 1458
1460 return all_valid; 1459 return all_valid;
1461 } 1460 }
1462 1461
1463 void AutofillDialogViews::TextfieldEditedOrActivated( 1462 void AutofillDialogViews::TextfieldEditedOrActivated(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1498 // Many fields (i.e. CC#) are invalid for most of the duration of editing, 1497 // Many fields (i.e. CC#) are invalid for most of the duration of editing,
1499 // so flagging them as invalid prematurely is not helpful. However, 1498 // so flagging them as invalid prematurely is not helpful. However,
1500 // correcting a minor mistake (i.e. a wrong CC digit) should immediately 1499 // correcting a minor mistake (i.e. a wrong CC digit) should immediately
1501 // result in validation - positive user feedback. 1500 // result in validation - positive user feedback.
1502 if (decorated->invalid() && was_edit) { 1501 if (decorated->invalid() && was_edit) {
1503 decorated->SetInvalid(!controller_->InputIsValid(type, textfield->text())); 1502 decorated->SetInvalid(!controller_->InputIsValid(type, textfield->text()));
1504 1503
1505 // If the field transitioned from invalid to valid, re-validate the group, 1504 // If the field transitioned from invalid to valid, re-validate the group,
1506 // since inter-field checks become meaningful with valid fields. 1505 // since inter-field checks become meaningful with valid fields.
1507 if (!decorated->invalid()) 1506 if (!decorated->invalid())
1508 ValidateGroup(group, AutofillDialogController::VALIDATE_EDIT); 1507 ValidateGroup(*group, AutofillDialogController::VALIDATE_EDIT);
1509 } 1508 }
1510 1509
1511 gfx::Image icon = controller_->IconForField(type, textfield->text()); 1510 gfx::Image icon = controller_->IconForField(type, textfield->text());
1512 textfield->SetIcon(icon.AsImageSkia()); 1511 textfield->SetIcon(icon.AsImageSkia());
1513 } 1512 }
1514 1513
1515 void AutofillDialogViews::ContentsPreferredSizeChanged() { 1514 void AutofillDialogViews::ContentsPreferredSizeChanged() {
1516 if (GetWidget()) { 1515 if (GetWidget()) {
1517 GetWidget()->SetSize(GetWidget()->non_client_view()->GetPreferredSize()); 1516 GetWidget()->SetSize(GetWidget()->non_client_view()->GetPreferredSize());
1518 // If the above line does not cause the dialog's size to change, |contents_| 1517 // If the above line does not cause the dialog's size to change, |contents_|
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1581 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section) 1580 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section)
1582 : section(section), 1581 : section(section),
1583 container(NULL), 1582 container(NULL),
1584 manual_input(NULL), 1583 manual_input(NULL),
1585 suggested_info(NULL), 1584 suggested_info(NULL),
1586 suggested_button(NULL) {} 1585 suggested_button(NULL) {}
1587 1586
1588 AutofillDialogViews::DetailsGroup::~DetailsGroup() {} 1587 AutofillDialogViews::DetailsGroup::~DetailsGroup() {}
1589 1588
1590 } // namespace autofill 1589 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/autofill/autofill_dialog_views.h ('k') | components/autofill/browser/wallet/full_wallet_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698