Add a header file for CSS property aliases (and temporarily resurrect the aliases whose DOM properties we forgot to remove). (Bug 730532, patch 1) r=bzbarsky
authorL. David Baron <dbaron@dbaron.org>
Fri, 24 Feb 2012 21:23:14 -0800
changeset 87710 ffc9d929b260b2d3c25d2ac855ea56c3c9de7833
parent 87709 b958923e04baf46fc6ae15bc57e4bc983d1113f4
child 87711 9cbf894da185144eb3e1b8ba144e90784127b764
push id22143
push userphilringnalda@gmail.com
push dateSun, 26 Feb 2012 23:12:35 +0000
treeherdermozilla-central@b98fc24ac54b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs730532
milestone13.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Add a header file for CSS property aliases (and temporarily resurrect the aliases whose DOM properties we forgot to remove). (Bug 730532, patch 1) r=bzbarsky
js/xpconnect/src/nsCSSPropertiesQS.h
layout/style/Makefile.in
layout/style/nsCSSPropAliasList.h
layout/style/nsCSSProps.cpp
layout/style/nsDOMCSSDeclaration.cpp
--- a/js/xpconnect/src/nsCSSPropertiesQS.h
+++ b/js/xpconnect/src/nsCSSPropertiesQS.h
@@ -44,22 +44,19 @@
                  stylestruct_, stylestructoffset_, animtype_)                 \
 static const nsCSSProperty QS_CSS_PROP_##method_ = eCSSProperty_##id_;
 
 #define CSS_PROP_LIST_EXCLUDE_INTERNAL
 #define CSS_PROP_SHORTHAND(name_, id_, method_, flags_) \
   CSS_PROP(name_, id_, method_, flags_, X, X, X, X, X)
 #include "nsCSSPropList.h"
 
-// Aliases
-CSS_PROP(X, opacity, MozOpacity, X, X, X, X, X, X)
-CSS_PROP(X, outline, MozOutline, X, X, X, X, X, X)
-CSS_PROP(X, outline_color, MozOutlineColor, X, X, X, X, X, X)
-CSS_PROP(X, outline_style, MozOutlineStyle, X, X, X, X, X, X)
-CSS_PROP(X, outline_width, MozOutlineWidth, X, X, X, X, X, X)
-CSS_PROP(X, outline_offset, MozOutlineOffset, X, X, X, X, X, X)
+#define CSS_PROP_ALIAS(aliasname_, propid_, aliasmethod_) \
+  CSS_PROP(X, propid_, aliasmethod_, X, X, X, X, X, X)
+#include "nsCSSPropAliasList.h"
+#undef CSS_PROP_ALIAS
 
 #undef CSS_PROP_SHORTHAND
 #undef CSS_PROP_LIST_EXCLUDE_INTERNAL
 #undef CSS_PROP
 #undef CSS_PROP_DOMPROP_PREFIXED
 
 #endif /* nsCSSPropertiesQS_h__ */
--- a/layout/style/Makefile.in
+++ b/layout/style/Makefile.in
@@ -55,16 +55,17 @@ EXPORTS_NAMESPACES = mozilla/css
 
 EXPORTS		= \
 		nsCSSAnonBoxList.h \
 		nsCSSAnonBoxes.h \
 		nsCSSFontDescList.h \
 		nsCSSKeywordList.h \
 		nsCSSKeywords.h \
 		nsCSSParser.h \
+		nsCSSPropAliasList.h \
 		nsCSSPropList.h \
 		nsCSSProperty.h \
 		nsCSSProps.h \
 		nsCSSPseudoClassList.h \
 		nsCSSPseudoClasses.h \
 		nsCSSPseudoElementList.h \
 		nsCSSPseudoElements.h \
 		nsCSSRuleProcessor.h \
