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" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h" | 12 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h" |
13 #include "chrome/browser/ui/views/constrained_window_views.h" | 13 #include "chrome/browser/ui/views/constrained_window_views.h" |
14 #include "chrome/browser/ui/web_contents_modal_dialog_manager.h" | 14 #include "chrome/browser/ui/web_contents_modal_dialog_manager.h" |
15 #include "components/autofill/browser/wallet/wallet_service_url.h" | 15 #include "components/autofill/browser/wallet/wallet_service_url.h" |
16 #include "content/public/browser/native_web_keyboard_event.h" | 16 #include "content/public/browser/native_web_keyboard_event.h" |
17 #include "content/public/browser/navigation_controller.h" | 17 #include "content/public/browser/navigation_controller.h" |
18 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
19 #include "content/public/browser/web_contents_view.h" | 19 #include "content/public/browser/web_contents_view.h" |
20 #include "grit/theme_resources.h" | 20 #include "grit/theme_resources.h" |
21 #include "grit/ui_resources.h" | 21 #include "grit/ui_resources.h" |
22 #include "third_party/skia/include/core/SkColor.h" | 22 #include "third_party/skia/include/core/SkColor.h" |
23 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
24 #include "ui/base/models/combobox_model.h" | 24 #include "ui/base/models/combobox_model.h" |
| 25 #include "ui/base/models/menu_model.h" |
25 #include "ui/base/resource/resource_bundle.h" | 26 #include "ui/base/resource/resource_bundle.h" |
26 #include "ui/gfx/canvas.h" | 27 #include "ui/gfx/canvas.h" |
27 #include "ui/views/background.h" | 28 #include "ui/views/background.h" |
28 #include "ui/views/border.h" | 29 #include "ui/views/border.h" |
29 #include "ui/views/controls/button/checkbox.h" | 30 #include "ui/views/controls/button/checkbox.h" |
30 #include "ui/views/controls/button/image_button.h" | 31 #include "ui/views/controls/button/image_button.h" |
31 #include "ui/views/controls/combobox/combobox.h" | 32 #include "ui/views/controls/combobox/combobox.h" |
32 #include "ui/views/controls/image_view.h" | 33 #include "ui/views/controls/image_view.h" |
33 #include "ui/views/controls/label.h" | 34 #include "ui/views/controls/label.h" |
34 #include "ui/views/controls/link.h" | 35 #include "ui/views/controls/link.h" |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 0); | 345 0); |
345 | 346 |
346 layout->StartRow(0, kColumnSetId); | 347 layout->StartRow(0, kColumnSetId); |
347 layout->AddView(CreateDetailsSectionLabel(label)); | 348 layout->AddView(CreateDetailsSectionLabel(label)); |
348 layout->AddView(controls); | 349 layout->AddView(controls); |
349 } | 350 } |
350 | 351 |
351 AutofillDialogViews::SectionContainer::~SectionContainer() {} | 352 AutofillDialogViews::SectionContainer::~SectionContainer() {} |
352 | 353 |
353 void AutofillDialogViews::SectionContainer::SetActive(bool active) { | 354 void AutofillDialogViews::SectionContainer::SetActive(bool active) { |
354 if (active == !!background()) | 355 bool is_active = active && proxy_button_->visible(); |
| 356 if (is_active == !!background()) |
355 return; | 357 return; |
356 | 358 |
357 set_background(active ? | 359 set_background(is_active ? |
358 views::Background::CreateSolidBackground(SkColorSetARGB(9, 0, 0, 0)): | 360 views::Background::CreateSolidBackground(SkColorSetARGB(9, 0, 0, 0)): |
359 NULL); | 361 NULL); |
360 SchedulePaint(); | 362 SchedulePaint(); |
361 } | 363 } |
362 | 364 |
363 void AutofillDialogViews::SectionContainer::SetForwardMouseEvents( | 365 void AutofillDialogViews::SectionContainer::SetForwardMouseEvents( |
364 bool forward) { | 366 bool forward) { |
365 forward_mouse_events_ = forward; | 367 forward_mouse_events_ = forward; |
366 if (!forward) | 368 if (!forward) |
367 set_background(NULL); | 369 set_background(NULL); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 // AutofilDialogViews::SuggestionView ------------------------------------------ | 424 // AutofilDialogViews::SuggestionView ------------------------------------------ |
423 | 425 |
424 AutofillDialogViews::SuggestionView::SuggestionView( | 426 AutofillDialogViews::SuggestionView::SuggestionView( |
425 const string16& edit_label, | 427 const string16& edit_label, |
426 AutofillDialogViews* autofill_dialog) | 428 AutofillDialogViews* autofill_dialog) |
427 : label_(new views::Label()), | 429 : label_(new views::Label()), |
428 label_line_2_(new views::Label()), | 430 label_line_2_(new views::Label()), |
429 icon_(new views::ImageView()), | 431 icon_(new views::ImageView()), |
430 label_container_(new views::View()), | 432 label_container_(new views::View()), |
431 decorated_( | 433 decorated_( |
432 new DecoratedTextfield(string16(), string16(), autofill_dialog)) { | 434 new DecoratedTextfield(string16(), string16(), autofill_dialog)), |
| 435 edit_link_(new views::Link(edit_label)) { |
433 // Label and icon. | 436 // Label and icon. |
434 label_container_->SetLayoutManager( | 437 label_container_->SetLayoutManager( |
435 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, | 438 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, |
436 kAroundTextPadding)); | 439 kAroundTextPadding)); |
437 label_container_->AddChildView(icon_); | 440 label_container_->AddChildView(icon_); |
438 label_container_->AddChildView(label_); | 441 label_container_->AddChildView(label_); |
439 label_container_->AddChildView(decorated_); | 442 label_container_->AddChildView(decorated_); |
440 decorated_->SetVisible(false); | 443 decorated_->SetVisible(false); |
441 // TODO(estade): get the sizing and spacing right on this textfield. | 444 // TODO(estade): get the sizing and spacing right on this textfield. |
442 decorated_->textfield()->set_default_width_in_chars(10); | 445 decorated_->textfield()->set_default_width_in_chars(10); |
443 AddChildView(label_container_); | 446 AddChildView(label_container_); |
444 | 447 |
445 label_line_2_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 448 label_line_2_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
446 label_line_2_->SetVisible(false); | 449 label_line_2_->SetVisible(false); |
447 AddChildView(label_line_2_); | 450 AddChildView(label_line_2_); |
448 | 451 |
449 // TODO(estade): The link needs to have a different color when hovered. | 452 // TODO(estade): The link needs to have a different color when hovered. |
450 views::Link* edit_link = new views::Link(edit_label); | 453 edit_link_->set_listener(autofill_dialog); |
451 edit_link->set_listener(autofill_dialog); | 454 edit_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
452 edit_link->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 455 edit_link_->SetUnderline(false); |
453 edit_link->SetUnderline(false); | |
454 | 456 |
455 // This container prevents the edit link from being horizontally stretched. | 457 // This container prevents the edit link from being horizontally stretched. |
456 views::View* link_container = new views::View(); | 458 views::View* link_container = new views::View(); |
457 link_container->SetLayoutManager( | 459 link_container->SetLayoutManager( |
458 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); | 460 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); |
459 link_container->AddChildView(edit_link); | 461 link_container->AddChildView(edit_link_); |
460 AddChildView(link_container); | 462 AddChildView(link_container); |
461 | 463 |
462 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 464 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
463 } | 465 } |
464 | 466 |
465 AutofillDialogViews::SuggestionView::~SuggestionView() {} | 467 AutofillDialogViews::SuggestionView::~SuggestionView() {} |
466 | 468 |
| 469 void AutofillDialogViews::SuggestionView::SetEditable(bool editable) { |
| 470 edit_link_->SetVisible(editable); |
| 471 } |
| 472 |
467 void AutofillDialogViews::SuggestionView::SetSuggestionText( | 473 void AutofillDialogViews::SuggestionView::SetSuggestionText( |
468 const string16& text) { | 474 const string16& text) { |
469 // TODO(estade): does this localize well? | 475 // TODO(estade): does this localize well? |
470 string16 line_return(ASCIIToUTF16("\n")); | 476 string16 line_return(ASCIIToUTF16("\n")); |
471 size_t position = text.find(line_return); | 477 size_t position = text.find(line_return); |
472 if (position == string16::npos) { | 478 if (position == string16::npos) { |
473 label_->SetText(text); | 479 label_->SetText(text); |
474 label_line_2_->SetVisible(false); | 480 label_line_2_->SetVisible(false); |
475 } else { | 481 } else { |
476 label_->SetText(text.substr(0, position)); | 482 label_->SetText(text.substr(0, position)); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 output->insert(std::make_pair(it->first, it->second->textfield()->text())); | 646 output->insert(std::make_pair(it->first, it->second->textfield()->text())); |
641 } | 647 } |
642 for (ComboboxMap::const_iterator it = group->comboboxes.begin(); | 648 for (ComboboxMap::const_iterator it = group->comboboxes.begin(); |
643 it != group->comboboxes.end(); ++it) { | 649 it != group->comboboxes.end(); ++it) { |
644 output->insert(std::make_pair(it->first, | 650 output->insert(std::make_pair(it->first, |
645 it->second->model()->GetItemAt(it->second->selected_index()))); | 651 it->second->model()->GetItemAt(it->second->selected_index()))); |
646 } | 652 } |
647 } | 653 } |
648 | 654 |
649 string16 AutofillDialogViews::GetCvc() { | 655 string16 AutofillDialogViews::GetCvc() { |
650 return GroupForSection(SECTION_CC)->suggested_info->decorated_textfield()-> | 656 DialogSection billing_section = controller_->SectionIsActive(SECTION_CC) ? |
651 textfield()->text(); | 657 SECTION_CC : SECTION_CC_BILLING; |
| 658 return GroupForSection(billing_section)->suggested_info-> |
| 659 decorated_textfield()->textfield()->text(); |
652 } | 660 } |
653 | 661 |
654 bool AutofillDialogViews::UseBillingForShipping() { | 662 bool AutofillDialogViews::UseBillingForShipping() { |
655 return use_billing_for_shipping_->checked(); | 663 return use_billing_for_shipping_->checked(); |
656 } | 664 } |
657 | 665 |
658 bool AutofillDialogViews::SaveDetailsInWallet() { | 666 bool AutofillDialogViews::SaveDetailsInWallet() { |
659 return notification_area_->CheckboxIsChecked(); | 667 return notification_area_->CheckboxIsChecked(); |
660 } | 668 } |
661 | 669 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 footnote_view_ = new views::StyledLabel(string16(), this); | 764 footnote_view_ = new views::StyledLabel(string16(), this); |
757 return footnote_view_; | 765 return footnote_view_; |
758 } | 766 } |
759 | 767 |
760 bool AutofillDialogViews::Cancel() { | 768 bool AutofillDialogViews::Cancel() { |
761 controller_->OnCancel(); | 769 controller_->OnCancel(); |
762 return true; | 770 return true; |
763 } | 771 } |
764 | 772 |
765 bool AutofillDialogViews::Accept() { | 773 bool AutofillDialogViews::Accept() { |
766 if (!ValidateForm()) | 774 if (ValidateForm()) |
767 return false; | 775 controller_->OnAccept(); |
768 | 776 |
769 controller_->OnSubmit(); | 777 // |controller_| decides when to hide the dialog. |
770 | |
771 // Let |controller_| decide when to hide the dialog. | |
772 return false; | 778 return false; |
773 } | 779 } |
774 | 780 |
775 // TODO(wittman): Remove this override once we move to the new style frame view | 781 // TODO(wittman): Remove this override once we move to the new style frame view |
776 // on all dialogs. | 782 // on all dialogs. |
777 views::NonClientFrameView* AutofillDialogViews::CreateNonClientFrameView( | 783 views::NonClientFrameView* AutofillDialogViews::CreateNonClientFrameView( |
778 views::Widget* widget) { | 784 views::Widget* widget) { |
779 return CreateConstrainedStyleNonClientFrameView( | 785 return CreateConstrainedStyleNonClientFrameView( |
780 widget, | 786 widget, |
781 controller_->web_contents()->GetBrowserContext()); | 787 controller_->web_contents()->GetBrowserContext()); |
(...skipping 10 matching lines...) Expand all Loading... |
792 DetailsGroup* group = NULL; | 798 DetailsGroup* group = NULL; |
793 for (DetailGroupMap::iterator iter = detail_groups_.begin(); | 799 for (DetailGroupMap::iterator iter = detail_groups_.begin(); |
794 iter != detail_groups_.end(); ++iter) { | 800 iter != detail_groups_.end(); ++iter) { |
795 if (sender == iter->second.suggested_button) { | 801 if (sender == iter->second.suggested_button) { |
796 group = &iter->second; | 802 group = &iter->second; |
797 break; | 803 break; |
798 } | 804 } |
799 } | 805 } |
800 DCHECK(group); | 806 DCHECK(group); |
801 | 807 |
| 808 if (!group->suggested_button->visible()) |
| 809 return; |
| 810 |
802 menu_runner_.reset(new views::MenuRunner( | 811 menu_runner_.reset(new views::MenuRunner( |
803 controller_->MenuModelForSection(group->section))); | 812 controller_->MenuModelForSection(group->section))); |
804 | 813 |
805 group->container->SetActive(true); | 814 group->container->SetActive(true); |
806 // Ignore the result since we don't need to handle a deleted menu specially. | 815 // Ignore the result since we don't need to handle a deleted menu specially. |
807 ignore_result( | 816 ignore_result( |
808 menu_runner_->RunMenuAt(sender->GetWidget(), | 817 menu_runner_->RunMenuAt(sender->GetWidget(), |
809 NULL, | 818 NULL, |
810 group->suggested_button->GetBoundsInScreen(), | 819 group->suggested_button->GetBoundsInScreen(), |
811 views::MenuItemView::TOPRIGHT, | 820 views::MenuItemView::TOPRIGHT, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
844 } | 853 } |
845 | 854 |
846 void AutofillDialogViews::OnDidChangeFocus( | 855 void AutofillDialogViews::OnDidChangeFocus( |
847 views::View* focused_before, | 856 views::View* focused_before, |
848 views::View* focused_now) { | 857 views::View* focused_now) { |
849 if (!focused_before) | 858 if (!focused_before) |
850 return; | 859 return; |
851 | 860 |
852 // If user leaves an edit-field, revalidate the group it belongs to. | 861 // If user leaves an edit-field, revalidate the group it belongs to. |
853 DetailsGroup* group = GroupForView(focused_before); | 862 DetailsGroup* group = GroupForView(focused_before); |
854 if (group) | 863 if (group && group->container->visible()) |
855 ValidateGroup(group, AutofillDialogController::VALIDATE_EDIT); | 864 ValidateGroup(group, AutofillDialogController::VALIDATE_EDIT); |
856 } | 865 } |
857 | 866 |
858 void AutofillDialogViews::LinkClicked(views::Link* source, int event_flags) { | 867 void AutofillDialogViews::LinkClicked(views::Link* source, int event_flags) { |
859 // Edit links. | 868 // Edit links. |
860 for (DetailGroupMap::iterator iter = detail_groups_.begin(); | 869 for (DetailGroupMap::iterator iter = detail_groups_.begin(); |
861 iter != detail_groups_.end(); ++iter) { | 870 iter != detail_groups_.end(); ++iter) { |
862 if (iter->second.suggested_info->Contains(source)) { | 871 if (iter->second.suggested_info->Contains(source)) { |
863 controller_->EditClickedForSection(iter->first); | 872 controller_->EditClickedForSection(iter->first); |
864 return; | 873 return; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
981 0); | 990 0); |
982 column_set->AddColumn(views::GridLayout::CENTER, | 991 column_set->AddColumn(views::GridLayout::CENTER, |
983 views::GridLayout::LEADING, | 992 views::GridLayout::LEADING, |
984 0, | 993 0, |
985 views::GridLayout::USE_PREF, | 994 views::GridLayout::USE_PREF, |
986 0, | 995 0, |
987 0); | 996 0); |
988 layout->StartRow(0, kColumnSetId); | 997 layout->StartRow(0, kColumnSetId); |
989 | 998 |
990 // The |info_view| holds |manual_inputs| and |suggested_info|, allowing the | 999 // The |info_view| holds |manual_inputs| and |suggested_info|, allowing the |
991 // dialog toggle which is shown. | 1000 // dialog to toggle which is shown. |
992 views::View* info_view = new views::View(); | 1001 views::View* info_view = new views::View(); |
993 info_view->SetLayoutManager( | 1002 info_view->SetLayoutManager( |
994 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 1003 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
995 | 1004 |
996 if (section == SECTION_SHIPPING) { | 1005 if (section == SECTION_SHIPPING) { |
997 use_billing_for_shipping_ = | 1006 use_billing_for_shipping_ = |
998 new views::Checkbox(controller_->UseBillingForShippingText()); | 1007 new views::Checkbox(controller_->UseBillingForShippingText()); |
999 use_billing_for_shipping_->SetChecked(true); | 1008 use_billing_for_shipping_->SetChecked(true); |
1000 use_billing_for_shipping_->set_listener(this); | 1009 use_billing_for_shipping_->set_listener(this); |
1001 info_view->AddChildView(use_billing_for_shipping_); | 1010 info_view->AddChildView(use_billing_for_shipping_); |
1002 } | 1011 } |
1003 | 1012 |
1004 views::View* manual_inputs = InitInputsView(section); | 1013 views::View* manual_inputs = InitInputsView(section); |
1005 info_view->AddChildView(manual_inputs); | 1014 info_view->AddChildView(manual_inputs); |
1006 SuggestionView* suggested_info = | 1015 SuggestionView* suggested_info = |
1007 new SuggestionView(controller_->EditSuggestionText(), this); | 1016 new SuggestionView(controller_->EditSuggestionText(), this); |
1008 info_view->AddChildView(suggested_info); | 1017 info_view->AddChildView(suggested_info); |
1009 layout->AddView(info_view); | 1018 layout->AddView(info_view); |
1010 | 1019 |
1011 if (section == SECTION_CC) { | |
1012 // TODO(estade): don't hardcode this string. | |
1013 suggested_info->ShowTextfield( | |
1014 ASCIIToUTF16("CVC"), | |
1015 controller_->IconForField(CREDIT_CARD_VERIFICATION_CODE, | |
1016 string16()).AsImageSkia()); | |
1017 } | |
1018 | |
1019 // TODO(estade): Fix the appearance of this button. | 1020 // TODO(estade): Fix the appearance of this button. |
1020 views::ImageButton* menu_button = new views::ImageButton(this); | 1021 views::ImageButton* menu_button = new views::ImageButton(this); |
1021 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 1022 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
1022 menu_button->SetImage(views::CustomButton::STATE_NORMAL, | 1023 menu_button->SetImage(views::CustomButton::STATE_NORMAL, |
1023 rb.GetImageSkiaNamed(IDR_AUTOFILL_DIALOG_MENU_BUTTON)); | 1024 rb.GetImageSkiaNamed(IDR_AUTOFILL_DIALOG_MENU_BUTTON)); |
1024 menu_button->SetImage(views::CustomButton::STATE_PRESSED, | 1025 menu_button->SetImage(views::CustomButton::STATE_PRESSED, |
1025 rb.GetImageSkiaNamed(IDR_AUTOFILL_DIALOG_MENU_BUTTON_P)); | 1026 rb.GetImageSkiaNamed(IDR_AUTOFILL_DIALOG_MENU_BUTTON_P)); |
1026 layout->AddView(menu_button); | 1027 layout->AddView(menu_button); |
1027 | 1028 |
1028 DetailsGroup* group = GroupForSection(section); | 1029 DetailsGroup* group = GroupForSection(section); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1096 | 1097 |
1097 textfields->insert(std::make_pair(&input, field)); | 1098 textfields->insert(std::make_pair(&input, field)); |
1098 layout->AddView(field); | 1099 layout->AddView(field); |
1099 } | 1100 } |
1100 } | 1101 } |
1101 | 1102 |
1102 return view; | 1103 return view; |
1103 } | 1104 } |
1104 | 1105 |
1105 void AutofillDialogViews::UpdateDetailsGroupState(const DetailsGroup& group) { | 1106 void AutofillDialogViews::UpdateDetailsGroupState(const DetailsGroup& group) { |
1106 string16 suggestion_text = | 1107 const SuggestionState& suggestion_state = |
1107 controller_->SuggestionTextForSection(group.section); | 1108 controller_->SuggestionStateForSection(group.section); |
1108 bool show_suggestions = !suggestion_text.empty(); | 1109 bool show_suggestions = !suggestion_state.text.empty(); |
1109 group.suggested_info->SetVisible(show_suggestions); | 1110 group.suggested_info->SetVisible(show_suggestions); |
1110 group.suggested_info->SetSuggestionText(suggestion_text); | 1111 group.suggested_info->SetSuggestionText(suggestion_state.text); |
1111 gfx::Image icon = controller_->SuggestionIconForSection(group.section); | 1112 group.suggested_info->SetSuggestionIcon(suggestion_state.icon); |
1112 group.suggested_info->SetSuggestionIcon(icon); | 1113 group.suggested_info->SetEditable(suggestion_state.editable); |
| 1114 |
| 1115 if (!suggestion_state.extra_text.empty()) { |
| 1116 group.suggested_info->ShowTextfield( |
| 1117 suggestion_state.extra_text, |
| 1118 suggestion_state.extra_icon.AsImageSkia()); |
| 1119 } |
1113 | 1120 |
1114 if (group.section == SECTION_SHIPPING) { | 1121 if (group.section == SECTION_SHIPPING) { |
1115 bool show_checkbox = !show_suggestions; | 1122 bool show_checkbox = !show_suggestions; |
1116 // When the checkbox is going from hidden to visible, it's because the | 1123 // When the checkbox is going from hidden to visible, it's because the |
1117 // user clicked "Enter new address". Reset the checkbox to unchecked in this | 1124 // user clicked "Enter new address". Reset the checkbox to unchecked in this |
1118 // case. | 1125 // case. |
1119 if (show_checkbox && !use_billing_for_shipping_->visible()) | 1126 if (show_checkbox && !use_billing_for_shipping_->visible()) |
1120 use_billing_for_shipping_->SetChecked(false); | 1127 use_billing_for_shipping_->SetChecked(false); |
1121 | 1128 |
1122 use_billing_for_shipping_->SetVisible(show_checkbox); | 1129 use_billing_for_shipping_->SetVisible(show_checkbox); |
1123 group.manual_input->SetVisible( | 1130 group.manual_input->SetVisible( |
1124 show_checkbox && !use_billing_for_shipping_->checked()); | 1131 show_checkbox && !use_billing_for_shipping_->checked()); |
1125 } else { | 1132 } else { |
1126 group.manual_input->SetVisible(!show_suggestions); | 1133 group.manual_input->SetVisible(!show_suggestions); |
1127 } | 1134 } |
1128 | 1135 |
1129 // Show or hide the "Save in chrome" checkbox. If nothing is in editing mode, | 1136 // Show or hide the "Save in chrome" checkbox. If nothing is in editing mode, |
1130 // hide. If the controller tells us not to show it, likewise hide. | 1137 // hide. If the controller tells us not to show it, likewise hide. |
1131 save_in_chrome_checkbox_->SetVisible( | 1138 save_in_chrome_checkbox_->SetVisible( |
1132 controller_->ShouldOfferToSaveInChrome() && AtLeastOneSectionIsEditing()); | 1139 controller_->ShouldOfferToSaveInChrome() && AtLeastOneSectionIsEditing()); |
1133 | 1140 |
| 1141 const bool has_suggestions = |
| 1142 controller_->MenuModelForSection(group.section)->GetItemCount() > 0; |
| 1143 |
| 1144 if (group.suggested_button) |
| 1145 group.suggested_button->SetVisible(has_suggestions); |
| 1146 |
1134 if (group.container) { | 1147 if (group.container) { |
1135 group.container->SetForwardMouseEvents(show_suggestions); | 1148 group.container->SetForwardMouseEvents(has_suggestions && show_suggestions); |
1136 group.container->SetVisible(controller_->SectionIsActive(group.section)); | 1149 group.container->SetVisible(controller_->SectionIsActive(group.section)); |
1137 } | 1150 } |
1138 | 1151 |
1139 ContentsPreferredSizeChanged(); | 1152 ContentsPreferredSizeChanged(); |
1140 } | 1153 } |
1141 | 1154 |
1142 bool AutofillDialogViews::AtLeastOneSectionIsEditing() { | 1155 bool AutofillDialogViews::AtLeastOneSectionIsEditing() { |
1143 for (DetailGroupMap::iterator iter = detail_groups_.begin(); | 1156 for (DetailGroupMap::iterator iter = detail_groups_.begin(); |
1144 iter != detail_groups_.end(); ++iter) { | 1157 iter != detail_groups_.end(); ++iter) { |
1145 if (iter->second.manual_input && iter->second.manual_input->visible()) | 1158 if (iter->second.manual_input && iter->second.manual_input->visible()) |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1206 } | 1219 } |
1207 | 1220 |
1208 bool AutofillDialogViews::ValidateForm() { | 1221 bool AutofillDialogViews::ValidateForm() { |
1209 bool all_valid = true; | 1222 bool all_valid = true; |
1210 for (DetailGroupMap::iterator iter = detail_groups_.begin(); | 1223 for (DetailGroupMap::iterator iter = detail_groups_.begin(); |
1211 iter != detail_groups_.end(); ++iter) { | 1224 iter != detail_groups_.end(); ++iter) { |
1212 DetailsGroup* group = &iter->second; | 1225 DetailsGroup* group = &iter->second; |
1213 if (!group->container->visible()) | 1226 if (!group->container->visible()) |
1214 continue; | 1227 continue; |
1215 | 1228 |
1216 if (!ValidateGroup(group, AutofillDialogController::VALIDATE_FINAL)) | 1229 if (!ValidateGroup(group, AutofillDialogController::VALIDATE_FINAL)) |
1217 all_valid = false; | 1230 all_valid = false; |
1218 } | 1231 } |
1219 | 1232 |
1220 return all_valid; | 1233 return all_valid; |
1221 } | 1234 } |
1222 | 1235 |
1223 void AutofillDialogViews::TextfieldEditedOrActivated( | 1236 void AutofillDialogViews::TextfieldEditedOrActivated( |
1224 views::Textfield* textfield, | 1237 views::Textfield* textfield, |
1225 bool was_edit) { | 1238 bool was_edit) { |
1226 DetailsGroup* group = GroupForView(textfield); | 1239 DetailsGroup* group = GroupForView(textfield); |
1227 DCHECK(group); | 1240 DCHECK(group); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1311 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section) | 1324 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section) |
1312 : section(section), | 1325 : section(section), |
1313 container(NULL), | 1326 container(NULL), |
1314 manual_input(NULL), | 1327 manual_input(NULL), |
1315 suggested_info(NULL), | 1328 suggested_info(NULL), |
1316 suggested_button(NULL) {} | 1329 suggested_button(NULL) {} |
1317 | 1330 |
1318 AutofillDialogViews::DetailsGroup::~DetailsGroup() {} | 1331 AutofillDialogViews::DetailsGroup::~DetailsGroup() {} |
1319 | 1332 |
1320 } // namespace autofill | 1333 } // namespace autofill |
OLD | NEW |