layout/style/test/ListCSSProperties.cpp

Wed, 31 Dec 2014 07:16:47 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:16:47 +0100
branch
TOR_BUG_9701
changeset 3
141e0f1194b1
permissions
-rw-r--r--

Revert simplistic fix pending revisit of Mozilla integration attempt.

     1 /* vim: set shiftwidth=4 tabstop=8 autoindent cindent expandtab: */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 /* build (from code) lists of all supported CSS properties */
     8 #include <stdio.h>
     9 #include <string.h>
    10 #include <stdlib.h>
    12 struct PropertyInfo {
    13     const char *propName;
    14     const char *domName;
    15     const char *pref;
    16 };
    18 const PropertyInfo gLonghandProperties[] = {
    20 #define CSS_PROP_PUBLIC_OR_PRIVATE(publicname_, privatename_) publicname_
    21 #define CSS_PROP(name_, id_, method_, flags_, pref_, parsevariant_, kwtable_, \
    22                  stylestruct_, stylestructoffset_, animtype_)                 \
    23     { #name_, #method_, pref_ },
    25 #include "nsCSSPropList.h"
    27 #undef CSS_PROP
    28 #undef CSS_PROP_PUBLIC_OR_PRIVATE
    30 };
    32 /*
    33  * These are the properties for which domName in the above list should
    34  * be used.  They're in the same order as the above list, with some
    35  * items skipped.
    36  */
    37 const char* gLonghandPropertiesWithDOMProp[] = {
    39 #define CSS_PROP_LIST_EXCLUDE_INTERNAL
    40 #define CSS_PROP(name_, id_, method_, flags_, pref_, parsevariant_, kwtable_, \
    41                  stylestruct_, stylestructoffset_, animtype_)                 \
    42     #name_,
    44 #include "nsCSSPropList.h"
    46 #undef CSS_PROP
    47 #undef CSS_PROP_LIST_EXCLUDE_INTERNAL
    49 };
    51 const PropertyInfo gShorthandProperties[] = {
    53 #define CSS_PROP_PUBLIC_OR_PRIVATE(publicname_, privatename_) publicname_
    54 // Need an extra level of macro nesting to force expansion of method_
    55 // params before they get pasted.
    56 #define LISTCSSPROPERTIES_INNER_MACRO(method_) #method_
    57 #define CSS_PROP_SHORTHAND(name_, id_, method_, flags_, pref_)	\
    58     { #name_, LISTCSSPROPERTIES_INNER_MACRO(method_), pref_ },
    60 #include "nsCSSPropList.h"
    62 #undef CSS_PROP_SHORTHAND
    63 #undef LISTCSSPROPERTIES_INNER_MACRO
    64 #undef CSS_PROP_PUBLIC_OR_PRIVATE
    66 #define CSS_PROP_ALIAS(name_, id_, method_, pref_) \
    67     { #name_, #method_, pref_ },
    69 #include "nsCSSPropAliasList.h"
    71 #undef CSS_PROP_ALIAS
    73 };
    75 /* see gLonghandPropertiesWithDOMProp */
    76 const char* gShorthandPropertiesWithDOMProp[] = {
    78 #define CSS_PROP_LIST_EXCLUDE_INTERNAL
    79 #define CSS_PROP_SHORTHAND(name_, id_, method_, flags_, pref_)	\
    80     #name_,
    82 #include "nsCSSPropList.h"
    84 #undef CSS_PROP_SHORTHAND
    85 #undef CSS_PROP_LIST_EXCLUDE_INTERNAL
    87 #define CSS_PROP_ALIAS(name_, id_, method_, pref_) \
    88     #name_,
    90 #include "nsCSSPropAliasList.h"
    92 #undef CSS_PROP_ALIAS
    94 };
    97 #define ARRAY_LENGTH(a_) (sizeof(a_)/sizeof((a_)[0]))
    99 const char *gInaccessibleProperties[] = {
   100     // Don't print the properties that aren't accepted by the parser, per
   101     // CSSParserImpl::ParseProperty
   102     "-x-cols",
   103     "-x-lang",
   104     "-x-span",
   105     "-x-system-font",
   106     "-x-text-zoom",
   107     "border-end-color-value",
   108     "border-end-style-value",
   109     "border-end-width-value",
   110     "border-left-color-value",
   111     "border-left-color-ltr-source",
   112     "border-left-color-rtl-source",
   113     "border-left-style-value",
   114     "border-left-style-ltr-source",
   115     "border-left-style-rtl-source",
   116     "border-left-width-value",
   117     "border-left-width-ltr-source",
   118     "border-left-width-rtl-source",
   119     "border-right-color-value",
   120     "border-right-color-ltr-source",
   121     "border-right-color-rtl-source",
   122     "border-right-style-value",
   123     "border-right-style-ltr-source",
   124     "border-right-style-rtl-source",
   125     "border-right-width-value",
   126     "border-right-width-ltr-source",
   127     "border-right-width-rtl-source",
   128     "border-start-color-value",
   129     "border-start-style-value",
   130     "border-start-width-value",
   131     "margin-end-value",
   132     "margin-left-value",
   133     "margin-right-value",
   134     "margin-start-value",
   135     "margin-left-ltr-source",
   136     "margin-left-rtl-source",
   137     "margin-right-ltr-source",
   138     "margin-right-rtl-source",
   139     "padding-end-value",
   140     "padding-left-value",
   141     "padding-right-value",
   142     "padding-start-value",
   143     "padding-left-ltr-source",
   144     "padding-left-rtl-source",
   145     "padding-right-ltr-source",
   146     "padding-right-rtl-source",
   147     "-moz-control-character-visibility",
   148     "-moz-script-level", // parsed by UA sheets only
   149     "-moz-script-size-multiplier",
   150     "-moz-script-min-size",
   151     "-moz-math-variant",
   152     "-moz-math-display" // parsed by UA sheets only
   153 };
   155 inline int
   156 is_inaccessible(const char* aPropName)
   157 {
   158     for (unsigned j = 0; j < ARRAY_LENGTH(gInaccessibleProperties); ++j) {
   159         if (strcmp(aPropName, gInaccessibleProperties[j]) == 0)
   160             return 1;
   161     }
   162     return 0;
   163 }
   165 void
   166 print_array(const char *aName,
   167             const PropertyInfo *aProps, unsigned aPropsLength,
   168             const char * const * aDOMProps, unsigned aDOMPropsLength)
   169 {
   170     printf("var %s = [\n", aName);
   172     int first = 1;
   173     unsigned j = 0; // index into DOM prop list
   174     for (unsigned i = 0; i < aPropsLength; ++i) {
   175         const PropertyInfo *p = aProps + i;
   177         if (is_inaccessible(p->propName))
   178             // inaccessible properties never have DOM props, so don't
   179             // worry about incrementing j.  The assertion below will
   180             // catch if they do.
   181             continue;
   183         if (first)
   184             first = 0;
   185         else
   186             printf(",\n");
   188         printf("\t{ name: \"%s\", prop: ", p->propName);
   189         if (j >= aDOMPropsLength || strcmp(p->propName, aDOMProps[j]) != 0)
   190             printf("null");
   191         else {
   192             ++j;
   193             if (strncmp(p->domName, "Moz", 3) == 0)
   194                 printf("\"%s\"", p->domName);
   195             else
   196                 // lowercase the first letter
   197                 printf("\"%c%s\"", p->domName[0] + 32, p->domName + 1);
   198         }
   199         if (p->pref[0]) {
   200             printf(", pref: \"%s\"", p->pref);
   201         }
   202         printf(" }");
   203     }
   205     if (j != aDOMPropsLength) {
   206         fprintf(stderr, "Assertion failure %s:%d\n", __FILE__, __LINE__);
   207         fprintf(stderr, "j==%d, aDOMPropsLength == %d\n", j, aDOMPropsLength);
   208         exit(1);
   209     }
   211     printf("\n];\n\n");
   212 }
   214 int
   215 main()
   216 {
   217     print_array("gLonghandProperties",
   218                 gLonghandProperties,
   219                 ARRAY_LENGTH(gLonghandProperties),
   220                 gLonghandPropertiesWithDOMProp,
   221                 ARRAY_LENGTH(gLonghandPropertiesWithDOMProp));
   222     print_array("gShorthandProperties",
   223                 gShorthandProperties,
   224                 ARRAY_LENGTH(gShorthandProperties),
   225                 gShorthandPropertiesWithDOMProp,
   226                 ARRAY_LENGTH(gShorthandPropertiesWithDOMProp));
   227     return 0;
   228 }

mercurial