summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-11 22:44:12 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-11 22:44:12 +0000
commitd98ed55b583d55a4f851b0f5e1f62699d4b3f476 (patch)
treef56575ff7c3a9f745c8e7560b8425359b8441ef0
parent550543e2cfacddb3340481a073968a0d2456b35c (diff)
downloadchromium_src-d98ed55b583d55a4f851b0f5e1f62699d4b3f476.zip
chromium_src-d98ed55b583d55a4f851b0f5e1f62699d4b3f476.tar.gz
chromium_src-d98ed55b583d55a4f851b0f5e1f62699d4b3f476.tar.bz2
progress on requestAutocomplete dialog
- Show invalid markers for all sections, not just billing. - hide invalid markers when the field becomes valid BUG=163516 Review URL: https://codereview.chromium.org/11854004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@176456 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/ui/views/autofill/autofill_dialog_views.cc125
-rw-r--r--chrome/browser/ui/views/autofill/autofill_dialog_views.h12
2 files changed, 74 insertions, 63 deletions
diff --git a/chrome/browser/ui/views/autofill/autofill_dialog_views.cc b/chrome/browser/ui/views/autofill/autofill_dialog_views.cc
index 48b2480..a70b852 100644
--- a/chrome/browser/ui/views/autofill/autofill_dialog_views.cc
+++ b/chrome/browser/ui/views/autofill/autofill_dialog_views.cc
@@ -34,6 +34,8 @@ namespace {
// Size of the triangular mark that indicates an invalid textfield.
const int kDogEarSize = 10;
+const char kDecoratedTextfieldClassName[] = "autofill/DecoratedTextfield";
+
// Returns a label that describes a details section.
views::Label* CreateDetailsSectionLabel(const string16& text) {
views::Label* label = new views::Label(text);
@@ -73,6 +75,10 @@ void AutofillDialogViews::DecoratedTextfield::SetInvalid(bool invalid) {
SchedulePaint();
}
+std::string AutofillDialogViews::DecoratedTextfield::GetClassName() const {
+ return kDecoratedTextfieldClassName;
+}
+
void AutofillDialogViews::DecoratedTextfield::PaintChildren(
gfx::Canvas* canvas) {}
@@ -202,12 +208,16 @@ AutofillDialogViews::AutofillDialogViews(AutofillDialogController* controller)
: controller_(controller),
did_submit_(false),
window_(NULL),
- contents_(NULL),
- email_(SECTION_EMAIL),
- cc_(SECTION_CC),
- billing_(SECTION_BILLING),
- shipping_(SECTION_SHIPPING) {
+ contents_(NULL) {
DCHECK(controller);
+ detail_groups_.insert(std::make_pair(SECTION_EMAIL,
+ DetailsGroup(SECTION_EMAIL)));
+ detail_groups_.insert(std::make_pair(SECTION_CC,
+ DetailsGroup(SECTION_CC)));
+ detail_groups_.insert(std::make_pair(SECTION_BILLING,
+ DetailsGroup(SECTION_BILLING)));
+ detail_groups_.insert(std::make_pair(SECTION_SHIPPING,
+ DetailsGroup(SECTION_SHIPPING)));
}
AutofillDialogViews::~AutofillDialogViews() {
@@ -306,14 +316,17 @@ bool AutofillDialogViews::Accept() {
void AutofillDialogViews::ButtonPressed(views::Button* sender,
const ui::Event& event) {
if (sender == use_billing_for_shipping_) {
- UpdateDetailsGroupState(shipping_);
+ UpdateDetailsGroupState(*GroupForSection(SECTION_SHIPPING));
} else {
// TODO(estade): Should the menu be shown on mouse down?
- DetailsGroup* group =
- sender == email_.suggested_button ? &email_ :
- sender == cc_.suggested_button ? &cc_ :
- sender == billing_.suggested_button ? &billing_ :
- sender == shipping_.suggested_button ? &shipping_ : NULL;
+ DetailsGroup* group = NULL;
+ for (DetailGroupMap::iterator iter = detail_groups_.begin();
+ iter != detail_groups_.end(); ++iter) {
+ if (sender == iter->second.suggested_button) {
+ group = &iter->second;
+ break;
+ }
+ }
DCHECK(group);
views::MenuModelAdapter adapter(
@@ -332,21 +345,36 @@ void AutofillDialogViews::ButtonPressed(views::Button* sender,
void AutofillDialogViews::ContentsChanged(views::Textfield* sender,
const string16& new_contents) {
- const DetailsGroup& group =
- sender->parent()->parent() == email_.manual_input ? email_ :
- sender->parent()->parent() == cc_.manual_input ? cc_ :
- sender->parent()->parent() == billing_.manual_input ? billing_ :
- shipping_;
-
- for (TextfieldMap::const_iterator iter = group.textfields.begin();
- iter != group.textfields.end();
+ views::View* ancestor =
+ sender->GetAncestorWithClassName(kDecoratedTextfieldClassName);
+ DetailsGroup* group = NULL;
+ for (DetailGroupMap::iterator iter = detail_groups_.begin();
+ iter != detail_groups_.end(); ++iter) {
+ if (ancestor->parent() == iter->second.manual_input) {
+ group = &iter->second;
+ break;
+ }
+ }
+ DCHECK(group);
+
+ for (TextfieldMap::const_iterator iter = group->textfields.begin();
+ iter != group->textfields.end();
++iter) {
- if (iter->second->textfield() == sender) {
+ DecoratedTextfield* decorated = iter->second;
+ if (decorated == ancestor) {
controller_->UserEditedInput(iter->first,
- group.section,
+ group->section,
GetWidget()->GetNativeView(),
sender->GetBoundsInScreen(),
new_contents);
+
+ // If the field is marked as invalid, check if the text is now valid.
+ if (decorated->invalid()) {
+ decorated->SetInvalid(
+ !controller_->InputIsValid(iter->first,
+ decorated->textfield()->text()));
+ }
+
break;
}
}
@@ -433,19 +461,11 @@ views::View* AutofillDialogViews::CreateDetailsContainer() {
view->SetLayoutManager(
new views::BoxLayout(views::BoxLayout::kVertical, 0, 0,
views::kRelatedControlVerticalSpacing));
-
- // Email.
- CreateDetailsSection(SECTION_EMAIL);
- view->AddChildView(email_.container);
- // Credit card.
- CreateDetailsSection(SECTION_CC);
- view->AddChildView(cc_.container);
- // Billing.
- CreateDetailsSection(SECTION_BILLING);
- view->AddChildView(billing_.container);
- // Shipping.
- CreateDetailsSection(SECTION_SHIPPING);
- view->AddChildView(shipping_.container);
+ for (DetailGroupMap::iterator iter = detail_groups_.begin();
+ iter != detail_groups_.end(); ++iter) {
+ CreateDetailsSection(iter->second.section);
+ view->AddChildView(iter->second.container);
+ }
return view;
}
@@ -616,36 +636,27 @@ void AutofillDialogViews::UpdateDetailsGroupState(const DetailsGroup& group) {
}
bool AutofillDialogViews::ValidateForm() {
- // TODO(estade): work for all sections, not just billing.
bool all_valid = true;
- if (billing_.manual_input->visible()) {
- for (TextfieldMap::iterator iter = billing_.textfields.begin();
- iter != billing_.textfields.end(); ++iter) {
- if (!controller_->InputIsValid(iter->first,
- iter->second->textfield()->text())) {
- iter->second->SetInvalid(true);
- all_valid = false;
+ for (DetailGroupMap::iterator iter = detail_groups_.begin();
+ iter != detail_groups_.end(); ++iter) {
+ DetailsGroup* group = &iter->second;
+ if (group->manual_input->visible()) {
+ for (TextfieldMap::iterator iter = group->textfields.begin();
+ iter != group->textfields.end(); ++iter) {
+ if (!controller_->InputIsValid(iter->first,
+ iter->second->textfield()->text())) {
+ iter->second->SetInvalid(true);
+ all_valid = false;
+ }
}
}
}
return all_valid;
}
-AutofillDialogViews::DetailsGroup* AutofillDialogViews::
- GroupForSection(DialogSection section) {
- switch (section) {
- case SECTION_EMAIL:
- return &email_;
- case SECTION_CC:
- return &cc_;
- case SECTION_BILLING:
- return &billing_;
- case SECTION_SHIPPING:
- return &shipping_;
- }
-
- NOTREACHED();
- return NULL;
+AutofillDialogViews::DetailsGroup* AutofillDialogViews::GroupForSection(
+ DialogSection section) {
+ return &detail_groups_.find(section)->second;
}
AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section)
diff --git a/chrome/browser/ui/views/autofill/autofill_dialog_views.h b/chrome/browser/ui/views/autofill/autofill_dialog_views.h
index dd266f0..75ac9f3 100644
--- a/chrome/browser/ui/views/autofill/autofill_dialog_views.h
+++ b/chrome/browser/ui/views/autofill/autofill_dialog_views.h
@@ -94,8 +94,10 @@ class AutofillDialogViews : public AutofillDialogView,
// Sets whether to indicate the textfield has invalid content.
void SetInvalid(bool invalid);
+ bool invalid() const { return invalid_; }
// views::View implementation.
+ virtual std::string GetClassName() const OVERRIDE;
virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE;
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
@@ -163,6 +165,8 @@ class AutofillDialogViews : public AutofillDialogView,
views::ImageButton* suggested_button;
};
+ typedef std::map<DialogSection, DetailsGroup> DetailGroupMap;
+
void InitChildViews();
// Creates and returns a view that holds all detail sections.
@@ -212,12 +216,8 @@ class AutofillDialogViews : public AutofillDialogView,
// The top-level View for the dialog. Owned by the constrained window.
views::View* contents_;
- DetailsGroup email_;
- // The credit card and billing sections are combined, so cc_.container is
- // not used.
- DetailsGroup cc_;
- DetailsGroup billing_;
- DetailsGroup shipping_;
+ // An array of the DetailGroup structs.
+ DetailGroupMap detail_groups_;
// The checkbox that controls whether to use the billing details for shipping
// as well.