Chromium Code Reviews| 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 #include "chrome/browser/ui/autofill/data_model_wrapper.h" | 5 #include "chrome/browser/ui/autofill/data_model_wrapper.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "components/autofill/browser/autofill_country.h" | 9 #include "components/autofill/browser/autofill_country.h" |
| 10 #include "components/autofill/browser/autofill_profile.h" | 10 #include "components/autofill/browser/autofill_profile.h" |
| 11 #include "components/autofill/browser/credit_card.h" | 11 #include "components/autofill/browser/credit_card.h" |
| 12 #include "components/autofill/browser/form_group.h" | 12 #include "components/autofill/browser/form_group.h" |
| 13 #include "components/autofill/browser/form_structure.h" | 13 #include "components/autofill/browser/form_structure.h" |
| 14 #include "components/autofill/browser/wallet/wallet_address.h" | 14 #include "components/autofill/browser/wallet/full_wallet.h" |
| 15 #include "components/autofill/browser/wallet/wallet_address.h" | 15 #include "components/autofill/browser/wallet/wallet_address.h" |
| 16 #include "components/autofill/browser/wallet/wallet_items.h" | 16 #include "components/autofill/browser/wallet/wallet_items.h" |
| 17 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
| 18 #include "ui/gfx/image/image.h" | 18 #include "ui/gfx/image/image.h" |
| 19 | 19 |
| 20 namespace autofill { | 20 namespace autofill { |
| 21 | 21 |
| 22 DataModelWrapper::~DataModelWrapper() {} | 22 DataModelWrapper::~DataModelWrapper() {} |
| 23 | 23 |
| 24 string16 DataModelWrapper::GetDisplayText() { | 24 string16 DataModelWrapper::GetDisplayText() { |
| 25 string16 comma = ASCIIToUTF16(", "); | 25 string16 comma = ASCIIToUTF16(", "); |
| 26 string16 label = GetInfo(NAME_FULL) + comma + GetInfo(ADDRESS_HOME_LINE1); | 26 string16 label = GetInfo(NAME_FULL) + comma + GetInfo(ADDRESS_HOME_LINE1); |
| 27 string16 address2 = GetInfo(ADDRESS_HOME_LINE2); | 27 string16 address2 = GetInfo(ADDRESS_HOME_LINE2); |
| 28 if (!address2.empty()) | 28 if (!address2.empty()) |
| 29 label += comma + address2; | 29 label += comma + address2; |
| 30 label += ASCIIToUTF16("\n") + | 30 label += ASCIIToUTF16("\n") + |
| 31 GetInfo(ADDRESS_HOME_CITY) + comma + | 31 GetInfo(ADDRESS_HOME_CITY) + comma + |
| 32 GetInfo(ADDRESS_HOME_STATE) + ASCIIToUTF16(" ") + | 32 GetInfo(ADDRESS_HOME_STATE) + ASCIIToUTF16(" ") + |
| 33 GetInfo(ADDRESS_HOME_ZIP); | 33 GetInfo(ADDRESS_HOME_ZIP); |
| 34 return label; | 34 return label; |
| 35 } | 35 } |
| 36 | 36 |
| 37 void DataModelWrapper::FillFormStructure( | 37 void DataModelWrapper::FillFormStructure( |
| 38 const DetailInputs& inputs, | 38 const DetailInputs& inputs, |
| 39 const InputFieldComparator& compare, | 39 const InputFieldComparator& compare, |
| 40 FormStructure* form_structure) { | 40 FormStructure* form_structure) { |
|
Dan Beam
2013/03/13 01:43:57
or this would need to take a section so FullWallet
| |
| 41 for (size_t i = 0; i < form_structure->field_count(); ++i) { | 41 for (size_t i = 0; i < form_structure->field_count(); ++i) { |
| 42 AutofillField* field = form_structure->field(i); | 42 AutofillField* field = form_structure->field(i); |
| 43 for (size_t j = 0; j < inputs.size(); ++j) { | 43 for (size_t j = 0; j < inputs.size(); ++j) { |
| 44 if (compare.Run(inputs[j], *field)) { | 44 if (compare.Run(inputs[j], *field)) { |
| 45 FillFormField(field); | 45 FillFormField(field); |
| 46 break; | 46 break; |
| 47 } | 47 } |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 } | 50 } |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 | 163 |
| 164 string16 WalletInstrumentWrapper::GetInfo(AutofillFieldType type) { | 164 string16 WalletInstrumentWrapper::GetInfo(AutofillFieldType type) { |
| 165 return instrument_->address().GetInfo(type); | 165 return instrument_->address().GetInfo(type); |
| 166 } | 166 } |
| 167 | 167 |
| 168 gfx::Image WalletInstrumentWrapper::GetIcon() { | 168 gfx::Image WalletInstrumentWrapper::GetIcon() { |
| 169 return instrument_->CardIcon(); | 169 return instrument_->CardIcon(); |
| 170 } | 170 } |
| 171 | 171 |
| 172 void WalletInstrumentWrapper::FillInputs(DetailInputs* inputs) { | 172 void WalletInstrumentWrapper::FillInputs(DetailInputs* inputs) { |
| 173 // TODO(estade): implement. | 173 NOTREACHED(); // Use FullWalletWrapper to fill inputs. |
| 174 } | 174 } |
| 175 | 175 |
| 176 string16 WalletInstrumentWrapper::GetDisplayText() { | 176 string16 WalletInstrumentWrapper::GetDisplayText() { |
| 177 // TODO(estade): descriptive_name() is user-provided. Should we use it or | 177 // TODO(estade): descriptive_name() is user-provided. Should we use it or |
| 178 // just type + last 4 digits? | 178 // just type + last 4 digits? |
| 179 string16 line1 = instrument_->descriptive_name(); | 179 string16 line1 = instrument_->descriptive_name(); |
| 180 return line1 + ASCIIToUTF16("\n") + DataModelWrapper::GetDisplayText(); | 180 return line1 + ASCIIToUTF16("\n") + DataModelWrapper::GetDisplayText(); |
| 181 } | 181 } |
| 182 | 182 |
| 183 void WalletInstrumentWrapper::FillFormField(AutofillField* field) { | 183 void WalletInstrumentWrapper::FillFormField(AutofillField* field) { |
| 184 field->value = GetInfo(field->type()); | 184 field->value = GetInfo(field->type()); |
| 185 } | 185 } |
| 186 | 186 |
| 187 // FullWalletWrapper | |
| 188 /* | |
| 189 FullWalletWrapper::FullWalletWrapper(const wallet::FullWallet* full_wallet) | |
| 190 : full_wallet_(full_wallet) { | |
| 191 DCHECK(full_wallet_); | |
| 192 } | |
| 193 | |
| 194 FullWalletWrapper::~FullWalletWrapper() {} | |
| 195 | |
| 196 string16 FullWalletWrapper::GetInfo(AutofillFieldType type) { | |
| 197 return full_wallet_->GetInfo(type, false); | |
| 198 } | |
| 199 | |
| 200 gfx::Image FullWalletWrapper::GetIcon() { | |
| 201 // TODO(dbeam): this could be implemented if necessary, I just don't see where | |
| 202 // we'd ever need it -- this wrapper is only used to fill values into | |
| 203 // |AutofillDialogControllerImlp::form_structure_| at the moment. | |
| 204 return gfx::Image(); | |
| 205 } | |
| 206 | |
| 207 void FullWalletWrapper::FillInputs(DetailInputs* inputs) { | |
| 208 // This class shouldn't be used to fill view inputs. | |
| 209 NOTREACHED(); | |
| 210 } | |
| 211 | |
| 212 void FullWalletWrapper::FillFormField(AutofillField* field) { | |
| 213 field->value = GetInfo(field->type()); | |
| 214 } | |
| 215 */ | |
| 187 } // namespace autofill | 216 } // namespace autofill |
| OLD | NEW |