OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/shadow/SlotAssignment.h" | 5 #include "core/dom/shadow/SlotAssignment.h" |
6 | 6 |
7 #include "core/HTMLNames.h" | 7 #include "core/HTMLNames.h" |
8 #include "core/dom/ElementTraversal.h" | 8 #include "core/dom/ElementTraversal.h" |
9 #include "core/dom/NodeTraversal.h" | 9 #include "core/dom/NodeTraversal.h" |
10 #include "core/dom/shadow/InsertionPoint.h" | 10 #include "core/dom/shadow/InsertionPoint.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 node.lazyReattachIfAttached(); | 24 node.lazyReattachIfAttached(); |
25 } | 25 } |
26 | 26 |
27 void SlotAssignment::resolveAssignment(const ShadowRoot& shadowRoot) | 27 void SlotAssignment::resolveAssignment(const ShadowRoot& shadowRoot) |
28 { | 28 { |
29 m_assignment.clear(); | 29 m_assignment.clear(); |
30 | 30 |
31 using Name2Slot = HashMap<AtomicString, HTMLSlotElement*>; | 31 using Name2Slot = HashMap<AtomicString, HTMLSlotElement*>; |
32 Name2Slot name2slot; | 32 Name2Slot name2slot; |
33 HTMLSlotElement* defaultSlot = nullptr; | 33 HTMLSlotElement* defaultSlot = nullptr; |
| 34 Vector<HTMLSlotElement*> slots; |
34 | 35 |
35 // TODO(hayato): Cache slots elements so that we do not have to travese the
shadow tree. See ShadowRoot::descendantInsertionPoints() | 36 // TODO(hayato): Cache slots elements so that we do not have to travese the
shadow tree. See ShadowRoot::descendantInsertionPoints() |
36 for (HTMLSlotElement& slot : Traversal<HTMLSlotElement>::descendantsOf(shado
wRoot)) { | 37 for (HTMLSlotElement& slot : Traversal<HTMLSlotElement>::descendantsOf(shado
wRoot)) { |
37 slot.clearDistribution(); | 38 slot.clearDistribution(); |
38 | 39 |
| 40 slots.append(&slot); |
| 41 |
39 AtomicString name = slot.fastGetAttribute(HTMLNames::nameAttr); | 42 AtomicString name = slot.fastGetAttribute(HTMLNames::nameAttr); |
40 if (name.isNull() || name.isEmpty()) { | 43 if (name.isNull() || name.isEmpty()) { |
41 if (!defaultSlot) | 44 if (!defaultSlot) |
42 defaultSlot = &slot; | 45 defaultSlot = &slot; |
43 } else { | 46 } else { |
44 name2slot.add(name, &slot); | 47 name2slot.add(name, &slot); |
45 } | 48 } |
46 } | 49 } |
47 | 50 |
48 for (Node& child : NodeTraversal::childrenOf(*shadowRoot.host())) { | 51 for (Node& child : NodeTraversal::childrenOf(*shadowRoot.host())) { |
(...skipping 15 matching lines...) Expand all Loading... |
64 assign(child, *slot); | 67 assign(child, *slot); |
65 else | 68 else |
66 detachNotAssignedNode(child); | 69 detachNotAssignedNode(child); |
67 } | 70 } |
68 } else if (defaultSlot) { | 71 } else if (defaultSlot) { |
69 assign(child, *defaultSlot); | 72 assign(child, *defaultSlot); |
70 } else { | 73 } else { |
71 detachNotAssignedNode(child); | 74 detachNotAssignedNode(child); |
72 } | 75 } |
73 } | 76 } |
| 77 |
| 78 // Update each slot's distribution in reverse tree order so that a child slo
t is visited before its parent slot. |
| 79 for (auto slot = slots.rbegin(); slot != slots.rend(); ++slot) |
| 80 (*slot)->updateDistributedNodesWithFallback(); |
74 } | 81 } |
75 | 82 |
76 void SlotAssignment::assign(Node& hostChild, HTMLSlotElement& slot) | 83 void SlotAssignment::assign(Node& hostChild, HTMLSlotElement& slot) |
77 { | 84 { |
78 m_assignment.add(&hostChild, &slot); | 85 m_assignment.add(&hostChild, &slot); |
79 slot.appendAssignedNode(hostChild); | 86 slot.appendAssignedNode(hostChild); |
80 if (isHTMLSlotElement(hostChild)) | 87 if (isHTMLSlotElement(hostChild)) |
81 slot.appendDistributedNodes(toHTMLSlotElement(hostChild).getDistributedN
odes()); | 88 slot.appendDistributedNodes(toHTMLSlotElement(hostChild).getDistributedN
odes()); |
82 else | 89 else |
83 slot.appendDistributedNode(hostChild); | 90 slot.appendDistributedNode(hostChild); |
84 } | 91 } |
85 | 92 |
86 DEFINE_TRACE(SlotAssignment) | 93 DEFINE_TRACE(SlotAssignment) |
87 { | 94 { |
88 #if ENABLE(OILPAN) | 95 #if ENABLE(OILPAN) |
89 visitor->trace(m_assignment); | 96 visitor->trace(m_assignment); |
90 #endif | 97 #endif |
91 } | 98 } |
92 | 99 |
93 } // namespace blink | 100 } // namespace blink |
OLD | NEW |