summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/build/scripts/core/style/templates/computed_style_base.cc.tmpl
blob: 5697ad5a94743538636bb09c781c3bed9e0bfa0a (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
{% from 'templates/macros.tmpl' import license, print_if, source_files_for_generated_file %}
{% from 'templates/fields/field.tmpl' import encode, getter_expression, setter_expression, fieldwise_copy, fieldwise_diff %}
{% from 'templates/fields/group.tmpl' import define_field_group_class %}
{{license()}}

{{source_files_for_generated_file(template_file, input_files)}}

#include "third_party/blink/renderer/core/style/computed_style.h"
#include "third_party/blink/renderer/core/style/computed_style_base.h"
#include "third_party/blink/renderer/platform/wtf/size_assertions.h"

namespace blink {

struct SameSizeAsComputedStyleBase {
  {% if computed_style.subgroups is defined %}
  void* dataRefs[{{computed_style.subgroups|length}}];
  {% endif %}
  {% for field in computed_style.fields|rejectattr("is_bit_field") %}
  {{field.type_name}} {{field.name}};
  {% endfor %}
  unsigned m_bit_fields[{{computed_style.num_32_bit_words_for_bit_fields}}];
};

// If this fails, the packing algorithm in make_computed_style_base.py has
// failed to produce the optimal packed size. To fix, update the algorithm to
// ensure that the buckets are placed so that each takes up at most 1 word.
ASSERT_SIZE(ComputedStyleBase, SameSizeAsComputedStyleBase);

// Constructor and destructor are protected so that only the parent class ComputedStyle
// can instantiate this class.
ComputedStyleBase::ComputedStyleBase() :
{% set comma = joiner(", ") %}
{% for field in computed_style.fields %}
    {{comma()}}{{field.name}}({{encode(field, field.default_value)}})
{% endfor %}
{
  {% for subgroup in computed_style.subgroups %}
  {{subgroup.member_name}}.Init();
  {% endfor %}
}

void ComputedStyleBase::InheritFrom(const ComputedStyleBase& other,
                                    IsAtShadowBoundary isAtShadowBoundary) {
  {{fieldwise_copy(computed_style, computed_style.all_fields
      |selectattr("is_property")
      |selectattr("is_inherited")
      |list
    )|indent(2)}}
}

void ComputedStyleBase::CopyNonInheritedFromCached(
    const ComputedStyleBase& other) {
  {{fieldwise_copy(computed_style, computed_style.all_fields
      |rejectattr("has_custom_compare_and_copy")
      |rejectattr("is_inherited")
      |list
    )|indent(2)}}
}

void ComputedStyleBase::PropagateIndependentInheritedProperties(
    const ComputedStyleBase& parentStyle) {
  {% for field in computed_style.all_fields if field.is_property and field.is_independent %}
  if ({{field.is_inherited_method_name}}())
    {{setter_expression(field)}} = parentStyle.{{getter_expression(field)}};
  {% endfor %}
}

{% for name, groups_to_diff in diff_functions_map.items() %}
bool ComputedStyleBase::{{name}}(const ComputedStyle& a, const ComputedStyle& b) {
  {{fieldwise_diff(groups_to_diff)|indent(4)}}
  return false;
}

{% endfor %}

{% for group in computed_style.subgroups %}
{{define_field_group_class(group)}}

{% endfor %}

} // namespace blink