Bug 1692937 [wpt PR 27636] - new parameter --include-file for wptrunner, a=testonly
[gecko.git] / layout / style / GenerateComputedDOMStyleGenerated.py
blobd298600fb40f12b3bdc319d37631a56a62ffc209
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 file,
3 # You can obtain one at http://mozilla.org/MPL/2.0/.
5 import runpy
8 def generate(output, dataFile):
9 output.write(
10 """/* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT */
12 /* processed file that defines entries for nsComputedDOMStyle, designed
13 to be #included in nsComputedDOMStyle.cpp */
15 static constexpr Entry kEntries[] = {
16 """
19 def exposed_on_getcs(p):
20 return "ExposedOnGetCS" in p.flags
22 def order_key(p):
23 # Put prefixed properties after normal properties.
24 # The spec is unclear about this, and Blink doesn't have any sensible
25 # order at all, so it probably doesn't matter a lot. But originally
26 # Gecko put then later so we do so as well. See w3c/csswg-drafts#2827.
27 order = p.name.startswith("-")
28 return (order, p.name)
30 def has_cpp_getter(p):
31 if "SerializedByServo" in p.flags:
32 return False
33 if p.type() == "longhand" and "IsLogical" in p.flags:
34 return False
35 return True
37 # Some special cases we may get rid of later. See bug 1471423.
38 def method(p):
39 if p.id.startswith("margin_"):
40 return "{}Width".format(p.method)
41 if p.id.startswith("_moz_"):
42 method = p.method[3:]
43 else:
44 method = p.method
45 if p.id.startswith("_moz_outline_radius_"):
46 method = method.replace("left", "Left")
47 method = method.replace("right", "Right")
48 return method
50 def getter_entry(p):
51 if has_cpp_getter(p):
52 return "DoGet" + method(p)
53 # Put a dummy getter here instead of nullptr because MSVC seems
54 # to have bug which ruins the table when we put nullptr for
55 # pointer-to-member-function. See bug 1471426.
56 return "DummyGetter"
58 properties = runpy.run_path(dataFile)["data"]
59 properties = filter(exposed_on_getcs, properties)
61 TEMPLATE = " {{ eCSSProperty_{}, &nsComputedDOMStyle::{} }},\n"
62 for p in sorted(properties, key=order_key):
63 output.write(TEMPLATE.format(p.id, getter_entry(p)))
65 output.write("};\n")