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* 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
| |
24 { | |
25 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.
| |
26 if (!loader) | |
27 return nullptr; | |
28 | |
29 return loader->firstImport()->link(); | |
30 } | |
31 | |
32 CustomElementUpgradeSorter::AddResult CustomElementUpgradeSorter::addToParentChi ldMap( | |
33 Node* parent, | |
34 Node* child) | |
35 { | |
36 ParentChildMap::iterator it = m_parentChildMap->find(parent); | |
37 if (it != m_parentChildMap->end()) { | |
38 it->value.add(child); | |
39 // The entry for the parent exists; so must its parents. | |
40 return kParentAlreadyExistsInMap; | |
41 } | |
42 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.
| |
43 m_parentChildMap->add(parent, HeapHashSet<Member<Node>>()); | |
44 result.storedValue->value.add(child); | |
45 return kParentAddedToMap; | |
46 } | |
47 | |
20 void CustomElementUpgradeSorter::add(Element* element) | 48 void CustomElementUpgradeSorter::add(Element* element) |
21 { | 49 { |
22 m_elements->add(element); | 50 m_elements->add(element); |
23 | 51 |
24 for (Node* n = element, *parent = n->parentOrShadowHostNode(); | 52 for (Node* n = element, *parent = n->parentOrShadowHostNode(); |
25 parent; | 53 parent; |
26 n = parent, parent = parent->parentOrShadowHostNode()) { | 54 n = parent, parent = parent->parentOrShadowHostNode()) { |
55 if (addToParentChildMap(parent, n) == kParentAlreadyExistsInMap) | |
56 break; | |
27 | 57 |
28 ParentChildMap::iterator it = m_parentChildMap->find(parent); | 58 // Create parent-child link between <link rel="import"> and its imported |
29 if (it == m_parentChildMap->end()) { | 59 // document so that the content of the imported document be visited as i f |
30 ParentChildMap::AddResult result = | 60 // the imported document were inserted in the link element. |
31 m_parentChildMap->add(parent, HeapHashSet<Member<Node>>()); | 61 if (parent->isDocumentNode()) { |
32 result.storedValue->value.add(n); | 62 Element* link = getLinkElement(*toDocument(parent)); |
33 } else { | 63 if (!link || addToParentChildMap(link, parent) == kParentAlreadyExis tsInMap) |
34 it->value.add(n); | 64 break; |
35 // The entry for the parent exists; so must its parents. | 65 parent = link; |
36 break; | |
37 } | 66 } |
38 } | 67 } |
39 } | 68 } |
40 | 69 |
41 void CustomElementUpgradeSorter::visit( | 70 void CustomElementUpgradeSorter::visit( |
42 HeapVector<Member<Element>>* result, | 71 HeapVector<Member<Element>>* result, |
43 ChildSet& children, | 72 ChildSet& children, |
44 const ChildSet::iterator& it) | 73 const ChildSet::iterator& it) |
45 { | 74 { |
46 if (it == children.end()) | 75 if (it == children.end()) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 visit(result, children, children.find(e)); | 110 visit(result, children, children.find(e)); |
82 } | 111 } |
83 | 112 |
84 if (children.size() == 1) | 113 if (children.size() == 1) |
85 visit(result, children, children.begin()); | 114 visit(result, children, children.begin()); |
86 | 115 |
87 DCHECK(children.isEmpty()); | 116 DCHECK(children.isEmpty()); |
88 } | 117 } |
89 | 118 |
90 } // namespace blink | 119 } // namespace blink |
OLD | NEW |