| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/autofill/form_structure.h" | 5 #include "chrome/browser/autofill/form_structure.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 field->set_phone_part(AutofillField::PHONE_PREFIX); | 190 field->set_phone_part(AutofillField::PHONE_PREFIX); |
| 191 return true; | 191 return true; |
| 192 } | 192 } |
| 193 | 193 |
| 194 if (autocomplete_type == ASCIIToUTF16("phone-local-suffix")) { | 194 if (autocomplete_type == ASCIIToUTF16("phone-local-suffix")) { |
| 195 field->set_heuristic_type(PHONE_HOME_NUMBER); | 195 field->set_heuristic_type(PHONE_HOME_NUMBER); |
| 196 field->set_phone_part(AutofillField::PHONE_SUFFIX); | 196 field->set_phone_part(AutofillField::PHONE_SUFFIX); |
| 197 return true; | 197 return true; |
| 198 } | 198 } |
| 199 | 199 |
| 200 if (autocomplete_type == ASCIIToUTF16("fax-full")) { | |
| 201 field->set_heuristic_type(PHONE_FAX_WHOLE_NUMBER); | |
| 202 return true; | |
| 203 } | |
| 204 | |
| 205 if (autocomplete_type == ASCIIToUTF16("fax-country-code")) { | |
| 206 field->set_heuristic_type(PHONE_FAX_COUNTRY_CODE); | |
| 207 return true; | |
| 208 } | |
| 209 | |
| 210 if (autocomplete_type == ASCIIToUTF16("fax-national")) { | |
| 211 field->set_heuristic_type(PHONE_FAX_CITY_AND_NUMBER); | |
| 212 return true; | |
| 213 } | |
| 214 | |
| 215 if (autocomplete_type == ASCIIToUTF16("fax-area-code")) { | |
| 216 field->set_heuristic_type(PHONE_FAX_CITY_CODE); | |
| 217 return true; | |
| 218 } | |
| 219 | |
| 220 if (autocomplete_type == ASCIIToUTF16("fax-local")) { | |
| 221 field->set_heuristic_type(PHONE_FAX_NUMBER); | |
| 222 return true; | |
| 223 } | |
| 224 | |
| 225 if (autocomplete_type == ASCIIToUTF16("fax-local-prefix")) { | |
| 226 field->set_heuristic_type(PHONE_FAX_NUMBER); | |
| 227 field->set_phone_part(AutofillField::PHONE_PREFIX); | |
| 228 return true; | |
| 229 } | |
| 230 | |
| 231 if (autocomplete_type == ASCIIToUTF16("fax-local-suffix")) { | |
| 232 field->set_heuristic_type(PHONE_FAX_NUMBER); | |
| 233 field->set_phone_part(AutofillField::PHONE_SUFFIX); | |
| 234 return true; | |
| 235 } | |
| 236 | |
| 237 if (autocomplete_type == ASCIIToUTF16("cc-full-name")) { | 200 if (autocomplete_type == ASCIIToUTF16("cc-full-name")) { |
| 238 field->set_heuristic_type(CREDIT_CARD_NAME); | 201 field->set_heuristic_type(CREDIT_CARD_NAME); |
| 239 return true; | 202 return true; |
| 240 } | 203 } |
| 241 | 204 |
| 242 if (autocomplete_type == ASCIIToUTF16("cc-number")) { | 205 if (autocomplete_type == ASCIIToUTF16("cc-number")) { |
| 243 field->set_heuristic_type(CREDIT_CARD_NUMBER); | 206 field->set_heuristic_type(CREDIT_CARD_NUMBER); |
| 244 return true; | 207 return true; |
| 245 } | 208 } |
| 246 | 209 |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 FieldTypeSet collapsed_field_types; | 650 FieldTypeSet collapsed_field_types; |
| 688 for (FieldTypeSet::const_iterator it = field_types.begin(); | 651 for (FieldTypeSet::const_iterator it = field_types.begin(); |
| 689 it != field_types.end(); | 652 it != field_types.end(); |
| 690 ++it) { | 653 ++it) { |
| 691 // Since we currently only support US phone numbers, the (city code + main | 654 // Since we currently only support US phone numbers, the (city code + main |
| 692 // digits) number is almost always identical to the whole phone number. | 655 // digits) number is almost always identical to the whole phone number. |
| 693 // TODO(isherman): Improve this logic once we add support for | 656 // TODO(isherman): Improve this logic once we add support for |
| 694 // international numbers. | 657 // international numbers. |
| 695 if (*it == PHONE_HOME_CITY_AND_NUMBER) | 658 if (*it == PHONE_HOME_CITY_AND_NUMBER) |
| 696 collapsed_field_types.insert(PHONE_HOME_WHOLE_NUMBER); | 659 collapsed_field_types.insert(PHONE_HOME_WHOLE_NUMBER); |
| 697 else if (*it == PHONE_FAX_CITY_AND_NUMBER) | |
| 698 collapsed_field_types.insert(PHONE_FAX_WHOLE_NUMBER); | |
| 699 else | 660 else |
| 700 collapsed_field_types.insert(AutofillType::GetEquivalentFieldType(*it)); | 661 collapsed_field_types.insert(AutofillType::GetEquivalentFieldType(*it)); |
| 701 } | 662 } |
| 702 | 663 |
| 703 // Capture the field's type, if it is unambiguous. | 664 // Capture the field's type, if it is unambiguous. |
| 704 AutofillFieldType field_type = UNKNOWN_TYPE; | 665 AutofillFieldType field_type = UNKNOWN_TYPE; |
| 705 if (collapsed_field_types.size() == 1) | 666 if (collapsed_field_types.size() == 1) |
| 706 field_type = *collapsed_field_types.begin(); | 667 field_type = *collapsed_field_types.begin(); |
| 707 | 668 |
| 708 AutofillFieldType heuristic_type = field->heuristic_type(); | 669 AutofillFieldType heuristic_type = field->heuristic_type(); |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 971 AutofillFieldType previous_type = UNKNOWN_TYPE; | 932 AutofillFieldType previous_type = UNKNOWN_TYPE; |
| 972 | 933 |
| 973 for (std::vector<AutofillField*>::iterator field = fields_->begin(); | 934 for (std::vector<AutofillField*>::iterator field = fields_->begin(); |
| 974 field != fields_->end(); ++field) { | 935 field != fields_->end(); ++field) { |
| 975 const AutofillFieldType current_type = | 936 const AutofillFieldType current_type = |
| 976 AutofillType::GetEquivalentFieldType((*field)->type()); | 937 AutofillType::GetEquivalentFieldType((*field)->type()); |
| 977 | 938 |
| 978 bool already_saw_current_type = seen_types.count(current_type) > 0; | 939 bool already_saw_current_type = seen_types.count(current_type) > 0; |
| 979 | 940 |
| 980 // Forms often ask for multiple phone numbers -- e.g. both a daytime and | 941 // Forms often ask for multiple phone numbers -- e.g. both a daytime and |
| 981 // evening phone number. Our phone and fax number detection is also | 942 // evening phone number. Our phone number detection is also generally a |
| 982 // generally a little off. Hence, ignore both field types as a signal here. | 943 // little off. Hence, ignore this field type as a signal here. |
| 983 AutofillType::FieldTypeGroup current_type_group = | 944 if (AutofillType(current_type).group() == AutofillType::PHONE_HOME) |
| 984 AutofillType(current_type).group(); | |
| 985 if (current_type_group == AutofillType::PHONE_HOME || | |
| 986 current_type_group == AutofillType::PHONE_FAX) | |
| 987 already_saw_current_type = false; | 945 already_saw_current_type = false; |
| 988 | 946 |
| 989 // Some forms have adjacent fields of the same type. Two common examples: | 947 // Some forms have adjacent fields of the same type. Two common examples: |
| 990 // * Forms with two email fields, where the second is meant to "confirm" | 948 // * Forms with two email fields, where the second is meant to "confirm" |
| 991 // the first. | 949 // the first. |
| 992 // * Forms with a <select> menu for states in some countries, and a | 950 // * Forms with a <select> menu for states in some countries, and a |
| 993 // freeform <input> field for states in other countries. (Usually, only | 951 // freeform <input> field for states in other countries. (Usually, only |
| 994 // one of these two will be visible for any given choice of country.) | 952 // one of these two will be visible for any given choice of country.) |
| 995 // Generally, adjacent fields of the same type belong in the same logical | 953 // Generally, adjacent fields of the same type belong in the same logical |
| 996 // section. | 954 // section. |
| 997 if (current_type == previous_type) | 955 if (current_type == previous_type) |
| 998 already_saw_current_type = false; | 956 already_saw_current_type = false; |
| 999 | 957 |
| 1000 previous_type = current_type; | 958 previous_type = current_type; |
| 1001 | 959 |
| 1002 if (current_type != UNKNOWN_TYPE && already_saw_current_type) { | 960 if (current_type != UNKNOWN_TYPE && already_saw_current_type) { |
| 1003 // We reached the end of a section, so start a new section. | 961 // We reached the end of a section, so start a new section. |
| 1004 seen_types.clear(); | 962 seen_types.clear(); |
| 1005 current_section = (*field)->unique_name(); | 963 current_section = (*field)->unique_name(); |
| 1006 } | 964 } |
| 1007 | 965 |
| 1008 seen_types.insert(current_type); | 966 seen_types.insert(current_type); |
| 1009 (*field)->set_section(current_section); | 967 (*field)->set_section(current_section); |
| 1010 } | 968 } |
| 1011 } | 969 } |
| OLD | NEW |