This source file includes following definitions.
- registerElement
- createCustomTagElement
- didGiveTypeExtension
- resolveOrScheduleResolution
- resolve
- create
- setIsAttributeAndTypeExtension
- setTypeExtension
#include "config.h"
#include "core/dom/custom/CustomElementRegistrationContext.h"
#include "HTMLNames.h"
#include "SVGNames.h"
#include "bindings/v8/ExceptionState.h"
#include "core/dom/Element.h"
#include "core/dom/custom/CustomElement.h"
#include "core/dom/custom/CustomElementDefinition.h"
#include "core/dom/custom/CustomElementScheduler.h"
#include "core/html/HTMLElement.h"
#include "core/html/HTMLUnknownElement.h"
#include "core/svg/SVGUnknownElement.h"
#include "wtf/RefPtr.h"
namespace WebCore {
void CustomElementRegistrationContext::registerElement(Document* document, CustomElementConstructorBuilder* constructorBuilder, const AtomicString& type, CustomElement::NameSet validNames, ExceptionState& exceptionState)
{
CustomElementDefinition* definition = m_registry.registerElement(document, constructorBuilder, type, validNames, exceptionState);
if (!definition)
return;
const CustomElementUpgradeCandidateMap::ElementSet& upgradeCandidates = m_candidates.takeUpgradeCandidatesFor(definition->descriptor());
for (CustomElementUpgradeCandidateMap::ElementSet::const_iterator it = upgradeCandidates.begin(); it != upgradeCandidates.end(); ++it)
CustomElement::define(*it, definition);
}
PassRefPtr<Element> CustomElementRegistrationContext::createCustomTagElement(Document& document, const QualifiedName& tagName)
{
ASSERT(CustomElement::isValidName(tagName.localName()));
RefPtr<Element> element;
if (HTMLNames::xhtmlNamespaceURI == tagName.namespaceURI()) {
element = HTMLElement::create(tagName, document);
} else if (SVGNames::svgNamespaceURI == tagName.namespaceURI()) {
element = SVGUnknownElement::create(tagName, document);
} else {
return Element::create(tagName, &document);
}
element->setCustomElementState(Element::WaitingForUpgrade);
resolveOrScheduleResolution(element.get(), nullAtom);
return element.release();
}
void CustomElementRegistrationContext::didGiveTypeExtension(Element* element, const AtomicString& type)
{
resolveOrScheduleResolution(element, type);
}
void CustomElementRegistrationContext::resolveOrScheduleResolution(Element* element, const AtomicString& typeExtension)
{
const AtomicString& type = CustomElement::isValidName(element->localName())
? element->localName()
: typeExtension;
ASSERT(!type.isNull());
CustomElementDescriptor descriptor(type, element->namespaceURI(), element->localName());
ASSERT(element->customElementState() == Element::WaitingForUpgrade);
CustomElementScheduler::resolveOrScheduleResolution(this, element, descriptor);
}
void CustomElementRegistrationContext::resolve(Element* element, const CustomElementDescriptor& descriptor)
{
CustomElementDefinition* definition = m_registry.find(descriptor);
if (definition) {
CustomElement::define(element, definition);
} else {
ASSERT(element->customElementState() == Element::WaitingForUpgrade);
m_candidates.add(descriptor, element);
}
}
PassRefPtr<CustomElementRegistrationContext> CustomElementRegistrationContext::create()
{
return adoptRef(new CustomElementRegistrationContext());
}
void CustomElementRegistrationContext::setIsAttributeAndTypeExtension(Element* element, const AtomicString& type)
{
ASSERT(element);
ASSERT(!type.isEmpty());
element->setAttribute(HTMLNames::isAttr, type);
setTypeExtension(element, type);
}
void CustomElementRegistrationContext::setTypeExtension(Element* element, const AtomicString& type)
{
if (!element->isHTMLElement() && !element->isSVGElement())
return;
if (element->isCustomElement()) {
return;
}
ASSERT(!CustomElement::isValidName(element->localName()));
element->setCustomElementState(Element::WaitingForUpgrade);
if (CustomElementRegistrationContext* context = element->document().registrationContext())
context->didGiveTypeExtension(element, type);
}
}