summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/build/scripts/templates/element_type_helpers.cc.tmpl
blob: ea03ce437761278f880a1344f78fb717c13fb7f8 (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
{% from "templates/macros.tmpl" import license, source_files_for_generated_file %}
{{ license() }}

{{source_files_for_generated_file(template_file, input_files)}}

#include "third_party/blink/renderer/core/{{namespace|lower}}_element_type_helpers.h"

#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/wtf/hash_map.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"

namespace blink {
{% if namespace == "HTML" %}
using HTMLTypeMap = HashMap<AtomicString, HTMLElementType>;

HTMLTypeMap CreateHTMLTypeMap() {
  HTMLTypeMap html_type_map;
  html_type_map.ReserveCapacityForSize({{tags|count}});
  static constexpr struct {
    const char* name;
    HTMLElementType type;
  } kTags[] = {
    {% for tag in tags|sort %}
    { "{{tag.name}}", HTMLElementType::k{{tag.js_interface}} },
    {% endfor %}
  };
  for (const auto& tag : kTags)
    html_type_map.insert(tag.name, tag.type);
  return html_type_map;
}

static const HTMLTypeMap& GetHTMLTypeMap() {
  DEFINE_STATIC_LOCAL(const HTMLTypeMap, html_type_map, (CreateHTMLTypeMap()));
  return html_type_map;
}

HTMLElementType htmlElementTypeForTag(const AtomicString& tagName, const Document* document) {
  const auto& html_type_map = GetHTMLTypeMap();
  auto it = html_type_map.find(tagName);
  if (it == html_type_map.end())
    return HTMLElementType::kHTMLUnknownElement;

  {% for tag in tags|sort %}
  {% if tag.runtimeEnabled %}
  if (tagName == "{{tag.name}}") {
    if (!RuntimeEnabledFeatures::{{tag.runtimeEnabled}}Enabled(document)) {
      return HTMLElementType::kHTMLUnknownElement;
    }
  }
  {% endif %}
  {% endfor %}
  return it->value;
}

bool IsKnownBuiltinTagName(const AtomicString& tag_name) {
  return GetHTMLTypeMap().Contains(tag_name);
}
{% endif %}
}  // namespace blink