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/. */
5
6 /* build (from code) lists of all supported CSS properties */
7
8 #include <stdio.h>
9 #include <string.h>
10 #include <stdlib.h>
11 #include "mozilla/ArrayUtils.h"
12
13 struct PropertyInfo {
14 const char *propName;
15 const char *domName;
16 const char *pref;
17 };
18
19 const PropertyInfo gLonghandProperties[] = {
20
21 #define CSS_PROP_PUBLIC_OR_PRIVATE(publicname_, privatename_) publicname_
22 #define CSS_PROP(name_, id_, method_, flags_, pref_, parsevariant_, kwtable_, \
23 stylestruct_, stylestructoffset_, animtype_) \
24 {#name_, #method_, pref_},
25 #define CSS_PROP_LIST_INCLUDE_LOGICAL
26
27 #include "nsCSSPropList.h"
28
29 #undef CSS_PROP_LIST_INCLUDE_LOGICAL
30 #undef CSS_PROP
31 #undef CSS_PROP_PUBLIC_OR_PRIVATE
32
33 };
34
35 /*
36 * These are the properties for which domName in the above list should
37 * be used. They're in the same order as the above list, with some
38 * items skipped.
39 */
40 const char *gLonghandPropertiesWithDOMProp[] = {
41
42 #define CSS_PROP_LIST_EXCLUDE_INTERNAL
43 #define CSS_PROP(name_, id_, method_, flags_, pref_, parsevariant_, kwtable_, \
44 stylestruct_, stylestructoffset_, animtype_) \
45 #name_,
46 #define CSS_PROP_LIST_INCLUDE_LOGICAL
47
48 #include "nsCSSPropList.h"
49
50 #undef CSS_PROP_LIST_INCLUDE_LOGICAL
51 #undef CSS_PROP
52 #undef CSS_PROP_LIST_EXCLUDE_INTERNAL
53
54 };
55
56 const PropertyInfo gShorthandProperties[] = {
57
58 #define CSS_PROP_PUBLIC_OR_PRIVATE(publicname_, privatename_) publicname_
59 // Need an extra level of macro nesting to force expansion of method_
60 // params before they get pasted.
61 #define LISTCSSPROPERTIES_INNER_MACRO(method_) #method_
62 #define CSS_PROP_SHORTHAND(name_, id_, method_, flags_, pref_) \
63 {#name_, LISTCSSPROPERTIES_INNER_MACRO(method_), pref_},
64
65 #include "nsCSSPropList.h"
66
67 #undef CSS_PROP_SHORTHAND
68 #undef LISTCSSPROPERTIES_INNER_MACRO
69 #undef CSS_PROP_PUBLIC_OR_PRIVATE
70
71 #define CSS_PROP_ALIAS(name_, aliasid_, id_, method_, pref_) \
72 {#name_, #method_, pref_},
73
74 #include "nsCSSPropAliasList.h"
75
76 #undef CSS_PROP_ALIAS
77
78 };
79
80 /* see gLonghandPropertiesWithDOMProp */
81 const char *gShorthandPropertiesWithDOMProp[] = {
82
83 #define CSS_PROP_LIST_EXCLUDE_INTERNAL
84 #define CSS_PROP_SHORTHAND(name_, id_, method_, flags_, pref_) #name_,
85
86 #include "nsCSSPropList.h"
87
88 #undef CSS_PROP_SHORTHAND
89 #undef CSS_PROP_LIST_EXCLUDE_INTERNAL
90
91 #define CSS_PROP_ALIAS(name_, aliasid_, id_, method_, pref_) #name_,
92
93 #include "nsCSSPropAliasList.h"
94
95 #undef CSS_PROP_ALIAS
96
97 };
98
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 "-moz-context-properties",
108 "-moz-control-character-visibility",
109 "-moz-script-level", // parsed by UA sheets only
110 "-moz-script-size-multiplier",
111 "-moz-script-min-size",
112 "-moz-math-variant",
113 "-moz-math-display", // parsed by UA sheets only
114 "-moz-top-layer", // parsed by UA sheets only
115 "-moz-min-font-size-ratio", // parsed by UA sheets only
116 "-moz-font-smoothing-background-color", // chrome-only internal properties
117 "-moz-window-opacity", // chrome-only internal properties
118 "-moz-window-transform", // chrome-only internal properties
119 "-moz-window-transform-origin", // chrome-only internal properties
120 "-moz-window-shadow", // chrome-only internal properties
121 };
122
is_inaccessible(const char * aPropName)123 inline int is_inaccessible(const char *aPropName) {
124 for (unsigned j = 0; j < MOZ_ARRAY_LENGTH(gInaccessibleProperties); ++j) {
125 if (strcmp(aPropName, gInaccessibleProperties[j]) == 0) return 1;
126 }
127 return 0;
128 }
129
print_array(const char * aName,const PropertyInfo * aProps,unsigned aPropsLength,const char * const * aDOMProps,unsigned aDOMPropsLength)130 void print_array(const char *aName, const PropertyInfo *aProps,
131 unsigned aPropsLength, const char *const *aDOMProps,
132 unsigned aDOMPropsLength) {
133 printf("var %s = [\n", aName);
134
135 int first = 1;
136 unsigned j = 0; // index into DOM prop list
137 for (unsigned i = 0; i < aPropsLength; ++i) {
138 const PropertyInfo *p = aProps + i;
139
140 if (is_inaccessible(p->propName))
141 // inaccessible properties never have DOM props, so don't
142 // worry about incrementing j. The assertion below will
143 // catch if they do.
144 continue;
145
146 if (first)
147 first = 0;
148 else
149 printf(",\n");
150
151 printf("\t{ name: \"%s\", prop: ", p->propName);
152 if (j >= aDOMPropsLength || strcmp(p->propName, aDOMProps[j]) != 0)
153 printf("null");
154 else {
155 ++j;
156 if (strncmp(p->domName, "Moz", 3) == 0)
157 printf("\"%s\"", p->domName);
158 else
159 // lowercase the first letter
160 printf("\"%c%s\"", p->domName[0] + 32, p->domName + 1);
161 }
162 if (p->pref[0]) {
163 printf(", pref: \"%s\"", p->pref);
164 }
165 printf(" }");
166 }
167
168 if (j != aDOMPropsLength) {
169 fprintf(stderr, "Assertion failure %s:%d\n", __FILE__, __LINE__);
170 fprintf(stderr, "j==%d, aDOMPropsLength == %d\n", j, aDOMPropsLength);
171 exit(1);
172 }
173
174 printf("\n];\n\n");
175 }
176
main()177 int main() {
178 print_array("gLonghandProperties", gLonghandProperties,
179 MOZ_ARRAY_LENGTH(gLonghandProperties),
180 gLonghandPropertiesWithDOMProp,
181 MOZ_ARRAY_LENGTH(gLonghandPropertiesWithDOMProp));
182 print_array("gShorthandProperties", gShorthandProperties,
183 MOZ_ARRAY_LENGTH(gShorthandProperties),
184 gShorthandPropertiesWithDOMProp,
185 MOZ_ARRAY_LENGTH(gShorthandPropertiesWithDOMProp));
186 return 0;
187 }
188