layout/style/test/ListCSSProperties.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/style/test/ListCSSProperties.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,228 @@
     1.4 +/* vim: set shiftwidth=4 tabstop=8 autoindent cindent expandtab: */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/* build (from code) lists of all supported CSS properties */
    1.10 +
    1.11 +#include <stdio.h>
    1.12 +#include <string.h>
    1.13 +#include <stdlib.h>
    1.14 +
    1.15 +struct PropertyInfo {
    1.16 +    const char *propName;
    1.17 +    const char *domName;
    1.18 +    const char *pref;
    1.19 +};
    1.20 +
    1.21 +const PropertyInfo gLonghandProperties[] = {
    1.22 +
    1.23 +#define CSS_PROP_PUBLIC_OR_PRIVATE(publicname_, privatename_) publicname_
    1.24 +#define CSS_PROP(name_, id_, method_, flags_, pref_, parsevariant_, kwtable_, \
    1.25 +                 stylestruct_, stylestructoffset_, animtype_)                 \
    1.26 +    { #name_, #method_, pref_ },
    1.27 +
    1.28 +#include "nsCSSPropList.h"
    1.29 +
    1.30 +#undef CSS_PROP
    1.31 +#undef CSS_PROP_PUBLIC_OR_PRIVATE
    1.32 +
    1.33 +};
    1.34 +
    1.35 +/*
    1.36 + * These are the properties for which domName in the above list should
    1.37 + * be used.  They're in the same order as the above list, with some
    1.38 + * items skipped.
    1.39 + */
    1.40 +const char* gLonghandPropertiesWithDOMProp[] = {
    1.41 +
    1.42 +#define CSS_PROP_LIST_EXCLUDE_INTERNAL
    1.43 +#define CSS_PROP(name_, id_, method_, flags_, pref_, parsevariant_, kwtable_, \
    1.44 +                 stylestruct_, stylestructoffset_, animtype_)                 \
    1.45 +    #name_,
    1.46 +
    1.47 +#include "nsCSSPropList.h"
    1.48 +
    1.49 +#undef CSS_PROP
    1.50 +#undef CSS_PROP_LIST_EXCLUDE_INTERNAL
    1.51 +
    1.52 +};
    1.53 +
    1.54 +const PropertyInfo gShorthandProperties[] = {
    1.55 +
    1.56 +#define CSS_PROP_PUBLIC_OR_PRIVATE(publicname_, privatename_) publicname_
    1.57 +// Need an extra level of macro nesting to force expansion of method_
    1.58 +// params before they get pasted.
    1.59 +#define LISTCSSPROPERTIES_INNER_MACRO(method_) #method_
    1.60 +#define CSS_PROP_SHORTHAND(name_, id_, method_, flags_, pref_)	\
    1.61 +    { #name_, LISTCSSPROPERTIES_INNER_MACRO(method_), pref_ },
    1.62 +
    1.63 +#include "nsCSSPropList.h"
    1.64 +
    1.65 +#undef CSS_PROP_SHORTHAND
    1.66 +#undef LISTCSSPROPERTIES_INNER_MACRO
    1.67 +#undef CSS_PROP_PUBLIC_OR_PRIVATE
    1.68 +
    1.69 +#define CSS_PROP_ALIAS(name_, id_, method_, pref_) \
    1.70 +    { #name_, #method_, pref_ },
    1.71 +
    1.72 +#include "nsCSSPropAliasList.h"
    1.73 +
    1.74 +#undef CSS_PROP_ALIAS
    1.75 +
    1.76 +};
    1.77 +
    1.78 +/* see gLonghandPropertiesWithDOMProp */
    1.79 +const char* gShorthandPropertiesWithDOMProp[] = {
    1.80 +
    1.81 +#define CSS_PROP_LIST_EXCLUDE_INTERNAL
    1.82 +#define CSS_PROP_SHORTHAND(name_, id_, method_, flags_, pref_)	\
    1.83 +    #name_,
    1.84 +
    1.85 +#include "nsCSSPropList.h"
    1.86 +
    1.87 +#undef CSS_PROP_SHORTHAND
    1.88 +#undef CSS_PROP_LIST_EXCLUDE_INTERNAL
    1.89 +
    1.90 +#define CSS_PROP_ALIAS(name_, id_, method_, pref_) \
    1.91 +    #name_,
    1.92 +
    1.93 +#include "nsCSSPropAliasList.h"
    1.94 +
    1.95 +#undef CSS_PROP_ALIAS
    1.96 +
    1.97 +};
    1.98 +
    1.99 +
   1.100 +#define ARRAY_LENGTH(a_) (sizeof(a_)/sizeof((a_)[0]))
   1.101 +
   1.102 +const char *gInaccessibleProperties[] = {
   1.103 +    // Don't print the properties that aren't accepted by the parser, per
   1.104 +    // CSSParserImpl::ParseProperty
   1.105 +    "-x-cols",
   1.106 +    "-x-lang",
   1.107 +    "-x-span",
   1.108 +    "-x-system-font",
   1.109 +    "-x-text-zoom",
   1.110 +    "border-end-color-value",
   1.111 +    "border-end-style-value",
   1.112 +    "border-end-width-value",
   1.113 +    "border-left-color-value",
   1.114 +    "border-left-color-ltr-source",
   1.115 +    "border-left-color-rtl-source",
   1.116 +    "border-left-style-value",
   1.117 +    "border-left-style-ltr-source",
   1.118 +    "border-left-style-rtl-source",
   1.119 +    "border-left-width-value",
   1.120 +    "border-left-width-ltr-source",
   1.121 +    "border-left-width-rtl-source",
   1.122 +    "border-right-color-value",
   1.123 +    "border-right-color-ltr-source",
   1.124 +    "border-right-color-rtl-source",
   1.125 +    "border-right-style-value",
   1.126 +    "border-right-style-ltr-source",
   1.127 +    "border-right-style-rtl-source",
   1.128 +    "border-right-width-value",
   1.129 +    "border-right-width-ltr-source",
   1.130 +    "border-right-width-rtl-source",
   1.131 +    "border-start-color-value",
   1.132 +    "border-start-style-value",
   1.133 +    "border-start-width-value",
   1.134 +    "margin-end-value",
   1.135 +    "margin-left-value",
   1.136 +    "margin-right-value",
   1.137 +    "margin-start-value",
   1.138 +    "margin-left-ltr-source",
   1.139 +    "margin-left-rtl-source",
   1.140 +    "margin-right-ltr-source",
   1.141 +    "margin-right-rtl-source",
   1.142 +    "padding-end-value",
   1.143 +    "padding-left-value",
   1.144 +    "padding-right-value",
   1.145 +    "padding-start-value",
   1.146 +    "padding-left-ltr-source",
   1.147 +    "padding-left-rtl-source",
   1.148 +    "padding-right-ltr-source",
   1.149 +    "padding-right-rtl-source",
   1.150 +    "-moz-control-character-visibility",
   1.151 +    "-moz-script-level", // parsed by UA sheets only
   1.152 +    "-moz-script-size-multiplier",
   1.153 +    "-moz-script-min-size",
   1.154 +    "-moz-math-variant",
   1.155 +    "-moz-math-display" // parsed by UA sheets only
   1.156 +};
   1.157 +
   1.158 +inline int
   1.159 +is_inaccessible(const char* aPropName)
   1.160 +{
   1.161 +    for (unsigned j = 0; j < ARRAY_LENGTH(gInaccessibleProperties); ++j) {
   1.162 +        if (strcmp(aPropName, gInaccessibleProperties[j]) == 0)
   1.163 +            return 1;
   1.164 +    }
   1.165 +    return 0;
   1.166 +}
   1.167 +
   1.168 +void
   1.169 +print_array(const char *aName,
   1.170 +            const PropertyInfo *aProps, unsigned aPropsLength,
   1.171 +            const char * const * aDOMProps, unsigned aDOMPropsLength)
   1.172 +{
   1.173 +    printf("var %s = [\n", aName);
   1.174 +
   1.175 +    int first = 1;
   1.176 +    unsigned j = 0; // index into DOM prop list
   1.177 +    for (unsigned i = 0; i < aPropsLength; ++i) {
   1.178 +        const PropertyInfo *p = aProps + i;
   1.179 +
   1.180 +        if (is_inaccessible(p->propName))
   1.181 +            // inaccessible properties never have DOM props, so don't
   1.182 +            // worry about incrementing j.  The assertion below will
   1.183 +            // catch if they do.
   1.184 +            continue;
   1.185 +
   1.186 +        if (first)
   1.187 +            first = 0;
   1.188 +        else
   1.189 +            printf(",\n");
   1.190 +
   1.191 +        printf("\t{ name: \"%s\", prop: ", p->propName);
   1.192 +        if (j >= aDOMPropsLength || strcmp(p->propName, aDOMProps[j]) != 0)
   1.193 +            printf("null");
   1.194 +        else {
   1.195 +            ++j;
   1.196 +            if (strncmp(p->domName, "Moz", 3) == 0)
   1.197 +                printf("\"%s\"", p->domName);
   1.198 +            else
   1.199 +                // lowercase the first letter
   1.200 +                printf("\"%c%s\"", p->domName[0] + 32, p->domName + 1);
   1.201 +        }
   1.202 +        if (p->pref[0]) {
   1.203 +            printf(", pref: \"%s\"", p->pref);
   1.204 +        }
   1.205 +        printf(" }");
   1.206 +    }
   1.207 +
   1.208 +    if (j != aDOMPropsLength) {
   1.209 +        fprintf(stderr, "Assertion failure %s:%d\n", __FILE__, __LINE__);
   1.210 +        fprintf(stderr, "j==%d, aDOMPropsLength == %d\n", j, aDOMPropsLength);
   1.211 +        exit(1);
   1.212 +    }
   1.213 +
   1.214 +    printf("\n];\n\n");
   1.215 +}
   1.216 +
   1.217 +int
   1.218 +main()
   1.219 +{
   1.220 +    print_array("gLonghandProperties",
   1.221 +                gLonghandProperties,
   1.222 +                ARRAY_LENGTH(gLonghandProperties),
   1.223 +                gLonghandPropertiesWithDOMProp,
   1.224 +                ARRAY_LENGTH(gLonghandPropertiesWithDOMProp));
   1.225 +    print_array("gShorthandProperties",
   1.226 +                gShorthandProperties,
   1.227 +                ARRAY_LENGTH(gShorthandProperties),
   1.228 +                gShorthandPropertiesWithDOMProp,
   1.229 +                ARRAY_LENGTH(gShorthandPropertiesWithDOMProp));
   1.230 +    return 0;
   1.231 +}

mercurial