| 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 | 4 |
| 5 #import "chrome/browser/autofill/autofill_dialog_controller_mac.h" | 5 #import "chrome/browser/autofill/autofill_dialog_controller_mac.h" |
| 6 #include "app/l10n_util.h" | 6 #include "app/l10n_util.h" |
| 7 #include "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
| 8 #include "base/mac_util.h" | 8 #include "base/mac_util.h" |
| 9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
| 10 #include "chrome/browser/browser.h" | 10 #include "chrome/browser/browser.h" |
| 11 #include "chrome/browser/browser_list.h" | 11 #include "chrome/browser/browser_list.h" |
| 12 #import "chrome/browser/autofill/autofill_address_model_mac.h" | 12 #import "chrome/browser/autofill/autofill_address_model_mac.h" |
| 13 #import "chrome/browser/autofill/autofill_address_sheet_controller_mac.h" | 13 #import "chrome/browser/autofill/autofill_address_sheet_controller_mac.h" |
| 14 #import "chrome/browser/autofill/autofill_credit_card_model_mac.h" | 14 #import "chrome/browser/autofill/autofill_credit_card_model_mac.h" |
| 15 #import "chrome/browser/autofill/autofill_credit_card_sheet_controller_mac.h" | 15 #import "chrome/browser/autofill/autofill_credit_card_sheet_controller_mac.h" |
| 16 #import "chrome/browser/autofill/personal_data_manager.h" | 16 #import "chrome/browser/autofill/personal_data_manager.h" |
| 17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 18 #import "chrome/browser/cocoa/window_size_autosaver.h" | 18 #import "chrome/browser/cocoa/window_size_autosaver.h" |
| 19 #include "chrome/browser/pref_service.h" | 19 #include "chrome/browser/pref_service.h" |
| 20 #include "chrome/browser/profile.h" | 20 #include "chrome/browser/profile.h" |
| 21 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
| 22 #include "grit/generated_resources.h" | 22 #include "grit/generated_resources.h" |
| 23 #include "grit/app_resources.h" | 23 #include "grit/app_resources.h" |
| 24 #include "grit/theme_resources.h" | 24 #include "grit/theme_resources.h" |
| 25 | 25 |
| 26 namespace { |
| 27 |
| 28 // Update profile labels passed as |input|. When profile data changes as a |
| 29 // result of adding new profiles, edititing existing profiles, or deleting a |
| 30 // profile, then the list of profiles need to have their derived labels |
| 31 // recomputed. |
| 32 void UpdateProfileLabels(std::vector<AutoFillProfile>* input) { |
| 33 DCHECK(input); |
| 34 std::vector<AutoFillProfile*> profiles; |
| 35 profiles.resize(input->size()); |
| 36 for (size_t i = 0; i < input->size(); ++i) { |
| 37 profiles[i] = &(*input)[i]; |
| 38 } |
| 39 AutoFillProfile::AdjustInferredLabels(&profiles); |
| 40 } |
| 41 |
| 42 } // namespace |
| 43 |
| 26 // Delegate protocol that needs to be in place for the AutoFillTableView's | 44 // Delegate protocol that needs to be in place for the AutoFillTableView's |
| 27 // handling of delete and backspace keys. | 45 // handling of delete and backspace keys. |
| 28 @protocol DeleteKeyDelegate | 46 @protocol DeleteKeyDelegate |
| 29 - (IBAction)deleteSelection:(id)sender; | 47 - (IBAction)deleteSelection:(id)sender; |
| 30 @end | 48 @end |
| 31 | 49 |
| 32 // A subclass of NSTableView that allows for deleting selected elements using | 50 // A subclass of NSTableView that allows for deleting selected elements using |
| 33 // the delete or backspace keys. | 51 // the delete or backspace keys. |
| 34 @interface AutoFillTableView : NSTableView { | 52 @interface AutoFillTableView : NSTableView { |
| 35 } | 53 } |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 contextInfo:(void*)contextInfo { | 313 contextInfo:(void*)contextInfo { |
| 296 DCHECK(contextInfo == NULL); | 314 DCHECK(contextInfo == NULL); |
| 297 | 315 |
| 298 if (returnCode) { | 316 if (returnCode) { |
| 299 // Create a new address and save it to the |profiles_| list. | 317 // Create a new address and save it to the |profiles_| list. |
| 300 AutoFillProfile newAddress(string16(), 0); | 318 AutoFillProfile newAddress(string16(), 0); |
| 301 [addressSheetController copyModelToProfile:&newAddress]; | 319 [addressSheetController copyModelToProfile:&newAddress]; |
| 302 profiles_.push_back(newAddress); | 320 profiles_.push_back(newAddress); |
| 303 | 321 |
| 304 // Refresh the view based on new data. | 322 // Refresh the view based on new data. |
| 323 UpdateProfileLabels(&profiles_); |
| 305 [tableView_ reloadData]; | 324 [tableView_ reloadData]; |
| 306 | 325 |
| 307 // Update the selection to the newly added item. | 326 // Update the selection to the newly added item. |
| 308 NSInteger row = [self rowFromProfileIndex:profiles_.size() - 1]; | 327 NSInteger row = [self rowFromProfileIndex:profiles_.size() - 1]; |
| 309 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:row] | 328 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:row] |
| 310 byExtendingSelection:NO]; | 329 byExtendingSelection:NO]; |
| 311 } | 330 } |
| 312 [sheet orderOut:self]; | 331 [sheet orderOut:self]; |
| 313 addressSheetController.reset(nil); | 332 addressSheetController.reset(nil); |
| 314 } | 333 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 if ([self tableView:tableView_ shouldSelectRow:selectedRow-1]) { | 367 if ([self tableView:tableView_ shouldSelectRow:selectedRow-1]) { |
| 349 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow-1] | 368 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow-1] |
| 350 byExtendingSelection:NO]; | 369 byExtendingSelection:NO]; |
| 351 } else if ([self tableView:tableView_ shouldSelectRow:selectedRow]) { | 370 } else if ([self tableView:tableView_ shouldSelectRow:selectedRow]) { |
| 352 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow] | 371 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow] |
| 353 byExtendingSelection:NO]; | 372 byExtendingSelection:NO]; |
| 354 } else { | 373 } else { |
| 355 [tableView_ selectRowIndexes:[NSIndexSet indexSet] | 374 [tableView_ selectRowIndexes:[NSIndexSet indexSet] |
| 356 byExtendingSelection:NO]; | 375 byExtendingSelection:NO]; |
| 357 } | 376 } |
| 377 UpdateProfileLabels(&profiles_); |
| 358 [tableView_ reloadData]; | 378 [tableView_ reloadData]; |
| 359 } else if ([self isCreditCardRow:selectedRow]) { | 379 } else if ([self isCreditCardRow:selectedRow]) { |
| 360 creditCards_.erase( | 380 creditCards_.erase( |
| 361 creditCards_.begin() + [self creditCardIndexFromRow:selectedRow]); | 381 creditCards_.begin() + [self creditCardIndexFromRow:selectedRow]); |
| 362 | 382 |
| 363 // Select the previous row if possible, else current row, else deselect all. | 383 // Select the previous row if possible, else current row, else deselect all. |
| 364 if ([self tableView:tableView_ shouldSelectRow:selectedRow-1]) { | 384 if ([self tableView:tableView_ shouldSelectRow:selectedRow-1]) { |
| 365 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow-1] | 385 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow-1] |
| 366 byExtendingSelection:NO]; | 386 byExtendingSelection:NO]; |
| 367 } else if ([self tableView:tableView_ shouldSelectRow:selectedRow]) { | 387 } else if ([self tableView:tableView_ shouldSelectRow:selectedRow]) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 } | 447 } |
| 428 | 448 |
| 429 // Edit address sheet was dismissed. Non-zero |returnCode| indicates a save. | 449 // Edit address sheet was dismissed. Non-zero |returnCode| indicates a save. |
| 430 - (void)addressEditDidEnd:(NSWindow *)sheet | 450 - (void)addressEditDidEnd:(NSWindow *)sheet |
| 431 returnCode:(int)returnCode | 451 returnCode:(int)returnCode |
| 432 contextInfo:(void *)contextInfo { | 452 contextInfo:(void *)contextInfo { |
| 433 DCHECK(contextInfo != NULL); | 453 DCHECK(contextInfo != NULL); |
| 434 if (returnCode) { | 454 if (returnCode) { |
| 435 AutoFillProfile* profile = static_cast<AutoFillProfile*>(contextInfo); | 455 AutoFillProfile* profile = static_cast<AutoFillProfile*>(contextInfo); |
| 436 [addressSheetController copyModelToProfile:profile]; | 456 [addressSheetController copyModelToProfile:profile]; |
| 457 UpdateProfileLabels(&profiles_); |
| 437 [tableView_ reloadData]; | 458 [tableView_ reloadData]; |
| 438 } | 459 } |
| 439 [sheet orderOut:self]; | 460 [sheet orderOut:self]; |
| 440 addressSheetController.reset(nil); | 461 addressSheetController.reset(nil); |
| 441 } | 462 } |
| 442 | 463 |
| 443 // Edit credit card sheet was dismissed. Non-zero |returnCode| indicates a | 464 // Edit credit card sheet was dismissed. Non-zero |returnCode| indicates a |
| 444 // save. | 465 // save. |
| 445 - (void)creditCardEditDidEnd:(NSWindow *)sheet | 466 - (void)creditCardEditDidEnd:(NSWindow *)sheet |
| 446 returnCode:(int)returnCode | 467 returnCode:(int)returnCode |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 return @""; | 507 return @""; |
| 487 } | 508 } |
| 488 | 509 |
| 489 if (row < 0) | 510 if (row < 0) |
| 490 return @""; | 511 return @""; |
| 491 | 512 |
| 492 // Data row. | 513 // Data row. |
| 493 if ([self isProfileRow:row]) { | 514 if ([self isProfileRow:row]) { |
| 494 if ([[tableColumn identifier] isEqualToString:@"Summary"]) { | 515 if ([[tableColumn identifier] isEqualToString:@"Summary"]) { |
| 495 return SysUTF16ToNSString( | 516 return SysUTF16ToNSString( |
| 496 profiles_[[self profileIndexFromRow:row]].PreviewSummary()); | 517 profiles_[[self profileIndexFromRow:row]].Label()); |
| 497 } | 518 } |
| 498 | 519 |
| 499 return @""; | 520 return @""; |
| 500 } | 521 } |
| 501 | 522 |
| 502 // Section label. | 523 // Section label. |
| 503 if ([self isCreditCardGroupRow:row]) { | 524 if ([self isCreditCardGroupRow:row]) { |
| 504 if ([[tableColumn identifier] isEqualToString:@"Summary"]) | 525 if ([[tableColumn identifier] isEqualToString:@"Summary"]) |
| 505 return l10n_util::GetNSString(IDS_AUTOFILL_CREDITCARDS_GROUP_NAME); | 526 return l10n_util::GetNSString(IDS_AUTOFILL_CREDITCARDS_GROUP_NAME); |
| 506 else | 527 else |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 // Make local copy of |profiles|. | 687 // Make local copy of |profiles|. |
| 667 for (std::vector<AutoFillProfile*>::const_iterator iter = profiles.begin(); | 688 for (std::vector<AutoFillProfile*>::const_iterator iter = profiles.begin(); |
| 668 iter != profiles.end(); ++iter) | 689 iter != profiles.end(); ++iter) |
| 669 profiles_.push_back(**iter); | 690 profiles_.push_back(**iter); |
| 670 | 691 |
| 671 // Make local copy of |creditCards|. | 692 // Make local copy of |creditCards|. |
| 672 for (std::vector<CreditCard*>::const_iterator iter = creditCards.begin(); | 693 for (std::vector<CreditCard*>::const_iterator iter = creditCards.begin(); |
| 673 iter != creditCards.end(); ++iter) | 694 iter != creditCards.end(); ++iter) |
| 674 creditCards_.push_back(**iter); | 695 creditCards_.push_back(**iter); |
| 675 } | 696 } |
| 697 |
| 698 UpdateProfileLabels(&profiles_); |
| 676 } | 699 } |
| 677 | 700 |
| 678 - (BOOL)isProfileRow:(NSInteger)row { | 701 - (BOOL)isProfileRow:(NSInteger)row { |
| 679 if (row > 0 && static_cast<size_t>(row) <= profiles_.size()) | 702 if (row > 0 && static_cast<size_t>(row) <= profiles_.size()) |
| 680 return YES; | 703 return YES; |
| 681 return NO; | 704 return NO; |
| 682 } | 705 } |
| 683 | 706 |
| 684 - (BOOL)isProfileGroupRow:(NSInteger)row { | 707 - (BOOL)isProfileGroupRow:(NSInteger)row { |
| 685 if (row == 0) | 708 if (row == 0) |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 765 if (!image) { | 788 if (!image) { |
| 766 image = rb.GetNSImageNamed(IDR_INPUT_GOOD); | 789 image = rb.GetNSImageNamed(IDR_INPUT_GOOD); |
| 767 DCHECK(image); | 790 DCHECK(image); |
| 768 return image; | 791 return image; |
| 769 } | 792 } |
| 770 | 793 |
| 771 return nil; | 794 return nil; |
| 772 } | 795 } |
| 773 | 796 |
| 774 @end | 797 @end |
| OLD | NEW |