summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGaming4JC <g4jc@hyperbola.info>2020-01-19 22:25:30 -0500
committerGaming4JC <g4jc@hyperbola.info>2020-01-26 15:50:46 -0500
commit72d4c0b8df4a0080ee10ba302dd4fafeacd0f560 (patch)
treebb0abd00977392711c4c371ef466829aed8ea2ed
parentc199dd22e6722a693ece15422ee3ec224f6d0a28 (diff)
downloadUXP-72d4c0b8df4a0080ee10ba302dd4fafeacd0f560.tar
UXP-72d4c0b8df4a0080ee10ba302dd4fafeacd0f560.tar.gz
UXP-72d4c0b8df4a0080ee10ba302dd4fafeacd0f560.tar.lz
UXP-72d4c0b8df4a0080ee10ba302dd4fafeacd0f560.tar.xz
UXP-72d4c0b8df4a0080ee10ba302dd4fafeacd0f560.zip
Bug 1406325 - Part 3: Refactor custom elements clone a node.
Tag UXP Issue #1344
-rw-r--r--dom/base/nsNodeUtils.cpp44
1 files changed, 19 insertions, 25 deletions
diff --git a/dom/base/nsNodeUtils.cpp b/dom/base/nsNodeUtils.cpp
index 3670b5438..85cd791c5 100644
--- a/dom/base/nsNodeUtils.cpp
+++ b/dom/base/nsNodeUtils.cpp
@@ -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);
}
}
}