OLD | NEW |
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/contact_info_editor_view_controller.h
" | 5 #include "chrome/browser/ui/views/payments/contact_info_editor_view_controller.h
" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/ui/views/payments/validating_textfield.h" | 10 #include "chrome/browser/ui/views/payments/validating_textfield.h" |
9 #include "components/autofill/core/browser/autofill_country.h" | 11 #include "components/autofill/core/browser/autofill_country.h" |
10 #include "components/autofill/core/browser/autofill_profile.h" | 12 #include "components/autofill/core/browser/autofill_profile.h" |
11 #include "components/autofill/core/browser/autofill_type.h" | 13 #include "components/autofill/core/browser/autofill_type.h" |
12 #include "components/autofill/core/browser/personal_data_manager.h" | 14 #include "components/autofill/core/browser/personal_data_manager.h" |
13 #include "components/autofill/core/browser/validation.h" | 15 #include "components/autofill/core/browser/validation.h" |
14 #include "components/autofill/core/common/autofill_constants.h" | 16 #include "components/autofill/core/common/autofill_constants.h" |
15 #include "components/payments/content/payment_request_spec.h" | 17 #include "components/payments/content/payment_request_spec.h" |
16 #include "components/payments/content/payment_request_state.h" | 18 #include "components/payments/content/payment_request_state.h" |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 ContactInfoEditorViewController::ContactInfoValidationDelegate:: | 145 ContactInfoEditorViewController::ContactInfoValidationDelegate:: |
144 ContactInfoValidationDelegate(const EditorField& field, | 146 ContactInfoValidationDelegate(const EditorField& field, |
145 const std::string& locale, | 147 const std::string& locale, |
146 EditorViewController* controller) | 148 EditorViewController* controller) |
147 : field_(field), controller_(controller), locale_(locale) {} | 149 : field_(field), controller_(controller), locale_(locale) {} |
148 | 150 |
149 ContactInfoEditorViewController::ContactInfoValidationDelegate:: | 151 ContactInfoEditorViewController::ContactInfoValidationDelegate:: |
150 ~ContactInfoValidationDelegate() {} | 152 ~ContactInfoValidationDelegate() {} |
151 | 153 |
152 bool ContactInfoEditorViewController::ContactInfoValidationDelegate:: | 154 bool ContactInfoEditorViewController::ContactInfoValidationDelegate:: |
153 ValidateTextfield(views::Textfield* textfield) { | 155 IsValidTextfield(views::Textfield* textfield) { |
| 156 return ValidateTextfield(textfield, nullptr); |
| 157 } |
| 158 |
| 159 bool ContactInfoEditorViewController::ContactInfoValidationDelegate:: |
| 160 TextfieldValueChanged(views::Textfield* textfield) { |
| 161 base::string16 error_message; |
| 162 bool is_valid = ValidateTextfield(textfield, &error_message); |
| 163 controller_->DisplayErrorMessageForField(field_, error_message); |
| 164 return is_valid; |
| 165 } |
| 166 |
| 167 bool ContactInfoEditorViewController::ContactInfoValidationDelegate:: |
| 168 ValidateTextfield(views::Textfield* textfield, |
| 169 base::string16* error_message) { |
154 bool is_valid = true; | 170 bool is_valid = true; |
155 base::string16 error_message; | |
156 | 171 |
157 if (textfield->text().empty()) { | 172 if (textfield->text().empty()) { |
158 is_valid = false; | 173 is_valid = false; |
159 error_message = l10n_util::GetStringUTF16( | 174 if (error_message) { |
160 IDS_PAYMENTS_FIELD_REQUIRED_VALIDATION_MESSAGE); | 175 *error_message = l10n_util::GetStringUTF16( |
| 176 IDS_PAYMENTS_FIELD_REQUIRED_VALIDATION_MESSAGE); |
| 177 } |
161 } else { | 178 } else { |
162 switch (field_.type) { | 179 switch (field_.type) { |
163 case autofill::PHONE_HOME_WHOLE_NUMBER: { | 180 case autofill::PHONE_HOME_WHOLE_NUMBER: { |
164 const std::string default_region_code = | 181 const std::string default_region_code = |
165 autofill::AutofillCountry::CountryCodeForLocale(locale_); | 182 autofill::AutofillCountry::CountryCodeForLocale(locale_); |
166 if (!autofill::IsValidPhoneNumber(textfield->text(), | 183 if (!autofill::IsValidPhoneNumber(textfield->text(), |
167 default_region_code)) { | 184 default_region_code)) { |
168 is_valid = false; | 185 is_valid = false; |
169 error_message = l10n_util::GetStringUTF16( | 186 if (error_message) { |
170 IDS_PAYMENTS_PHONE_INVALID_VALIDATION_MESSAGE); | 187 *error_message = l10n_util::GetStringUTF16( |
| 188 IDS_PAYMENTS_PHONE_INVALID_VALIDATION_MESSAGE); |
| 189 } |
171 } | 190 } |
172 break; | 191 break; |
173 } | 192 } |
174 | 193 |
175 case autofill::EMAIL_ADDRESS: { | 194 case autofill::EMAIL_ADDRESS: { |
176 if (!autofill::IsValidEmailAddress(textfield->text())) { | 195 if (!autofill::IsValidEmailAddress(textfield->text())) { |
177 is_valid = false; | 196 is_valid = false; |
178 error_message = l10n_util::GetStringUTF16( | 197 if (error_message) { |
179 IDS_PAYMENTS_EMAIL_INVALID_VALIDATION_MESSAGE); | 198 *error_message = l10n_util::GetStringUTF16( |
| 199 IDS_PAYMENTS_EMAIL_INVALID_VALIDATION_MESSAGE); |
| 200 } |
180 } | 201 } |
181 break; | 202 break; |
182 } | 203 } |
183 | 204 |
184 case autofill::NAME_FULL: { | 205 case autofill::NAME_FULL: { |
185 // We have already determined that name is nonempty, which is the only | 206 // We have already determined that name is nonempty, which is the only |
186 // requirement. | 207 // requirement. |
187 break; | 208 break; |
188 } | 209 } |
189 | 210 |
190 default: { | 211 default: { |
191 NOTREACHED(); | 212 NOTREACHED(); |
192 break; | 213 break; |
193 } | 214 } |
194 } | 215 } |
195 } | 216 } |
196 | 217 |
197 controller_->DisplayErrorMessageForField(field_, error_message); | |
198 return is_valid; | 218 return is_valid; |
199 } | 219 } |
200 | 220 |
201 bool ContactInfoEditorViewController::ContactInfoValidationDelegate:: | 221 bool ContactInfoEditorViewController::ContactInfoValidationDelegate:: |
202 ValidateCombobox(views::Combobox* combobox) { | 222 IsValidCombobox(views::Combobox* combobox) { |
203 // This UI doesn't contain any comboboxes. | 223 // This UI doesn't contain any comboboxes. |
204 NOTREACHED(); | 224 NOTREACHED(); |
205 return true; | 225 return true; |
| 226 } |
| 227 |
| 228 bool ContactInfoEditorViewController::ContactInfoValidationDelegate:: |
| 229 ComboboxValueChanged(views::Combobox* combobox) { |
| 230 // This UI doesn't contain any comboboxes. |
| 231 NOTREACHED(); |
| 232 return true; |
206 } | 233 } |
207 | 234 |
208 } // namespace payments | 235 } // namespace payments |
OLD | NEW |