Add ICU message format support
[chromium-blink-merge.git] / chrome / browser / ui / autofill / data_model_wrapper.h
blobbcc95d94288d97312110c88482d261fa4e814108
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_AUTOFILL_DATA_MODEL_WRAPPER_H_
6 #define CHROME_BROWSER_UI_AUTOFILL_DATA_MODEL_WRAPPER_H_
8 #include <vector>
10 #include "base/compiler_specific.h"
11 #include "base/strings/string16.h"
12 #include "chrome/browser/ui/autofill/autofill_dialog_types.h"
13 #include "components/autofill/content/browser/wallet/wallet_items.h"
14 #include "components/autofill/core/browser/detail_input.h"
15 #include "components/autofill/core/browser/field_types.h"
16 #include "components/autofill/core/browser/form_structure.h"
18 namespace gfx {
19 class Image;
22 namespace i18n {
23 namespace addressinput {
24 struct AddressData;
28 namespace autofill {
30 class AutofillDataModel;
31 class AutofillProfile;
32 class AutofillType;
33 class CreditCard;
34 class FormStructure;
36 namespace wallet {
37 class Address;
38 class FullWallet;
41 // A glue class that allows uniform interactions with autocomplete data sources,
42 // regardless of their type. Implementations are intended to be lightweight and
43 // copyable, only holding weak references to their backing model.
44 class DataModelWrapper {
45 public:
46 virtual ~DataModelWrapper();
48 // Fills in |inputs| with the data that this model contains (|inputs| is an
49 // out-param).
50 void FillInputs(DetailInputs* inputs);
52 // Returns the data for a specific autocomplete type in a format for filling
53 // into a web form.
54 virtual base::string16 GetInfo(const AutofillType& type) const = 0;
56 // Returns the data for a specified type in a format optimized for displaying
57 // to the user.
58 virtual base::string16 GetInfoForDisplay(const AutofillType& type) const;
60 // Returns the icon, if any, that represents this model.
61 virtual gfx::Image GetIcon();
63 // Gets text to display to the user to summarize this data source. The
64 // default implementation assumes this is an address. Both params are required
65 // to be non-NULL and will be filled in with text that is vertically compact
66 // (but may take up a lot of horizontal space) and horizontally compact (but
67 // may take up a lot of vertical space) respectively. The return value will
68 // be true and the outparams will be filled in only if the data represented is
69 // complete and valid.
70 virtual bool GetDisplayText(base::string16* vertically_compact,
71 base::string16* horizontally_compact);
73 // Returns the BCP 47 language code that should be used for formatting the
74 // data for display.
75 virtual const std::string& GetLanguageCode() const = 0;
77 // Fills in |form_structure| with the data that this model contains. |inputs|
78 // and |comparator| are used to determine whether each field in the
79 // FormStructure should be filled in or left alone. Returns whether any fields
80 // in |form_structure| were found to be matching.
81 bool FillFormStructure(
82 const std::vector<ServerFieldType>& types,
83 const FormStructure::InputFieldComparator& compare,
84 FormStructure* form_structure) const;
86 protected:
87 DataModelWrapper();
89 private:
90 DISALLOW_COPY_AND_ASSIGN(DataModelWrapper);
93 // A DataModelWrapper for Autofill profiles.
94 class AutofillProfileWrapper : public DataModelWrapper {
95 public:
96 explicit AutofillProfileWrapper(const AutofillProfile* profile);
97 ~AutofillProfileWrapper() override;
99 base::string16 GetInfo(const AutofillType& type) const override;
100 base::string16 GetInfoForDisplay(const AutofillType& type) const override;
101 const std::string& GetLanguageCode() const override;
103 private:
104 const AutofillProfile* profile_;
106 DISALLOW_COPY_AND_ASSIGN(AutofillProfileWrapper);
109 // A DataModelWrapper specifically for shipping address profiles.
110 class AutofillShippingAddressWrapper : public AutofillProfileWrapper {
111 public:
112 explicit AutofillShippingAddressWrapper(const AutofillProfile* profile);
113 ~AutofillShippingAddressWrapper() override;
115 base::string16 GetInfo(const AutofillType& type) const override;
117 private:
118 DISALLOW_COPY_AND_ASSIGN(AutofillShippingAddressWrapper);
121 // A DataModelWrapper specifically for Autofill CreditCard data.
122 class AutofillCreditCardWrapper : public DataModelWrapper {
123 public:
124 explicit AutofillCreditCardWrapper(const CreditCard* card);
125 ~AutofillCreditCardWrapper() override;
127 base::string16 GetInfo(const AutofillType& type) const override;
128 gfx::Image GetIcon() override;
129 bool GetDisplayText(base::string16* vertically_compact,
130 base::string16* horizontally_compact) override;
131 const std::string& GetLanguageCode() const override;
133 private:
134 const CreditCard* card_;
136 DISALLOW_COPY_AND_ASSIGN(AutofillCreditCardWrapper);
139 // A DataModelWrapper for Wallet addresses.
140 class WalletAddressWrapper : public DataModelWrapper {
141 public:
142 explicit WalletAddressWrapper(const wallet::Address* address);
143 ~WalletAddressWrapper() override;
145 base::string16 GetInfo(const AutofillType& type) const override;
146 base::string16 GetInfoForDisplay(const AutofillType& type) const override;
147 bool GetDisplayText(base::string16* vertically_compact,
148 base::string16* horizontally_compact) override;
149 const std::string& GetLanguageCode() const override;
151 private:
152 const wallet::Address* address_;
154 DISALLOW_COPY_AND_ASSIGN(WalletAddressWrapper);
157 // A DataModelWrapper for Wallet instruments.
158 class WalletInstrumentWrapper : public DataModelWrapper {
159 public:
160 explicit WalletInstrumentWrapper(
161 const wallet::WalletItems::MaskedInstrument* instrument);
162 ~WalletInstrumentWrapper() override;
164 base::string16 GetInfo(const AutofillType& type) const override;
165 base::string16 GetInfoForDisplay(const AutofillType& type) const override;
166 gfx::Image GetIcon() override;
167 bool GetDisplayText(base::string16* vertically_compact,
168 base::string16* horizontally_compact) override;
169 const std::string& GetLanguageCode() const override;
171 private:
172 const wallet::WalletItems::MaskedInstrument* instrument_;
174 DISALLOW_COPY_AND_ASSIGN(WalletInstrumentWrapper);
177 // A DataModelWrapper for FullWallet billing data.
178 class FullWalletBillingWrapper : public DataModelWrapper {
179 public:
180 explicit FullWalletBillingWrapper(wallet::FullWallet* full_wallet);
181 ~FullWalletBillingWrapper() override;
183 base::string16 GetInfo(const AutofillType& type) const override;
184 bool GetDisplayText(base::string16* vertically_compact,
185 base::string16* horizontally_compact) override;
186 const std::string& GetLanguageCode() const override;
188 private:
189 wallet::FullWallet* full_wallet_;
191 DISALLOW_COPY_AND_ASSIGN(FullWalletBillingWrapper);
194 // A DataModelWrapper for FullWallet shipping data.
195 class FullWalletShippingWrapper : public DataModelWrapper {
196 public:
197 explicit FullWalletShippingWrapper(wallet::FullWallet* full_wallet);
198 ~FullWalletShippingWrapper() override;
200 base::string16 GetInfo(const AutofillType& type) const override;
201 const std::string& GetLanguageCode() const override;
203 private:
204 wallet::FullWallet* full_wallet_;
206 DISALLOW_COPY_AND_ASSIGN(FullWalletShippingWrapper);
209 // A DataModelWrapper for ::i18n::addressinput::AddressData objects.
210 class I18nAddressDataWrapper : public DataModelWrapper {
211 public:
212 explicit I18nAddressDataWrapper(
213 const ::i18n::addressinput::AddressData* address);
214 ~I18nAddressDataWrapper() override;
216 base::string16 GetInfo(const AutofillType& type) const override;
217 const std::string& GetLanguageCode() const override;
219 private:
220 const ::i18n::addressinput::AddressData* address_;
222 DISALLOW_COPY_AND_ASSIGN(I18nAddressDataWrapper);
225 } // namespace autofill
227 #endif // CHROME_BROWSER_UI_AUTOFILL_DATA_MODEL_WRAPPER_H_