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

Side by Side Diff: chrome/browser/ui/views/payments/shipping_address_editor_view_controller.cc

Issue 2888413006: [Payment Request] Moves autofill utility function to autofill_address_util.h (Closed)
Patch Set: Addressed comment Created 3 years, 7 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
« no previous file with comments | « no previous file | components/autofill/core/browser/autofill_address_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/views/payments/shipping_address_editor_view_controll er.h" 5 #include "chrome/browser/ui/views/payments/shipping_address_editor_view_controll er.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 17 matching lines...) Expand all
28 #include "components/payments/core/payments_profile_comparator.h" 28 #include "components/payments/core/payments_profile_comparator.h"
29 #include "components/strings/grit/components_strings.h" 29 #include "components/strings/grit/components_strings.h"
30 #include "third_party/libaddressinput/messages.h" 30 #include "third_party/libaddressinput/messages.h"
31 #include "ui/base/l10n/l10n_util.h" 31 #include "ui/base/l10n/l10n_util.h"
32 #include "ui/views/controls/textfield/textfield.h" 32 #include "ui/views/controls/textfield/textfield.h"
33 33
34 namespace payments { 34 namespace payments {
35 35
36 namespace { 36 namespace {
37 37
38 // Converts a field type in string format as returned by
39 // autofill::GetAddressComponents into the appropriate autofill::ServerFieldType
40 // enum.
41 autofill::ServerFieldType GetFieldTypeFromString(const std::string& type) {
42 if (type == autofill::kFullNameField)
43 return autofill::NAME_FULL;
44 if (type == autofill::kCompanyNameField)
45 return autofill::COMPANY_NAME;
46 if (type == autofill::kAddressLineField)
47 return autofill::ADDRESS_HOME_STREET_ADDRESS;
48 if (type == autofill::kDependentLocalityField)
49 return autofill::ADDRESS_HOME_DEPENDENT_LOCALITY;
50 if (type == autofill::kCityField)
51 return autofill::ADDRESS_HOME_CITY;
52 if (type == autofill::kStateField)
53 return autofill::ADDRESS_HOME_STATE;
54 if (type == autofill::kPostalCodeField)
55 return autofill::ADDRESS_HOME_ZIP;
56 if (type == autofill::kSortingCodeField)
57 return autofill::ADDRESS_HOME_SORTING_CODE;
58 if (type == autofill::kCountryField)
59 return autofill::ADDRESS_HOME_COUNTRY;
60 NOTREACHED();
61 return autofill::UNKNOWN_TYPE;
62 }
63
64 // size_t doesn't have a defined maximum value, so this is a trick to create one 38 // size_t doesn't have a defined maximum value, so this is a trick to create one
65 // as is done for std::string::npos. 39 // as is done for std::string::npos.
66 // http://www.cplusplus.com/reference/string/string/npos 40 // http://www.cplusplus.com/reference/string/string/npos
67 const size_t kInvalidCountryIndex = static_cast<size_t>(-1); 41 const size_t kInvalidCountryIndex = static_cast<size_t>(-1);
68 42
69 } // namespace 43 } // namespace
70 44
71 ShippingAddressEditorViewController::ShippingAddressEditorViewController( 45 ShippingAddressEditorViewController::ShippingAddressEditorViewController(
72 PaymentRequestSpec* spec, 46 PaymentRequestSpec* spec,
73 PaymentRequestState* state, 47 PaymentRequestState* state,
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 if (!component->GetString(autofill::kFieldLengthKey, &field_length)) { 301 if (!component->GetString(autofill::kFieldLengthKey, &field_length)) {
328 NOTREACHED(); 302 NOTREACHED();
329 return; 303 return;
330 } 304 }
331 EditorField::LengthHint length_hint = EditorField::LengthHint::HINT_SHORT; 305 EditorField::LengthHint length_hint = EditorField::LengthHint::HINT_SHORT;
332 if (field_length == autofill::kLongField) 306 if (field_length == autofill::kLongField)
333 length_hint = EditorField::LengthHint::HINT_LONG; 307 length_hint = EditorField::LengthHint::HINT_LONG;
334 else 308 else
335 DCHECK_EQ(autofill::kShortField, field_length); 309 DCHECK_EQ(autofill::kShortField, field_length);
336 autofill::ServerFieldType server_field_type = 310 autofill::ServerFieldType server_field_type =
337 GetFieldTypeFromString(field_type); 311 autofill::GetFieldTypeFromString(field_type);
338 EditorField::ControlType control_type = 312 EditorField::ControlType control_type =
339 EditorField::ControlType::TEXTFIELD; 313 EditorField::ControlType::TEXTFIELD;
340 if (server_field_type == autofill::ADDRESS_HOME_COUNTRY || 314 if (server_field_type == autofill::ADDRESS_HOME_COUNTRY ||
341 (server_field_type == autofill::ADDRESS_HOME_STATE && 315 (server_field_type == autofill::ADDRESS_HOME_STATE &&
342 !failed_to_load_region_data_)) { 316 !failed_to_load_region_data_)) {
343 control_type = EditorField::ControlType::COMBOBOX; 317 control_type = EditorField::ControlType::COMBOBOX;
344 } 318 }
345 editor_fields_.emplace_back( 319 editor_fields_.emplace_back(
346 server_field_type, base::UTF8ToUTF16(field_name), length_hint, 320 server_field_type, base::UTF8ToUTF16(field_name), length_hint,
347 /*required=*/server_field_type != autofill::COMPANY_NAME, 321 /*required=*/server_field_type != autofill::COMPANY_NAME,
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 bool is_required_valid = !field_.required; 480 bool is_required_valid = !field_.required;
507 const base::string16 displayed_message = 481 const base::string16 displayed_message =
508 is_required_valid ? base::ASCIIToUTF16("") 482 is_required_valid ? base::ASCIIToUTF16("")
509 : l10n_util::GetStringUTF16( 483 : l10n_util::GetStringUTF16(
510 IDS_PAYMENTS_FIELD_REQUIRED_VALIDATION_MESSAGE); 484 IDS_PAYMENTS_FIELD_REQUIRED_VALIDATION_MESSAGE);
511 controller_->DisplayErrorMessageForField(field_, displayed_message); 485 controller_->DisplayErrorMessageForField(field_, displayed_message);
512 return is_required_valid; 486 return is_required_valid;
513 } 487 }
514 488
515 } // namespace payments 489 } // namespace payments
OLDNEW
« no previous file with comments | « no previous file | components/autofill/core/browser/autofill_address_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698