new file mode 100644
--- /dev/null
+++ b/layout/style/nsCSSPropAliasList.h
@@ -0,0 +1,71 @@
+/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is nsCSSPropAliasList.h.
+ *
+ * The Initial Developer of the Original Code is the Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2012
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   L. David Baron <dbaron@dbaron.org>, Mozilla Corporation (original author)
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+/*
+ * a list of all CSS property aliases with data about them, for preprocessing
+ */
+
+/******
+
+  This file contains the list of all CSS properties that are just
+  aliases for other properties (e.g., for when we temporarily continue
+  to support a prefixed property after adding support for its unprefixed
+  form).  It is designed to be used as inline input through the magic of
+  C preprocessing.  All entries must be enclosed in the appropriate
+  CSS_PROP_ALIAS macro which will have cruel and unusual things done to
+  it.
+
+  The arguments to CSS_PROP_ALIAS are:
+
+  -. 'aliasname' entries represent a CSS property name and *must* use
+  only lowercase characters.
+
+  -. 'id' should be the same as the 'id' field in nsCSSPropList.h for
+  the property that 'aliasname' is being aliased to.
+
+  -. 'method' is the CSS2Properties property name.  Unlike
+  nsCSSPropList.h, prefixes should just be included in this file (rather
+  than needing the CSS_PROP_DOMPROP_PREFIXED(prop) macro).
+
+ ******/
+
+CSS_PROP_ALIAS(-moz-opacity, opacity, MozOpacity)
+CSS_PROP_ALIAS(-moz-outline, outline, MozOutline)
+CSS_PROP_ALIAS(-moz-outline-color, outline_color, MozOutlineColor)
+CSS_PROP_ALIAS(-moz-outline-style, outline_style, MozOutlineStyle)
+CSS_PROP_ALIAS(-moz-outline-width, outline_width, MozOutlineWidth)
+CSS_PROP_ALIAS(-moz-outline-offset, outline_offset, MozOutlineOffset)
--- a/layout/style/nsCSSProps.cpp
+++ b/layout/style/nsCSSProps.cpp
@@ -311,69 +311,100 @@ nsCSSProps::ReleaseTable(void)
     delete gFontDescTable;
     gFontDescTable = nsnull;
 
     delete [] gShorthandsContainingPool;
     gShorthandsContainingPool = nsnull;
   }
 }
 
