Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(692)

Side by Side Diff: chrome/browser/ui/autofill/data_model_wrapper.cc

Issue 12263023: git add data_model_wrapper.* again (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/autofill/data_model_wrapper.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 #include "chrome/browser/ui/autofill/data_model_wrapper.h"
6
7 #include "base/callback.h"
8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/autofill/autofill_country.h"
10 #include "chrome/browser/autofill/credit_card.h"
11 #include "chrome/browser/autofill/form_group.h"
12 #include "chrome/browser/autofill/form_structure.h"
13 #include "chrome/browser/autofill/wallet/wallet_address.h"
14 #include "chrome/browser/autofill/wallet/wallet_address.h"
15 #include "chrome/browser/autofill/wallet/wallet_items.h"
16 #include "ui/base/resource/resource_bundle.h"
17 #include "ui/gfx/image/image.h"
18
19 namespace autofill {
20
21 DataModelWrapper::~DataModelWrapper() {}
22
23 string16 DataModelWrapper::GetDisplayText() {
24 string16 comma = ASCIIToUTF16(", ");
25 string16 label = GetInfo(NAME_FULL) + comma + GetInfo(ADDRESS_HOME_LINE1);
26 string16 address2 = GetInfo(ADDRESS_HOME_LINE2);
27 if (!address2.empty())
28 label += comma + address2;
29 label += ASCIIToUTF16("\n") +
30 GetInfo(ADDRESS_HOME_CITY) + comma +
31 GetInfo(ADDRESS_HOME_STATE) + ASCIIToUTF16(" ") +
32 GetInfo(ADDRESS_HOME_ZIP);
33 return label;
34 }
35
36 void DataModelWrapper::FillFormStructure(
37 const DetailInputs& inputs,
38 const InputFieldComparator& compare,
39 FormStructure* form_structure) {
40 for (size_t i = 0; i < form_structure->field_count(); ++i) {
41 AutofillField* field = form_structure->field(i);
42 for (size_t j = 0; j < inputs.size(); ++j) {
43 if (compare.Run(inputs[j], *field)) {
44 FillFormField(field);
45 break;
46 }
47 }
48 }
49 }
50
51 // AutofillDataModelWrapper
52
53 AutofillDataModelWrapper::AutofillDataModelWrapper(const FormGroup* form_group,
54 size_t variant)
55 : form_group_(form_group),
56 variant_(variant) {}
57
58 AutofillDataModelWrapper::~AutofillDataModelWrapper() {}
59
60 string16 AutofillDataModelWrapper::GetInfo(AutofillFieldType type) {
61 return form_group_->GetInfo(type, AutofillCountry::ApplicationLocale());
62 }
63
64 gfx::Image AutofillDataModelWrapper::GetIcon() {
65 return gfx::Image();
66 }
67
68 void AutofillDataModelWrapper::FillInputs(DetailInputs* inputs) {
69 // TODO(estade): use |variant_|?
70 const std::string app_locale = AutofillCountry::ApplicationLocale();
71 for (size_t j = 0; j < inputs->size(); ++j) {
72 (*inputs)[j].autofilled_value =
73 form_group_->GetInfo((*inputs)[j].type, app_locale);
74 }
75 }
76
77 void AutofillDataModelWrapper::FillFormField(AutofillField* field) {
78 form_group_->FillFormField(*field, variant_, field);
79 }
80
81 // AutofillCreditCardWrapper
82
83 AutofillCreditCardWrapper::AutofillCreditCardWrapper(const CreditCard* card)
84 : AutofillDataModelWrapper(card, 0),
85 card_(card) {}
86
87 AutofillCreditCardWrapper::~AutofillCreditCardWrapper() {}
88
89 gfx::Image AutofillCreditCardWrapper::GetIcon() {
90 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
91 return rb.GetImageNamed(card_->IconResourceId());
92 }
93
94 string16 AutofillCreditCardWrapper::GetDisplayText() {
95 return card_->TypeAndLastFourDigits();
96 }
97
98 // WalletAddressWrapper
99
100 WalletAddressWrapper::WalletAddressWrapper(
101 const wallet::Address* address) : address_(address) {}
102
103 WalletAddressWrapper::~WalletAddressWrapper() {}
104
105 string16 WalletAddressWrapper::GetInfo(AutofillFieldType type) {
106 return address_->GetInfo(type);
107 }
108
109 gfx::Image WalletAddressWrapper::GetIcon() {
110 return gfx::Image();
111 }
112
113 void WalletAddressWrapper::FillInputs(DetailInputs* inputs) {
114 for (size_t j = 0; j < inputs->size(); ++j) {
115 (*inputs)[j].autofilled_value = address_->GetInfo((*inputs)[j].type);
116 }
117 }
118
119 void WalletAddressWrapper::FillFormField(AutofillField* field) {
120 field->value = GetInfo(field->type());
121 }
122
123 // WalletInstrumentWrapper
124
125 WalletInstrumentWrapper::WalletInstrumentWrapper(
126 const wallet::WalletItems::MaskedInstrument* instrument)
127 : instrument_(instrument) {}
128
129 WalletInstrumentWrapper::~WalletInstrumentWrapper() {}
130
131 string16 WalletInstrumentWrapper::GetInfo(AutofillFieldType type) {
132 // TODO(estade): implement.
133 return string16(ASCIIToUTF16("foo"));
134 }
135
136 gfx::Image WalletInstrumentWrapper::GetIcon() {
137 // TODO(estade): implement.
138 return gfx::Image();
139 }
140
141 void WalletInstrumentWrapper::FillInputs(DetailInputs* inputs) {
142 // TODO(estade): implement.
143 }
144
145 string16 WalletInstrumentWrapper::GetDisplayText() {
146 // TODO(estade): implement better.
147 return UTF8ToUTF16(instrument_->descriptive_name());
148 }
149
150 void WalletInstrumentWrapper::FillFormField(AutofillField* field) {
151 field->value = GetInfo(field->type());
152 }
153
154 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/autofill/data_model_wrapper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698