Bug 1025483 - Use Macro for AutocompleteField* enums. r=smaug
☠☠ backed out by b563ec69fa02 ☠ ☠
authorGiovanni Sferro <agi.novanta@gmail.com>
Sat, 21 Jun 2014 18:30:00 -0400
changeset 190142 83d14fd3d7390a0f212920fb6741c82df2508de2
parent 190141 ee82e0ae5488316baa81e719fc47d94613799074
child 190143 f5cec3f008aa50726cbc76e3bdd586e61c0720a2
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewerssmaug
bugs1025483
milestone33.0a1
Bug 1025483 - Use Macro for AutocompleteField* enums. r=smaug
content/base/src/AutocompleteFieldList.h
content/base/src/moz.build
content/base/src/nsContentUtils.cpp
new file mode 100644
--- /dev/null
+++ b/content/base/src/AutocompleteFieldList.h
@@ -0,0 +1,141 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+ * This file contains the list of field names that are used in @autocomplete
+ * attribute for <input>, <select> and <textarea> controls. It is designed
+ * to be used as inline input through the magic of C preprocessing.
+ *
+ * The first argument to AUTOCOMPLETE_* macro is the identifier for the token
+ * The second argument is the string value of the token
+ */
+
+#ifndef AUTOCOMPLETE_FIELD_NAME
+#define AUTOCOMPLETE_FIELD_NAME(name_, value_)
+#define DEFINED_AUTOCOMPLETE_FIELD_NAME
+#endif
+
+#ifndef AUTOCOMPLETE_CONTACT_FIELD_NAME
+#define AUTOCOMPLETE_CONTACT_FIELD_NAME(name_, value_)
+#define DEFINED_AUTOCOMPLETE_CONTACT_FIELD_NAME
+#endif
+
+#ifndef AUTOCOMPLETE_FIELD_HINT
+#define AUTOCOMPLETE_FIELD_HINT(name_, value_)
+#define DEFINED_AUTOCOMPLETE_FIELD_HINT
+#endif
+
+#ifndef AUTOCOMPLETE_FIELD_CONTACT_HINT
+#define AUTOCOMPLETE_FIELD_CONTACT_HINT(name_, value_)
+#define DEFINED_AUTOCOMPLETE_FIELD_CONTACT_HINT
+#endif
+
+#ifndef AUTOCOMPLETE_CATEGORY
+#define AUTOCOMPLETE_CATEGORY(name_, value_)
+#define DEFINED_AUTOCOMPLETE_CATEGORY
+#endif
+
+AUTOCOMPLETE_FIELD_NAME(OFF, "off")
+AUTOCOMPLETE_FIELD_NAME(ON, "on")
+
+// Name types
+AUTOCOMPLETE_FIELD_NAME(NAME, "name")
+// AUTOCOMPLETE_FIELD_NAME(HONORIFIX_PREFIX, "honorifix-prefix")
+AUTOCOMPLETE_FIELD_NAME(GIVEN_NAME, "given-name")
+AUTOCOMPLETE_FIELD_NAME(ADDITIONAL_NAME, "additional-name")
+AUTOCOMPLETE_FIELD_NAME(FAMILY_NAME, "family-name")
+// AUTOCOMPLETE_FIELD_NAME(HONORIFIX_SUFFIX, "honorifix-suffix")
+// AUTOCOMPLETE_FIELD_NAME(NICKNAME, "nickname")
+// AUTOCOMPLETE_FIELD_NAME(ORGANIZATION_TITLE, "organization-title")
+
+// Login types
+AUTOCOMPLETE_FIELD_NAME(USERNAME, "username")
+AUTOCOMPLETE_FIELD_NAME(NEW_PASSWORD, "new-password")
+AUTOCOMPLETE_FIELD_NAME(CURRENT_PASSWORD, "current-password")
+
+// Address types
+AUTOCOMPLETE_FIELD_NAME(ORGANIZATION, "organization")
+AUTOCOMPLETE_FIELD_NAME(STREET_ADDRESS, "street-address")
+AUTOCOMPLETE_FIELD_NAME(ADDRESS_LINE1, "address-line1")
+AUTOCOMPLETE_FIELD_NAME(ADDRESS_LINE2, "address-line2")
+AUTOCOMPLETE_FIELD_NAME(ADDRESS_LINE3, "address-line3")
+AUTOCOMPLETE_FIELD_NAME(ADDRESS_LEVEL4, "address-level4")
+AUTOCOMPLETE_FIELD_NAME(ADDRESS_LEVEL3, "address-level3")
+AUTOCOMPLETE_FIELD_NAME(ADDRESS_LEVEL2, "address-level2")
+AUTOCOMPLETE_FIELD_NAME(ADDRESS_LEVEL1, "address-level1")
+AUTOCOMPLETE_FIELD_NAME(COUNTRY, "country")
+AUTOCOMPLETE_FIELD_NAME(COUNTRY_NAME, "country-name")
+AUTOCOMPLETE_FIELD_NAME(POSTAL_CODE, "postal-code")
+
+// Credit Card types
+// AUTOCOMPLETE_FIELD_NAME(CC_NAME, "cc-name")
+// AUTOCOMPLETE_FIELD_NAME(CC_GIVEN_NAME, "cc-given-name")
+// AUTOCOMPLETE_FIELD_NAME(CC_ADDITIONAL_NAME, "cc-additional-name")
+// AUTOCOMPLETE_FIELD_NAME(CC_FAMILY_NAME, "cc-family-name")
+// AUTOCOMPLETE_FIELD_NAME(CC_NUMBER, "cc-number")
+// AUTOCOMPLETE_FIELD_NAME(CC_EXP, "cc-exp")
+// AUTOCOMPLETE_FIELD_NAME(CC_EXP_MONTH, "cc-exp-month")
+// AUTOCOMPLETE_FIELD_NAME(CC_EXP_YEAR, "cc-exp-year")
+// AUTOCOMPLETE_FIELD_NAME(CC_CSC, "cc-csc")
+// AUTOCOMPLETE_FIELD_NAME(CC_TYPE, "cc-type")
+
+// Additional field types
+// AUTOCOMPLETE_FIELD_NAME(LANGUAGE, "language")
+// AUTOCOMPLETE_FIELD_NAME(BDAY, "bday")
+// AUTOCOMPLETE_FIELD_NAME(BDAY_DAY, "bday-day")
+// AUTOCOMPLETE_FIELD_NAME(BDAY_MONTH, "bday-month")
+// AUTOCOMPLETE_FIELD_NAME(BDAY_YEAR, "bday-year")
+// AUTOCOMPLETE_FIELD_NAME(SEX, "sex")
+// AUTOCOMPLETE_FIELD_NAME(URL, "url")
+// AUTOCOMPLETE_FIELD_NAME(PHOTO, "photo")
+
+// Contact category types
+AUTOCOMPLETE_CONTACT_FIELD_NAME(TEL, "tel")
+AUTOCOMPLETE_CONTACT_FIELD_NAME(TEL_COUNTRY_CODE, "tel-country-code")
+AUTOCOMPLETE_CONTACT_FIELD_NAME(TEL_NATIONAL, "tel-national")
+AUTOCOMPLETE_CONTACT_FIELD_NAME(TEL_AREA_CODE, "tel-area-code")
+AUTOCOMPLETE_CONTACT_FIELD_NAME(TEL_LOCAL, "tel-local")
+AUTOCOMPLETE_CONTACT_FIELD_NAME(TEL_LOCAL_PREFIX, "tel-local-prefix")
+AUTOCOMPLETE_CONTACT_FIELD_NAME(TEL_LOCAL_SUFFIX, "tel-local-suffix")
+AUTOCOMPLETE_CONTACT_FIELD_NAME(TEL_EXTENSION, "tel-extension")
+AUTOCOMPLETE_CONTACT_FIELD_NAME(EMAIL, "email")
+// AUTOCOMPLETE_CONTACT_FIELD_NAME(IMPP, "impp")
+
+AUTOCOMPLETE_FIELD_HINT(SHIPPING, "shipping")
+AUTOCOMPLETE_FIELD_HINT(BILLING, "billing")
+
+AUTOCOMPLETE_FIELD_CONTACT_HINT(HOME, "home")
+AUTOCOMPLETE_FIELD_CONTACT_HINT(WORK, "work")
+AUTOCOMPLETE_FIELD_CONTACT_HINT(MOBILE, "mobile")
+AUTOCOMPLETE_FIELD_CONTACT_HINT(FAX, "fax")
+// AUTOCOMPLETE_FIELD_CONTACT_HINT(PAGER, "pager")
+
+AUTOCOMPLETE_CATEGORY(NORMAL, "normal")
+AUTOCOMPLETE_CATEGORY(CONTACT, "contact")
+
+#ifdef DEFINED_AUTOCOMPLETE_FIELD_NAME
+#undef AUTOCOMPLETE_FIELD_NAME
+#undef DEFINED_AUTOCOMPLETE_FIELD_NAME
+#endif
+
+#ifdef DEFINED_AUTOCOMPLETE_CONTACT_FIELD_NAME
+#undef AUTOCOMPLETE_CONTACT_FIELD_NAME
+#undef DEFINED_AUTOCOMPLETE_CONTACT_FIELD_NAME
+#endif
+
+#ifdef DEFINED_AUTOCOMPLETE_FIELD_HINT
+#undef AUTOCOMPLETE_FIELD_HINT
+#undef DEFINED_AUTOCOMPLETE_FIELD_HINT
+#endif
+
+#ifdef DEFINED_AUTOCOMPLETE_FIELD_CONTACT_HINT
+#undef AUTOCOMPLETE_FIELD_CONTACT_HINT
+#undef DEFINED_AUTOCOMPLETE_FIELD_CONTACT_HINT
+#endif
+
+#ifdef DEFINED_AUTOCOMPLETE_CATEGORY
+#undef AUTOCOMPLETE_CATEGORY
+#undef DEFINED_AUTOCOMPLETE_CATEGORY
+#endif
--- a/content/base/src/moz.build
+++ b/content/base/src/moz.build
@@ -1,15 +1,16 @@
 # -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 EXPORTS += [
