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" |
(...skipping 13 matching lines...) Expand all Loading... |
24 { | 24 { |
25 if (HTMLImportLoader* loader = import.importLoader()) | 25 if (HTMLImportLoader* loader = import.importLoader()) |
26 return loader->firstImport()->link(); | 26 return loader->firstImport()->link(); |
27 return nullptr; | 27 return nullptr; |
28 } | 28 } |
29 | 29 |
30 CustomElementUpgradeSorter::AddResult CustomElementUpgradeSorter::addToParentChi
ldMap( | 30 CustomElementUpgradeSorter::AddResult CustomElementUpgradeSorter::addToParentChi
ldMap( |
31 Node* parent, | 31 Node* parent, |
32 Node* child) | 32 Node* child) |
33 { | 33 { |
34 ParentChildMap::iterator it = m_parentChildMap->find(parent); | 34 ParentChildMap::AddResult result = m_parentChildMap->add(parent, nullptr); |
35 if (it != m_parentChildMap->end()) { | 35 if (!result.isNewEntry) { |
36 it->value.add(child); | 36 result.storedValue->value->add(child); |
37 // The entry for the parent exists; so must its parents. | 37 // The entry for the parent exists; so must its parents. |
38 return kParentAlreadyExistsInMap; | 38 return kParentAlreadyExistsInMap; |
39 } | 39 } |
40 ParentChildMap::AddResult result = | 40 |
41 m_parentChildMap->add(parent, HeapHashSet<Member<Node>>()); | 41 ChildSet* childSet = new ChildSet(); |
42 result.storedValue->value.add(child); | 42 childSet->add(child); |
| 43 result.storedValue->value = childSet; |
43 return kParentAddedToMap; | 44 return kParentAddedToMap; |
44 } | 45 } |
45 | 46 |
46 void CustomElementUpgradeSorter::add(Element* element) | 47 void CustomElementUpgradeSorter::add(Element* element) |
47 { | 48 { |
48 m_elements->add(element); | 49 m_elements->add(element); |
49 | 50 |
50 for (Node* n = element, *parent = n->parentOrShadowHostNode(); | 51 for (Node* n = element, *parent = n->parentOrShadowHostNode(); |
51 parent; | 52 parent; |
52 n = parent, parent = parent->parentOrShadowHostNode()) { | 53 n = parent, parent = parent->parentOrShadowHostNode()) { |
(...skipping 26 matching lines...) Expand all Loading... |
79 } | 80 } |
80 | 81 |
81 void CustomElementUpgradeSorter::sorted( | 82 void CustomElementUpgradeSorter::sorted( |
82 HeapVector<Member<Element>>* result, | 83 HeapVector<Member<Element>>* result, |
83 Node* parent) | 84 Node* parent) |
84 { | 85 { |
85 ParentChildMap::iterator childrenIterator = m_parentChildMap->find(parent); | 86 ParentChildMap::iterator childrenIterator = m_parentChildMap->find(parent); |
86 if (childrenIterator == m_parentChildMap->end()) | 87 if (childrenIterator == m_parentChildMap->end()) |
87 return; | 88 return; |
88 | 89 |
89 ChildSet& children = childrenIterator->value; | 90 ChildSet* children = childrenIterator->value.get(); |
90 | 91 |
91 if (children.size() == 1) { | 92 if (children->size() == 1) { |
92 visit(result, children, children.begin()); | 93 visit(result, *children, children->begin()); |
93 return; | 94 return; |
94 } | 95 } |
95 | 96 |
96 // TODO(dominicc): When custom elements are used in UA shadow | 97 // TODO(dominicc): When custom elements are used in UA shadow |
97 // roots, expand this to include UA shadow roots. | 98 // roots, expand this to include UA shadow roots. |
98 ShadowRoot* shadowRoot = parent->isElementNode() | 99 ShadowRoot* shadowRoot = parent->isElementNode() |
99 ? toElement(parent)->authorShadowRoot() | 100 ? toElement(parent)->authorShadowRoot() |
100 : nullptr; | 101 : nullptr; |
101 if (shadowRoot) | 102 if (shadowRoot) |
102 visit(result, children, children.find(shadowRoot)); | 103 visit(result, *children, children->find(shadowRoot)); |
103 | 104 |
104 for (Element* e = ElementTraversal::firstChild(*parent); | 105 for (Element* e = ElementTraversal::firstChild(*parent); |
105 e && children.size() > 1; | 106 e && children->size() > 1; |
106 e = ElementTraversal::nextSibling(*e)) { | 107 e = ElementTraversal::nextSibling(*e)) { |
107 | 108 |
108 visit(result, children, children.find(e)); | 109 visit(result, *children, children->find(e)); |
109 } | 110 } |
110 | 111 |
111 if (children.size() == 1) | 112 if (children->size() == 1) |
112 visit(result, children, children.begin()); | 113 visit(result, *children, children->begin()); |
113 | 114 |
114 DCHECK(children.isEmpty()); | 115 DCHECK(children->isEmpty()); |
115 } | 116 } |
116 | 117 |
117 } // namespace blink | 118 } // namespace blink |
OLD | NEW |