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

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

Issue 14821005: [RFP, Autofill] Switching dialog field identification to int. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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
« no previous file with comments | « chrome/browser/ui/views/autofill/autofill_dialog_views.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 757 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 DCHECK(notification_area_); 768 DCHECK(notification_area_);
769 notification_area_->SetNotifications(controller_->CurrentNotifications()); 769 notification_area_->SetNotifications(controller_->CurrentNotifications());
770 ContentsPreferredSizeChanged(); 770 ContentsPreferredSizeChanged();
771 } 771 }
772 772
773 void AutofillDialogViews::UpdateSection(DialogSection section) { 773 void AutofillDialogViews::UpdateSection(DialogSection section) {
774 UpdateSectionImpl(section, true); 774 UpdateSectionImpl(section, true);
775 } 775 }
776 776
777 void AutofillDialogViews::FillSection(DialogSection section, 777 void AutofillDialogViews::FillSection(DialogSection section,
778 const DetailInput& originating_input) { 778 AutofillFieldType type) {
779 DetailsGroup* group = GroupForSection(section); 779 DetailsGroup* group = GroupForSection(section);
780 TextfieldMap::iterator text_mapping = 780 TextfieldMap::iterator text_mapping = group->textfields.find(type);
781 group->textfields.find(&originating_input);
782 if (text_mapping != group->textfields.end()) 781 if (text_mapping != group->textfields.end())
783 text_mapping->second->textfield()->SetText(string16()); 782 text_mapping->second->textfield()->SetText(string16());
784 783
785 UpdateSectionImpl(section, false); 784 UpdateSectionImpl(section, false);
786 } 785 }
787 786
788 void AutofillDialogViews::GetUserInput(DialogSection section, 787 void AutofillDialogViews::GetUserInput(DialogSection section,
789 DetailOutputMap* output) { 788 DetailOutputMap* output) {
790 DetailsGroup* group = GroupForSection(section); 789 DetailsGroup* group = GroupForSection(section);
791 for (TextfieldMap::const_iterator it = group->textfields.begin(); 790 for (TextfieldMap::const_iterator it = group->textfields.begin();
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 852
854 void AutofillDialogViews::SubmitForTesting() { 853 void AutofillDialogViews::SubmitForTesting() {
855 Accept(); 854 Accept();
856 } 855 }
857 856
858 void AutofillDialogViews::CancelForTesting() { 857 void AutofillDialogViews::CancelForTesting() {
859 if (Cancel()) 858 if (Cancel())
860 Hide(); 859 Hide();
861 } 860 }
862 861
863 string16 AutofillDialogViews::GetTextContentsOfInput(const DetailInput& input) { 862 string16 AutofillDialogViews::GetTextContentsOfInput(DialogSection section,
864 views::Textfield* textfield = TextfieldForInput(input); 863 AutofillFieldType type) {
864 views::Textfield* textfield = TextfieldForInput(section, type);
865 if (textfield) 865 if (textfield)
866 return textfield->text(); 866 return textfield->text();
867 867
868 views::Combobox* combobox = ComboboxForInput(input); 868 views::Combobox* combobox = ComboboxForInput(section, type);
869 if (combobox) 869 if (combobox)
870 return combobox->model()->GetItemAt(combobox->selected_index()); 870 return combobox->model()->GetItemAt(combobox->selected_index());
871 871
872 NOTREACHED(); 872 NOTREACHED();
873 return string16(); 873 return string16();
874 } 874 }
875 875
876 void AutofillDialogViews::SetTextContentsOfInput(const DetailInput& input, 876 void AutofillDialogViews::SetTextContentsOfInput(DialogSection section,
877 AutofillFieldType type,
877 const string16& contents) { 878 const string16& contents) {
878 views::Textfield* textfield = TextfieldForInput(input); 879 views::Textfield* textfield = TextfieldForInput(section, type);
879 if (textfield) { 880 if (textfield) {
880 TextfieldForInput(input)->SetText(contents); 881 textfield->SetText(contents);
881 return; 882 return;
882 } 883 }
883 884
884 views::Combobox* combobox = ComboboxForInput(input); 885 views::Combobox* combobox = ComboboxForInput(section, type);
885 if (combobox) { 886 if (combobox) {
886 for (int i = 0; i < combobox->model()->GetItemCount(); ++i) { 887 for (int i = 0; i < combobox->model()->GetItemCount(); ++i) {
887 if (contents == combobox->model()->GetItemAt(i)) { 888 if (contents == combobox->model()->GetItemAt(i)) {
888 combobox->SetSelectedIndex(i); 889 combobox->SetSelectedIndex(i);
889 return; 890 return;
890 } 891 }
891 } 892 }
892 // If we don't find a match, return the combobox to its default state. 893 // If we don't find a match, return the combobox to its default state.
893 combobox->SetSelectedIndex(combobox->model()->GetDefaultIndex()); 894 combobox->SetSelectedIndex(combobox->model()->GetDefaultIndex());
894 return; 895 return;
895 } 896 }
896 897
897 NOTREACHED(); 898 NOTREACHED();
898 } 899 }
899 900
900 void AutofillDialogViews::ActivateInput(const DetailInput& input) { 901 void AutofillDialogViews::ActivateInput(DialogSection section,
901 TextfieldEditedOrActivated(TextfieldForInput(input), false); 902 AutofillFieldType type) {
903 TextfieldEditedOrActivated(TextfieldForInput(section, type), false);
902 } 904 }
903 905
904 string16 AutofillDialogViews::GetWindowTitle() const { 906 string16 AutofillDialogViews::GetWindowTitle() const {
905 return controller_->DialogTitle(); 907 return controller_->DialogTitle();
906 } 908 }
907 909
908 void AutofillDialogViews::WindowClosing() { 910 void AutofillDialogViews::WindowClosing() {
909 focus_manager_->RemoveFocusChangeListener(this); 911 focus_manager_->RemoveFocusChangeListener(this);
910 } 912 }
911 913
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 expand ? expand : 1, 1282 expand ? expand : 1,
1281 views::GridLayout::USE_PREF, 1283 views::GridLayout::USE_PREF,
1282 0, 1284 0,
1283 0); 1285 0);
1284 1286
1285 ui::ComboboxModel* input_model = 1287 ui::ComboboxModel* input_model =
1286 controller_->ComboboxModelForAutofillType(input.type); 1288 controller_->ComboboxModelForAutofillType(input.type);
1287 if (input_model) { 1289 if (input_model) {
1288 views::Combobox* combobox = new views::Combobox(input_model); 1290 views::Combobox* combobox = new views::Combobox(input_model);
1289 combobox->set_listener(this); 1291 combobox->set_listener(this);
1290 comboboxes->insert(std::make_pair(&input, combobox)); 1292 comboboxes->insert(std::make_pair(input.type, combobox));
1291 layout->AddView(combobox); 1293 layout->AddView(combobox);
1292 1294
1293 for (int i = 0; i < input_model->GetItemCount(); ++i) { 1295 for (int i = 0; i < input_model->GetItemCount(); ++i) {
1294 if (input.initial_value == input_model->GetItemAt(i)) { 1296 if (input.initial_value == input_model->GetItemAt(i)) {
1295 combobox->SetSelectedIndex(i); 1297 combobox->SetSelectedIndex(i);
1296 break; 1298 break;
1297 } 1299 }
1298 } 1300 }
1299 } else { 1301 } else {
1300 DecoratedTextfield* field = new DecoratedTextfield( 1302 DecoratedTextfield* field = new DecoratedTextfield(
1301 input.initial_value, 1303 input.initial_value,
1302 l10n_util::GetStringUTF16(input.placeholder_text_rid), 1304 l10n_util::GetStringUTF16(input.placeholder_text_rid),
1303 this); 1305 this);
1304 1306
1305 gfx::Image icon = 1307 gfx::Image icon =
1306 controller_->IconForField(input.type, input.initial_value); 1308 controller_->IconForField(input.type, input.initial_value);
1307 field->textfield()->SetIcon(icon.AsImageSkia()); 1309 field->textfield()->SetIcon(icon.AsImageSkia());
1308 1310
1309 textfields->insert(std::make_pair(&input, field)); 1311 textfields->insert(std::make_pair(input.type, field));
1310 layout->AddView(field); 1312 layout->AddView(field);
1311 } 1313 }
1312 } 1314 }
1313 1315
1314 return view; 1316 return view;
1315 } 1317 }
1316 1318
1317 void AutofillDialogViews::UpdateSectionImpl( 1319 void AutofillDialogViews::UpdateSectionImpl(
1318 DialogSection section, 1320 DialogSection section,
1319 bool clobber_inputs) { 1321 bool clobber_inputs) {
1320 const DetailInputs& updated_inputs = 1322 const DetailInputs& updated_inputs =
1321 controller_->RequestedFieldsForSection(section); 1323 controller_->RequestedFieldsForSection(section);
1322 DetailsGroup* group = GroupForSection(section); 1324 DetailsGroup* group = GroupForSection(section);
1323 1325
1324 for (DetailInputs::const_iterator iter = updated_inputs.begin(); 1326 for (DetailInputs::const_iterator iter = updated_inputs.begin();
1325 iter != updated_inputs.end(); ++iter) { 1327 iter != updated_inputs.end(); ++iter) {
1326 const DetailInput& input = *iter; 1328 AutofillFieldType type = iter->type;
1327 TextfieldMap::iterator text_mapping = group->textfields.find(&input); 1329 TextfieldMap::iterator text_mapping = group->textfields.find(type);
1328 1330
1329 if (text_mapping != group->textfields.end()) { 1331 if (text_mapping != group->textfields.end()) {
1330 views::Textfield* textfield = text_mapping->second->textfield(); 1332 views::Textfield* textfield = text_mapping->second->textfield();
1331 if (textfield->text().empty() || clobber_inputs) { 1333 if (textfield->text().empty() || clobber_inputs) {
1332 textfield->SetText(iter->initial_value); 1334 textfield->SetText(iter->initial_value);
1333 textfield->SetIcon(controller_->IconForField( 1335 textfield->SetIcon(controller_->IconForField(type, textfield->text())
1334 input.type, textfield->text()).AsImageSkia()); 1336 .AsImageSkia());
1335 } 1337 }
1336 } 1338 }
1337 1339
1338 ComboboxMap::iterator combo_mapping = group->comboboxes.find(&input); 1340 ComboboxMap::iterator combo_mapping = group->comboboxes.find(type);
1339 if (combo_mapping != group->comboboxes.end()) { 1341 if (combo_mapping != group->comboboxes.end()) {
1340 views::Combobox* combobox = combo_mapping->second; 1342 views::Combobox* combobox = combo_mapping->second;
1341 for (int i = 0; i < combobox->model()->GetItemCount(); ++i) { 1343 for (int i = 0; i < combobox->model()->GetItemCount(); ++i) {
1342 if (input.initial_value == combobox->model()->GetItemAt(i)) { 1344 if (iter->initial_value == combobox->model()->GetItemAt(i)) {
1343 combobox->SetSelectedIndex(i); 1345 combobox->SetSelectedIndex(i);
1344 break; 1346 break;
1345 } 1347 }
1346 } 1348 }
1347 } 1349 }
1348 } 1350 }
1349 1351
1350 UpdateDetailsGroupState(*group); 1352 UpdateDetailsGroupState(*group);
1351 if (group->container && group->container->visible()) 1353 if (group->container && group->container->visible())
1352 ValidateGroup(group, AutofillDialogController::VALIDATE_EDIT); 1354 ValidateGroup(group, AutofillDialogController::VALIDATE_EDIT);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1387 } 1389 }
1388 1390
1389 ContentsPreferredSizeChanged(); 1391 ContentsPreferredSizeChanged();
1390 } 1392 }
1391 1393
1392 bool AutofillDialogViews::ValidateGroup( 1394 bool AutofillDialogViews::ValidateGroup(
1393 DetailsGroup* group, 1395 DetailsGroup* group,
1394 AutofillDialogController::ValidationType validation_type) { 1396 AutofillDialogController::ValidationType validation_type) {
1395 DCHECK(group->container->visible()); 1397 DCHECK(group->container->visible());
1396 1398
1397 scoped_ptr<DetailInput> cvc_input;
1398 DetailOutputMap detail_outputs; 1399 DetailOutputMap detail_outputs;
1399 std::map<AutofillFieldType, base::Callback<void(bool)> > field_map; 1400 std::map<AutofillFieldType, base::Callback<void(bool)> > field_map;
1400 1401
1401 if (group->manual_input->visible()) { 1402 if (group->manual_input->visible()) {
1402 for (TextfieldMap::iterator iter = group->textfields.begin(); 1403 for (TextfieldMap::iterator iter = group->textfields.begin();
1403 iter != group->textfields.end(); ++iter) { 1404 iter != group->textfields.end(); ++iter) {
1404 detail_outputs[iter->first] = iter->second->textfield()->text(); 1405 detail_outputs[iter->first] = iter->second->textfield()->text();
1405 field_map[iter->first->type] = 1406 field_map[iter->first] = base::Bind(&DecoratedTextfield::SetInvalid,
1406 base::Bind(&DecoratedTextfield::SetInvalid, 1407 base::Unretained(iter->second));
1407 base::Unretained(iter->second));
1408 } 1408 }
1409 for (ComboboxMap::iterator iter = group->comboboxes.begin(); 1409 for (ComboboxMap::iterator iter = group->comboboxes.begin();
1410 iter != group->comboboxes.end(); ++iter) { 1410 iter != group->comboboxes.end(); ++iter) {
1411 views::Combobox* combobox = iter->second; 1411 views::Combobox* combobox = iter->second;
1412 string16 item = 1412 string16 item =
1413 combobox->model()->GetItemAt(combobox->selected_index()); 1413 combobox->model()->GetItemAt(combobox->selected_index());
1414 detail_outputs[iter->first] = item; 1414 detail_outputs[iter->first] = item;
1415 field_map[iter->first->type] = 1415 field_map[iter->first] = base::Bind(&views::Combobox::SetInvalid,
1416 base::Bind(&views::Combobox::SetInvalid, 1416 base::Unretained(iter->second));
1417 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 detail_outputs[CREDIT_CARD_VERIFICATION_CODE] =
1423 cvc_input->type = CREDIT_CARD_VERIFICATION_CODE; 1422 decorated_cvc->textfield()->text();
1424 detail_outputs[cvc_input.get()] = decorated_cvc->textfield()->text(); 1423 field_map[CREDIT_CARD_VERIFICATION_CODE] = base::Bind(
1425 field_map[cvc_input->type] = 1424 &DecoratedTextfield::SetInvalid, base::Unretained(decorated_cvc));
1426 base::Bind(&DecoratedTextfield::SetInvalid,
1427 base::Unretained(decorated_cvc));
1428 } 1425 }
1429 1426
1430 std::vector<AutofillFieldType> invalid_inputs; 1427 std::vector<AutofillFieldType> invalid_inputs;
1431 invalid_inputs = controller_->InputsAreValid(detail_outputs, validation_type); 1428 invalid_inputs = controller_->InputsAreValid(detail_outputs, validation_type);
1432 // Flag invalid fields, removing them from |field_map|. 1429 // Flag invalid fields, removing them from |field_map|.
1433 for (std::vector<AutofillFieldType>::const_iterator iter = 1430 for (std::vector<AutofillFieldType>::const_iterator iter =
1434 invalid_inputs.begin(); iter != invalid_inputs.end(); ++iter) { 1431 invalid_inputs.begin(); iter != invalid_inputs.end(); ++iter) {
1435 field_map[*iter].Run(true); 1432 field_map[*iter].Run(true);
1436 field_map.erase(*iter); 1433 field_map.erase(*iter);
1437 } 1434 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1471 DecoratedTextfield* decorated = NULL; 1468 DecoratedTextfield* decorated = NULL;
1472 1469
1473 // Look for the input in the manual inputs. 1470 // Look for the input in the manual inputs.
1474 views::View* ancestor = 1471 views::View* ancestor =
1475 textfield->GetAncestorWithClassName(kDecoratedTextfieldClassName); 1472 textfield->GetAncestorWithClassName(kDecoratedTextfieldClassName);
1476 for (TextfieldMap::const_iterator iter = group->textfields.begin(); 1473 for (TextfieldMap::const_iterator iter = group->textfields.begin();
1477 iter != group->textfields.end(); 1474 iter != group->textfields.end();
1478 ++iter) { 1475 ++iter) {
1479 decorated = iter->second; 1476 decorated = iter->second;
1480 if (decorated == ancestor) { 1477 if (decorated == ancestor) {
1481 controller_->UserEditedOrActivatedInput(iter->first, 1478 controller_->UserEditedOrActivatedInput(group->section,
1479 iter->first,
1482 GetWidget()->GetNativeView(), 1480 GetWidget()->GetNativeView(),
1483 textfield->GetBoundsInScreen(), 1481 textfield->GetBoundsInScreen(),
1484 textfield->text(), 1482 textfield->text(),
1485 was_edit); 1483 was_edit);
1486 type = iter->first->type; 1484 type = iter->first;
1487 break; 1485 break;
1488 } 1486 }
1489 } 1487 }
1490 1488
1491 if (ancestor == group->suggested_info->decorated_textfield()) { 1489 if (ancestor == group->suggested_info->decorated_textfield()) {
1492 decorated = group->suggested_info->decorated_textfield(); 1490 decorated = group->suggested_info->decorated_textfield();
1493 type = CREDIT_CARD_VERIFICATION_CODE; 1491 type = CREDIT_CARD_VERIFICATION_CODE;
1494 } 1492 }
1495 DCHECK_NE(UNKNOWN_TYPE, type); 1493 DCHECK_NE(UNKNOWN_TYPE, type);
1496 1494
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1546 // accessed via |suggested_info|. 1544 // accessed via |suggested_info|.
1547 if (ancestor && 1545 if (ancestor &&
1548 ancestor == group->suggested_info->decorated_textfield()) { 1546 ancestor == group->suggested_info->decorated_textfield()) {
1549 return group; 1547 return group;
1550 } 1548 }
1551 } 1549 }
1552 return NULL; 1550 return NULL;
1553 } 1551 }
1554 1552
1555 views::Textfield* AutofillDialogViews::TextfieldForInput( 1553 views::Textfield* AutofillDialogViews::TextfieldForInput(
1556 const DetailInput& input) { 1554 DialogSection section,
1557 for (DetailGroupMap::iterator iter = detail_groups_.begin(); 1555 AutofillFieldType type) {
1558 iter != detail_groups_.end(); ++iter) { 1556 DetailsGroup* group = GroupForSection(section);
1559 const DetailsGroup& group = iter->second; 1557 if (group) {
1560 TextfieldMap::const_iterator text_mapping = group.textfields.find(&input); 1558 TextfieldMap::const_iterator text_mapping = group->textfields.find(type);
1561 if (text_mapping != group.textfields.end()) 1559 if (text_mapping != group->textfields.end())
1562 return text_mapping->second->textfield(); 1560 return text_mapping->second->textfield();
1563 } 1561 }
1564 1562
1565 return NULL; 1563 return NULL;
1566 } 1564 }
1567 1565
1568 views::Combobox* AutofillDialogViews::ComboboxForInput( 1566 views::Combobox* AutofillDialogViews::ComboboxForInput(DialogSection section,
1569 const DetailInput& input) { 1567 AutofillFieldType type) {
1570 for (DetailGroupMap::iterator iter = detail_groups_.begin(); 1568 DetailsGroup* group = GroupForSection(section);
1571 iter != detail_groups_.end(); ++iter) { 1569 if (group) {
1572 const DetailsGroup& group = iter->second; 1570 ComboboxMap::const_iterator combo_mapping = group->comboboxes.find(type);
1573 ComboboxMap::const_iterator combo_mapping = group.comboboxes.find(&input); 1571 if (combo_mapping != group->comboboxes.end())
1574 if (combo_mapping != group.comboboxes.end())
1575 return combo_mapping->second; 1572 return combo_mapping->second;
1576 } 1573 }
1577 1574
1578 return NULL; 1575 return NULL;
1579 } 1576 }
1580 1577
1581 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section) 1578 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section)
1582 : section(section), 1579 : section(section),
1583 container(NULL), 1580 container(NULL),
1584 manual_input(NULL), 1581 manual_input(NULL),
1585 suggested_info(NULL), 1582 suggested_info(NULL),
1586 suggested_button(NULL) {} 1583 suggested_button(NULL) {}
1587 1584
1588 AutofillDialogViews::DetailsGroup::~DetailsGroup() {} 1585 AutofillDialogViews::DetailsGroup::~DetailsGroup() {}
1589 1586
1590 } // namespace autofill 1587 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/autofill/autofill_dialog_views.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698