diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-15 20:58:44 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-15 20:58:44 +0000 |
commit | 9aa4ed8e23f966aee43960856be87d2b722aca7f (patch) | |
tree | cd224dd79ab35301ee5cb0650525aa32a3bb9c7e /chrome | |
parent | 3b098dc68835305b3f9945cec17df3c221284ea1 (diff) | |
download | chromium_src-9aa4ed8e23f966aee43960856be87d2b722aca7f.zip chromium_src-9aa4ed8e23f966aee43960856be87d2b722aca7f.tar.gz chromium_src-9aa4ed8e23f966aee43960856be87d2b722aca7f.tar.bz2 |
Simplify the gtk AutoFill dialog and bring it more in line with the mocks.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/551034
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36402 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/app/generated_resources.grd | 18 | ||||
-rw-r--r-- | chrome/app/resources/locale_settings.grd | 7 | ||||
-rw-r--r-- | chrome/browser/autofill/autofill_dialog_gtk.cc | 388 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_manager_gtk.cc | 8 | ||||
-rw-r--r-- | chrome/browser/gtk/clear_browsing_data_dialog_gtk.cc | 7 | ||||
-rw-r--r-- | chrome/browser/gtk/create_application_shortcuts_dialog_gtk.cc | 7 | ||||
-rw-r--r-- | chrome/browser/gtk/first_run_dialog.cc | 7 | ||||
-rw-r--r-- | chrome/browser/gtk/import_dialog_gtk.cc | 7 | ||||
-rw-r--r-- | chrome/browser/gtk/keyword_editor_view.cc | 11 | ||||
-rw-r--r-- | chrome/browser/gtk/options/passwords_exceptions_window_gtk.cc | 11 | ||||
-rw-r--r-- | chrome/browser/gtk/options/url_picker_dialog_gtk.cc | 13 | ||||
-rw-r--r-- | chrome/common/gtk_util.cc | 18 | ||||
-rw-r--r-- | chrome/common/gtk_util.h | 8 |
13 files changed, 206 insertions, 304 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index d91e209..5361c23 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -4569,14 +4569,20 @@ Keep your key file in a safe place. You will need it to create new versions of y <message name="IDS_AUTOFILL_CREDITCARDS_GROUP_NAME" desc="The name of the Credit Cards group of the AutoFill dialog."> Credit Cards </message> - <message name="IDS_AUTOFILL_ADD_BUTTON" desc="The label of the button that adds a new AutoFill profile."> - Add... + <message name="IDS_AUTOFILL_ADD_ADDRESS_BUTTON" desc="The label of the button that adds a new AutoFill address."> + Add an address </message> - <message name="IDS_AUTOFILL_EDIT_BUTTON" desc="The label of the button that edits an AutoFill profile."> - Edit... + <message name="IDS_AUTOFILL_ADD_CREDITCARD_BUTTON" desc="The label of the button that adds a new AutoFill credit card."> + Add a credit card </message> - <message name="IDS_AUTOFILL_REMOVE_BUTTON" desc="The label of the button that removes an AutoFill profile."> - Remove + <message name="IDS_AUTOFILL_DELETE_BUTTON" desc="The label of the button that deletes an AutoFill profile."> + Delete + </message> + <message name="IDS_AUTOFILL_NEW_ADDRESS" desc="The profile label of a new address."> + New address + </message> + <message name="IDS_AUTOFILL_NEW_CREDITCARD" desc="The profile label of a new credit card."> + New credit card </message> <message name="IDS_THEMES_GROUP_NAME" desc="The title of the themes group"> diff --git a/chrome/app/resources/locale_settings.grd b/chrome/app/resources/locale_settings.grd index b6e8788..ae4e79d 100644 --- a/chrome/app/resources/locale_settings.grd +++ b/chrome/app/resources/locale_settings.grd @@ -676,10 +676,15 @@ 55 </message> - <!-- The width for the AutoFill dialog in characters. --> + <!-- The width of the AutoFill dialog in characters. --> <message name="IDS_AUTOFILL_DIALOG_WIDTH_CHARS" use_name_for_id="true"> 80 </message> + + <!-- The height of the AutoFill dialog in lines. --> + <message name="IDS_AUTOFILL_DIALOG_HEIGHT_LINES" use_name_for_id="true"> + 30 + </message> </messages> </release> </grit> diff --git a/chrome/browser/autofill/autofill_dialog_gtk.cc b/chrome/browser/autofill/autofill_dialog_gtk.cc index 6752f41..3c7b1b3 100644 --- a/chrome/browser/autofill/autofill_dialog_gtk.cc +++ b/chrome/browser/autofill/autofill_dialog_gtk.cc @@ -8,32 +8,54 @@ #include <vector> +#include "app/gfx/gtk_util.h" #include "app/l10n_util.h" #include "base/message_loop.h" +#include "chrome/browser/autofill/autofill_profile.h" +#include "chrome/browser/autofill/form_group.h" #include "chrome/browser/gtk/options/options_layout_gtk.h" #include "chrome/common/gtk_util.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" -// Column IDs for |addresses_model_|. -enum { - ADDRESSES_COL_LABEL, - ADDRESSES_COL_COUNT, -}; +namespace { -// Column IDs for |creditcards_model_|. -enum { - CREDITCARDS_COL_LABEL, - CREDITCARDS_COL_COUNT, -}; +// Style for dialog group titles. +const char kDialogGroupTitleMarkup[] = "<span weight='bold'>%s</span>"; + +// How far we indent dialog widgets, in pixels. +const int kAutoFillDialogIndent = 5; + +// Adds an alignment around |widget| which indents the widget by +// |kAutoFillDialogIndent|. +GtkWidget* IndentWidget(GtkWidget* widget) { + GtkWidget* alignment = gtk_alignment_new(0, 0, 0, 0); + gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), 0, 0, + kAutoFillDialogIndent, 0); + gtk_container_add(GTK_CONTAINER(alignment), widget); + return alignment; +} + +// Makes sure we use the gtk theme colors by loading the base color of an entry +// widget. +void SetWhiteBackground(GtkWidget* widget) { + GtkWidget* entry = gtk_entry_new(); + gtk_widget_ensure_style(entry); + GtkStyle* style = gtk_widget_get_style(entry); + gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, + &style->base[GTK_STATE_NORMAL]); + gtk_widget_destroy(entry); +} + +} // namespace // The contents of the AutoFill dialog. This dialog allows users to add, edit // and remove AutoFill profiles. class AutoFillDialog { public: - explicit AutoFillDialog(std::vector<AutoFillProfile>* profiles, - std::vector<FormGroup>* credit_cards); + AutoFillDialog(std::vector<AutoFillProfile>* profiles, + std::vector<FormGroup>* credit_cards); ~AutoFillDialog() {} // Shows the AutoFill dialog. @@ -44,33 +66,25 @@ class AutoFillDialog { // from here. static void OnDestroy(GtkWidget* widget, AutoFillDialog* autofill_dialog); - // 'changed' signal handler which notifies us when the user has selected a - // different Address profile. - static void OnAddressesSelectionChanged(GtkTreeSelection *selection, - AutoFillDialog* dialog); - - // 'changed' signal handler which notifies us when the user has selected a - // different CreditCard profile. - static void OnCreditCardSelectionChanged(GtkTreeSelection *selection, - AutoFillDialog* dialog); - - // 'clicked' signal handler which is sent when a user clicks on one of the - // Add/Edit/Remove Address buttons. + // 'clicked' signal handler. We add a new address. static void OnAddAddressClicked(GtkButton* button, AutoFillDialog* dialog); - static void OnEditAddressClicked(GtkButton* button, AutoFillDialog* dialog); - static void OnRemoveAddressClicked(GtkButton* button, AutoFillDialog* dialog); - // 'clicked' signal handler which is sent when a user clicks on one of the - // Add/Edit/Remove Credit Card buttons. + // 'clicked' signal handler. We add a new credit card. static void OnAddCreditCardClicked(GtkButton* button, AutoFillDialog* dialog); - static void OnEditCreditCardClicked(GtkButton* button, - AutoFillDialog* dialog); - static void OnRemoveCreditCardClicked(GtkButton* button, - AutoFillDialog* dialog); - // Initialize the group widgets, return their container. - GtkWidget* InitAddressesGroup(); - GtkWidget* InitCreditCardsGroup(); + // Initializes the group widgets and returns their container. |name_id| is + // the resource ID of the group label. |button_id| is the resource name of + // the button label. |clicked_callback| is a callback that handles the + // 'clicked' signal emitted when the user presses the 'Add' button. + GtkWidget* InitGroup(int label_id, + int button_id, + GCallback clicked_callback); + + // Returns a GtkExpander that is added to the appropriate vbox. Each method + // adds the necessary widgets and layout required to fill out information + // for either an address or a credit card. + GtkWidget* AddNewAddress(); + GtkWidget* AddNewCreditCard(); // The list of current AutoFill profiles. Owned by AutoFillManager. std::vector<AutoFillProfile>* profiles_; @@ -81,27 +95,11 @@ class AutoFillDialog { // The AutoFill dialog. GtkWidget* dialog_; - // Widgets of the Addresses group. - GtkWidget* addresses_tree_; - GtkListStore* addresses_model_; - GtkTreeSelection* addresses_selection_; - // TODO(jhawkins): We might not need to store these widgets. The add button - // should never need to be desensitized, but we should desensitize the edit - // and remove buttons if there is no current selection. - GtkWidget* addresses_add_button_; - GtkWidget* addresses_edit_button_; - GtkWidget* addresses_remove_button_; - - // Widgets of the Credit Cards group. - GtkWidget* creditcards_tree_; - GtkListStore* creditcards_model_; - GtkTreeSelection* creditcards_selection_; - // TODO(jhawkins): We might not need to store these widgets. The add button - // should never need to be desensitized, but we should desensitize the edit - // and remove buttons if there is no current selection. - GtkWidget* creditcards_add_button_; - GtkWidget* creditcards_edit_button_; - GtkWidget* creditcards_remove_button_; + // The addresses group. + GtkWidget* addresses_vbox_; + + // The credit cards group. + GtkWidget* creditcards_vbox_; DISALLOW_COPY_AND_ASSIGN(AutoFillDialog); }; @@ -119,14 +117,19 @@ AutoFillDialog::AutoFillDialog(std::vector<AutoFillProfile>* profiles, NULL, // Non-modal. GTK_DIALOG_NO_SEPARATOR, - GTK_STOCK_CLOSE, - GTK_RESPONSE_CLOSE, + GTK_STOCK_APPLY, + GTK_RESPONSE_APPLY, + GTK_STOCK_CANCEL, + GTK_RESPONSE_CANCEL, + GTK_STOCK_OK, + GTK_RESPONSE_OK, NULL); gtk_widget_realize(dialog_); - gtk_util::SetWindowWidthFromResources(GTK_WINDOW(dialog_), - IDS_AUTOFILL_DIALOG_WIDTH_CHARS, - true); + gtk_util::SetWindowSizeFromResources(GTK_WINDOW(dialog_), + IDS_AUTOFILL_DIALOG_WIDTH_CHARS, + IDS_AUTOFILL_DIALOG_HEIGHT_LINES, + true); // Allow browser windows to go in front of the AutoFill dialog in Metacity. gtk_window_set_type_hint(GTK_WINDOW(dialog_), GDK_WINDOW_TYPE_HINT_NORMAL); @@ -135,16 +138,39 @@ AutoFillDialog::AutoFillDialog(std::vector<AutoFillProfile>* profiles, g_signal_connect(dialog_, "response", G_CALLBACK(gtk_widget_destroy), NULL); g_signal_connect(dialog_, "destroy", G_CALLBACK(OnDestroy), this); - // TODO(jhawkins): Refactor OptionsLayoutBuilderGtk out of gtk/options. - OptionsLayoutBuilderGtk options_builder; - options_builder.AddOptionGroup( - l10n_util::GetStringUTF8(IDS_AUTOFILL_ADDRESSES_GROUP_NAME), - InitAddressesGroup(), true); - options_builder.AddOptionGroup( - l10n_util::GetStringUTF8(IDS_AUTOFILL_CREDITCARDS_GROUP_NAME), - InitCreditCardsGroup(), true); - gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog_)->vbox), - options_builder.get_page_widget()); + // Allow the contents to be scrolled. + GtkWidget* scrolled_window = gtk_scrolled_window_new(NULL, NULL); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), + GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog_)->vbox), scrolled_window); + + // We create an event box so that we can color the frame background white. + GtkWidget* frame_event_box = gtk_event_box_new(); + SetWhiteBackground(frame_event_box); + gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window), + frame_event_box); + + // The frame outline of the content area. + GtkWidget* frame = gtk_frame_new(NULL); + gtk_container_add(GTK_CONTAINER(frame_event_box), frame); + + // The content vbox. + GtkWidget* outer_vbox = gtk_vbox_new(true, 0); + gtk_container_add(GTK_CONTAINER(frame), outer_vbox); + + addresses_vbox_ = InitGroup(IDS_AUTOFILL_ADDRESSES_GROUP_NAME, + IDS_AUTOFILL_ADD_ADDRESS_BUTTON, + G_CALLBACK(OnAddAddressClicked)); + gtk_box_pack_start_defaults(GTK_BOX(outer_vbox), addresses_vbox_); + + // TODO(jhawkins): Add addresses from |profiles|. + + creditcards_vbox_ = InitGroup(IDS_AUTOFILL_CREDITCARDS_GROUP_NAME, + IDS_AUTOFILL_ADD_CREDITCARD_BUTTON, + G_CALLBACK(OnAddCreditCardClicked)); + gtk_box_pack_start_defaults(GTK_BOX(outer_vbox), creditcards_vbox_); + + // TODO(jhawkins): Add credit cards from |credit_cards|. gtk_widget_show_all(dialog_); } @@ -162,201 +188,67 @@ void AutoFillDialog::OnDestroy(GtkWidget* widget, } // static -void AutoFillDialog::OnAddressesSelectionChanged(GtkTreeSelection *selection, - AutoFillDialog* dialog) { -} - -// static -void AutoFillDialog::OnCreditCardSelectionChanged(GtkTreeSelection *selection, - AutoFillDialog* dialog) { -} - -// static void AutoFillDialog::OnAddAddressClicked(GtkButton* button, AutoFillDialog* dialog) { - // TODO(jhawkins): Open the EditAddress dialog with an empty profile. -} - -// static -void AutoFillDialog::OnEditAddressClicked(GtkButton* button, - AutoFillDialog* dialog) { - // TODO(jhawkins): Implement the EditAddress dialog. -} - -// static -void AutoFillDialog::OnRemoveAddressClicked(GtkButton* button, - AutoFillDialog* dialog) { - // TODO(jhawkins): Remove the selected profile from |profiles_|. + GtkWidget* new_address = dialog->AddNewAddress(); + gtk_box_pack_start(GTK_BOX(dialog->addresses_vbox_), new_address, + FALSE, FALSE, 0); + gtk_widget_show(new_address); } // static void AutoFillDialog::OnAddCreditCardClicked(GtkButton* button, AutoFillDialog* dialog) { - // TODO(jhawkins): Open the EditCreditCard dialog with an empty profile. + GtkWidget* new_creditcard = dialog->AddNewCreditCard(); + gtk_box_pack_start(GTK_BOX(dialog->creditcards_vbox_), new_creditcard, + FALSE, FALSE, 0); + gtk_widget_show(new_creditcard); } -// static -void AutoFillDialog::OnEditCreditCardClicked(GtkButton* button, - AutoFillDialog* dialog) { - // TODO(jhawkins): Implement the EditAddress dialog. -} +GtkWidget* AutoFillDialog::InitGroup(int name_id, + int button_id, + GCallback clicked_callback) { + GtkWidget* vbox = gtk_vbox_new(false, gtk_util::kControlSpacing); + + // Group label. + GtkWidget* label = gtk_label_new(NULL); + char* markup = g_markup_printf_escaped( + kDialogGroupTitleMarkup, + l10n_util::GetStringUTF8(name_id).c_str()); + gtk_label_set_markup(GTK_LABEL(label), markup); + g_free(markup); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_box_pack_start(GTK_BOX(vbox), IndentWidget(label), FALSE, FALSE, 0); + + // Separator. + GtkWidget* separator = gtk_hseparator_new(); + gtk_box_pack_start(GTK_BOX(vbox), separator, FALSE, FALSE, 0); + + // Add profile button. + GtkWidget* button = gtk_button_new_with_label( + l10n_util::GetStringUTF8(name_id).c_str()); + g_signal_connect(button, "clicked", clicked_callback, this); + gtk_box_pack_end_defaults(GTK_BOX(vbox), IndentWidget(button)); -// static -void AutoFillDialog::OnRemoveCreditCardClicked(GtkButton* button, - AutoFillDialog* dialog) { - // TODO(jhawkins): Remove the selected profile from |profiles_|. + return vbox; } -GtkWidget* AutoFillDialog::InitAddressesGroup() { - GtkWidget* vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); - - // Addresses container hbox. - GtkWidget* addresses_container = gtk_hbox_new(FALSE, - gtk_util::kControlSpacing); - gtk_box_pack_start(GTK_BOX(vbox), addresses_container, TRUE, TRUE, 0); - - // Addresses container scroll window. - GtkWidget* scroll_window = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll_window), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scroll_window), - GTK_SHADOW_ETCHED_IN); - gtk_container_add(GTK_CONTAINER(addresses_container), scroll_window); - - addresses_model_ = gtk_list_store_new(ADDRESSES_COL_COUNT, - G_TYPE_STRING); - addresses_tree_ = gtk_tree_view_new_with_model( - GTK_TREE_MODEL(addresses_model_)); - - // Release |addresses_model_| so that |addresses_tree_| owns the model. - g_object_unref(addresses_model_); - - gtk_container_add(GTK_CONTAINER(scroll_window), addresses_tree_); - gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(addresses_tree_), FALSE); - - // Addresses column. - GtkTreeViewColumn* column; - GtkCellRenderer* renderer = gtk_cell_renderer_text_new(); - column = gtk_tree_view_column_new_with_attributes("label", - renderer, - "text", ADDRESSES_COL_LABEL, - NULL); - gtk_tree_view_append_column(GTK_TREE_VIEW(addresses_tree_), column); - - // Addresses selection. - addresses_selection_ = gtk_tree_view_get_selection( - GTK_TREE_VIEW(addresses_tree_)); - gtk_tree_selection_set_mode(addresses_selection_, GTK_SELECTION_SINGLE); - g_signal_connect(G_OBJECT(addresses_selection_), "changed", - G_CALLBACK(OnAddressesSelectionChanged), this); - - GtkWidget* addresses_buttons = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); - gtk_box_pack_end(GTK_BOX(addresses_container), addresses_buttons, - FALSE, FALSE, 0); - - // Add Address button. - addresses_add_button_ = gtk_button_new_with_label( - l10n_util::GetStringUTF8(IDS_AUTOFILL_ADD_BUTTON).c_str()); - g_signal_connect(G_OBJECT(addresses_add_button_), "clicked", - G_CALLBACK(OnAddAddressClicked), this); - gtk_box_pack_start(GTK_BOX(addresses_buttons), addresses_add_button_, - FALSE, FALSE, 0); - - // Edit Address button. - addresses_edit_button_ = gtk_button_new_with_label( - l10n_util::GetStringUTF8(IDS_AUTOFILL_EDIT_BUTTON).c_str()); - g_signal_connect(G_OBJECT(addresses_edit_button_), "clicked", - G_CALLBACK(OnEditAddressClicked), this); - gtk_box_pack_start(GTK_BOX(addresses_buttons), addresses_edit_button_, - FALSE, FALSE, 0); +GtkWidget* AutoFillDialog::AddNewAddress() { + GtkWidget* address = gtk_expander_new( + l10n_util::GetStringUTF8(IDS_AUTOFILL_NEW_ADDRESS).c_str()); - // Remove Address button. - addresses_remove_button_ = gtk_button_new_with_label( - l10n_util::GetStringUTF8(IDS_AUTOFILL_REMOVE_BUTTON).c_str()); - g_signal_connect(G_OBJECT(addresses_remove_button_), "clicked", - G_CALLBACK(OnRemoveAddressClicked), this); - gtk_box_pack_start(GTK_BOX(addresses_buttons), addresses_remove_button_, - FALSE, FALSE, 0); + // TODO(jhawkins): Implement the address form. - return vbox; + return address; } -GtkWidget* AutoFillDialog::InitCreditCardsGroup() { - GtkWidget* vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); - - // Credit Cards container hbox. - GtkWidget* creditcards_container = gtk_hbox_new(FALSE, - gtk_util::kControlSpacing); - gtk_box_pack_start(GTK_BOX(vbox), creditcards_container, TRUE, TRUE, 0); - - // Credit Cards container scroll window. - GtkWidget* scroll_window = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll_window), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scroll_window), - GTK_SHADOW_ETCHED_IN); - gtk_container_add(GTK_CONTAINER(creditcards_container), scroll_window); - - creditcards_model_ = gtk_list_store_new(CREDITCARDS_COL_COUNT, - G_TYPE_STRING); - creditcards_tree_ = gtk_tree_view_new_with_model( - GTK_TREE_MODEL(creditcards_model_)); - - // Release |creditcards_model_| so that |creditcards_tree_| owns the model. - g_object_unref(creditcards_model_); - - gtk_container_add(GTK_CONTAINER(scroll_window), creditcards_tree_); - gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(creditcards_tree_), FALSE); - - // Credit Cards column. - GtkTreeViewColumn* column; - GtkCellRenderer* renderer = gtk_cell_renderer_text_new(); - column = gtk_tree_view_column_new_with_attributes( - "label", - renderer, - "text", CREDITCARDS_COL_LABEL, - NULL); - gtk_tree_view_append_column(GTK_TREE_VIEW(creditcards_tree_), column); - - // Credit Cards selection. - creditcards_selection_ = gtk_tree_view_get_selection( - GTK_TREE_VIEW(creditcards_tree_)); - gtk_tree_selection_set_mode(creditcards_selection_, GTK_SELECTION_SINGLE); - g_signal_connect(G_OBJECT(creditcards_selection_), "changed", - G_CALLBACK(OnCreditCardSelectionChanged), this); - - GtkWidget* creditcards_buttons = gtk_vbox_new(FALSE, - gtk_util::kControlSpacing); - gtk_box_pack_end(GTK_BOX(creditcards_container), creditcards_buttons, - FALSE, FALSE, 0); - - // Address Add button. - creditcards_add_button_ = gtk_button_new_with_label( - l10n_util::GetStringUTF8(IDS_AUTOFILL_ADD_BUTTON).c_str()); - g_signal_connect(G_OBJECT(creditcards_add_button_), "clicked", - G_CALLBACK(OnAddCreditCardClicked), this); - gtk_box_pack_start(GTK_BOX(creditcards_buttons), creditcards_add_button_, - FALSE, FALSE, 0); - - // Credit Cards Edit button. - creditcards_edit_button_ = gtk_button_new_with_label( - l10n_util::GetStringUTF8(IDS_AUTOFILL_EDIT_BUTTON).c_str()); - g_signal_connect(G_OBJECT(creditcards_edit_button_), "clicked", - G_CALLBACK(OnEditCreditCardClicked), this); - gtk_box_pack_start(GTK_BOX(creditcards_buttons), creditcards_edit_button_, - FALSE, FALSE, 0); +GtkWidget* AutoFillDialog::AddNewCreditCard() { + GtkWidget* credit_card = gtk_expander_new( + l10n_util::GetStringUTF8(IDS_AUTOFILL_NEW_CREDITCARD).c_str()); - // Address Remove button. - creditcards_remove_button_ = gtk_button_new_with_label( - l10n_util::GetStringUTF8(IDS_AUTOFILL_REMOVE_BUTTON).c_str()); - g_signal_connect(G_OBJECT(creditcards_remove_button_), "clicked", - G_CALLBACK(OnRemoveCreditCardClicked), this); - gtk_box_pack_start(GTK_BOX(creditcards_buttons), creditcards_remove_button_, - FALSE, FALSE, 0); + // TODO(jhawkins): Implement the credit card form. - return vbox; + return credit_card; } /////////////////////////////////////////////////////////////////////////////// diff --git a/chrome/browser/gtk/bookmark_manager_gtk.cc b/chrome/browser/gtk/bookmark_manager_gtk.cc index a7e5ee7..11100af 100644 --- a/chrome/browser/gtk/bookmark_manager_gtk.cc +++ b/chrome/browser/gtk/bookmark_manager_gtk.cc @@ -607,13 +607,11 @@ void BookmarkManagerGtk::SetInitialWindowSize() { // Otherwise, just set a default size (GTK will override this if it's not // large enough to hold the window's contents). gtk_widget_realize(window_); - int width = 1, height = 1; - gtk_util::GetWidgetSizeFromResources( - window_, + gtk_util::SetWindowSizeFromResources( + GTK_WINDOW(window_), IDS_BOOKMARK_MANAGER_DIALOG_WIDTH_CHARS, IDS_BOOKMARK_MANAGER_DIALOG_HEIGHT_LINES, - &width, &height); - gtk_window_set_default_size(GTK_WINDOW(window_), width, height); + true); } void BookmarkManagerGtk::ResetOrganizeMenu(bool left) { diff --git a/chrome/browser/gtk/clear_browsing_data_dialog_gtk.cc b/chrome/browser/gtk/clear_browsing_data_dialog_gtk.cc index 6259923..2064241 100644 --- a/chrome/browser/gtk/clear_browsing_data_dialog_gtk.cc +++ b/chrome/browser/gtk/clear_browsing_data_dialog_gtk.cc @@ -31,9 +31,10 @@ ClearBrowsingDataDialogGtk::ClearBrowsingDataDialogGtk(GtkWindow* parent, GTK_RESPONSE_REJECT, NULL); gtk_widget_realize(dialog); - gtk_util::SetWindowWidthFromResources(GTK_WINDOW(dialog), - IDS_CLEARDATA_DIALOG_WIDTH_CHARS, - /* resizable */ false); + gtk_util::SetWindowSizeFromResources(GTK_WINDOW(dialog), + IDS_CLEARDATA_DIALOG_WIDTH_CHARS, + -1, // height + false); // resizable gtk_util::AddButtonToDialog(dialog, l10n_util::GetStringUTF8(IDS_CLEAR_BROWSING_DATA_COMMIT).c_str(), GTK_STOCK_APPLY, GTK_RESPONSE_ACCEPT); diff --git a/chrome/browser/gtk/create_application_shortcuts_dialog_gtk.cc b/chrome/browser/gtk/create_application_shortcuts_dialog_gtk.cc index 61105d3..1907fba 100644 --- a/chrome/browser/gtk/create_application_shortcuts_dialog_gtk.cc +++ b/chrome/browser/gtk/create_application_shortcuts_dialog_gtk.cc @@ -35,9 +35,10 @@ CreateApplicationShortcutsDialogGtk::CreateApplicationShortcutsDialogGtk( GTK_RESPONSE_REJECT, NULL); gtk_widget_realize(dialog); - gtk_util::SetWindowWidthFromResources(GTK_WINDOW(dialog), - IDS_CREATE_SHORTCUTS_DIALOG_WIDTH_CHARS, - /* resizable */ false); + gtk_util::SetWindowSizeFromResources(GTK_WINDOW(dialog), + IDS_CREATE_SHORTCUTS_DIALOG_WIDTH_CHARS, + -1, // height + false); // resizable gtk_util::AddButtonToDialog(dialog, l10n_util::GetStringUTF8(IDS_CREATE_SHORTCUTS_COMMIT).c_str(), GTK_STOCK_APPLY, GTK_RESPONSE_ACCEPT); diff --git a/chrome/browser/gtk/first_run_dialog.cc b/chrome/browser/gtk/first_run_dialog.cc index 6f3fc68..6bbb630 100644 --- a/chrome/browser/gtk/first_run_dialog.cc +++ b/chrome/browser/gtk/first_run_dialog.cc @@ -63,12 +63,11 @@ FirstRunDialog::FirstRunDialog(Profile* profile, int& response) gtk_window_set_resizable(GTK_WINDOW(dialog_), FALSE); gtk_widget_realize(dialog_); - int width, height; - gtk_util::GetWidgetSizeFromResources(dialog_, + gtk_util::SetWindowSizeFromResources(GTK_WINDOW(dialog_), IDS_FIRSTRUN_DIALOG_WIDTH_CHARS, IDS_FIRSTRUN_DIALOG_HEIGHT_LINES, - &width, &height); - gtk_window_set_default_size(GTK_WINDOW(dialog_), width, height); + true); + g_signal_connect(G_OBJECT(dialog_), "delete-event", G_CALLBACK(gtk_widget_hide_on_delete), NULL); diff --git a/chrome/browser/gtk/import_dialog_gtk.cc b/chrome/browser/gtk/import_dialog_gtk.cc index 443d453..877e07c 100644 --- a/chrome/browser/gtk/import_dialog_gtk.cc +++ b/chrome/browser/gtk/import_dialog_gtk.cc @@ -37,9 +37,10 @@ ImportDialogGtk::ImportDialogGtk(GtkWindow* parent, Profile* profile) GTK_RESPONSE_REJECT, NULL); gtk_widget_realize(dialog_); - gtk_util::SetWindowWidthFromResources(GTK_WINDOW(dialog_), - IDS_IMPORT_DIALOG_WIDTH_CHARS, - /* resizable */ false); + gtk_util::SetWindowSizeFromResources(GTK_WINDOW(dialog_), + IDS_IMPORT_DIALOG_WIDTH_CHARS, + -1, // height + false); // resizable importer_host_->set_parent_window(GTK_WINDOW(dialog_)); // Add import button separately as we might need to disable it, if diff --git a/chrome/browser/gtk/keyword_editor_view.cc b/chrome/browser/gtk/keyword_editor_view.cc index 7ed31ed..541782b 100644 --- a/chrome/browser/gtk/keyword_editor_view.cc +++ b/chrome/browser/gtk/keyword_editor_view.cc @@ -190,13 +190,10 @@ void KeywordEditorView::Init() { // Set the size of the dialog. gtk_widget_realize(dialog_); - int width = 1, height = 1; - gtk_util::GetWidgetSizeFromResources( - dialog_, - IDS_SEARCHENGINES_DIALOG_WIDTH_CHARS, - IDS_SEARCHENGINES_DIALOG_HEIGHT_LINES, - &width, &height); - gtk_window_set_default_size(GTK_WINDOW(dialog_), width, height); + gtk_util::SetWindowSizeFromResources(GTK_WINDOW(dialog_), + IDS_SEARCHENGINES_DIALOG_WIDTH_CHARS, + IDS_SEARCHENGINES_DIALOG_HEIGHT_LINES, + true); g_signal_connect(dialog_, "response", G_CALLBACK(OnResponse), this); g_signal_connect(dialog_, "destroy", G_CALLBACK(OnWindowDestroy), this); diff --git a/chrome/browser/gtk/options/passwords_exceptions_window_gtk.cc b/chrome/browser/gtk/options/passwords_exceptions_window_gtk.cc index 811ceaa..4f5be8f 100644 --- a/chrome/browser/gtk/options/passwords_exceptions_window_gtk.cc +++ b/chrome/browser/gtk/options/passwords_exceptions_window_gtk.cc @@ -91,13 +91,10 @@ PasswordsExceptionsWindowGtk::PasswordsExceptionsWindowGtk(Profile* profile) gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog_)->vbox), notebook_); gtk_widget_realize(dialog_); - int width = 1, height = 1; - gtk_util::GetWidgetSizeFromResources( - dialog_, - IDS_PASSWORDS_DIALOG_WIDTH_CHARS, - IDS_PASSWORDS_DIALOG_HEIGHT_LINES, - &width, &height); - gtk_window_set_default_size(GTK_WINDOW(dialog_), width, height); + gtk_util::SetWindowSizeFromResources(GTK_WINDOW(dialog_), + IDS_PASSWORDS_DIALOG_WIDTH_CHARS, + IDS_PASSWORDS_DIALOG_HEIGHT_LINES, + true); // We only have one button and don't do any special handling, so just hook it // directly to gtk_widget_destroy. diff --git a/chrome/browser/gtk/options/url_picker_dialog_gtk.cc b/chrome/browser/gtk/options/url_picker_dialog_gtk.cc index f7198b4..de472f8 100644 --- a/chrome/browser/gtk/options/url_picker_dialog_gtk.cc +++ b/chrome/browser/gtk/options/url_picker_dialog_gtk.cc @@ -152,14 +152,13 @@ UrlPickerDialogGtk::UrlPickerDialogGtk(UrlPickerCallback* callback, // Set the size of the dialog. gtk_widget_realize(dialog_); - int width = 1, height = 1; - gtk_util::GetWidgetSizeFromResources( - dialog_, - IDS_URLPICKER_DIALOG_WIDTH_CHARS, - IDS_URLPICKER_DIALOG_HEIGHT_LINES, - &width, &height); - gtk_window_set_default_size(GTK_WINDOW(dialog_), width, height); + gtk_util::SetWindowSizeFromResources(GTK_WINDOW(dialog_), + IDS_URLPICKER_DIALOG_WIDTH_CHARS, + IDS_URLPICKER_DIALOG_HEIGHT_LINES, + true); + // Set the width of the first column as well. + int width; gtk_util::GetWidgetSizeFromResources( dialog_, IDS_URLPICKER_DIALOG_LEFT_COLUMN_WIDTH_CHARS, 0, diff --git a/chrome/common/gtk_util.cc b/chrome/common/gtk_util.cc index 469ff08..62b7465 100644 --- a/chrome/common/gtk_util.cc +++ b/chrome/common/gtk_util.cc @@ -8,6 +8,7 @@ #include <gdk/gdkx.h> #include <cstdarg> +#include <map> #include "app/l10n_util.h" #include "app/resource_bundle.h" @@ -223,15 +224,18 @@ void GetWidgetSizeFromCharacters(GtkWidget* widget, double width_chars, g_object_unref(context); } -void SetWindowWidthFromResources(GtkWindow* window, int resource_id, - bool resizable) { - int width; - gtk_util::GetWidgetSizeFromResources(GTK_WIDGET(window), resource_id, 0, - &width, NULL); +void SetWindowSizeFromResources(GtkWindow* window, + int width_id, int height_id, bool resizable) { + int width = -1; + int height = -1; + gtk_util::GetWidgetSizeFromResources(GTK_WIDGET(window), width_id, height_id, + (width_id != -1) ? &width : NULL, + (height_id != -1) ? &height : NULL); + if (resizable) { - gtk_window_set_default_size(window, width, -1); + gtk_window_set_default_size(window, width, height); } else { - gtk_widget_set_size_request(GTK_WIDGET(window), width, -1); + gtk_widget_set_size_request(GTK_WIDGET(window), width, height); } gtk_window_set_resizable(window, resizable ? TRUE : FALSE); } diff --git a/chrome/common/gtk_util.h b/chrome/common/gtk_util.h index 389026e..4bf75fd 100644 --- a/chrome/common/gtk_util.h +++ b/chrome/common/gtk_util.h @@ -82,12 +82,14 @@ void GetWidgetSizeFromResources(GtkWidget* widget, int width_chars, void GetWidgetSizeFromCharacters(GtkWidget* widget, double width_chars, double height_lines, int* width, int* height); -// As above, but a convenience method for configuring dialog width. +// As above, but a convenience method for configuring dialog size. +// |width_id| and |height_id| are resource IDs for the size. If either of these +// are set to -1, the respective size will be set to the widget default. // |resizable| also controls whether the dialog will be resizable // (this info is also necessary for getting the width-setting code // right). -void SetWindowWidthFromResources(GtkWindow* window, int resource_id, - bool resizable); +void SetWindowSizeFromResources(GtkWindow* window, + int width_id, int height_id, bool resizable); // Remove all children from this container. void RemoveAllChildren(GtkWidget* container); |