summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/Source/build/scripts/templates/CSSPropertyMetadata.cpp.tmpl
blob: fae33029ac5bae7d48d57cf308ec758d8e3feea7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
{% from 'macros.tmpl' import license %}
{{license()}}

#include "core/css/CSSPropertyMetadata.h"

#include "platform/RuntimeEnabledFeatures.h"
#include "wtf/BitArray.h"

namespace blink {
{% for flag, function_name in switches %}

bool CSSPropertyMetadata::{{function_name}}(CSSPropertyID property)
{
    switch(property) {
    case CSSPropertyInvalid:
        ASSERT_NOT_REACHED();
        return false;
    {% for property_id, property in properties.items() if property[flag] %}
    case {{property_id}}:
    {% endfor %}
    {% if function_name == "isInheritedProperty" %}
    case CSSPropertyVariable:
    {% endif %}
        return true;
    default:
        return false;
    }
}
{% endfor %}

bool CSSPropertyMetadata::isEnabledProperty(CSSPropertyID unresolvedProperty)
{
    CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty);
    static BitArray<numCSSProperties>* enabledProperties = 0;
    if (!enabledProperties) {
        enabledProperties = new BitArray<numCSSProperties>(true); // All bits sets to 1.
        {% for property_id, property in properties.items() if property.runtime_flag %}
        if (!RuntimeEnabledFeatures::{{property.runtime_flag|lower_first}}Enabled())
            enabledProperties->clear({{property_id}} - {{first_enum_value}});
        {% endfor %}
        {% for property_id, property in properties.items() if property.is_internal %}
        enabledProperties->clear({{property_id}} - {{first_enum_value}});
        {% endfor %}
    }

    if (unresolvedProperty >= {{first_enum_value}})
        return enabledProperties->get(property - {{first_enum_value}});

    if (unresolvedProperty == CSSPropertyVariable)
        return RuntimeEnabledFeatures::cssVariablesEnabled();
    ASSERT(unresolvedProperty == CSSPropertyApplyAtRule);
    return RuntimeEnabledFeatures::cssApplyAtRulesEnabled();
}

void CSSPropertyMetadata::filterEnabledCSSPropertiesIntoVector(const CSSPropertyID* properties, size_t propertyCount, Vector<CSSPropertyID>& outVector)
{
    for (unsigned i = 0; i < propertyCount; i++) {
        CSSPropertyID property = properties[i];
        if (isEnabledProperty(property))
            outVector.append(property);
    }
}

} // namespace blink