-#if 0 /* aliases code */
+// We need eCSSAliasCount so we can make gAliases nonzero size when there
+// are no aliases.
+enum {
+#define CSS_PROP_ALIAS(aliasname_, propid_, aliasmethod_)                     \
+  eCSSAliasCountBefore_##aliasmethod_,
+#include "nsCSSPropAliasList.h"
+#undef CSS_PROP_ALIAS
+
+  eCSSAliasCount
+};
+
+enum {
+  // We want the largest sizeof(#aliasname_).  To find that, we use the
+  // auto-incrementing behavior of C++ enums (a value without an
+  // initializer is one larger than the previous value, or 0 at the
+  // start of the enum), and for each alias we define two values:
+  //   eMaxCSSAliasNameSizeBefore_##aliasmethod_ is the largest
+  //     sizeof(#aliasname_) before that alias.  The first one is
+  //     conveniently zero.
+  //   eMaxCSSAliasNameSizeWith_##aliasmethod_ is **one less than** the
+  //     largest sizeof(#aliasname_) before or including that alias.
+#define CSS_PROP_ALIAS(aliasname_, propid_, aliasmethod_)                     \
+  eMaxCSSAliasNameSizeBefore_##aliasmethod_,                                  \
+  eMaxCSSAliasNameSizeWith_##aliasmethod_ =                                   \
+    PR_MAX(sizeof(#aliasname_), eMaxCSSAliasNameSizeBefore_##aliasmethod_) - 1,
+#include "nsCSSPropAliasList.h"
+#undef CSS_PROP_ALIAS
+
+  eMaxCSSAliasNameSize
+};
+
 struct CSSPropertyAlias {
-  char name[sizeof("-moz-...")];
+  char name[PR_MAX(eMaxCSSAliasNameSize, 1)];
   nsCSSProperty id;
 };
 
-static const CSSPropertyAlias gAliases[] = {
-  // Don't forget to update the sizeof in CSSPropertyAlias above with the
-  // longest string when you add stuff here.
+static const CSSPropertyAlias gAliases[PR_MAX(eCSSAliasCount, 1)] = {
+#define CSS_PROP_ALIAS(aliasname_, propid_, aliasmethod_) \
+  { #aliasname_, eCSSProperty_##propid_ },
+#include "nsCSSPropAliasList.h"
+#undef CSS_PROP_ALIAS
 };
-#endif
 
 nsCSSProperty
 nsCSSProps::LookupProperty(const nsACString& aProperty)
 {
   NS_ABORT_IF_FALSE(gPropertyTable, "no lookup table, needs addref");
 
   nsCSSProperty res = nsCSSProperty(gPropertyTable->Lookup(aProperty));
-#if 0 /* aliases code */
-  if (res == eCSSProperty_UNKNOWN) {
+  // Check eCSSAliasCount against 0 to make it easy for the
+  // compiler to optimize away the 0-aliases case.
+  if (eCSSAliasCount != 0 && res == eCSSProperty_UNKNOWN) {
     for (const CSSPropertyAlias *alias = gAliases,
                             *alias_end = ArrayEnd(gAliases);
          alias < alias_end; ++alias) {
       if (aProperty.LowerCaseEqualsASCII(alias->name)) {
         res = alias->id;
         break;
       }
     }
   }
-#endif
   return res;
 }
 
 nsCSSProperty
 nsCSSProps::LookupProperty(const nsAString& aProperty)
 {
   // This is faster than converting and calling
   // LookupProperty(nsACString&).  The table will do its own
   // converting and avoid a PromiseFlatCString() call.
   NS_ABORT_IF_FALSE(gPropertyTable, "no lookup table, needs addref");
   nsCSSProperty res = nsCSSProperty(gPropertyTable->Lookup(aProperty));
-#if 0 /* aliases code */
-  if (res == eCSSProperty_UNKNOWN) {
+  // Check eCSSAliasCount against 0 to make it easy for the
+  // compiler to optimize away the 0-aliases case.
+  if (eCSSAliasCount != 0 && res == eCSSProperty_UNKNOWN) {
     for (const CSSPropertyAlias *alias = gAliases,
                             *alias_end = ArrayEnd(gAliases);
          alias < alias_end; ++alias) {
       if (aProperty.LowerCaseEqualsASCII(alias->name)) {
         res = alias->id;
         break;
       }
     }
   }
-#endif
   return res;
 }
 
 nsCSSFontDesc
 nsCSSProps::LookupFontDesc(const nsACString& aFontDesc)
 {
   NS_ABORT_IF_FALSE(gFontDescTable, "no lookup table, needs addref");
   return nsCSSFontDesc(gFontDescTable->Lookup(aFontDesc));
--- a/layout/style/nsDOMCSSDeclaration.cpp
+++ b/layout/style/nsDOMCSSDeclaration.cpp
@@ -358,20 +358,17 @@ nsDOMCSSDeclaration::RemoveProperty(cons
     return SetPropertyValue(eCSSProperty_##id_, aValue);                     \
   }
 
 #define CSS_PROP_LIST_EXCLUDE_INTERNAL
 #define CSS_PROP_SHORTHAND(name_, id_, method_, flags_) \
   CSS_PROP(name_, id_, method_, flags_, X, X, X, X, X)
 #include "nsCSSPropList.h"
 
-// Aliases
-CSS_PROP(X, opacity, MozOpacity, X, X, X, X, X, X)
-CSS_PROP(X, outline, MozOutline, X, X, X, X, X, X)
-CSS_PROP(X, outline_color, MozOutlineColor, X, X, X, X, X, X)
-CSS_PROP(X, outline_style, MozOutlineStyle, X, X, X, X, X, X)
-CSS_PROP(X, outline_width, MozOutlineWidth, X, X, X, X, X, X)
-CSS_PROP(X, outline_offset, MozOutlineOffset, X, X, X, X, X, X)
+#define CSS_PROP_ALIAS(aliasname_, propid_, aliasmethod_) \
+  CSS_PROP(X, propid_, aliasmethod_, X, X, X, X, X, X)
+#include "nsCSSPropAliasList.h"
+#undef CSS_PROP_ALIAS
 
 #undef CSS_PROP_SHORTHAND
 #undef CSS_PROP_LIST_EXCLUDE_INTERNAL
 #undef CSS_PROP
 #undef CSS_PROP_DOMPROP_PREFIXED