+    'AutocompleteFieldList.h',
     'mozAutoDocUpdate.h',
     'nsAtomListUtils.h',
     'nsAttrAndChildArray.h',
     'nsAttrName.h',
     'nsAttrValue.h',
     'nsAttrValueInlines.h',
     'nsContentList.h',
     'nsContentListDeclarations.h',
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -248,165 +248,77 @@ bool nsContentUtils::sFragmentParsingAct
 
 #if !(defined(DEBUG) || defined(MOZ_ENABLE_JS_DUMP))
 bool nsContentUtils::sDOMWindowDumpEnabled;
 #endif
 
 // Subset of http://www.whatwg.org/specs/web-apps/current-work/#autofill-field-name
 enum AutocompleteFieldName
 {
-  eAutocompleteFieldName_OFF,
-  eAutocompleteFieldName_ON,
-
-  // Name types
-  eAutocompleteFieldName_NAME,
-  //eAutocompleteFieldName_HONORIFIC_PREFIX,
-  eAutocompleteFieldName_GIVEN_NAME,
-  eAutocompleteFieldName_ADDITIONAL_NAME,
-  eAutocompleteFieldName_FAMILY_NAME,
-  //eAutocompleteFieldName_HONORIFIC_SUFFIX,
-  //eAutocompleteFieldName_NICKNAME,
-  //eAutocompleteFieldName_ORGANIZATION_TITLE,
-
-  // Login types
-  eAutocompleteFieldName_USERNAME,
-  eAutocompleteFieldName_NEW_PASSWORD,
-  eAutocompleteFieldName_CURRENT_PASSWORD,
-
-  // Address types
-  eAutocompleteFieldName_ORGANIZATION,
-  eAutocompleteFieldName_STREET_ADDRESS,
-  eAutocompleteFieldName_ADDRESS_LINE1,
-  eAutocompleteFieldName_ADDRESS_LINE2,
-  eAutocompleteFieldName_ADDRESS_LINE3,
-  eAutocompleteFieldName_ADDRESS_LEVEL4,
-  eAutocompleteFieldName_ADDRESS_LEVEL3,
-  eAutocompleteFieldName_ADDRESS_LEVEL2,
-  eAutocompleteFieldName_ADDRESS_LEVEL1,
-  eAutocompleteFieldName_COUNTRY,
-  eAutocompleteFieldName_COUNTRY_NAME,
-  eAutocompleteFieldName_POSTAL_CODE,
-
-  // Credit card types
-  /*
-  eAutocompleteFieldName_CC_NAME,
-  eAutocompleteFieldName_CC_GIVEN_NAME,
-  eAutocompleteFieldName_CC_ADDITIONAL_NAME,
-  eAutocompleteFieldName_CC_FAMILY_NAME,
-  eAutocompleteFieldName_CC_NUMBER,
-  eAutocompleteFieldName_CC_EXP,
-  eAutocompleteFieldName_CC_EXP_MONTH,
-  eAutocompleteFieldName_CC_EXP_YEAR,
-  eAutocompleteFieldName_CC_CSC,
-  eAutocompleteFieldName_CC_TYPE
-  */
-
-  // Additional field types
-  /*
-  eAutocompleteFieldName_LANGUAGE,
-  eAutocompleteFieldName_BDAY,
-  eAutocompleteFieldName_BDAY_DAY,
-  eAutocompleteFieldName_BDAY_MONTH,
-  eAutocompleteFieldName_BDAY_YEAR,
-  eAutocompleteFieldName_SEX,
-  eAutocompleteFieldName_URL,
-  eAutocompleteFieldName_PHOTO,
-  */
-
-  // Contact category types
-  eAutocompleteFieldName_TEL,
-  eAutocompleteFieldName_TEL_COUNTRY_CODE,
-  eAutocompleteFieldName_TEL_NATIONAL,
-  eAutocompleteFieldName_TEL_AREA_CODE,
-  eAutocompleteFieldName_TEL_LOCAL,
-  eAutocompleteFieldName_TEL_LOCAL_PREFIX,
-  eAutocompleteFieldName_TEL_LOCAL_SUFFIX,
-  eAutocompleteFieldName_TEL_EXTENSION,
-  eAutocompleteFieldName_EMAIL,
-  //eAutocompleteFieldName_IMPP,
-
-  eAutocompleteFieldName_last, // Dummy to check table sizes
+  #define AUTOCOMPLETE_FIELD_NAME(name_, value_) \
+    eAutocompleteFieldName_##name_,
+  #define AUTOCOMPLETE_CONTACT_FIELD_NAME(name_, value_) \
+    AUTOCOMPLETE_FIELD_NAME(name_, value_)
+  #include "AutocompleteFieldList.h"
+  #undef AUTOCOMPLETE_FIELD_NAME
+  #undef AUTOCOMPLETE_CONTACT_FIELD_NAME
 };
 
 enum AutocompleteFieldHint
 {
-  eAutocompleteFieldHint_SHIPPING,
-  eAutocompleteFieldHint_BILLING,
-  eAutocompleteFieldHint_last, // Dummy to check table sizes
+  #define AUTOCOMPLETE_FIELD_HINT(name_, value_) \
+    eAutocompleteFieldHint_##name_,
+  #include "AutocompleteFieldList.h"
+  #undef AUTOCOMPLETE_FIELD_HINT
 };
 
 enum AutocompleteFieldContactHint
 {
-  eAutocompleteFieldContactHint_HOME,
-  eAutocompleteFieldContactHint_WORK,
-  eAutocompleteFieldContactHint_MOBILE,
-  eAutocompleteFieldContactHint_FAX,
-  //eAutocompleteFieldContactHint_PAGER,
-  eAutocompleteFieldContactHint_last, // Dummy to check table sizes
+  #define AUTOCOMPLETE_FIELD_CONTACT_HINT(name_, value_) \
+    eAutocompleteFieldContactHint_##name_,
+  #include "AutocompleteFieldList.h"
+  #undef AUTOCOMPLETE_FIELD_CONTACT_HINT
 };
 
 enum AutocompleteCategory
 {
-  eAutocompleteCategory_NORMAL,
-  eAutocompleteCategory_CONTACT,
+  #define AUTOCOMPLETE_CATEGORY(name_, value_) eAutocompleteCategory_##name_,
+  #include "AutocompleteFieldList.h"
+  #undef AUTOCOMPLETE_CATEGORY
 };
 
 static const nsAttrValue::EnumTable kAutocompleteFieldNameTable[] = {
-  { "off", eAutocompleteFieldName_OFF },
-  { "on", eAutocompleteFieldName_ON },
-
-  { "name", eAutocompleteFieldName_NAME },
-  { "given-name", eAutocompleteFieldName_GIVEN_NAME },
-  { "additional-name", eAutocompleteFieldName_ADDITIONAL_NAME },
-  { "family-name", eAutocompleteFieldName_FAMILY_NAME },
-
-  { "username", eAutocompleteFieldName_USERNAME },
-  { "new-password", eAutocompleteFieldName_NEW_PASSWORD },
-  { "current-password", eAutocompleteFieldName_CURRENT_PASSWORD },
-
-  { "organization", eAutocompleteFieldName_ORGANIZATION },
-  { "street-address", eAutocompleteFieldName_STREET_ADDRESS },
-  { "address-line1", eAutocompleteFieldName_ADDRESS_LINE1 },
-  { "address-line2", eAutocompleteFieldName_ADDRESS_LINE2 },
-  { "address-line3", eAutocompleteFieldName_ADDRESS_LINE3 },
-  { "address-level4", eAutocompleteFieldName_ADDRESS_LEVEL4 },
-  { "address-level3", eAutocompleteFieldName_ADDRESS_LEVEL3 },
-  { "address-level2", eAutocompleteFieldName_ADDRESS_LEVEL2 },
-  { "address-level1", eAutocompleteFieldName_ADDRESS_LEVEL1 },
-  { "country", eAutocompleteFieldName_COUNTRY },
-  { "country-name", eAutocompleteFieldName_COUNTRY_NAME },
-  { "postal-code", eAutocompleteFieldName_POSTAL_CODE },
+  #define AUTOCOMPLETE_FIELD_NAME(name_, value_) \
+    { value_, eAutocompleteFieldName_##name_ },
+  #include "AutocompleteFieldList.h"
+  #undef AUTOCOMPLETE_FIELD_NAME
   { 0 }
 };
 
 static const nsAttrValue::EnumTable kAutocompleteContactFieldNameTable[] = {
-  { "tel", eAutocompleteFieldName_TEL },
-  { "tel-country-code", eAutocompleteFieldName_TEL_COUNTRY_CODE },
-  { "tel-national", eAutocompleteFieldName_TEL_NATIONAL },
-  { "tel-area-code", eAutocompleteFieldName_TEL_AREA_CODE },
-  { "tel-local", eAutocompleteFieldName_TEL_LOCAL },
-  { "tel-local-prefix", eAutocompleteFieldName_TEL_LOCAL_PREFIX },
-  { "tel-local-suffix", eAutocompleteFieldName_TEL_LOCAL_SUFFIX },
-  { "tel-extension", eAutocompleteFieldName_TEL_EXTENSION },
-
-  { "email", eAutocompleteFieldName_EMAIL },
+  #define AUTOCOMPLETE_CONTACT_FIELD_NAME(name_, value_) \
+    { value_, eAutocompleteFieldName_##name_ },
+  #include "AutocompleteFieldList.h"
+  #undef AUTOCOMPLETE_CONTACT_FIELD_NAME
   { 0 }
 };
 
 static const nsAttrValue::EnumTable kAutocompleteFieldHintTable[] = {
-  { "shipping", eAutocompleteFieldHint_SHIPPING },
-  { "billing", eAutocompleteFieldHint_BILLING },
+  #define AUTOCOMPLETE_FIELD_HINT(name_, value_) \
+    { value_, eAutocompleteFieldHint_##name_ },
+  #include "AutocompleteFieldList.h"
+  #undef AUTOCOMPLETE_FIELD_HINT
   { 0 }
 };
 
 static const nsAttrValue::EnumTable kAutocompleteContactFieldHintTable[] = {
-  { "home", eAutocompleteFieldContactHint_HOME },
-  { "work", eAutocompleteFieldContactHint_WORK },
-  { "mobile", eAutocompleteFieldContactHint_MOBILE },
-  { "fax", eAutocompleteFieldContactHint_FAX },
+  #define AUTOCOMPLETE_FIELD_CONTACT_HINT(name_, value_) \
+    { value_, eAutocompleteFieldContactHint_##name_ },
+  #include "AutocompleteFieldList.h"
+  #undef AUTOCOMPLETE_FIELD_CONTACT_HINT
   { 0 }
 };
 
 namespace {
 
 static NS_DEFINE_CID(kParserServiceCID, NS_PARSERSERVICE_CID);
 static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID);
 
@@ -519,22 +431,16 @@ nsresult
 nsContentUtils::Init()
 {
   if (sInitialized) {
     NS_WARNING("Init() called twice");
 
     return NS_OK;
   }
 
-  // Check that all the entries in the autocomplete enums are handled in EnumTables
-  MOZ_ASSERT(eAutocompleteFieldName_last == ArrayLength(kAutocompleteFieldNameTable)
-             + ArrayLength(kAutocompleteContactFieldNameTable) - 2);
-  MOZ_ASSERT(eAutocompleteFieldHint_last == ArrayLength(kAutocompleteFieldHintTable) - 1);
-  MOZ_ASSERT(eAutocompleteFieldContactHint_last == ArrayLength(kAutocompleteContactFieldHintTable) - 1);
-
   sNameSpaceManager = nsNameSpaceManager::GetInstance();
   NS_ENSURE_TRUE(sNameSpaceManager, NS_ERROR_OUT_OF_MEMORY);
 
   sXPConnect = nsXPConnect::XPConnect();
 
   sSecurityManager = nsScriptSecurityManager::GetScriptSecurityManager();
   if(!sSecurityManager)
     return NS_ERROR_FAILURE;