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_CONTACT_INFO_H_ 6 #define CHROME_BROWSER_AUTOFILL_CONTACT_INFO_H_ 7 #pragma once 8 9 #include <vector> 10 11 #include "base/gtest_prod_util.h" 12 #include "base/string16.h" 13 #include "chrome/browser/autofill/field_types.h" 14 #include "chrome/browser/autofill/form_group.h" 15 16 // A form group that stores name information. 17 class NameInfo : public FormGroup { 18 public: 19 NameInfo(); 20 NameInfo(const NameInfo& info); 21 virtual ~NameInfo(); 22 23 NameInfo& operator=(const NameInfo& info); 24 25 // FormGroup: 26 virtual void GetPossibleFieldTypes(const string16& text, 27 FieldTypeSet* possible_types) const; 28 virtual void GetAvailableFieldTypes(FieldTypeSet* available_types) const; 29 virtual string16 GetInfo(AutofillFieldType type) const; 30 virtual void SetInfo(AutofillFieldType type, const string16& value); 31 32 private: 33 FRIEND_TEST_ALL_PREFIXES(NameInfoTest, TestSetFullName); 34 35 // Returns the full name, which can include up to the first, middle, and last 36 // name. 37 string16 FullName() const; 38 39 // Returns the middle initial if |middle_| is non-empty. Returns an empty 40 // string otherwise. 41 string16 MiddleInitial() const; 42 first()43 const string16& first() const { return first_; } middle()44 const string16& middle() const { return middle_; } last()45 const string16& last() const { return last_; } 46 47 // Returns true if |text| is the first name. 48 bool IsFirstName(const string16& text) const; 49 50 // Returns true if |text| is the middle name. 51 bool IsMiddleName(const string16& text) const; 52 53 // Returns true if |text| is the last name. 54 bool IsLastName(const string16& text) const; 55 56 // Returns true if |text| is the middle initial. 57 bool IsMiddleInitial(const string16& text) const; 58 59 // Returns true if |text| is the last name. 60 bool IsFullName(const string16& text) const; 61 62 // Returns true if all of the tokens in |text| match the tokens in 63 // |name_tokens|. 64 bool IsNameMatch(const string16& text, 65 const std::vector<string16>& name_tokens) const; 66 67 // Returns true if |word| is one of the tokens in |name_tokens|. 68 bool IsWordInName(const string16& word, 69 const std::vector<string16>& name_tokens) const; 70 71 // Sets |first_| to |first| and |first_tokens_| to the set of tokens in 72 // |first|, made lowercase. 73 void SetFirst(const string16& first); 74 75 // Sets |middle_| to |middle| and |middle_tokens_| to the set of tokens in 76 // |middle|, made lowercase. 77 void SetMiddle(const string16& middle); 78 79 // Sets |last_| to |last| and |last_tokens_| to the set of tokens in |last|, 80 // made lowercase. 81 void SetLast(const string16& last); 82 83 // Sets |first_|, |middle_|, |last_| and |*_tokens_| to the tokenized 84 // |full|. It is tokenized on a space only. 85 void SetFullName(const string16& full); 86 87 // List of tokens in each part of the name. 88 std::vector<string16> first_tokens_; 89 std::vector<string16> middle_tokens_; 90 std::vector<string16> last_tokens_; 91 92 string16 first_; 93 string16 middle_; 94 string16 last_; 95 }; 96 97 class EmailInfo : public FormGroup { 98 public: 99 EmailInfo(); 100 EmailInfo(const EmailInfo& info); 101 virtual ~EmailInfo(); 102 103 EmailInfo& operator=(const EmailInfo& info); 104 105 // FormGroup: 106 virtual void GetPossibleFieldTypes(const string16& text, 107 FieldTypeSet* possible_types) const; 108 virtual void GetAvailableFieldTypes(FieldTypeSet* available_types) const; 109 virtual string16 GetInfo(AutofillFieldType type) const; 110 virtual void SetInfo(AutofillFieldType type, const string16& value); 111 112 private: 113 string16 email_; 114 }; 115 116 class CompanyInfo : public FormGroup { 117 public: 118 CompanyInfo(); 119 CompanyInfo(const CompanyInfo& info); 120 virtual ~CompanyInfo(); 121 122 CompanyInfo& operator=(const CompanyInfo& info); 123 124 // FormGroup: 125 virtual void GetPossibleFieldTypes(const string16& text, 126 FieldTypeSet* possible_types) const; 127 virtual void GetAvailableFieldTypes(FieldTypeSet* available_types) const; 128 virtual string16 GetInfo(AutofillFieldType type) const; 129 virtual void SetInfo(AutofillFieldType type, const string16& value); 130 131 private: 132 string16 company_name_; 133 }; 134 135 #endif // CHROME_BROWSER_AUTOFILL_CONTACT_INFO_H_ 136