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

Side by Side Diff: chrome/browser/ui/views/autofill/autofill_dialog_views.cc

Issue 12893007: Implementing VERIFY_CVV required action. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ahutter@ review Created 7 years, 9 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 | Annotate | Revision Log
OLDNEW
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
344 AutofillDialogViews::SectionContainer::~SectionContainer() {} 345 AutofillDialogViews::SectionContainer::~SectionContainer() {}
345 346
346 void AutofillDialogViews::SectionContainer::SetForwardMouseEvents( 347 void AutofillDialogViews::SectionContainer::SetForwardMouseEvents(
347 bool forward) { 348 bool forward) {
348 forward_mouse_events_ = forward; 349 forward_mouse_events_ = forward;
349 if (!forward) 350 if (!forward)
350 set_background(NULL); 351 set_background(NULL);
351 } 352 }
352 353
353 void AutofillDialogViews::SectionContainer::SetActive(bool active) { 354 void AutofillDialogViews::SectionContainer::SetActive(bool active) {
355 active &= can_activate_;
Evan Stade 2013/03/26 19:29:54 I don't like that you're using a bitwise operator
Dan Beam 2013/03/27 00:38:27 Done.
354 if (active == !!background()) 356 if (active == !!background())
355 return; 357 return;
356 358
357 set_background(active ? 359 set_background(active ?
358 // TODO(estade): use the correct color. 360 // TODO(estade): use the correct color.
359 views::Background::CreateSolidBackground(SK_ColorLTGRAY): 361 views::Background::CreateSolidBackground(SK_ColorLTGRAY):
360 NULL); 362 NULL);
361 SchedulePaint(); 363 SchedulePaint();
362 } 364 }
363 365
366 void AutofillDialogViews::SectionContainer::SetCanActivate(bool can_activate) {
367 can_activate_ = can_activate;
368 if (!can_activate_)
369 SetActive(false);
370 }
371
364 void AutofillDialogViews::SectionContainer::OnMouseMoved( 372 void AutofillDialogViews::SectionContainer::OnMouseMoved(
365 const ui::MouseEvent& event) { 373 const ui::MouseEvent& event) {
366 if (!forward_mouse_events_) 374 if (!forward_mouse_events_)
367 return; 375 return;
368 376
369 SetActive(true); 377 SetActive(true);
370 } 378 }
371 379
372 void AutofillDialogViews::SectionContainer::OnMouseEntered( 380 void AutofillDialogViews::SectionContainer::OnMouseEntered(
373 const ui::MouseEvent& event) { 381 const ui::MouseEvent& event) {
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 output->insert(std::make_pair(it->first, it->second->textfield()->text())); 628 output->insert(std::make_pair(it->first, it->second->textfield()->text()));
621 } 629 }
622 for (ComboboxMap::const_iterator it = group->comboboxes.begin(); 630 for (ComboboxMap::const_iterator it = group->comboboxes.begin();
623 it != group->comboboxes.end(); ++it) { 631 it != group->comboboxes.end(); ++it) {
624 output->insert(std::make_pair(it->first, 632 output->insert(std::make_pair(it->first,
625 it->second->model()->GetItemAt(it->second->selected_index()))); 633 it->second->model()->GetItemAt(it->second->selected_index())));
626 } 634 }
627 } 635 }
628 636
629 string16 AutofillDialogViews::GetCvc() { 637 string16 AutofillDialogViews::GetCvc() {
630 return GroupForSection(SECTION_CC)->suggested_info->decorated_textfield()-> 638 DialogSection billing_section = controller_->SectionIsActive(SECTION_CC) ?
631 textfield()->text(); 639 SECTION_CC : SECTION_CC_BILLING;
640 return GroupForSection(billing_section)->suggested_info->
641 decorated_textfield()->textfield()->text();
632 } 642 }
633 643
634 bool AutofillDialogViews::UseBillingForShipping() { 644 bool AutofillDialogViews::UseBillingForShipping() {
635 return use_billing_for_shipping_->checked(); 645 return use_billing_for_shipping_->checked();
636 } 646 }
637 647
638 bool AutofillDialogViews::SaveDetailsInWallet() { 648 bool AutofillDialogViews::SaveDetailsInWallet() {
639 return notification_area_->CheckboxIsChecked(); 649 return notification_area_->CheckboxIsChecked();
640 } 650 }
641 651
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 // TODO(estade): add a view to contain the terms of service. 744 // TODO(estade): add a view to contain the terms of service.
735 return NULL; 745 return NULL;
736 } 746 }
737 747
738 bool AutofillDialogViews::Cancel() { 748 bool AutofillDialogViews::Cancel() {
739 controller_->OnCancel(); 749 controller_->OnCancel();
740 return true; 750 return true;
741 } 751 }
742 752
743 bool AutofillDialogViews::Accept() { 753 bool AutofillDialogViews::Accept() {
744 if (!ValidateForm()) 754 if (ValidateForm())
745 return false; 755 controller_->OnAccept();
746 756
747 controller_->OnSubmit(); 757 // |controller_| decides when to hide the dialog.
748
749 // Let |controller_| decide when to hide the dialog.
750 return false; 758 return false;
751 } 759 }
752 760
753 // TODO(wittman): Remove this override once we move to the new style frame view 761 // TODO(wittman): Remove this override once we move to the new style frame view
754 // on all dialogs. 762 // on all dialogs.
755 views::NonClientFrameView* AutofillDialogViews::CreateNonClientFrameView( 763 views::NonClientFrameView* AutofillDialogViews::CreateNonClientFrameView(
756 views::Widget* widget) { 764 views::Widget* widget) {
757 return CreateConstrainedStyleNonClientFrameView( 765 return CreateConstrainedStyleNonClientFrameView(
758 widget, 766 widget,
759 controller_->web_contents()->GetBrowserContext()); 767 controller_->web_contents()->GetBrowserContext());
(...skipping 10 matching lines...) Expand all
770 DetailsGroup* group = NULL; 778 DetailsGroup* group = NULL;
771 for (DetailGroupMap::iterator iter = detail_groups_.begin(); 779 for (DetailGroupMap::iterator iter = detail_groups_.begin();
772 iter != detail_groups_.end(); ++iter) { 780 iter != detail_groups_.end(); ++iter) {
773 if (sender == iter->second.suggested_button) { 781 if (sender == iter->second.suggested_button) {
774 group = &iter->second; 782 group = &iter->second;
775 break; 783 break;
776 } 784 }
777 } 785 }
778 DCHECK(group); 786 DCHECK(group);
779 787
788 if (group->container && !group->container->can_activate())
789 return;
790
780 views::MenuModelAdapter adapter( 791 views::MenuModelAdapter adapter(
781 controller_->MenuModelForSection(group->section)); 792 controller_->MenuModelForSection(group->section));
782 menu_runner_.reset(new views::MenuRunner(adapter.CreateMenu())); 793 menu_runner_.reset(new views::MenuRunner(adapter.CreateMenu()));
783 794
784 group->container->SetActive(true); 795 group->container->SetActive(true);
785 // Ignore the result since we don't need to handle a deleted menu specially. 796 // Ignore the result since we don't need to handle a deleted menu specially.
786 ignore_result( 797 ignore_result(
787 menu_runner_->RunMenuAt(sender->GetWidget(), 798 menu_runner_->RunMenuAt(sender->GetWidget(),
788 NULL, 799 NULL,
789 group->suggested_button->GetBoundsInScreen(), 800 group->suggested_button->GetBoundsInScreen(),
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
955 0); 966 0);
956 column_set->AddColumn(views::GridLayout::CENTER, 967 column_set->AddColumn(views::GridLayout::CENTER,
957 views::GridLayout::LEADING, 968 views::GridLayout::LEADING,
958 0, 969 0,
959 views::GridLayout::USE_PREF, 970 views::GridLayout::USE_PREF,
960 0, 971 0,
961 0); 972 0);
962 layout->StartRow(0, kColumnSetId); 973 layout->StartRow(0, kColumnSetId);
963 974
964 // The |info_view| holds |manual_inputs| and |suggested_info|, allowing the 975 // The |info_view| holds |manual_inputs| and |suggested_info|, allowing the
965 // dialog toggle which is shown. 976 // dialog to toggle which is shown.
966 views::View* info_view = new views::View(); 977 views::View* info_view = new views::View();
967 info_view->SetLayoutManager( 978 info_view->SetLayoutManager(
968 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); 979 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
969 980
970 if (section == SECTION_SHIPPING) { 981 if (section == SECTION_SHIPPING) {
971 use_billing_for_shipping_ = 982 use_billing_for_shipping_ =
972 new views::Checkbox(controller_->UseBillingForShippingText()); 983 new views::Checkbox(controller_->UseBillingForShippingText());
973 use_billing_for_shipping_->SetChecked(true); 984 use_billing_for_shipping_->SetChecked(true);
974 use_billing_for_shipping_->set_listener(this); 985 use_billing_for_shipping_->set_listener(this);
975 info_view->AddChildView(use_billing_for_shipping_); 986 info_view->AddChildView(use_billing_for_shipping_);
976 } 987 }
977 988
978 views::View* manual_inputs = InitInputsView(section); 989 views::View* manual_inputs = InitInputsView(section);
979 info_view->AddChildView(manual_inputs); 990 info_view->AddChildView(manual_inputs);
980 SuggestionView* suggested_info = 991 SuggestionView* suggested_info =
981 new SuggestionView(controller_->EditSuggestionText(), this); 992 new SuggestionView(controller_->EditSuggestionText(), this);
982 info_view->AddChildView(suggested_info); 993 info_view->AddChildView(suggested_info);
983 layout->AddView(info_view); 994 layout->AddView(info_view);
984 995
985 if (section == SECTION_CC) {
986 // TODO(estade): don't hardcode this string.
987 suggested_info->ShowTextfield(
988 ASCIIToUTF16("CVC"),
989 controller_->IconForField(CREDIT_CARD_VERIFICATION_CODE,
990 string16()).AsImageSkia());
991 }
992
993 // TODO(estade): Fix the appearance of this button. 996 // TODO(estade): Fix the appearance of this button.
994 views::ImageButton* menu_button = new views::ImageButton(this); 997 views::ImageButton* menu_button = new views::ImageButton(this);
995 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 998 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
996 menu_button->SetImage(views::CustomButton::STATE_NORMAL, 999 menu_button->SetImage(views::CustomButton::STATE_NORMAL,
997 rb.GetImageSkiaNamed(IDR_AUTOFILL_DIALOG_MENU_BUTTON)); 1000 rb.GetImageSkiaNamed(IDR_AUTOFILL_DIALOG_MENU_BUTTON));
998 menu_button->SetImage(views::CustomButton::STATE_PRESSED, 1001 menu_button->SetImage(views::CustomButton::STATE_PRESSED,
999 rb.GetImageSkiaNamed(IDR_AUTOFILL_DIALOG_MENU_BUTTON_P)); 1002 rb.GetImageSkiaNamed(IDR_AUTOFILL_DIALOG_MENU_BUTTON_P));
1000 layout->AddView(menu_button); 1003 layout->AddView(menu_button);
1001 1004
1002 DetailsGroup* group = GroupForSection(section); 1005 DetailsGroup* group = GroupForSection(section);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 1081
1079 void AutofillDialogViews::UpdateDetailsGroupState(const DetailsGroup& group) { 1082 void AutofillDialogViews::UpdateDetailsGroupState(const DetailsGroup& group) {
1080 string16 suggestion_text = 1083 string16 suggestion_text =
1081 controller_->SuggestionTextForSection(group.section); 1084 controller_->SuggestionTextForSection(group.section);
1082 bool show_suggestions = !suggestion_text.empty(); 1085 bool show_suggestions = !suggestion_text.empty();
1083 group.suggested_info->SetVisible(show_suggestions); 1086 group.suggested_info->SetVisible(show_suggestions);
1084 group.suggested_info->SetSuggestionText(suggestion_text); 1087 group.suggested_info->SetSuggestionText(suggestion_text);
1085 gfx::Image icon = controller_->SuggestionIconForSection(group.section); 1088 gfx::Image icon = controller_->SuggestionIconForSection(group.section);
1086 group.suggested_info->SetSuggestionIcon(icon); 1089 group.suggested_info->SetSuggestionIcon(icon);
1087 1090
1091 if (group.section == SECTION_CC ||
1092 (group.section == SECTION_CC_BILLING &&
1093 controller_->IsSubmitPausedOn(wallet::VERIFY_CVV))) {
1094 // TODO(estade): don't hardcode this string.
1095 group.suggested_info->ShowTextfield(
1096 ASCIIToUTF16("CVC"),
1097 controller_->IconForField(CREDIT_CARD_VERIFICATION_CODE,
1098 string16()).AsImageSkia());
1099 }
1100
1088 if (group.section == SECTION_SHIPPING) { 1101 if (group.section == SECTION_SHIPPING) {
1089 bool show_checkbox = !show_suggestions; 1102 bool show_checkbox = !show_suggestions;
1090 // When the checkbox is going from hidden to visible, it's because the 1103 // When the checkbox is going from hidden to visible, it's because the
1091 // user clicked "Enter new address". Reset the checkbox to unchecked in this 1104 // user clicked "Enter new address". Reset the checkbox to unchecked in this
1092 // case. 1105 // case.
1093 if (show_checkbox && !use_billing_for_shipping_->visible()) 1106 if (show_checkbox && !use_billing_for_shipping_->visible())
1094 use_billing_for_shipping_->SetChecked(false); 1107 use_billing_for_shipping_->SetChecked(false);
1095 1108
1096 use_billing_for_shipping_->SetVisible(show_checkbox); 1109 use_billing_for_shipping_->SetVisible(show_checkbox);
1097 group.manual_input->SetVisible( 1110 group.manual_input->SetVisible(
1098 show_checkbox && !use_billing_for_shipping_->checked()); 1111 show_checkbox && !use_billing_for_shipping_->checked());
1099 } else { 1112 } else {
1100 group.manual_input->SetVisible(!show_suggestions); 1113 group.manual_input->SetVisible(!show_suggestions);
1101 } 1114 }
1102 1115
1103 // Show or hide the "Save in chrome" checkbox. If nothing is in editing mode, 1116 // Show or hide the "Save in chrome" checkbox. If nothing is in editing mode,
1104 // hide. If the controller tells us not to show it, likewise hide. 1117 // hide. If the controller tells us not to show it, likewise hide.
1105 save_in_chrome_checkbox_->SetVisible( 1118 save_in_chrome_checkbox_->SetVisible(
1106 controller_->ShouldOfferToSaveInChrome() && AtLeastOneSectionIsEditing()); 1119 controller_->ShouldOfferToSaveInChrome() && AtLeastOneSectionIsEditing());
1107 1120
1121 const bool can_activate =
1122 controller_->MenuModelForSection(group.section)->GetItemCount() > 0;
1123
1108 if (group.container) { 1124 if (group.container) {
1125 group.container->SetCanActivate(can_activate);
Evan Stade 2013/03/26 19:29:54 "can activate" can just be controlled by whether p
Dan Beam 2013/03/27 00:38:27 Done.
1109 group.container->SetForwardMouseEvents(show_suggestions); 1126 group.container->SetForwardMouseEvents(show_suggestions);
1110 group.container->SetVisible(controller_->SectionIsActive(group.section)); 1127 group.container->SetVisible(controller_->SectionIsActive(group.section));
1111 } 1128 }
1112 1129
1130 if (group.suggested_button)
1131 group.suggested_button->SetVisible(can_activate);
1132
1113 ContentsPreferredSizeChanged(); 1133 ContentsPreferredSizeChanged();
1114 } 1134 }
1115 1135
1116 bool AutofillDialogViews::AtLeastOneSectionIsEditing() { 1136 bool AutofillDialogViews::AtLeastOneSectionIsEditing() {
1117 for (DetailGroupMap::iterator iter = detail_groups_.begin(); 1137 for (DetailGroupMap::iterator iter = detail_groups_.begin();
1118 iter != detail_groups_.end(); ++iter) { 1138 iter != detail_groups_.end(); ++iter) {
1119 if (iter->second.manual_input && iter->second.manual_input->visible()) 1139 if (iter->second.manual_input && iter->second.manual_input->visible())
1120 return true; 1140 return true;
1121 } 1141 }
1122 1142
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section) 1276 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section)
1257 : section(section), 1277 : section(section),
1258 container(NULL), 1278 container(NULL),
1259 manual_input(NULL), 1279 manual_input(NULL),
1260 suggested_info(NULL), 1280 suggested_info(NULL),
1261 suggested_button(NULL) {} 1281 suggested_button(NULL) {}
1262 1282
1263 AutofillDialogViews::DetailsGroup::~DetailsGroup() {} 1283 AutofillDialogViews::DetailsGroup::~DetailsGroup() {}
1264 1284
1265 } // namespace autofill 1285 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698