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