Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(410)

Unified Diff: third_party/WebKit/Source/core/dom/custom/CustomElementUpgradeSorter.cpp

Issue 2242743002: Make custom elements work in HTML imports (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: clean up tests, remove redundant cases Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..3cc71eec74b54b7f7b248f4da7db9b49dff0bfd2 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,6 +20,31 @@ CustomElementUpgradeSorter::CustomElementUpgradeSorter()
{
}
+static HTMLLinkElement* getLinkElement(const Document& document)
tkent 2016/08/24 12:07:20 * Chromium coding style prefers anonymous namespac
kochi 2016/08/24 15:36:52 The static function follows the convention used in
+{
+ HTMLImportLoader* loader = document.importLoader();
tkent 2016/08/24 12:07:20 I prefer shorter code like: if (HTMLImportLoad
kochi 2016/08/24 15:36:52 Neat. Done.
+ 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 =
tkent 2016/08/24 12:07:20 This function contains two hash lookups and avoida
kochi 2016/08/24 15:36:51 Will do in a separate CL.
+ m_parentChildMap->add(parent, HeapHashSet<Member<Node>>());
+ result.storedValue->value.add(child);
+ return kParentAddedToMap;
+}
+
void CustomElementUpgradeSorter::add(Element* element)
{
m_elements->add(element);
@@ -24,16 +52,17 @@ void CustomElementUpgradeSorter::add(Element* 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.
+ if (addToParentChildMap(parent, n) == kParentAlreadyExistsInMap)
break;
+
+ // Create parent-child link between <link rel="import"> and its imported
+ // document so that the content of the imported document be visited as if
+ // the imported document were inserted in the link element.
+ if (parent->isDocumentNode()) {
+ Element* link = getLinkElement(*toDocument(parent));
+ if (!link || addToParentChildMap(link, parent) == kParentAlreadyExistsInMap)
+ break;
+ parent = link;
}
}
}

Powered by Google App Engine
This is Rietveld 408576698