Home | History | Annotate | Download | only in autofill
      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_FIELD_H_
      6 #define CHROME_BROWSER_AUTOFILL_ADDRESS_FIELD_H_
      7 #pragma once
      8 
      9 #include <vector>
     10 
     11 #include "base/basictypes.h"
     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_field.h"
     16 
     17 class AutofillField;
     18 
     19 class AddressField : public FormField {
     20  public:
     21   virtual bool GetFieldInfo(FieldTypeMap* field_type_map) const;
     22   virtual FormFieldType GetFormFieldType() const;
     23 
     24   static AddressField* Parse(std::vector<AutofillField*>::const_iterator* iter,
     25                              bool is_ecml);
     26 
     27   // Tries to determine the billing/shipping type of this address.
     28   AddressType FindType() const;
     29 
     30   void SetType(AddressType address_type) { type_ = address_type; }
     31 
     32   // Returns true if this is a full address as opposed to an address fragment
     33   // such as a stand-alone ZIP code.
     34   bool IsFullAddress();
     35 
     36  private:
     37   AddressField();
     38 
     39   static bool ParseCompany(std::vector<AutofillField*>::const_iterator* iter,
     40                            bool is_ecml, AddressField* address_field);
     41   static bool ParseAddressLines(
     42       std::vector<AutofillField*>::const_iterator* iter,
     43       bool is_ecml, AddressField* address_field);
     44   static bool ParseCountry(std::vector<AutofillField*>::const_iterator* iter,
     45                            bool is_ecml, AddressField* address_field);
     46   static bool ParseZipCode(std::vector<AutofillField*>::const_iterator* iter,
     47                            bool is_ecml, AddressField* address_field);
     48   static bool ParseCity(std::vector<AutofillField*>::const_iterator* iter,
     49                         bool is_ecml, AddressField* address_field);
     50   static bool ParseState(std::vector<AutofillField*>::const_iterator* iter,
     51                          bool is_ecml, AddressField* address_field);
     52 
     53   // Looks for an address type in the given text, which the caller must
     54   // convert to lowercase.
     55   static AddressType AddressTypeFromText(const string16& text);
     56 
     57   AutofillField* company_;   // optional
     58   AutofillField* address1_;
     59   AutofillField* address2_;  // optional
     60   AutofillField* city_;
     61   AutofillField* state_;     // optional
     62   AutofillField* zip_;
     63   AutofillField* zip4_;      // optional ZIP+4; we don't fill this yet
     64   AutofillField* country_;   // optional
     65 
     66   AddressType type_;
     67   bool is_ecml_;
     68 
     69   DISALLOW_COPY_AND_ASSIGN(AddressField);
     70 };
     71 
     72 #endif  // CHROME_BROWSER_AUTOFILL_ADDRESS_FIELD_H_
     73