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/HTMLImportTreeRoot.h" | |
14 #include "core/html/imports/HTMLImportsController.h" | |
11 | 15 |
12 namespace blink { | 16 namespace blink { |
13 | 17 |
14 CustomElementUpgradeSorter::CustomElementUpgradeSorter() | 18 CustomElementUpgradeSorter::CustomElementUpgradeSorter() |
15 : m_elements(new HeapHashSet<Member<Element>>()) | 19 : m_elements(new HeapHashSet<Member<Element>>()) |
16 , m_parentChildMap(new ParentChildMap()) | 20 , m_parentChildMap(new ParentChildMap()) |
17 { | 21 { |
18 } | 22 } |
19 | 23 |
24 static HTMLLinkElement* GetParentLinkElement(Document* d) | |
dominicc (has gone to gerrit)
2016/08/22 08:07:36
Get -> get
Does HTML imports use this nomenclatur
kochi
2016/08/22 12:02:00
Renamed the function to getLinkElement().
| |
25 { | |
26 DCHECK(d); | |
27 HTMLImportsController* c = d->importsController(); | |
28 if (!c) | |
29 return nullptr; | |
30 | |
31 HTMLImportTreeRoot* r = c->root(); | |
32 DCHECK(r); | |
33 | |
34 HTMLImportChild* ch = r->find(*d); | |
35 if (!ch) | |
36 return nullptr; | |
37 | |
38 // Get HTMLLinkElement <link rel="import"> | |
39 return ch->link(); | |
40 } | |
41 | |
42 CustomElementUpgradeSorter::AddResult CustomElementUpgradeSorter::addToParentChi ldMap( | |
43 Node* parent, | |
44 Node* child) | |
45 { | |
46 ParentChildMap::iterator it = m_parentChildMap->find(parent); | |
47 if (it != m_parentChildMap->end()) { | |
48 it->value.add(child); | |
49 // The entry for the parent exists; so must its parents. | |
50 return kParentAlreadyExistsInMap; | |
51 } | |
52 ParentChildMap::AddResult result = | |
53 m_parentChildMap->add(parent, HeapHashSet<Member<Node>>()); | |
54 result.storedValue->value.add(child); | |
55 return kParentAddedToMap; | |
56 } | |
57 | |
20 void CustomElementUpgradeSorter::add(Element* element) | 58 void CustomElementUpgradeSorter::add(Element* element) |
21 { | 59 { |
22 m_elements->add(element); | 60 m_elements->add(element); |
23 | 61 |
24 for (Node* n = element, *parent = n->parentOrShadowHostNode(); | 62 for (Node* n = element, *parent = n->parentOrShadowHostNode(); parent;) { |
dominicc (has gone to gerrit)
2016/08/22 08:07:36
Think about what you've done here when the documen
dominicc (has gone to gerrit)
2016/08/22 08:10:55
Hmm, actually, maybe this is fine, because this wi
kochi
2016/08/22 12:02:00
Added some comments.
| |
25 parent; | 63 if (addToParentChildMap(parent, n) == kParentAlreadyExistsInMap) |
26 n = parent, parent = parent->parentOrShadowHostNode()) { | 64 break; |
27 | 65 |
28 ParentChildMap::iterator it = m_parentChildMap->find(parent); | 66 n = parent; |
29 if (it == m_parentChildMap->end()) { | 67 parent = parent->parentOrShadowHostNode(); |
30 ParentChildMap::AddResult result = | 68 |
31 m_parentChildMap->add(parent, HeapHashSet<Member<Node>>()); | 69 if (!parent && n->isDocumentNode()) { |
32 result.storedValue->value.add(n); | 70 Document* d = toDocument(n); |
33 } else { | 71 Element* link = GetParentLinkElement(d); |
34 it->value.add(n); | 72 if (!link || addToParentChildMap(link, n) == kParentAlreadyExistsInM ap) |
35 // The entry for the parent exists; so must its parents. | 73 break; |
36 break; | 74 |
75 n = link; | |
76 parent = link->parentOrShadowHostNode(); | |
37 } | 77 } |
38 } | 78 } |
39 } | 79 } |
40 | 80 |
41 void CustomElementUpgradeSorter::visit( | 81 void CustomElementUpgradeSorter::visit( |
42 HeapVector<Member<Element>>* result, | 82 HeapVector<Member<Element>>* result, |
43 ChildSet& children, | 83 ChildSet& children, |
44 const ChildSet::iterator& it) | 84 const ChildSet::iterator& it) |
45 { | 85 { |
46 if (it == children.end()) | 86 if (it == children.end()) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 visit(result, children, children.find(e)); | 121 visit(result, children, children.find(e)); |
82 } | 122 } |
83 | 123 |
84 if (children.size() == 1) | 124 if (children.size() == 1) |
85 visit(result, children, children.begin()); | 125 visit(result, children, children.begin()); |
86 | 126 |
87 DCHECK(children.isEmpty()); | 127 DCHECK(children.isEmpty()); |
88 } | 128 } |
89 | 129 |
90 } // namespace blink | 130 } // namespace blink |
OLD | NEW |