Bug 1406325 - Part 3: Refactor custom elements clone a node.

Tag UXP Issue #1344
This commit is contained in:
Gaming4JC 2020-01-19 22:25:30 -05:00 committed by Roy Tam
commit c4718c47bb

View file

@ -479,37 +479,31 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNode, bool aClone, bool aDeep,
rv = aNode->Clone(nodeInfo, getter_AddRefs(clone));
NS_ENSURE_SUCCESS(rv, rv);
if (CustomElementRegistry::IsCustomElementEnabled() && clone->IsElement()) {
if (CustomElementRegistry::IsCustomElementEnabled() &&
clone->IsHTMLElement()) {
// The cloned node may be a custom element that may require
// enqueing upgrade reaction.
Element* elem = clone->AsElement();
CustomElementDefinition* definition = nullptr;
Element* cloneElem = clone->AsElement();
RefPtr<nsIAtom> tagAtom = nodeInfo->NameAtom();
if (nsContentUtils::IsCustomElementName(tagAtom)) {
elem->SetCustomElementData(new CustomElementData(tagAtom));
definition =
CustomElementData* data = elem->GetCustomElementData();
// Check if node may be custom element by type extension.
// ex. <button is="x-button">
nsAutoString extension;
if (!data || data->GetCustomElementType() != tagAtom) {
cloneElem->GetAttr(kNameSpaceID_None, nsGkAtoms::is, extension);
}
if (data || !extension.IsEmpty()) {
RefPtr<nsIAtom> typeAtom = extension.IsEmpty() ? tagAtom : NS_Atomize(extension);
cloneElem->SetCustomElementData(new CustomElementData(typeAtom));
CustomElementDefinition* definition =
nsContentUtils::LookupCustomElementDefinition(nodeInfo->GetDocument(),
nodeInfo->LocalName(),
nodeInfo->NamespaceID());
nodeInfo->NamespaceID(),
extension.IsEmpty() ? nullptr : &extension);
if (definition) {
nsContentUtils::EnqueueUpgradeReaction(elem, definition);
}
} else {
// Check if node may be custom element by type extension.
// ex. <button is="x-button">
nsAutoString extension;
if (elem->GetAttr(kNameSpaceID_None, nsGkAtoms::is, extension) &&
!extension.IsEmpty()) {
RefPtr<nsAtom> typeAtom = NS_Atomize(extension);
elem->SetCustomElementData(new CustomElementData(typeAtom));
definition =
nsContentUtils::LookupCustomElementDefinition(nodeInfo->GetDocument(),
nodeInfo->LocalName(),
nodeInfo->NamespaceID(),
&extension);
if (definition) {
nsContentUtils::EnqueueUpgradeReaction(elem, definition);
}
nsContentUtils::EnqueueUpgradeReaction(cloneElem, definition);
}
}
}