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

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

Issue 12208070: allow wallet items to appear in requestAutocomplete UI (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: relative patchset again 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
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/utf_string_conversions.h"
8 #include "chrome/browser/autofill/autofill_country.h"
9 #include "chrome/browser/autofill/credit_card.h"
10 #include "chrome/browser/autofill/form_group.h"
11 #include "chrome/browser/autofill/form_structure.h"
12 #include "chrome/browser/autofill/wallet/wallet_address.h"
13 #include "chrome/browser/autofill/wallet/wallet_address.h"
14 #include "chrome/browser/autofill/wallet/wallet_items.h"
15 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/gfx/image/image.h"
17
18 namespace autofill {
19
20 DataModelWrapper::~DataModelWrapper() {}
21
22 string16 DataModelWrapper::GetDisplayText() {
23 string16 comma = ASCIIToUTF16(", ");
24 string16 label = GetInfo(NAME_FULL) + comma + GetInfo(ADDRESS_HOME_LINE1);
25 string16 address2 = GetInfo(ADDRESS_HOME_LINE2);
26 if (!address2.empty())
27 label += comma + address2;
28 label += ASCIIToUTF16("\n") +
29 GetInfo(ADDRESS_HOME_CITY) + comma +
30 GetInfo(ADDRESS_HOME_STATE) + ASCIIToUTF16(" ") +
31 GetInfo(ADDRESS_HOME_ZIP);
32 return label;
33 }
34
35 // AutofillDataModelWrapper
36
37 AutofillDataModelWrapper::AutofillDataModelWrapper(const FormGroup* form_group,
38 size_t variant)
39 : form_group_(form_group),
40 variant_(variant) {}
41
42 AutofillDataModelWrapper::~AutofillDataModelWrapper() {}
43
44 string16 AutofillDataModelWrapper::GetInfo(AutofillFieldType type) {
45 return form_group_->GetInfo(type, AutofillCountry::ApplicationLocale());
46 }
47
48 gfx::Image AutofillDataModelWrapper::GetIcon() {
49 return gfx::Image();
50 }
51
52 void AutofillDataModelWrapper::FillInputs(DetailInputs* inputs) {
53 // TODO(estade): use |variant_|?
54 const std::string app_locale = AutofillCountry::ApplicationLocale();
55 for (size_t j = 0; j < inputs->size(); ++j) {
56 (*inputs)[j].autofilled_value =
57 form_group_->GetInfo((*inputs)[j].type, app_locale);
58 }
59 }
60
61 void AutofillDataModelWrapper::FillFormStructure(
62 const DetailInputs& inputs,
63 const InputFieldComparator& compare,
64 FormStructure* form_structure) {
65 for (size_t i = 0; i < form_structure->field_count(); ++i) {
66 AutofillField* field = form_structure->field(i);
67 for (size_t j = 0; j < inputs.size(); ++j) {
68 if (compare.Run(inputs[j], *field)) {
69 form_group_->FillFormField(*field, variant_, field);
70 break;
71 }
72 }
73 }
74 }
75
76 // AutofillCreditCardWrapper
77
78 AutofillCreditCardWrapper::AutofillCreditCardWrapper(const CreditCard* card)
79 : AutofillDataModelWrapper(card, 0),
80 card_(card) {}
81
82 AutofillCreditCardWrapper::~AutofillCreditCardWrapper() {}
83
84 gfx::Image AutofillCreditCardWrapper::GetIcon() {
85 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
86 return rb.GetImageNamed(card_->IconResourceId());
87 }
88
89 string16 AutofillCreditCardWrapper::GetDisplayText() {
90 return card_->TypeAndLastFourDigits();
91 }
92
93 // WalletInstrumentWrapper
94
95 WalletInstrumentWrapper::WalletInstrumentWrapper(
96 const wallet::WalletItems::MaskedInstrument* instrument)
97 : instrument_(instrument) {}
98
99 WalletInstrumentWrapper::~WalletInstrumentWrapper() {}
100
101 string16 WalletInstrumentWrapper::GetInfo(AutofillFieldType type) {
102 // TODO(estade): implement.
103 return string16(ASCIIToUTF16("foo"));
104 }
105
106 gfx::Image WalletInstrumentWrapper::GetIcon() {
107 // TODO(estade): implement.
108 return gfx::Image();
109 }
110
111 void WalletInstrumentWrapper::FillInputs(DetailInputs* inputs) {
112 // TODO(estade): implement.
113 }
114
115 void WalletInstrumentWrapper::FillFormStructure(
116 const DetailInputs& inputs,
117 const InputFieldComparator& compare,
118 FormStructure* form_structure) {
119 // TODO(estade): implement.
120 }
121
122 // WalletAddressWrapper
123
124 WalletAddressWrapper::WalletAddressWrapper(
125 const wallet::Address* address) : address_(address) {}
126
127 WalletAddressWrapper::~WalletAddressWrapper() {}
128
129 string16 WalletAddressWrapper::GetInfo(AutofillFieldType type) {
130 return address_->GetInfo(type);
131 }
132
133 gfx::Image WalletAddressWrapper::GetIcon() {
134 return gfx::Image();
135 }
136
137 void WalletAddressWrapper::FillInputs(DetailInputs* inputs) {
138 for (size_t j = 0; j < inputs->size(); ++j)
Ilya Sherman 2013/02/12 22:50:34 Optional nit: I prefer always using curly braces t
Evan Stade 2013/02/13 00:11:58 me too. Done.
139 (*inputs)[j].autofilled_value = address_->GetInfo((*inputs)[j].type);
140 }
141
142 void WalletAddressWrapper::FillFormStructure(
143 const DetailInputs& inputs,
144 const InputFieldComparator& compare,
145 FormStructure* form_structure) {
146 for (size_t i = 0; i < form_structure->field_count(); ++i) {
147 AutofillField* field = form_structure->field(i);
148 for (size_t j = 0; j < inputs.size(); ++j) {
149 if (compare.Run(inputs[j], *field)) {
150 field->value = GetInfo(field->type());
151 break;
152 }
153 }
154 }
Ilya Sherman 2013/02/12 22:50:34 This implementation looks almost identical to Auto
Evan Stade 2013/02/13 00:11:58 Done.
155 }
156
157 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698