Bug 1883861 - Part 1: Move visitMemoryBarrier into the common CodeGenerator file...
[gecko.git] / layout / style / ServoCSSPropList.mako.py
blob56061288d5c1cef7b31d3358942bae9da3731c1c
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/.
5 def _assign_slots(obj, args):
6 for i, attr in enumerate(obj.__slots__):
7 setattr(obj, attr, args[i])
10 class Longhand(object):
11 __slots__ = ["name", "method", "id", "rules", "flags", "pref", "aliases"]
13 def __init__(self, *args):
14 _assign_slots(self, args)
16 @staticmethod
17 def type():
18 return "longhand"
21 class Shorthand(object):
22 __slots__ = ["name", "method", "id", "rules", "flags", "pref", "subprops", "aliases"]
24 def __init__(self, *args):
25 _assign_slots(self, args)
27 @staticmethod
28 def type():
29 return "shorthand"
32 class Alias(object):
33 __slots__ = ["name", "method", "alias_id", "prop_id", "rules", "flags", "pref"]
35 def __init__(self, *args):
36 _assign_slots(self, args)
38 @staticmethod
39 def type():
40 return "alias"
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()
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
56 # TODO(emilio): Get this to zero.
57 LONGHANDS_NOT_SERIALIZED_WITH_SERVO = [
58 # Servo serializes one value when both are the same, a few tests expect two.
59 "border-spacing",
61 # These resolve auto to zero in a few cases, but not all.
62 "max-height",
63 "max-width",
64 "min-height",
65 "min-width",
67 # resistfingerprinting stuff.
68 "-moz-osx-font-smoothing",
70 # Layout dependent.
71 "width",
72 "height",
73 "grid-template-rows",
74 "grid-template-columns",
75 "perspective-origin",
76 "transform-origin",
77 "transform",
78 "top",
79 "right",
80 "bottom",
81 "left",
82 "border-top-width",
83 "border-right-width",
84 "border-bottom-width",
85 "border-left-width",
86 "margin-top",
87 "margin-right",
88 "margin-bottom",
89 "margin-left",
90 "padding-top",
91 "padding-right",
92 "padding-bottom",
93 "padding-left",
96 def serialized_by_servo(prop):
97 if prop.type() == "shorthand" or prop.type() == "alias":
98 return True
99 # Keywords are all fine, except -moz-osx-font-smoothing, which does
100 # resistfingerprinting stuff.
101 if prop.keyword and prop.name != "-moz-osx-font-smoothing":
102 return True
103 return prop.name not in LONGHANDS_NOT_SERIALIZED_WITH_SERVO
105 def exposed_on_getcs(prop):
106 if "Style" not in prop.rule_types_allowed_names():
107 return False
108 if is_internal(prop):
109 return False
110 return True
112 def rules(prop):
113 return ", ".join('"{}"'.format(rule) for rule in prop.rule_types_allowed_names())
115 RUST_TO_CPP_FLAGS = {
116 "CAN_ANIMATE_ON_COMPOSITOR": "CanAnimateOnCompositor",
117 "AFFECTS_LAYOUT": "AffectsLayout",
118 "AFFECTS_PAINT": "AffectsPaint",
119 "AFFECTS_OVERFLOW": "AffectsOverflow",
122 def flags(prop):
123 result = []
124 if prop.explicitly_enabled_in_chrome():
125 result.append("EnabledInUASheetsAndChrome")
126 elif prop.explicitly_enabled_in_ua_sheets():
127 result.append("EnabledInUASheets")
128 if is_internal(prop):
129 result.append("Internal")
130 if prop.enabled_in == "":
131 result.append("Inaccessible")
132 for (k, v) in RUST_TO_CPP_FLAGS.items():
133 if k in prop.flags:
134 result.append(v)
135 if exposed_on_getcs(prop):
136 result.append("ExposedOnGetCS")
137 if prop.type() == "shorthand" and "SHORTHAND_IN_GETCS" in prop.flags:
138 result.append("ShorthandUnconditionallyExposedOnGetCS")
139 if serialized_by_servo(prop):
140 result.append("SerializedByServo")
141 if prop.type() == "longhand" and prop.logical:
142 result.append("IsLogical")
143 return ", ".join('"{}"'.format(flag) for flag in result)
145 def pref(prop):
146 if prop.gecko_pref:
147 return '"' + prop.gecko_pref + '"'
148 return '""'
150 def sub_properties(prop):
151 return ", ".join('"{}"'.format(p.ident) for p in prop.sub_properties)
153 def aliases(prop):
154 return ", ".join('"{}"'.format(p.ident) for p in prop.aliases)
157 data = {
158 % for prop in data.longhands:
159 "${prop.ident}": Longhand("${prop.name}", "${method(prop)}", "${prop.ident}", [${rules(prop)}], [${flags(prop)}], ${pref(prop)}, [${aliases(prop)}]),
160 % endfor
162 % for prop in data.shorthands:
163 "${prop.ident}": Shorthand("${prop.name}", "${prop.camel_case}", "${prop.ident}", [${rules(prop)}], [${flags(prop)}], ${pref(prop)}, [${sub_properties(prop)}], [${aliases(prop)}]),
164 % endfor
166 % for prop in data.all_aliases():
167 "${prop.ident}": Alias("${prop.name}", "${prop.camel_case}", "${prop.ident}", "${prop.original.ident}", [${rules(prop)}], [${flags(prop)}], ${pref(prop)}),
168 % endfor