ServoCSSPropList.mako.py (4626B)
1 # This Source Code Form is subject to the terms of the Mozilla Public 2 # License, v. 2.0. If a copy of the MPL was not distributed with this 3 # file, You can obtain one at https://mozilla.org/MPL/2.0/. 4 5 def _assign_slots(obj, args): 6 for i, attr in enumerate(obj.__slots__): 7 setattr(obj, attr, args[i]) 8 9 10 class Longhand(object): 11 __slots__ = ["name", "method", "id", "rules", "flags", "pref", "aliases"] 12 13 def __init__(self, *args): 14 _assign_slots(self, args) 15 16 @staticmethod 17 def type(): 18 return "longhand" 19 20 21 class Shorthand(object): 22 __slots__ = ["name", "method", "id", "rules", "flags", "pref", "subprops", "aliases"] 23 24 def __init__(self, *args): 25 _assign_slots(self, args) 26 27 @staticmethod 28 def type(): 29 return "shorthand" 30 31 32 class Alias(object): 33 __slots__ = ["name", "method", "alias_id", "prop_id", "rules", "flags", "pref"] 34 35 def __init__(self, *args): 36 _assign_slots(self, args) 37 38 @staticmethod 39 def type(): 40 return "alias" 41 42 <%! 43 # See bug 1454823 for situation of internal flag. 44 def is_internal(prop): 45 # A property which is not controlled by pref and not enabled in 46 # content by default is an internal property. 47 return not prop.gecko_pref and not prop.enabled_in_content() 48 49 def method(prop): 50 if prop.name == "float": 51 return "CssFloat" 52 if prop.name.startswith("-x-"): 53 return prop.camel_case[1:] 54 return prop.camel_case 55 56 # TODO(emilio): Get this to zero. 57 LONGHANDS_NOT_SERIALIZED_WITH_SERVO = [ 58 # These resolve auto to zero in a few cases, but not all. 59 "max-height", 60 "max-width", 61 "min-height", 62 "min-width", 63 64 # resistfingerprinting stuff. 65 "-moz-osx-font-smoothing", 66 67 # Layout dependent. 68 "width", 69 "height", 70 "grid-template-rows", 71 "grid-template-columns", 72 "perspective-origin", 73 "transform-origin", 74 "transform", 75 "top", 76 "right", 77 "bottom", 78 "left", 79 "margin-top", 80 "margin-right", 81 "margin-bottom", 82 "margin-left", 83 "padding-top", 84 "padding-right", 85 "padding-bottom", 86 "padding-left", 87 ] 88 89 def serialized_by_servo(prop): 90 if prop.type() == "shorthand" or prop.type() == "alias": 91 return True 92 # Keywords are all fine, except -moz-osx-font-smoothing, which does 93 # resistfingerprinting stuff. 94 if prop.keyword and prop.name != "-moz-osx-font-smoothing": 95 return True 96 return prop.name not in LONGHANDS_NOT_SERIALIZED_WITH_SERVO 97 98 def exposed_on_getcs(prop): 99 if "Style" not in prop.rule_types_allowed_names(): 100 return False 101 if is_internal(prop): 102 return False 103 return True 104 105 def rules(prop): 106 return ", ".join('"{}"'.format(rule) for rule in prop.rule_types_allowed_names()) 107 108 RUST_TO_CPP_FLAGS = { 109 "CAN_ANIMATE_ON_COMPOSITOR": "CanAnimateOnCompositor", 110 "AFFECTS_LAYOUT": "AffectsLayout", 111 "AFFECTS_PAINT": "AffectsPaint", 112 "AFFECTS_OVERFLOW": "AffectsOverflow", 113 } 114 115 def flags(prop): 116 result = [] 117 if prop.explicitly_enabled_in_chrome(): 118 result.append("EnabledInUASheetsAndChrome") 119 elif prop.explicitly_enabled_in_ua_sheets(): 120 result.append("EnabledInUASheets") 121 if is_internal(prop): 122 result.append("Internal") 123 if prop.enabled_in == "": 124 result.append("Inaccessible") 125 for (k, v) in RUST_TO_CPP_FLAGS.items(): 126 if k in prop.flags: 127 result.append(v) 128 if exposed_on_getcs(prop): 129 result.append("ExposedOnGetCS") 130 if serialized_by_servo(prop): 131 result.append("SerializedByServo") 132 if prop.type() == "longhand" and prop.logical: 133 result.append("IsLogical") 134 return ", ".join('"{}"'.format(flag) for flag in result) 135 136 def pref(prop): 137 if prop.gecko_pref: 138 return '"' + prop.gecko_pref + '"' 139 return '""' 140 141 def sub_properties(prop): 142 return ", ".join('"{}"'.format(p.ident) for p in prop.sub_properties) 143 144 def aliases(prop): 145 return ", ".join('"{}"'.format(p.ident) for p in prop.aliases) 146 %> 147 148 data = { 149 % for prop in data.longhands: 150 "${prop.ident}": Longhand("${prop.name}", "${method(prop)}", "${prop.ident}", [${rules(prop)}], [${flags(prop)}], ${pref(prop)}, [${aliases(prop)}]), 151 % endfor 152 153 % for prop in data.shorthands: 154 "${prop.ident}": Shorthand("${prop.name}", "${prop.camel_case}", "${prop.ident}", [${rules(prop)}], [${flags(prop)}], ${pref(prop)}, [${sub_properties(prop)}], [${aliases(prop)}]), 155 % endfor 156 157 % for prop in data.all_aliases(): 158 "${prop.ident}": Alias("${prop.name}", "${prop.camel_case}", "${prop.ident}", "${prop.original.ident}", [${rules(prop)}], [${flags(prop)}], ${pref(prop)}), 159 % endfor 160 }