summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autofill/autofill_dialog_controller_mac.mm
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/autofill/autofill_dialog_controller_mac.mm')
-rw-r--r--chrome/browser/autofill/autofill_dialog_controller_mac.mm62
1 files changed, 46 insertions, 16 deletions
diff --git a/chrome/browser/autofill/autofill_dialog_controller_mac.mm b/chrome/browser/autofill/autofill_dialog_controller_mac.mm
index d2df304..713c172 100644
--- a/chrome/browser/autofill/autofill_dialog_controller_mac.mm
+++ b/chrome/browser/autofill/autofill_dialog_controller_mac.mm
@@ -5,18 +5,19 @@
#import "chrome/browser/autofill/autofill_dialog_controller_mac.h"
#include "app/l10n_util.h"
#include "app/resource_bundle.h"
+#include "base/lazy_instance.h"
#include "base/mac_util.h"
-#include "base/singleton.h"
#include "base/sys_string_conversions.h"
#import "chrome/browser/autofill/autofill_address_model_mac.h"
#import "chrome/browser/autofill/autofill_address_sheet_controller_mac.h"
#import "chrome/browser/autofill/autofill_credit_card_model_mac.h"
#import "chrome/browser/autofill/autofill_credit_card_sheet_controller_mac.h"
+#import "chrome/browser/autofill/autofill-inl.h"
#import "chrome/browser/autofill/personal_data_manager.h"
#include "chrome/browser/browser_process.h"
-#import "chrome/browser/cocoa/window_size_autosaver.h"
+#import "chrome/browser/ui/cocoa/window_size_autosaver.h"
#include "chrome/browser/prefs/pref_service.h"
-#include "chrome/browser/profile.h"
+#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/common/notification_details.h"
@@ -32,6 +33,9 @@ namespace {
// dialog.
typedef std::map<Profile*, AutoFillDialogController*> ProfileControllerMap;
+static base::LazyInstance<ProfileControllerMap> g_profile_controller_map(
+ base::LINKER_INITIALIZED);
+
} // namespace
// Delegate protocol that needs to be in place for the AutoFillTableView's
@@ -91,6 +95,14 @@ typedef std::map<Profile*, AutoFillDialogController*> ProfileControllerMap;
// UI.
- (void)preferenceDidChange:(const std::string&)preferenceName;
+// Adjust the selected index when underlying data changes.
+// Selects the previous row if possible, else current row, else deselect all.
+- (void) adjustSelectionOnDelete:(NSInteger)selectedRow;
+
+// Adjust the selected index when underlying data changes.
+// Selects the current row if possible, else previous row, else deselect all.
+- (void) adjustSelectionOnReload:(NSInteger)selectedRow;
+
// Returns true if |row| is an index to a valid profile in |tableView_|, and
// false otherwise.
- (BOOL)isProfileRow:(NSInteger)row;
@@ -268,7 +280,7 @@ class PreferenceObserver : public NotificationObserver {
[self autorelease];
// Remove ourself from the map.
- ProfileControllerMap* map = Singleton<ProfileControllerMap>::get();
+ ProfileControllerMap* map = g_profile_controller_map.Pointer();
ProfileControllerMap::iterator it = map->find(profile_);
if (it != map->end()) {
map->erase(it);
@@ -329,7 +341,7 @@ class PreferenceObserver : public NotificationObserver {
// Create a new address and save it to the |profiles_| list.
AutoFillProfile newAddress;
[addressSheetController copyModelToProfile:&newAddress];
- if (!newAddress.IsEmpty()) {
+ if (!newAddress.IsEmpty() && !FindByContents(profiles_, newAddress)) {
profiles_.push_back(newAddress);
// Saving will save to the PDM and the table will refresh when PDM sends
@@ -356,7 +368,8 @@ class PreferenceObserver : public NotificationObserver {
// Create a new credit card and save it to the |creditCards_| list.
CreditCard newCreditCard;
[creditCardSheetController copyModelToCreditCard:&newCreditCard];
- if (!newCreditCard.IsEmpty()) {
+ if (!newCreditCard.IsEmpty() &&
+ !FindByContents(creditCards_, newCreditCard)) {
creditCards_.push_back(newCreditCard);
// Saving will save to the PDM and the table will refresh when PDM sends
@@ -397,15 +410,7 @@ class PreferenceObserver : public NotificationObserver {
}
// Select the previous row if possible, else current row, else deselect all.
- if ([self tableView:tableView_ shouldSelectRow:selectedRow-1]) {
- [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow-1]
- byExtendingSelection:NO];
- } else if ([self tableView:tableView_ shouldSelectRow:selectedRow]) {
- [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow]
- byExtendingSelection:NO];
- } else {
- [tableView_ deselectAll:self];
- }
+ [self adjustSelectionOnDelete:selectedRow];
// Saving will save to the PDM and the table will refresh when PDM sends
// notification that the underlying model has changed.
@@ -633,7 +638,7 @@ class PreferenceObserver : public NotificationObserver {
profile:(Profile*)profile {
profile = profile->GetOriginalProfile();
- ProfileControllerMap* map = Singleton<ProfileControllerMap>::get();
+ ProfileControllerMap* map = g_profile_controller_map.Pointer();
DCHECK(map != NULL);
ProfileControllerMap::iterator it = map->find(profile);
if (it == map->end()) {
@@ -796,6 +801,7 @@ class PreferenceObserver : public NotificationObserver {
iter != creditCards.end(); ++iter)
creditCards_.push_back(**iter);
+ [self adjustSelectionOnReload:[tableView_ selectedRow]];
[tableView_ reloadData];
}
@@ -812,6 +818,30 @@ class PreferenceObserver : public NotificationObserver {
}
}
+- (void) adjustSelectionOnDelete:(NSInteger)selectedRow {
+ if ([self tableView:tableView_ shouldSelectRow:selectedRow-1]) {
+ [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow-1]
+ byExtendingSelection:NO];
+ } else if ([self tableView:tableView_ shouldSelectRow:selectedRow]) {
+ [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow]
+ byExtendingSelection:NO];
+ } else {
+ [tableView_ deselectAll:self];
+ }
+}
+
+- (void) adjustSelectionOnReload:(NSInteger)selectedRow {
+ if ([self tableView:tableView_ shouldSelectRow:selectedRow]) {
+ [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow]
+ byExtendingSelection:NO];
+ } else if ([self tableView:tableView_ shouldSelectRow:selectedRow-1]) {
+ [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow-1]
+ byExtendingSelection:NO];
+ } else {
+ [tableView_ deselectAll:self];
+ }
+}
+
- (BOOL)isProfileRow:(NSInteger)row {
if (row > 0 && static_cast<size_t>(row) <= profiles_.size())
return YES;