| 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/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 1231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1242 error_bubble_.reset(); | 1242 error_bubble_.reset(); |
| 1243 } | 1243 } |
| 1244 | 1244 |
| 1245 void AutofillDialogViews::OnDidChangeFocus( | 1245 void AutofillDialogViews::OnDidChangeFocus( |
| 1246 views::View* focused_before, | 1246 views::View* focused_before, |
| 1247 views::View* focused_now) { | 1247 views::View* focused_now) { |
| 1248 // If user leaves an edit-field, revalidate the group it belongs to. | 1248 // If user leaves an edit-field, revalidate the group it belongs to. |
| 1249 if (focused_before) { | 1249 if (focused_before) { |
| 1250 DetailsGroup* group = GroupForView(focused_before); | 1250 DetailsGroup* group = GroupForView(focused_before); |
| 1251 if (group && group->container->visible()) | 1251 if (group && group->container->visible()) |
| 1252 ValidateGroup(*group, AutofillDialogController::VALIDATE_EDIT); | 1252 ValidateGroup(*group, VALIDATE_EDIT); |
| 1253 } | 1253 } |
| 1254 | 1254 |
| 1255 // Show an error bubble when the user focuses the input. | 1255 // Show an error bubble when the user focuses the input. |
| 1256 if (focused_now) | 1256 if (focused_now) |
| 1257 ShowErrorBubbleForViewIfNecessary(focused_now); | 1257 ShowErrorBubbleForViewIfNecessary(focused_now); |
| 1258 } | 1258 } |
| 1259 | 1259 |
| 1260 void AutofillDialogViews::LinkClicked(views::Link* source, int event_flags) { | 1260 void AutofillDialogViews::LinkClicked(views::Link* source, int event_flags) { |
| 1261 // Edit links. | 1261 // Edit links. |
| 1262 for (DetailGroupMap::iterator iter = detail_groups_.begin(); | 1262 for (DetailGroupMap::iterator iter = detail_groups_.begin(); |
| 1263 iter != detail_groups_.end(); ++iter) { | 1263 iter != detail_groups_.end(); ++iter) { |
| 1264 if (iter->second.suggested_info->Contains(source)) { | 1264 if (iter->second.suggested_info->Contains(source)) { |
| 1265 controller_->EditClickedForSection(iter->first); | 1265 controller_->EditClickedForSection(iter->first); |
| 1266 return; | 1266 return; |
| 1267 } | 1267 } |
| 1268 } | 1268 } |
| 1269 } | 1269 } |
| 1270 | 1270 |
| 1271 void AutofillDialogViews::OnSelectedIndexChanged(views::Combobox* combobox) { | 1271 void AutofillDialogViews::OnSelectedIndexChanged(views::Combobox* combobox) { |
| 1272 DetailsGroup* group = GroupForView(combobox); | 1272 DetailsGroup* group = GroupForView(combobox); |
| 1273 ValidateGroup(*group, AutofillDialogController::VALIDATE_EDIT); | 1273 ValidateGroup(*group, VALIDATE_EDIT); |
| 1274 } | 1274 } |
| 1275 | 1275 |
| 1276 void AutofillDialogViews::StyledLabelLinkClicked(const ui::Range& range, | 1276 void AutofillDialogViews::StyledLabelLinkClicked(const ui::Range& range, |
| 1277 int event_flags) { | 1277 int event_flags) { |
| 1278 controller_->LegalDocumentLinkClicked(range); | 1278 controller_->LegalDocumentLinkClicked(range); |
| 1279 } | 1279 } |
| 1280 | 1280 |
| 1281 void AutofillDialogViews::InitChildViews() { | 1281 void AutofillDialogViews::InitChildViews() { |
| 1282 button_strip_extra_view_ = new ButtonStripView(); | 1282 button_strip_extra_view_ = new ButtonStripView(); |
| 1283 button_strip_extra_view_->SetLayoutManager( | 1283 button_strip_extra_view_->SetLayoutManager( |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1557 | 1557 |
| 1558 const bool has_menu = !!controller_->MenuModelForSection(group.section); | 1558 const bool has_menu = !!controller_->MenuModelForSection(group.section); |
| 1559 | 1559 |
| 1560 if (group.suggested_button) | 1560 if (group.suggested_button) |
| 1561 group.suggested_button->SetVisible(has_menu); | 1561 group.suggested_button->SetVisible(has_menu); |
| 1562 | 1562 |
| 1563 if (group.container) { | 1563 if (group.container) { |
| 1564 group.container->SetForwardMouseEvents(has_menu && show_suggestions); | 1564 group.container->SetForwardMouseEvents(has_menu && show_suggestions); |
| 1565 group.container->SetVisible(controller_->SectionIsActive(group.section)); | 1565 group.container->SetVisible(controller_->SectionIsActive(group.section)); |
| 1566 if (group.container->visible()) | 1566 if (group.container->visible()) |
| 1567 ValidateGroup(group, AutofillDialogController::VALIDATE_EDIT); | 1567 ValidateGroup(group, VALIDATE_SUGGESTION); |
| 1568 } | 1568 } |
| 1569 | 1569 |
| 1570 ContentsPreferredSizeChanged(); | 1570 ContentsPreferredSizeChanged(); |
| 1571 } | 1571 } |
| 1572 | 1572 |
| 1573 template<class T> | 1573 template<class T> |
| 1574 void AutofillDialogViews::SetValidityForInput( | 1574 void AutofillDialogViews::SetValidityForInput( |
| 1575 T* input, | 1575 T* input, |
| 1576 const string16& message) { | 1576 const string16& message) { |
| 1577 bool invalid = !message.empty(); | 1577 bool invalid = !message.empty(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1600 | 1600 |
| 1601 if (error_bubble_ && error_bubble_->anchor() == input) | 1601 if (error_bubble_ && error_bubble_->anchor() == input) |
| 1602 return; | 1602 return; |
| 1603 | 1603 |
| 1604 std::map<views::View*, string16>::iterator error_message = | 1604 std::map<views::View*, string16>::iterator error_message = |
| 1605 validity_map_.find(input); | 1605 validity_map_.find(input); |
| 1606 if (error_message != validity_map_.end()) | 1606 if (error_message != validity_map_.end()) |
| 1607 error_bubble_.reset(new ErrorBubble(input, error_message->second)); | 1607 error_bubble_.reset(new ErrorBubble(input, error_message->second)); |
| 1608 } | 1608 } |
| 1609 | 1609 |
| 1610 bool AutofillDialogViews::ValidateGroup( | 1610 bool AutofillDialogViews::ValidateGroup(const DetailsGroup& group, |
| 1611 const DetailsGroup& group, | 1611 ValidationType validation_type) { |
| 1612 AutofillDialogController::ValidationType validation_type) { | |
| 1613 DCHECK(group.container->visible()); | 1612 DCHECK(group.container->visible()); |
| 1614 | 1613 |
| 1615 scoped_ptr<DetailInput> cvc_input; | 1614 scoped_ptr<DetailInput> cvc_input; |
| 1616 DetailOutputMap detail_outputs; | 1615 DetailOutputMap detail_outputs; |
| 1617 typedef std::map<AutofillFieldType, base::Callback<void(const string16&)> > | 1616 typedef std::map<AutofillFieldType, base::Callback<void(const string16&)> > |
| 1618 FieldMap; | 1617 FieldMap; |
| 1619 FieldMap field_map; | 1618 FieldMap field_map; |
| 1620 | 1619 |
| 1621 if (group.manual_input->visible()) { | 1620 if (group.manual_input->visible()) { |
| 1622 for (TextfieldMap::const_iterator iter = group.textfields.begin(); | 1621 for (TextfieldMap::const_iterator iter = group.textfields.begin(); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1676 } | 1675 } |
| 1677 | 1676 |
| 1678 bool AutofillDialogViews::ValidateForm() { | 1677 bool AutofillDialogViews::ValidateForm() { |
| 1679 bool all_valid = true; | 1678 bool all_valid = true; |
| 1680 for (DetailGroupMap::iterator iter = detail_groups_.begin(); | 1679 for (DetailGroupMap::iterator iter = detail_groups_.begin(); |
| 1681 iter != detail_groups_.end(); ++iter) { | 1680 iter != detail_groups_.end(); ++iter) { |
| 1682 const DetailsGroup& group = iter->second; | 1681 const DetailsGroup& group = iter->second; |
| 1683 if (!group.container->visible()) | 1682 if (!group.container->visible()) |
| 1684 continue; | 1683 continue; |
| 1685 | 1684 |
| 1686 if (!ValidateGroup(group, AutofillDialogController::VALIDATE_FINAL)) | 1685 if (!ValidateGroup(group, VALIDATE_FINAL)) |
| 1687 all_valid = false; | 1686 all_valid = false; |
| 1688 } | 1687 } |
| 1689 | 1688 |
| 1690 return all_valid; | 1689 return all_valid; |
| 1691 } | 1690 } |
| 1692 | 1691 |
| 1693 void AutofillDialogViews::TextfieldEditedOrActivated( | 1692 void AutofillDialogViews::TextfieldEditedOrActivated( |
| 1694 views::Textfield* textfield, | 1693 views::Textfield* textfield, |
| 1695 bool was_edit) { | 1694 bool was_edit) { |
| 1696 DetailsGroup* group = GroupForView(textfield); | 1695 DetailsGroup* group = GroupForView(textfield); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1730 // correcting a minor mistake (i.e. a wrong CC digit) should immediately | 1729 // correcting a minor mistake (i.e. a wrong CC digit) should immediately |
| 1731 // result in validation - positive user feedback. | 1730 // result in validation - positive user feedback. |
| 1732 if (decorated->invalid() && was_edit) { | 1731 if (decorated->invalid() && was_edit) { |
| 1733 SetValidityForInput<DecoratedTextfield>( | 1732 SetValidityForInput<DecoratedTextfield>( |
| 1734 decorated, | 1733 decorated, |
| 1735 controller_->InputValidityMessage(type, textfield->text())); | 1734 controller_->InputValidityMessage(type, textfield->text())); |
| 1736 | 1735 |
| 1737 // If the field transitioned from invalid to valid, re-validate the group, | 1736 // If the field transitioned from invalid to valid, re-validate the group, |
| 1738 // since inter-field checks become meaningful with valid fields. | 1737 // since inter-field checks become meaningful with valid fields. |
| 1739 if (!decorated->invalid()) | 1738 if (!decorated->invalid()) |
| 1740 ValidateGroup(*group, AutofillDialogController::VALIDATE_EDIT); | 1739 ValidateGroup(*group, VALIDATE_EDIT); |
| 1741 } | 1740 } |
| 1742 | 1741 |
| 1743 gfx::Image icon = controller_->IconForField(type, textfield->text()); | 1742 gfx::Image icon = controller_->IconForField(type, textfield->text()); |
| 1744 textfield->SetIcon(icon.AsImageSkia()); | 1743 textfield->SetIcon(icon.AsImageSkia()); |
| 1745 } | 1744 } |
| 1746 | 1745 |
| 1747 void AutofillDialogViews::UpdateSaveInChromeCheckbox() { | 1746 void AutofillDialogViews::UpdateSaveInChromeCheckbox() { |
| 1748 save_in_chrome_checkbox_->SetVisible( | 1747 save_in_chrome_checkbox_->SetVisible( |
| 1749 controller_->ShouldOfferToSaveInChrome()); | 1748 controller_->ShouldOfferToSaveInChrome()); |
| 1750 } | 1749 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1826 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section) | 1825 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section) |
| 1827 : section(section), | 1826 : section(section), |
| 1828 container(NULL), | 1827 container(NULL), |
| 1829 manual_input(NULL), | 1828 manual_input(NULL), |
| 1830 suggested_info(NULL), | 1829 suggested_info(NULL), |
| 1831 suggested_button(NULL) {} | 1830 suggested_button(NULL) {} |
| 1832 | 1831 |
| 1833 AutofillDialogViews::DetailsGroup::~DetailsGroup() {} | 1832 AutofillDialogViews::DetailsGroup::~DetailsGroup() {} |
| 1834 | 1833 |
| 1835 } // namespace autofill | 1834 } // namespace autofill |
| OLD | NEW |