summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/autofill/autofill_dialog.h47
-rw-r--r--chrome/browser/autofill/autofill_dialog_gtk.cc669
-rw-r--r--chrome/browser/autofill/autofill_dialog_mac.mm13
-rw-r--r--chrome/browser/autofill/autofill_editor_gtk.cc875
-rw-r--r--chrome/browser/autofill/autofill_manager.cc1
-rw-r--r--chrome/browser/autofill/autofill_manager.h1
-rw-r--r--chrome/browser/autofill/personal_data_manager.cc15
-rw-r--r--chrome/browser/autofill/personal_data_manager.h6
-rw-r--r--chrome/browser/automation/testing_automation_provider.cc6
-rw-r--r--chrome/browser/ui/views/autofill_profiles_view_win.cc1324
-rw-r--r--chrome/browser/ui/views/autofill_profiles_view_win.h442
-rw-r--r--chrome/chrome_browser.gypi8
12 files changed, 4 insertions, 3403 deletions
diff --git a/chrome/browser/autofill/autofill_dialog.h b/chrome/browser/autofill/autofill_dialog.h
deleted file mode 100644
index 1f56c03..0000000
--- a/chrome/browser/autofill/autofill_dialog.h
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_AUTOFILL_AUTOFILL_DIALOG_H_
-#define CHROME_BROWSER_AUTOFILL_AUTOFILL_DIALOG_H_
-#pragma once
-
-#include <vector>
-
-#include "chrome/browser/autofill/autofill_profile.h"
-#include "chrome/browser/autofill/credit_card.h"
-#include "ui/gfx/native_widget_types.h"
-
-class Profile;
-
-// An interface the AutoFill dialog uses to notify its clients (observers) when
-// the user has applied changes to the AutoFill profile data.
-class AutoFillDialogObserver {
- public:
- // The user has confirmed changes by clicking "Apply" or "OK". Any of the
- // parameters may be NULL. A NULL parameter is treated as not changing the
- // existing data. For example, |OnAutoFillDialogApply(new_profiles, NULL)|
- // only sets the profiles and not the credit cards.
- virtual void OnAutoFillDialogApply(
- std::vector<AutofillProfile>* profiles,
- std::vector<CreditCard>* credit_cards) = 0;
-
- protected:
- virtual ~AutoFillDialogObserver() {}
-};
-
-// Shows the AutoFill dialog, which allows the user to edit profile information.
-// |profile| is profile from which you can get vectors of autofill profiles that
-// contains the current profile information and credit cards. The dialog fills
-// out the profile fields using this data.
-//
-// |observer| will be notified by OnAutoFillDialogAccept when the user has
-// applied changes. May not be NULL.
-//
-// The |parent| parameter (currently only used on Windows) specifies the parent
-// view in the view hierarchy. May be NULL on Mac and gtk.
-void ShowAutoFillDialog(gfx::NativeView parent,
- AutoFillDialogObserver* observer,
- Profile* profile);
-
-#endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_DIALOG_H_
diff --git a/chrome/browser/autofill/autofill_dialog_gtk.cc b/chrome/browser/autofill/autofill_dialog_gtk.cc
deleted file mode 100644
index 7428ea9..0000000
--- a/chrome/browser/autofill/autofill_dialog_gtk.cc
+++ /dev/null
@@ -1,669 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/autofill/autofill_dialog.h"
-
-#include <gtk/gtk.h>
-
-#include <algorithm>
-#include <string>
-#include <vector>
-
-#include "base/logging.h"
-#include "base/message_loop.h"
-#include "base/utf_string_conversions.h"
-#include "chrome/browser/autofill/autofill_manager.h"
-#include "chrome/browser/autofill/autofill_profile.h"
-#include "chrome/browser/autofill/credit_card.h"
-#include "chrome/browser/autofill/form_group.h"
-#include "chrome/browser/autofill/personal_data_manager.h"
-#include "chrome/browser/autofill/phone_number.h"
-#include "chrome/browser/metrics/user_metrics.h"
-#include "chrome/browser/prefs/pref_member.h"
-#include "chrome/browser/prefs/pref_service.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/ui/browser.h"
-#include "chrome/browser/ui/browser_list.h"
-#include "chrome/browser/ui/gtk/gtk_chrome_link_button.h"
-#include "chrome/browser/ui/gtk/gtk_tree.h"
-#include "chrome/browser/ui/gtk/gtk_util.h"
-#include "chrome/common/pref_names.h"
-#include "content/common/notification_details.h"
-#include "content/common/notification_observer.h"
-#include "content/common/notification_type.h"
-#include "grit/chromium_strings.h"
-#include "grit/generated_resources.h"
-#include "grit/locale_settings.h"
-#include "ui/base/gtk/gtk_signal.h"
-#include "ui/base/l10n/l10n_util.h"
-#include "ui/gfx/gtk_util.h"
-
-// Shows the editor for adding/editing an AutofillProfile. If
-// |auto_fill_profile| is NULL, a new AutofillProfile should be created.
-void ShowAutofillProfileEditor(gfx::NativeView parent,
- AutoFillDialogObserver* observer,
- Profile* profile,
- AutofillProfile* auto_fill_profile);
-
-// Shows the editor for adding/editing a CreditCard. If |credit_card| is NULL, a
-// new CreditCard should be created.
-void ShowAutoFillCreditCardEditor(gfx::NativeView parent,
- AutoFillDialogObserver* observer,
- Profile* profile,
- CreditCard* credit_card);
-
-namespace {
-
-// The resource id for the 'About Autofill' link button.
-const gint kAutoFillDialogAboutLink = 1;
-
-////////////////////////////////////////////////////////////////////////////////
-// AutoFillDialog
-//
-// The contents of the AutoFill dialog. This dialog allows users to add, edit
-// and remove AutoFill profiles.
-class AutoFillDialog : public PersonalDataManager::Observer,
- public NotificationObserver {
- public:
- // Identifiers for columns in the store.
- enum Column {
- COL_TITLE = 0,
- COL_IS_HEADER,
- COL_IS_SEPARATOR, // Identifies an empty row used to reserve visual space.
- COL_WEIGHT,
- COL_WEIGHT_SET,
- COL_COUNT
- };
-
- // Used to identify the selection. See GetSelectionType.
- enum SelectionType {
- // Nothing is selected.
- SELECTION_EMPTY = 0,
-
- // At least one header/separator row is selected.
- SELECTION_HEADER = 1 << 0,
-
- // At least one non-header/separator row is selected.
- SELECTION_SINGLE = 1 << 1,
-
- // Multiple non-header/separator rows are selected.
- SELECTION_MULTI = 1 << 2,
- };
-
- AutoFillDialog(Profile* profile, AutoFillDialogObserver* observer);
- ~AutoFillDialog();
-
- // PersonalDataManager::Observer implementation:
- void OnPersonalDataLoaded();
- void OnPersonalDataChanged();
-
- // NotificationObserver implementation:
- virtual void Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details);
-
- // Shows the AutoFill dialog.
- void Show();
-
- private:
- // 'destroy' signal handler. Calls DeleteSoon on the global singleton dialog
- // object.
- CHROMEGTK_CALLBACK_0(AutoFillDialog, void, OnDestroy);
-
- // 'response' signal handler. Notifies the AutoFillDialogObserver that new
- // data is available if the response is GTK_RESPONSE_APPLY or GTK_RESPONSE_OK.
- // We close the dialog if the response is GTK_RESPONSE_OK or
- // GTK_RESPONSE_CANCEL.
- CHROMEGTK_CALLBACK_1(AutoFillDialog, void, OnResponse, int);
-
- CHROMEGTK_CALLBACK_0(AutoFillDialog, void, OnAutoFillCheckToggled);
- CHROMEG_CALLBACK_2(AutoFillDialog, void, OnRowActivated, GtkTreeView*,
- GtkTreePath*, GtkTreeViewColumn*);
- CHROMEG_CALLBACK_0(AutoFillDialog, void, OnSelectionChanged,
- GtkTreeSelection*);
- CHROMEG_CALLBACK_1(AutoFillDialog, gboolean, OnCheckRowIsSeparator,
- GtkTreeModel*, GtkTreeIter*);
- CHROMEGTK_CALLBACK_0(AutoFillDialog, void, OnAddAddress);
- CHROMEGTK_CALLBACK_0(AutoFillDialog, void, OnAddCreditCard);
- CHROMEGTK_CALLBACK_0(AutoFillDialog, void, OnEdit);
- CHROMEGTK_CALLBACK_0(AutoFillDialog, void, OnRemove);
- CHROMEG_CALLBACK_3(AutoFillDialog, gboolean, OnSelectionFilter,
- GtkTreeSelection*, GtkTreeModel*, GtkTreePath*, gboolean);
-
- // Opens the 'Learn more' link in a new foreground tab.
- void OnLinkActivated();
-
- // Loads AutoFill profiles and credit cards using the PersonalDataManager.
- void LoadAutoFillData();
-
- // Creates the dialog UI widgets.
- void InitializeWidgets();
-
- // Updates the state of the various widgets dependant upon the state of the
- // selection, loaded state and whether AutoFill is enabled.
- void UpdateWidgetState();
-
- // Returns a bitmask of the selection types.
- int GetSelectionType();
-
- void AddAddressToTree(const AutofillProfile& profile, GtkTreeIter* iter);
-
- void AddCreditCardToTree(const CreditCard& credit_card, GtkTreeIter* iter);
-
- // Returns the set of selected profiles and cards. The values placed in
- // the specified vectors are owned by PersonalDataManager.
- void GetSelectedEntries(std::vector<AutofillProfile*>* profiles,
- std::vector<CreditCard*>* cards);
-
- Profile* profile_;
-
- // Our observer. May not be NULL.
- AutoFillDialogObserver* observer_;
-
- // The personal data manager, used to load AutoFill profiles and credit cards.
- // Unowned pointer, may not be NULL.
- PersonalDataManager* personal_data_;
-
- // Number of profiles we're displaying.
- int profile_count_;
-
- // The AutoFill dialog.
- GtkWidget* dialog_;
-
- BooleanPrefMember enable_form_autofill_;
-
- GtkWidget* form_autofill_enable_check_;
-
- // Displays the addresses then credit cards.
- GtkListStore* list_store_;
-
- // Displays the list_store_.
- GtkWidget* tree_;
-
- GtkWidget* add_address_button_;
- GtkWidget* add_credit_card_button_;
- GtkWidget* edit_button_;
- GtkWidget* remove_button_;
-
- DISALLOW_COPY_AND_ASSIGN(AutoFillDialog);
-};
-
-// The singleton AutoFill dialog object.
-static AutoFillDialog* dialog = NULL;
-
-AutoFillDialog::AutoFillDialog(Profile* profile,
- AutoFillDialogObserver* observer)
- : profile_(profile),
- observer_(observer),
- personal_data_(profile->GetPersonalDataManager()),
- profile_count_(0) {
- DCHECK(observer_);
- DCHECK(personal_data_);
-
- enable_form_autofill_.Init(prefs::kAutoFillEnabled, profile->GetPrefs(),
- this);
-
- personal_data_->SetObserver(this);
-
- InitializeWidgets();
- LoadAutoFillData();
-
- gtk_util::ShowDialogWithLocalizedSize(dialog_,
- IDS_AUTOFILL_DIALOG_WIDTH_CHARS,
- IDS_AUTOFILL_DIALOG_HEIGHT_LINES,
- true);
-}
-
-AutoFillDialog::~AutoFillDialog() {
- // Removes observer if we are observing Profile load. Does nothing otherwise.
- personal_data_->RemoveObserver(this);
-}
-
-/////////////////////////////////////////////////////////////////////////////
-// PersonalDataManager::Observer implementation:
-void AutoFillDialog::OnPersonalDataLoaded() {
- LoadAutoFillData();
-}
-
-void AutoFillDialog::OnPersonalDataChanged() {
- LoadAutoFillData();
-}
-
-void AutoFillDialog::Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details) {
- DCHECK_EQ(NotificationType::PREF_CHANGED, type.value);
- const std::string* pref_name = Details<std::string>(details).ptr();
- if (!pref_name || *pref_name == prefs::kAutoFillEnabled) {
- gtk_toggle_button_set_active(
- GTK_TOGGLE_BUTTON(form_autofill_enable_check_),
- enable_form_autofill_.GetValue() ? TRUE : FALSE);
- UpdateWidgetState();
- }
-}
-
-void AutoFillDialog::Show() {
- gtk_util::PresentWindow(dialog_, gtk_get_current_event_time());
-}
-
-void AutoFillDialog::OnDestroy(GtkWidget* widget) {
- dialog = NULL;
- MessageLoop::current()->DeleteSoon(FROM_HERE, this);
-}
-
-void AutoFillDialog::OnResponse(GtkWidget* dialog, int response_id) {
- if (response_id == GTK_RESPONSE_OK ||
- response_id == GTK_RESPONSE_CANCEL ||
- response_id == GTK_RESPONSE_DELETE_EVENT) {
- gtk_widget_destroy(dialog);
- }
-
- if (response_id == kAutoFillDialogAboutLink)
- OnLinkActivated();
-}
-
-void AutoFillDialog::OnAutoFillCheckToggled(GtkWidget* widget) {
- bool enabled = gtk_toggle_button_get_active(
- GTK_TOGGLE_BUTTON(form_autofill_enable_check_));
- if (enabled) {
- UserMetrics::RecordAction(UserMetricsAction("Options_FormAutofill_Enable"),
- profile_);
- } else {
- UserMetrics::RecordAction(UserMetricsAction("Options_FormAutofill_Disable"),
- profile_);
- }
- enable_form_autofill_.SetValueIfNotManaged(enabled);
- profile_->GetPrefs()->ScheduleSavePersistentPrefs();
- UpdateWidgetState();
-}
-
-void AutoFillDialog::OnRowActivated(GtkTreeView* tree_view,
- GtkTreePath* path,
- GtkTreeViewColumn* column) {
- if (GetSelectionType() == SELECTION_SINGLE)
- OnEdit(NULL);
-}
-
-void AutoFillDialog::OnSelectionChanged(GtkTreeSelection* selection) {
- UpdateWidgetState();
-}
-
-gboolean AutoFillDialog::OnCheckRowIsSeparator(GtkTreeModel* model,
- GtkTreeIter* iter) {
- gboolean is_separator;
- gtk_tree_model_get(model, iter, COL_IS_SEPARATOR, &is_separator, -1);
- return is_separator;
-}
-
-void AutoFillDialog::OnAddAddress(GtkWidget* widget) {
- ShowAutofillProfileEditor(NULL, observer_, profile_, NULL);
-}
-
-void AutoFillDialog::OnAddCreditCard(GtkWidget* widget) {
- ShowAutoFillCreditCardEditor(NULL, observer_, profile_, NULL);
-}
-
-void AutoFillDialog::OnEdit(GtkWidget* widget) {
- DCHECK_EQ(SELECTION_SINGLE, GetSelectionType());
-
- std::vector<AutofillProfile*> profiles;
- std::vector<CreditCard*> cards;
-
- GetSelectedEntries(&profiles, &cards);
-
- if (profiles.size() == 1)
- ShowAutofillProfileEditor(dialog_, observer_, profile_, profiles[0]);
- else if (cards.size() == 1)
- ShowAutoFillCreditCardEditor(dialog_, observer_, profile_, cards[0]);
-}
-
-void AutoFillDialog::OnRemove(GtkWidget* widget) {
- PersonalDataManager* data_manager = profile_->GetPersonalDataManager();
- std::vector<AutofillProfile*> selected_profiles;
- std::vector<CreditCard*> selected_cards;
-
- GetSelectedEntries(&selected_profiles, &selected_cards);
-
- std::vector<AutofillProfile> profiles;
- for (std::vector<AutofillProfile*>::const_iterator i =
- data_manager->profiles().begin();
- i != data_manager->profiles().end(); ++i) {
- if (std::find(selected_profiles.begin(), selected_profiles.end(), *i) ==
- selected_profiles.end()) {
- profiles.push_back(**i);
- }
- }
-
- std::vector<CreditCard> cards;
- for (std::vector<CreditCard*>::const_iterator i =
- data_manager->credit_cards().begin();
- i != data_manager->credit_cards().end(); ++i) {
- if (std::find(selected_cards.begin(), selected_cards.end(), *i) ==
- selected_cards.end()) {
- cards.push_back(**i);
- }
- }
-
- observer_->OnAutoFillDialogApply(&profiles, &cards);
-}
-
-gboolean AutoFillDialog::OnSelectionFilter(GtkTreeSelection* selection,
- GtkTreeModel* model,
- GtkTreePath* path,
- gboolean path_currently_selected) {
- GtkTreeIter iter;
- if (!gtk_tree_model_get_iter(model, &iter, path)) {
- NOTREACHED();
- return TRUE;
- }
- gboolean is_header;
- gboolean is_separator;
- gtk_tree_model_get(model, &iter, COL_IS_HEADER, &is_header,
- COL_IS_SEPARATOR, &is_separator, -1);
- return !is_header && !is_separator;
-}
-
-void AutoFillDialog::OnLinkActivated() {
- Browser* browser = BrowserList::GetLastActive();
- if (!browser || !browser->GetSelectedTabContents())
- browser = Browser::Create(profile_);
- browser->OpenAutoFillHelpTabAndActivate();
-}
-
-void AutoFillDialog::LoadAutoFillData() {
- if (!personal_data_->IsDataLoaded()) {
- UpdateWidgetState();
- return;
- }
-
- // Rebuild the underlying store.
- gtk_list_store_clear(list_store_);
-
- GtkTreeIter iter;
- // Address title.
- gtk_list_store_append(list_store_, &iter);
- gtk_list_store_set(
- list_store_, &iter,
- COL_WEIGHT, PANGO_WEIGHT_BOLD,
- COL_WEIGHT_SET, TRUE,
- COL_TITLE,
- l10n_util::GetStringUTF8(IDS_AUTOFILL_ADDRESSES_GROUP_NAME).c_str(),
- COL_IS_HEADER, TRUE,
- -1);
- // Address separator.
- gtk_list_store_append(list_store_, &iter);
- gtk_list_store_set(
- list_store_, &iter,
- COL_IS_SEPARATOR, TRUE,
- -1);
-
- // The addresses.
- profile_count_ = 0;
- for (std::vector<AutofillProfile*>::const_iterator i =
- personal_data_->profiles().begin();
- i != personal_data_->profiles().end(); ++i) {
- AddAddressToTree(*(*i), &iter);
- profile_count_++;
- }
-
- // Blank row between addresses and credit cards.
- gtk_list_store_append(list_store_, &iter);
- gtk_list_store_set(
- list_store_, &iter,
- COL_IS_HEADER, TRUE,
- -1);
-
- // Credit card title.
- gtk_list_store_append(list_store_, &iter);
- gtk_list_store_set(
- list_store_, &iter,
- COL_WEIGHT, PANGO_WEIGHT_BOLD,
- COL_WEIGHT_SET, TRUE,
- COL_TITLE,
- l10n_util::GetStringUTF8(IDS_AUTOFILL_CREDITCARDS_GROUP_NAME).c_str(),
- COL_IS_HEADER, TRUE,
- -1);
- // Credit card separator.
- gtk_list_store_append(list_store_, &iter);
- gtk_list_store_set(
- list_store_, &iter,
- COL_IS_SEPARATOR, TRUE,
- -1);
-
- // The credit cards.
- for (std::vector<CreditCard*>::const_iterator i =
- personal_data_->credit_cards().begin();
- i != personal_data_->credit_cards().end(); ++i) {
- AddCreditCardToTree(*(*i), &iter);
- }
-
- UpdateWidgetState();
-}
-
-void AutoFillDialog::InitializeWidgets() {
- dialog_ = gtk_dialog_new_with_buttons(
- l10n_util::GetStringUTF8(IDS_AUTOFILL_OPTIONS_TITLE).c_str(),
- // AutoFill dialog is shared between all browser windows.
- NULL,
- // Non-modal.
- GTK_DIALOG_NO_SEPARATOR,
- GTK_STOCK_OK,
- GTK_RESPONSE_OK,
- NULL);
-
- GtkBox* vbox = GTK_BOX(GTK_DIALOG(dialog_)->vbox);
- gtk_box_set_spacing(vbox, gtk_util::kControlSpacing);
- g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this);
- g_signal_connect(dialog_, "destroy", G_CALLBACK(OnDestroyThunk), this);
-
- form_autofill_enable_check_ = gtk_check_button_new_with_label(
- l10n_util::GetStringUTF8(IDS_OPTIONS_AUTOFILL_ENABLE).c_str());
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(form_autofill_enable_check_),
- enable_form_autofill_.GetValue());
- g_signal_connect(G_OBJECT(form_autofill_enable_check_), "toggled",
- G_CALLBACK(OnAutoFillCheckToggledThunk), this);
- gtk_box_pack_start(vbox, form_autofill_enable_check_, FALSE, FALSE, 0);
-
- // Allow the contents to be scrolled.
- GtkWidget* scrolled_window = gtk_scrolled_window_new(NULL, NULL);
- gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
- GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
- gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled_window),
- GTK_SHADOW_ETCHED_IN);
-
- list_store_ = gtk_list_store_new(COL_COUNT,
- G_TYPE_STRING,
- G_TYPE_BOOLEAN,
- G_TYPE_BOOLEAN,
- G_TYPE_INT,
- G_TYPE_BOOLEAN);
- tree_ = gtk_tree_view_new_with_model(GTK_TREE_MODEL(list_store_));
- g_object_unref(list_store_);
- gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(tree_), FALSE);
- gtk_tree_view_set_row_separator_func(GTK_TREE_VIEW(tree_),
- OnCheckRowIsSeparatorThunk, this, NULL);
- g_signal_connect(tree_, "row-activated", G_CALLBACK(OnRowActivatedThunk),
- this);
- gtk_container_add(GTK_CONTAINER(scrolled_window), tree_);
-
- GtkWidget* h_box1 = gtk_hbox_new(FALSE, gtk_util::kControlSpacing);
- gtk_box_pack_start(vbox, h_box1, TRUE, TRUE, 0);
- gtk_box_pack_start(GTK_BOX(h_box1), scrolled_window, TRUE, TRUE, 0);
-
- GtkWidget* controls_box = gtk_vbox_new(FALSE, gtk_util::kControlSpacing);
- gtk_box_pack_start(GTK_BOX(h_box1), controls_box, FALSE, FALSE, 0);
-
- add_address_button_ = gtk_button_new_with_label(
- l10n_util::GetStringUTF8(IDS_AUTOFILL_ADD_ADDRESS_BUTTON).c_str());
- g_signal_connect(add_address_button_, "clicked",
- G_CALLBACK(OnAddAddressThunk), this);
- gtk_box_pack_start(GTK_BOX(controls_box), add_address_button_, FALSE, FALSE,
- 0);
-
- add_credit_card_button_ = gtk_button_new_with_label(
- l10n_util::GetStringUTF8(IDS_AUTOFILL_ADD_CREDITCARD_BUTTON).c_str());
- g_signal_connect(add_credit_card_button_, "clicked",
- G_CALLBACK(OnAddCreditCardThunk), this);
- gtk_box_pack_start(GTK_BOX(controls_box), add_credit_card_button_, FALSE,
- FALSE, 0);
-
- edit_button_ = gtk_button_new_with_label(
- l10n_util::GetStringUTF8(IDS_AUTOFILL_EDIT_BUTTON).c_str());
- g_signal_connect(edit_button_, "clicked", G_CALLBACK(OnEditThunk), this);
- gtk_box_pack_start(GTK_BOX(controls_box), edit_button_, FALSE, FALSE, 0);
-
- remove_button_ = gtk_button_new_with_label(
- l10n_util::GetStringUTF8(IDS_AUTOFILL_DELETE_BUTTON).c_str());
- g_signal_connect(remove_button_, "clicked", G_CALLBACK(OnRemoveThunk), this);
- gtk_box_pack_start(GTK_BOX(controls_box), remove_button_, FALSE, FALSE, 0);
-
- GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes(
- "",
- gtk_cell_renderer_text_new(),
- "text", COL_TITLE,
- "weight", COL_WEIGHT,
- "weight-set", COL_WEIGHT_SET,
- NULL);
- gtk_tree_view_append_column(GTK_TREE_VIEW(tree_), column);
-
- GtkTreeSelection* selection =
- gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_));
- gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
- gtk_tree_selection_set_select_function(selection, OnSelectionFilterThunk,
- this, NULL);
- g_signal_connect(selection, "changed", G_CALLBACK(OnSelectionChangedThunk),
- this);
-
- GtkWidget* link = gtk_chrome_link_button_new(
- l10n_util::GetStringUTF8(IDS_AUTOFILL_HELP_LABEL).c_str());
- gtk_dialog_add_action_widget(GTK_DIALOG(dialog_), link,
- kAutoFillDialogAboutLink);
-
- // Setting the link widget to secondary positions the button on the left side
- // of the action area (vice versa for RTL layout).
- gtk_button_box_set_child_secondary(
- GTK_BUTTON_BOX(GTK_DIALOG(dialog_)->action_area), link, TRUE);
-}
-
-void AutoFillDialog::UpdateWidgetState() {
- gtk_widget_set_sensitive(form_autofill_enable_check_,
- !enable_form_autofill_.IsManaged());
- if (!personal_data_->IsDataLoaded() || !enable_form_autofill_.GetValue()) {
- gtk_widget_set_sensitive(add_address_button_, FALSE);
- gtk_widget_set_sensitive(add_credit_card_button_, FALSE);
- gtk_widget_set_sensitive(edit_button_, FALSE);
- gtk_widget_set_sensitive(remove_button_, FALSE);
- gtk_widget_set_sensitive(tree_, FALSE);
- } else {
- gtk_widget_set_sensitive(add_address_button_, TRUE);
- gtk_widget_set_sensitive(add_credit_card_button_, TRUE);
- int selection_type = GetSelectionType();
- gtk_widget_set_sensitive(edit_button_, selection_type == SELECTION_SINGLE);
- // Enable the remove button if at least one non-header row is selected.
- gtk_widget_set_sensitive(remove_button_,
- (selection_type & SELECTION_SINGLE) != 0);
- gtk_widget_set_sensitive(tree_, TRUE);
- }
-}
-
-static void RowIteratorFunction(GtkTreeModel* model,
- GtkTreePath* path,
- GtkTreeIter* iter,
- gpointer data) {
- int* type = reinterpret_cast<int*>(data);
- bool is_header = false;
- GValue value = { 0 };
- gtk_tree_model_get_value(model, iter, AutoFillDialog::COL_IS_HEADER, &value);
- is_header = g_value_get_boolean(&value);
- g_value_unset(&value);
-
- if (!is_header) {
- // Is it a separator?
- GValue value = { 0 };
- gtk_tree_model_get_value(model, iter, AutoFillDialog::COL_IS_SEPARATOR,
- &value);
- is_header = g_value_get_boolean(&value);
- g_value_unset(&value);
- }
-
- if (is_header) {
- *type |= AutoFillDialog::SELECTION_HEADER;
- } else {
- if ((*type & AutoFillDialog::SELECTION_SINGLE) == 0)
- *type |= AutoFillDialog::SELECTION_SINGLE;
- else
- *type |= AutoFillDialog::SELECTION_MULTI;
- }
-}
-
-int AutoFillDialog::GetSelectionType() {
- int state = SELECTION_EMPTY;
- gtk_tree_selection_selected_foreach(
- gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_)), RowIteratorFunction,
- &state);
- return state;
-}
-
-void AutoFillDialog::AddAddressToTree(const AutofillProfile& profile,
- GtkTreeIter* iter) {
- gtk_list_store_append(list_store_, iter);
- gtk_list_store_set(
- list_store_, iter,
- COL_WEIGHT, PANGO_WEIGHT_NORMAL,
- COL_WEIGHT_SET, TRUE,
- COL_TITLE, UTF16ToUTF8(profile.Label()).c_str(),
- -1);
-}
-
-void AutoFillDialog::AddCreditCardToTree(const CreditCard& credit_card,
- GtkTreeIter* iter) {
- gtk_list_store_append(list_store_, iter);
- gtk_list_store_set(
- list_store_, iter,
- COL_WEIGHT, PANGO_WEIGHT_NORMAL,
- COL_WEIGHT_SET, TRUE,
- COL_TITLE, UTF16ToUTF8(credit_card.PreviewSummary()).c_str(),
- -1);
-}
-
-void AutoFillDialog::GetSelectedEntries(
- std::vector<AutofillProfile*>* profiles,
- std::vector<CreditCard*>* cards) {
- std::set<int> selection;
- gtk_tree::GetSelectedIndices(
- gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_)), &selection);
-
- for (std::set<int>::const_iterator i = selection.begin();
- i != selection.end(); ++i) {
- // 2 is the number of header rows.
- int index = *i - 2;
- if (index >= 0 &&
- index < static_cast<int>(personal_data_->profiles().size())) {
- profiles->push_back(personal_data_->profiles()[index]);
- continue;
- }
-
- // Empty row, header and separator are next.
- index -= profile_count_ + 3;
- if (index >= 0 && index <
- static_cast<int>(personal_data_->credit_cards().size())) {
- cards->push_back(personal_data_->credit_cards()[index]);
- }
- }
-}
-
-} // namespace
-
-///////////////////////////////////////////////////////////////////////////////
-// Factory/finder method:
-
-void ShowAutoFillDialog(gfx::NativeView parent,
- AutoFillDialogObserver* observer,
- Profile* profile) {
- DCHECK(profile);
-
- if (!dialog)
- dialog = new AutoFillDialog(profile, observer);
- dialog->Show();
-}
diff --git a/chrome/browser/autofill/autofill_dialog_mac.mm b/chrome/browser/autofill/autofill_dialog_mac.mm
deleted file mode 100644
index 8cb27b6..0000000
--- a/chrome/browser/autofill/autofill_dialog_mac.mm
+++ /dev/null
@@ -1,13 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/autofill/autofill_dialog.h"
-
-// Mac implementation of |ShowAutoFillDialog| interface defined in
-// |chrome/browser/autofill/autofill_dialog.h|.
-void ShowAutoFillDialog(gfx::NativeView parent,
- AutoFillDialogObserver* observer,
- Profile* profile) {
- NOTIMPLEMENTED();
-}
diff --git a/chrome/browser/autofill/autofill_editor_gtk.cc b/chrome/browser/autofill/autofill_editor_gtk.cc
deleted file mode 100644
index 42b555d..0000000
--- a/chrome/browser/autofill/autofill_editor_gtk.cc
+++ /dev/null
@@ -1,875 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/autofill/autofill_dialog.h"
-
-#include <gtk/gtk.h>
-
-#include "base/message_loop.h"
-#include "base/string_number_conversions.h"
-#include "base/string_util.h"
-#include "base/task.h"
-#include "base/time.h"
-#include "base/utf_string_conversions.h"
-#include "chrome/browser/autofill/personal_data_manager.h"
-#include "chrome/browser/autofill/phone_number.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/ui/gtk/gtk_util.h"
-#include "grit/app_resources.h"
-#include "grit/generated_resources.h"
-#include "grit/locale_settings.h"
-#include "grit/theme_resources.h"
-#include "ui/base/gtk/gtk_signal.h"
-#include "ui/base/l10n/l10n_util.h"
-#include "ui/base/resource/resource_bundle.h"
-
-namespace {
-
-// Creates a label whose text is set from the resource id |label_id|.
-GtkWidget* CreateLabel(int label_id) {
- GtkWidget* label = gtk_label_new(l10n_util::GetStringUTF8(label_id).c_str());
- gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
- return label;
-}
-
-// Sets the text of |entry| to the value of the field |type| from |profile|.
-void SetEntryText(GtkWidget* entry, FormGroup* profile, _FieldType type) {
- gtk_entry_set_text(
- GTK_ENTRY(entry),
- UTF16ToUTF8(profile->GetFieldText(AutofillType(type))).c_str());
-}
-
-// Returns the current value of |entry|.
-string16 GetEntryText(GtkWidget* entry) {
- return UTF8ToUTF16(gtk_entry_get_text(GTK_ENTRY(entry)));
-}
-
-// Sets |form|'s field of type |type| to the text in |entry|.
-void SetFormValue(GtkWidget* entry, FormGroup* form, _FieldType type) {
- form->SetInfo(AutofillType(type), GetEntryText(entry));
-}
-
-// Sets the number of characters to display in |combobox| to |width|.
-void SetComboBoxCellRendererCharWidth(GtkWidget* combobox, int width) {
- GList* cells = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(combobox));
- DCHECK(g_list_length(cells) > 0);
- GtkCellRendererText* renderer =
- GTK_CELL_RENDERER_TEXT(g_list_first(cells)->data);
- g_object_set(G_OBJECT(renderer), "width-chars", width, NULL);
- g_list_free(cells);
-}
-
-// TableBuilder ----------------------------------------------------------------
-
-// A convenience used in populating a GtkTable. To use it create a TableBuilder
-// and repeatedly invoke AddWidget. TableBuilder keeps track of the current
-// row/col. You can increment the row explicitly by invoking |increment_row|.
-class TableBuilder {
- public:
- TableBuilder(int row_count, int col_count);
- ~TableBuilder();
-
- GtkWidget* table() { return table_; }
-
- void increment_row() {
- row_++;
- col_ = 0;
- }
-
- GtkWidget* AddWidget(GtkWidget* widget, int col_span);
-
- void set_x_padding(int x) { x_padding_ = x; }
- void set_y_padding(int y) { y_padding_ = y; }
-
- void reset_padding() {
- x_padding_ = y_padding_ = gtk_util::kControlSpacing / 2;
- }
-
- private:
- GtkWidget* table_;
-
- // Number of rows/columns.
- const int row_count_;
- const int col_count_;
-
- // Current row/column.
- int row_;
- int col_;
-
- // Padding.
- int x_padding_;
- int y_padding_;
-
- DISALLOW_COPY_AND_ASSIGN(TableBuilder);
-};
-
-TableBuilder::TableBuilder(int row_count, int col_count)
- : table_(gtk_table_new(row_count, col_count, FALSE)),
- row_count_(row_count),
- col_count_(col_count),
- row_(0),
- col_(0),
- x_padding_(gtk_util::kControlSpacing / 2),
- y_padding_(gtk_util::kControlSpacing / 2) {
-}
-
-TableBuilder::~TableBuilder() {
- DCHECK_EQ(row_count_, row_);
-}
-
-GtkWidget* TableBuilder::AddWidget(GtkWidget* widget, int col_span) {
- gtk_table_attach(
- GTK_TABLE(table_),
- widget,
- col_, col_ + col_span,
- row_, row_ + 1,
- // The next line makes the widget expand to take up any extra horizontal
- // space.
- static_cast<GtkAttachOptions>(GTK_FILL | GTK_EXPAND),
- GTK_FILL,
- x_padding_, y_padding_);
- col_ += col_span;
- if (col_ == col_count_) {
- row_++;
- col_ = 0;
- }
- return widget;
-}
-
-// Returns true if the text contained in the entry |widget| is non-empty and
-// parses as a valid phone number.
-bool IsValidPhoneNumber(GtkWidget* widget) {
- string16 text(GetEntryText(widget));
- if (text.empty())
- return true;
-
- string16 number, city_code, country_code;
- return PhoneNumber::ParsePhoneNumber(text, &number, &city_code,&country_code);
-}
-
-// AutofillProfileEditor -------------------------------------------------------
-
-// Class responsible for editing or creating an AutofillProfile.
-class AutofillProfileEditor {
- public:
- AutofillProfileEditor(AutoFillDialogObserver* observer,
- Profile* profile,
- AutofillProfile* auto_fill_profile);
-
- private:
- friend class DeleteTask<AutofillProfileEditor>;
-
- virtual ~AutofillProfileEditor() {}
-
- void Init();
-
- // Registers for the text changed on all our text fields.
- void RegisterForTextChanged();
-
- // Sets the values of the various widgets to |profile|.
- void SetWidgetValues(AutofillProfile* profile);
-
- // Notifies the observer of the new changes. This either updates the current
- // AutofillProfile or creates a new one.
- void ApplyEdits();
-
- // Sets the various form fields in |profile| to match the values in the
- // widgets.
- void SetProfileValuesFromWidgets(AutofillProfile* profile);
-
- // Updates the image displayed by |image| depending upon whether the text in
- // |entry| is a valid phone number.
- void UpdatePhoneImage(GtkWidget* entry, GtkWidget* image);
-
- // Sets the size request for the widget to match the size of the good/bad
- // images. We must do this as the image of the phone widgets is set to null
- // when not empty.
- void SetPhoneSizeRequest(GtkWidget* widget);
-
- // Updates the enabled state of the ok button.
- void UpdateOkButton();
-
- CHROMEGTK_CALLBACK_0(AutofillProfileEditor, void, OnDestroy);
- CHROMEGTK_CALLBACK_1(AutofillProfileEditor, void, OnResponse, int);
- CHROMEG_CALLBACK_0(AutofillProfileEditor, void, OnPhoneChanged, GtkEditable*);
- CHROMEG_CALLBACK_0(AutofillProfileEditor, void, OnFaxChanged, GtkEditable*);
- CHROMEG_CALLBACK_0(AutofillProfileEditor, void, OnFieldChanged, GtkEditable*);
-
- // Are we creating a new profile?
- const bool is_new_;
-
- // If is_new_ is false this is the unique id of the profile the user is
- // editing.
- const std::string profile_guid_;
-
- AutoFillDialogObserver* observer_;
-
- Profile* profile_;
-
- GtkWidget* dialog_;
- GtkWidget* full_name_;
- GtkWidget* company_;
- GtkWidget* address_1_;
- GtkWidget* address_2_;
- GtkWidget* city_;
- GtkWidget* state_;
- GtkWidget* zip_;
- GtkWidget* country_;
- GtkWidget* phone_;
- GtkWidget* phone_image_;
- GtkWidget* fax_;
- GtkWidget* fax_image_;
- GtkWidget* email_;
- GtkWidget* ok_button_;
-
- DISALLOW_COPY_AND_ASSIGN(AutofillProfileEditor);
-};
-
-AutofillProfileEditor::AutofillProfileEditor(
- AutoFillDialogObserver* observer,
- Profile* profile,
- AutofillProfile* auto_fill_profile)
- : is_new_(!auto_fill_profile ? true : false),
- profile_guid_(auto_fill_profile ? auto_fill_profile->guid()
- : std::string()),
- observer_(observer),
- profile_(profile) {
- Init();
-
- if (auto_fill_profile)
- SetWidgetValues(auto_fill_profile);
-
- RegisterForTextChanged();
-
- UpdateOkButton();
-
- gtk_util::ShowDialogWithLocalizedSize(
- dialog_,
- IDS_AUTOFILL_DIALOG_EDIT_ADDRESS_WIDTH_CHARS,
- IDS_AUTOFILL_DIALOG_EDIT_ADDRESS_HEIGHT_LINES,
- true);
- gtk_util::PresentWindow(dialog_, gtk_get_current_event_time());
-}
-
-void AutofillProfileEditor::Init() {
- TableBuilder main_table_builder(15, 2);
-
- main_table_builder.AddWidget(CreateLabel(IDS_AUTOFILL_DIALOG_FULL_NAME), 2);
- full_name_ = main_table_builder.AddWidget(gtk_entry_new(), 1);
- main_table_builder.increment_row();
-
- main_table_builder.AddWidget(CreateLabel(IDS_AUTOFILL_DIALOG_COMPANY_NAME),
- 2);
- company_ = main_table_builder.AddWidget(gtk_entry_new(), 1);
- main_table_builder.increment_row();
-
- main_table_builder.AddWidget(CreateLabel(IDS_AUTOFILL_DIALOG_ADDRESS_LINE_1),
- 2);
- address_1_ = main_table_builder.AddWidget(gtk_entry_new(), 1);
- main_table_builder.increment_row();
-
- main_table_builder.AddWidget(CreateLabel(IDS_AUTOFILL_DIALOG_ADDRESS_LINE_2),
- 2);
- address_2_ = main_table_builder.AddWidget(gtk_entry_new(), 1);
- main_table_builder.increment_row();
-
- TableBuilder city_state_builder(2, 3);
- city_state_builder.AddWidget(CreateLabel(IDS_AUTOFILL_DIALOG_CITY), 1);
- city_state_builder.AddWidget(CreateLabel(IDS_AUTOFILL_DIALOG_STATE), 1);
- city_state_builder.AddWidget(CreateLabel(IDS_AUTOFILL_DIALOG_ZIP_CODE), 1);
-
- city_ = city_state_builder.AddWidget(gtk_entry_new(), 1);
- state_ = city_state_builder.AddWidget(gtk_entry_new(), 1);
- zip_ = city_state_builder.AddWidget(gtk_entry_new(), 1);
-
- main_table_builder.set_x_padding(0);
- main_table_builder.set_y_padding(0);
- main_table_builder.AddWidget(city_state_builder.table(), 2);
- main_table_builder.reset_padding();
-
- main_table_builder.AddWidget(CreateLabel(IDS_AUTOFILL_DIALOG_COUNTRY), 2);
- country_ = main_table_builder.AddWidget(gtk_entry_new(), 1);
- main_table_builder.increment_row();
-
- main_table_builder.AddWidget(CreateLabel(IDS_AUTOFILL_DIALOG_PHONE), 1);
- main_table_builder.AddWidget(CreateLabel(IDS_AUTOFILL_DIALOG_FAX), 1);
-
- GtkWidget* phone_box =
- main_table_builder.AddWidget(gtk_hbox_new(FALSE, 0), 1);
- gtk_box_set_spacing(GTK_BOX(phone_box), gtk_util::kControlSpacing);
- phone_ = gtk_entry_new();
- g_signal_connect(phone_, "changed", G_CALLBACK(OnPhoneChangedThunk), this);
- gtk_box_pack_start(GTK_BOX(phone_box), phone_, TRUE, TRUE, 0);
- phone_image_ = gtk_image_new_from_pixbuf(NULL);
- SetPhoneSizeRequest(phone_image_);
- gtk_box_pack_start(GTK_BOX(phone_box), phone_image_, FALSE, FALSE, 0);
-
- GtkWidget* fax_box =
- main_table_builder.AddWidget(gtk_hbox_new(FALSE, 0), 1);
- gtk_box_set_spacing(GTK_BOX(fax_box), gtk_util::kControlSpacing);
- fax_ = gtk_entry_new();
- g_signal_connect(fax_, "changed", G_CALLBACK(OnFaxChangedThunk), this);
- gtk_box_pack_start(GTK_BOX(fax_box), fax_, TRUE, TRUE, 0);
- fax_image_ = gtk_image_new_from_pixbuf(NULL);
- SetPhoneSizeRequest(fax_image_);
- gtk_box_pack_start(GTK_BOX(fax_box), fax_image_, FALSE, FALSE, 0);
-
- main_table_builder.AddWidget(CreateLabel(IDS_AUTOFILL_DIALOG_EMAIL), 2);
- email_ = main_table_builder.AddWidget(gtk_entry_new(), 1);
- main_table_builder.increment_row();
-
- int caption_id = is_new_ ? IDS_AUTOFILL_ADD_ADDRESS_CAPTION :
- IDS_AUTOFILL_EDIT_ADDRESS_CAPTION;
- dialog_ = gtk_dialog_new_with_buttons(
- l10n_util::GetStringUTF8(caption_id).c_str(),
- NULL,
- static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR),
- NULL);
-
- ok_button_ = gtk_dialog_add_button(GTK_DIALOG(dialog_),
- GTK_STOCK_APPLY,
- GTK_RESPONSE_APPLY);
- gtk_dialog_set_default_response(GTK_DIALOG(dialog_), GTK_RESPONSE_APPLY);
-
- gtk_dialog_add_button(GTK_DIALOG(dialog_), GTK_STOCK_CANCEL,
- GTK_RESPONSE_CANCEL);
-
- g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this);
- g_signal_connect(dialog_, "destroy", G_CALLBACK(OnDestroyThunk), this);
-
- gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog_)->vbox),
- main_table_builder.table(), TRUE, TRUE, 0);
-}
-
-void AutofillProfileEditor::RegisterForTextChanged() {
- g_signal_connect(full_name_, "changed", G_CALLBACK(OnFieldChangedThunk),
- this);
- g_signal_connect(company_, "changed", G_CALLBACK(OnFieldChangedThunk),
- this);
- g_signal_connect(address_1_, "changed", G_CALLBACK(OnFieldChangedThunk),
- this);
- g_signal_connect(address_2_, "changed", G_CALLBACK(OnFieldChangedThunk),
- this);
- g_signal_connect(city_, "changed", G_CALLBACK(OnFieldChangedThunk), this);
- g_signal_connect(state_, "changed", G_CALLBACK(OnFieldChangedThunk), this);
- g_signal_connect(zip_, "changed", G_CALLBACK(OnFieldChangedThunk), this);
- g_signal_connect(country_, "changed", G_CALLBACK(OnFieldChangedThunk), this);
- g_signal_connect(email_, "changed", G_CALLBACK(OnFieldChangedThunk), this);
- g_signal_connect(phone_, "changed", G_CALLBACK(OnFieldChangedThunk), this);
- g_signal_connect(fax_, "changed", G_CALLBACK(OnFieldChangedThunk), this);
-}
-
-void AutofillProfileEditor::SetWidgetValues(AutofillProfile* profile) {
- SetEntryText(full_name_, profile, NAME_FULL);
- SetEntryText(company_, profile, COMPANY_NAME);
- SetEntryText(address_1_, profile, ADDRESS_HOME_LINE1);
- SetEntryText(address_2_, profile, ADDRESS_HOME_LINE2);
- SetEntryText(city_, profile, ADDRESS_HOME_CITY);
- SetEntryText(state_, profile, ADDRESS_HOME_STATE);
- SetEntryText(zip_, profile, ADDRESS_HOME_ZIP);
- SetEntryText(country_, profile, ADDRESS_HOME_COUNTRY);
- SetEntryText(phone_, profile, PHONE_HOME_WHOLE_NUMBER);
- SetEntryText(fax_, profile, PHONE_FAX_WHOLE_NUMBER);
- SetEntryText(email_, profile, EMAIL_ADDRESS);
-
- UpdatePhoneImage(phone_, phone_image_);
- UpdatePhoneImage(fax_, fax_image_);
-}
-
-void AutofillProfileEditor::ApplyEdits() {
- // Build the current set of profiles.
- std::vector<AutofillProfile> profiles;
- PersonalDataManager* data_manager = profile_->GetPersonalDataManager();
- for (std::vector<AutofillProfile*>::const_iterator i =
- data_manager->profiles().begin();
- i != data_manager->profiles().end(); ++i) {
- profiles.push_back(**i);
- }
- AutofillProfile* profile = NULL;
-
- if (!is_new_) {
- // The user is editing an existing profile, find it.
- for (std::vector<AutofillProfile>::iterator i = profiles.begin();
- i != profiles.end(); ++i) {
- if (i->guid() == profile_guid_) {
- profile = &(*i);
- break;
- }
- }
- DCHECK(profile); // We should have found a profile, if not we'll end up
- // creating one below.
- }
-
- if (!profile) {
- profiles.push_back(AutofillProfile());
- profile = &profiles.back();
- }
-
- // Update the values in the profile.
- SetProfileValuesFromWidgets(profile);
-
- // And apply the edits.
- observer_->OnAutoFillDialogApply(&profiles, NULL);
-}
-
-void AutofillProfileEditor::SetProfileValuesFromWidgets(
- AutofillProfile* profile) {
- SetFormValue(full_name_, profile, NAME_FULL);
- SetFormValue(company_, profile, COMPANY_NAME);
- SetFormValue(address_1_, profile, ADDRESS_HOME_LINE1);
- SetFormValue(address_2_, profile, ADDRESS_HOME_LINE2);
- SetFormValue(city_, profile, ADDRESS_HOME_CITY);
- SetFormValue(state_, profile, ADDRESS_HOME_STATE);
- SetFormValue(zip_, profile, ADDRESS_HOME_ZIP);
- SetFormValue(country_, profile, ADDRESS_HOME_COUNTRY);
- SetFormValue(email_, profile, EMAIL_ADDRESS);
-
- string16 number, city_code, country_code;
- PhoneNumber::ParsePhoneNumber(
- GetEntryText(phone_), &number, &city_code, &country_code);
- profile->SetInfo(AutofillType(PHONE_HOME_COUNTRY_CODE), country_code);
- profile->SetInfo(AutofillType(PHONE_HOME_CITY_CODE), city_code);
- profile->SetInfo(AutofillType(PHONE_HOME_NUMBER), number);
-
- PhoneNumber::ParsePhoneNumber(
- GetEntryText(fax_), &number, &city_code, &country_code);
- profile->SetInfo(AutofillType(PHONE_FAX_COUNTRY_CODE), country_code);
- profile->SetInfo(AutofillType(PHONE_FAX_CITY_CODE), city_code);
- profile->SetInfo(AutofillType(PHONE_FAX_NUMBER), number);
-}
-
-void AutofillProfileEditor::UpdatePhoneImage(GtkWidget* entry,
- GtkWidget* image) {
- string16 number, city_code, country_code;
- string16 text(GetEntryText(entry));
- if (text.empty()) {
- gtk_image_set_from_pixbuf(GTK_IMAGE(image), NULL);
- } else if (PhoneNumber::ParsePhoneNumber(text, &number, &city_code,
- &country_code)) {
- gtk_image_set_from_pixbuf(GTK_IMAGE(image),
- ResourceBundle::GetSharedInstance().GetPixbufNamed(
- IDR_INPUT_GOOD));
- } else {
- gtk_image_set_from_pixbuf(GTK_IMAGE(image),
- ResourceBundle::GetSharedInstance().GetPixbufNamed(
- IDR_INPUT_ALERT));
- }
-}
-
-void AutofillProfileEditor::SetPhoneSizeRequest(GtkWidget* widget) {
- GdkPixbuf* buf =
- ResourceBundle::GetSharedInstance().GetPixbufNamed(IDR_INPUT_ALERT);
- gtk_widget_set_size_request(widget,
- gdk_pixbuf_get_width(buf),
- gdk_pixbuf_get_height(buf));
-}
-
-void AutofillProfileEditor::UpdateOkButton() {
- // Enable the ok button if at least one field is non-empty and the phone
- // numbers are valid.
- bool valid =
- !GetEntryText(full_name_).empty() ||
- !GetEntryText(company_).empty() ||
- !GetEntryText(address_1_).empty() ||
- !GetEntryText(address_2_).empty() ||
- !GetEntryText(city_).empty() ||
- !GetEntryText(state_).empty() ||
- !GetEntryText(zip_).empty() ||
- !GetEntryText(country_).empty() ||
- !GetEntryText(email_).empty();
- if (valid) {
- valid = IsValidPhoneNumber(phone_) && IsValidPhoneNumber(fax_);
- } else {
- valid = IsValidPhoneNumber(phone_) && IsValidPhoneNumber(fax_) &&
- (!GetEntryText(full_name_).empty() ||
- !GetEntryText(company_).empty());
- }
- gtk_widget_set_sensitive(ok_button_, valid);
-}
-
-void AutofillProfileEditor::OnDestroy(GtkWidget* widget) {
- MessageLoop::current()->DeleteSoon(FROM_HERE, this);
-}
-
-void AutofillProfileEditor::OnResponse(GtkWidget* dialog, int response_id) {
- if (response_id == GTK_RESPONSE_APPLY || response_id == GTK_RESPONSE_OK)
- ApplyEdits();
-
- if (response_id == GTK_RESPONSE_OK ||
- response_id == GTK_RESPONSE_APPLY ||
- response_id == GTK_RESPONSE_CANCEL ||
- response_id == GTK_RESPONSE_DELETE_EVENT) {
- gtk_widget_destroy(dialog);
- }
-}
-
-void AutofillProfileEditor::OnPhoneChanged(GtkEditable* editable) {
- UpdatePhoneImage(phone_, phone_image_);
-}
-
-void AutofillProfileEditor::OnFaxChanged(GtkEditable* editable) {
- UpdatePhoneImage(fax_, fax_image_);
-}
-
-void AutofillProfileEditor::OnFieldChanged(GtkEditable* editable) {
- UpdateOkButton();
-}
-
-// AutoFillCreditCardEditor ----------------------------------------------------
-
-// Number of years shown in the expiration year combobox.
-const int kNumYears = 10;
-
-// Class responsible for editing/creating a CreditCard.
-class AutoFillCreditCardEditor {
- public:
- AutoFillCreditCardEditor(AutoFillDialogObserver* observer,
- Profile* profile,
- CreditCard* credit_card);
-
- private:
- friend class DeleteTask<AutoFillCreditCardEditor>;
-
- virtual ~AutoFillCreditCardEditor() {}
-
- // Creates the combobox for choosing the month.
- GtkWidget* CreateMonthWidget();
-
- // Creates the combobox for choosing the year.
- GtkWidget* CreateYearWidget();
-
- void Init();
-
- // Registers for the text changed on all our text fields.
- void RegisterForTextChanged();
-
- // Sets the values displayed in the various widgets from |profile|.
- void SetWidgetValues(CreditCard* profile);
-
- // Updates the observer with the CreditCard being edited.
- void ApplyEdits();
-
- // Updates |card| with the values from the widgets.
- void SetCreditCardValuesFromWidgets(CreditCard* card);
-
- // Updates the enabled state of the ok button.
- void UpdateOkButton();
-
- CHROMEGTK_CALLBACK_0(AutoFillCreditCardEditor, void, OnDestroy);
- CHROMEGTK_CALLBACK_1(AutoFillCreditCardEditor, void, OnResponse, int);
- CHROMEG_CALLBACK_0(AutoFillCreditCardEditor, void, OnFieldChanged,
- GtkEditable*);
- CHROMEG_CALLBACK_2(AutoFillCreditCardEditor, void, OnDeleteTextFromNumber,
- GtkEditable*, gint, gint);
- CHROMEG_CALLBACK_3(AutoFillCreditCardEditor, void, OnInsertTextIntoNumber,
- GtkEditable*, gchar*, gint, gint*);
-
- // Are we creating a new credit card?
- const bool is_new_;
-
- // If is_new_ is false this is the unique id of the credit card the user is
- // editing.
- const std::string credit_card_guid_;
-
- AutoFillDialogObserver* observer_;
-
- Profile* profile_;
-
- // Initial year shown in expiration date year combobox.
- int base_year_;
-
- // Has the number_ field been edited by the user yet?
- bool edited_number_;
-
- GtkWidget* dialog_;
- GtkWidget* name_;
- GtkWidget* number_;
- GtkWidget* month_;
- GtkWidget* year_;
- GtkWidget* ok_button_;
-
- DISALLOW_COPY_AND_ASSIGN(AutoFillCreditCardEditor);
-};
-
-AutoFillCreditCardEditor::AutoFillCreditCardEditor(
- AutoFillDialogObserver* observer,
- Profile* profile,
- CreditCard* credit_card)
- : is_new_(!credit_card ? true : false),
- credit_card_guid_(credit_card ? credit_card->guid() : std::string()),
- observer_(observer),
- profile_(profile),
- base_year_(0),
- edited_number_(false) {
- base::Time::Exploded exploded_time;
- base::Time::Now().LocalExplode(&exploded_time);
- base_year_ = exploded_time.year;
-
- Init();
-
- if (credit_card) {
- SetWidgetValues(credit_card);
- } else {
- // We're creating a new credit card. Select January of next year by default.
- gtk_combo_box_set_active(GTK_COMBO_BOX(month_), 0);
- gtk_combo_box_set_active(GTK_COMBO_BOX(year_), 1);
- }
-
- RegisterForTextChanged();
-
- UpdateOkButton();
-
- gtk_util::ShowDialogWithLocalizedSize(
- dialog_,
- IDS_AUTOFILL_DIALOG_EDIT_CCARD_WIDTH_CHARS,
- IDS_AUTOFILL_DIALOG_EDIT_CCARD_HEIGHT_LINES,
- true);
- gtk_util::PresentWindow(dialog_, gtk_get_current_event_time());
-}
-
-GtkWidget* AutoFillCreditCardEditor::CreateMonthWidget() {
- GtkWidget* combobox = gtk_combo_box_new_text();
- for (int i = 1; i <= 12; ++i) {
- gtk_combo_box_append_text(GTK_COMBO_BOX(combobox),
- StringPrintf("%02i", i).c_str());
- }
-
- SetComboBoxCellRendererCharWidth(combobox, 2);
- return combobox;
-}
-
-GtkWidget* AutoFillCreditCardEditor::CreateYearWidget() {
- GtkWidget* combobox = gtk_combo_box_new_text();
- for (int i = 0; i < kNumYears; ++i) {
- gtk_combo_box_append_text(GTK_COMBO_BOX(combobox),
- StringPrintf("%04i", i + base_year_).c_str());
- }
-
- SetComboBoxCellRendererCharWidth(combobox, 4);
- return combobox;
-}
-
-void AutoFillCreditCardEditor::Init() {
- TableBuilder main_table_builder(6, 2);
-
- main_table_builder.AddWidget(
- CreateLabel(IDS_AUTOFILL_DIALOG_NAME_ON_CARD), 2);
- name_ = main_table_builder.AddWidget(gtk_entry_new(), 2);
-
- main_table_builder.AddWidget(
- CreateLabel(IDS_AUTOFILL_DIALOG_CREDIT_CARD_NUMBER), 2);
- number_ = main_table_builder.AddWidget(gtk_entry_new(), 1);
- gtk_entry_set_width_chars(GTK_ENTRY(number_), 20);
- // Add an empty widget purely for spacing to match the mocks.
- main_table_builder.AddWidget(gtk_hbox_new(FALSE, 0), 1);
-
- main_table_builder.AddWidget(CreateLabel(IDS_AUTOFILL_DIALOG_EXPIRATION_DATE),
- 2);
- GtkWidget* box = main_table_builder.AddWidget(
- gtk_hbox_new(FALSE, gtk_util::kControlSpacing), 1);
- month_ = CreateMonthWidget();
- gtk_box_pack_start(GTK_BOX(box), month_, FALSE, FALSE, 0);
- year_ = CreateYearWidget();
- gtk_box_pack_start(GTK_BOX(box), year_, FALSE, FALSE, 0);
- main_table_builder.increment_row();
-
- int caption_id = is_new_ ? IDS_AUTOFILL_ADD_CREDITCARD_CAPTION :
- IDS_AUTOFILL_EDIT_CREDITCARD_CAPTION;
- dialog_ = gtk_dialog_new_with_buttons(
- l10n_util::GetStringUTF8(caption_id).c_str(),
- NULL,
- static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR),
- NULL);
-
- ok_button_ = gtk_dialog_add_button(GTK_DIALOG(dialog_),
- GTK_STOCK_APPLY,
- GTK_RESPONSE_APPLY);
- gtk_dialog_set_default_response(GTK_DIALOG(dialog_), GTK_RESPONSE_APPLY);
-
- gtk_dialog_add_button(GTK_DIALOG(dialog_), GTK_STOCK_CANCEL,
- GTK_RESPONSE_CANCEL);
-
- g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this);
- g_signal_connect(dialog_, "destroy", G_CALLBACK(OnDestroyThunk), this);
-
- gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog_)->vbox),
- main_table_builder.table(), TRUE, TRUE, 0);
-}
-
-void AutoFillCreditCardEditor::RegisterForTextChanged() {
- g_signal_connect(name_, "changed", G_CALLBACK(OnFieldChangedThunk), this);
- g_signal_connect(number_, "changed", G_CALLBACK(OnFieldChangedThunk), this);
- g_signal_connect(number_, "delete-text",
- G_CALLBACK(OnDeleteTextFromNumberThunk), this);
- g_signal_connect(number_, "insert-text",
- G_CALLBACK(OnInsertTextIntoNumberThunk), this);
-}
-
-void AutoFillCreditCardEditor::SetWidgetValues(CreditCard* card) {
- SetEntryText(name_, card, CREDIT_CARD_NAME);
-
- gtk_entry_set_text(GTK_ENTRY(number_),
- UTF16ToUTF8(card->ObfuscatedNumber()).c_str());
-
- int month;
- base::StringToInt(card->GetFieldText(AutofillType(CREDIT_CARD_EXP_MONTH)),
- &month);
- if (month >= 1 && month <= 12) {
- gtk_combo_box_set_active(GTK_COMBO_BOX(month_), month - 1);
- } else {
- gtk_combo_box_set_active(GTK_COMBO_BOX(month_), 0);
- }
-
- int year;
- if (!base::StringToInt(
- card->GetFieldText(AutofillType(CREDIT_CARD_EXP_4_DIGIT_YEAR)),
- &year)) {
- NOTREACHED();
- }
- if (year >= base_year_ && year < base_year_ + kNumYears)
- gtk_combo_box_set_active(GTK_COMBO_BOX(year_), year - base_year_);
- else
- gtk_combo_box_set_active(GTK_COMBO_BOX(year_), 0);
-}
-
-void AutoFillCreditCardEditor::ApplyEdits() {
- // Build a vector of the current set of credit cards.
- PersonalDataManager* data_manager = profile_->GetPersonalDataManager();
- std::vector<CreditCard> cards;
- for (std::vector<CreditCard*>::const_iterator i =
- data_manager->credit_cards().begin();
- i != data_manager->credit_cards().end(); ++i) {
- cards.push_back(**i);
- }
-
- CreditCard* card = NULL;
-
- if (!is_new_) {
- // The user is editing an existing credit card, find it.
- for (std::vector<CreditCard>::iterator i = cards.begin();
- i != cards.end(); ++i) {
- if (i->guid() == credit_card_guid_) {
- card = &(*i);
- break;
- }
- }
- DCHECK(card); // We should have found the credit card we were created with,
- // if not we'll end up creating one below.
- }
-
- if (!card) {
- cards.push_back(CreditCard());
- card = &cards.back();
- }
-
- // Update the credit card from what the user typed in.
- SetCreditCardValuesFromWidgets(card);
-
- // And update the model.
- observer_->OnAutoFillDialogApply(NULL, &cards);
-}
-
-void AutoFillCreditCardEditor::SetCreditCardValuesFromWidgets(
- CreditCard* card) {
- SetFormValue(name_, card, CREDIT_CARD_NAME);
-
- if (edited_number_)
- SetFormValue(number_, card, CREDIT_CARD_NUMBER);
-
- int selected_month_index =
- gtk_combo_box_get_active(GTK_COMBO_BOX(month_));
- if (selected_month_index == -1)
- selected_month_index = 0;
- card->SetInfo(AutofillType(CREDIT_CARD_EXP_MONTH),
- base::IntToString16(selected_month_index + 1));
-
- int selected_year_index =
- gtk_combo_box_get_active(GTK_COMBO_BOX(year_));
- if (selected_year_index == -1)
- selected_year_index = 0;
- card->SetInfo(AutofillType(CREDIT_CARD_EXP_4_DIGIT_YEAR),
- base::IntToString16(selected_year_index + base_year_));
-}
-
-void AutoFillCreditCardEditor::UpdateOkButton() {
- // Enable the ok button if at least one field is non-empty and the phone
- // numbers are valid.
- bool valid = !GetEntryText(name_).empty() || !GetEntryText(number_).empty();
- gtk_widget_set_sensitive(ok_button_, valid);
-}
-
-void AutoFillCreditCardEditor::OnDestroy(GtkWidget* widget) {
- MessageLoop::current()->DeleteSoon(FROM_HERE, this);
-}
-
-void AutoFillCreditCardEditor::OnResponse(GtkWidget* dialog, int response_id) {
- if (response_id == GTK_RESPONSE_APPLY || response_id == GTK_RESPONSE_OK)
- ApplyEdits();
-
- if (response_id == GTK_RESPONSE_OK ||
- response_id == GTK_RESPONSE_APPLY ||
- response_id == GTK_RESPONSE_CANCEL ||
- response_id == GTK_RESPONSE_DELETE_EVENT) {
- gtk_widget_destroy(dialog);
- }
-}
-
-void AutoFillCreditCardEditor::OnFieldChanged(GtkEditable* editable) {
- if (editable == GTK_EDITABLE(number_))
- edited_number_ = true;
- UpdateOkButton();
-}
-
-void AutoFillCreditCardEditor::OnDeleteTextFromNumber(GtkEditable* editable,
- gint start,
- gint end) {
- if (!edited_number_) {
- // The user hasn't deleted any text yet, so delete it all.
- edited_number_ = true;
- g_signal_stop_emission_by_name(editable, "delete-text");
- gtk_entry_set_text(GTK_ENTRY(number_), "");
- }
-}
-
-void AutoFillCreditCardEditor::OnInsertTextIntoNumber(GtkEditable* editable,
- gchar* new_text,
- gint new_text_length,
- gint* position) {
- if (!edited_number_) {
- // This is the first edit to the number. If |editable| is not empty, reset
- // the text so that any obfuscated text is removed.
- edited_number_ = true;
-
- if (GetEntryText(GTK_WIDGET(editable)).empty())
- return;
-
- g_signal_stop_emission_by_name(editable, "insert-text");
-
- if (new_text_length < 0)
- new_text_length = strlen(new_text);
- gtk_entry_set_text(GTK_ENTRY(number_),
- std::string(new_text, new_text_length).c_str());
-
- // Sets the cursor after the last character in |editable|.
- gtk_editable_set_position(editable, -1);
- }
-}
-
-} // namespace
-
-void ShowAutofillProfileEditor(gfx::NativeView parent,
- AutoFillDialogObserver* observer,
- Profile* profile,
- AutofillProfile* auto_fill_profile) {
- // AutofillProfileEditor takes care of deleting itself.
- new AutofillProfileEditor(observer, profile, auto_fill_profile);
-}
-
-void ShowAutoFillCreditCardEditor(gfx::NativeView parent,
- AutoFillDialogObserver* observer,
- Profile* profile,
- CreditCard* credit_card) {
- // AutoFillCreditCardEditor takes care of deleting itself.
- new AutoFillCreditCardEditor(observer, profile, credit_card);
-}
diff --git a/chrome/browser/autofill/autofill_manager.cc b/chrome/browser/autofill/autofill_manager.cc
index 1c0fd81..6f49282 100644
--- a/chrome/browser/autofill/autofill_manager.cc
+++ b/chrome/browser/autofill/autofill_manager.cc
@@ -14,7 +14,6 @@
#include "base/utf_string_conversions.h"
#include "chrome/browser/autocomplete_history_manager.h"
#include "chrome/browser/autofill/autofill_cc_infobar_delegate.h"
-#include "chrome/browser/autofill/autofill_dialog.h"
#include "chrome/browser/autofill/autofill_metrics.h"
#include "chrome/browser/autofill/form_structure.h"
#include "chrome/browser/autofill/phone_number.h"
diff --git a/chrome/browser/autofill/autofill_manager.h b/chrome/browser/autofill/autofill_manager.h
index cf69c3d..42f158f 100644
--- a/chrome/browser/autofill/autofill_manager.h
+++ b/chrome/browser/autofill/autofill_manager.h
@@ -13,7 +13,6 @@
#include "base/gtest_prod_util.h"
#include "base/scoped_ptr.h"
#include "base/scoped_vector.h"
-#include "chrome/browser/autofill/autofill_dialog.h"
#include "chrome/browser/autofill/autofill_download.h"
#include "chrome/browser/autofill/personal_data_manager.h"
#include "content/browser/tab_contents/tab_contents_observer.h"
diff --git a/chrome/browser/autofill/personal_data_manager.cc b/chrome/browser/autofill/personal_data_manager.cc
index 287ce948..c21d31d 100644
--- a/chrome/browser/autofill/personal_data_manager.cc
+++ b/chrome/browser/autofill/personal_data_manager.cc
@@ -139,21 +139,6 @@ void PersonalDataManager::OnWebDataServiceRequestDone(
/////////////////////////////////////////////////////////////////////////////
// PersonalDataManager,
// views::ButtonListener implementations
-void PersonalDataManager::OnAutoFillDialogApply(
- std::vector<AutofillProfile>* profiles,
- std::vector<CreditCard>* credit_cards) {
- // |profiles| may be NULL.
- // |credit_cards| may be NULL.
- if (profiles) {
- CancelPendingQuery(&pending_profiles_query_);
- SetProfiles(profiles);
- }
- if (credit_cards) {
- CancelPendingQuery(&pending_creditcards_query_);
- SetCreditCards(credit_cards);
- }
-}
-
void PersonalDataManager::SetObserver(PersonalDataManager::Observer* observer) {
// TODO: RemoveObserver is for compatibility with old code, it should be
// nuked.
diff --git a/chrome/browser/autofill/personal_data_manager.h b/chrome/browser/autofill/personal_data_manager.h
index 6778093..bd64ec8 100644
--- a/chrome/browser/autofill/personal_data_manager.h
+++ b/chrome/browser/autofill/personal_data_manager.h
@@ -14,7 +14,6 @@
#include "base/scoped_ptr.h"
#include "base/scoped_vector.h"
#include "base/string16.h"
-#include "chrome/browser/autofill/autofill_dialog.h"
#include "chrome/browser/autofill/autofill_profile.h"
#include "chrome/browser/autofill/credit_card.h"
#include "chrome/browser/autofill/field_types.h"
@@ -30,7 +29,6 @@ class Profile;
// AutoFill.
class PersonalDataManager
: public WebDataServiceConsumer,
- public AutoFillDialogObserver,
public base::RefCountedThreadSafe<PersonalDataManager> {
public:
// An interface the PersonalDataManager uses to notify its clients (observers)
@@ -54,10 +52,6 @@ class PersonalDataManager
virtual void OnWebDataServiceRequestDone(WebDataService::Handle h,
const WDTypedResult* result);
- // AutoFillDialogObserver implementation:
- virtual void OnAutoFillDialogApply(std::vector<AutofillProfile>* profiles,
- std::vector<CreditCard>* credit_cards);
-
// Sets the listener to be notified of PersonalDataManager events.
virtual void SetObserver(PersonalDataManager::Observer* observer);
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc
index 476f0ee..83f82de 100644
--- a/chrome/browser/automation/testing_automation_provider.cc
+++ b/chrome/browser/automation/testing_automation_provider.cc
@@ -3955,8 +3955,10 @@ void TestingAutomationProvider::FillAutofillProfile(
PersonalDataManager* pdm = tab_contents->profile()
->GetPersonalDataManager();
if (pdm) {
- pdm->OnAutoFillDialogApply(profiles? &autofill_profiles : NULL,
- cards? &credit_cards : NULL);
+ if (profiles)
+ pdm->SetProfiles(&autofill_profiles);
+ if (cards)
+ pdm->SetCreditCards(&credit_cards);
} else {
reply.SendError("No PersonalDataManager.");
return;
diff --git a/chrome/browser/ui/views/autofill_profiles_view_win.cc b/chrome/browser/ui/views/autofill_profiles_view_win.cc
deleted file mode 100644
index d3a9bfe..0000000
--- a/chrome/browser/ui/views/autofill_profiles_view_win.cc
+++ /dev/null
@@ -1,1324 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/ui/views/autofill_profiles_view_win.h"
-
-#include <vsstyle.h>
-#include <vssym32.h>
-
-#include "base/message_loop.h"
-#include "base/string16.h"
-#include "base/string_number_conversions.h"
-#include "base/time.h"
-#include "base/utf_string_conversions.h"
-#include "chrome/browser/autofill/autofill_manager.h"
-#include "chrome/browser/autofill/phone_number.h"
-#include "chrome/browser/metrics/user_metrics.h"
-#include "chrome/browser/prefs/pref_service.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/ui/browser.h"
-#include "chrome/browser/ui/browser_list.h"
-#include "chrome/browser/ui/browser_window.h"
-#include "chrome/browser/ui/views/list_background.h"
-#include "chrome/browser/ui/window_sizer.h"
-#include "chrome/common/pref_names.h"
-#include "content/common/notification_details.h"
-#include "grit/app_resources.h"
-#include "grit/generated_resources.h"
-#include "grit/locale_settings.h"
-#include "grit/theme_resources.h"
-#include "ui/base/l10n/l10n_util.h"
-#include "ui/base/resource/resource_bundle.h"
-#include "ui/gfx/canvas.h"
-#include "ui/gfx/native_theme_win.h"
-#include "ui/gfx/size.h"
-#include "views/border.h"
-#include "views/controls/button/image_button.h"
-#include "views/controls/button/native_button.h"
-#include "views/controls/button/radio_button.h"
-#include "views/controls/button/text_button.h"
-#include "views/controls/label.h"
-#include "views/controls/scroll_view.h"
-#include "views/controls/separator.h"
-#include "views/controls/table/table_view.h"
-#include "views/controls/textfield/textfield.h"
-#include "views/layout/grid_layout.h"
-#include "views/layout/layout_constants.h"
-#include "views/window/window.h"
-
-namespace {
-
-// padding on the sides of AutoFill settings dialog.
-const int kDialogPadding = 7;
-
-// Insets for subview controls.
-const int kSubViewHorizotalInsets = 18;
-const int kSubViewVerticalInsets = 5;
-
-}; // namespace
-
-/////////////////////////////////////////////////////////////////////////////
-// AutofillProfilesView, static data:
-AutofillProfilesView* AutofillProfilesView::instance_ = NULL;
-
-/////////////////////////////////////////////////////////////////////////////
-// AutofillProfilesView, public:
-AutofillProfilesView::AutofillProfilesView(
- AutoFillDialogObserver* observer,
- PersonalDataManager* personal_data_manager,
- Profile* profile,
- PrefService* preferences,
- AutofillProfile* imported_profile,
- CreditCard* imported_credit_card)
- : observer_(observer),
- personal_data_manager_(personal_data_manager),
- profile_(profile),
- preferences_(preferences),
- enable_auto_fill_button_(NULL),
- add_address_button_(NULL),
- add_credit_card_button_(NULL),
- edit_button_(NULL),
- remove_button_(NULL),
- scroll_view_(NULL),
- focus_manager_(NULL),
- child_dialog_opened_(false) {
- DCHECK(preferences_);
- enable_auto_fill_.Init(prefs::kAutoFillEnabled, preferences_, this);
- if (imported_profile) {
- profiles_set_.push_back(EditableSetInfo(imported_profile));
- }
- if (imported_credit_card) {
- credit_card_set_.push_back(
- EditableSetInfo(imported_credit_card));
- }
- personal_data_manager_->SetObserver(this);
-}
-
-AutofillProfilesView::~AutofillProfilesView() {
- // Clear model as it gets deleted before the view.
- if (scroll_view_)
- scroll_view_->SetModel(NULL);
-
- if (personal_data_manager_)
- personal_data_manager_->RemoveObserver(this);
-}
-
-// TODO: get rid of imported_profile and imported_credit_card.
-int AutofillProfilesView::Show(gfx::NativeWindow parent,
- AutoFillDialogObserver* observer,
- PersonalDataManager* personal_data_manager,
- Profile* profile,
- PrefService* preferences,
- AutofillProfile* imported_profile,
- CreditCard* imported_credit_card) {
- if (!instance_) {
- instance_ = new AutofillProfilesView(observer, personal_data_manager,
- profile, preferences, imported_profile, imported_credit_card);
-
- // |instance_| will get deleted once Close() is called.
- views::Window::CreateChromeWindow(parent, gfx::Rect(), instance_);
- }
- if (!instance_->window()->IsVisible())
- instance_->window()->Show();
- else
- instance_->window()->Activate();
- return 0;
-}
-
-/////////////////////////////////////////////////////////////////////////////
-// AutofillProfilesView, protected:
-void AutofillProfilesView::AddClicked(int group_type) {
- scoped_ptr<EditableSetInfo> info;
- std::vector<EditableSetInfo>::iterator it = profiles_set_.end();
- int added_item_index = -1;
- if (group_type == ContentListTableModel::kAddressGroup) {
- AutofillProfile address;
- info.reset(new EditableSetInfo(&address));
- } else if (group_type == ContentListTableModel::kCreditCardGroup) {
- CreditCard credit_card;
- info.reset(new EditableSetInfo(&credit_card));
- } else {
- NOTREACHED();
- }
- EditableSetViewContents *edit_view = new
- EditableSetViewContents(this, true, *info);
- views::Window::CreateChromeWindow(window()->GetNativeWindow(), gfx::Rect(),
- edit_view);
- edit_view->window()->Show();
-}
-
-void AutofillProfilesView::EditClicked() {
- int index = scroll_view_->FirstSelectedRow();
- if (index == -1)
- return; // Happens if user double clicks and the table is empty.
- DCHECK(index >= 0);
- DCHECK(index < static_cast<int>(profiles_set_.size() +
- credit_card_set_.size()));
- std::vector<EditableSetInfo>::iterator it;
- if (index < static_cast<int>(profiles_set_.size()))
- it = profiles_set_.begin() + index;
- else
- it = credit_card_set_.begin() + (index - profiles_set_.size());
-
- EditableSetViewContents *edit_view = new
- EditableSetViewContents(this, false, *it);
- views::Window::CreateChromeWindow(window()->GetNativeWindow(), gfx::Rect(),
- edit_view);
- edit_view->window()->Show();
-}
-
-void AutofillProfilesView::DeleteClicked() {
- DCHECK_GT(scroll_view_->SelectedRowCount(), 0);
- int last_view_row = -1;
- for (views::TableView::iterator i = scroll_view_->SelectionBegin();
- i != scroll_view_->SelectionEnd(); ++i) {
- last_view_row = scroll_view_->ModelToView(*i);
- table_model_->RemoveItem(*i);
- }
- if (last_view_row >= table_model_->RowCount())
- last_view_row = table_model_->RowCount() - 1;
- if (last_view_row >= 0)
- scroll_view_->Select(scroll_view_->ViewToModel(last_view_row));
- UpdateWidgetState();
- SaveData();
-}
-
-void AutofillProfilesView::EditAccepted(EditableSetInfo* data,
- bool new_item) {
- DCHECK(data);
- std::vector<EditableSetInfo>::iterator it;
- it = data->is_address ? profiles_set_.begin() : credit_card_set_.begin();
- std::vector<EditableSetInfo>::iterator end_it;
- end_it = data->is_address ? profiles_set_.end() : credit_card_set_.end();
- for (; it != end_it; ++it) {
- if (it->guid() == data->guid()) {
- *it = *data;
- break;
- }
- if (new_item) {
- if (data->is_address) {
- if (it->address.Compare(data->address) == 0)
- break;
- } else {
- if (it->credit_card.Compare(data->credit_card) == 0)
- break;
- }
- }
- }
- if (it == end_it) {
- if (data->is_address)
- profiles_set_.push_back(*data);
- else
- credit_card_set_.push_back(*data);
- }
- UpdateWidgetState();
- SaveData();
-}
-
-void AutofillProfilesView::UpdateWidgetState() {
- bool autofill_enabled = enable_auto_fill_.GetValue();
- enable_auto_fill_button_->SetChecked(autofill_enabled);
- enable_auto_fill_button_->SetEnabled(!enable_auto_fill_.IsManaged());
- scroll_view_->SetEnabled(autofill_enabled);
- add_address_button_->SetEnabled(personal_data_manager_->IsDataLoaded() &&
- !child_dialog_opened_ && autofill_enabled);
- add_credit_card_button_->SetEnabled(personal_data_manager_->IsDataLoaded() &&
- !child_dialog_opened_ &&
- autofill_enabled);
-
- int selected_row_count = scroll_view_->SelectedRowCount();
- edit_button_->SetEnabled(selected_row_count == 1 && !child_dialog_opened_ &&
- autofill_enabled);
- remove_button_->SetEnabled(selected_row_count > 0 && !child_dialog_opened_ &&
- autofill_enabled);
-}
-
-void AutofillProfilesView::ChildWindowOpened() {
- child_dialog_opened_ = true;
- UpdateWidgetState();
-}
-
-void AutofillProfilesView::ChildWindowClosed() {
- child_dialog_opened_ = false;
- UpdateWidgetState();
-}
-
-SkBitmap* AutofillProfilesView::GetWarningBitmap(bool good) {
- ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- return rb.GetBitmapNamed(good ? IDR_INPUT_GOOD : IDR_INPUT_ALERT);
-}
-
-
-/////////////////////////////////////////////////////////////////////////////
-// AutofillProfilesView, views::View implementations
-void AutofillProfilesView::Layout() {
- View::Layout();
-}
-
-gfx::Size AutofillProfilesView::GetPreferredSize() {
- return views::Window::GetLocalizedContentsSize(
- IDS_AUTOFILL_DIALOG_WIDTH_CHARS,
- IDS_AUTOFILL_DIALOG_HEIGHT_LINES);
-}
-
-void AutofillProfilesView::ViewHierarchyChanged(bool is_add,
- views::View* parent,
- views::View* child) {
- if (is_add && child == this)
- Init();
-}
-
-/////////////////////////////////////////////////////////////////////////////
-// AutofillProfilesView, views::DialogDelegate implementations:
-int AutofillProfilesView::GetDialogButtons() const {
- return MessageBoxFlags::DIALOGBUTTON_CANCEL;
-}
-
-std::wstring AutofillProfilesView::GetDialogButtonLabel(
- MessageBoxFlags::DialogButton button) const {
- switch (button) {
- case MessageBoxFlags::DIALOGBUTTON_CANCEL:
- return std::wstring();
- default:
- break;
- }
- NOTREACHED();
- return std::wstring();
-}
-
-views::View* AutofillProfilesView::GetExtraView() {
- // The dialog sizes the extra view to fill the entire available space.
- // We use a container to lay it out properly.
- views::View* link_container = new views::View();
- views::GridLayout* layout = new views::GridLayout(link_container);
- link_container->SetLayoutManager(layout);
-
- views::ColumnSet* column_set = layout->AddColumnSet(0);
- column_set->AddPaddingColumn(0, kDialogPadding);
- column_set->AddColumn(views::GridLayout::LEADING,
- views::GridLayout::LEADING, 0,
- views::GridLayout::USE_PREF, 0, 0);
- layout->StartRow(0, 0);
- views::Link* link = new views::Link(
- UTF16ToWide(l10n_util::GetStringUTF16(IDS_AUTOFILL_LEARN_MORE)));
- link->SetController(this);
- layout->AddView(link);
-
- return link_container;
-}
-
-bool AutofillProfilesView::IsDialogButtonEnabled(
- MessageBoxFlags::DialogButton button) const {
- switch (button) {
- case MessageBoxFlags::DIALOGBUTTON_OK:
- case MessageBoxFlags::DIALOGBUTTON_CANCEL:
- return true;
- default:
- break;
- }
- NOTREACHED();
- return false;
-}
-
-
-std::wstring AutofillProfilesView::GetWindowTitle() const {
- return UTF16ToWide(l10n_util::GetStringUTF16(IDS_AUTOFILL_OPTIONS_TITLE));
-}
-
-void AutofillProfilesView::WindowClosing() {
- focus_manager_->RemoveFocusChangeListener(this);
- instance_ = NULL;
-}
-
-views::View* AutofillProfilesView::GetContentsView() {
- return this;
-}
-
-bool AutofillProfilesView::Cancel() {
- // No way to cancel - we save back all the info always.
- return Accept();
-}
-
-bool AutofillProfilesView::Accept() {
- return true;
-}
-
-/////////////////////////////////////////////////////////////////////////////
-// AutofillProfilesView, views::ButtonListener implementations:
-void AutofillProfilesView::ButtonPressed(views::Button* sender,
- const views::Event& event) {
- if (sender == add_address_button_) {
- AddClicked(ContentListTableModel::kAddressGroup);
- } else if (sender == add_credit_card_button_) {
- AddClicked(ContentListTableModel::kCreditCardGroup);
- } else if (sender == edit_button_) {
- EditClicked();
- } else if (sender == remove_button_) {
- DeleteClicked();
- } else if (sender == enable_auto_fill_button_) {
- bool enabled = enable_auto_fill_button_->checked();
- UserMetricsAction action(enabled ? "Options_FormAutofill_Enable" :
- "Options_FormAutofill_Disable");
- UserMetrics::RecordAction(action, profile_);
- enable_auto_fill_.SetValueIfNotManaged(enabled);
- preferences_->ScheduleSavePersistentPrefs();
- UpdateWidgetState();
- }
-}
-
-/////////////////////////////////////////////////////////////////////////////
-// AutofillProfilesView, views::LinkController implementations:
-void AutofillProfilesView::LinkActivated(views::Link* source, int event_flags) {
- Browser* browser = BrowserList::GetLastActive();
- if (!browser || !browser->GetSelectedTabContents())
- browser = Browser::Create(profile_);
- browser->OpenAutoFillHelpTabAndActivate();
-}
-
-
-/////////////////////////////////////////////////////////////////////////////
-// AutofillProfilesView, views::FocusChangeListener implementations:
-void AutofillProfilesView::FocusWillChange(views::View* focused_before,
- views::View* focused_now) {
- if (focused_now) {
- focused_now->ScrollRectToVisible(gfx::Rect(focused_now->width(),
- focused_now->height()));
- }
-}
-
-/////////////////////////////////////////////////////////////////////////////
-// AutofillProfilesView, views::TableViewObserver implementations:
-void AutofillProfilesView::OnSelectionChanged() {
- UpdateWidgetState();
-}
-
-void AutofillProfilesView::OnDoubleClick() {
- if (!child_dialog_opened_)
- EditClicked();
-}
-
-
-/////////////////////////////////////////////////////////////////////////////
-// AutofillProfilesView, PersonalDataManager::Observer implementations.
-void AutofillProfilesView::OnPersonalDataLoaded() {
- GetData();
-}
-
-void AutofillProfilesView::OnPersonalDataChanged() {
- profiles_set_.clear();
- for (std::vector<AutofillProfile*>::const_iterator address_it =
- personal_data_manager_->profiles().begin();
- address_it != personal_data_manager_->profiles().end();
- ++address_it) {
- profiles_set_.push_back(EditableSetInfo(*address_it));
- }
-
- credit_card_set_.clear();
- for (std::vector<CreditCard*>::const_iterator cc_it =
- personal_data_manager_->credit_cards().begin();
- cc_it != personal_data_manager_->credit_cards().end();
- ++cc_it) {
- credit_card_set_.push_back(EditableSetInfo(*cc_it));
- }
-
- if (table_model_.get())
- table_model_->Refresh();
-
- // Update state only if buttons already created.
- if (add_address_button_) {
- UpdateWidgetState();
- }
-}
-
-/////////////////////////////////////////////////////////////////////////////
-// AutofillProfilesView, NotificationObserver implementation.
-void AutofillProfilesView::Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details) {
- DCHECK_EQ(NotificationType::PREF_CHANGED, type.value);
- const std::string* pref_name = Details<std::string>(details).ptr();
- if (!pref_name || *pref_name == prefs::kAutoFillEnabled)
- UpdateWidgetState();
-}
-
-/////////////////////////////////////////////////////////////////////////////
-// AutofillProfilesView, private:
-void AutofillProfilesView::Init() {
- GetData();
-
- enable_auto_fill_button_ = new views::Checkbox(
- UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_AUTOFILL_ENABLE)));
- enable_auto_fill_button_->set_listener(this);
-
- table_model_.reset(new ContentListTableModel(&profiles_set_,
- &credit_card_set_));
- std::vector<TableColumn> columns;
- columns.push_back(TableColumn());
- scroll_view_ = new views::TableView(table_model_.get(), columns,
- views::TEXT_ONLY, false, true, true);
- scroll_view_->SetObserver(this);
-
- add_address_button_ = new views::NativeButton(this,
- UTF16ToWide(l10n_util::GetStringUTF16(IDS_AUTOFILL_ADD_ADDRESS_BUTTON)));
- add_credit_card_button_ = new views::NativeButton(this, UTF16ToWide(
- l10n_util::GetStringUTF16(IDS_AUTOFILL_ADD_CREDITCARD_BUTTON)));
- edit_button_ = new views::NativeButton(this,
- UTF16ToWide(l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_BUTTON)));
- remove_button_ = new views::NativeButton(this,
- UTF16ToWide(l10n_util::GetStringUTF16(IDS_AUTOFILL_DELETE_BUTTON)));
-
- views::GridLayout* layout = views::GridLayout::CreatePanel(this);
- SetLayoutManager(layout);
-
- const int table_with_buttons_column_view_set_id = 0;
- views::ColumnSet* column_set =
- layout->AddColumnSet(table_with_buttons_column_view_set_id);
- column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
- views::GridLayout::USE_PREF, 0, 0);
- column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
- column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 0,
- views::GridLayout::USE_PREF, 0, 0);
-
- layout->StartRow(0, table_with_buttons_column_view_set_id);
- layout->AddView(enable_auto_fill_button_, 3, 1, views::GridLayout::FILL,
- views::GridLayout::FILL);
- layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
-
- layout->StartRow(0, table_with_buttons_column_view_set_id);
- layout->AddView(scroll_view_, 1, 8, views::GridLayout::FILL,
- views::GridLayout::FILL);
- layout->AddView(add_address_button_);
-
- layout->StartRowWithPadding(0, table_with_buttons_column_view_set_id, 0,
- views::kRelatedControlVerticalSpacing);
- layout->SkipColumns(2);
- layout->AddView(add_credit_card_button_);
-
- layout->StartRowWithPadding(0, table_with_buttons_column_view_set_id, 0,
- views::kRelatedControlVerticalSpacing);
- layout->SkipColumns(2);
- layout->AddView(edit_button_);
-
- layout->StartRowWithPadding(0, table_with_buttons_column_view_set_id, 0,
- views::kRelatedControlVerticalSpacing);
- layout->SkipColumns(2);
- layout->AddView(remove_button_);
-
- layout->AddPaddingRow(1, table_with_buttons_column_view_set_id);
-
-
- focus_manager_ = GetFocusManager();
- focus_manager_->AddFocusChangeListener(this);
-
- UpdateWidgetState();
-}
-
-void AutofillProfilesView::GetData() {
- if (!personal_data_manager_->IsDataLoaded()) {
- return;
- }
- bool imported_data_present = !profiles_set_.empty() ||
- !credit_card_set_.empty();
- if (!imported_data_present) {
- profiles_set_.reserve(personal_data_manager_->profiles().size());
- for (std::vector<AutofillProfile*>::const_iterator address_it =
- personal_data_manager_->profiles().begin();
- address_it != personal_data_manager_->profiles().end();
- ++address_it) {
- profiles_set_.push_back(EditableSetInfo(*address_it));
- }
- }
-
- if (!imported_data_present) {
- credit_card_set_.reserve(personal_data_manager_->credit_cards().size());
- for (std::vector<CreditCard*>::const_iterator cc_it =
- personal_data_manager_->credit_cards().begin();
- cc_it != personal_data_manager_->credit_cards().end();
- ++cc_it) {
- credit_card_set_.push_back(EditableSetInfo(*cc_it));
- }
- }
-
- if (table_model_.get())
- table_model_->Refresh();
-
- // Update state only if buttons already created.
- if (add_address_button_) {
- UpdateWidgetState();
- }
-}
-
-bool AutofillProfilesView::IsDataReady() const {
- return personal_data_manager_->IsDataLoaded();
-}
-
-void AutofillProfilesView::SaveData() {
- std::vector<AutofillProfile> profiles;
- profiles.reserve(profiles_set_.size());
- std::vector<EditableSetInfo>::iterator it;
- for (it = profiles_set_.begin(); it != profiles_set_.end(); ++it) {
- profiles.push_back(it->address);
- }
- std::vector<CreditCard> credit_cards;
- credit_cards.reserve(credit_card_set_.size());
- for (it = credit_card_set_.begin(); it != credit_card_set_.end(); ++it) {
- credit_cards.push_back(it->credit_card);
- }
- observer_->OnAutoFillDialogApply(&profiles, &credit_cards);
-}
-
-/////////////////////////////////////////////////////////////////////////////
-// AutofillProfilesView::PhoneSubView, public:
-AutofillProfilesView::PhoneSubView::PhoneSubView(
- AutofillProfilesView* autofill_view,
- views::Label* label,
- views::Textfield* text_phone)
- : autofill_view_(autofill_view),
- label_(label),
- text_phone_(text_phone),
- phone_warning_button_(NULL),
- last_state_(false) {
- DCHECK(label_);
- DCHECK(text_phone_);
-}
-
-void AutofillProfilesView::PhoneSubView::ContentsChanged(
- views::Textfield* sender, const string16& new_contents) {
- if (sender == text_phone_) {
- UpdateButtons();
- }
-}
-
-bool AutofillProfilesView::PhoneSubView::IsValid() const {
- if (text_phone_) {
- string16 phone = text_phone_->text();
- if (phone.empty())
- return true;
-
- // Try to parse it.
- string16 number, city, country;
- return PhoneNumber::ParsePhoneNumber(phone, &number, &city, &country);
- }
- return false;
-}
-
-void AutofillProfilesView::PhoneSubView::UpdateButtons() {
- if (phone_warning_button_) {
- SkBitmap* image = text_phone_->text().empty() ? NULL :
- autofill_view_->GetWarningBitmap(IsValid());
- phone_warning_button_->SetImage(views::CustomButton::BS_NORMAL, image);
- if (last_state_ != IsValid()) {
- last_state_ = IsValid();
- SchedulePaint();
- }
- }
-}
-
-/////////////////////////////////////////////////////////////////////////////
-// AutofillProfilesView::PhoneSubView, protected:
-/////////////////////////////////////////////////////////////////////////////
-// AutofillProfilesView::PhoneSubView, views::View implementations
-void AutofillProfilesView::PhoneSubView::ViewHierarchyChanged(
- bool is_add, views::View* parent, views::View* child) {
- if (is_add && this == child) {
- views::GridLayout* layout = new views::GridLayout(this);
- SetLayoutManager(layout);
- const int two_column_fill_view_set_id = 0;
- views::ColumnSet* column_set =
- layout->AddColumnSet(two_column_fill_view_set_id);
- column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 1,
- views::GridLayout::USE_PREF, 0, 0);
- column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
- column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 0,
- views::GridLayout::USE_PREF, 0, 0);
- layout->StartRow(0, two_column_fill_view_set_id);
- layout->AddView(label_, 3, 1);
- layout->StartRow(0, two_column_fill_view_set_id);
- text_phone_->set_default_width_in_chars(15);
- layout->AddView(text_phone_);
- phone_warning_button_ = new views::ImageButton(this);
- // Set default size of the image.
- SkBitmap* image = autofill_view_->GetWarningBitmap(true);
- phone_warning_button_->SetPreferredSize(gfx::Size(image->width(),
- image->height()));
- phone_warning_button_->SetEnabled(false);
- phone_warning_button_->SetImageAlignment(views::ImageButton::ALIGN_LEFT,
- views::ImageButton::ALIGN_MIDDLE);
- layout->AddView(phone_warning_button_);
- UpdateButtons();
- }
-}
-
-/////////////////////////////////////////////////////////////////////////////
-// AutofillProfilesView::EditableSetViewContents, static data:
-AutofillProfilesView::EditableSetViewContents::TextFieldToAutoFill
- AutofillProfilesView::EditableSetViewContents::address_fields_[] = {
- { AutofillProfilesView::EditableSetViewContents::TEXT_FULL_NAME,
- NAME_FULL },
- { AutofillProfilesView::EditableSetViewContents::TEXT_COMPANY, COMPANY_NAME },
- { AutofillProfilesView::EditableSetViewContents::TEXT_EMAIL, EMAIL_ADDRESS },
- { AutofillProfilesView::EditableSetViewContents::TEXT_ADDRESS_LINE_1,
- ADDRESS_HOME_LINE1 },
- { AutofillProfilesView::EditableSetViewContents::TEXT_ADDRESS_LINE_2,
- ADDRESS_HOME_LINE2 },
- { AutofillProfilesView::EditableSetViewContents::TEXT_ADDRESS_CITY,
- ADDRESS_HOME_CITY },
- { AutofillProfilesView::EditableSetViewContents::TEXT_ADDRESS_STATE,
- ADDRESS_HOME_STATE },
- { AutofillProfilesView::EditableSetViewContents::TEXT_ADDRESS_ZIP,
- ADDRESS_HOME_ZIP },
- { AutofillProfilesView::EditableSetViewContents::TEXT_ADDRESS_COUNTRY,
- ADDRESS_HOME_COUNTRY },
- { AutofillProfilesView::EditableSetViewContents::TEXT_PHONE_PHONE,
- PHONE_HOME_WHOLE_NUMBER },
- { AutofillProfilesView::EditableSetViewContents::TEXT_FAX_PHONE,
- PHONE_FAX_WHOLE_NUMBER },
-};
-
-AutofillProfilesView::EditableSetViewContents::TextFieldToAutoFill
- AutofillProfilesView::EditableSetViewContents::credit_card_fields_[] = {
- { AutofillProfilesView::EditableSetViewContents::TEXT_CC_NAME,
- CREDIT_CARD_NAME },
- { AutofillProfilesView::EditableSetViewContents::TEXT_CC_NUMBER,
- CREDIT_CARD_NUMBER },
-};
-
-/////////////////////////////////////////////////////////////////////////////
-// AutofillProfilesView::EditableSetViewContents, public:
-AutofillProfilesView::EditableSetViewContents::EditableSetViewContents(
- AutofillProfilesView* observer,
- bool new_item,
- const EditableSetInfo& field_set)
- : temporary_info_(field_set),
- has_credit_card_number_been_edited_(false),
- observer_(observer),
- new_item_(new_item) {
- ZeroMemory(text_fields_, sizeof(text_fields_));
-}
-
-/////////////////////////////////////////////////////////////////////////////
-// AutofillProfilesView::EditableSetViewContents, protected:
-/////////////////////////////////////////////////////////////////////////////
-// AutofillProfilesView::EditableSetViewContents, views::View implementations
-void AutofillProfilesView::EditableSetViewContents::Layout() {
- View::Layout();
-}
-
-gfx::Size AutofillProfilesView::EditableSetViewContents::GetPreferredSize() {
- if (temporary_info_.is_address) {
- return views::Window::GetLocalizedContentsSize(
- IDS_AUTOFILL_DIALOG_EDIT_ADDRESS_WIDTH_CHARS,
- IDS_AUTOFILL_DIALOG_EDIT_ADDRESS_HEIGHT_LINES);
- } else {
- return views::Window::GetLocalizedContentsSize(
- IDS_AUTOFILL_DIALOG_EDIT_CCARD_WIDTH_CHARS,
- IDS_AUTOFILL_DIALOG_EDIT_CCARD_HEIGHT_LINES);
- }
-}
-
-void AutofillProfilesView::EditableSetViewContents::ViewHierarchyChanged(
- bool is_add, views::View* parent, views::View* child) {
- if (is_add && this == child) {
- observer_->ChildWindowOpened();
- views::GridLayout* layout = new views::GridLayout(this);
- layout->SetInsets(kSubViewVerticalInsets, kSubViewHorizotalInsets,
- kSubViewVerticalInsets, kSubViewHorizotalInsets);
- SetLayoutManager(layout);
- InitLayoutGrid(layout);
- if (temporary_info_.is_address)
- InitAddressFields(layout);
- else
- InitCreditCardFields(layout);
- }
-}
-
-/////////////////////////////////////////////////////////////////////////////
-// AutofillProfilesView::EditableSetViewContents,
-// views::DialogDelegate implementations
-int AutofillProfilesView::EditableSetViewContents::GetDialogButtons() const {
- return MessageBoxFlags::DIALOGBUTTON_CANCEL |
- MessageBoxFlags::DIALOGBUTTON_OK;
-}
-
-std::wstring
-AutofillProfilesView::EditableSetViewContents::GetDialogButtonLabel(
- MessageBoxFlags::DialogButton button) const {
- switch (button) {
- case MessageBoxFlags::DIALOGBUTTON_OK:
- return UTF16ToWide(l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SAVE));
- case MessageBoxFlags::DIALOGBUTTON_CANCEL:
- return std::wstring();
- default:
- break;
- }
- NOTREACHED();
- return std::wstring();
-}
-
-bool AutofillProfilesView::EditableSetViewContents::IsDialogButtonEnabled(
- MessageBoxFlags::DialogButton button) const {
- switch (button) {
- case MessageBoxFlags::DIALOGBUTTON_OK: {
- // Enable the ok button if at least one non-phone number field has text,
- // or the phone numbers are valid.
- bool valid = false;
- TextFieldToAutoFill* fields;
- int field_count;
- if (temporary_info_.is_address) {
- fields = address_fields_;
- field_count = arraysize(address_fields_);
- } else {
- fields = credit_card_fields_;
- field_count = arraysize(credit_card_fields_);
- }
- for (int i = 0; i < field_count; ++i) {
- DCHECK(text_fields_[fields[i].text_field]);
- // Phone and fax are handled separately.
- if (fields[i].text_field != TEXT_PHONE_PHONE &&
- fields[i].text_field != TEXT_FAX_PHONE &&
- !text_fields_[fields[i].text_field]->text().empty()) {
- valid = true;
- break;
- }
- }
- for (std::vector<PhoneSubView*>::const_iterator i =
- phone_sub_views_.begin(); i != phone_sub_views_.end(); ++i) {
- if (!(*i)->IsValid()) {
- valid = false;
- break;
- } else if (!valid && !(*i)->text_phone()->text().empty()) {
- valid = true;
- }
- }
- return valid;
- }
- case MessageBoxFlags::DIALOGBUTTON_CANCEL:
- return true;
- default:
- break;
- }
- NOTREACHED();
- return false;
-}
-
-std::wstring
-AutofillProfilesView::EditableSetViewContents::GetWindowTitle() const {
- int string_id = 0;
- if (temporary_info_.is_address) {
- string_id = new_item_ ? IDS_AUTOFILL_ADD_ADDRESS_CAPTION :
- IDS_AUTOFILL_EDIT_ADDRESS_CAPTION;
- } else {
- string_id = new_item_ ? IDS_AUTOFILL_ADD_CREDITCARD_CAPTION :
- IDS_AUTOFILL_EDIT_CREDITCARD_CAPTION;
- }
- return UTF16ToWide(l10n_util::GetStringUTF16(string_id));
-}
-
-void AutofillProfilesView::EditableSetViewContents::WindowClosing() {
- observer_->ChildWindowClosed();
-}
-
-views::View* AutofillProfilesView::EditableSetViewContents::GetContentsView() {
- return this;
-}
-
-bool AutofillProfilesView::EditableSetViewContents::Cancel() {
- return true;
-}
-
-bool AutofillProfilesView::EditableSetViewContents::Accept() {
- observer_->EditAccepted(&temporary_info_, new_item_);
- return true;
-}
-
-/////////////////////////////////////////////////////////////////////////////
-// AutofillProfilesView::EditableSetViewContents,
-// views::ButtonListener implementations
-void AutofillProfilesView::EditableSetViewContents::ButtonPressed(
- views::Button* sender, const views::Event& event) {
- NOTREACHED();
-}
-
-/////////////////////////////////////////////////////////////////////////////
-// AutofillProfilesView::EditableSetViewContents,
-// views::TextfieldController implementations:
-void AutofillProfilesView::EditableSetViewContents::ContentsChanged(
- views::Textfield* sender, const string16& new_contents) {
- if (temporary_info_.is_address) {
- for (int field = 0; field < arraysize(address_fields_); ++field) {
- DCHECK(text_fields_[address_fields_[field].text_field]);
- if (text_fields_[address_fields_[field].text_field] == sender) {
- if (!UpdateContentsPhoneViews(address_fields_[field].text_field,
- sender, new_contents)) {
- temporary_info_.address.SetInfo(
- AutofillType(address_fields_[field].type), new_contents);
- }
- UpdateButtons();
- return;
- }
- }
- } else {
- for (int field = 0; field < arraysize(credit_card_fields_); ++field) {
- DCHECK(text_fields_[credit_card_fields_[field].text_field]);
- if (text_fields_[credit_card_fields_[field].text_field] == sender) {
- UpdateContentsPhoneViews(address_fields_[field].text_field,
- sender, new_contents);
- temporary_info_.credit_card.SetInfo(
- AutofillType(credit_card_fields_[field].type), new_contents);
- UpdateButtons();
- return;
- }
- }
- }
-}
-
-bool AutofillProfilesView::EditableSetViewContents::HandleKeyEvent(
- views::Textfield* sender, const views::KeyEvent& key_event) {
- if (sender == text_fields_[TEXT_CC_NUMBER] &&
- !has_credit_card_number_been_edited_) {
- // You cannot edit obfuscated number, you must retype it anew.
- sender->SetText(string16());
- has_credit_card_number_been_edited_ = true;
- }
- return false;
-}
-
-/////////////////////////////////////////////////////////////////////////////
-// AutofillProfilesView::EditableSetViewContents,
-// views::Combobox::Listener implementations:
-void AutofillProfilesView::EditableSetViewContents::ItemChanged(
- views::Combobox* combo_box, int prev_index, int new_index) {
- if (combo_box == combo_box_month_) {
- if (new_index == -1) {
- NOTREACHED();
- } else {
- temporary_info_.credit_card.SetInfo(
- AutofillType(CREDIT_CARD_EXP_MONTH),
- UTF16ToWideHack(combo_box_model_month_->GetItemAt(new_index)));
- }
- } else if (combo_box == combo_box_year_) {
- if (new_index == -1) {
- NOTREACHED();
- } else {
- temporary_info_.credit_card.SetInfo(
- AutofillType(CREDIT_CARD_EXP_4_DIGIT_YEAR),
- UTF16ToWideHack(combo_box_model_year_->GetItemAt(new_index)));
- }
- } else {
- NOTREACHED();
- }
-}
-
-/////////////////////////////////////////////////////////////////////////////
-// AutofillProfilesView::EditableSetViewContents, private:
-void AutofillProfilesView::EditableSetViewContents::InitAddressFields(
- views::GridLayout* layout) {
- DCHECK(temporary_info_.is_address);
-
- for (int field = 0; field < arraysize(address_fields_); ++field) {
- DCHECK(!text_fields_[address_fields_[field].text_field]);
- text_fields_[address_fields_[field].text_field] =
- new views::Textfield(views::Textfield::STYLE_DEFAULT);
- text_fields_[address_fields_[field].text_field]->SetController(this);
- text_fields_[address_fields_[field].text_field]->SetText(
- temporary_info_.address.GetFieldText(
- AutofillType(address_fields_[field].type)));
- }
-
- layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
- layout->StartRow(0, double_column_fill_view_set_id_);
- layout->AddView(CreateLeftAlignedLabel(IDS_AUTOFILL_DIALOG_FULL_NAME));
-
- layout->StartRow(0, double_column_fill_view_set_id_);
- layout->AddView(text_fields_[TEXT_FULL_NAME]);
-
- layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
- layout->StartRow(0, double_column_fill_view_set_id_);
- layout->AddView(CreateLeftAlignedLabel(IDS_AUTOFILL_DIALOG_COMPANY_NAME));
-
- layout->StartRow(0, double_column_fill_view_set_id_);
- layout->AddView(text_fields_[TEXT_COMPANY]);
-
- layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
- layout->StartRow(0, double_column_leading_view_set_id_);
- layout->AddView(new views::Label(UTF16ToWide(l10n_util::GetStringUTF16(
- IDS_AUTOFILL_DIALOG_ADDRESS_LINE_1))));
-
- layout->StartRow(0, double_column_fill_view_set_id_);
- layout->AddView(text_fields_[TEXT_ADDRESS_LINE_1]);
-
- layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
- layout->StartRow(0, double_column_leading_view_set_id_);
- layout->AddView(new views::Label(UTF16ToWide(l10n_util::GetStringUTF16(
- IDS_AUTOFILL_DIALOG_ADDRESS_LINE_2))));
-
- layout->StartRow(0, double_column_fill_view_set_id_);
- layout->AddView(text_fields_[TEXT_ADDRESS_LINE_2]);
-
- layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
- layout->StartRow(0, triple_column_fill_view_set_id_);
- layout->AddView(CreateLeftAlignedLabel(IDS_AUTOFILL_DIALOG_CITY));
- layout->AddView(CreateLeftAlignedLabel(IDS_AUTOFILL_DIALOG_STATE));
- layout->AddView(CreateLeftAlignedLabel(IDS_AUTOFILL_DIALOG_ZIP_CODE));
-
- text_fields_[TEXT_ADDRESS_CITY]->set_default_width_in_chars(16);
- text_fields_[TEXT_ADDRESS_STATE]->set_default_width_in_chars(16);
- text_fields_[TEXT_ADDRESS_ZIP]->set_default_width_in_chars(5);
-
- layout->StartRow(0, triple_column_fill_view_set_id_);
- layout->AddView(text_fields_[TEXT_ADDRESS_CITY]);
- layout->AddView(text_fields_[TEXT_ADDRESS_STATE]);
- layout->AddView(text_fields_[TEXT_ADDRESS_ZIP]);
-
- layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
- layout->StartRow(0, double_column_fill_view_set_id_);
- layout->AddView(CreateLeftAlignedLabel(IDS_AUTOFILL_DIALOG_COUNTRY));
-
- text_fields_[TEXT_ADDRESS_COUNTRY]->set_default_width_in_chars(11);
-
- layout->StartRow(0, double_column_fill_view_set_id_);
- layout->AddView(text_fields_[TEXT_ADDRESS_COUNTRY]);
-
- PhoneSubView* phone = new PhoneSubView(
- observer_,
- CreateLeftAlignedLabel(IDS_AUTOFILL_DIALOG_PHONE),
- text_fields_[TEXT_PHONE_PHONE]);
-
- phone_sub_views_.push_back(phone);
-
- PhoneSubView* fax = new PhoneSubView(
- observer_,
- CreateLeftAlignedLabel(IDS_AUTOFILL_DIALOG_FAX),
- text_fields_[TEXT_FAX_PHONE]);
-
- phone_sub_views_.push_back(fax);
-
- layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
- layout->StartRow(0, double_column_fill_view_set_id_);
- layout->AddView(phone);
- layout->AddView(fax);
-
- layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
- layout->StartRow(0, double_column_fill_view_set_id_);
- layout->AddView(CreateLeftAlignedLabel(IDS_AUTOFILL_DIALOG_EMAIL));
-
- layout->StartRow(0, double_column_fill_view_set_id_);
- layout->AddView(text_fields_[TEXT_EMAIL]);
-
- UpdateButtons();
-}
-
-void AutofillProfilesView::EditableSetViewContents::InitCreditCardFields(
- views::GridLayout* layout) {
- DCHECK(!temporary_info_.is_address);
-
- // Create combo box models.
- combo_box_model_month_.reset(new StringVectorComboboxModel);
- std::vector<std::wstring> model_strings;
- model_strings.reserve(12);
- for (int month = 1; month <= 12; ++month)
- model_strings.push_back(StringPrintf(L"%02i", month));
- combo_box_model_month_->set_cb_strings(&model_strings);
- model_strings.clear();
- model_strings.reserve(20);
- base::Time::Exploded exploded_time;
- base::Time::Now().LocalExplode(&exploded_time);
- for (int year = 0; year < 10; ++year)
- model_strings.push_back(StringPrintf(L"%04i", year + exploded_time.year));
- combo_box_model_year_.reset(new StringVectorComboboxModel);
- combo_box_model_year_->set_cb_strings(&model_strings);
-
- for (int field = 0; field < arraysize(credit_card_fields_); ++field) {
- DCHECK(!text_fields_[credit_card_fields_[field].text_field]);
- text_fields_[credit_card_fields_[field].text_field] =
- new views::Textfield(views::Textfield::STYLE_DEFAULT);
- text_fields_[credit_card_fields_[field].text_field]->SetController(this);
- string16 field_text;
- if (credit_card_fields_[field].text_field == TEXT_CC_NUMBER) {
- field_text = temporary_info_.credit_card.GetFieldText(
- AutofillType(credit_card_fields_[field].type));
- if (!field_text.empty())
- field_text = temporary_info_.credit_card.ObfuscatedNumber();
- } else {
- field_text = temporary_info_.credit_card.GetFieldText(
- AutofillType(credit_card_fields_[field].type));
- }
- text_fields_[credit_card_fields_[field].text_field]->SetText(field_text);
- }
-
- layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
- layout->StartRow(0, double_column_fill_view_set_id_);
- layout->AddView(CreateLeftAlignedLabel(IDS_AUTOFILL_DIALOG_NAME_ON_CARD));
- layout->StartRow(0, double_column_fill_view_set_id_);
- layout->AddView(text_fields_[TEXT_CC_NAME]);
-
- // Layout credit card info
- layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
- layout->StartRow(0, double_column_ccnumber_cvc_);
- layout->AddView(
- CreateLeftAlignedLabel(IDS_AUTOFILL_DIALOG_CREDIT_CARD_NUMBER));
- layout->StartRow(0, double_column_ccnumber_cvc_);
- // Number (20 chars), month(2 chars), year (4 chars), cvc (4 chars)
- text_fields_[TEXT_CC_NUMBER]->set_default_width_in_chars(20);
- layout->AddView(text_fields_[TEXT_CC_NUMBER]);
-
- layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
- layout->StartRow(0, double_column_ccexpiration_);
- layout->AddView(
- CreateLeftAlignedLabel(IDS_AUTOFILL_DIALOG_EXPIRATION_DATE), 3, 1);
-
- combo_box_month_ = new views::Combobox(combo_box_model_month_.get());
- combo_box_month_->set_listener(this);
- string16 field_text;
- field_text = temporary_info_.credit_card.GetFieldText(
- AutofillType(CREDIT_CARD_EXP_MONTH));
- combo_box_month_->SetSelectedItem(
- combo_box_model_month_->GetIndex(field_text));
-
- combo_box_year_ = new views::Combobox(combo_box_model_year_.get());
- combo_box_year_->set_listener(this);
- field_text = temporary_info_.credit_card.GetFieldText(
- AutofillType(CREDIT_CARD_EXP_4_DIGIT_YEAR));
- combo_box_year_->SetSelectedItem(combo_box_model_year_->GetIndex(field_text));
-
- layout->StartRow(0, double_column_ccexpiration_);
- layout->AddView(combo_box_month_);
- layout->AddView(combo_box_year_);
-
- UpdateButtons();
-}
-
-void AutofillProfilesView::EditableSetViewContents::InitLayoutGrid(
- views::GridLayout* layout) {
- views::ColumnSet* column_set =
- layout->AddColumnSet(double_column_fill_view_set_id_);
- int i;
- for (i = 0; i < 2; ++i) {
- if (i)
- column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
- column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 1,
- views::GridLayout::USE_PREF, 0, 0);
- }
- column_set = layout->AddColumnSet(double_column_leading_view_set_id_);
- for (i = 0; i < 2; ++i) {
- if (i)
- column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
- column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER,
- 1, views::GridLayout::USE_PREF, 0, 0);
- }
- column_set = layout->AddColumnSet(triple_column_fill_view_set_id_);
- for (i = 0; i < 3; ++i) {
- if (i)
- column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
- column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 1,
- views::GridLayout::USE_PREF, 0, 0);
- }
- column_set = layout->AddColumnSet(triple_column_leading_view_set_id_);
- for (i = 0; i < 3; ++i) {
- if (i)
- column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
- column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER,
- 1, views::GridLayout::USE_PREF, 0, 0);
- }
- // City (33% - 16/48), state(33%), zip (12.7% - 5/42), country (21% - 11/48)
- column_set = layout->AddColumnSet(four_column_city_state_zip_set_id_);
- column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER,
- 16, views::GridLayout::USE_PREF, 0, 0);
- column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
- column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER,
- 16, views::GridLayout::USE_PREF, 0, 0);
- column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
- column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER,
- 5, views::GridLayout::USE_PREF, 0, 0);
- column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
- column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER,
- 11, views::GridLayout::USE_PREF, 0, 0);
-
- column_set = layout->AddColumnSet(double_column_ccnumber_cvc_);
- // Number and CVC are in ratio 20:4
- column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER,
- 20, views::GridLayout::USE_PREF, 0, 0);
- column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
- column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER,
- 4, views::GridLayout::USE_PREF, 0, 0);
-
- column_set = layout->AddColumnSet(double_column_ccexpiration_);
-
- ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- gfx::Font font =
- rb.GetFont(ResourceBundle::BaseFont).DeriveFont(0, gfx::Font::BOLD);
-
- // The sizes: 4 characters for drop down icon + 2 for a month or 4 for a year.
- column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER,
- 0, views::GridLayout::FIXED,
- font.GetStringWidth(ASCIIToUTF16("000000")), 0);
- column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
- column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER,
- 0, views::GridLayout::FIXED,
- font.GetStringWidth(ASCIIToUTF16("00000000")), 0);
-
- column_set = layout->AddColumnSet(three_column_header_);
- column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL,
- 0, views::GridLayout::USE_PREF, 0, 0);
- column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
- column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
- 1, views::GridLayout::FIXED, 0, 0);
- column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
- column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
- 1, views::GridLayout::FIXED, 0, 0);
-}
-
-views::Label*
-AutofillProfilesView::EditableSetViewContents::CreateLeftAlignedLabel(
- int label_id) {
- views::Label* label =
- new views::Label(UTF16ToWide(l10n_util::GetStringUTF16(label_id)));
- label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
- return label;
-}
-
-void AutofillProfilesView::EditableSetViewContents::UpdateButtons() {
- GetDialogClientView()->UpdateDialogButtons();
-}
-
-bool AutofillProfilesView::EditableSetViewContents::UpdateContentsPhoneViews(
- TextFields field, views::Textfield* sender, const string16& new_contents) {
- switch (field) {
- case TEXT_PHONE_PHONE:
- case TEXT_FAX_PHONE: {
- for (std::vector<PhoneSubView*>::iterator it = phone_sub_views_.begin();
- it != phone_sub_views_.end(); ++it)
- (*it)->ContentsChanged(sender, new_contents);
- DCHECK(temporary_info_.is_address); // Only addresses have phone numbers.
- string16 number, city, country;
- PhoneNumber::ParsePhoneNumber(new_contents, &number, &city, &country);
- temporary_info_.address.SetInfo(
- AutofillType(field == TEXT_PHONE_PHONE ? PHONE_HOME_COUNTRY_CODE :
- PHONE_FAX_COUNTRY_CODE), country);
- temporary_info_.address.SetInfo(
- AutofillType(field == TEXT_PHONE_PHONE ? PHONE_HOME_CITY_CODE :
- PHONE_FAX_CITY_CODE), city);
- temporary_info_.address.SetInfo(
- AutofillType(field == TEXT_PHONE_PHONE ? PHONE_HOME_NUMBER :
- PHONE_FAX_NUMBER), number);
- return true;
- }
- }
- return false;
-}
-
-void AutofillProfilesView::StringVectorComboboxModel::set_cb_strings(
- std::vector<std::wstring> *source) {
- cb_strings_.swap(*source);
-}
-
-int AutofillProfilesView::StringVectorComboboxModel::GetItemCount() {
- return cb_strings_.size();
-}
-
-string16 AutofillProfilesView::StringVectorComboboxModel::GetItemAt(int index) {
- DCHECK_GT(static_cast<int>(cb_strings_.size()), index);
- return WideToUTF16Hack(cb_strings_[index]);
-}
-
-int AutofillProfilesView::StringVectorComboboxModel::GetIndex(
- const std::wstring& value) {
- for (size_t index = 0; index < cb_strings_.size(); ++index) {
- if (cb_strings_[index] == value)
- return index;
- }
- return -1;
-}
-
-AutofillProfilesView::ContentListTableModel::ContentListTableModel(
- std::vector<EditableSetInfo>* profiles,
- std::vector<EditableSetInfo>* credit_cards)
- : profiles_(profiles),
- credit_cards_(credit_cards),
- observer_(NULL) {
-}
-
-void AutofillProfilesView::ContentListTableModel::Refresh() {
- if (observer_)
- observer_->OnModelChanged();
-}
-
-void AutofillProfilesView::ContentListTableModel::AddItem(int index) {
- if (observer_)
- observer_->OnItemsAdded(index, 1);
-}
-
-void AutofillProfilesView::ContentListTableModel::RemoveItem(int index) {
- DCHECK(index < static_cast<int>(profiles_->size() + credit_cards_->size()));
- if (index < static_cast<int>(profiles_->size()))
- profiles_->erase(profiles_->begin() + index);
- else
- credit_cards_->erase(credit_cards_->begin() + (index - profiles_->size()));
- if (observer_)
- observer_->OnItemsRemoved(index, 1);
-}
-
-void AutofillProfilesView::ContentListTableModel::UpdateItem(int index) {
- if (observer_)
- observer_->OnItemsChanged(index, 1);
-}
-
-int AutofillProfilesView::ContentListTableModel::RowCount() {
- return profiles_->size() + credit_cards_->size();
-}
-
-string16 AutofillProfilesView::ContentListTableModel::GetText(
- int row, int column_id) {
- DCHECK(row < static_cast<int>(profiles_->size() + credit_cards_->size()));
- if (row < static_cast<int>(profiles_->size())) {
- return WideToUTF16Hack(profiles_->at(row).address.Label());
- } else {
- row -= profiles_->size();
- return WideToUTF16Hack(credit_cards_->at(row).credit_card.PreviewSummary());
- }
-}
-
-ui::TableModel::Groups
- AutofillProfilesView::ContentListTableModel::GetGroups() {
- ui::TableModel::Groups groups;
-
- ui::TableModel::Group profile_group;
- profile_group.title =
- l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESSES_GROUP_NAME);
- profile_group.id = kAddressGroup;
- groups.push_back(profile_group);
-
- Group cc_group;
- cc_group.title =
- l10n_util::GetStringUTF16(IDS_AUTOFILL_CREDITCARDS_GROUP_NAME);
- cc_group.id = kCreditCardGroup;
- groups.push_back(cc_group);
-
- return groups;
-}
-
-int AutofillProfilesView::ContentListTableModel::GetGroupID(int row) {
- DCHECK(row < static_cast<int>(profiles_->size() + credit_cards_->size()));
- return (row < static_cast<int>(profiles_->size())) ? kAddressGroup :
- kCreditCardGroup;
-}
-
-void AutofillProfilesView::ContentListTableModel::SetObserver(
- ui::TableModelObserver* observer) {
- observer_ = observer;
-}
-
-
-// Declared in "chrome/browser/autofill/autofill_dialog.h"
-void ShowAutoFillDialog(gfx::NativeView parent,
- AutoFillDialogObserver* observer,
- Profile* profile) {
- DCHECK(profile);
-
- PersonalDataManager* personal_data_manager =
- profile->GetPersonalDataManager();
- DCHECK(personal_data_manager);
- AutofillProfilesView::Show(parent, observer, personal_data_manager, profile,
- profile->GetPrefs(), NULL, NULL);
-}
diff --git a/chrome/browser/ui/views/autofill_profiles_view_win.h b/chrome/browser/ui/views/autofill_profiles_view_win.h
deleted file mode 100644
index 5206167..0000000
--- a/chrome/browser/ui/views/autofill_profiles_view_win.h
+++ /dev/null
@@ -1,442 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_UI_VIEWS_AUTOFILL_PROFILES_VIEW_WIN_H_
-#define CHROME_BROWSER_UI_VIEWS_AUTOFILL_PROFILES_VIEW_WIN_H_
-#pragma once
-
-#include <list>
-#include <map>
-#include <vector>
-
-#include "base/compiler_specific.h"
-#include "base/string16.h"
-#include "chrome/browser/autofill/autofill_dialog.h"
-#include "chrome/browser/autofill/autofill_profile.h"
-#include "chrome/browser/autofill/personal_data_manager.h"
-#include "chrome/browser/prefs/pref_member.h"
-#include "content/common/notification_observer.h"
-#include "ui/base/models/combobox_model.h"
-#include "ui/base/models/table_model.h"
-#include "views/controls/combobox/combobox.h"
-#include "views/controls/link.h"
-#include "views/controls/table/table_view_observer.h"
-#include "views/controls/textfield/textfield_controller.h"
-#include "views/focus/focus_manager.h"
-#include "views/view.h"
-#include "views/window/dialog_delegate.h"
-
-namespace views {
-class Checkbox;
-class GridLayout;
-class ImageButton;
-class Label;
-class RadioButton;
-class TableView;
-class TextButton;
-} // namespace views
-
-class PrefService;
-class SkBitmap;
-
-///////////////////////////////////////////////////////////////////////////////
-// AutofillProfilesView
-//
-// The contents of the "AutoFill profiles" dialog window.
-//
-// Overview: has following sub-views:
-// EditableSetViewContents - set of displayed fields for address or credit card,
-// has iterator to std::vector<EditableSetInfo> vector so data could be
-// updated or notifications passes to the dialog view.
-// PhoneSubView - support view for the phone fields sets. used in
-// ScrollViewContents.
-// And there is a support data structure EditableSetInfo which encapsulates
-// editable set (address or credit card) and allows for quick addition and
-// deletion.
-class AutofillProfilesView : public views::View,
- public views::DialogDelegate,
- public views::ButtonListener,
- public views::LinkController,
- public views::FocusChangeListener,
- public views::TableViewObserver,
- public PersonalDataManager::Observer,
- public NotificationObserver {
- public:
- virtual ~AutofillProfilesView();
-
- static int Show(gfx::NativeWindow parent,
- AutoFillDialogObserver* observer,
- PersonalDataManager* personal_data_manager,
- Profile* profile,
- PrefService* preferences,
- AutofillProfile* imported_profile,
- CreditCard* imported_credit_card);
-
- protected:
- // Forward declaration. This struct defined further down.
- struct EditableSetInfo;
- // Called when 'Add Address' (|group_type| is
- // ContentListTableModel::kAddressGroup) or 'Add Credit Card' (|group_type| is
- // ContentListTableModel::kCreditCardGroup) is clicked.
- void AddClicked(int group_type);
- // Called when 'Edit...' is clicked.
- void EditClicked();
- // Called when 'Remove' is clicked.
- void DeleteClicked();
- // Called when 'Edit' dialog is accepted.
- void EditAccepted(EditableSetInfo* data, bool new_item);
-
- // Updates state of the buttons.
- void UpdateWidgetState();
-
- // Following two functions are called from opened child dialog to
- // disable/enable buttons.
- void ChildWindowOpened();
- void ChildWindowClosed();
-
- // Returns warning bitmap to set on warning indicator. If |good| is true it
- // returns the bitmap idicating validity, if false - indicating error.
- // Caller owns the bitmap after the call.
- SkBitmap* GetWarningBitmap(bool good);
-
- // views::View methods:
- virtual void Layout();
- virtual gfx::Size GetPreferredSize();
- virtual void ViewHierarchyChanged(bool is_add, views::View* parent,
- views::View* child);
-
- // views::DialogDelegate methods:
- virtual int GetDialogButtons() const;
- virtual std::wstring GetDialogButtonLabel(
- MessageBoxFlags::DialogButton button) const;
- virtual View* GetExtraView();
- virtual bool IsDialogButtonEnabled(
- MessageBoxFlags::DialogButton button) const;
- virtual bool CanResize() const { return true; }
- virtual bool CanMaximize() const { return false; }
- virtual bool IsAlwaysOnTop() const { return false; }
- virtual bool HasAlwaysOnTopMenu() const { return false; }
- virtual std::wstring GetWindowTitle() const;
- virtual void WindowClosing();
- virtual views::View* GetContentsView();
- virtual bool Cancel();
- virtual bool Accept();
-
- // views::ButtonListener methods:
- virtual void ButtonPressed(views::Button* sender,
- const views::Event& event);
-
- // views::LinkController methods:
- virtual void LinkActivated(views::Link* source, int event_flags);
-
- // views::FocusChangeListener methods:
- virtual void FocusWillChange(views::View* focused_before,
- views::View* focused_now);
-
- // views::TableViewObserver methods:
- virtual void OnSelectionChanged();
- virtual void OnDoubleClick();
-
- // PersonalDataManager::Observer methods:
- virtual void OnPersonalDataLoaded();
- virtual void OnPersonalDataChanged();
-
- // NotificationObserver methods:
- virtual void Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details);
-
- // Helper structure to keep info on one address or credit card.
- // Keeps info on one item in EditableSetViewContents.
- // Also keeps info on opened status. Allows to quickly add and delete items,
- // and then rebuild EditableSetViewContents.
- struct EditableSetInfo {
- bool is_address;
- // If |is_address| is true |address| has some data and |credit_card|
- // is empty, and vice versa
- AutofillProfile address;
- CreditCard credit_card;
-
- explicit EditableSetInfo(const AutofillProfile* input_address)
- : address(*input_address),
- is_address(true) {
- }
- explicit EditableSetInfo(const CreditCard* input_credit_card)
- : credit_card(*input_credit_card),
- is_address(false) {
- }
-
- std::string guid() const {
- if (is_address)
- return address.guid();
- else
- return credit_card.guid();
- }
- };
-
- private:
- // Indicates that there was no item focused. After re-building of the lists
- // first item will be focused.
- static const int kNoItemFocused = -1;
-
- struct FocusedItem {
- int group;
- int item;
- FocusedItem() : group(kNoItemFocused), item(kNoItemFocused) {}
- FocusedItem(int g, int i) : group(g), item(i) {}
- };
-
- AutofillProfilesView(AutoFillDialogObserver* observer,
- PersonalDataManager* personal_data_manager,
- Profile* profile,
- PrefService* preferences,
- AutofillProfile* imported_profile,
- CreditCard* imported_credit_card);
- void Init();
-
- void GetData();
- bool IsDataReady() const;
- void SaveData();
-
- // Rebuilds the view by deleting and re-creating sub-views
- void RebuildView(const FocusedItem& new_focus_index);
-
- // PhoneSubView encapsulates three phone fields (country, area, and phone)
- // and label above them, so they could be used together in one grid cell.
- class PhoneSubView : public views::View,
- public views::ButtonListener {
- public:
- PhoneSubView(AutofillProfilesView* autofill_view,
- views::Label* label,
- views::Textfield* text_phone);
- virtual ~PhoneSubView() {}
-
- virtual void ContentsChanged(views::Textfield* sender,
- const string16& new_contents);
-
- bool IsValid() const;
-
- views::Textfield* text_phone() { return text_phone_; }
-
- protected:
- // views::View methods:
- virtual void ViewHierarchyChanged(bool is_add, views::View* parent,
- views::View* child);
-
- // public views::ButtonListener method:
- virtual void ButtonPressed(views::Button* sender,
- const views::Event& event) {
- // Only stub is needed, it is never called.
- NOTREACHED();
- }
-
- private:
- void UpdateButtons();
- AutofillProfilesView* autofill_view_;
- views::Label* label_;
- views::Textfield* text_phone_;
- views::ImageButton* phone_warning_button_;
- bool last_state_;
-
- DISALLOW_COPY_AND_ASSIGN(PhoneSubView);
- };
-
- // Forward declaration.
- class StringVectorComboboxModel;
-
- // Sub-view for editing/adding a credit card or address.
- class EditableSetViewContents : public views::View,
- public views::DialogDelegate,
- public views::ButtonListener,
- public views::TextfieldController,
- public views::Combobox::Listener {
- public:
- EditableSetViewContents(AutofillProfilesView* observer,
- bool new_item,
- const EditableSetInfo& field_set);
- virtual ~EditableSetViewContents() {}
-
- protected:
- // views::View:
- virtual void Layout();
- virtual gfx::Size GetPreferredSize();
- virtual void ViewHierarchyChanged(bool is_add,
- views::View* parent,
- views::View* child);
-
- // views::DialogDelegate:
- virtual int GetDialogButtons() const;
- virtual std::wstring GetDialogButtonLabel(
- MessageBoxFlags::DialogButton button) const;
- virtual bool IsDialogButtonEnabled(
- MessageBoxFlags::DialogButton button) const;
- virtual bool CanResize() const { return false; }
- virtual bool CanMaximize() const { return false; }
- virtual bool IsModal() const { return true; }
- virtual bool HasAlwaysOnTopMenu() const { return false; }
- virtual std::wstring GetWindowTitle() const;
- virtual void WindowClosing();
- virtual views::View* GetContentsView();
- virtual bool Cancel();
- virtual bool Accept();
-
- // views::ButtonListener:
- virtual void ButtonPressed(views::Button* sender,
- const views::Event& event);
-
- // views::TextfieldController:
- virtual void ContentsChanged(views::Textfield* sender,
- const string16& new_contents);
- virtual bool HandleKeyEvent(views::Textfield* sender,
- const views::KeyEvent& keystroke);
-
- // views::Combobox::Listener methods:
- virtual void ItemChanged(views::Combobox* combo_box,
- int prev_index,
- int new_index);
- private:
- enum TextFields {
- TEXT_FULL_NAME,
- TEXT_COMPANY,
- TEXT_EMAIL,
- TEXT_ADDRESS_LINE_1,
- TEXT_ADDRESS_LINE_2,
- TEXT_ADDRESS_CITY,
- TEXT_ADDRESS_STATE,
- TEXT_ADDRESS_ZIP,
- TEXT_ADDRESS_COUNTRY,
- TEXT_PHONE_PHONE,
- TEXT_FAX_PHONE,
- TEXT_CC_NAME,
- TEXT_CC_NUMBER,
- // Must be last.
- MAX_TEXT_FIELD
- };
-
- void InitAddressFields(views::GridLayout* layout);
- void InitCreditCardFields(views::GridLayout* layout);
- void InitLayoutGrid(views::GridLayout* layout);
- views::Label* CreateLeftAlignedLabel(int label_id);
-
- void UpdateButtons();
-
- // If |field| is a phone or fax ContentsChanged is passed to the
- // PhoneSubView, the appropriate fields in |temporary_info_| are updated and
- // true is returned. Otherwise false is returned.
- bool UpdateContentsPhoneViews(TextFields field,
- views::Textfield* sender,
- const string16& new_contents);
-
- views::Textfield* text_fields_[MAX_TEXT_FIELD];
- EditableSetInfo temporary_info_;
- bool has_credit_card_number_been_edited_;
- AutofillProfilesView* observer_;
- scoped_ptr<StringVectorComboboxModel> combo_box_model_month_;
- views::Combobox* combo_box_month_;
- scoped_ptr<StringVectorComboboxModel> combo_box_model_year_;
- views::Combobox* combo_box_year_;
- bool new_item_;
- std::vector<PhoneSubView*> phone_sub_views_;
-
- struct TextFieldToAutoFill {
- TextFields text_field;
- AutofillFieldType type;
- };
-
- static TextFieldToAutoFill address_fields_[];
- static TextFieldToAutoFill credit_card_fields_[];
-
- static const int double_column_fill_view_set_id_ = 0;
- static const int double_column_leading_view_set_id_ = 1;
- static const int triple_column_fill_view_set_id_ = 2;
- static const int triple_column_leading_view_set_id_ = 3;
- static const int four_column_city_state_zip_set_id_ = 4;
- static const int double_column_ccnumber_cvc_ = 5;
- static const int three_column_header_ = 6;
- static const int double_column_ccexpiration_ = 7;
-
- DISALLOW_COPY_AND_ASSIGN(EditableSetViewContents);
- };
-
- class StringVectorComboboxModel : public ui::ComboboxModel {
- public:
- StringVectorComboboxModel() {}
- virtual ~StringVectorComboboxModel() {}
-
- // Sets the vector of the strings for the combobox. Swaps content with
- // |source|.
- void set_cb_strings(std::vector<std::wstring> *source);
-
- // Overridden from ui::ComboboxModel:
- virtual int GetItemCount();
- virtual string16 GetItemAt(int index);
-
- // Find an index of the item in the model, -1 if not present.
- int GetIndex(const std::wstring& value);
-
- private:
- std::vector<std::wstring> cb_strings_;
-
- DISALLOW_COPY_AND_ASSIGN(StringVectorComboboxModel);
- };
-
- // Model for scrolling credit cards and addresses.
- class ContentListTableModel : public ui::TableModel {
- public:
- ContentListTableModel(std::vector<EditableSetInfo>* profiles,
- std::vector<EditableSetInfo>* credit_cards);
- virtual ~ContentListTableModel() {}
-
- // Two constants defined for indexes of groups. The first one is index
- // of Add Address button, the second one is the index of Add Credit Card
- // button.
- static const int kAddressGroup = 1;
- static const int kCreditCardGroup = 2;
-
- void Refresh();
- void AddItem(int index);
- void RemoveItem(int index);
- void UpdateItem(int index);
-
- // ui::TableModel members:
- virtual int RowCount() OVERRIDE;
- virtual string16 GetText(int row, int column_id) OVERRIDE;
- virtual bool HasGroups() OVERRIDE { return true; }
- virtual ui::TableModel::Groups GetGroups() OVERRIDE;
- virtual int GetGroupID(int row) OVERRIDE;
- virtual void SetObserver(ui::TableModelObserver* observer) OVERRIDE;
-
- private:
- std::vector<EditableSetInfo>* profiles_;
- std::vector<EditableSetInfo>* credit_cards_;
- ui::TableModelObserver* observer_;
-
- DISALLOW_COPY_AND_ASSIGN(ContentListTableModel);
- };
-
- AutoFillDialogObserver* observer_;
- PersonalDataManager* personal_data_manager_;
- Profile* profile_;
- PrefService* preferences_;
- std::vector<EditableSetInfo> profiles_set_;
- std::vector<EditableSetInfo> credit_card_set_;
-
- BooleanPrefMember enable_auto_fill_;
-
- views::Checkbox* enable_auto_fill_button_;
- views::Button* add_address_button_;
- views::Button* add_credit_card_button_;
- views::Button* edit_button_;
- views::Button* remove_button_;
- views::TableView* scroll_view_;
- scoped_ptr<ContentListTableModel> table_model_;
- views::FocusManager* focus_manager_;
- bool child_dialog_opened_;
-
- static AutofillProfilesView* instance_;
-
- DISALLOW_COPY_AND_ASSIGN(AutofillProfilesView);
-};
-
-#endif // CHROME_BROWSER_UI_VIEWS_AUTOFILL_PROFILES_VIEW_WIN_H_
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 0e4c47b..674f306 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -149,14 +149,8 @@
'browser/autofill/autofill_cc_infobar_delegate.h',
'browser/autofill/autofill_country.cc',
'browser/autofill/autofill_country.h',
- 'browser/autofill/autofill_dialog.h',
- 'browser/autofill/autofill_dialog_gtk.cc',
- 'browser/autofill/autofill_dialog_mac.mm',
- # Windows version of autofill dialog is defined in
- # 'browser/ui/views/autofill_profiles_view_win.cc'
'browser/autofill/autofill_download.cc',
'browser/autofill/autofill_download.h',
- 'browser/autofill/autofill_editor_gtk.cc',
'browser/autofill/autofill_field.cc',
'browser/autofill/autofill_field.h',
'browser/autofill/autofill_ie_toolbar_import_win.cc',
@@ -2790,8 +2784,6 @@
'browser/ui/views/autocomplete/autocomplete_result_view.h',
'browser/ui/views/autocomplete/touch_autocomplete_popup_contents_view.cc',
'browser/ui/views/autocomplete/touch_autocomplete_popup_contents_view.h',
- 'browser/ui/views/autofill_profiles_view_win.cc',
- 'browser/ui/views/autofill_profiles_view_win.h',
'browser/ui/views/bookmarks/bookmark_bar_instructions_view.cc',
'browser/ui/views/bookmarks/bookmark_bar_instructions_view.h',
'browser/ui/views/bookmarks/bookmark_bar_view.cc',