Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6081)

Unified Diff: chrome/browser/ui/autofill/autofill_dialog_utils.cc

Issue 21124012: [WIP] Split AutofillDialogControllerImpl + integrate rAc on Android. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/autofill/autofill_dialog_utils.cc
diff --git a/chrome/browser/ui/autofill/autofill_dialog_utils.cc b/chrome/browser/ui/autofill/autofill_dialog_utils.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9e94449cfae49141e0783b88560b0ef13cdb8c71
--- /dev/null
+++ b/chrome/browser/ui/autofill/autofill_dialog_utils.cc
@@ -0,0 +1,149 @@
+// Copyright 2013 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/autofill/autofill_dialog_utils.h"
+
+#include "components/autofill/core/browser/autofill_field.h"
+#include "components/autofill/core/browser/autofill_type.h"
+#include "grit/chromium_strings.h"
+#include "grit/component_strings.h"
+#include "grit/generated_resources.h"
+#include "grit/theme_resources.h"
+#include "grit/webkit_resources.h"
+
+namespace autofill {
+
+namespace utils {
+
+const DetailInput kEmailInputs[] = {
Evan Stade 2013/08/01 19:44:52 I think it's better not to statically initialize a
aruslan 2013/08/07 23:17:03 Done.
+ { 1, EMAIL_ADDRESS, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL },
+};
+
+const DetailInput kCCInputs[] = {
+ { 2, CREDIT_CARD_NUMBER, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARD_NUMBER },
+ { 3, CREDIT_CARD_EXP_MONTH },
+ { 3, CREDIT_CARD_EXP_4_DIGIT_YEAR },
+ { 3, CREDIT_CARD_VERIFICATION_CODE, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC,
+ 1.5 },
+};
+
+const DetailInput kBillingInputs[] = {
+ { 4, NAME_FULL, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARDHOLDER_NAME },
+ { 5, ADDRESS_BILLING_LINE1,
+ IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1 },
+ { 6, ADDRESS_BILLING_LINE2,
+ IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2 },
+ { 7, ADDRESS_BILLING_CITY,
+ IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY },
+ // TODO(estade): state placeholder should depend on locale.
+ { 8, ADDRESS_BILLING_STATE, IDS_AUTOFILL_FIELD_LABEL_STATE },
+ { 8, ADDRESS_BILLING_ZIP,
+ IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE },
+ // We don't allow the user to change the country: http://crbug.com/247518
+ { -1, ADDRESS_BILLING_COUNTRY, 0 },
+ { 10, PHONE_BILLING_WHOLE_NUMBER,
+ IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER },
+};
+
+const DetailInput kShippingInputs[] = {
+ { 11, NAME_FULL, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESSEE_NAME },
+ { 12, ADDRESS_HOME_LINE1, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1 },
+ { 13, ADDRESS_HOME_LINE2, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2 },
+ { 14, ADDRESS_HOME_CITY, IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY },
+ { 15, ADDRESS_HOME_STATE, IDS_AUTOFILL_FIELD_LABEL_STATE },
+ { 15, ADDRESS_HOME_ZIP, IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE },
+ { -1, ADDRESS_HOME_COUNTRY, 0 },
+ { 17, PHONE_HOME_WHOLE_NUMBER,
+ IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER },
+};
+
+// Returns true if |input| should be shown when |field_type| has been requested.
+bool InputTypeMatchesFieldType(const DetailInput& input,
+ AutofillFieldType field_type) {
+ // If any credit card expiration info is asked for, show both month and year
+ // inputs.
+ if (field_type == CREDIT_CARD_EXP_4_DIGIT_YEAR ||
+ field_type == CREDIT_CARD_EXP_2_DIGIT_YEAR ||
+ field_type == CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR ||
+ field_type == CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR ||
+ field_type == CREDIT_CARD_EXP_MONTH) {
+ return input.type == CREDIT_CARD_EXP_4_DIGIT_YEAR ||
+ input.type == CREDIT_CARD_EXP_MONTH;
+ }
+
+ if (field_type == CREDIT_CARD_TYPE)
+ return input.type == CREDIT_CARD_NUMBER;
+
+ return input.type == field_type;
+}
+
+// Returns true if |input| in the given |section| should be used for a
+// site-requested |field|.
+bool DetailInputMatchesField(DialogSection section,
+ const DetailInput& input,
+ const AutofillField& field) {
+ // The credit card name is filled from the billing section's data.
+ if (field.type() == CREDIT_CARD_NAME &&
+ (section == SECTION_BILLING || section == SECTION_CC_BILLING)) {
+ return input.type == NAME_FULL;
+ }
+
+ return InputTypeMatchesFieldType(input, field.type());
+}
+
+bool IsCreditCardType(AutofillFieldType type) {
+ return AutofillType(type).group() == AutofillType::CREDIT_CARD;
+}
+
+// Constructs |inputs| from template data.
+void BuildInputs(const DetailInput* input_template,
+ size_t template_size,
+ DetailInputs* inputs) {
+ for (size_t i = 0; i < template_size; ++i) {
+ const DetailInput* input = &input_template[i];
+ inputs->push_back(*input);
+ }
+}
+
+// Constructs |inputs| from template data for a given |dialog_section|.
+void BuildInputsForSection(DialogSection dialog_section,
+ DetailInputs* inputs) {
+ switch (dialog_section) {
+ case SECTION_EMAIL:
+ BuildInputs(kEmailInputs,
+ arraysize(kEmailInputs),
+ inputs);
+ break;
+
+ case SECTION_CC:
+ BuildInputs(kCCInputs,
+ arraysize(kCCInputs),
+ inputs);
+ break;
+
+ case SECTION_BILLING:
+ BuildInputs(kBillingInputs,
+ arraysize(kBillingInputs),
+ inputs);
+ break;
+
+ case SECTION_CC_BILLING:
+ BuildInputs(kCCInputs,
+ arraysize(kCCInputs),
+ inputs);
+ BuildInputs(kBillingInputs,
+ arraysize(kBillingInputs),
+ inputs);
+ break;
+
+ case SECTION_SHIPPING:
+ BuildInputs(kShippingInputs,
+ arraysize(kShippingInputs),
+ inputs);
+ break;
+ }
+}
+
+} // namespace utils
+} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698