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