address.h revision 3345a6884c488ff3a535c2c9acdd33d74b37e311
1c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Copyright (c) 2010 The Chromium Authors. All rights reserved.
2c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Use of this source code is governed by a BSD-style license that can be
3c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// found in the LICENSE file.
4c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
5c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#ifndef CHROME_BROWSER_AUTOFILL_ADDRESS_H_
6c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#define CHROME_BROWSER_AUTOFILL_ADDRESS_H_
73345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick#pragma once
8c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
9c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include <vector>
10c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
11c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "base/string16.h"
12c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "chrome/browser/autofill/form_group.h"
13c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
14c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// A form group that stores address information.
15c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass Address : public FormGroup {
16c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch public:
17c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  Address() {}
18c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual ~Address() {}
19c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
20c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // FormGroup implementation:
21c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual FormGroup* Clone() const = 0;
22c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void GetPossibleFieldTypes(const string16& text,
23c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                                     FieldTypeSet* possible_types) const;
24c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void GetAvailableFieldTypes(FieldTypeSet* available_types) const;
25c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void FindInfoMatches(const AutoFillType& type,
26c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                               const string16& info,
27c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                               std::vector<string16>* matched_text) const;
28c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual string16 GetFieldText(const AutoFillType& type) const;
29c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void SetInfo(const AutoFillType& type, const string16& value);
30c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
31c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Sets all of the fields to the empty string.
32c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void Clear();
33c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
34c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Sets the values of this object to the values in |address|.
35c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void Clone(const Address& address);
36c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
37c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch protected:
38c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  explicit Address(const Address& address);
39c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
40c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch private:
41c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Vector of tokens in an address line.
42c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  typedef std::vector<string16> LineTokens;
43c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
44c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  const string16& line1() const { return line1_; }
45c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  const string16& line2() const { return line2_; }
46c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  const string16& apt_num() const { return apt_num_; }
47c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  const string16& city() const { return city_; }
48c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  const string16& state() const { return state_; }
49c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  const string16& country() const { return country_; }
50c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  const string16& zip_code() const { return zip_code_; }
51c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
52c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void set_line1(const string16& line1);
53c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void set_line2(const string16& line2);
54c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void set_apt_num(const string16& apt_num) { apt_num_ = apt_num; }
55c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void set_city(const string16& city) { city_ = city; }
56c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void set_state(const string16& state) { state_ = state; }
57c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void set_country(const string16& country) { country_ = country; }
58c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void set_zip_code(const string16& zip_code) { zip_code_ = zip_code; }
59c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
60c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void operator=(const Address& address);
61c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
62c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The following functions match |text| against the various values of the
63c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // address, returning true on match.
64c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual bool IsLine1(const string16& text) const;
65c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual bool IsLine2(const string16& text) const;
66c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual bool IsAptNum(const string16& text) const;
67c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual bool IsCity(const string16& text) const;
68c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual bool IsState(const string16& text) const;
69c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual bool IsCountry(const string16& text) const;
70c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual bool IsZipCode(const string16& text) const;
71c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
72c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The following functions should return the field type for each part of the
73c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // address.  Currently, these are either home or billing address types.
74c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual AutoFillFieldType GetLine1Type() const = 0;
75c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual AutoFillFieldType GetLine2Type() const = 0;
76c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual AutoFillFieldType GetAptNumType() const = 0;
77c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual AutoFillFieldType GetCityType() const = 0;
78c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual AutoFillFieldType GetStateType() const = 0;
79c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual AutoFillFieldType GetZipCodeType() const = 0;
80c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual AutoFillFieldType GetCountryType() const = 0;
81c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
82c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // A helper function for FindInfoMatches that only handles matching |info|
83c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // with the requested field subgroup.
84c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  bool FindInfoMatchesHelper(const FieldTypeSubGroup& subgroup,
85c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                             const string16& info,
86c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                             string16* match) const;
87c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
88c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Returns true if all of the tokens in |text| match the tokens in
89c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // |line_tokens|.
90c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  bool IsLineMatch(const string16& text, const LineTokens& line_tokens) const;
91c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
92c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Returns true if |word| is one of the tokens in |line_tokens|.
93c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  bool IsWordInLine(const string16& word, const LineTokens& line_tokens) const;
94c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
95c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // List of tokens in each part of |line1_| and |line2_|.
96c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  LineTokens line1_tokens_;
97c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  LineTokens line2_tokens_;
98c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
99c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The address.
100c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  string16 line1_;
101c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  string16 line2_;
102c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  string16 apt_num_;
103c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  string16 city_;
104c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  string16 state_;
105c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  string16 country_;
106c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  string16 zip_code_;
107c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch};
108c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
109c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#endif  // CHROME_BROWSER_AUTOFILL_ADDRESS_H_
110