chromium/third_party/blink/renderer/build/scripts/templates/fields/group.tmpl

{% from 'templates/fields/field.tmpl' import encode, declare_storage, compare, group_source_expression, field_source_expression %}
{% from 'templates/macros.tmpl' import print_if %}
{% macro declare_field_group_class(group): -%}
{% for subgroup in group.subgroups %}
{{declare_field_group_class(subgroup)}}

{% endfor %}
class {{group.type_name}} : public GarbageCollected<{{group.type_name}}> {
 public:
  explicit {{group.type_name}}();
  CORE_EXPORT {{group.type_name}}(const {{group.type_name}}&);

  static {{group.type_name}}* Create() {
    return MakeGarbageCollected<{{group.type_name}}>();
  }
  {{group.type_name}}* Copy() const {
    return MakeGarbageCollected<{{group.type_name}}>(*this);
  }

  {% if group.all_fields|selectattr("is_inherited")|list|length > 0 and
        group.all_fields|rejectattr("is_inherited")|list|length > 0 %}
    // Used when constructing ComputedStyleBase, since this group contains
    // both inherited and non-inherited members.
    CORE_EXPORT {{group.type_name}}(const {{group.type_name}}& source_for_noninherited,
                                    const {{group.type_name}}& parent_style) :
    {% set comma = joiner(", ") %}
    {% for subgroup in group.subgroups %}
    {{comma()}}{{subgroup.member_name}}({{group_source_expression(subgroup, 'source_for_noninherited', 'parent_style')}})
    {% endfor %}
    {% for field in group.fields %}
    {{comma()}}{{field.name}}({{field_source_expression(field, 'source_for_noninherited', 'parent_style')}})
    {% endfor %}
    {}
  {% endif %}

  CORE_EXPORT void Trace(Visitor* visitor) const {
  {% for subgroup in group.subgroups %}
    visitor->Trace({{subgroup.member_name}});
  {% endfor %}
  {% for field in group.fields %}
    {% if field.wrapper_pointer_name == 'Member' %}
    visitor->Trace({{field.name}});
    {% elif not field.size and not field.wrapper_pointer_name %}
    TraceIfNeeded<{{field.type_name}}>::Trace(visitor, {{field.name}});
    {% endif %}
  {% endfor %}
  }

  bool operator==(const {{group.type_name}}& other) const {
    return (
    {% set boolean_and = joiner("&& ") %}
    {% for subgroup in group.subgroups %}
      {{boolean_and()}}base::ValuesEquivalent({{subgroup.member_name}}, other.{{subgroup.member_name}})
    {% endfor %}
    {% for field in group.fields if not field.custom_compare %}
      {{boolean_and()}}{{compare(field.wrapper_pointer_name, field.name, "other")}}
    {% endfor %}
    );
  }
  bool operator!=(const {{group.type_name}}& other) const { return !(*this == other); }

  {% for subgroup in group.subgroups %}
  Member<{{subgroup.type_name}}> {{subgroup.member_name}};
  {% endfor %}
  {% for field in group.fields %}
  {{declare_storage(field)}}
  {% endfor %}
};
{%- endmacro %}

{% macro define_field_group_class(group): -%}
{% for subgroup in group.subgroups %}
{{define_field_group_class(subgroup)}}

{% endfor %}
ComputedStyleBase::{{group.type_name}}::{{group.type_name}}() {{print_if(group.fields|length > 0, ':')}}
  {% set comma = joiner(", ") %}
  {% for subgroup in group.subgroups %}
    {{comma()}}{{subgroup.member_name}}({{subgroup.type_name}}::Create())
  {% endfor %}
  {% for field in group.fields %}
      {{comma()}}{{field.name}}({{encode(field, field.default_value)}})
  {% endfor %}
  {}

ComputedStyleBase::{{group.type_name}}::{{group.type_name}}(const {{group.type_name}}& other) :
  {% set comma = joiner(", ") %}
  {% for subgroup in group.subgroups %}
      {{comma()}}{{subgroup.member_name}}(other.{{subgroup.member_name}})
  {% endfor %}
  {% for field in group.fields %}
    {% if field.wrapper_pointer_name %}
      {{comma()}}{{field.name}}(MemberCopy(other.{{field.name}}))
    {% else %}
      {{comma()}}{{field.name}}(other.{{field.name}})
     {% endif %}
  {% endfor %}
  {}
{%- endmacro %}