CustomElementDefinitions.cpp [plain text]
#include "config.h"
#include "CustomElementDefinitions.h"
#if ENABLE(CUSTOM_ELEMENTS)
#include "Document.h"
#include "Element.h"
#include "JSCustomElementInterface.h"
#include "MathMLNames.h"
#include "QualifiedName.h"
#include "SVGNames.h"
#include <runtime/JSCJSValueInlines.h>
#include <wtf/text/AtomicString.h>
namespace WebCore {
void CustomElementDefinitions::addElementDefinition(Ref<JSCustomElementInterface>&& elementInterface)
{
AtomicString localName = elementInterface->name().localName();
ASSERT(!m_nameMap.contains(localName));
m_constructorMap.add(elementInterface->constructor(), elementInterface.ptr());
m_nameMap.add(localName, elementInterface.copyRef());
auto candidateList = m_upgradeCandidatesMap.find(localName);
if (candidateList == m_upgradeCandidatesMap.end())
return;
Vector<RefPtr<Element>> list(WTFMove(candidateList->value));
m_upgradeCandidatesMap.remove(localName);
for (auto& candidate : list) {
ASSERT(candidate);
elementInterface->upgradeElement(*candidate);
}
ASSERT(!m_upgradeCandidatesMap.contains(localName));
}
void CustomElementDefinitions::addUpgradeCandidate(Element& candidate)
{
auto result = m_upgradeCandidatesMap.ensure(candidate.localName(), [] {
return Vector<RefPtr<Element>>();
});
auto& nodeVector = result.iterator->value;
ASSERT(!nodeVector.contains(&candidate));
nodeVector.append(&candidate);
}
JSCustomElementInterface* CustomElementDefinitions::findInterface(const QualifiedName& name) const
{
auto it = m_nameMap.find(name.localName());
return it == m_nameMap.end() || it->value->name() != name ? nullptr : it->value.get();
}
JSCustomElementInterface* CustomElementDefinitions::findInterface(const AtomicString& name) const
{
return m_nameMap.get(name);
}
JSCustomElementInterface* CustomElementDefinitions::findInterface(const JSC::JSObject* constructor) const
{
return m_constructorMap.get(constructor);
}
bool CustomElementDefinitions::containsConstructor(const JSC::JSObject* constructor) const
{
return m_constructorMap.contains(constructor);
}
}
#endif