blob: adbc66a0a459732184179b709753c67874345689 [file] [log] [blame]
[email protected]6c178512010-01-04 20:27:251// Copyright (c) 2010 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_CONTACT_INFO_H_
6#define CHROME_BROWSER_AUTOFILL_CONTACT_INFO_H_
7
8#include <vector>
9
10#include "base/string16.h"
11#include "chrome/browser/autofill/form_group.h"
12
13typedef std::vector<string16> NameTokens;
14
15// A form group that stores contact information.
16class ContactInfo : public FormGroup {
17 public:
18 ContactInfo() {}
19
20 // FormGroup implementation:
21 virtual FormGroup* Clone() const;
22 virtual void GetPossibleFieldTypes(const string16& text,
23 FieldTypeSet* possible_types) const;
24 virtual void FindInfoMatches(const AutoFillType& type,
25 const string16& info,
26 std::vector<string16>* matched_text) const;
27 virtual string16 GetFieldText(const AutoFillType& type) const;
28 virtual void SetInfo(const AutoFillType& type, const string16& value);
29
[email protected]877535172010-03-03 01:57:0730 private:
31 explicit ContactInfo(const ContactInfo& contact_info);
32 void operator=(const ContactInfo& info);
33
[email protected]6c178512010-01-04 20:27:2534 // Returns the full name, which can include up to the first, middle, middle
35 // initial, last name, and suffix.
36 string16 FullName() const;
37
[email protected]877535172010-03-03 01:57:0738 // Returns the middle initial if |middle_| is non-empty. Returns an empty
39 // string otherwise.
[email protected]6c178512010-01-04 20:27:2540 string16 MiddleInitial() const;
[email protected]6c178512010-01-04 20:27:2541
[email protected]877535172010-03-03 01:57:0742 const string16& first() const { return first_; }
43 const string16& middle() const { return middle_; }
44 const string16& last() const { return last_; }
45 const string16& suffix() const { return suffix_; }
46 const string16& email() const { return email_; }
47 const string16& company_name() const { return company_name_; }
[email protected]6c178512010-01-04 20:27:2548
49 // A helper function for FindInfoMatches that only handles matching the info
50 // with the requested field type.
51 bool FindInfoMatchesHelper(const AutoFillFieldType& field_type,
52 const string16& info,
53 string16* matched_text) const;
54
55 // Returns true if |text| is the first name.
56 bool IsFirstName(const string16& text) const;
57
58 // Returns true if |text| is the middle name.
59 bool IsMiddleName(const string16& text) const;
60
61 // Returns true if |text| is the last name.
62 bool IsLastName(const string16& text) const;
63
64 // Returns true if |text| is the suffix.
65 bool IsSuffix(const string16& text) const;
66
67 // Returns true if |text| is the middle initial.
68 bool IsMiddleInitial(const string16& text) const;
69
70 // Returns true if |text| is the last name.
71 bool IsFullName(const string16& text) const;
72
73 // Returns true if all of the tokens in |text| match the tokens in
74 // |name_tokens|.
75 bool IsNameMatch(const string16& text, const NameTokens& name_tokens) const;
76
77 // Returns true if |word| is one of the tokens in |name_tokens|.
78 bool IsWordInName(const string16& word, const NameTokens& name_tokens) const;
79
80 // Sets |first_| to |first| and |first_tokens_| to the set of tokens in
81 // |first|, made lowercase.
82 void SetFirst(const string16& first);
83
84 // Sets |middle_| to |middle| and |middle_tokens_| to the set of tokens in
85 // |middle|, made lowercase.
86 void SetMiddle(const string16& middle);
87
88 // Sets |last_| to |last| and |last_tokens_| to the set of tokens in |last|,
89 // made lowercase.
90 void SetLast(const string16& last);
91
92 void set_suffix(const string16& suffix) { suffix_ = suffix; }
93
94 // List of tokens in each part of the name.
95 NameTokens first_tokens_;
96 NameTokens middle_tokens_;
97 NameTokens last_tokens_;
98
99 // Contact information data.
100 string16 first_;
101 string16 middle_;
102 string16 last_;
103 string16 suffix_;
104 string16 email_;
105 string16 company_name_;
106};
107
108#endif // CHROME_BROWSER_AUTOFILL_CONTACT_INFO_H_