blob: 516cd99ed6445a041bb7357d981c9c10fcee1a34 [file] [log] [blame]
{% from "macros.tmpl" import license -%}
{{ license() }}
#include "config.h"
#include "{{namespace}}ElementFactory.h"
#include "RuntimeEnabledFeatures.h"
#include "{{namespace}}Names.h"
{%- for tag in tags|sort %}
#include "core/{{namespace|lower}}/{{tag.interface}}.h"
{%- endfor %}
{%- if fallback_interface %}
#include "core/{{namespace|lower}}/{{fallback_interface}}.h"
{%- endif %}
#include "core/dom/ContextFeatures.h"
#include "core/dom/custom/CustomElement.h"
#include "core/dom/custom/CustomElementRegistrationContext.h"
#include "core/dom/Document.h"
#include "core/page/Settings.h"
#include "wtf/HashMap.h"
namespace WebCore {
using namespace {{namespace}}Names;
typedef PassRefPtr<{{namespace}}Element> (*ConstructorFunction)(Document&,
{%- if namespace == 'HTML' %}
HTMLFormElement*,
{%- endif %}
bool createdByParser);
typedef HashMap<AtomicString, ConstructorFunction> FunctionMap;
static FunctionMap* g_constructors = 0;
{%- for tag in tags|sort if not tag.noConstructor %}
static PassRefPtr<{{namespace}}Element> {{tag|symbol}}Constructor(
Document& document,
{%- if namespace == 'HTML' %}
HTMLFormElement* formElement,
{%- endif %}
bool createdByParser)
{
{%- if tag.contextConditional %}
if (!ContextFeatures::{{tag.contextConditional}}Enabled(&document))
return {{fallback_interface}}::create({{tag|symbol}}Tag, document);
{%- endif %}
{%- if tag.runtimeEnabled %}
if (!RuntimeEnabledFeatures::{{tag.runtimeEnabled}}Enabled())
return {{fallback_interface}}::create({{tag|symbol}}Tag, document);
{%- endif %}
return {{tag.interface}}::create(
{%- if tag.multipleTagNames -%} {{tag|symbol}}Tag, {% endif -%}
document
{%- if namespace == 'HTML' and tag.constructorNeedsFormElement %}, formElement{% endif -%}
{%- if tag.constructorNeedsCreatedByParser %}, createdByParser{% endif -%}
);
}
{%- endfor %}
static void addTag(const QualifiedName& tag, ConstructorFunction func)
{
g_constructors->set(tag.localName(), func);
}
static void createFunctionMap()
{
ASSERT(!g_constructors);
g_constructors = new FunctionMap;
{%- for tag in tags|sort if not tag.noConstructor %}
addTag({{tag|symbol}}Tag, {{tag|symbol}}Constructor);
{%- endfor %}
}
PassRefPtr<{{namespace}}Element> {{namespace}}ElementFactory::create{{namespace}}Element(
const AtomicString& localName,
Document& document,
{%- if namespace == 'HTML' %}
HTMLFormElement* formElement,
{%- endif %}
bool createdByParser)
{
if (!g_constructors)
createFunctionMap();
if (ConstructorFunction function = g_constructors->get(localName))
return function(document, {%- if namespace == 'HTML' %}formElement,{% endif %} createdByParser);
if (document.registrationContext() && CustomElement::isValidName(localName)) {
RefPtr<Element> element = document.registrationContext()->createCustomTagElement(document, QualifiedName(nullAtom, localName, {{namespace_prefix}}NamespaceURI));
ASSERT_WITH_SECURITY_IMPLICATION(element->is{{namespace}}Element());
return static_pointer_cast<{{namespace}}Element>(element.release());
}
return {{fallback_interface}}::create(QualifiedName(nullAtom, localName, {{namespace_prefix}}NamespaceURI), document);
}
} // namespace WebCore