OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_UI_AUTOFILL_DATA_MODEL_WRAPPER_H_ | 5 #ifndef CHROME_BROWSER_UI_AUTOFILL_DATA_MODEL_WRAPPER_H_ |
6 #define CHROME_BROWSER_UI_AUTOFILL_DATA_MODEL_WRAPPER_H_ | 6 #define CHROME_BROWSER_UI_AUTOFILL_DATA_MODEL_WRAPPER_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "chrome/browser/ui/autofill/autofill_dialog_types.h" | 10 #include "chrome/browser/ui/autofill/autofill_dialog_types.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 } | 28 } |
29 | 29 |
30 // A glue class that allows uniform interactions with autocomplete data sources, | 30 // A glue class that allows uniform interactions with autocomplete data sources, |
31 // regardless of their type. Implementations are intended to be lightweight and | 31 // regardless of their type. Implementations are intended to be lightweight and |
32 // copyable, only holding weak references to their backing model. | 32 // copyable, only holding weak references to their backing model. |
33 class DataModelWrapper { | 33 class DataModelWrapper { |
34 public: | 34 public: |
35 virtual ~DataModelWrapper(); | 35 virtual ~DataModelWrapper(); |
36 | 36 |
37 // Returns the data for a specific autocomplete type. | 37 // Returns the data for a specific autocomplete type. |
38 virtual string16 GetInfo(AutofillFieldType type) const = 0; | 38 virtual base::string16 GetInfo(AutofillFieldType type) const = 0; |
39 | 39 |
40 // Returns the icon, if any, that represents this model. | 40 // Returns the icon, if any, that represents this model. |
41 virtual gfx::Image GetIcon(); | 41 virtual gfx::Image GetIcon(); |
42 | 42 |
43 // Fills in |inputs| with the data that this model contains (|inputs| is an | 43 // Fills in |inputs| with the data that this model contains (|inputs| is an |
44 // out-param). | 44 // out-param). |
45 virtual void FillInputs(DetailInputs* inputs); | 45 virtual void FillInputs(DetailInputs* inputs); |
46 | 46 |
47 // Returns text to display to the user to summarize this data source. The | 47 // Gets text to display to the user to summarize this data source. The |
48 // default implementation assumes this is an address. | 48 // default implementation assumes this is an address. Both params are required |
49 virtual string16 GetDisplayText(); | 49 // to be non-NULL and will be filled in with text that is vertically compact |
| 50 // (but may take up a lot of horizontal space) and horizontally compact (but |
| 51 // may take up a lot of vertical space) respectively. The return value will |
| 52 // be true and the outparams will be filled in only if the data represented is |
| 53 // complete and valid. |
| 54 virtual bool GetDisplayText(base::string16* vertically_compact, |
| 55 base::string16* horizontally_compact); |
50 | 56 |
51 // Fills in |form_structure| with the data that this model contains. |inputs| | 57 // Fills in |form_structure| with the data that this model contains. |inputs| |
52 // and |comparator| are used to determine whether each field in the | 58 // and |comparator| are used to determine whether each field in the |
53 // FormStructure should be filled in or left alone. Returns whether any fields | 59 // FormStructure should be filled in or left alone. Returns whether any fields |
54 // in |form_structure| were found to be matching. | 60 // in |form_structure| were found to be matching. |
55 bool FillFormStructure( | 61 bool FillFormStructure( |
56 const DetailInputs& inputs, | 62 const DetailInputs& inputs, |
57 const InputFieldComparator& compare, | 63 const InputFieldComparator& compare, |
58 FormStructure* form_structure) const; | 64 FormStructure* form_structure) const; |
59 | 65 |
60 protected: | 66 protected: |
61 DataModelWrapper(); | 67 DataModelWrapper(); |
62 | 68 |
63 // Fills in |field| with data from the model. | 69 // Fills in |field| with data from the model. |
64 virtual void FillFormField(AutofillField* field) const; | 70 virtual void FillFormField(AutofillField* field) const; |
65 | 71 |
66 private: | 72 private: |
| 73 // Formats address data into a single string using |separator| between |
| 74 // fields. |
| 75 base::string16 GetAddressDisplayText(const base::string16& separator); |
| 76 |
67 DISALLOW_COPY_AND_ASSIGN(DataModelWrapper); | 77 DISALLOW_COPY_AND_ASSIGN(DataModelWrapper); |
68 }; | 78 }; |
69 | 79 |
70 // A DataModelWrapper that does not hold data and does nothing when told to | 80 // A DataModelWrapper that does not hold data and does nothing when told to |
71 // fill in a form. | 81 // fill in a form. |
72 class EmptyDataModelWrapper : public DataModelWrapper { | 82 class EmptyDataModelWrapper : public DataModelWrapper { |
73 public: | 83 public: |
74 EmptyDataModelWrapper(); | 84 EmptyDataModelWrapper(); |
75 virtual ~EmptyDataModelWrapper(); | 85 virtual ~EmptyDataModelWrapper(); |
76 | 86 |
77 virtual string16 GetInfo(AutofillFieldType type) const OVERRIDE; | 87 virtual base::string16 GetInfo(AutofillFieldType type) const OVERRIDE; |
78 | 88 |
79 protected: | 89 protected: |
80 virtual void FillFormField(AutofillField* field) const OVERRIDE; | 90 virtual void FillFormField(AutofillField* field) const OVERRIDE; |
81 | 91 |
82 DISALLOW_COPY_AND_ASSIGN(EmptyDataModelWrapper); | 92 DISALLOW_COPY_AND_ASSIGN(EmptyDataModelWrapper); |
83 }; | 93 }; |
84 | 94 |
85 // A DataModelWrapper for Autofill data. | 95 // A DataModelWrapper for Autofill data. |
86 class AutofillDataModelWrapper : public DataModelWrapper { | 96 class AutofillDataModelWrapper : public DataModelWrapper { |
87 public: | 97 public: |
88 AutofillDataModelWrapper(const AutofillDataModel* data_model, size_t variant); | 98 AutofillDataModelWrapper(const AutofillDataModel* data_model, size_t variant); |
89 virtual ~AutofillDataModelWrapper(); | 99 virtual ~AutofillDataModelWrapper(); |
90 | 100 |
91 virtual string16 GetInfo(AutofillFieldType type) const OVERRIDE; | 101 virtual base::string16 GetInfo(AutofillFieldType type) const OVERRIDE; |
92 | 102 |
93 protected: | 103 protected: |
94 virtual void FillFormField(AutofillField* field) const OVERRIDE; | 104 virtual void FillFormField(AutofillField* field) const OVERRIDE; |
95 | 105 |
96 size_t variant() const { return variant_; } | 106 size_t variant() const { return variant_; } |
97 | 107 |
98 private: | 108 private: |
99 const AutofillDataModel* data_model_; | 109 const AutofillDataModel* data_model_; |
100 const size_t variant_; | 110 const size_t variant_; |
101 | 111 |
(...skipping 15 matching lines...) Expand all Loading... |
117 | 127 |
118 DISALLOW_COPY_AND_ASSIGN(AutofillProfileWrapper); | 128 DISALLOW_COPY_AND_ASSIGN(AutofillProfileWrapper); |
119 }; | 129 }; |
120 | 130 |
121 // A DataModelWrapper specifically for Autofill CreditCard data. | 131 // A DataModelWrapper specifically for Autofill CreditCard data. |
122 class AutofillCreditCardWrapper : public AutofillDataModelWrapper { | 132 class AutofillCreditCardWrapper : public AutofillDataModelWrapper { |
123 public: | 133 public: |
124 explicit AutofillCreditCardWrapper(const CreditCard* card); | 134 explicit AutofillCreditCardWrapper(const CreditCard* card); |
125 virtual ~AutofillCreditCardWrapper(); | 135 virtual ~AutofillCreditCardWrapper(); |
126 | 136 |
127 virtual string16 GetInfo(AutofillFieldType type) const OVERRIDE; | 137 virtual base::string16 GetInfo(AutofillFieldType type) const OVERRIDE; |
128 virtual gfx::Image GetIcon() OVERRIDE; | 138 virtual gfx::Image GetIcon() OVERRIDE; |
129 virtual string16 GetDisplayText() OVERRIDE; | 139 virtual bool GetDisplayText(base::string16* vertically_compact, |
| 140 base::string16* horizontally_compact) OVERRIDE; |
130 | 141 |
131 private: | 142 private: |
132 const CreditCard* card_; | 143 const CreditCard* card_; |
133 | 144 |
134 DISALLOW_COPY_AND_ASSIGN(AutofillCreditCardWrapper); | 145 DISALLOW_COPY_AND_ASSIGN(AutofillCreditCardWrapper); |
135 }; | 146 }; |
136 | 147 |
137 // A DataModelWrapper for Wallet addresses. | 148 // A DataModelWrapper for Wallet addresses. |
138 class WalletAddressWrapper : public DataModelWrapper { | 149 class WalletAddressWrapper : public DataModelWrapper { |
139 public: | 150 public: |
140 explicit WalletAddressWrapper(const wallet::Address* address); | 151 explicit WalletAddressWrapper(const wallet::Address* address); |
141 virtual ~WalletAddressWrapper(); | 152 virtual ~WalletAddressWrapper(); |
142 | 153 |
143 virtual string16 GetInfo(AutofillFieldType type) const OVERRIDE; | 154 virtual base::string16 GetInfo(AutofillFieldType type) const OVERRIDE; |
144 virtual string16 GetDisplayText() OVERRIDE; | 155 virtual bool GetDisplayText(base::string16* vertically_compact, |
| 156 base::string16* horizontally_compact) OVERRIDE; |
145 | 157 |
146 private: | 158 private: |
147 const wallet::Address* address_; | 159 const wallet::Address* address_; |
148 | 160 |
149 DISALLOW_COPY_AND_ASSIGN(WalletAddressWrapper); | 161 DISALLOW_COPY_AND_ASSIGN(WalletAddressWrapper); |
150 }; | 162 }; |
151 | 163 |
152 // A DataModelWrapper for Wallet instruments. | 164 // A DataModelWrapper for Wallet instruments. |
153 class WalletInstrumentWrapper : public DataModelWrapper { | 165 class WalletInstrumentWrapper : public DataModelWrapper { |
154 public: | 166 public: |
155 explicit WalletInstrumentWrapper( | 167 explicit WalletInstrumentWrapper( |
156 const wallet::WalletItems::MaskedInstrument* instrument); | 168 const wallet::WalletItems::MaskedInstrument* instrument); |
157 virtual ~WalletInstrumentWrapper(); | 169 virtual ~WalletInstrumentWrapper(); |
158 | 170 |
159 virtual string16 GetInfo(AutofillFieldType type) const OVERRIDE; | 171 virtual base::string16 GetInfo(AutofillFieldType type) const OVERRIDE; |
160 virtual gfx::Image GetIcon() OVERRIDE; | 172 virtual gfx::Image GetIcon() OVERRIDE; |
161 virtual string16 GetDisplayText() OVERRIDE; | 173 virtual bool GetDisplayText(base::string16* vertically_compact, |
| 174 base::string16* horizontally_compact) OVERRIDE; |
162 | 175 |
163 private: | 176 private: |
164 const wallet::WalletItems::MaskedInstrument* instrument_; | 177 const wallet::WalletItems::MaskedInstrument* instrument_; |
165 | 178 |
166 DISALLOW_COPY_AND_ASSIGN(WalletInstrumentWrapper); | 179 DISALLOW_COPY_AND_ASSIGN(WalletInstrumentWrapper); |
167 }; | 180 }; |
168 | 181 |
169 // A DataModelWrapper for FullWallet billing data. | 182 // A DataModelWrapper for FullWallet billing data. |
170 class FullWalletBillingWrapper : public DataModelWrapper { | 183 class FullWalletBillingWrapper : public DataModelWrapper { |
171 public: | 184 public: |
172 explicit FullWalletBillingWrapper(wallet::FullWallet* full_wallet); | 185 explicit FullWalletBillingWrapper(wallet::FullWallet* full_wallet); |
173 virtual ~FullWalletBillingWrapper(); | 186 virtual ~FullWalletBillingWrapper(); |
174 | 187 |
175 virtual string16 GetInfo(AutofillFieldType type) const OVERRIDE; | 188 virtual base::string16 GetInfo(AutofillFieldType type) const OVERRIDE; |
176 virtual string16 GetDisplayText() OVERRIDE; | 189 virtual bool GetDisplayText(base::string16* vertically_compact, |
| 190 base::string16* horizontally_compact) OVERRIDE; |
177 | 191 |
178 private: | 192 private: |
179 wallet::FullWallet* full_wallet_; | 193 wallet::FullWallet* full_wallet_; |
180 | 194 |
181 DISALLOW_COPY_AND_ASSIGN(FullWalletBillingWrapper); | 195 DISALLOW_COPY_AND_ASSIGN(FullWalletBillingWrapper); |
182 }; | 196 }; |
183 | 197 |
184 // A DataModelWrapper for FullWallet shipping data. | 198 // A DataModelWrapper for FullWallet shipping data. |
185 class FullWalletShippingWrapper : public DataModelWrapper { | 199 class FullWalletShippingWrapper : public DataModelWrapper { |
186 public: | 200 public: |
187 explicit FullWalletShippingWrapper(wallet::FullWallet* full_wallet); | 201 explicit FullWalletShippingWrapper(wallet::FullWallet* full_wallet); |
188 virtual ~FullWalletShippingWrapper(); | 202 virtual ~FullWalletShippingWrapper(); |
189 | 203 |
190 virtual string16 GetInfo(AutofillFieldType type) const OVERRIDE; | 204 virtual base::string16 GetInfo(AutofillFieldType type) const OVERRIDE; |
191 | 205 |
192 private: | 206 private: |
193 wallet::FullWallet* full_wallet_; | 207 wallet::FullWallet* full_wallet_; |
194 | 208 |
195 DISALLOW_COPY_AND_ASSIGN(FullWalletShippingWrapper); | 209 DISALLOW_COPY_AND_ASSIGN(FullWalletShippingWrapper); |
196 }; | 210 }; |
197 | 211 |
198 // A DataModelWrapper to copy the output of one section to the input of another. | 212 // A DataModelWrapper to copy the output of one section to the input of another. |
199 class DetailOutputWrapper : public DataModelWrapper { | 213 class DetailOutputWrapper : public DataModelWrapper { |
200 public: | 214 public: |
201 explicit DetailOutputWrapper(const DetailOutputMap& outputs); | 215 explicit DetailOutputWrapper(const DetailOutputMap& outputs); |
202 virtual ~DetailOutputWrapper(); | 216 virtual ~DetailOutputWrapper(); |
203 | 217 |
204 virtual base::string16 GetInfo(AutofillFieldType type) const OVERRIDE; | 218 virtual base::string16 GetInfo(AutofillFieldType type) const OVERRIDE; |
205 | 219 |
206 private: | 220 private: |
207 const DetailOutputMap& outputs_; | 221 const DetailOutputMap& outputs_; |
208 | 222 |
209 DISALLOW_COPY_AND_ASSIGN(DetailOutputWrapper); | 223 DISALLOW_COPY_AND_ASSIGN(DetailOutputWrapper); |
210 }; | 224 }; |
211 | 225 |
212 } // namespace autofill | 226 } // namespace autofill |
213 | 227 |
214 #endif // CHROME_BROWSER_UI_AUTOFILL_DATA_MODEL_WRAPPER_H_ | 228 #endif // CHROME_BROWSER_UI_AUTOFILL_DATA_MODEL_WRAPPER_H_ |
OLD | NEW |