blob: 52755aae4bb8259d2f0f9437d51ced9dc8b05c25 [file] [log] [blame]
[email protected]7b37fbb2011-03-07 16:16:031// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]6c178512010-01-04 20:27:252// 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_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
[email protected]6c178512010-01-04 20:27:258
9#include <vector>
10
[email protected]43897242011-03-09 03:52:1111#include "base/gtest_prod_util.h"
[email protected]6c178512010-01-04 20:27:2512#include "base/string16.h"
13#include "chrome/browser/autofill/form_group.h"
14
[email protected]43897242011-03-09 03:52:1115// A form group that stores name information.
16class NameInfo : public FormGroup {
[email protected]6c178512010-01-04 20:27:2517 public:
[email protected]43897242011-03-09 03:52:1118 NameInfo();
[email protected]791c8c72011-03-28 22:54:0319 NameInfo(const NameInfo& info);
[email protected]43897242011-03-09 03:52:1120 virtual ~NameInfo();
[email protected]6c178512010-01-04 20:27:2521
[email protected]43897242011-03-09 03:52:1122 NameInfo& operator=(const NameInfo& info);
23
24 // FormGroup:
[email protected]6c178512010-01-04 20:27:2525 virtual void GetPossibleFieldTypes(const string16& text,
26 FieldTypeSet* possible_types) const;
[email protected]cea1d112010-07-01 00:57:3327 virtual void GetAvailableFieldTypes(FieldTypeSet* available_types) const;
[email protected]1ffe8e992011-03-17 06:26:2928 virtual void FindInfoMatches(AutofillFieldType type,
[email protected]6c178512010-01-04 20:27:2529 const string16& info,
30 std::vector<string16>* matched_text) const;
[email protected]3b3a0ca72011-03-17 23:04:5531 virtual string16 GetInfo(AutofillFieldType type) const;
[email protected]1ffe8e992011-03-17 06:26:2932 virtual void SetInfo(AutofillFieldType type, const string16& value);
[email protected]6c178512010-01-04 20:27:2533
[email protected]877535172010-03-03 01:57:0734 private:
[email protected]43897242011-03-09 03:52:1135 FRIEND_TEST_ALL_PREFIXES(NameInfoTest, TestSetFullName);
[email protected]877535172010-03-03 01:57:0736
[email protected]43897242011-03-09 03:52:1137 // Returns the full name, which can include up to the first, middle, and last
38 // name.
[email protected]6c178512010-01-04 20:27:2539 string16 FullName() const;
40
[email protected]877535172010-03-03 01:57:0741 // Returns the middle initial if |middle_| is non-empty. Returns an empty
42 // string otherwise.
[email protected]6c178512010-01-04 20:27:2543 string16 MiddleInitial() const;
[email protected]6c178512010-01-04 20:27:2544
[email protected]877535172010-03-03 01:57:0745 const string16& first() const { return first_; }
46 const string16& middle() const { return middle_; }
47 const string16& last() const { return last_; }
[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.
[email protected]1ffe8e992011-03-17 06:26:2951 bool FindInfoMatchesHelper(AutofillFieldType field_type,
[email protected]6c178512010-01-04 20:27:2552 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
[email protected]6c178512010-01-04 20:27:2564 // Returns true if |text| is the middle initial.
65 bool IsMiddleInitial(const string16& text) const;
66
67 // Returns true if |text| is the last name.
68 bool IsFullName(const string16& text) const;
69
70 // Returns true if all of the tokens in |text| match the tokens in
71 // |name_tokens|.
[email protected]43897242011-03-09 03:52:1172 bool IsNameMatch(const string16& text,
73 const std::vector<string16>& name_tokens) const;
[email protected]6c178512010-01-04 20:27:2574
75 // Returns true if |word| is one of the tokens in |name_tokens|.
[email protected]43897242011-03-09 03:52:1176 bool IsWordInName(const string16& word,
77 const std::vector<string16>& name_tokens) const;
[email protected]6c178512010-01-04 20:27:2578
79 // Sets |first_| to |first| and |first_tokens_| to the set of tokens in
80 // |first|, made lowercase.
81 void SetFirst(const string16& first);
82
83 // Sets |middle_| to |middle| and |middle_tokens_| to the set of tokens in
84 // |middle|, made lowercase.
85 void SetMiddle(const string16& middle);
86
87 // Sets |last_| to |last| and |last_tokens_| to the set of tokens in |last|,
88 // made lowercase.
89 void SetLast(const string16& last);
90
[email protected]95f41652010-06-07 22:29:2491 // Sets |first_|, |middle_|, |last_| and |*_tokens_| to the tokenized
92 // |full|. It is tokenized on a space only.
93 void SetFullName(const string16& full);
94
[email protected]6c178512010-01-04 20:27:2595 // List of tokens in each part of the name.
[email protected]43897242011-03-09 03:52:1196 std::vector<string16> first_tokens_;
97 std::vector<string16> middle_tokens_;
98 std::vector<string16> last_tokens_;
[email protected]6c178512010-01-04 20:27:2599
[email protected]6c178512010-01-04 20:27:25100 string16 first_;
101 string16 middle_;
102 string16 last_;
[email protected]43897242011-03-09 03:52:11103};
104
105class EmailInfo : public FormGroup {
106 public:
107 EmailInfo();
[email protected]791c8c72011-03-28 22:54:03108 EmailInfo(const EmailInfo& info);
[email protected]43897242011-03-09 03:52:11109 virtual ~EmailInfo();
110
111 EmailInfo& operator=(const EmailInfo& info);
112
113 // FormGroup:
114 virtual void GetPossibleFieldTypes(const string16& text,
115 FieldTypeSet* possible_types) const;
116 virtual void GetAvailableFieldTypes(FieldTypeSet* available_types) const;
[email protected]1ffe8e992011-03-17 06:26:29117 virtual void FindInfoMatches(AutofillFieldType type,
[email protected]43897242011-03-09 03:52:11118 const string16& info,
119 std::vector<string16>* matched_text) const;
[email protected]3b3a0ca72011-03-17 23:04:55120 virtual string16 GetInfo(AutofillFieldType type) const;
[email protected]1ffe8e992011-03-17 06:26:29121 virtual void SetInfo(AutofillFieldType type, const string16& value);
[email protected]43897242011-03-09 03:52:11122
123 private:
[email protected]6c178512010-01-04 20:27:25124 string16 email_;
[email protected]43897242011-03-09 03:52:11125};
126
127class CompanyInfo : public FormGroup {
128 public:
129 CompanyInfo();
[email protected]791c8c72011-03-28 22:54:03130 CompanyInfo(const CompanyInfo& info);
[email protected]43897242011-03-09 03:52:11131 virtual ~CompanyInfo();
132
133 CompanyInfo& operator=(const CompanyInfo& info);
134
135 // FormGroup:
136 virtual void GetPossibleFieldTypes(const string16& text,
137 FieldTypeSet* possible_types) const;
138 virtual void GetAvailableFieldTypes(FieldTypeSet* available_types) const;
[email protected]1ffe8e992011-03-17 06:26:29139 virtual void FindInfoMatches(AutofillFieldType type,
[email protected]43897242011-03-09 03:52:11140 const string16& info,
141 std::vector<string16>* matched_text) const;
[email protected]3b3a0ca72011-03-17 23:04:55142 virtual string16 GetInfo(AutofillFieldType type) const;
[email protected]1ffe8e992011-03-17 06:26:29143 virtual void SetInfo(AutofillFieldType type, const string16& value);
[email protected]43897242011-03-09 03:52:11144
145 private:
[email protected]6c178512010-01-04 20:27:25146 string16 company_name_;
147};
148
149#endif // CHROME_BROWSER_AUTOFILL_CONTACT_INFO_H_