OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/dom/custom/CustomElementUpgradeSorter.h" | 5 #include "core/dom/custom/CustomElementUpgradeSorter.h" |
6 | 6 |
7 #include "core/dom/Element.h" | 7 #include "core/dom/Element.h" |
8 #include "core/dom/ElementTraversal.h" | 8 #include "core/dom/ElementTraversal.h" |
9 #include "core/dom/Node.h" | 9 #include "core/dom/Node.h" |
10 #include "core/dom/shadow/ShadowRoot.h" | 10 #include "core/dom/shadow/ShadowRoot.h" |
| 11 #include "core/html/HTMLLinkElement.h" |
| 12 #include "core/html/imports/HTMLImportChild.h" |
| 13 #include "core/html/imports/HTMLImportLoader.h" |
11 | 14 |
12 namespace blink { | 15 namespace blink { |
13 | 16 |
14 CustomElementUpgradeSorter::CustomElementUpgradeSorter() | 17 CustomElementUpgradeSorter::CustomElementUpgradeSorter() |
15 : m_elements(new HeapHashSet<Member<Element>>()) | 18 : m_elements(new HeapHashSet<Member<Element>>()) |
16 , m_parentChildMap(new ParentChildMap()) | 19 , m_parentChildMap(new ParentChildMap()) |
17 { | 20 { |
18 } | 21 } |
19 | 22 |
| 23 static HTMLLinkElement* getLinkElementForImport(const Document& import) |
| 24 { |
| 25 if (HTMLImportLoader* loader = import.importLoader()) |
| 26 return loader->firstImport()->link(); |
| 27 return nullptr; |
| 28 } |
| 29 |
| 30 CustomElementUpgradeSorter::AddResult CustomElementUpgradeSorter::addToParentChi
ldMap( |
| 31 Node* parent, |
| 32 Node* child) |
| 33 { |
| 34 ParentChildMap::iterator it = m_parentChildMap->find(parent); |
| 35 if (it != m_parentChildMap->end()) { |
| 36 it->value.add(child); |
| 37 // The entry for the parent exists; so must its parents. |
| 38 return kParentAlreadyExistsInMap; |
| 39 } |
| 40 ParentChildMap::AddResult result = |
| 41 m_parentChildMap->add(parent, HeapHashSet<Member<Node>>()); |
| 42 result.storedValue->value.add(child); |
| 43 return kParentAddedToMap; |
| 44 } |
| 45 |
20 void CustomElementUpgradeSorter::add(Element* element) | 46 void CustomElementUpgradeSorter::add(Element* element) |
21 { | 47 { |
22 m_elements->add(element); | 48 m_elements->add(element); |
23 | 49 |
24 for (Node* n = element, *parent = n->parentOrShadowHostNode(); | 50 for (Node* n = element, *parent = n->parentOrShadowHostNode(); |
25 parent; | 51 parent; |
26 n = parent, parent = parent->parentOrShadowHostNode()) { | 52 n = parent, parent = parent->parentOrShadowHostNode()) { |
| 53 if (addToParentChildMap(parent, n) == kParentAlreadyExistsInMap) |
| 54 break; |
27 | 55 |
28 ParentChildMap::iterator it = m_parentChildMap->find(parent); | 56 // Create parent-child link between <link rel="import"> and its imported |
29 if (it == m_parentChildMap->end()) { | 57 // document so that the content of the imported document be visited as i
f |
30 ParentChildMap::AddResult result = | 58 // the imported document were inserted in the link element. |
31 m_parentChildMap->add(parent, HeapHashSet<Member<Node>>()); | 59 if (parent->isDocumentNode()) { |
32 result.storedValue->value.add(n); | 60 Element* link = getLinkElementForImport(*toDocument(parent)); |
33 } else { | 61 if (!link || addToParentChildMap(link, parent) == kParentAlreadyExis
tsInMap) |
34 it->value.add(n); | 62 break; |
35 // The entry for the parent exists; so must its parents. | 63 parent = link; |
36 break; | |
37 } | 64 } |
38 } | 65 } |
39 } | 66 } |
40 | 67 |
41 void CustomElementUpgradeSorter::visit( | 68 void CustomElementUpgradeSorter::visit( |
42 HeapVector<Member<Element>>* result, | 69 HeapVector<Member<Element>>* result, |
43 ChildSet& children, | 70 ChildSet& children, |
44 const ChildSet::iterator& it) | 71 const ChildSet::iterator& it) |
45 { | 72 { |
46 if (it == children.end()) | 73 if (it == children.end()) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 visit(result, children, children.find(e)); | 108 visit(result, children, children.find(e)); |
82 } | 109 } |
83 | 110 |
84 if (children.size() == 1) | 111 if (children.size() == 1) |
85 visit(result, children, children.begin()); | 112 visit(result, children, children.begin()); |
86 | 113 |
87 DCHECK(children.isEmpty()); | 114 DCHECK(children.isEmpty()); |
88 } | 115 } |
89 | 116 |
90 } // namespace blink | 117 } // namespace blink |
OLD | NEW |