Backed out changeset 852edb03db18 (bug 1905435) for causing multiple failures. CLOSED...
[gecko.git] / layout / style / test / ListCSSProperties.cpp
blob13ac6ae93db939b66076ba34dbdd1631ebef32d6
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>
11 #include "mozilla/ArrayUtils.h"
13 // Do not consider properties not valid in style rules
14 #define CSS_PROP_LIST_EXCLUDE_NOT_IN_STYLE
16 // Need an extra level of macro nesting to force expansion of method_
17 // params before they get pasted.
18 #define STRINGIFY_METHOD(method_) #method_
20 struct PropertyInfo {
21 const char* propName;
22 const char* domName;
23 const char* pref;
26 const PropertyInfo gLonghandProperties[] = {
28 #define CSS_PROP_PUBLIC_OR_PRIVATE(publicname_, privatename_) publicname_
29 #define CSS_PROP_LONGHAND(name_, id_, method_, flags_, pref_, ...) \
30 {#name_, STRINGIFY_METHOD(method_), pref_},
32 #include "mozilla/ServoCSSPropList.h"
34 #undef CSS_PROP_LONGHAND
35 #undef CSS_PROP_PUBLIC_OR_PRIVATE
40 * These are the properties for which domName in the above list should
41 * be used. They're in the same order as the above list, with some
42 * items skipped.
44 const char* gLonghandPropertiesWithDOMProp[] = {
46 #define CSS_PROP_LIST_EXCLUDE_INTERNAL
47 #define CSS_PROP_LONGHAND(name_, ...) #name_,
49 #include "mozilla/ServoCSSPropList.h"
51 #undef CSS_PROP_LONGHAND
52 #undef CSS_PROP_LIST_EXCLUDE_INTERNAL
56 const PropertyInfo gShorthandProperties[] = {
58 #define CSS_PROP_PUBLIC_OR_PRIVATE(publicname_, privatename_) publicname_
59 #define CSS_PROP_SHORTHAND(name_, id_, method_, flags_, pref_) \
60 {#name_, STRINGIFY_METHOD(method_), pref_},
61 #define CSS_PROP_ALIAS(name_, aliasid_, id_, method_, flags_, pref_) \
62 {#name_, #method_, pref_},
64 #include "mozilla/ServoCSSPropList.h"
66 #undef CSS_PROP_ALIAS
67 #undef CSS_PROP_SHORTHAND
68 #undef CSS_PROP_PUBLIC_OR_PRIVATE
72 /* see gLonghandPropertiesWithDOMProp */
73 const char* gShorthandPropertiesWithDOMProp[] = {
75 #define CSS_PROP_LIST_EXCLUDE_INTERNAL
76 #define CSS_PROP_SHORTHAND(name_, id_, method_, flags_, pref_) #name_,
77 #define CSS_PROP_ALIAS(name_, aliasid_, id_, method_, flags_, pref_) #name_,
79 #include "mozilla/ServoCSSPropList.h"
81 #undef CSS_PROP_ALIAS
82 #undef CSS_PROP_SHORTHAND
83 #undef CSS_PROP_LIST_EXCLUDE_INTERNAL
87 #undef STRINGIFY_METHOD
89 const char* gInaccessibleProperties[] = {
90 // Don't print the properties that aren't accepted by the parser, per
91 // CSSParserImpl::ParseProperty
92 "-x-cols",
93 "-x-lang",
94 "-x-span",
95 "-x-text-scale",
96 "-moz-default-appearance",
97 "-moz-theme",
98 "-moz-inert",
99 "-moz-script-level", // parsed by UA sheets only
100 "-moz-math-variant",
101 "-moz-math-display", // parsed by UA sheets only
102 "-moz-top-layer", // parsed by UA sheets only
103 "-moz-min-font-size-ratio", // parsed by UA sheets only
104 "-moz-box-collapse", // chrome-only internal properties
105 "-moz-subtree-hidden-only-visually", // chrome-only internal properties
106 "-moz-user-focus", // chrome-only internal properties
107 "-moz-window-input-region-margin", // chrome-only internal properties
108 "-moz-window-opacity", // chrome-only internal properties
109 "-moz-window-transform", // chrome-only internal properties
110 "-moz-window-transform-origin", // chrome-only internal properties
111 "-moz-window-shadow", // chrome-only internal properties
114 inline int is_inaccessible(const char* aPropName) {
115 for (unsigned j = 0; j < MOZ_ARRAY_LENGTH(gInaccessibleProperties); ++j) {
116 if (strcmp(aPropName, gInaccessibleProperties[j]) == 0) return 1;
118 return 0;
121 void print_array(const char* aName, const PropertyInfo* aProps,
122 unsigned aPropsLength, const char* const* aDOMProps,
123 unsigned aDOMPropsLength) {
124 printf("var %s = [\n", aName);
126 int first = 1;
127 unsigned j = 0; // index into DOM prop list
128 for (unsigned i = 0; i < aPropsLength; ++i) {
129 const PropertyInfo* p = aProps + i;
131 if (is_inaccessible(p->propName))
132 // inaccessible properties never have DOM props, so don't
133 // worry about incrementing j. The assertion below will
134 // catch if they do.
135 continue;
137 if (first)
138 first = 0;
139 else
140 printf(",\n");
142 printf("\t{ name: \"%s\", prop: ", p->propName);
143 if (j >= aDOMPropsLength || strcmp(p->propName, aDOMProps[j]) != 0)
144 printf("null");
145 else {
146 ++j;
147 if (strncmp(p->domName, "Moz", 3) == 0)
148 printf("\"%s\"", p->domName);
149 else
150 // lowercase the first letter
151 printf("\"%c%s\"", p->domName[0] + 32, p->domName + 1);
153 if (p->pref[0]) {
154 printf(", pref: \"%s\"", p->pref);
156 printf(" }");
159 if (j != aDOMPropsLength) {
160 fprintf(stderr, "Assertion failure %s:%d\n", __FILE__, __LINE__);
161 fprintf(stderr, "j==%d, aDOMPropsLength == %d\n", j, aDOMPropsLength);
162 exit(1);
165 printf("\n];\n\n");
168 int main() {
169 print_array("gLonghandProperties", gLonghandProperties,
170 MOZ_ARRAY_LENGTH(gLonghandProperties),
171 gLonghandPropertiesWithDOMProp,
172 MOZ_ARRAY_LENGTH(gLonghandPropertiesWithDOMProp));
173 print_array("gShorthandProperties", gShorthandProperties,
174 MOZ_ARRAY_LENGTH(gShorthandProperties),
175 gShorthandPropertiesWithDOMProp,
176 MOZ_ARRAY_LENGTH(gShorthandPropertiesWithDOMProp));
177 return 0;