OLD | NEW |
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 #include "chrome/browser/views/autofill_profiles_view_win.h" | 4 #include "chrome/browser/views/autofill_profiles_view_win.h" |
5 | 5 |
6 #include <vsstyle.h> | 6 #include <vsstyle.h> |
7 #include <vssym32.h> | 7 #include <vssym32.h> |
8 | 8 |
9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "base/time.h" | 13 #include "base/time.h" |
14 #include "chrome/browser/autofill/autofill_manager.h" | 14 #include "chrome/browser/autofill/autofill_manager.h" |
15 #include "chrome/browser/autofill/phone_number.h" | 15 #include "chrome/browser/autofill/phone_number.h" |
16 #include "chrome/browser/browser.h" | 16 #include "chrome/browser/browser.h" |
17 #include "chrome/browser/browser_list.h" | 17 #include "chrome/browser/browser_list.h" |
18 #include "chrome/browser/browser_window.h" | 18 #include "chrome/browser/browser_window.h" |
| 19 #include "chrome/browser/metrics/user_metrics.h" |
19 #include "chrome/browser/pref_service.h" | 20 #include "chrome/browser/pref_service.h" |
20 #include "chrome/browser/profile.h" | 21 #include "chrome/browser/profile.h" |
21 #include "chrome/browser/views/list_background.h" | 22 #include "chrome/browser/views/list_background.h" |
22 #include "chrome/browser/window_sizer.h" | 23 #include "chrome/browser/window_sizer.h" |
23 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
24 #include "gfx/canvas.h" | 25 #include "gfx/canvas.h" |
25 #include "gfx/native_theme_win.h" | 26 #include "gfx/native_theme_win.h" |
26 #include "gfx/size.h" | 27 #include "gfx/size.h" |
27 #include "grit/app_resources.h" | 28 #include "grit/app_resources.h" |
28 #include "grit/generated_resources.h" | 29 #include "grit/generated_resources.h" |
(...skipping 26 matching lines...) Expand all Loading... |
55 | 56 |
56 ///////////////////////////////////////////////////////////////////////////// | 57 ///////////////////////////////////////////////////////////////////////////// |
57 // AutoFillProfilesView, static data: | 58 // AutoFillProfilesView, static data: |
58 AutoFillProfilesView* AutoFillProfilesView::instance_ = NULL; | 59 AutoFillProfilesView* AutoFillProfilesView::instance_ = NULL; |
59 | 60 |
60 ///////////////////////////////////////////////////////////////////////////// | 61 ///////////////////////////////////////////////////////////////////////////// |
61 // AutoFillProfilesView, public: | 62 // AutoFillProfilesView, public: |
62 AutoFillProfilesView::AutoFillProfilesView( | 63 AutoFillProfilesView::AutoFillProfilesView( |
63 AutoFillDialogObserver* observer, | 64 AutoFillDialogObserver* observer, |
64 PersonalDataManager* personal_data_manager, | 65 PersonalDataManager* personal_data_manager, |
| 66 Profile* profile, |
65 PrefService* preferences, | 67 PrefService* preferences, |
66 AutoFillProfile* imported_profile, | 68 AutoFillProfile* imported_profile, |
67 CreditCard* imported_credit_card) | 69 CreditCard* imported_credit_card) |
68 : observer_(observer), | 70 : observer_(observer), |
69 personal_data_manager_(personal_data_manager), | 71 personal_data_manager_(personal_data_manager), |
| 72 profile_(profile), |
70 preferences_(preferences), | 73 preferences_(preferences), |
| 74 enable_auto_fill_button_(NULL), |
71 add_address_button_(NULL), | 75 add_address_button_(NULL), |
72 add_credit_card_button_(NULL), | 76 add_credit_card_button_(NULL), |
73 edit_button_(NULL), | 77 edit_button_(NULL), |
74 remove_button_(NULL), | 78 remove_button_(NULL), |
75 scroll_view_(NULL), | 79 scroll_view_(NULL), |
76 focus_manager_(NULL), | 80 focus_manager_(NULL), |
77 billing_model_(true), | 81 billing_model_(true), |
78 child_dialog_opened_(false) { | 82 child_dialog_opened_(false) { |
79 DCHECK(preferences_); | 83 DCHECK(preferences_); |
80 if (imported_profile) { | 84 if (imported_profile) { |
(...skipping 12 matching lines...) Expand all Loading... |
93 | 97 |
94 // Removes observer if we are observing Profile load. Does nothing otherwise. | 98 // Removes observer if we are observing Profile load. Does nothing otherwise. |
95 if (personal_data_manager_) | 99 if (personal_data_manager_) |
96 personal_data_manager_->RemoveObserver(this); | 100 personal_data_manager_->RemoveObserver(this); |
97 } | 101 } |
98 | 102 |
99 // TODO: get rid of imported_profile and imported_credit_card. | 103 // TODO: get rid of imported_profile and imported_credit_card. |
100 int AutoFillProfilesView::Show(gfx::NativeWindow parent, | 104 int AutoFillProfilesView::Show(gfx::NativeWindow parent, |
101 AutoFillDialogObserver* observer, | 105 AutoFillDialogObserver* observer, |
102 PersonalDataManager* personal_data_manager, | 106 PersonalDataManager* personal_data_manager, |
| 107 Profile* profile, |
103 PrefService* preferences, | 108 PrefService* preferences, |
104 AutoFillProfile* imported_profile, | 109 AutoFillProfile* imported_profile, |
105 CreditCard* imported_credit_card) { | 110 CreditCard* imported_credit_card) { |
106 if (!instance_) { | 111 if (!instance_) { |
107 instance_ = new AutoFillProfilesView(observer, personal_data_manager, | 112 instance_ = new AutoFillProfilesView(observer, personal_data_manager, |
108 preferences, imported_profile, imported_credit_card); | 113 profile, preferences, imported_profile, imported_credit_card); |
109 | 114 |
110 // |instance_| will get deleted once Close() is called. | 115 // |instance_| will get deleted once Close() is called. |
111 views::Window::CreateChromeWindow(parent, gfx::Rect(), instance_); | 116 views::Window::CreateChromeWindow(parent, gfx::Rect(), instance_); |
112 } | 117 } |
113 if (!instance_->window()->IsVisible()) | 118 if (!instance_->window()->IsVisible()) |
114 instance_->window()->Show(); | 119 instance_->window()->Show(); |
115 else | 120 else |
116 instance_->window()->Activate(); | 121 instance_->window()->Activate(); |
117 return 0; | 122 return 0; |
118 } | 123 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 UpdateButtonState(); | 184 UpdateButtonState(); |
180 } | 185 } |
181 | 186 |
182 void AutoFillProfilesView::UpdateButtonState() { | 187 void AutoFillProfilesView::UpdateButtonState() { |
183 DCHECK(personal_data_manager_); | 188 DCHECK(personal_data_manager_); |
184 DCHECK(scroll_view_); | 189 DCHECK(scroll_view_); |
185 DCHECK(add_address_button_); | 190 DCHECK(add_address_button_); |
186 DCHECK(add_credit_card_button_); | 191 DCHECK(add_credit_card_button_); |
187 DCHECK(edit_button_); | 192 DCHECK(edit_button_); |
188 DCHECK(remove_button_); | 193 DCHECK(remove_button_); |
| 194 bool autofill_enabled = preferences_->GetBoolean(prefs::kAutoFillEnabled); |
| 195 scroll_view_->SetEnabled(autofill_enabled); |
189 add_address_button_->SetEnabled(personal_data_manager_->IsDataLoaded() && | 196 add_address_button_->SetEnabled(personal_data_manager_->IsDataLoaded() && |
190 !child_dialog_opened_); | 197 !child_dialog_opened_ && autofill_enabled); |
191 add_credit_card_button_->SetEnabled(personal_data_manager_->IsDataLoaded() && | 198 add_credit_card_button_->SetEnabled(personal_data_manager_->IsDataLoaded() && |
192 !child_dialog_opened_); | 199 !child_dialog_opened_ && |
| 200 autofill_enabled); |
193 | 201 |
194 int selected_row_count = scroll_view_->SelectedRowCount(); | 202 int selected_row_count = scroll_view_->SelectedRowCount(); |
195 edit_button_->SetEnabled(selected_row_count == 1 && !child_dialog_opened_); | 203 edit_button_->SetEnabled(selected_row_count == 1 && !child_dialog_opened_ && |
196 remove_button_->SetEnabled(selected_row_count > 0 && !child_dialog_opened_); | 204 autofill_enabled); |
| 205 remove_button_->SetEnabled(selected_row_count > 0 && !child_dialog_opened_ && |
| 206 autofill_enabled); |
| 207 } |
| 208 |
| 209 void AutoFillProfilesView::UpdateProfileLabels() { |
| 210 std::vector<AutoFillProfile*> profiles; |
| 211 profiles.resize(profiles_set_.size()); |
| 212 for (size_t i = 0; i < profiles_set_.size(); ++i) { |
| 213 profiles[i] = &(profiles_set_[i].address); |
| 214 } |
| 215 AutoFillProfile::AdjustInferredLabels(&profiles); |
197 } | 216 } |
198 | 217 |
199 void AutoFillProfilesView::ChildWindowOpened() { | 218 void AutoFillProfilesView::ChildWindowOpened() { |
200 child_dialog_opened_ = true; | 219 child_dialog_opened_ = true; |
201 UpdateButtonState(); | 220 UpdateButtonState(); |
202 } | 221 } |
203 | 222 |
204 void AutoFillProfilesView::ChildWindowClosed() { | 223 void AutoFillProfilesView::ChildWindowClosed() { |
205 child_dialog_opened_ = false; | 224 child_dialog_opened_ = false; |
206 UpdateButtonState(); | 225 UpdateButtonState(); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 void AutoFillProfilesView::ButtonPressed(views::Button* sender, | 345 void AutoFillProfilesView::ButtonPressed(views::Button* sender, |
327 const views::Event& event) { | 346 const views::Event& event) { |
328 if (sender == add_address_button_) { | 347 if (sender == add_address_button_) { |
329 AddClicked(ContentListTableModel::kAddressGroup); | 348 AddClicked(ContentListTableModel::kAddressGroup); |
330 } else if (sender == add_credit_card_button_) { | 349 } else if (sender == add_credit_card_button_) { |
331 AddClicked(ContentListTableModel::kCreditCardGroup); | 350 AddClicked(ContentListTableModel::kCreditCardGroup); |
332 } else if (sender == edit_button_) { | 351 } else if (sender == edit_button_) { |
333 EditClicked(); | 352 EditClicked(); |
334 } else if (sender == remove_button_) { | 353 } else if (sender == remove_button_) { |
335 DeleteClicked(); | 354 DeleteClicked(); |
| 355 } else if (sender == enable_auto_fill_button_) { |
| 356 bool enabled = enable_auto_fill_button_->checked(); |
| 357 UserMetricsAction action(enabled ? "Options_FormAutofill_Enable" : |
| 358 "Options_FormAutofill_Disable"); |
| 359 UserMetrics::RecordAction(action, profile_); |
| 360 preferences_->SetBoolean(prefs::kAutoFillEnabled, enabled); |
| 361 preferences_->ScheduleSavePersistentPrefs(); |
| 362 UpdateButtonState(); |
336 } | 363 } |
337 } | 364 } |
338 | 365 |
339 ///////////////////////////////////////////////////////////////////////////// | 366 ///////////////////////////////////////////////////////////////////////////// |
340 // AutoFillProfilesView, views::LinkController implementations: | 367 // AutoFillProfilesView, views::LinkController implementations: |
341 void AutoFillProfilesView::LinkActivated(views::Link* source, int event_flags) { | 368 void AutoFillProfilesView::LinkActivated(views::Link* source, int event_flags) { |
342 Browser* browser = BrowserList::GetLastActive(); | 369 Browser* browser = BrowserList::GetLastActive(); |
343 browser->OpenURL(GURL(kAutoFillLearnMoreUrl), GURL(), NEW_FOREGROUND_TAB, | 370 browser->OpenURL(GURL(kAutoFillLearnMoreUrl), GURL(), NEW_FOREGROUND_TAB, |
344 PageTransition::TYPED); | 371 PageTransition::TYPED); |
345 } | 372 } |
(...skipping 26 matching lines...) Expand all Loading... |
372 void AutoFillProfilesView::OnPersonalDataLoaded() { | 399 void AutoFillProfilesView::OnPersonalDataLoaded() { |
373 personal_data_manager_->RemoveObserver(this); | 400 personal_data_manager_->RemoveObserver(this); |
374 GetData(); | 401 GetData(); |
375 } | 402 } |
376 | 403 |
377 ///////////////////////////////////////////////////////////////////////////// | 404 ///////////////////////////////////////////////////////////////////////////// |
378 // AutoFillProfilesView, private: | 405 // AutoFillProfilesView, private: |
379 void AutoFillProfilesView::Init() { | 406 void AutoFillProfilesView::Init() { |
380 GetData(); | 407 GetData(); |
381 | 408 |
| 409 enable_auto_fill_button_ = new views::Checkbox( |
| 410 l10n_util::GetString(IDS_OPTIONS_AUTOFILL_ENABLE)); |
| 411 enable_auto_fill_button_->set_listener(this); |
| 412 enable_auto_fill_button_->SetChecked( |
| 413 preferences_->GetBoolean(prefs::kAutoFillEnabled)); |
| 414 |
382 billing_model_.set_address_labels(&profiles_set_); | 415 billing_model_.set_address_labels(&profiles_set_); |
383 | 416 |
384 table_model_.reset(new ContentListTableModel(&profiles_set_, | 417 table_model_.reset(new ContentListTableModel(&profiles_set_, |
385 &credit_card_set_)); | 418 &credit_card_set_)); |
386 std::vector<TableColumn> columns; | 419 std::vector<TableColumn> columns; |
387 columns.resize(2); | 420 columns.resize(1); |
388 columns[0] = TableColumn(IDS_AUTOFILL_LIST_HEADER_LABEL, | 421 columns[0] = TableColumn(IDS_AUTOFILL_LIST_HEADER_SUMMARY, |
389 TableColumn::LEFT, -1, .33f); | |
390 columns.back().sortable = false; | |
391 columns[1] = TableColumn(IDS_AUTOFILL_LIST_HEADER_SUMMARY, | |
392 TableColumn::LEFT, -1, .67f); | 422 TableColumn::LEFT, -1, .67f); |
393 columns.back().sortable = false; | 423 columns.back().sortable = false; |
394 | 424 |
395 scroll_view_ = new views::TableView(table_model_.get(), columns, | 425 scroll_view_ = new views::TableView(table_model_.get(), columns, |
396 views::TEXT_ONLY, false, true, true); | 426 views::TEXT_ONLY, false, true, true); |
397 scroll_view_->SetObserver(this); | 427 scroll_view_->SetObserver(this); |
398 | 428 |
399 add_address_button_ = new views::NativeButton(this, | 429 add_address_button_ = new views::NativeButton(this, |
400 l10n_util::GetString(IDS_AUTOFILL_ADD_ADDRESS_BUTTON)); | 430 l10n_util::GetString(IDS_AUTOFILL_ADD_ADDRESS_BUTTON)); |
401 add_credit_card_button_ = new views::NativeButton(this, | 431 add_credit_card_button_ = new views::NativeButton(this, |
402 l10n_util::GetString(IDS_AUTOFILL_ADD_CREDITCARD_BUTTON)); | 432 l10n_util::GetString(IDS_AUTOFILL_ADD_CREDITCARD_BUTTON)); |
403 edit_button_ = new views::NativeButton(this, | 433 edit_button_ = new views::NativeButton(this, |
404 l10n_util::GetString(IDS_AUTOFILL_EDIT_BUTTON)); | 434 l10n_util::GetString(IDS_AUTOFILL_EDIT_BUTTON)); |
405 remove_button_ = new views::NativeButton(this, | 435 remove_button_ = new views::NativeButton(this, |
406 l10n_util::GetString(IDS_AUTOFILL_DELETE_BUTTON)); | 436 l10n_util::GetString(IDS_AUTOFILL_DELETE_BUTTON)); |
407 | 437 |
408 views::GridLayout* layout = CreatePanelGridLayout(this); | 438 views::GridLayout* layout = CreatePanelGridLayout(this); |
409 SetLayoutManager(layout); | 439 SetLayoutManager(layout); |
410 | 440 |
411 const int table_with_buttons_column_view_set_id = 0; | 441 const int table_with_buttons_column_view_set_id = 0; |
412 views::ColumnSet* column_set = | 442 views::ColumnSet* column_set = |
413 layout->AddColumnSet(table_with_buttons_column_view_set_id); | 443 layout->AddColumnSet(table_with_buttons_column_view_set_id); |
414 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, | 444 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, |
415 views::GridLayout::USE_PREF, 0, 0); | 445 views::GridLayout::USE_PREF, 0, 0); |
416 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); | 446 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); |
417 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 0, | 447 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 0, |
418 views::GridLayout::USE_PREF, 0, 0); | 448 views::GridLayout::USE_PREF, 0, 0); |
419 | 449 |
420 layout->StartRow(0, table_with_buttons_column_view_set_id); | 450 layout->StartRow(0, table_with_buttons_column_view_set_id); |
| 451 layout->AddView(enable_auto_fill_button_, 3, 1, views::GridLayout::FILL, |
| 452 views::GridLayout::FILL); |
| 453 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
| 454 |
| 455 layout->StartRow(0, table_with_buttons_column_view_set_id); |
421 layout->AddView(scroll_view_, 1, 8, views::GridLayout::FILL, | 456 layout->AddView(scroll_view_, 1, 8, views::GridLayout::FILL, |
422 views::GridLayout::FILL); | 457 views::GridLayout::FILL); |
423 layout->AddView(add_address_button_); | 458 layout->AddView(add_address_button_); |
424 | 459 |
425 layout->StartRowWithPadding(0, table_with_buttons_column_view_set_id, 0, | 460 layout->StartRowWithPadding(0, table_with_buttons_column_view_set_id, 0, |
426 kRelatedControlVerticalSpacing); | 461 kRelatedControlVerticalSpacing); |
427 layout->SkipColumns(2); | 462 layout->SkipColumns(2); |
428 layout->AddView(add_credit_card_button_); | 463 layout->AddView(add_credit_card_button_); |
429 | 464 |
430 layout->StartRowWithPadding(0, table_with_buttons_column_view_set_id, 0, | 465 layout->StartRowWithPadding(0, table_with_buttons_column_view_set_id, 0, |
(...skipping 25 matching lines...) Expand all Loading... |
456 !credit_card_set_.empty(); | 491 !credit_card_set_.empty(); |
457 if (!imported_data_present) { | 492 if (!imported_data_present) { |
458 profiles_set_.reserve(personal_data_manager_->profiles().size()); | 493 profiles_set_.reserve(personal_data_manager_->profiles().size()); |
459 for (std::vector<AutoFillProfile*>::const_iterator address_it = | 494 for (std::vector<AutoFillProfile*>::const_iterator address_it = |
460 personal_data_manager_->profiles().begin(); | 495 personal_data_manager_->profiles().begin(); |
461 address_it != personal_data_manager_->profiles().end(); | 496 address_it != personal_data_manager_->profiles().end(); |
462 ++address_it) { | 497 ++address_it) { |
463 profiles_set_.push_back(EditableSetInfo(*address_it)); | 498 profiles_set_.push_back(EditableSetInfo(*address_it)); |
464 } | 499 } |
465 } | 500 } |
| 501 UpdateProfileLabels(); |
466 | 502 |
467 if (!imported_data_present) { | 503 if (!imported_data_present) { |
468 credit_card_set_.reserve(personal_data_manager_->credit_cards().size()); | 504 credit_card_set_.reserve(personal_data_manager_->credit_cards().size()); |
469 for (std::vector<CreditCard*>::const_iterator cc_it = | 505 for (std::vector<CreditCard*>::const_iterator cc_it = |
470 personal_data_manager_->credit_cards().begin(); | 506 personal_data_manager_->credit_cards().begin(); |
471 cc_it != personal_data_manager_->credit_cards().end(); | 507 cc_it != personal_data_manager_->credit_cards().end(); |
472 ++cc_it) { | 508 ++cc_it) { |
473 credit_card_set_.push_back(EditableSetInfo(*cc_it)); | 509 credit_card_set_.push_back(EditableSetInfo(*cc_it)); |
474 } | 510 } |
475 } | 511 } |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 views::ImageButton::ALIGN_MIDDLE); | 602 views::ImageButton::ALIGN_MIDDLE); |
567 layout->AddView(phone_warning_button_); | 603 layout->AddView(phone_warning_button_); |
568 UpdateButtons(); | 604 UpdateButtons(); |
569 } | 605 } |
570 } | 606 } |
571 | 607 |
572 ///////////////////////////////////////////////////////////////////////////// | 608 ///////////////////////////////////////////////////////////////////////////// |
573 // AutoFillProfilesView::EditableSetViewContents, static data: | 609 // AutoFillProfilesView::EditableSetViewContents, static data: |
574 AutoFillProfilesView::EditableSetViewContents::TextFieldToAutoFill | 610 AutoFillProfilesView::EditableSetViewContents::TextFieldToAutoFill |
575 AutoFillProfilesView::EditableSetViewContents::address_fields_[] = { | 611 AutoFillProfilesView::EditableSetViewContents::address_fields_[] = { |
576 { AutoFillProfilesView::EditableSetViewContents::TEXT_LABEL, NO_SERVER_DATA }, | |
577 { AutoFillProfilesView::EditableSetViewContents::TEXT_FULL_NAME, | 612 { AutoFillProfilesView::EditableSetViewContents::TEXT_FULL_NAME, |
578 NAME_FULL }, | 613 NAME_FULL }, |
579 { AutoFillProfilesView::EditableSetViewContents::TEXT_COMPANY, COMPANY_NAME }, | 614 { AutoFillProfilesView::EditableSetViewContents::TEXT_COMPANY, COMPANY_NAME }, |
580 { AutoFillProfilesView::EditableSetViewContents::TEXT_EMAIL, EMAIL_ADDRESS }, | 615 { AutoFillProfilesView::EditableSetViewContents::TEXT_EMAIL, EMAIL_ADDRESS }, |
581 { AutoFillProfilesView::EditableSetViewContents::TEXT_ADDRESS_LINE_1, | 616 { AutoFillProfilesView::EditableSetViewContents::TEXT_ADDRESS_LINE_1, |
582 ADDRESS_HOME_LINE1 }, | 617 ADDRESS_HOME_LINE1 }, |
583 { AutoFillProfilesView::EditableSetViewContents::TEXT_ADDRESS_LINE_2, | 618 { AutoFillProfilesView::EditableSetViewContents::TEXT_ADDRESS_LINE_2, |
584 ADDRESS_HOME_LINE2 }, | 619 ADDRESS_HOME_LINE2 }, |
585 { AutoFillProfilesView::EditableSetViewContents::TEXT_ADDRESS_CITY, | 620 { AutoFillProfilesView::EditableSetViewContents::TEXT_ADDRESS_CITY, |
586 ADDRESS_HOME_CITY }, | 621 ADDRESS_HOME_CITY }, |
587 { AutoFillProfilesView::EditableSetViewContents::TEXT_ADDRESS_STATE, | 622 { AutoFillProfilesView::EditableSetViewContents::TEXT_ADDRESS_STATE, |
588 ADDRESS_HOME_STATE }, | 623 ADDRESS_HOME_STATE }, |
589 { AutoFillProfilesView::EditableSetViewContents::TEXT_ADDRESS_ZIP, | 624 { AutoFillProfilesView::EditableSetViewContents::TEXT_ADDRESS_ZIP, |
590 ADDRESS_HOME_ZIP }, | 625 ADDRESS_HOME_ZIP }, |
591 { AutoFillProfilesView::EditableSetViewContents::TEXT_ADDRESS_COUNTRY, | 626 { AutoFillProfilesView::EditableSetViewContents::TEXT_ADDRESS_COUNTRY, |
592 ADDRESS_HOME_COUNTRY }, | 627 ADDRESS_HOME_COUNTRY }, |
593 { AutoFillProfilesView::EditableSetViewContents::TEXT_PHONE_PHONE, | 628 { AutoFillProfilesView::EditableSetViewContents::TEXT_PHONE_PHONE, |
594 PHONE_HOME_NUMBER }, | 629 PHONE_HOME_NUMBER }, |
595 { AutoFillProfilesView::EditableSetViewContents::TEXT_FAX_PHONE, | 630 { AutoFillProfilesView::EditableSetViewContents::TEXT_FAX_PHONE, |
596 PHONE_FAX_NUMBER }, | 631 PHONE_FAX_NUMBER }, |
597 }; | 632 }; |
598 | 633 |
599 AutoFillProfilesView::EditableSetViewContents::TextFieldToAutoFill | 634 AutoFillProfilesView::EditableSetViewContents::TextFieldToAutoFill |
600 AutoFillProfilesView::EditableSetViewContents::credit_card_fields_[] = { | 635 AutoFillProfilesView::EditableSetViewContents::credit_card_fields_[] = { |
601 { AutoFillProfilesView::EditableSetViewContents::TEXT_LABEL, NO_SERVER_DATA }, | |
602 { AutoFillProfilesView::EditableSetViewContents::TEXT_CC_NAME, | 636 { AutoFillProfilesView::EditableSetViewContents::TEXT_CC_NAME, |
603 CREDIT_CARD_NAME }, | 637 CREDIT_CARD_NAME }, |
604 { AutoFillProfilesView::EditableSetViewContents::TEXT_CC_NUMBER, | 638 { AutoFillProfilesView::EditableSetViewContents::TEXT_CC_NUMBER, |
605 CREDIT_CARD_NUMBER }, | 639 CREDIT_CARD_NUMBER }, |
606 }; | 640 }; |
607 | 641 |
608 ///////////////////////////////////////////////////////////////////////////// | 642 ///////////////////////////////////////////////////////////////////////////// |
609 // AutoFillProfilesView::EditableSetViewContents, public: | 643 // AutoFillProfilesView::EditableSetViewContents, public: |
610 AutoFillProfilesView::EditableSetViewContents::EditableSetViewContents( | 644 AutoFillProfilesView::EditableSetViewContents::EditableSetViewContents( |
611 AutoFillProfilesView* observer, | 645 AutoFillProfilesView* observer, |
612 AddressComboBoxModel* billing_model, | 646 AddressComboBoxModel* billing_model, |
613 bool new_item, | 647 bool new_item, |
614 std::vector<EditableSetInfo>::iterator field_set) | 648 std::vector<EditableSetInfo>::iterator field_set) |
615 : editable_fields_set_(field_set), | 649 : editable_fields_set_(field_set), |
616 temporary_info_(*editable_fields_set_), | 650 temporary_info_(*editable_fields_set_), |
617 label_warning_button_(NULL), | |
618 observer_(observer), | 651 observer_(observer), |
619 billing_model_(billing_model), | 652 billing_model_(billing_model), |
620 combo_box_billing_(NULL), | 653 combo_box_billing_(NULL), |
621 new_item_(new_item) { | 654 new_item_(new_item) { |
622 ZeroMemory(text_fields_, sizeof(text_fields_)); | 655 ZeroMemory(text_fields_, sizeof(text_fields_)); |
623 } | 656 } |
624 | 657 |
625 ///////////////////////////////////////////////////////////////////////////// | 658 ///////////////////////////////////////////////////////////////////////////// |
626 // AutoFillProfilesView::EditableSetViewContents, protected: | 659 // AutoFillProfilesView::EditableSetViewContents, protected: |
627 ///////////////////////////////////////////////////////////////////////////// | 660 ///////////////////////////////////////////////////////////////////////////// |
(...skipping 16 matching lines...) Expand all Loading... |
644 | 677 |
645 void AutoFillProfilesView::EditableSetViewContents::ViewHierarchyChanged( | 678 void AutoFillProfilesView::EditableSetViewContents::ViewHierarchyChanged( |
646 bool is_add, views::View* parent, views::View* child) { | 679 bool is_add, views::View* parent, views::View* child) { |
647 if (is_add && this == child) { | 680 if (is_add && this == child) { |
648 observer_->ChildWindowOpened(); | 681 observer_->ChildWindowOpened(); |
649 views::GridLayout* layout = new views::GridLayout(this); | 682 views::GridLayout* layout = new views::GridLayout(this); |
650 layout->SetInsets(kSubViewVerticalInsets, kSubViewHorizotalInsets, | 683 layout->SetInsets(kSubViewVerticalInsets, kSubViewHorizotalInsets, |
651 kSubViewVerticalInsets, kSubViewHorizotalInsets); | 684 kSubViewVerticalInsets, kSubViewHorizotalInsets); |
652 SetLayoutManager(layout); | 685 SetLayoutManager(layout); |
653 InitLayoutGrid(layout); | 686 InitLayoutGrid(layout); |
654 InitTitle(layout); | |
655 if (temporary_info_.is_address) | 687 if (temporary_info_.is_address) |
656 InitAddressFields(layout); | 688 InitAddressFields(layout); |
657 else | 689 else |
658 InitCreditCardFields(layout); | 690 InitCreditCardFields(layout); |
659 } | 691 } |
660 } | 692 } |
661 | 693 |
662 ///////////////////////////////////////////////////////////////////////////// | 694 ///////////////////////////////////////////////////////////////////////////// |
663 // AutoFillProfilesView::EditableSetViewContents, | 695 // AutoFillProfilesView::EditableSetViewContents, |
664 // views::DialogDelegate implementations | 696 // views::DialogDelegate implementations |
(...skipping 20 matching lines...) Expand all Loading... |
685 bool AutoFillProfilesView::EditableSetViewContents::IsDialogButtonEnabled( | 717 bool AutoFillProfilesView::EditableSetViewContents::IsDialogButtonEnabled( |
686 MessageBoxFlags::DialogButton button) const { | 718 MessageBoxFlags::DialogButton button) const { |
687 switch (button) { | 719 switch (button) { |
688 case MessageBoxFlags::DIALOGBUTTON_OK: { | 720 case MessageBoxFlags::DIALOGBUTTON_OK: { |
689 bool phones_are_valid = true; | 721 bool phones_are_valid = true; |
690 for (std::vector<PhoneSubView*>::const_iterator it = | 722 for (std::vector<PhoneSubView*>::const_iterator it = |
691 phone_sub_views_.begin(); | 723 phone_sub_views_.begin(); |
692 it != phone_sub_views_.end() && phones_are_valid; ++it) | 724 it != phone_sub_views_.end() && phones_are_valid; ++it) |
693 phones_are_valid = (phones_are_valid && (*it)->IsValid()); | 725 phones_are_valid = (phones_are_valid && (*it)->IsValid()); |
694 | 726 |
695 return phones_are_valid && LabelValid(); | 727 return phones_are_valid; |
696 } | 728 } |
697 case MessageBoxFlags::DIALOGBUTTON_CANCEL: | 729 case MessageBoxFlags::DIALOGBUTTON_CANCEL: |
698 return true; | 730 return true; |
699 default: | 731 default: |
700 break; | 732 break; |
701 } | 733 } |
702 NOTREACHED(); | 734 NOTREACHED(); |
703 return false; | 735 return false; |
704 } | 736 } |
705 | 737 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 if (temporary_info_.is_address) { | 775 if (temporary_info_.is_address) { |
744 index = editable_fields_set_ - observer_->profiles_set_.begin(); | 776 index = editable_fields_set_ - observer_->profiles_set_.begin(); |
745 } else { | 777 } else { |
746 index = editable_fields_set_ - observer_->credit_card_set_.begin(); | 778 index = editable_fields_set_ - observer_->credit_card_set_.begin(); |
747 index += observer_->profiles_set_.size(); | 779 index += observer_->profiles_set_.size(); |
748 } | 780 } |
749 if (new_item_) | 781 if (new_item_) |
750 observer_->table_model_->AddItem(index); | 782 observer_->table_model_->AddItem(index); |
751 else | 783 else |
752 observer_->table_model_->UpdateItem(index); | 784 observer_->table_model_->UpdateItem(index); |
| 785 if (temporary_info_.is_address) |
| 786 observer_->UpdateProfileLabels(); |
753 return true; | 787 return true; |
754 } | 788 } |
755 | 789 |
756 ///////////////////////////////////////////////////////////////////////////// | 790 ///////////////////////////////////////////////////////////////////////////// |
757 // AutoFillProfilesView::EditableSetViewContents, | 791 // AutoFillProfilesView::EditableSetViewContents, |
758 // views::ButtonListener implementations | 792 // views::ButtonListener implementations |
759 void AutoFillProfilesView::EditableSetViewContents::ButtonPressed( | 793 void AutoFillProfilesView::EditableSetViewContents::ButtonPressed( |
760 views::Button* sender, const views::Event& event) { | 794 views::Button* sender, const views::Event& event) { |
761 NOTREACHED(); | 795 NOTREACHED(); |
762 } | 796 } |
763 | 797 |
764 | 798 |
765 ///////////////////////////////////////////////////////////////////////////// | 799 ///////////////////////////////////////////////////////////////////////////// |
766 // AutoFillProfilesView::EditableSetViewContents, | 800 // AutoFillProfilesView::EditableSetViewContents, |
767 // views::Textfield::Controller implementations | 801 // views::Textfield::Controller implementations |
768 void AutoFillProfilesView::EditableSetViewContents::ContentsChanged( | 802 void AutoFillProfilesView::EditableSetViewContents::ContentsChanged( |
769 views::Textfield* sender, const string16& new_contents) { | 803 views::Textfield* sender, const string16& new_contents) { |
770 if (temporary_info_.is_address) { | 804 if (temporary_info_.is_address) { |
771 for (int field = 0; field < arraysize(address_fields_); ++field) { | 805 for (int field = 0; field < arraysize(address_fields_); ++field) { |
772 DCHECK(text_fields_[address_fields_[field].text_field]); | 806 DCHECK(text_fields_[address_fields_[field].text_field]); |
773 if (text_fields_[address_fields_[field].text_field] == sender) { | 807 if (text_fields_[address_fields_[field].text_field] == sender) { |
774 if (address_fields_[field].text_field == TEXT_LABEL) { | 808 UpdateContentsPhoneViews(address_fields_[field].text_field, |
775 temporary_info_.address.set_label(new_contents); | 809 sender, new_contents); |
776 // One of the address labels changed - update combo boxes | 810 temporary_info_.address.SetInfo( |
777 billing_model_->LabelChanged(); | 811 AutoFillType(address_fields_[field].type), new_contents); |
778 } else { | |
779 UpdateContentsPhoneViews(address_fields_[field].text_field, | |
780 sender, new_contents); | |
781 temporary_info_.address.SetInfo( | |
782 AutoFillType(address_fields_[field].type), new_contents); | |
783 } | |
784 UpdateButtons(); | 812 UpdateButtons(); |
785 return; | 813 return; |
786 } | 814 } |
787 } | 815 } |
788 } else { | 816 } else { |
789 for (int field = 0; field < arraysize(credit_card_fields_); ++field) { | 817 for (int field = 0; field < arraysize(credit_card_fields_); ++field) { |
790 DCHECK(text_fields_[credit_card_fields_[field].text_field]); | 818 DCHECK(text_fields_[credit_card_fields_[field].text_field]); |
791 if (text_fields_[credit_card_fields_[field].text_field] == sender) { | 819 if (text_fields_[credit_card_fields_[field].text_field] == sender) { |
792 if (credit_card_fields_[field].text_field == TEXT_LABEL) { | 820 UpdateContentsPhoneViews(address_fields_[field].text_field, |
793 temporary_info_.credit_card.set_label(new_contents); | 821 sender, new_contents); |
794 } else { | 822 temporary_info_.credit_card.SetInfo( |
795 UpdateContentsPhoneViews(address_fields_[field].text_field, | 823 AutoFillType(credit_card_fields_[field].type), new_contents); |
796 sender, new_contents); | |
797 temporary_info_.credit_card.SetInfo( | |
798 AutoFillType(credit_card_fields_[field].type), new_contents); | |
799 } | |
800 UpdateButtons(); | 824 UpdateButtons(); |
801 return; | 825 return; |
802 } | 826 } |
803 } | 827 } |
804 } | 828 } |
805 } | 829 } |
806 | 830 |
807 bool AutoFillProfilesView::EditableSetViewContents::HandleKeystroke( | 831 bool AutoFillProfilesView::EditableSetViewContents::HandleKeystroke( |
808 views::Textfield* sender, const views::Textfield::Keystroke& keystroke) { | 832 views::Textfield* sender, const views::Textfield::Keystroke& keystroke) { |
809 if (sender == text_fields_[TEXT_CC_NUMBER] && | 833 if (sender == text_fields_[TEXT_CC_NUMBER] && |
810 !temporary_info_.has_credit_card_number_been_edited) { | 834 !temporary_info_.has_credit_card_number_been_edited) { |
811 // You cannot edit obfuscated number, you must retype it anew. | 835 // You cannot edit obfuscated number, you must retype it anew. |
812 sender->SetText(string16()); | 836 sender->SetText(string16()); |
813 temporary_info_.has_credit_card_number_been_edited = true; | 837 temporary_info_.has_credit_card_number_been_edited = true; |
814 } | 838 } |
815 return false; | 839 return false; |
816 } | 840 } |
817 | 841 |
818 ///////////////////////////////////////////////////////////////////////////// | 842 ///////////////////////////////////////////////////////////////////////////// |
819 // AutoFillProfilesView::EditableSetViewContents, | 843 // AutoFillProfilesView::EditableSetViewContents, |
820 // views::Combobox::Listener implementations: | 844 // views::Combobox::Listener implementations: |
821 void AutoFillProfilesView::EditableSetViewContents::ItemChanged( | 845 void AutoFillProfilesView::EditableSetViewContents::ItemChanged( |
822 views::Combobox* combo_box, int prev_index, int new_index) { | 846 views::Combobox* combo_box, int prev_index, int new_index) { |
823 DCHECK(billing_model_); | 847 DCHECK(billing_model_); |
824 if (combo_box == combo_box_billing_) { | 848 if (combo_box == combo_box_billing_) { |
825 if (new_index == -1) { | 849 if (new_index == -1) { |
826 NOTREACHED(); | 850 NOTREACHED(); |
827 } else { | 851 } else { |
| 852 DCHECK(new_index < static_cast<int>(observer_->profiles_set_.size())); |
828 temporary_info_.credit_card.set_billing_address( | 853 temporary_info_.credit_card.set_billing_address( |
829 billing_model_->GetItemAt(new_index)); | 854 IntToString16( |
| 855 observer_->profiles_set_[new_index].address.unique_id())); |
830 } | 856 } |
831 } else if (combo_box == combo_box_month_) { | 857 } else if (combo_box == combo_box_month_) { |
832 if (new_index == -1) { | 858 if (new_index == -1) { |
833 NOTREACHED(); | 859 NOTREACHED(); |
834 } else { | 860 } else { |
835 temporary_info_.credit_card.SetInfo( | 861 temporary_info_.credit_card.SetInfo( |
836 AutoFillType(CREDIT_CARD_EXP_MONTH), | 862 AutoFillType(CREDIT_CARD_EXP_MONTH), |
837 combo_box_model_month_->GetItemAt(new_index)); | 863 combo_box_model_month_->GetItemAt(new_index)); |
838 } | 864 } |
839 } else if (combo_box == combo_box_year_) { | 865 } else if (combo_box == combo_box_year_) { |
840 if (new_index == -1) { | 866 if (new_index == -1) { |
841 NOTREACHED(); | 867 NOTREACHED(); |
842 } else { | 868 } else { |
843 temporary_info_.credit_card.SetInfo( | 869 temporary_info_.credit_card.SetInfo( |
844 AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), | 870 AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), |
845 combo_box_model_year_->GetItemAt(new_index)); | 871 combo_box_model_year_->GetItemAt(new_index)); |
846 } | 872 } |
847 } else { | 873 } else { |
848 NOTREACHED(); | 874 NOTREACHED(); |
849 } | 875 } |
850 } | 876 } |
851 | 877 |
852 ///////////////////////////////////////////////////////////////////////////// | 878 ///////////////////////////////////////////////////////////////////////////// |
853 // AutoFillProfilesView::EditableSetViewContents, private: | 879 // AutoFillProfilesView::EditableSetViewContents, private: |
854 void AutoFillProfilesView::EditableSetViewContents::InitTitle( | |
855 views::GridLayout* layout) { | |
856 std::wstring title; | |
857 if (temporary_info_.is_address) { | |
858 title = temporary_info_.address.Label(); | |
859 if (title.empty()) | |
860 title = l10n_util::GetString(IDS_AUTOFILL_NEW_ADDRESS); | |
861 } else { | |
862 title = temporary_info_.credit_card.Label(); | |
863 if (title.empty()) | |
864 title = l10n_util::GetString(IDS_AUTOFILL_NEW_CREDITCARD); | |
865 } | |
866 label_warning_button_ = new views::ImageButton(this); | |
867 label_warning_button_->SetEnabled(false); | |
868 label_warning_button_->SetImageAlignment(views::ImageButton::ALIGN_LEFT, | |
869 views::ImageButton::ALIGN_MIDDLE); | |
870 text_fields_[TEXT_LABEL] = | |
871 new views::Textfield(views::Textfield::STYLE_DEFAULT); | |
872 text_fields_[TEXT_LABEL]->SetText(temporary_info_.is_address ? | |
873 temporary_info_.address.Label() : temporary_info_.credit_card.Label()); | |
874 text_fields_[TEXT_LABEL]->SetController(this); | |
875 | |
876 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | |
877 layout->StartRow(0, triple_column_leading_view_set_id_); | |
878 layout->AddView(new views::Label( | |
879 l10n_util::GetString(IDS_AUTOFILL_DIALOG_LABEL))); | |
880 | |
881 layout->StartRow(0, triple_column_fill_view_set_id_); | |
882 layout->AddView(text_fields_[TEXT_LABEL]); | |
883 layout->AddView(label_warning_button_); | |
884 } | |
885 | |
886 void AutoFillProfilesView::EditableSetViewContents::InitAddressFields( | 880 void AutoFillProfilesView::EditableSetViewContents::InitAddressFields( |
887 views::GridLayout* layout) { | 881 views::GridLayout* layout) { |
888 DCHECK(temporary_info_.is_address); | 882 DCHECK(temporary_info_.is_address); |
889 | 883 |
890 for (int field = 0; field < arraysize(address_fields_); ++field) { | 884 for (int field = 0; field < arraysize(address_fields_); ++field) { |
891 if (address_fields_[field].text_field == TEXT_LABEL) | |
892 continue; | |
893 DCHECK(!text_fields_[address_fields_[field].text_field]); | 885 DCHECK(!text_fields_[address_fields_[field].text_field]); |
894 text_fields_[address_fields_[field].text_field] = | 886 text_fields_[address_fields_[field].text_field] = |
895 new views::Textfield(views::Textfield::STYLE_DEFAULT); | 887 new views::Textfield(views::Textfield::STYLE_DEFAULT); |
896 text_fields_[address_fields_[field].text_field]->SetController(this); | 888 text_fields_[address_fields_[field].text_field]->SetController(this); |
897 text_fields_[address_fields_[field].text_field]->SetText( | 889 text_fields_[address_fields_[field].text_field]->SetText( |
898 temporary_info_.address.GetFieldText( | 890 temporary_info_.address.GetFieldText( |
899 AutoFillType(address_fields_[field].type))); | 891 AutoFillType(address_fields_[field].type))); |
900 } | 892 } |
901 | 893 |
902 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 894 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
997 model_strings.clear(); | 989 model_strings.clear(); |
998 model_strings.reserve(20); | 990 model_strings.reserve(20); |
999 base::Time::Exploded exploded_time; | 991 base::Time::Exploded exploded_time; |
1000 base::Time::Now().LocalExplode(&exploded_time); | 992 base::Time::Now().LocalExplode(&exploded_time); |
1001 for (int year = 0; year < 10; ++year) | 993 for (int year = 0; year < 10; ++year) |
1002 model_strings.push_back(StringPrintf(L"%04i", year + exploded_time.year)); | 994 model_strings.push_back(StringPrintf(L"%04i", year + exploded_time.year)); |
1003 combo_box_model_year_.reset(new StringVectorComboboxModel); | 995 combo_box_model_year_.reset(new StringVectorComboboxModel); |
1004 combo_box_model_year_->set_cb_strings(&model_strings); | 996 combo_box_model_year_->set_cb_strings(&model_strings); |
1005 | 997 |
1006 for (int field = 0; field < arraysize(credit_card_fields_); ++field) { | 998 for (int field = 0; field < arraysize(credit_card_fields_); ++field) { |
1007 if (credit_card_fields_[field].text_field == TEXT_LABEL) | |
1008 continue; | |
1009 DCHECK(!text_fields_[credit_card_fields_[field].text_field]); | 999 DCHECK(!text_fields_[credit_card_fields_[field].text_field]); |
1010 text_fields_[credit_card_fields_[field].text_field] = | 1000 text_fields_[credit_card_fields_[field].text_field] = |
1011 new views::Textfield(views::Textfield::STYLE_DEFAULT); | 1001 new views::Textfield(views::Textfield::STYLE_DEFAULT); |
1012 text_fields_[credit_card_fields_[field].text_field]->SetController(this); | 1002 text_fields_[credit_card_fields_[field].text_field]->SetController(this); |
1013 string16 field_text; | 1003 string16 field_text; |
1014 if (credit_card_fields_[field].text_field == TEXT_CC_NUMBER) { | 1004 if (credit_card_fields_[field].text_field == TEXT_CC_NUMBER) { |
1015 field_text = temporary_info_.credit_card.GetFieldText( | 1005 field_text = temporary_info_.credit_card.GetFieldText( |
1016 AutoFillType(credit_card_fields_[field].type)); | 1006 AutoFillType(credit_card_fields_[field].type)); |
1017 if (!field_text.empty()) | 1007 if (!field_text.empty()) |
1018 field_text = temporary_info_.credit_card.ObfuscatedNumber(); | 1008 field_text = temporary_info_.credit_card.ObfuscatedNumber(); |
1019 } else { | 1009 } else { |
1020 field_text = temporary_info_.credit_card.GetFieldText( | 1010 field_text = temporary_info_.credit_card.GetFieldText( |
1021 AutoFillType(credit_card_fields_[field].type)); | 1011 AutoFillType(credit_card_fields_[field].type)); |
1022 } | 1012 } |
1023 text_fields_[credit_card_fields_[field].text_field]->SetText(field_text); | 1013 text_fields_[credit_card_fields_[field].text_field]->SetText(field_text); |
1024 } | 1014 } |
1025 | 1015 |
1026 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 1016 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
1027 layout->StartRow(0, double_column_fill_view_set_id_); | 1017 layout->StartRow(0, double_column_fill_view_set_id_); |
1028 layout->AddView(CreateLeftAlignedLabel(IDS_AUTOFILL_DIALOG_NAME_ON_CARD)); | 1018 layout->AddView(CreateLeftAlignedLabel(IDS_AUTOFILL_DIALOG_NAME_ON_CARD)); |
1029 layout->StartRow(0, double_column_fill_view_set_id_); | 1019 layout->StartRow(0, double_column_fill_view_set_id_); |
1030 layout->AddView(text_fields_[TEXT_CC_NAME]); | 1020 layout->AddView(text_fields_[TEXT_CC_NAME]); |
1031 | 1021 |
1032 // Address combo boxes. | 1022 // Address combo boxes. |
1033 combo_box_billing_ = new views::Combobox(billing_model_); | 1023 combo_box_billing_ = new views::Combobox(billing_model_); |
1034 combo_box_billing_->set_listener(this); | 1024 combo_box_billing_->set_listener(this); |
1035 combo_box_billing_->SetSelectedItem( | 1025 int billing_id = -1; |
1036 billing_model_->GetIndex( | 1026 if (StringToInt(temporary_info_.credit_card.billing_address(), &billing_id)) |
1037 temporary_info_.credit_card.billing_address())); | 1027 combo_box_billing_->SetSelectedItem(billing_model_->GetIndex(billing_id)); |
1038 billing_model_->UsedWithComboBox(combo_box_billing_); | 1028 billing_model_->UsedWithComboBox(combo_box_billing_); |
1039 | 1029 |
1040 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 1030 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
1041 layout->StartRow(0, double_column_fill_view_set_id_); | 1031 layout->StartRow(0, double_column_fill_view_set_id_); |
1042 layout->AddView(CreateLeftAlignedLabel(IDS_AUTOFILL_DIALOG_BILLING_ADDRESS)); | 1032 layout->AddView(CreateLeftAlignedLabel(IDS_AUTOFILL_DIALOG_BILLING_ADDRESS)); |
1043 layout->StartRow(0, double_column_fill_view_set_id_); | 1033 layout->StartRow(0, double_column_fill_view_set_id_); |
1044 layout->AddView(combo_box_billing_); | 1034 layout->AddView(combo_box_billing_); |
1045 | 1035 |
1046 // Layout credit card info | 1036 // Layout credit card info |
1047 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 1037 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1160 } | 1150 } |
1161 | 1151 |
1162 views::Label* | 1152 views::Label* |
1163 AutoFillProfilesView::EditableSetViewContents::CreateLeftAlignedLabel( | 1153 AutoFillProfilesView::EditableSetViewContents::CreateLeftAlignedLabel( |
1164 int label_id) { | 1154 int label_id) { |
1165 views::Label* label = new views::Label(l10n_util::GetString(label_id)); | 1155 views::Label* label = new views::Label(l10n_util::GetString(label_id)); |
1166 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 1156 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
1167 return label; | 1157 return label; |
1168 } | 1158 } |
1169 | 1159 |
1170 bool AutoFillProfilesView::EditableSetViewContents::LabelValid() const { | |
1171 if (temporary_info_.is_address) | |
1172 return !temporary_info_.address.Label().empty(); | |
1173 else | |
1174 return !temporary_info_.credit_card.Label().empty(); | |
1175 } | |
1176 | |
1177 void AutoFillProfilesView::EditableSetViewContents::UpdateButtons() { | 1160 void AutoFillProfilesView::EditableSetViewContents::UpdateButtons() { |
1178 SkBitmap* image = observer_->GetWarningBimap(LabelValid()); | |
1179 if (LabelValid()) { | |
1180 label_warning_button_->SetTooltipText(std::wstring()); | |
1181 } else { | |
1182 label_warning_button_->SetTooltipText(l10n_util::GetString( | |
1183 IDS_AUTOFILL_BAD_LABEL_TOOLTIP)); | |
1184 } | |
1185 label_warning_button_->SetImage(views::CustomButton::BS_NORMAL, image); | |
1186 GetDialogClientView()->UpdateDialogButtons(); | 1161 GetDialogClientView()->UpdateDialogButtons(); |
1187 } | 1162 } |
1188 | 1163 |
1189 void AutoFillProfilesView::EditableSetViewContents::UpdateContentsPhoneViews( | 1164 void AutoFillProfilesView::EditableSetViewContents::UpdateContentsPhoneViews( |
1190 TextFields field, views::Textfield* sender, const string16& new_contents) { | 1165 TextFields field, views::Textfield* sender, const string16& new_contents) { |
1191 switch (field) { | 1166 switch (field) { |
1192 case TEXT_PHONE_PHONE: | 1167 case TEXT_PHONE_PHONE: |
1193 case TEXT_FAX_PHONE: { | 1168 case TEXT_FAX_PHONE: { |
1194 for (std::vector<PhoneSubView*>::iterator it = phone_sub_views_.begin(); | 1169 for (std::vector<PhoneSubView*>::iterator it = phone_sub_views_.begin(); |
1195 it != phone_sub_views_.end(); ++it) | 1170 it != phone_sub_views_.end(); ++it) |
(...skipping 23 matching lines...) Expand all Loading... |
1219 } | 1194 } |
1220 | 1195 |
1221 void AutoFillProfilesView::AddressComboBoxModel::LabelChanged() { | 1196 void AutoFillProfilesView::AddressComboBoxModel::LabelChanged() { |
1222 DCHECK(address_labels_); | 1197 DCHECK(address_labels_); |
1223 for (std::list<views::Combobox*>::iterator it = combo_boxes_.begin(); | 1198 for (std::list<views::Combobox*>::iterator it = combo_boxes_.begin(); |
1224 it != combo_boxes_.end(); | 1199 it != combo_boxes_.end(); |
1225 ++it) | 1200 ++it) |
1226 (*it)->ModelChanged(); | 1201 (*it)->ModelChanged(); |
1227 } | 1202 } |
1228 | 1203 |
1229 int AutoFillProfilesView::AddressComboBoxModel::GetIndex(const string16 &s) { | 1204 int AutoFillProfilesView::AddressComboBoxModel::GetIndex(int unique_id) { |
1230 int shift = is_billing_ ? 0 : 1; | 1205 int shift = is_billing_ ? 0 : 1; |
1231 DCHECK(address_labels_); | 1206 DCHECK(address_labels_); |
1232 for (size_t i = 0; i < address_labels_->size(); ++i) { | 1207 for (size_t i = 0; i < address_labels_->size(); ++i) { |
1233 DCHECK(address_labels_->at(i).is_address); | 1208 DCHECK(address_labels_->at(i).is_address); |
1234 if (address_labels_->at(i).address.Label() == s) | 1209 if (address_labels_->at(i).address.unique_id() == unique_id) |
1235 return i + shift; | 1210 return i + shift; |
1236 } | 1211 } |
1237 return -1; | 1212 return -1; |
1238 } | 1213 } |
1239 | 1214 |
1240 ///////////////////////////////////////////////////////////////////////////// | 1215 ///////////////////////////////////////////////////////////////////////////// |
1241 // AutoFillProfilesView::AddressComboBoxModel, ComboboxModel methods | 1216 // AutoFillProfilesView::AddressComboBoxModel, ComboboxModel methods |
1242 int AutoFillProfilesView::AddressComboBoxModel::GetItemCount() { | 1217 int AutoFillProfilesView::AddressComboBoxModel::GetItemCount() { |
1243 DCHECK(address_labels_); | 1218 DCHECK(address_labels_); |
1244 int shift = is_billing_ ? 0 : 1; | 1219 int shift = is_billing_ ? 0 : 1; |
1245 return static_cast<int>(address_labels_->size()) + shift; | 1220 return static_cast<int>(address_labels_->size()) + shift; |
1246 } | 1221 } |
1247 | 1222 |
1248 std::wstring AutoFillProfilesView::AddressComboBoxModel::GetItemAt(int index) { | 1223 std::wstring AutoFillProfilesView::AddressComboBoxModel::GetItemAt(int index) { |
1249 DCHECK(address_labels_); | 1224 DCHECK(address_labels_); |
1250 int shift = is_billing_ ? 0 : 1; | 1225 int shift = is_billing_ ? 0 : 1; |
1251 DCHECK(index < (static_cast<int>(address_labels_->size()) + shift)); | 1226 DCHECK(index < (static_cast<int>(address_labels_->size()) + shift)); |
1252 if (!is_billing_ && !index) | 1227 if (!is_billing_ && !index) |
1253 return l10n_util::GetString(IDS_AUTOFILL_DIALOG_SAME_AS_BILLING); | 1228 return l10n_util::GetString(IDS_AUTOFILL_DIALOG_SAME_AS_BILLING); |
1254 DCHECK(address_labels_->at(index - shift).is_address); | 1229 DCHECK(address_labels_->at(index - shift).is_address); |
1255 std::wstring label = address_labels_->at(index - shift).address.Label(); | 1230 std::wstring label = |
| 1231 address_labels_->at(index - shift).address.Label(); |
1256 if (label.empty()) | 1232 if (label.empty()) |
1257 label = l10n_util::GetString(IDS_AUTOFILL_NEW_ADDRESS); | 1233 label = l10n_util::GetString(IDS_AUTOFILL_NEW_ADDRESS); |
1258 return label; | 1234 return label; |
1259 } | 1235 } |
1260 | 1236 |
1261 void AutoFillProfilesView::StringVectorComboboxModel::set_cb_strings( | 1237 void AutoFillProfilesView::StringVectorComboboxModel::set_cb_strings( |
1262 std::vector<std::wstring> *source) { | 1238 std::vector<std::wstring> *source) { |
1263 cb_strings_.swap(*source); | 1239 cb_strings_.swap(*source); |
1264 } | 1240 } |
1265 | 1241 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1315 } | 1291 } |
1316 | 1292 |
1317 int AutoFillProfilesView::ContentListTableModel::RowCount() { | 1293 int AutoFillProfilesView::ContentListTableModel::RowCount() { |
1318 return profiles_->size() + credit_cards_->size(); | 1294 return profiles_->size() + credit_cards_->size(); |
1319 } | 1295 } |
1320 | 1296 |
1321 std::wstring AutoFillProfilesView::ContentListTableModel::GetText( | 1297 std::wstring AutoFillProfilesView::ContentListTableModel::GetText( |
1322 int row, int column_id) { | 1298 int row, int column_id) { |
1323 DCHECK(row < static_cast<int>(profiles_->size() + credit_cards_->size())); | 1299 DCHECK(row < static_cast<int>(profiles_->size() + credit_cards_->size())); |
1324 if (row < static_cast<int>(profiles_->size())) { | 1300 if (row < static_cast<int>(profiles_->size())) { |
1325 if (column_id == IDS_AUTOFILL_LIST_HEADER_LABEL) { | 1301 return profiles_->at(row).address.PreviewSummary(); |
1326 return profiles_->at(row).address.Label(); | |
1327 } else { | |
1328 return profiles_->at(row).address.PreviewSummary(); | |
1329 } | |
1330 } else { | 1302 } else { |
1331 row -= profiles_->size(); | 1303 row -= profiles_->size(); |
1332 if (column_id == IDS_AUTOFILL_LIST_HEADER_LABEL) { | 1304 return credit_cards_->at(row).credit_card.PreviewSummary(); |
1333 return credit_cards_->at(row).credit_card.Label(); | |
1334 } else { | |
1335 return credit_cards_->at(row).credit_card.PreviewSummary(); | |
1336 } | |
1337 } | 1305 } |
1338 } | 1306 } |
1339 | 1307 |
1340 TableModel::Groups AutoFillProfilesView::ContentListTableModel::GetGroups() { | 1308 TableModel::Groups AutoFillProfilesView::ContentListTableModel::GetGroups() { |
1341 TableModel::Groups groups; | 1309 TableModel::Groups groups; |
1342 | 1310 |
1343 TableModel::Group profile_group; | 1311 TableModel::Group profile_group; |
1344 profile_group.title = l10n_util::GetString(IDS_AUTOFILL_ADDRESSES_GROUP_NAME); | 1312 profile_group.title = l10n_util::GetString(IDS_AUTOFILL_ADDRESSES_GROUP_NAME); |
1345 profile_group.id = kAddressGroup; | 1313 profile_group.id = kAddressGroup; |
1346 groups.push_back(profile_group); | 1314 groups.push_back(profile_group); |
(...skipping 20 matching lines...) Expand all Loading... |
1367 | 1335 |
1368 // Declared in "chrome/browser/autofill/autofill_dialog.h" | 1336 // Declared in "chrome/browser/autofill/autofill_dialog.h" |
1369 void ShowAutoFillDialog(gfx::NativeView parent, | 1337 void ShowAutoFillDialog(gfx::NativeView parent, |
1370 AutoFillDialogObserver* observer, | 1338 AutoFillDialogObserver* observer, |
1371 Profile* profile) { | 1339 Profile* profile) { |
1372 DCHECK(profile); | 1340 DCHECK(profile); |
1373 | 1341 |
1374 PersonalDataManager* personal_data_manager = | 1342 PersonalDataManager* personal_data_manager = |
1375 profile->GetPersonalDataManager(); | 1343 profile->GetPersonalDataManager(); |
1376 DCHECK(personal_data_manager); | 1344 DCHECK(personal_data_manager); |
1377 AutoFillProfilesView::Show(parent, observer, personal_data_manager, | 1345 AutoFillProfilesView::Show(parent, observer, personal_data_manager, profile, |
1378 profile->GetPrefs(), NULL, NULL); | 1346 profile->GetPrefs(), NULL, NULL); |
1379 } | 1347 } |
OLD | NEW |