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 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 495 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
496 } | 496 } |
497 | 497 |
498 AutofillDialogViews::SuggestionView::~SuggestionView() {} | 498 AutofillDialogViews::SuggestionView::~SuggestionView() {} |
499 | 499 |
500 void AutofillDialogViews::SuggestionView::SetEditable(bool editable) { | 500 void AutofillDialogViews::SuggestionView::SetEditable(bool editable) { |
501 edit_link_->SetVisible(editable); | 501 edit_link_->SetVisible(editable); |
502 } | 502 } |
503 | 503 |
504 void AutofillDialogViews::SuggestionView::SetSuggestionText( | 504 void AutofillDialogViews::SuggestionView::SetSuggestionText( |
505 const string16& text) { | 505 const string16& text, |
| 506 gfx::Font::FontStyle text_style) { |
| 507 label_->SetFont(ui::ResourceBundle::GetSharedInstance().GetFont( |
| 508 ui::ResourceBundle::BaseFont).DeriveFont(0, text_style)); |
| 509 |
506 // TODO(estade): does this localize well? | 510 // TODO(estade): does this localize well? |
507 string16 line_return(ASCIIToUTF16("\n")); | 511 string16 line_return(ASCIIToUTF16("\n")); |
508 size_t position = text.find(line_return); | 512 size_t position = text.find(line_return); |
509 if (position == string16::npos) { | 513 if (position == string16::npos) { |
510 label_->SetText(text); | 514 label_->SetText(text); |
511 label_line_2_->SetVisible(false); | 515 label_line_2_->SetVisible(false); |
512 } else { | 516 } else { |
513 label_->SetText(text.substr(0, position)); | 517 label_->SetText(text.substr(0, position)); |
514 label_line_2_->SetText(text.substr(position + line_return.length())); | 518 label_line_2_->SetText(text.substr(position + line_return.length())); |
515 label_line_2_->SetVisible(true); | 519 label_line_2_->SetVisible(true); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 return new AutofillDialogViews(controller); | 554 return new AutofillDialogViews(controller); |
551 } | 555 } |
552 | 556 |
553 // AutofillDialogViews --------------------------------------------------------- | 557 // AutofillDialogViews --------------------------------------------------------- |
554 | 558 |
555 AutofillDialogViews::AutofillDialogViews(AutofillDialogController* controller) | 559 AutofillDialogViews::AutofillDialogViews(AutofillDialogController* controller) |
556 : controller_(controller), | 560 : controller_(controller), |
557 window_(NULL), | 561 window_(NULL), |
558 contents_(NULL), | 562 contents_(NULL), |
559 notification_area_(NULL), | 563 notification_area_(NULL), |
560 use_billing_for_shipping_(NULL), | |
561 account_chooser_(NULL), | 564 account_chooser_(NULL), |
562 sign_in_container_(NULL), | 565 sign_in_container_(NULL), |
563 cancel_sign_in_(NULL), | 566 cancel_sign_in_(NULL), |
564 sign_in_webview_(NULL), | 567 sign_in_webview_(NULL), |
565 main_container_(NULL), | 568 main_container_(NULL), |
566 details_container_(NULL), | 569 details_container_(NULL), |
567 button_strip_extra_view_(NULL), | 570 button_strip_extra_view_(NULL), |
568 save_in_chrome_checkbox_(NULL), | 571 save_in_chrome_checkbox_(NULL), |
569 autocheckout_progress_bar_view_(NULL), | 572 autocheckout_progress_bar_view_(NULL), |
570 autocheckout_progress_bar_(NULL), | 573 autocheckout_progress_bar_(NULL), |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 } | 705 } |
703 } | 706 } |
704 | 707 |
705 string16 AutofillDialogViews::GetCvc() { | 708 string16 AutofillDialogViews::GetCvc() { |
706 DialogSection billing_section = controller_->SectionIsActive(SECTION_CC) ? | 709 DialogSection billing_section = controller_->SectionIsActive(SECTION_CC) ? |
707 SECTION_CC : SECTION_CC_BILLING; | 710 SECTION_CC : SECTION_CC_BILLING; |
708 return GroupForSection(billing_section)->suggested_info-> | 711 return GroupForSection(billing_section)->suggested_info-> |
709 decorated_textfield()->textfield()->text(); | 712 decorated_textfield()->textfield()->text(); |
710 } | 713 } |
711 | 714 |
712 bool AutofillDialogViews::UseBillingForShipping() { | |
713 return use_billing_for_shipping_->checked(); | |
714 } | |
715 | |
716 bool AutofillDialogViews::SaveDetailsLocally() { | 715 bool AutofillDialogViews::SaveDetailsLocally() { |
717 return save_in_chrome_checkbox_->checked(); | 716 return save_in_chrome_checkbox_->checked(); |
718 } | 717 } |
719 | 718 |
720 const content::NavigationController* AutofillDialogViews::ShowSignIn() { | 719 const content::NavigationController* AutofillDialogViews::ShowSignIn() { |
721 // TODO(abodenha) We should be able to use the WebContents of the WebView | 720 // TODO(abodenha) We should be able to use the WebContents of the WebView |
722 // to navigate instead of LoadInitialURL. Figure out why it doesn't work. | 721 // to navigate instead of LoadInitialURL. Figure out why it doesn't work. |
723 | 722 |
724 account_chooser_->SetSignInLinkEnabled(false); | 723 account_chooser_->SetSignInLinkEnabled(false); |
725 sign_in_webview_->LoadInitialURL(wallet::GetSignInUrl()); | 724 sign_in_webview_->LoadInitialURL(wallet::GetSignInUrl()); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
821 kLegalDocPadding, | 820 kLegalDocPadding, |
822 kLegalDocPadding, | 821 kLegalDocPadding, |
823 0)); | 822 0)); |
824 footnote_view_->set_border( | 823 footnote_view_->set_border( |
825 views::Border::CreateSolidSidedBorder(1, 0, 0, 0, kSubtleBorderColor)); | 824 views::Border::CreateSolidSidedBorder(1, 0, 0, 0, kSubtleBorderColor)); |
826 footnote_view_->set_background( | 825 footnote_view_->set_background( |
827 views::Background::CreateSolidBackground(kShadingColor)); | 826 views::Background::CreateSolidBackground(kShadingColor)); |
828 | 827 |
829 legal_document_view_ = new views::StyledLabel(string16(), this); | 828 legal_document_view_ = new views::StyledLabel(string16(), this); |
830 footnote_view_->AddChildView(legal_document_view_); | 829 footnote_view_->AddChildView(legal_document_view_); |
| 830 UpdateAccountChooser(); |
831 | 831 |
832 return footnote_view_; | 832 return footnote_view_; |
833 } | 833 } |
834 | 834 |
835 bool AutofillDialogViews::Cancel() { | 835 bool AutofillDialogViews::Cancel() { |
836 controller_->OnCancel(); | 836 controller_->OnCancel(); |
837 return true; | 837 return true; |
838 } | 838 } |
839 | 839 |
840 bool AutofillDialogViews::Accept() { | 840 bool AutofillDialogViews::Accept() { |
841 if (ValidateForm()) | 841 if (ValidateForm()) |
842 controller_->OnAccept(); | 842 controller_->OnAccept(); |
843 | 843 |
844 // |controller_| decides when to hide the dialog. | 844 // |controller_| decides when to hide the dialog. |
845 return false; | 845 return false; |
846 } | 846 } |
847 | 847 |
848 // TODO(wittman): Remove this override once we move to the new style frame view | 848 // TODO(wittman): Remove this override once we move to the new style frame view |
849 // on all dialogs. | 849 // on all dialogs. |
850 views::NonClientFrameView* AutofillDialogViews::CreateNonClientFrameView( | 850 views::NonClientFrameView* AutofillDialogViews::CreateNonClientFrameView( |
851 views::Widget* widget) { | 851 views::Widget* widget) { |
852 return CreateConstrainedStyleNonClientFrameView( | 852 return CreateConstrainedStyleNonClientFrameView( |
853 widget, | 853 widget, |
854 controller_->web_contents()->GetBrowserContext()); | 854 controller_->web_contents()->GetBrowserContext()); |
855 } | 855 } |
856 | 856 |
857 void AutofillDialogViews::ButtonPressed(views::Button* sender, | 857 void AutofillDialogViews::ButtonPressed(views::Button* sender, |
858 const ui::Event& event) { | 858 const ui::Event& event) { |
859 if (sender == use_billing_for_shipping_) { | 859 if (sender == cancel_sign_in_) { |
860 UpdateDetailsGroupState(*GroupForSection(SECTION_SHIPPING)); | |
861 } else if (sender == cancel_sign_in_) { | |
862 controller_->EndSignInFlow(); | 860 controller_->EndSignInFlow(); |
863 } else { | 861 } else { |
864 // TODO(estade): Should the menu be shown on mouse down? | 862 // TODO(estade): Should the menu be shown on mouse down? |
865 DetailsGroup* group = NULL; | 863 DetailsGroup* group = NULL; |
866 for (DetailGroupMap::iterator iter = detail_groups_.begin(); | 864 for (DetailGroupMap::iterator iter = detail_groups_.begin(); |
867 iter != detail_groups_.end(); ++iter) { | 865 iter != detail_groups_.end(); ++iter) { |
868 if (sender == iter->second.suggested_button) { | 866 if (sender == iter->second.suggested_button) { |
869 group = &iter->second; | 867 group = &iter->second; |
870 break; | 868 break; |
871 } | 869 } |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1065 0, | 1063 0, |
1066 0); | 1064 0); |
1067 layout->StartRow(0, kColumnSetId); | 1065 layout->StartRow(0, kColumnSetId); |
1068 | 1066 |
1069 // The |info_view| holds |manual_inputs| and |suggested_info|, allowing the | 1067 // The |info_view| holds |manual_inputs| and |suggested_info|, allowing the |
1070 // dialog to toggle which is shown. | 1068 // dialog to toggle which is shown. |
1071 views::View* info_view = new views::View(); | 1069 views::View* info_view = new views::View(); |
1072 info_view->SetLayoutManager( | 1070 info_view->SetLayoutManager( |
1073 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 1071 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
1074 | 1072 |
1075 if (section == SECTION_SHIPPING) { | |
1076 use_billing_for_shipping_ = | |
1077 new views::Checkbox(controller_->UseBillingForShippingText()); | |
1078 use_billing_for_shipping_->SetChecked(true); | |
1079 use_billing_for_shipping_->set_listener(this); | |
1080 info_view->AddChildView(use_billing_for_shipping_); | |
1081 } | |
1082 | |
1083 views::View* manual_inputs = InitInputsView(section); | 1073 views::View* manual_inputs = InitInputsView(section); |
1084 info_view->AddChildView(manual_inputs); | 1074 info_view->AddChildView(manual_inputs); |
1085 SuggestionView* suggested_info = | 1075 SuggestionView* suggested_info = |
1086 new SuggestionView(controller_->EditSuggestionText(), this); | 1076 new SuggestionView(controller_->EditSuggestionText(), this); |
1087 info_view->AddChildView(suggested_info); | 1077 info_view->AddChildView(suggested_info); |
1088 layout->AddView(info_view); | 1078 layout->AddView(info_view); |
1089 | 1079 |
1090 // TODO(estade): Fix the appearance of this button. | 1080 // TODO(estade): Fix the appearance of this button. |
1091 views::ImageButton* menu_button = new views::ImageButton(this); | 1081 views::ImageButton* menu_button = new views::ImageButton(this); |
1092 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 1082 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1176 } | 1166 } |
1177 | 1167 |
1178 return view; | 1168 return view; |
1179 } | 1169 } |
1180 | 1170 |
1181 void AutofillDialogViews::UpdateDetailsGroupState(const DetailsGroup& group) { | 1171 void AutofillDialogViews::UpdateDetailsGroupState(const DetailsGroup& group) { |
1182 const SuggestionState& suggestion_state = | 1172 const SuggestionState& suggestion_state = |
1183 controller_->SuggestionStateForSection(group.section); | 1173 controller_->SuggestionStateForSection(group.section); |
1184 bool show_suggestions = !suggestion_state.text.empty(); | 1174 bool show_suggestions = !suggestion_state.text.empty(); |
1185 group.suggested_info->SetVisible(show_suggestions); | 1175 group.suggested_info->SetVisible(show_suggestions); |
1186 group.suggested_info->SetSuggestionText(suggestion_state.text); | 1176 group.suggested_info->SetSuggestionText(suggestion_state.text, |
| 1177 suggestion_state.text_style); |
1187 group.suggested_info->SetSuggestionIcon(suggestion_state.icon); | 1178 group.suggested_info->SetSuggestionIcon(suggestion_state.icon); |
1188 group.suggested_info->SetEditable(suggestion_state.editable); | 1179 group.suggested_info->SetEditable(suggestion_state.editable); |
1189 | 1180 |
1190 if (!suggestion_state.extra_text.empty()) { | 1181 if (!suggestion_state.extra_text.empty()) { |
1191 group.suggested_info->ShowTextfield( | 1182 group.suggested_info->ShowTextfield( |
1192 suggestion_state.extra_text, | 1183 suggestion_state.extra_text, |
1193 suggestion_state.extra_icon.AsImageSkia()); | 1184 suggestion_state.extra_icon.AsImageSkia()); |
1194 } | 1185 } |
1195 | 1186 |
1196 if (group.section == SECTION_SHIPPING) { | 1187 group.manual_input->SetVisible(!show_suggestions); |
1197 bool show_checkbox = !show_suggestions; | |
1198 // When the checkbox is going from hidden to visible, it's because the | |
1199 // user clicked "Enter new address". Reset the checkbox to unchecked in this | |
1200 // case. | |
1201 if (show_checkbox && !use_billing_for_shipping_->visible()) | |
1202 use_billing_for_shipping_->SetChecked(false); | |
1203 | |
1204 use_billing_for_shipping_->SetVisible(show_checkbox); | |
1205 group.manual_input->SetVisible( | |
1206 show_checkbox && !use_billing_for_shipping_->checked()); | |
1207 } else { | |
1208 group.manual_input->SetVisible(!show_suggestions); | |
1209 } | |
1210 | 1188 |
1211 // Show or hide the "Save in chrome" checkbox. If nothing is in editing mode, | 1189 // Show or hide the "Save in chrome" checkbox. If nothing is in editing mode, |
1212 // hide. If the controller tells us not to show it, likewise hide. | 1190 // hide. If the controller tells us not to show it, likewise hide. |
1213 save_in_chrome_checkbox_->SetVisible( | 1191 save_in_chrome_checkbox_->SetVisible( |
1214 controller_->ShouldOfferToSaveInChrome()); | 1192 controller_->ShouldOfferToSaveInChrome()); |
1215 | 1193 |
1216 const bool has_suggestions = | 1194 const bool has_suggestions = |
1217 controller_->MenuModelForSection(group.section)->GetItemCount() > 0; | 1195 controller_->MenuModelForSection(group.section)->GetItemCount() > 0; |
1218 | 1196 |
1219 if (group.suggested_button) | 1197 if (group.suggested_button) |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1388 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section) | 1366 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section) |
1389 : section(section), | 1367 : section(section), |
1390 container(NULL), | 1368 container(NULL), |
1391 manual_input(NULL), | 1369 manual_input(NULL), |
1392 suggested_info(NULL), | 1370 suggested_info(NULL), |
1393 suggested_button(NULL) {} | 1371 suggested_button(NULL) {} |
1394 | 1372 |
1395 AutofillDialogViews::DetailsGroup::~DetailsGroup() {} | 1373 AutofillDialogViews::DetailsGroup::~DetailsGroup() {} |
1396 | 1374 |
1397 } // namespace autofill | 1375 } // namespace autofill |
OLD | NEW |