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

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

Issue 21724002: rAc: try really hard not to ellipsize addresses (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync'd Created 7 years, 4 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
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/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/ui/autofill/autofill_dialog_models.h" 10 #include "chrome/browser/ui/autofill/autofill_dialog_models.h"
11 #include "components/autofill/content/browser/wallet/full_wallet.h" 11 #include "components/autofill/content/browser/wallet/full_wallet.h"
12 #include "components/autofill/content/browser/wallet/wallet_address.h" 12 #include "components/autofill/content/browser/wallet/wallet_address.h"
13 #include "components/autofill/content/browser/wallet/wallet_items.h" 13 #include "components/autofill/content/browser/wallet/wallet_items.h"
14 #include "components/autofill/core/browser/autofill_data_model.h" 14 #include "components/autofill/core/browser/autofill_data_model.h"
15 #include "components/autofill/core/browser/autofill_profile.h" 15 #include "components/autofill/core/browser/autofill_profile.h"
16 #include "components/autofill/core/browser/autofill_type.h" 16 #include "components/autofill/core/browser/autofill_type.h"
17 #include "components/autofill/core/browser/credit_card.h" 17 #include "components/autofill/core/browser/credit_card.h"
18 #include "components/autofill/core/browser/form_structure.h" 18 #include "components/autofill/core/browser/form_structure.h"
19 #include "components/autofill/core/browser/validation.h" 19 #include "components/autofill/core/browser/validation.h"
20 #include "ui/base/resource/resource_bundle.h" 20 #include "ui/base/resource/resource_bundle.h"
21 #include "ui/gfx/image/image.h" 21 #include "ui/gfx/image/image.h"
22 22
23 namespace autofill { 23 namespace autofill {
24 24
25 DataModelWrapper::~DataModelWrapper() {} 25 DataModelWrapper::~DataModelWrapper() {}
26 26
27 string16 DataModelWrapper::GetDisplayText() { 27 gfx::Image DataModelWrapper::GetIcon() {
28 string16 comma = ASCIIToUTF16(", "); 28 return gfx::Image();
29 string16 label = 29 }
30 GetInfo(AutofillType(NAME_FULL)) + comma + 30
31 GetInfo(AutofillType(ADDRESS_HOME_LINE1)); 31 void DataModelWrapper::FillInputs(DetailInputs* inputs) {
32 string16 address2 = GetInfo(AutofillType(ADDRESS_HOME_LINE2)); 32 for (size_t i = 0; i < inputs->size(); ++i) {
33 if (!address2.empty()) 33 (*inputs)[i].initial_value = GetInfo(AutofillType((*inputs)[i].type));
34 label += comma + address2; 34 }
35 label += ASCIIToUTF16("\n") + 35 }
36 GetInfo(AutofillType(ADDRESS_HOME_CITY)) + comma + 36
37 GetInfo(AutofillType(ADDRESS_HOME_STATE)) + ASCIIToUTF16(" ") + 37 bool DataModelWrapper::GetDisplayText(
38 GetInfo(AutofillType(ADDRESS_HOME_ZIP)); 38 base::string16* vertically_compact,
39 return label; 39 base::string16* horizontally_compact) {
40 base::string16 comma = ASCIIToUTF16(", ");
41 base::string16 newline = ASCIIToUTF16("\n");
42
43 *vertically_compact = GetAddressDisplayText(comma);
44 *horizontally_compact = GetAddressDisplayText(newline);
45 return true;
40 } 46 }
41 47
42 bool DataModelWrapper::FillFormStructure( 48 bool DataModelWrapper::FillFormStructure(
43 const DetailInputs& inputs, 49 const DetailInputs& inputs,
44 const InputFieldComparator& compare, 50 const InputFieldComparator& compare,
45 FormStructure* form_structure) const { 51 FormStructure* form_structure) const {
46 bool filled_something = false; 52 bool filled_something = false;
47 for (size_t i = 0; i < form_structure->field_count(); ++i) { 53 for (size_t i = 0; i < form_structure->field_count(); ++i) {
48 AutofillField* field = form_structure->field(i); 54 AutofillField* field = form_structure->field(i);
49 for (size_t j = 0; j < inputs.size(); ++j) { 55 for (size_t j = 0; j < inputs.size(); ++j) {
50 if (compare.Run(inputs[j], *field)) { 56 if (compare.Run(inputs[j], *field)) {
51 FillFormField(field); 57 FillFormField(field);
52 filled_something = true; 58 filled_something = true;
53 break; 59 break;
54 } 60 }
55 } 61 }
56 } 62 }
57 return filled_something; 63 return filled_something;
58 } 64 }
59 65
60 void DataModelWrapper::FillInputs(DetailInputs* inputs) { 66 DataModelWrapper::DataModelWrapper() {}
61 for (size_t i = 0; i < inputs->size(); ++i) {
62 (*inputs)[i].initial_value = GetInfo(AutofillType((*inputs)[i].type));
63 }
64 }
65 67
66 void DataModelWrapper::FillFormField(AutofillField* field) const { 68 void DataModelWrapper::FillFormField(AutofillField* field) const {
67 field->value = GetInfo(field->Type()); 69 field->value = GetInfo(field->Type());
68 } 70 }
69 71
70 DataModelWrapper::DataModelWrapper() {} 72 base::string16 DataModelWrapper::GetAddressDisplayText(
73 const base::string16& separator) {
74 base::string16 address = GetInfo(AutofillType(NAME_FULL)) + separator +
75 GetInfo(AutofillType(ADDRESS_HOME_LINE1));
76 base::string16 address2 = GetInfo(AutofillType(ADDRESS_HOME_LINE2));
77 if (!address2.empty())
78 address += separator + address2;
71 79
72 gfx::Image DataModelWrapper::GetIcon() { 80 base::string16 comma = ASCIIToUTF16(", ");
73 return gfx::Image(); 81 base::string16 newline = ASCIIToUTF16("\n");
82 address += separator +
83 GetInfo(AutofillType(ADDRESS_HOME_CITY)) + comma +
84 GetInfo(AutofillType(ADDRESS_HOME_STATE)) + ASCIIToUTF16(" ") +
85 GetInfo(AutofillType(ADDRESS_HOME_ZIP));
86
87 // TODO(estade): email?
88 address += newline + GetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER));
89
90 return address;
74 } 91 }
75 92
76 // EmptyDataModelWrapper 93 // EmptyDataModelWrapper
77 94
78 EmptyDataModelWrapper::EmptyDataModelWrapper() {} 95 EmptyDataModelWrapper::EmptyDataModelWrapper() {}
79 EmptyDataModelWrapper::~EmptyDataModelWrapper() {} 96 EmptyDataModelWrapper::~EmptyDataModelWrapper() {}
80 97
81 string16 EmptyDataModelWrapper::GetInfo(const AutofillType& type) const { 98 base::string16 EmptyDataModelWrapper::GetInfo(const AutofillType& type) const {
82 return string16(); 99 return base::string16();
83 } 100 }
84 101
85 void EmptyDataModelWrapper::FillFormField(AutofillField* field) const {} 102 void EmptyDataModelWrapper::FillFormField(AutofillField* field) const {}
86 103
87 // AutofillDataModelWrapper 104 // AutofillDataModelWrapper
88 105
89 AutofillDataModelWrapper::AutofillDataModelWrapper( 106 AutofillDataModelWrapper::AutofillDataModelWrapper(
90 const AutofillDataModel* data_model, 107 const AutofillDataModel* data_model,
91 size_t variant) 108 size_t variant)
92 : data_model_(data_model), 109 : data_model_(data_model),
93 variant_(variant) {} 110 variant_(variant) {}
94 111
95 AutofillDataModelWrapper::~AutofillDataModelWrapper() {} 112 AutofillDataModelWrapper::~AutofillDataModelWrapper() {}
96 113
97 string16 AutofillDataModelWrapper::GetInfo(const AutofillType& type) const { 114 base::string16 AutofillDataModelWrapper::GetInfo(const AutofillType& type)
115 const {
98 return data_model_->GetInfo(type, g_browser_process->GetApplicationLocale()); 116 return data_model_->GetInfo(type, g_browser_process->GetApplicationLocale());
99 } 117 }
100 118
101 void AutofillDataModelWrapper::FillFormField(AutofillField* field) const { 119 void AutofillDataModelWrapper::FillFormField(AutofillField* field) const {
102 data_model_->FillFormField( 120 data_model_->FillFormField(
103 *field, variant_, g_browser_process->GetApplicationLocale(), field); 121 *field, variant_, g_browser_process->GetApplicationLocale(), field);
104 } 122 }
105 123
106 // AutofillProfileWrapper 124 // AutofillProfileWrapper
107 125
108 AutofillProfileWrapper::AutofillProfileWrapper( 126 AutofillProfileWrapper::AutofillProfileWrapper(
109 const AutofillProfile* profile, size_t variant) 127 const AutofillProfile* profile, size_t variant)
110 : AutofillDataModelWrapper(profile, variant), 128 : AutofillDataModelWrapper(profile, variant),
111 profile_(profile) {} 129 profile_(profile) {}
112 130
113 AutofillProfileWrapper::~AutofillProfileWrapper() {} 131 AutofillProfileWrapper::~AutofillProfileWrapper() {}
114 132
115 void AutofillProfileWrapper::FillInputs(DetailInputs* inputs) { 133 void AutofillProfileWrapper::FillInputs(DetailInputs* inputs) {
116 const std::string app_locale = g_browser_process->GetApplicationLocale(); 134 const std::string app_locale = g_browser_process->GetApplicationLocale();
117 for (size_t j = 0; j < inputs->size(); ++j) { 135 for (size_t j = 0; j < inputs->size(); ++j) {
118 std::vector<string16> values; 136 std::vector<base::string16> values;
119 profile_->GetMultiInfo( 137 profile_->GetMultiInfo(
120 AutofillType((*inputs)[j].type), app_locale, &values); 138 AutofillType((*inputs)[j].type), app_locale, &values);
121 (*inputs)[j].initial_value = values[variant()]; 139 (*inputs)[j].initial_value = values[variant()];
122 } 140 }
123 } 141 }
124 142
125 void AutofillProfileWrapper::FillFormField(AutofillField* field) const { 143 void AutofillProfileWrapper::FillFormField(AutofillField* field) const {
126 if (field->Type().GetStorableType() == CREDIT_CARD_NAME) { 144 if (field->Type().GetStorableType() == CREDIT_CARD_NAME) {
127 // Cache the field's true type. 145 // Cache the field's true type.
128 HtmlFieldType original_type = field->html_type(); 146 HtmlFieldType original_type = field->html_type();
(...skipping 12 matching lines...) Expand all
141 } 159 }
142 160
143 // AutofillCreditCardWrapper 161 // AutofillCreditCardWrapper
144 162
145 AutofillCreditCardWrapper::AutofillCreditCardWrapper(const CreditCard* card) 163 AutofillCreditCardWrapper::AutofillCreditCardWrapper(const CreditCard* card)
146 : AutofillDataModelWrapper(card, 0), 164 : AutofillDataModelWrapper(card, 0),
147 card_(card) {} 165 card_(card) {}
148 166
149 AutofillCreditCardWrapper::~AutofillCreditCardWrapper() {} 167 AutofillCreditCardWrapper::~AutofillCreditCardWrapper() {}
150 168
151 string16 AutofillCreditCardWrapper::GetInfo(const AutofillType& type) const { 169 base::string16 AutofillCreditCardWrapper::GetInfo(const AutofillType& type)
170 const {
152 if (type.GetStorableType() == CREDIT_CARD_EXP_MONTH) 171 if (type.GetStorableType() == CREDIT_CARD_EXP_MONTH)
153 return MonthComboboxModel::FormatMonth(card_->expiration_month()); 172 return MonthComboboxModel::FormatMonth(card_->expiration_month());
154 173
155 return AutofillDataModelWrapper::GetInfo(type); 174 return AutofillDataModelWrapper::GetInfo(type);
156 } 175 }
157 176
158 gfx::Image AutofillCreditCardWrapper::GetIcon() { 177 gfx::Image AutofillCreditCardWrapper::GetIcon() {
159 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 178 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
160 return rb.GetImageNamed(CreditCard::IconResourceId(card_->type())); 179 return rb.GetImageNamed(CreditCard::IconResourceId(card_->type()));
161 } 180 }
162 181
163 string16 AutofillCreditCardWrapper::GetDisplayText() { 182 bool AutofillCreditCardWrapper::GetDisplayText(
183 base::string16* vertically_compact,
184 base::string16* horizontally_compact) {
164 if (!card_->IsValid()) 185 if (!card_->IsValid())
165 return string16(); 186 return false;
166 187
167 return card_->TypeAndLastFourDigits(); 188 *vertically_compact = *horizontally_compact = card_->TypeAndLastFourDigits();
189 return true;
168 } 190 }
169 191
170 // WalletAddressWrapper 192 // WalletAddressWrapper
171 193
172 WalletAddressWrapper::WalletAddressWrapper( 194 WalletAddressWrapper::WalletAddressWrapper(
173 const wallet::Address* address) : address_(address) {} 195 const wallet::Address* address) : address_(address) {}
174 196
175 WalletAddressWrapper::~WalletAddressWrapper() {} 197 WalletAddressWrapper::~WalletAddressWrapper() {}
176 198
177 string16 WalletAddressWrapper::GetInfo(const AutofillType& type) const { 199 base::string16 WalletAddressWrapper::GetInfo(const AutofillType& type) const {
178 return address_->GetInfo(type, g_browser_process->GetApplicationLocale()); 200 return address_->GetInfo(type, g_browser_process->GetApplicationLocale());
179 } 201 }
180 202
181 string16 WalletAddressWrapper::GetDisplayText() { 203 bool WalletAddressWrapper::GetDisplayText(
204 base::string16* vertically_compact,
205 base::string16* horizontally_compact) {
182 if (!address_->is_complete_address() || 206 if (!address_->is_complete_address() ||
183 GetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER)).empty()) { 207 GetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER)).empty()) {
184 return string16(); 208 return false;
185 } 209 }
186 210
187 return DataModelWrapper::GetDisplayText(); 211 return DataModelWrapper::GetDisplayText(vertically_compact,
212 horizontally_compact);
188 } 213 }
189 214
190 // WalletInstrumentWrapper 215 // WalletInstrumentWrapper
191 216
192 WalletInstrumentWrapper::WalletInstrumentWrapper( 217 WalletInstrumentWrapper::WalletInstrumentWrapper(
193 const wallet::WalletItems::MaskedInstrument* instrument) 218 const wallet::WalletItems::MaskedInstrument* instrument)
194 : instrument_(instrument) {} 219 : instrument_(instrument) {}
195 220
196 WalletInstrumentWrapper::~WalletInstrumentWrapper() {} 221 WalletInstrumentWrapper::~WalletInstrumentWrapper() {}
197 222
198 string16 WalletInstrumentWrapper::GetInfo(const AutofillType& type) const { 223 base::string16 WalletInstrumentWrapper::GetInfo(const AutofillType& type)
224 const {
199 if (type.GetStorableType() == CREDIT_CARD_EXP_MONTH) 225 if (type.GetStorableType() == CREDIT_CARD_EXP_MONTH)
200 return MonthComboboxModel::FormatMonth(instrument_->expiration_month()); 226 return MonthComboboxModel::FormatMonth(instrument_->expiration_month());
201 227
202 return instrument_->GetInfo(type, g_browser_process->GetApplicationLocale()); 228 return instrument_->GetInfo(type, g_browser_process->GetApplicationLocale());
203 } 229 }
204 230
205 gfx::Image WalletInstrumentWrapper::GetIcon() { 231 gfx::Image WalletInstrumentWrapper::GetIcon() {
206 return instrument_->CardIcon(); 232 return instrument_->CardIcon();
207 } 233 }
208 234
209 string16 WalletInstrumentWrapper::GetDisplayText() { 235 bool WalletInstrumentWrapper::GetDisplayText(
236 base::string16* vertically_compact,
237 base::string16* horizontally_compact) {
210 // TODO(dbeam): handle other instrument statuses? http://crbug.com/233048 238 // TODO(dbeam): handle other instrument statuses? http://crbug.com/233048
211 if (instrument_->status() == wallet::WalletItems::MaskedInstrument::EXPIRED || 239 if (instrument_->status() == wallet::WalletItems::MaskedInstrument::EXPIRED ||
212 !instrument_->address().is_complete_address() || 240 !instrument_->address().is_complete_address() ||
213 GetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER)).empty()) { 241 GetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER)).empty()) {
214 return string16(); 242 return false;
215 } 243 }
216 244
245 DataModelWrapper::GetDisplayText(vertically_compact, horizontally_compact);
217 // TODO(estade): descriptive_name() is user-provided. Should we use it or 246 // TODO(estade): descriptive_name() is user-provided. Should we use it or
218 // just type + last 4 digits? 247 // just type + last 4 digits?
219 string16 line1 = instrument_->descriptive_name(); 248 base::string16 line1 = instrument_->descriptive_name() + ASCIIToUTF16("\n");
220 return line1 + ASCIIToUTF16("\n") + DataModelWrapper::GetDisplayText(); 249 *vertically_compact = line1 + *vertically_compact;
250 *horizontally_compact = line1 + *horizontally_compact;
251 return true;
221 } 252 }
222 253
223 // FullWalletBillingWrapper 254 // FullWalletBillingWrapper
224 255
225 FullWalletBillingWrapper::FullWalletBillingWrapper( 256 FullWalletBillingWrapper::FullWalletBillingWrapper(
226 wallet::FullWallet* full_wallet) 257 wallet::FullWallet* full_wallet)
227 : full_wallet_(full_wallet) { 258 : full_wallet_(full_wallet) {
228 DCHECK(full_wallet_); 259 DCHECK(full_wallet_);
229 } 260 }
230 261
231 FullWalletBillingWrapper::~FullWalletBillingWrapper() {} 262 FullWalletBillingWrapper::~FullWalletBillingWrapper() {}
232 263
233 string16 FullWalletBillingWrapper::GetInfo(const AutofillType& type) const { 264 base::string16 FullWalletBillingWrapper::GetInfo(const AutofillType& type)
265 const {
234 if (type.GetStorableType() == CREDIT_CARD_EXP_MONTH) 266 if (type.GetStorableType() == CREDIT_CARD_EXP_MONTH)
235 return MonthComboboxModel::FormatMonth(full_wallet_->expiration_month()); 267 return MonthComboboxModel::FormatMonth(full_wallet_->expiration_month());
236 268
237 if (type.group() == CREDIT_CARD) 269 if (type.group() == CREDIT_CARD)
238 return full_wallet_->GetInfo(type); 270 return full_wallet_->GetInfo(type);
239 271
240 return full_wallet_->billing_address()->GetInfo( 272 return full_wallet_->billing_address()->GetInfo(
241 type, g_browser_process->GetApplicationLocale()); 273 type, g_browser_process->GetApplicationLocale());
242 } 274 }
243 275
244 string16 FullWalletBillingWrapper::GetDisplayText() { 276 bool FullWalletBillingWrapper::GetDisplayText(
277 base::string16* vertically_compact,
278 base::string16* horizontally_compact) {
245 // TODO(dbeam): handle other required actions? http://crbug.com/163508 279 // TODO(dbeam): handle other required actions? http://crbug.com/163508
246 if (full_wallet_->HasRequiredAction(wallet::UPDATE_EXPIRATION_DATE)) 280 if (full_wallet_->HasRequiredAction(wallet::UPDATE_EXPIRATION_DATE))
247 return string16(); 281 return false;
248 282
249 return DataModelWrapper::GetDisplayText(); 283 return DataModelWrapper::GetDisplayText(vertically_compact,
284 horizontally_compact);
250 } 285 }
251 286
252 // FullWalletShippingWrapper 287 // FullWalletShippingWrapper
253 288
254 FullWalletShippingWrapper::FullWalletShippingWrapper( 289 FullWalletShippingWrapper::FullWalletShippingWrapper(
255 wallet::FullWallet* full_wallet) 290 wallet::FullWallet* full_wallet)
256 : full_wallet_(full_wallet) { 291 : full_wallet_(full_wallet) {
257 DCHECK(full_wallet_); 292 DCHECK(full_wallet_);
258 } 293 }
259 294
260 FullWalletShippingWrapper::~FullWalletShippingWrapper() {} 295 FullWalletShippingWrapper::~FullWalletShippingWrapper() {}
261 296
262 string16 FullWalletShippingWrapper::GetInfo(const AutofillType& type) const { 297 base::string16 FullWalletShippingWrapper::GetInfo(
298 const AutofillType& type) const {
263 return full_wallet_->shipping_address()->GetInfo( 299 return full_wallet_->shipping_address()->GetInfo(
264 type, g_browser_process->GetApplicationLocale()); 300 type, g_browser_process->GetApplicationLocale());
265 } 301 }
266 302
267 DetailOutputWrapper::DetailOutputWrapper(const DetailOutputMap& outputs) 303 DetailOutputWrapper::DetailOutputWrapper(const DetailOutputMap& outputs)
268 : outputs_(outputs) {} 304 : outputs_(outputs) {}
269 305
270 DetailOutputWrapper::~DetailOutputWrapper() {} 306 DetailOutputWrapper::~DetailOutputWrapper() {}
271 307
272 base::string16 DetailOutputWrapper::GetInfo(const AutofillType& type) const { 308 base::string16 DetailOutputWrapper::GetInfo(const AutofillType& type) const {
273 ServerFieldType storable_type = type.GetStorableType(); 309 ServerFieldType storable_type = type.GetStorableType();
274 for (DetailOutputMap::const_iterator it = outputs_.begin(); 310 for (DetailOutputMap::const_iterator it = outputs_.begin();
275 it != outputs_.end(); ++it) { 311 it != outputs_.end(); ++it) {
276 if (storable_type == AutofillType(it->first->type).GetStorableType()) 312 if (storable_type == AutofillType(it->first->type).GetStorableType())
277 return it->second; 313 return it->second;
278 } 314 }
279 return base::string16(); 315 return base::string16();
280 } 316 }
281 317
282 } // namespace autofill 318 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/autofill/data_model_wrapper.h ('k') | chrome/browser/ui/autofill/data_model_wrapper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698