layout/style/ServoCSSPropList.mako.py
author Xidorn Quan <me@upsuper.org>
Mon, 16 Apr 2018 14:08:20 +1000
changeset 467832 4d3a028edaed24c108b999488531331ac4db066d
permissions -rw-r--r--
Bug 1452542 part 5 - Generate property list from Servo data. r=emilio,froydnj With this change, we first generate a data file ServoCSSPropList.py from Servo data, and then use this data to generate ServoCSSPropList.h. This change itself serves as a checkpoint with a runtime check that all information generated from Servo side matches what we have in the Gecko side. Following patches will start replacing uses of nsCSSPropList.h with either the data file or the header file. The reason that it generates data file rather than header directly is that, many users of PythonCSSProps.h invokes C++ preprocessor manually to extract data from nsCSSPropList.h without passing in search paths, so it is non-trivial to replace the use of nsCSSPropList.h there with a generated header. Generating a Python data file would hopefully simplify those users rather than adding more complexity to them. I also thought about generating JSON rather than plain Python file, but JSON doesn't allow trailing comma in array, which makes it less pretty to generate via mako template. MozReview-Commit-ID: CwK2oL88r6F

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.

<%!
# nsCSSPropertyID of longhands and shorthands is ordered alphabetically
# with vendor prefixes removed. Note that aliases use their alias name
# as order key directly because they may be duplicate without prefix.
def order_key(prop):
    if prop.name.startswith("-"):
        return prop.name[prop.name.find("-", 1) + 1:]
    return prop.name

# See bug 1454823 for situation of internal flag.
def is_internal(prop):
    # A property which is not controlled by pref and not enabled in
    # content by default is an internal property.
    if not prop.gecko_pref and not prop.enabled_in_content():
        return True
    # There are some special cases we may want to remove eventually.
    OTHER_INTERNALS = [
        "-moz-context-properties",
        "-moz-control-character-visibility",
    ]
    return prop.name in OTHER_INTERNALS

def flags(prop):
    result = []
    if prop.explicitly_enabled_in_chrome():
        result.append("CSS_PROPERTY_ENABLED_IN_UA_SHEETS_AND_CHROME")
    elif prop.explicitly_enabled_in_ua_sheets():
        result.append("CSS_PROPERTY_ENABLED_IN_UA_SHEETS")
    if is_internal(prop):
        result.append("CSS_PROPERTY_INTERNAL")
    if prop.enabled_in == "":
        result.append("CSS_PROPERTY_PARSE_INACCESSIBLE")
    return ", ".join('"{}"'.format(flag) for flag in result)

def pref(prop):
    if prop.gecko_pref:
        return '"' + prop.gecko_pref + '"'
    return '""'
%>

[
    % for prop in sorted(data.longhands, key=order_key):
    (
        "${prop.name}",
        % if prop.name == "float":
        "CssFloat",
        % elif prop.name.startswith("-x-"):
        "${prop.camel_case[1:]}",
        % else:
        "${prop.camel_case}",
        % endif
        "${prop.ident}",
        [${flags(prop)}],
        ${pref(prop)},
        "longhand",
    ),
    % endfor

    % for prop in sorted(data.shorthands, key=order_key):
    (
        "${prop.name}",
        "${prop.camel_case}",
        "${prop.ident}",
        [${flags(prop)}],
        ${pref(prop)},
        "shorthand",
    ),
    % endfor

    % for prop in sorted(data.all_aliases(), key=lambda x: x.name):
    (
        "${prop.name}",
        "${prop.camel_case}",
        ("${prop.ident}", "${prop.original.ident}"),
        [],
        ${pref(prop)},
        "alias",
    ),
    % endfor
]