1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_ADDRESS_FIELD_H_
6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_ADDRESS_FIELD_H_
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/gtest_prod_util.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/strings/string16.h"
15 #include "components/autofill/core/browser/autofill_type.h"
16 #include "components/autofill/core/browser/form_field.h"
21 class AutofillScanner
;
23 class AddressField
: public FormField
{
25 static scoped_ptr
<FormField
> Parse(AutofillScanner
* scanner
);
29 bool ClassifyField(ServerFieldTypeMap
* map
) const override
;
32 FRIEND_TEST_ALL_PREFIXES(AddressFieldTest
, ParseOneLineAddress
);
33 FRIEND_TEST_ALL_PREFIXES(AddressFieldTest
, ParseTwoLineAddress
);
34 FRIEND_TEST_ALL_PREFIXES(AddressFieldTest
, ParseThreeLineAddress
);
35 FRIEND_TEST_ALL_PREFIXES(AddressFieldTest
, ParseStreetAddressFromTextArea
);
36 FRIEND_TEST_ALL_PREFIXES(AddressFieldTest
, ParseCity
);
37 FRIEND_TEST_ALL_PREFIXES(AddressFieldTest
, ParseState
);
38 FRIEND_TEST_ALL_PREFIXES(AddressFieldTest
, ParseZip
);
39 FRIEND_TEST_ALL_PREFIXES(AddressFieldTest
, ParseStateAndZipOneLabel
);
40 FRIEND_TEST_ALL_PREFIXES(AddressFieldTest
, ParseCountry
);
41 FRIEND_TEST_ALL_PREFIXES(AddressFieldTest
, ParseTwoLineAddressMissingLabel
);
42 FRIEND_TEST_ALL_PREFIXES(AddressFieldTest
, ParseCompany
);
44 static const int kZipCodeMatchType
;
45 static const int kCityMatchType
;
46 static const int kStateMatchType
;
50 bool ParseCompany(AutofillScanner
* scanner
);
51 bool ParseAddressLines(AutofillScanner
* scanner
);
52 bool ParseCountry(AutofillScanner
* scanner
);
53 bool ParseZipCode(AutofillScanner
* scanner
);
54 bool ParseCity(AutofillScanner
* scanner
);
55 bool ParseState(AutofillScanner
* scanner
);
57 // Parses the current field pointed to by |scanner|, if it exists, and tries
58 // to figure out whether the field's type: city, state, zip, or none of those.
59 bool ParseCityStateZipCode(AutofillScanner
* scanner
);
61 // Run matches on the name and label separately. If the return result is
62 // RESULT_MATCH_NAME_LABEL, then |scanner| advances and the field is set.
63 // Otherwise |scanner| rewinds and the field is cleared.
64 ParseNameLabelResult
ParseNameAndLabelForZipCode(AutofillScanner
* scanner
);
65 ParseNameLabelResult
ParseNameAndLabelForCity(AutofillScanner
* scanner
);
66 ParseNameLabelResult
ParseNameAndLabelForState(AutofillScanner
* scanner
);
68 AutofillField
* company_
;
69 AutofillField
* address1_
;
70 AutofillField
* address2_
;
71 AutofillField
* address3_
;
72 AutofillField
* street_address_
;
74 AutofillField
* state_
;
76 AutofillField
* zip4_
; // optional ZIP+4; we don't fill this yet.
77 AutofillField
* country_
;
79 DISALLOW_COPY_AND_ASSIGN(AddressField
);
82 } // namespace autofill
84 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_ADDRESS_FIELD_H_