| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/autofill/autofill_dialog.h" | 5 #include "chrome/browser/autofill/autofill_dialog.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 | 8 |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 GtkWidget* CreateLabel(int label_id) { | 30 GtkWidget* CreateLabel(int label_id) { |
| 31 GtkWidget* label = gtk_label_new(l10n_util::GetStringUTF8(label_id).c_str()); | 31 GtkWidget* label = gtk_label_new(l10n_util::GetStringUTF8(label_id).c_str()); |
| 32 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | 32 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); |
| 33 return label; | 33 return label; |
| 34 } | 34 } |
| 35 | 35 |
| 36 // Sets the text of |entry| to the value of the field |type| from |profile|. | 36 // Sets the text of |entry| to the value of the field |type| from |profile|. |
| 37 void SetEntryText(GtkWidget* entry, FormGroup* profile, _FieldType type) { | 37 void SetEntryText(GtkWidget* entry, FormGroup* profile, _FieldType type) { |
| 38 gtk_entry_set_text( | 38 gtk_entry_set_text( |
| 39 GTK_ENTRY(entry), | 39 GTK_ENTRY(entry), |
| 40 UTF16ToUTF8(profile->GetFieldText(AutofillType(type))).c_str()); | 40 UTF16ToUTF8(profile->GetFieldText(type)).c_str()); |
| 41 } | 41 } |
| 42 | 42 |
| 43 // Returns the current value of |entry|. | 43 // Returns the current value of |entry|. |
| 44 string16 GetEntryText(GtkWidget* entry) { | 44 string16 GetEntryText(GtkWidget* entry) { |
| 45 return UTF8ToUTF16(gtk_entry_get_text(GTK_ENTRY(entry))); | 45 return UTF8ToUTF16(gtk_entry_get_text(GTK_ENTRY(entry))); |
| 46 } | 46 } |
| 47 | 47 |
| 48 // Sets |form|'s field of type |type| to the text in |entry|. | 48 // Sets |form|'s field of type |type| to the text in |entry|. |
| 49 void SetFormValue(GtkWidget* entry, FormGroup* form, _FieldType type) { | 49 void SetFormValue(GtkWidget* entry, FormGroup* form, _FieldType type) { |
| 50 form->SetInfo(AutofillType(type), GetEntryText(entry)); | 50 form->SetInfo(type, GetEntryText(entry)); |
| 51 } | 51 } |
| 52 | 52 |
| 53 // Sets the number of characters to display in |combobox| to |width|. | 53 // Sets the number of characters to display in |combobox| to |width|. |
| 54 void SetComboBoxCellRendererCharWidth(GtkWidget* combobox, int width) { | 54 void SetComboBoxCellRendererCharWidth(GtkWidget* combobox, int width) { |
| 55 GList* cells = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(combobox)); | 55 GList* cells = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(combobox)); |
| 56 DCHECK(g_list_length(cells) > 0); | 56 DCHECK(g_list_length(cells) > 0); |
| 57 GtkCellRendererText* renderer = | 57 GtkCellRendererText* renderer = |
| 58 GTK_CELL_RENDERER_TEXT(g_list_first(cells)->data); | 58 GTK_CELL_RENDERER_TEXT(g_list_first(cells)->data); |
| 59 g_object_set(G_OBJECT(renderer), "width-chars", width, NULL); | 59 g_object_set(G_OBJECT(renderer), "width-chars", width, NULL); |
| 60 g_list_free(cells); | 60 g_list_free(cells); |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 SetFormValue(address_2_, profile, ADDRESS_HOME_LINE2); | 421 SetFormValue(address_2_, profile, ADDRESS_HOME_LINE2); |
| 422 SetFormValue(city_, profile, ADDRESS_HOME_CITY); | 422 SetFormValue(city_, profile, ADDRESS_HOME_CITY); |
| 423 SetFormValue(state_, profile, ADDRESS_HOME_STATE); | 423 SetFormValue(state_, profile, ADDRESS_HOME_STATE); |
| 424 SetFormValue(zip_, profile, ADDRESS_HOME_ZIP); | 424 SetFormValue(zip_, profile, ADDRESS_HOME_ZIP); |
| 425 SetFormValue(country_, profile, ADDRESS_HOME_COUNTRY); | 425 SetFormValue(country_, profile, ADDRESS_HOME_COUNTRY); |
| 426 SetFormValue(email_, profile, EMAIL_ADDRESS); | 426 SetFormValue(email_, profile, EMAIL_ADDRESS); |
| 427 | 427 |
| 428 string16 number, city_code, country_code; | 428 string16 number, city_code, country_code; |
| 429 PhoneNumber::ParsePhoneNumber( | 429 PhoneNumber::ParsePhoneNumber( |
| 430 GetEntryText(phone_), &number, &city_code, &country_code); | 430 GetEntryText(phone_), &number, &city_code, &country_code); |
| 431 profile->SetInfo(AutofillType(PHONE_HOME_COUNTRY_CODE), country_code); | 431 profile->SetInfo(PHONE_HOME_COUNTRY_CODE, country_code); |
| 432 profile->SetInfo(AutofillType(PHONE_HOME_CITY_CODE), city_code); | 432 profile->SetInfo(PHONE_HOME_CITY_CODE, city_code); |
| 433 profile->SetInfo(AutofillType(PHONE_HOME_NUMBER), number); | 433 profile->SetInfo(PHONE_HOME_NUMBER, number); |
| 434 | 434 |
| 435 PhoneNumber::ParsePhoneNumber( | 435 PhoneNumber::ParsePhoneNumber( |
| 436 GetEntryText(fax_), &number, &city_code, &country_code); | 436 GetEntryText(fax_), &number, &city_code, &country_code); |
| 437 profile->SetInfo(AutofillType(PHONE_FAX_COUNTRY_CODE), country_code); | 437 profile->SetInfo(PHONE_FAX_COUNTRY_CODE, country_code); |
| 438 profile->SetInfo(AutofillType(PHONE_FAX_CITY_CODE), city_code); | 438 profile->SetInfo(PHONE_FAX_CITY_CODE, city_code); |
| 439 profile->SetInfo(AutofillType(PHONE_FAX_NUMBER), number); | 439 profile->SetInfo(PHONE_FAX_NUMBER, number); |
| 440 } | 440 } |
| 441 | 441 |
| 442 void AutofillProfileEditor::UpdatePhoneImage(GtkWidget* entry, | 442 void AutofillProfileEditor::UpdatePhoneImage(GtkWidget* entry, |
| 443 GtkWidget* image) { | 443 GtkWidget* image) { |
| 444 string16 number, city_code, country_code; | 444 string16 number, city_code, country_code; |
| 445 string16 text(GetEntryText(entry)); | 445 string16 text(GetEntryText(entry)); |
| 446 if (text.empty()) { | 446 if (text.empty()) { |
| 447 gtk_image_set_from_pixbuf(GTK_IMAGE(image), NULL); | 447 gtk_image_set_from_pixbuf(GTK_IMAGE(image), NULL); |
| 448 } else if (PhoneNumber::ParsePhoneNumber(text, &number, &city_code, | 448 } else if (PhoneNumber::ParsePhoneNumber(text, &number, &city_code, |
| 449 &country_code)) { | 449 &country_code)) { |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 G_CALLBACK(OnInsertTextIntoNumberThunk), this); | 706 G_CALLBACK(OnInsertTextIntoNumberThunk), this); |
| 707 } | 707 } |
| 708 | 708 |
| 709 void AutoFillCreditCardEditor::SetWidgetValues(CreditCard* card) { | 709 void AutoFillCreditCardEditor::SetWidgetValues(CreditCard* card) { |
| 710 SetEntryText(name_, card, CREDIT_CARD_NAME); | 710 SetEntryText(name_, card, CREDIT_CARD_NAME); |
| 711 | 711 |
| 712 gtk_entry_set_text(GTK_ENTRY(number_), | 712 gtk_entry_set_text(GTK_ENTRY(number_), |
| 713 UTF16ToUTF8(card->ObfuscatedNumber()).c_str()); | 713 UTF16ToUTF8(card->ObfuscatedNumber()).c_str()); |
| 714 | 714 |
| 715 int month; | 715 int month; |
| 716 base::StringToInt(card->GetFieldText(AutofillType(CREDIT_CARD_EXP_MONTH)), | 716 base::StringToInt(card->GetFieldText(CREDIT_CARD_EXP_MONTH), |
| 717 &month); | 717 &month); |
| 718 if (month >= 1 && month <= 12) { | 718 if (month >= 1 && month <= 12) { |
| 719 gtk_combo_box_set_active(GTK_COMBO_BOX(month_), month - 1); | 719 gtk_combo_box_set_active(GTK_COMBO_BOX(month_), month - 1); |
| 720 } else { | 720 } else { |
| 721 gtk_combo_box_set_active(GTK_COMBO_BOX(month_), 0); | 721 gtk_combo_box_set_active(GTK_COMBO_BOX(month_), 0); |
| 722 } | 722 } |
| 723 | 723 |
| 724 int year; | 724 int year; |
| 725 if (!base::StringToInt( | 725 if (!base::StringToInt( |
| 726 card->GetFieldText(AutofillType(CREDIT_CARD_EXP_4_DIGIT_YEAR)), | 726 card->GetFieldText(CREDIT_CARD_EXP_4_DIGIT_YEAR), |
| 727 &year)) { | 727 &year)) { |
| 728 NOTREACHED(); | 728 NOTREACHED(); |
| 729 } | 729 } |
| 730 if (year >= base_year_ && year < base_year_ + kNumYears) | 730 if (year >= base_year_ && year < base_year_ + kNumYears) |
| 731 gtk_combo_box_set_active(GTK_COMBO_BOX(year_), year - base_year_); | 731 gtk_combo_box_set_active(GTK_COMBO_BOX(year_), year - base_year_); |
| 732 else | 732 else |
| 733 gtk_combo_box_set_active(GTK_COMBO_BOX(year_), 0); | 733 gtk_combo_box_set_active(GTK_COMBO_BOX(year_), 0); |
| 734 } | 734 } |
| 735 | 735 |
| 736 void AutoFillCreditCardEditor::ApplyEdits() { | 736 void AutoFillCreditCardEditor::ApplyEdits() { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 774 CreditCard* card) { | 774 CreditCard* card) { |
| 775 SetFormValue(name_, card, CREDIT_CARD_NAME); | 775 SetFormValue(name_, card, CREDIT_CARD_NAME); |
| 776 | 776 |
| 777 if (edited_number_) | 777 if (edited_number_) |
| 778 SetFormValue(number_, card, CREDIT_CARD_NUMBER); | 778 SetFormValue(number_, card, CREDIT_CARD_NUMBER); |
| 779 | 779 |
| 780 int selected_month_index = | 780 int selected_month_index = |
| 781 gtk_combo_box_get_active(GTK_COMBO_BOX(month_)); | 781 gtk_combo_box_get_active(GTK_COMBO_BOX(month_)); |
| 782 if (selected_month_index == -1) | 782 if (selected_month_index == -1) |
| 783 selected_month_index = 0; | 783 selected_month_index = 0; |
| 784 card->SetInfo(AutofillType(CREDIT_CARD_EXP_MONTH), | 784 card->SetInfo(CREDIT_CARD_EXP_MONTH, |
| 785 base::IntToString16(selected_month_index + 1)); | 785 base::IntToString16(selected_month_index + 1)); |
| 786 | 786 |
| 787 int selected_year_index = | 787 int selected_year_index = |
| 788 gtk_combo_box_get_active(GTK_COMBO_BOX(year_)); | 788 gtk_combo_box_get_active(GTK_COMBO_BOX(year_)); |
| 789 if (selected_year_index == -1) | 789 if (selected_year_index == -1) |
| 790 selected_year_index = 0; | 790 selected_year_index = 0; |
| 791 card->SetInfo(AutofillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), | 791 card->SetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, |
| 792 base::IntToString16(selected_year_index + base_year_)); | 792 base::IntToString16(selected_year_index + base_year_)); |
| 793 } | 793 } |
| 794 | 794 |
| 795 void AutoFillCreditCardEditor::UpdateOkButton() { | 795 void AutoFillCreditCardEditor::UpdateOkButton() { |
| 796 // Enable the ok button if at least one field is non-empty and the phone | 796 // Enable the ok button if at least one field is non-empty and the phone |
| 797 // numbers are valid. | 797 // numbers are valid. |
| 798 bool valid = !GetEntryText(name_).empty() || !GetEntryText(number_).empty(); | 798 bool valid = !GetEntryText(name_).empty() || !GetEntryText(number_).empty(); |
| 799 gtk_widget_set_sensitive(ok_button_, valid); | 799 gtk_widget_set_sensitive(ok_button_, valid); |
| 800 } | 800 } |
| 801 | 801 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 866 new AutofillProfileEditor(observer, profile, auto_fill_profile); | 866 new AutofillProfileEditor(observer, profile, auto_fill_profile); |
| 867 } | 867 } |
| 868 | 868 |
| 869 void ShowAutoFillCreditCardEditor(gfx::NativeView parent, | 869 void ShowAutoFillCreditCardEditor(gfx::NativeView parent, |
| 870 AutoFillDialogObserver* observer, | 870 AutoFillDialogObserver* observer, |
| 871 Profile* profile, | 871 Profile* profile, |
| 872 CreditCard* credit_card) { | 872 CreditCard* credit_card) { |
| 873 // AutoFillCreditCardEditor takes care of deleting itself. | 873 // AutoFillCreditCardEditor takes care of deleting itself. |
| 874 new AutoFillCreditCardEditor(observer, profile, credit_card); | 874 new AutoFillCreditCardEditor(observer, profile, credit_card); |
| 875 } | 875 } |
| OLD | NEW |