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

Side by Side Diff: chrome/browser/autofill/autofill_dialog_gtk.cc

Issue 545175: Add the ability to save and remove AutoFill profiles from the AutoFillDialog.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 11 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
« no previous file with comments | « chrome/browser/autofill/autofill_dialog.cc ('k') | chrome/browser/autofill/autofill_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 <vector> 9 #include <vector>
10 10
11 #include "app/gfx/gtk_util.h" 11 #include "app/gfx/gtk_util.h"
12 #include "app/l10n_util.h" 12 #include "app/l10n_util.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/message_loop.h" 14 #include "base/message_loop.h"
15 #include "chrome/browser/autofill/autofill_profile.h" 15 #include "chrome/browser/autofill/autofill_profile.h"
16 #include "chrome/browser/autofill/credit_card.h" 16 #include "chrome/browser/autofill/credit_card.h"
17 #include "chrome/browser/autofill/form_group.h" 17 #include "chrome/browser/autofill/form_group.h"
18 #include "chrome/browser/gtk/options/options_layout_gtk.h" 18 #include "chrome/browser/gtk/options/options_layout_gtk.h"
19 #include "chrome/common/gtk_util.h" 19 #include "chrome/common/gtk_util.h"
20 #include "grit/chromium_strings.h" 20 #include "grit/chromium_strings.h"
21 #include "grit/generated_resources.h" 21 #include "grit/generated_resources.h"
22 #include "grit/locale_settings.h" 22 #include "grit/locale_settings.h"
23 23
24 namespace { 24 namespace {
25 25
26 // Style for dialog group titles. 26 // Style for dialog group titles.
27 const char kDialogGroupTitleMarkup[] = "<span weight='bold'>%s</span>"; 27 const char kDialogGroupTitleMarkup[] = "<span weight='bold'>%s</span>";
28 28
29 // The name of the object property used to store an entry widget pointer on
30 // another widget.
31 const char kButtonDataKey[] = "label-entry";
32
29 // How far we indent dialog widgets, in pixels. 33 // How far we indent dialog widgets, in pixels.
30 const int kAutoFillDialogIndent = 5; 34 const int kAutoFillDialogIndent = 5;
31 35
32 // All of these widgets are GtkEntrys except for default_profile, which is a 36 // All of these widgets are GtkEntrys except for default_profile, which is a
33 // GtkCheckButton. 37 // GtkCheckButton.
34 typedef struct _AddressWidgets { 38 typedef struct _AddressWidgets {
35 GtkWidget* label; 39 GtkWidget* label;
36 GtkWidget* default_profile; 40 GtkWidget* default_profile;
37 GtkWidget* first_name; 41 GtkWidget* first_name;
38 GtkWidget* middle_name; 42 GtkWidget* middle_name;
(...skipping 27 matching lines...) Expand all
66 // widget. 70 // widget.
67 void SetWhiteBackground(GtkWidget* widget) { 71 void SetWhiteBackground(GtkWidget* widget) {
68 GtkWidget* entry = gtk_entry_new(); 72 GtkWidget* entry = gtk_entry_new();
69 gtk_widget_ensure_style(entry); 73 gtk_widget_ensure_style(entry);
70 GtkStyle* style = gtk_widget_get_style(entry); 74 GtkStyle* style = gtk_widget_get_style(entry);
71 gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, 75 gtk_widget_modify_bg(widget, GTK_STATE_NORMAL,
72 &style->base[GTK_STATE_NORMAL]); 76 &style->base[GTK_STATE_NORMAL]);
73 gtk_widget_destroy(entry); 77 gtk_widget_destroy(entry);
74 } 78 }
75 79
80 string16 GetEntryText(GtkWidget* entry) {
81 return UTF8ToUTF16(gtk_entry_get_text(GTK_ENTRY(entry)));
82 }
83
84 void SetEntryText(GtkWidget* entry, const string16& text) {
85 gtk_entry_set_text(GTK_ENTRY(entry), UTF16ToUTF8(text).c_str());
86 }
87
88 void SetButtonData(GtkWidget* widget, GtkWidget* entry) {
89 g_object_set_data(G_OBJECT(widget), kButtonDataKey, entry);
90 }
91
92 GtkWidget* GetButtonData(GtkWidget* widget) {
93 return static_cast<GtkWidget*>(
94 g_object_get_data(G_OBJECT(widget), kButtonDataKey));
95 }
96
76 //////////////////////////////////////////////////////////////////////////////// 97 ////////////////////////////////////////////////////////////////////////////////
77 // Form Table helpers. 98 // Form Table helpers.
78 // 99 //
79 // The following functions can be used to create a form with labeled widgets. 100 // The following functions can be used to create a form with labeled widgets.
80 // 101 //
81 102
82 // Creates a form table with dimensions |rows| x |cols|. 103 // Creates a form table with dimensions |rows| x |cols|.
83 GtkWidget* InitFormTable(int rows, int cols) { 104 GtkWidget* InitFormTable(int rows, int cols) {
84 // We have two table rows per form table row. 105 // We have two table rows per form table row.
85 GtkWidget* table = gtk_table_new(rows * 2, cols, false); 106 GtkWidget* table = gtk_table_new(rows * 2, cols, false);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 } // namespace 205 } // namespace
185 206
186 //////////////////////////////////////////////////////////////////////////////// 207 ////////////////////////////////////////////////////////////////////////////////
187 // AutoFillDialog 208 // AutoFillDialog
188 // 209 //
189 // The contents of the AutoFill dialog. This dialog allows users to add, edit 210 // The contents of the AutoFill dialog. This dialog allows users to add, edit
190 // and remove AutoFill profiles. 211 // and remove AutoFill profiles.
191 class AutoFillDialog { 212 class AutoFillDialog {
192 public: 213 public:
193 AutoFillDialog(AutoFillDialogObserver* observer, 214 AutoFillDialog(AutoFillDialogObserver* observer,
194 const std::vector<AutoFillProfile>& profiles, 215 const std::vector<AutoFillProfile*>& profiles,
195 const std::vector<CreditCard>& credit_cards); 216 const std::vector<CreditCard*>& credit_cards);
196 ~AutoFillDialog() {} 217 ~AutoFillDialog() {}
197 218
198 // Shows the AutoFill dialog. 219 // Shows the AutoFill dialog.
199 void Show(); 220 void Show();
200 221
201 private: 222 private:
202 // 'destroy' signal handler. We DeleteSoon the global singleton dialog object 223 // 'destroy' signal handler. We DeleteSoon the global singleton dialog object
203 // from here. 224 // from here.
204 static void OnDestroy(GtkWidget* widget, AutoFillDialog* autofill_dialog); 225 static void OnDestroy(GtkWidget* widget, AutoFillDialog* autofill_dialog);
205 226
206 // 'response' signal handler. We notify the AutoFillDialogObserver that new 227 // 'response' signal handler. We notify the AutoFillDialogObserver that new
207 // data is available if the response is GTK_RESPONSE_APPLY or GTK_RESPONSE_OK. 228 // data is available if the response is GTK_RESPONSE_APPLY or GTK_RESPONSE_OK.
208 // We close the dialog if the response is GTK_RESPONSE_OK or 229 // We close the dialog if the response is GTK_RESPONSE_OK or
209 // GTK_RESPONSE_CANCEL. 230 // GTK_RESPONSE_CANCEL.
210 static void OnResponse(GtkDialog* dialog, gint response_id, 231 static void OnResponse(GtkDialog* dialog, gint response_id,
211 AutoFillDialog* autofill_dialog); 232 AutoFillDialog* autofill_dialog);
212 233
213 // 'clicked' signal handler. We add a new address. 234 // 'clicked' signal handler. We add a new address.
214 static void OnAddAddressClicked(GtkButton* button, AutoFillDialog* dialog); 235 static void OnAddAddressClicked(GtkButton* button, AutoFillDialog* dialog);
215 236
216 // 'clicked' signal handler. We add a new credit card. 237 // 'clicked' signal handler. We add a new credit card.
217 static void OnAddCreditCardClicked(GtkButton* button, AutoFillDialog* dialog); 238 static void OnAddCreditCardClicked(GtkButton* button, AutoFillDialog* dialog);
218 239
240 // 'clicked' signal handler. We delete the associated address.
241 static void OnDeleteAddressClicked(GtkButton* button, AutoFillDialog* dialog);
242
243 // 'clicked' signal handler. We delete the associated credit card.
244 static void OnDeleteCreditCardClicked(GtkButton* button,
245 AutoFillDialog* dialog);
246
219 // 'changed' signal handler. We update the title of the expander widget with 247 // 'changed' signal handler. We update the title of the expander widget with
220 // the contents of the label entry widget. 248 // the contents of the label entry widget.
221 static void OnLabelChanged(GtkEntry* label, GtkWidget* expander); 249 static void OnLabelChanged(GtkEntry* label, GtkWidget* expander);
222 250
223 // Initializes the group widgets and returns their container. |name_id| is 251 // Initializes the group widgets and returns their container. |name_id| is
224 // the resource ID of the group label. |button_id| is the resource name of 252 // the resource ID of the group label. |button_id| is the resource name of
225 // the button label. |clicked_callback| is a callback that handles the 253 // the button label. |clicked_callback| is a callback that handles the
226 // 'clicked' signal emitted when the user presses the 'Add' button. 254 // 'clicked' signal emitted when the user presses the 'Add' button.
227 GtkWidget* InitGroup(int label_id, 255 GtkWidget* InitGroup(int label_id,
228 int button_id, 256 int button_id,
229 GCallback clicked_callback); 257 GCallback clicked_callback);
230 258
231 // Initializes the expander, frame and table widgets used to hold the address 259 // Initializes the expander, frame and table widgets used to hold the address
232 // and credit card forms. |name_id| is the resource id of the label of the 260 // and credit card forms. |name_id| is the resource id of the label of the
233 // expander widget. The content vbox widget is returned in |content_vbox|. 261 // expander widget. The content vbox widget is returned in |content_vbox|.
234 // Returns the expander widget. 262 // Returns the expander widget.
235 GtkWidget* InitGroupContentArea(int name_id, GtkWidget** content_vbox); 263 GtkWidget* InitGroupContentArea(int name_id, GtkWidget** content_vbox);
236 264
237 // Returns a GtkExpander that is added to the appropriate vbox. Each method 265 // Returns a GtkExpander that is added to the appropriate vbox. Each method
238 // adds the necessary widgets and layout required to fill out information 266 // adds the necessary widgets and layout required to fill out information
239 // for either an address or a credit card. 267 // for either an address or a credit card. The expander will be expanded by
240 GtkWidget* AddNewAddress(); 268 // default if |expand| is true.
269 GtkWidget* AddNewAddress(bool expand);
241 GtkWidget* AddNewCreditCard(); 270 GtkWidget* AddNewCreditCard();
242 271
272 // Adds a new address filled out with information from |profile|.
273 void AddAddress(const AutoFillProfile& profile);
274
243 // The list of current AutoFill profiles. 275 // The list of current AutoFill profiles.
244 std::vector<AutoFillProfile> profiles_; 276 std::vector<AutoFillProfile> profiles_;
245 277
246 // The list of current AutoFill credit cards. 278 // The list of current AutoFill credit cards.
247 std::vector<CreditCard> credit_cards_; 279 std::vector<CreditCard> credit_cards_;
248 280
249 // The list of address widgets, used to modify the AutoFill profiles. 281 // The list of address widgets, used to modify the AutoFill profiles.
250 std::vector<AddressWidgets> address_widgets_; 282 std::vector<AddressWidgets> address_widgets_;
251 283
252 // The AutoFill dialog. 284 // The AutoFill dialog.
253 GtkWidget* dialog_; 285 GtkWidget* dialog_;
254 286
255 // The addresses group. 287 // The addresses group.
256 GtkWidget* addresses_vbox_; 288 GtkWidget* addresses_vbox_;
257 289
258 // The credit cards group. 290 // The credit cards group.
259 GtkWidget* creditcards_vbox_; 291 GtkWidget* creditcards_vbox_;
260 292
261 // Our observer. 293 // Our observer.
262 AutoFillDialogObserver* observer_; 294 AutoFillDialogObserver* observer_;
263 295
264 DISALLOW_COPY_AND_ASSIGN(AutoFillDialog); 296 DISALLOW_COPY_AND_ASSIGN(AutoFillDialog);
265 }; 297 };
266 298
267 // The singleton AutoFill dialog object. 299 // The singleton AutoFill dialog object.
268 static AutoFillDialog* dialog = NULL; 300 static AutoFillDialog* dialog = NULL;
269 301
270 AutoFillDialog::AutoFillDialog(AutoFillDialogObserver* observer, 302 AutoFillDialog::AutoFillDialog(AutoFillDialogObserver* observer,
271 const std::vector<AutoFillProfile>& profiles, 303 const std::vector<AutoFillProfile*>& profiles,
272 const std::vector<CreditCard>& credit_cards) 304 const std::vector<CreditCard*>& credit_cards)
273 : profiles_(profiles), 305 : observer_(observer) {
274 credit_cards_(credit_cards),
275 observer_(observer) {
276 DCHECK(observer); 306 DCHECK(observer);
277 307
308 // Copy the profiles.
309 std::vector<AutoFillProfile*>::const_iterator profile;
310 for (profile = profiles.begin(); profile != profiles.end(); ++profile)
311 profiles_.push_back(**profile);
312
313 // TODO(jhawkins): Copy the credit cards.
314
278 dialog_ = gtk_dialog_new_with_buttons( 315 dialog_ = gtk_dialog_new_with_buttons(
279 l10n_util::GetStringUTF8(IDS_AUTOFILL_DIALOG_TITLE).c_str(), 316 l10n_util::GetStringUTF8(IDS_AUTOFILL_DIALOG_TITLE).c_str(),
280 // AutoFill dialog is shared between all browser windows. 317 // AutoFill dialog is shared between all browser windows.
281 NULL, 318 NULL,
282 // Non-modal. 319 // Non-modal.
283 GTK_DIALOG_NO_SEPARATOR, 320 GTK_DIALOG_NO_SEPARATOR,
284 GTK_STOCK_APPLY, 321 GTK_STOCK_APPLY,
285 GTK_RESPONSE_APPLY, 322 GTK_RESPONSE_APPLY,
286 GTK_STOCK_CANCEL, 323 GTK_STOCK_CANCEL,
287 GTK_RESPONSE_CANCEL, 324 GTK_RESPONSE_CANCEL,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 // The content vbox. 358 // The content vbox.
322 GtkWidget* outer_vbox = gtk_vbox_new(false, 0); 359 GtkWidget* outer_vbox = gtk_vbox_new(false, 0);
323 gtk_box_set_spacing(GTK_BOX(outer_vbox), gtk_util::kContentAreaSpacing); 360 gtk_box_set_spacing(GTK_BOX(outer_vbox), gtk_util::kContentAreaSpacing);
324 gtk_container_add(GTK_CONTAINER(frame), outer_vbox); 361 gtk_container_add(GTK_CONTAINER(frame), outer_vbox);
325 362
326 addresses_vbox_ = InitGroup(IDS_AUTOFILL_ADDRESSES_GROUP_NAME, 363 addresses_vbox_ = InitGroup(IDS_AUTOFILL_ADDRESSES_GROUP_NAME,
327 IDS_AUTOFILL_ADD_ADDRESS_BUTTON, 364 IDS_AUTOFILL_ADD_ADDRESS_BUTTON,
328 G_CALLBACK(OnAddAddressClicked)); 365 G_CALLBACK(OnAddAddressClicked));
329 gtk_box_pack_start_defaults(GTK_BOX(outer_vbox), addresses_vbox_); 366 gtk_box_pack_start_defaults(GTK_BOX(outer_vbox), addresses_vbox_);
330 367
331 // TODO(jhawkins): Add addresses from |profiles|. 368 std::vector<AutoFillProfile>::const_iterator iter;
369 for (iter = profiles_.begin(); iter != profiles_.end(); ++iter)
370 AddAddress(*iter);
332 371
333 creditcards_vbox_ = InitGroup(IDS_AUTOFILL_CREDITCARDS_GROUP_NAME, 372 creditcards_vbox_ = InitGroup(IDS_AUTOFILL_CREDITCARDS_GROUP_NAME,
334 IDS_AUTOFILL_ADD_CREDITCARD_BUTTON, 373 IDS_AUTOFILL_ADD_CREDITCARD_BUTTON,
335 G_CALLBACK(OnAddCreditCardClicked)); 374 G_CALLBACK(OnAddCreditCardClicked));
336 gtk_box_pack_start_defaults(GTK_BOX(outer_vbox), creditcards_vbox_); 375 gtk_box_pack_start_defaults(GTK_BOX(outer_vbox), creditcards_vbox_);
337 376
338 // TODO(jhawkins): Add credit cards from |credit_cards|. 377 // TODO(jhawkins): Add credit cards from |credit_cards|.
339 378
340 gtk_widget_show_all(dialog_); 379 gtk_widget_show_all(dialog_);
341 } 380 }
342 381
343 void AutoFillDialog::Show() { 382 void AutoFillDialog::Show() {
344 gtk_window_present_with_time(GTK_WINDOW(dialog_), 383 gtk_window_present_with_time(GTK_WINDOW(dialog_),
345 gtk_get_current_event_time()); 384 gtk_get_current_event_time());
346 } 385 }
347 386
348 // static 387 // static
349 void AutoFillDialog::OnDestroy(GtkWidget* widget, 388 void AutoFillDialog::OnDestroy(GtkWidget* widget,
350 AutoFillDialog* autofill_dialog) { 389 AutoFillDialog* autofill_dialog) {
351 dialog = NULL; 390 dialog = NULL;
352 MessageLoop::current()->DeleteSoon(FROM_HERE, autofill_dialog); 391 MessageLoop::current()->DeleteSoon(FROM_HERE, autofill_dialog);
353 } 392 }
354 393
355 static string16 GetEntryText(GtkWidget* entry) {
356 return UTF8ToUTF16(gtk_entry_get_text(GTK_ENTRY(entry)));
357 }
358
359 static AutoFillProfile AutoFillProfileFromWidgetValues( 394 static AutoFillProfile AutoFillProfileFromWidgetValues(
360 const AddressWidgets& widgets) { 395 const AddressWidgets& widgets) {
361 // TODO(jhawkins): unique id? 396 // TODO(jhawkins): unique id?
362 AutoFillProfile profile(GetEntryText(widgets.label), 0); 397 AutoFillProfile profile(GetEntryText(widgets.label), 0);
363 profile.SetInfo(AutoFillType(NAME_FIRST), 398 profile.SetInfo(AutoFillType(NAME_FIRST),
364 GetEntryText(widgets.first_name)); 399 GetEntryText(widgets.first_name));
365 profile.SetInfo(AutoFillType(NAME_MIDDLE), 400 profile.SetInfo(AutoFillType(NAME_MIDDLE),
366 GetEntryText(widgets.middle_name)); 401 GetEntryText(widgets.middle_name));
367 profile.SetInfo(AutoFillType(NAME_LAST), 402 profile.SetInfo(AutoFillType(NAME_LAST),
368 GetEntryText(widgets.last_name)); 403 GetEntryText(widgets.last_name));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 autofill_dialog->profiles_.clear(); 439 autofill_dialog->profiles_.clear();
405 std::vector<AddressWidgets>::const_iterator iter; 440 std::vector<AddressWidgets>::const_iterator iter;
406 for (iter = autofill_dialog->address_widgets_.begin(); 441 for (iter = autofill_dialog->address_widgets_.begin();
407 iter != autofill_dialog->address_widgets_.end(); 442 iter != autofill_dialog->address_widgets_.end();
408 ++iter) { 443 ++iter) {
409 autofill_dialog->profiles_.push_back( 444 autofill_dialog->profiles_.push_back(
410 AutoFillProfileFromWidgetValues(*iter)); 445 AutoFillProfileFromWidgetValues(*iter));
411 } 446 }
412 447
413 autofill_dialog->observer_->OnAutoFillDialogApply( 448 autofill_dialog->observer_->OnAutoFillDialogApply(
414 autofill_dialog->profiles_, autofill_dialog->credit_cards_); 449 &autofill_dialog->profiles_,
450 &autofill_dialog->credit_cards_);
415 } 451 }
416 452
417 if (response_id == GTK_RESPONSE_OK || response_id == GTK_RESPONSE_CANCEL) { 453 if (response_id == GTK_RESPONSE_OK || response_id == GTK_RESPONSE_CANCEL) {
418 gtk_widget_destroy(GTK_WIDGET(dialog)); 454 gtk_widget_destroy(GTK_WIDGET(dialog));
419 } 455 }
420 } 456 }
421 457
422 // static 458 // static
423 void AutoFillDialog::OnAddAddressClicked(GtkButton* button, 459 void AutoFillDialog::OnAddAddressClicked(GtkButton* button,
424 AutoFillDialog* dialog) { 460 AutoFillDialog* dialog) {
425 GtkWidget* new_address = dialog->AddNewAddress(); 461 GtkWidget* new_address = dialog->AddNewAddress(true);
426 gtk_box_pack_start(GTK_BOX(dialog->addresses_vbox_), new_address, 462 gtk_box_pack_start(GTK_BOX(dialog->addresses_vbox_), new_address,
427 FALSE, FALSE, 0); 463 FALSE, FALSE, 0);
428 gtk_widget_show_all(new_address); 464 gtk_widget_show_all(new_address);
429 } 465 }
430 466
431 // static 467 // static
432 void AutoFillDialog::OnAddCreditCardClicked(GtkButton* button, 468 void AutoFillDialog::OnAddCreditCardClicked(GtkButton* button,
433 AutoFillDialog* dialog) { 469 AutoFillDialog* dialog) {
434 GtkWidget* new_creditcard = dialog->AddNewCreditCard(); 470 GtkWidget* new_creditcard = dialog->AddNewCreditCard();
435 gtk_box_pack_start(GTK_BOX(dialog->creditcards_vbox_), new_creditcard, 471 gtk_box_pack_start(GTK_BOX(dialog->creditcards_vbox_), new_creditcard,
436 FALSE, FALSE, 0); 472 FALSE, FALSE, 0);
437 gtk_widget_show_all(new_creditcard); 473 gtk_widget_show_all(new_creditcard);
438 } 474 }
439 475
440 // static 476 // static
477 void AutoFillDialog::OnDeleteAddressClicked(GtkButton* button,
478 AutoFillDialog* dialog) {
479 GtkWidget* entry = GetButtonData(GTK_WIDGET(button));
480 string16 label = GetEntryText(entry);
481
482 // TODO(jhawkins): Base this on ID.
483
484 // Remove the profile.
485 for (std::vector<AutoFillProfile>::iterator iter = dialog->profiles_.begin();
486 iter != dialog->profiles_.end();
487 ++iter) {
488 if (iter->Label() == label) {
489 dialog->profiles_.erase(iter);
490 break;
491 }
492 }
493
494 // Remove the set of address widgets.
495 for (std::vector<AddressWidgets>::iterator iter =
496 dialog->address_widgets_.begin();
497 iter != dialog->address_widgets_.end();
498 ++iter) {
499 if (iter->label == entry) {
500 dialog->address_widgets_.erase(iter);
501 break;
502 }
503 }
504
505 // Get back to the expander widget.
506 GtkWidget* expander = gtk_widget_get_ancestor(GTK_WIDGET(button),
507 GTK_TYPE_EXPANDER);
508 DCHECK(expander);
509
510 // Destroying the widget will also remove it from the parent container.
511 gtk_widget_destroy(expander);
512 }
513
514 // static
515 void AutoFillDialog::OnDeleteCreditCardClicked(GtkButton* button,
516 AutoFillDialog* dialog) {
517 // TODO(jhawkins): Remove the associated credit card.
518 }
519
520 // static
441 void AutoFillDialog::OnLabelChanged(GtkEntry* label, GtkWidget* expander) { 521 void AutoFillDialog::OnLabelChanged(GtkEntry* label, GtkWidget* expander) {
442 gtk_expander_set_label(GTK_EXPANDER(expander), gtk_entry_get_text(label)); 522 gtk_expander_set_label(GTK_EXPANDER(expander), gtk_entry_get_text(label));
443 } 523 }
444 524
445 GtkWidget* AutoFillDialog::InitGroup(int name_id, 525 GtkWidget* AutoFillDialog::InitGroup(int name_id,
446 int button_id, 526 int button_id,
447 GCallback clicked_callback) { 527 GCallback clicked_callback) {
448 GtkWidget* vbox = gtk_vbox_new(false, gtk_util::kControlSpacing); 528 GtkWidget* vbox = gtk_vbox_new(false, gtk_util::kControlSpacing);
449 529
450 // Group label. 530 // Group label.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 gtk_box_set_spacing(GTK_BOX(vbox), gtk_util::kControlSpacing); 565 gtk_box_set_spacing(GTK_BOX(vbox), gtk_util::kControlSpacing);
486 GtkWidget* vbox_alignment = gtk_alignment_new(0, 0, 0, 0); 566 GtkWidget* vbox_alignment = gtk_alignment_new(0, 0, 0, 0);
487 gtk_alignment_set_padding(GTK_ALIGNMENT(vbox_alignment), 567 gtk_alignment_set_padding(GTK_ALIGNMENT(vbox_alignment),
488 gtk_util::kControlSpacing, 568 gtk_util::kControlSpacing,
489 gtk_util::kControlSpacing, 569 gtk_util::kControlSpacing,
490 gtk_util::kGroupIndent, 570 gtk_util::kGroupIndent,
491 0); 571 0);
492 gtk_container_add(GTK_CONTAINER(vbox_alignment), vbox); 572 gtk_container_add(GTK_CONTAINER(vbox_alignment), vbox);
493 gtk_container_add(GTK_CONTAINER(frame), vbox_alignment); 573 gtk_container_add(GTK_CONTAINER(frame), vbox_alignment);
494 574
495 // Make it expand by default.
496 gtk_expander_set_expanded(GTK_EXPANDER(expander), true);
497
498 *content_vbox = vbox; 575 *content_vbox = vbox;
499 return expander; 576 return expander;
500 } 577 }
501 578
502 GtkWidget* AutoFillDialog::AddNewAddress() { 579 GtkWidget* AutoFillDialog::AddNewAddress(bool expand) {
503 AddressWidgets widgets = {0}; 580 AddressWidgets widgets = {0};
504 GtkWidget* vbox; 581 GtkWidget* vbox;
505 GtkWidget* address = InitGroupContentArea(IDS_AUTOFILL_NEW_ADDRESS, &vbox); 582 GtkWidget* address = InitGroupContentArea(IDS_AUTOFILL_NEW_ADDRESS, &vbox);
506 583
584 gtk_expander_set_expanded(GTK_EXPANDER(address), expand);
585
507 GtkWidget* table = InitFormTable(5, 3); 586 GtkWidget* table = InitFormTable(5, 3);
508 gtk_box_pack_start_defaults(GTK_BOX(vbox), table); 587 gtk_box_pack_start_defaults(GTK_BOX(vbox), table);
509 588
510 widgets.label = FormTableAddLabelEntry(table, 0, 0, 1, 589 widgets.label = FormTableAddLabelEntry(table, 0, 0, 1,
511 IDS_AUTOFILL_DIALOG_LABEL, 590 IDS_AUTOFILL_DIALOG_LABEL,
512 address, G_CALLBACK(OnLabelChanged)); 591 address, G_CALLBACK(OnLabelChanged));
513 widgets.first_name = FormTableAddEntry(table, 1, 0, 1, 592 widgets.first_name = FormTableAddEntry(table, 1, 0, 1,
514 IDS_AUTOFILL_DIALOG_FIRST_NAME); 593 IDS_AUTOFILL_DIALOG_FIRST_NAME);
515 widgets.middle_name = FormTableAddEntry(table, 1, 1, 1, 594 widgets.middle_name = FormTableAddEntry(table, 1, 1, 1,
516 IDS_AUTOFILL_DIALOG_MIDDLE_NAME); 595 IDS_AUTOFILL_DIALOG_MIDDLE_NAME);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 IDS_AUTOFILL_DIALOG_PHONE); 630 IDS_AUTOFILL_DIALOG_PHONE);
552 widgets.phone2 = FormTableAddSizedEntry(phone_table, 0, 1, 4, 0); 631 widgets.phone2 = FormTableAddSizedEntry(phone_table, 0, 1, 4, 0);
553 widgets.phone3 = FormTableAddEntry(phone_table, 0, 2, 2, 0); 632 widgets.phone3 = FormTableAddEntry(phone_table, 0, 2, 2, 0);
554 widgets.fax1 = FormTableAddSizedEntry(phone_table, 0, 4, 4, 633 widgets.fax1 = FormTableAddSizedEntry(phone_table, 0, 4, 4,
555 IDS_AUTOFILL_DIALOG_FAX); 634 IDS_AUTOFILL_DIALOG_FAX);
556 widgets.fax2 = FormTableAddSizedEntry(phone_table, 0, 5, 4, 0); 635 widgets.fax2 = FormTableAddSizedEntry(phone_table, 0, 5, 4, 0);
557 widgets.fax3 = FormTableAddEntry(phone_table, 0, 6, 2, 0); 636 widgets.fax3 = FormTableAddEntry(phone_table, 0, 6, 2, 0);
558 637
559 GtkWidget* button = gtk_button_new_with_label( 638 GtkWidget* button = gtk_button_new_with_label(
560 l10n_util::GetStringUTF8(IDS_AUTOFILL_DELETE_BUTTON).c_str()); 639 l10n_util::GetStringUTF8(IDS_AUTOFILL_DELETE_BUTTON).c_str());
640 g_signal_connect(button, "clicked", G_CALLBACK(OnDeleteAddressClicked), this);
641 SetButtonData(button, widgets.label);
561 GtkWidget* alignment = gtk_alignment_new(0, 0, 0, 0); 642 GtkWidget* alignment = gtk_alignment_new(0, 0, 0, 0);
562 gtk_container_add(GTK_CONTAINER(alignment), button); 643 gtk_container_add(GTK_CONTAINER(alignment), button);
563 gtk_box_pack_start_defaults(GTK_BOX(vbox), alignment); 644 gtk_box_pack_start_defaults(GTK_BOX(vbox), alignment);
564 645
565 address_widgets_.push_back(widgets); 646 address_widgets_.push_back(widgets);
566 return address; 647 return address;
567 } 648 }
568 649
569 GtkWidget* AutoFillDialog::AddNewCreditCard() { 650 GtkWidget* AutoFillDialog::AddNewCreditCard() {
570 GtkWidget* vbox; 651 GtkWidget* vbox;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 711
631 GtkWidget* button = gtk_button_new_with_label( 712 GtkWidget* button = gtk_button_new_with_label(
632 l10n_util::GetStringUTF8(IDS_AUTOFILL_DELETE_BUTTON).c_str()); 713 l10n_util::GetStringUTF8(IDS_AUTOFILL_DELETE_BUTTON).c_str());
633 GtkWidget* alignment = gtk_alignment_new(0, 0, 0, 0); 714 GtkWidget* alignment = gtk_alignment_new(0, 0, 0, 0);
634 gtk_container_add(GTK_CONTAINER(alignment), button); 715 gtk_container_add(GTK_CONTAINER(alignment), button);
635 gtk_box_pack_start_defaults(GTK_BOX(vbox), alignment); 716 gtk_box_pack_start_defaults(GTK_BOX(vbox), alignment);
636 717
637 return credit_card; 718 return credit_card;
638 } 719 }
639 720
721 void AutoFillDialog::AddAddress(const AutoFillProfile& profile) {
722 GtkWidget* address = AddNewAddress(false);
723 gtk_expander_set_label(GTK_EXPANDER(address),
724 UTF16ToUTF8(profile.Label()).c_str());
725
726 // We just pushed the widgets to the back of the vector.
727 const AddressWidgets& widgets = address_widgets_.back();
728 SetEntryText(widgets.label, profile.Label());
729 SetEntryText(widgets.first_name,
730 profile.GetFieldText(AutoFillType(NAME_FIRST)));
731 SetEntryText(widgets.middle_name,
732 profile.GetFieldText(AutoFillType(NAME_MIDDLE)));
733 SetEntryText(widgets.last_name,
734 profile.GetFieldText(AutoFillType(NAME_LAST)));
735 SetEntryText(widgets.email,
736 profile.GetFieldText(AutoFillType(EMAIL_ADDRESS)));
737 SetEntryText(widgets.company_name,
738 profile.GetFieldText(AutoFillType(COMPANY_NAME)));
739 SetEntryText(widgets.address_line1,
740 profile.GetFieldText(AutoFillType(ADDRESS_HOME_LINE1)));
741 SetEntryText(widgets.address_line2,
742 profile.GetFieldText(AutoFillType(ADDRESS_HOME_LINE2)));
743 SetEntryText(widgets.city,
744 profile.GetFieldText(AutoFillType(ADDRESS_HOME_CITY)));
745 SetEntryText(widgets.state,
746 profile.GetFieldText(AutoFillType(ADDRESS_HOME_STATE)));
747 SetEntryText(widgets.zipcode,
748 profile.GetFieldText(AutoFillType(ADDRESS_HOME_ZIP)));
749 SetEntryText(widgets.country,
750 profile.GetFieldText(AutoFillType(ADDRESS_HOME_COUNTRY)));
751 SetEntryText(widgets.phone1,
752 profile.GetFieldText(AutoFillType(PHONE_HOME_COUNTRY_CODE)));
753 SetEntryText(widgets.phone2,
754 profile.GetFieldText(AutoFillType(PHONE_HOME_CITY_CODE)));
755 SetEntryText(widgets.phone3,
756 profile.GetFieldText(AutoFillType(PHONE_HOME_NUMBER)));
757 SetEntryText(widgets.fax1,
758 profile.GetFieldText(AutoFillType(PHONE_FAX_COUNTRY_CODE)));
759 SetEntryText(widgets.fax2,
760 profile.GetFieldText(AutoFillType(PHONE_FAX_CITY_CODE)));
761 SetEntryText(widgets.fax3,
762 profile.GetFieldText(AutoFillType(PHONE_FAX_NUMBER)));
763
764 gtk_box_pack_start(GTK_BOX(addresses_vbox_), address, FALSE, FALSE, 0);
765 gtk_widget_show_all(address);
766 }
767
640 /////////////////////////////////////////////////////////////////////////////// 768 ///////////////////////////////////////////////////////////////////////////////
641 // Factory/finder method: 769 // Factory/finder method:
642 770
643 void ShowAutoFillDialog(AutoFillDialogObserver* observer, 771 void ShowAutoFillDialog(AutoFillDialogObserver* observer,
644 const std::vector<AutoFillProfile>& profiles, 772 const std::vector<AutoFillProfile*>& profiles,
645 const std::vector<CreditCard>& credit_cards) { 773 const std::vector<CreditCard*>& credit_cards) {
646 if (!dialog) { 774 if (!dialog) {
647 dialog = new AutoFillDialog(observer, profiles, credit_cards); 775 dialog = new AutoFillDialog(observer, profiles, credit_cards);
648 } 776 }
649 dialog->Show(); 777 dialog->Show();
650 } 778 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_dialog.cc ('k') | chrome/browser/autofill/autofill_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698