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
)
21 class Shorthand(object):
22 __slots__
= ["name", "method", "id", "rules", "flags", "pref", "subprops", "aliases"]
24 def __init__(self
, *args
):
25 _assign_slots(self
, args
)
33 __slots__
= ["name", "method", "alias_id", "prop_id", "rules", "flags", "pref"]
35 def __init__(self
, *args
):
36 _assign_slots(self
, args
)
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()
50 if prop
.name
== "float":
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.
61 # These resolve auto to zero in a few cases, but not all.
67 # resistfingerprinting stuff.
68 "-moz-osx-font-smoothing",
74 "grid-template-columns",
84 "border-bottom-width",
96 def serialized_by_servo(prop
):
97 if prop
.type() == "shorthand" or prop
.type() == "alias":
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":
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():
108 if is_internal(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",
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():
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
)
147 return '"' + prop
.gecko_pref
+ '"'
150 def sub_properties(prop
):
151 return ", ".join('"{}"'.format(p
.ident
) for p
in prop
.sub_properties
)
154 return ", ".join('"{}"'.format(p
.ident
) for p
in prop
.aliases
)
158 % for prop
in data
.longhands
:
159 "${prop.ident}": Longhand("${prop.name}", "${method(prop)}", "${prop.ident}", [$
{rules(prop
)}], [$
{flags(prop
)}], $
{pref(prop
)}, [$
{aliases(prop
)}]),
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
)}]),
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
)}),