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