| OLD | NEW |
| 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/views/autofill/autofill_dialog_views.h" | 5 #include "chrome/browser/ui/views/autofill/autofill_dialog_views.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 1325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1336 } | 1336 } |
| 1337 | 1337 |
| 1338 UpdateSectionImpl(section, false); | 1338 UpdateSectionImpl(section, false); |
| 1339 } | 1339 } |
| 1340 | 1340 |
| 1341 void AutofillDialogViews::GetUserInput(DialogSection section, | 1341 void AutofillDialogViews::GetUserInput(DialogSection section, |
| 1342 FieldValueMap* output) { | 1342 FieldValueMap* output) { |
| 1343 DetailsGroup* group = GroupForSection(section); | 1343 DetailsGroup* group = GroupForSection(section); |
| 1344 for (TextfieldMap::const_iterator it = group->textfields.begin(); | 1344 for (TextfieldMap::const_iterator it = group->textfields.begin(); |
| 1345 it != group->textfields.end(); ++it) { | 1345 it != group->textfields.end(); ++it) { |
| 1346 output->insert(std::make_pair(it->first, it->second->text())); | 1346 output->insert(std::make_pair(it->first, it->second->GetText())); |
| 1347 } | 1347 } |
| 1348 for (ComboboxMap::const_iterator it = group->comboboxes.begin(); | 1348 for (ComboboxMap::const_iterator it = group->comboboxes.begin(); |
| 1349 it != group->comboboxes.end(); ++it) { | 1349 it != group->comboboxes.end(); ++it) { |
| 1350 output->insert(std::make_pair(it->first, | 1350 output->insert(std::make_pair(it->first, |
| 1351 it->second->model()->GetItemAt(it->second->selected_index()))); | 1351 it->second->model()->GetItemAt(it->second->selected_index()))); |
| 1352 } | 1352 } |
| 1353 } | 1353 } |
| 1354 | 1354 |
| 1355 base::string16 AutofillDialogViews::GetCvc() { | 1355 base::string16 AutofillDialogViews::GetCvc() { |
| 1356 return GroupForSection(GetCreditCardSection())->suggested_info-> | 1356 return GroupForSection(GetCreditCardSection())->suggested_info-> |
| 1357 decorated_textfield()->text(); | 1357 decorated_textfield()->GetText(); |
| 1358 } | 1358 } |
| 1359 | 1359 |
| 1360 bool AutofillDialogViews::HitTestInput(const DetailInput& input, | 1360 bool AutofillDialogViews::HitTestInput(const DetailInput& input, |
| 1361 const gfx::Point& screen_point) { | 1361 const gfx::Point& screen_point) { |
| 1362 views::View* view = TextfieldForType(input.type); | 1362 views::View* view = TextfieldForType(input.type); |
| 1363 if (!view) | 1363 if (!view) |
| 1364 view = ComboboxForType(input.type); | 1364 view = ComboboxForType(input.type); |
| 1365 | 1365 |
| 1366 if (view) { | 1366 if (view) { |
| 1367 gfx::Point target_point(screen_point); | 1367 gfx::Point target_point(screen_point); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1439 } | 1439 } |
| 1440 | 1440 |
| 1441 void AutofillDialogViews::CancelForTesting() { | 1441 void AutofillDialogViews::CancelForTesting() { |
| 1442 GetDialogClientView()->CancelWindow(); | 1442 GetDialogClientView()->CancelWindow(); |
| 1443 } | 1443 } |
| 1444 | 1444 |
| 1445 base::string16 AutofillDialogViews::GetTextContentsOfInput( | 1445 base::string16 AutofillDialogViews::GetTextContentsOfInput( |
| 1446 const DetailInput& input) { | 1446 const DetailInput& input) { |
| 1447 views::Textfield* textfield = TextfieldForType(input.type); | 1447 views::Textfield* textfield = TextfieldForType(input.type); |
| 1448 if (textfield) | 1448 if (textfield) |
| 1449 return textfield->text(); | 1449 return textfield->GetText(); |
| 1450 | 1450 |
| 1451 views::Combobox* combobox = ComboboxForType(input.type); | 1451 views::Combobox* combobox = ComboboxForType(input.type); |
| 1452 if (combobox) | 1452 if (combobox) |
| 1453 return combobox->model()->GetItemAt(combobox->selected_index()); | 1453 return combobox->model()->GetItemAt(combobox->selected_index()); |
| 1454 | 1454 |
| 1455 NOTREACHED(); | 1455 NOTREACHED(); |
| 1456 return base::string16(); | 1456 return base::string16(); |
| 1457 } | 1457 } |
| 1458 | 1458 |
| 1459 void AutofillDialogViews::SetTextContentsOfInput( | 1459 void AutofillDialogViews::SetTextContentsOfInput( |
| (...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2050 delegate_->RequestedFieldsForSection(section); | 2050 delegate_->RequestedFieldsForSection(section); |
| 2051 DetailsGroup* group = GroupForSection(section); | 2051 DetailsGroup* group = GroupForSection(section); |
| 2052 | 2052 |
| 2053 for (DetailInputs::const_iterator iter = updated_inputs.begin(); | 2053 for (DetailInputs::const_iterator iter = updated_inputs.begin(); |
| 2054 iter != updated_inputs.end(); ++iter) { | 2054 iter != updated_inputs.end(); ++iter) { |
| 2055 const DetailInput& input = *iter; | 2055 const DetailInput& input = *iter; |
| 2056 TextfieldMap::iterator text_mapping = group->textfields.find(input.type); | 2056 TextfieldMap::iterator text_mapping = group->textfields.find(input.type); |
| 2057 | 2057 |
| 2058 if (text_mapping != group->textfields.end()) { | 2058 if (text_mapping != group->textfields.end()) { |
| 2059 DecoratedTextfield* decorated = text_mapping->second; | 2059 DecoratedTextfield* decorated = text_mapping->second; |
| 2060 if (decorated->text().empty() || clobber_inputs) | 2060 if (decorated->GetText().empty() || clobber_inputs) |
| 2061 decorated->SetText(input.initial_value); | 2061 decorated->SetText(input.initial_value); |
| 2062 } | 2062 } |
| 2063 | 2063 |
| 2064 ComboboxMap::iterator combo_mapping = group->comboboxes.find(input.type); | 2064 ComboboxMap::iterator combo_mapping = group->comboboxes.find(input.type); |
| 2065 if (combo_mapping != group->comboboxes.end()) { | 2065 if (combo_mapping != group->comboboxes.end()) { |
| 2066 views::Combobox* combobox = combo_mapping->second; | 2066 views::Combobox* combobox = combo_mapping->second; |
| 2067 if (combobox->selected_index() == combobox->model()->GetDefaultIndex() || | 2067 if (combobox->selected_index() == combobox->model()->GetDefaultIndex() || |
| 2068 clobber_inputs) { | 2068 clobber_inputs) { |
| 2069 SelectComboboxValueOrSetToDefault(combobox, input.initial_value); | 2069 SelectComboboxValueOrSetToDefault(combobox, input.initial_value); |
| 2070 } | 2070 } |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2208 DCHECK(group.container->visible()); | 2208 DCHECK(group.container->visible()); |
| 2209 | 2209 |
| 2210 FieldValueMap detail_outputs; | 2210 FieldValueMap detail_outputs; |
| 2211 | 2211 |
| 2212 if (group.manual_input->visible()) { | 2212 if (group.manual_input->visible()) { |
| 2213 for (TextfieldMap::const_iterator iter = group.textfields.begin(); | 2213 for (TextfieldMap::const_iterator iter = group.textfields.begin(); |
| 2214 iter != group.textfields.end(); ++iter) { | 2214 iter != group.textfields.end(); ++iter) { |
| 2215 if (!iter->second->editable()) | 2215 if (!iter->second->editable()) |
| 2216 continue; | 2216 continue; |
| 2217 | 2217 |
| 2218 detail_outputs[iter->first] = iter->second->text(); | 2218 detail_outputs[iter->first] = iter->second->GetText(); |
| 2219 } | 2219 } |
| 2220 for (ComboboxMap::const_iterator iter = group.comboboxes.begin(); | 2220 for (ComboboxMap::const_iterator iter = group.comboboxes.begin(); |
| 2221 iter != group.comboboxes.end(); ++iter) { | 2221 iter != group.comboboxes.end(); ++iter) { |
| 2222 if (!iter->second->enabled()) | 2222 if (!iter->second->enabled()) |
| 2223 continue; | 2223 continue; |
| 2224 | 2224 |
| 2225 views::Combobox* combobox = iter->second; | 2225 views::Combobox* combobox = iter->second; |
| 2226 base::string16 item = | 2226 base::string16 item = |
| 2227 combobox->model()->GetItemAt(combobox->selected_index()); | 2227 combobox->model()->GetItemAt(combobox->selected_index()); |
| 2228 detail_outputs[iter->first] = item; | 2228 detail_outputs[iter->first] = item; |
| 2229 } | 2229 } |
| 2230 } else if (group.section == GetCreditCardSection()) { | 2230 } else if (group.section == GetCreditCardSection()) { |
| 2231 DecoratedTextfield* decorated_cvc = | 2231 DecoratedTextfield* decorated_cvc = |
| 2232 group.suggested_info->decorated_textfield(); | 2232 group.suggested_info->decorated_textfield(); |
| 2233 if (decorated_cvc->visible()) | 2233 if (decorated_cvc->visible()) |
| 2234 detail_outputs[CREDIT_CARD_VERIFICATION_CODE] = decorated_cvc->text(); | 2234 detail_outputs[CREDIT_CARD_VERIFICATION_CODE] = decorated_cvc->GetText(); |
| 2235 } | 2235 } |
| 2236 | 2236 |
| 2237 ValidityMessages validity = delegate_->InputsAreValid(group.section, | 2237 ValidityMessages validity = delegate_->InputsAreValid(group.section, |
| 2238 detail_outputs); | 2238 detail_outputs); |
| 2239 MarkInputsInvalid(group.section, validity, validation_type == VALIDATE_FINAL); | 2239 MarkInputsInvalid(group.section, validity, validation_type == VALIDATE_FINAL); |
| 2240 | 2240 |
| 2241 // If there are any validation errors, sure or unsure, the group is invalid. | 2241 // If there are any validation errors, sure or unsure, the group is invalid. |
| 2242 return !validity.HasErrors(); | 2242 return !validity.HasErrors(); |
| 2243 } | 2243 } |
| 2244 | 2244 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 2272 // Look for the input in the manual inputs. | 2272 // Look for the input in the manual inputs. |
| 2273 for (TextfieldMap::const_iterator iter = group->textfields.begin(); | 2273 for (TextfieldMap::const_iterator iter = group->textfields.begin(); |
| 2274 iter != group->textfields.end(); | 2274 iter != group->textfields.end(); |
| 2275 ++iter) { | 2275 ++iter) { |
| 2276 decorated = iter->second; | 2276 decorated = iter->second; |
| 2277 if (decorated == textfield) { | 2277 if (decorated == textfield) { |
| 2278 delegate_->UserEditedOrActivatedInput(group->section, | 2278 delegate_->UserEditedOrActivatedInput(group->section, |
| 2279 iter->first, | 2279 iter->first, |
| 2280 GetWidget()->GetNativeView(), | 2280 GetWidget()->GetNativeView(), |
| 2281 textfield->GetBoundsInScreen(), | 2281 textfield->GetBoundsInScreen(), |
| 2282 textfield->text(), | 2282 textfield->GetText(), |
| 2283 was_edit); | 2283 was_edit); |
| 2284 type = iter->first; | 2284 type = iter->first; |
| 2285 break; | 2285 break; |
| 2286 } | 2286 } |
| 2287 } | 2287 } |
| 2288 | 2288 |
| 2289 if (textfield == group->suggested_info->decorated_textfield()) { | 2289 if (textfield == group->suggested_info->decorated_textfield()) { |
| 2290 decorated = group->suggested_info->decorated_textfield(); | 2290 decorated = group->suggested_info->decorated_textfield(); |
| 2291 type = CREDIT_CARD_VERIFICATION_CODE; | 2291 type = CREDIT_CARD_VERIFICATION_CODE; |
| 2292 } | 2292 } |
| 2293 DCHECK_NE(UNKNOWN_TYPE, type); | 2293 DCHECK_NE(UNKNOWN_TYPE, type); |
| 2294 | 2294 |
| 2295 // If the field is marked as invalid, check if the text is now valid. | 2295 // If the field is marked as invalid, check if the text is now valid. |
| 2296 // Many fields (i.e. CC#) are invalid for most of the duration of editing, | 2296 // Many fields (i.e. CC#) are invalid for most of the duration of editing, |
| 2297 // so flagging them as invalid prematurely is not helpful. However, | 2297 // so flagging them as invalid prematurely is not helpful. However, |
| 2298 // correcting a minor mistake (i.e. a wrong CC digit) should immediately | 2298 // correcting a minor mistake (i.e. a wrong CC digit) should immediately |
| 2299 // result in validation - positive user feedback. | 2299 // result in validation - positive user feedback. |
| 2300 if (decorated->invalid() && was_edit) { | 2300 if (decorated->invalid() && was_edit) { |
| 2301 SetValidityForInput( | 2301 SetValidityForInput( |
| 2302 decorated, | 2302 decorated, |
| 2303 delegate_->InputValidityMessage(group->section, type, | 2303 delegate_->InputValidityMessage(group->section, type, |
| 2304 textfield->text())); | 2304 textfield->GetText())); |
| 2305 | 2305 |
| 2306 // If the field transitioned from invalid to valid, re-validate the group, | 2306 // If the field transitioned from invalid to valid, re-validate the group, |
| 2307 // since inter-field checks become meaningful with valid fields. | 2307 // since inter-field checks become meaningful with valid fields. |
| 2308 if (!decorated->invalid()) | 2308 if (!decorated->invalid()) |
| 2309 ValidateGroup(*group, VALIDATE_EDIT); | 2309 ValidateGroup(*group, VALIDATE_EDIT); |
| 2310 } | 2310 } |
| 2311 | 2311 |
| 2312 if (delegate_->FieldControlsIcons(type)) | 2312 if (delegate_->FieldControlsIcons(type)) |
| 2313 SetIconsForSection(group->section); | 2313 SetIconsForSection(group->section); |
| 2314 | 2314 |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2448 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section) | 2448 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section) |
| 2449 : section(section), | 2449 : section(section), |
| 2450 container(NULL), | 2450 container(NULL), |
| 2451 manual_input(NULL), | 2451 manual_input(NULL), |
| 2452 suggested_info(NULL), | 2452 suggested_info(NULL), |
| 2453 suggested_button(NULL) {} | 2453 suggested_button(NULL) {} |
| 2454 | 2454 |
| 2455 AutofillDialogViews::DetailsGroup::~DetailsGroup() {} | 2455 AutofillDialogViews::DetailsGroup::~DetailsGroup() {} |
| 2456 | 2456 |
| 2457 } // namespace autofill | 2457 } // namespace autofill |
| OLD | NEW |