summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/build/scripts/core/css/templates/css_value_id_mappings_generated.h.tmpl
blob: b0ae312b4e3e088f482ad8f217858297f4d5da87 (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
{% from 'templates/macros.tmpl' import license, source_files_for_generated_file %}
{{license()}}

{{source_files_for_generated_file(template_file, input_files)}}

#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_CSS_CSS_VALUE_ID_MAPPINGS_GENERATED_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_CSS_CSS_VALUE_ID_MAPPINGS_GENERATED_H_

#include "base/notreached.h"
#include "base/check_op.h"
#include "third_party/blink/renderer/core/css_value_keywords.h"
#include "third_party/blink/renderer/core/style/computed_style_base_constants.h"
{% for path in include_paths %}
#include "{{path}}"
{% endfor %}

namespace blink {

// Do not use these functions directly, use the non-generated versions
// in CSSValueMappings.h

namespace detail {

template <class T>
T cssValueIDToPlatformEnumGenerated(CSSValueID);

{% for enum_name, mapping in mappings.items() %}
{% if 'segment' not in mapping %}
template <>
inline {{enum_name}} cssValueIDToPlatformEnumGenerated(CSSValueID v) {
  switch (v) {
  {% for value in mapping['mapping']: %}
    case CSSValueID::{{value}}:
      return {{enum_name}}::{{value}};
  {% endfor %}
    default:
      NOTREACHED();
      return {{mapping['default_value']}};
  }
}

inline CSSValueID platformEnumToCSSValueIDGenerated({{enum_name}} v) {
  switch (v) {
  {% for value in mapping['mapping']: %}
    case {{enum_name}}::{{value}}:
      return CSSValueID::{{value}};
  {% endfor %}
    default:
      NOTREACHED();
      return CSSValueID::kNone;
  }
}
{% else %}

template <>
inline {{enum_name}} cssValueIDToPlatformEnumGenerated(CSSValueID v) {
  {% if mapping['mapping'] | length > mapping.longest_segment_length %}
  switch (v) {
  {% for value, cs_num, css_num in mapping['mapping']: %}
  {% if css_num < mapping.start_segment[2] or css_num > mapping.end_segment[2] %}
    case CSSValueID::{{value}}:
      return {{enum_name}}::{{value}};
  {% endif %}
  {% endfor %}
    default:
      DCHECK_GE(v, CSSValueID::{{mapping.start_segment[0]}});
      DCHECK_LE(v, CSSValueID::{{mapping.end_segment[0]}});
      return static_cast<{{enum_name}}>(static_cast<int>(v) - static_cast<int>(CSSValueID::{{mapping.start_segment[0]}}) + static_cast<int>({{enum_name}}::{{mapping.start_segment[0]}}));
  }
  {% else %}
  DCHECK_GE(v, CSSValueID::{{mapping.start_segment[0]}});
  DCHECK_LE(v, CSSValueID::{{mapping.end_segment[0]}});
  return static_cast<{{enum_name}}>(static_cast<int>(v) - static_cast<int>(CSSValueID::{{mapping.start_segment[0]}}) + static_cast<int>({{enum_name}}::{{mapping.start_segment[0]}}));
  {% endif %}
}

inline CSSValueID platformEnumToCSSValueIDGenerated({{enum_name}} v) {
  {% if mapping['mapping'] | length > mapping.longest_segment_length %}
  switch (v) {
  {% for value, cs_num, css_num in mapping['mapping']: %}
  {% if cs_num < mapping.start_segment[1] or cs_num > mapping.end_segment[1] %}
    case {{enum_name}}::{{value}}:
      return CSSValueID::{{value}};
  {% endif %}
  {% endfor %}
    default:
      DCHECK_GE(v, {{enum_name}}::{{mapping.start_segment[0]}});
      DCHECK_LE(v, {{enum_name}}::{{mapping.end_segment[0]}});
      return static_cast<CSSValueID>(static_cast<int>(v) - static_cast<int>({{enum_name}}::{{mapping.start_segment[0]}}) + static_cast<int>(CSSValueID::{{mapping.start_segment[0]}}));
  }
  {% else %}
  DCHECK_GE(v, {{enum_name}}::{{mapping.start_segment[0]}});
  DCHECK_LE(v, {{enum_name}}::{{mapping.end_segment[0]}});
  return static_cast<CSSValueID>(static_cast<int>(v) - static_cast<int>({{enum_name}}::{{mapping.start_segment[0]}}) + static_cast<int>(CSSValueID::{{mapping.start_segment[0]}}));
  {% endif %}
}

{% endif %}
{% endfor %}
}  // namespace detail

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_CSS_CSS_VALUE_ID_MAPPINGS_GENERATED_H_