Index: third_party/WebKit/Source/core/dom/custom/CustomElementUpgradeSorter.cpp |
diff --git a/third_party/WebKit/Source/core/dom/custom/CustomElementUpgradeSorter.cpp b/third_party/WebKit/Source/core/dom/custom/CustomElementUpgradeSorter.cpp |
index 34f9e28e5ea741d3eb6a526ae982debb3d29d0fa..558f9adeca91a38abad0cfa71cb601026e0fa069 100644 |
--- a/third_party/WebKit/Source/core/dom/custom/CustomElementUpgradeSorter.cpp |
+++ b/third_party/WebKit/Source/core/dom/custom/CustomElementUpgradeSorter.cpp |
@@ -8,6 +8,9 @@ |
#include "core/dom/ElementTraversal.h" |
#include "core/dom/Node.h" |
#include "core/dom/shadow/ShadowRoot.h" |
+#include "core/html/HTMLLinkElement.h" |
+#include "core/html/imports/HTMLImportChild.h" |
+#include "core/html/imports/HTMLImportLoader.h" |
namespace blink { |
@@ -17,23 +20,57 @@ CustomElementUpgradeSorter::CustomElementUpgradeSorter() |
{ |
} |
+static HTMLLinkElement* getLinkElement(Document* document) |
+{ |
+ DCHECK(document); |
+ HTMLImportLoader* loader = document->importLoader(); |
+ if (!loader) |
+ return nullptr; |
+ |
+ return loader->firstImport()->link(); |
+} |
+ |
+CustomElementUpgradeSorter::AddResult CustomElementUpgradeSorter::addToParentChildMap( |
+ Node* parent, |
+ Node* child) |
+{ |
+ ParentChildMap::iterator it = m_parentChildMap->find(parent); |
+ if (it != m_parentChildMap->end()) { |
+ it->value.add(child); |
+ // The entry for the parent exists; so must its parents. |
+ return kParentAlreadyExistsInMap; |
+ } |
+ ParentChildMap::AddResult result = |
+ m_parentChildMap->add(parent, HeapHashSet<Member<Node>>()); |
+ result.storedValue->value.add(child); |
+ return kParentAddedToMap; |
+} |
+ |
void CustomElementUpgradeSorter::add(Element* element) |
{ |
m_elements->add(element); |
- for (Node* n = element, *parent = n->parentOrShadowHostNode(); |
- parent; |
- n = parent, parent = parent->parentOrShadowHostNode()) { |
- |
- ParentChildMap::iterator it = m_parentChildMap->find(parent); |
- if (it == m_parentChildMap->end()) { |
- ParentChildMap::AddResult result = |
- m_parentChildMap->add(parent, HeapHashSet<Member<Node>>()); |
- result.storedValue->value.add(n); |
- } else { |
- it->value.add(n); |
- // The entry for the parent exists; so must its parents. |
+ // Note: handling of |parent| here is tricky; At the first iteration |
+ // |parent| can never be nullptr because the input is |element| and this |
dominicc (has gone to gerrit)
2016/08/22 12:05:58
Actually this isn't true; the parent can be nullpt
kochi
2016/08/24 11:26:03
Refactored this code and I think the loop look bet
|
+ // loop traverses up to document. Therefore the <link> check in the middle |
+ // of the loop will be run whenever a document is found. |
+ for (Node* n = element, *parent = n->parentOrShadowHostNode(); parent;) { |
+ if (addToParentChildMap(parent, n) == kParentAlreadyExistsInMap) |
break; |
+ |
+ n = parent; |
+ parent = parent->parentOrShadowHostNode(); |
+ |
+ // Check if this is an imported document, and if it is, register its |
+ // corresponding <link rel="import"> element as its parent. |
+ if (!parent && n->isDocumentNode()) { |
+ Document* d = toDocument(n); |
+ Element* link = getLinkElement(d); |
+ if (!link || addToParentChildMap(link, n) == kParentAlreadyExistsInMap) |
+ break; |
+ |
+ n = link; |
+ parent = link->parentOrShadowHostNode(); |
} |
} |
} |