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