OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef CHROME_BROWSER_UI_AUTOFILL_DATA_MODEL_WRAPPER_H_ |
| 6 #define CHROME_BROWSER_UI_AUTOFILL_DATA_MODEL_WRAPPER_H_ |
| 7 |
| 8 #include "base/compiler_specific.h" |
| 9 #include "base/string16.h" |
| 10 #include "chrome/browser/autofill/field_types.h" |
| 11 #include "chrome/browser/autofill/wallet/wallet_items.h" |
| 12 #include "chrome/browser/ui/autofill/autofill_dialog_types.h" |
| 13 |
| 14 class CreditCard; |
| 15 class FormGroup; |
| 16 class FormStructure; |
| 17 |
| 18 namespace gfx { |
| 19 class Image; |
| 20 } |
| 21 |
| 22 namespace wallet { |
| 23 class Address; |
| 24 } |
| 25 |
| 26 namespace autofill { |
| 27 |
| 28 // A glue class that allows uniform interactions with autocomplete data sources, |
| 29 // regardless of their type. Implementations are intended to be lightweight and |
| 30 // copyable, only holding weak references to their backing model. |
| 31 class DataModelWrapper { |
| 32 public: |
| 33 virtual ~DataModelWrapper(); |
| 34 |
| 35 // Returns the data for a specific autocomplete type. |
| 36 virtual string16 GetInfo(AutofillFieldType type) = 0; |
| 37 |
| 38 // Returns the icon, if any, that represents this model. |
| 39 virtual gfx::Image GetIcon() = 0; |
| 40 |
| 41 // Fills in |inputs| with the data that this model contains (|inputs| is an |
| 42 // out-param). |
| 43 virtual void FillInputs(DetailInputs* inputs) = 0; |
| 44 |
| 45 // Returns text to display to the user to summarize this data source. The |
| 46 // default implementation assumes this is an address. |
| 47 virtual string16 GetDisplayText(); |
| 48 |
| 49 // Fills in |form_structure| with the data that this model contains. |inputs| |
| 50 // and |comparator| are used to determine whether each field in the |
| 51 // FormStructure should be filled in or left alone. |
| 52 void FillFormStructure( |
| 53 const DetailInputs& inputs, |
| 54 const InputFieldComparator& compare, |
| 55 FormStructure* form_structure); |
| 56 |
| 57 protected: |
| 58 // Fills in |field| with data from the model. |
| 59 virtual void FillFormField(AutofillField* field) = 0; |
| 60 }; |
| 61 |
| 62 // A DataModelWrapper for Autofill data. |
| 63 class AutofillDataModelWrapper : public DataModelWrapper { |
| 64 public: |
| 65 AutofillDataModelWrapper(const FormGroup* form_group, size_t variant); |
| 66 virtual ~AutofillDataModelWrapper(); |
| 67 |
| 68 virtual string16 GetInfo(AutofillFieldType type) OVERRIDE; |
| 69 virtual gfx::Image GetIcon() OVERRIDE; |
| 70 virtual void FillInputs(DetailInputs* inputs) OVERRIDE; |
| 71 |
| 72 protected: |
| 73 virtual void FillFormField(AutofillField* field) OVERRIDE; |
| 74 |
| 75 private: |
| 76 const FormGroup* form_group_; |
| 77 const size_t variant_; |
| 78 }; |
| 79 |
| 80 // A DataModelWrapper specifically for Autofill CreditCard data. |
| 81 class AutofillCreditCardWrapper : public AutofillDataModelWrapper { |
| 82 public: |
| 83 explicit AutofillCreditCardWrapper(const CreditCard* card); |
| 84 virtual ~AutofillCreditCardWrapper(); |
| 85 |
| 86 virtual gfx::Image GetIcon() OVERRIDE; |
| 87 virtual string16 GetDisplayText() OVERRIDE; |
| 88 |
| 89 private: |
| 90 const CreditCard* card_; |
| 91 }; |
| 92 |
| 93 // A DataModelWrapper for Wallet addresses. |
| 94 class WalletAddressWrapper : public DataModelWrapper { |
| 95 public: |
| 96 explicit WalletAddressWrapper(const wallet::Address* address); |
| 97 virtual ~WalletAddressWrapper(); |
| 98 |
| 99 virtual string16 GetInfo(AutofillFieldType type) OVERRIDE; |
| 100 virtual gfx::Image GetIcon() OVERRIDE; |
| 101 virtual void FillInputs(DetailInputs* inputs) OVERRIDE; |
| 102 |
| 103 protected: |
| 104 virtual void FillFormField(AutofillField* field) OVERRIDE; |
| 105 |
| 106 private: |
| 107 const wallet::Address* address_; |
| 108 }; |
| 109 |
| 110 // A DataModelWrapper for Wallet instruments. |
| 111 class WalletInstrumentWrapper : public DataModelWrapper { |
| 112 public: |
| 113 explicit WalletInstrumentWrapper( |
| 114 const wallet::WalletItems::MaskedInstrument* instrument); |
| 115 virtual ~WalletInstrumentWrapper(); |
| 116 |
| 117 virtual string16 GetInfo(AutofillFieldType type) OVERRIDE; |
| 118 virtual gfx::Image GetIcon() OVERRIDE; |
| 119 virtual void FillInputs(DetailInputs* inputs) OVERRIDE; |
| 120 virtual string16 GetDisplayText() OVERRIDE; |
| 121 |
| 122 protected: |
| 123 virtual void FillFormField(AutofillField* field) OVERRIDE; |
| 124 |
| 125 private: |
| 126 const wallet::WalletItems::MaskedInstrument* instrument_; |
| 127 }; |
| 128 |
| 129 } |
| 130 |
| 131 #endif // CHROME_BROWSER_UI_AUTOFILL_DATA_MODEL_WRAPPER_H_ |
OLD | NEW |