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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_AUTOFILL_ADDRESS_H_ 6 #define CHROME_BROWSER_AUTOFILL_ADDRESS_H_ 7 #pragma once 8 9 #include <string> 10 #include <vector> 11 12 #include "base/string16.h" 13 #include "chrome/browser/autofill/autofill_type.h" 14 #include "chrome/browser/autofill/field_types.h" 15 #include "chrome/browser/autofill/form_group.h" 16 17 // A form group that stores address information. 18 class Address : public FormGroup { 19 public: 20 Address(); 21 Address(const Address& address); 22 virtual ~Address(); 23 24 Address& operator=(const Address& address); 25 26 // FormGroup: 27 virtual void GetPossibleFieldTypes(const string16& text, 28 FieldTypeSet* possible_types) const; 29 virtual void GetAvailableFieldTypes(FieldTypeSet* available_types) const; 30 virtual string16 GetInfo(AutofillFieldType type) const; 31 virtual void SetInfo(AutofillFieldType type, const string16& value); 32 33 const std::string& country_code() const { return country_code_; } 34 void set_country_code(const std::string& country_code) { 35 country_code_ = country_code; 36 } 37 38 // Sets all of the fields to the empty string. 39 void Clear(); 40 41 private: 42 // Vector of tokens in an address line. 43 typedef std::vector<string16> LineTokens; 44 45 // Returns the localized country name corresponding to |country_code_|. 46 string16 Country() const; 47 48 void set_line1(const string16& line1); 49 void set_line2(const string16& line2); 50 51 // Sets the |country_code_| based on |country|, which should be a localized 52 // country name. 53 void SetCountry(const string16& country); 54 55 // The following functions match |text| against the various values of the 56 // address, returning true on match. 57 virtual bool IsLine1(const string16& text) const; 58 virtual bool IsLine2(const string16& text) const; 59 virtual bool IsCity(const string16& text) const; 60 virtual bool IsState(const string16& text) const; 61 virtual bool IsCountry(const string16& text) const; 62 virtual bool IsZipCode(const string16& text) const; 63 64 // Returns true if all of the tokens in |text| match the tokens in 65 // |line_tokens|. 66 bool IsLineMatch(const string16& text, const LineTokens& line_tokens) const; 67 68 // Returns true if |word| is one of the tokens in |line_tokens|. 69 bool IsWordInLine(const string16& word, const LineTokens& line_tokens) const; 70 71 // List of tokens in each part of |line1_| and |line2_|. 72 LineTokens line1_tokens_; 73 LineTokens line2_tokens_; 74 75 // The address. 76 string16 line1_; 77 string16 line2_; 78 string16 city_; 79 string16 state_; 80 std::string country_code_; 81 string16 zip_code_; 82 }; 83 84 #endif // CHROME_BROWSER_AUTOFILL_ADDRESS_H_ 85