| 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; | |
| 35 | 34 |
| 36 // TODO(hayato): Cache slots elements so that we do not have to travese the
shadow tree. See ShadowRoot::descendantInsertionPoints() | 35 // 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)) { | 36 for (HTMLSlotElement& slot : Traversal<HTMLSlotElement>::descendantsOf(shado
wRoot)) { |
| 38 slot.clearDistribution(); | 37 slot.clearDistribution(); |
| 39 | 38 |
| 40 slots.append(&slot); | |
| 41 | |
| 42 AtomicString name = slot.fastGetAttribute(HTMLNames::nameAttr); | 39 AtomicString name = slot.fastGetAttribute(HTMLNames::nameAttr); |
| 43 if (name.isNull() || name.isEmpty()) { | 40 if (name.isNull() || name.isEmpty()) { |
| 44 if (!defaultSlot) | 41 if (!defaultSlot) |
| 45 defaultSlot = &slot; | 42 defaultSlot = &slot; |
| 46 } else { | 43 } else { |
| 47 name2slot.add(name, &slot); | 44 name2slot.add(name, &slot); |
| 48 } | 45 } |
| 49 } | 46 } |
| 50 | 47 |
| 51 for (Node& child : NodeTraversal::childrenOf(*shadowRoot.host())) { | 48 for (Node& child : NodeTraversal::childrenOf(*shadowRoot.host())) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 67 assign(child, *slot); | 64 assign(child, *slot); |
| 68 else | 65 else |
| 69 detachNotAssignedNode(child); | 66 detachNotAssignedNode(child); |
| 70 } | 67 } |
| 71 } else if (defaultSlot) { | 68 } else if (defaultSlot) { |
| 72 assign(child, *defaultSlot); | 69 assign(child, *defaultSlot); |
| 73 } else { | 70 } else { |
| 74 detachNotAssignedNode(child); | 71 detachNotAssignedNode(child); |
| 75 } | 72 } |
| 76 } | 73 } |
| 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(); | |
| 81 } | 74 } |
| 82 | 75 |
| 83 void SlotAssignment::assign(Node& hostChild, HTMLSlotElement& slot) | 76 void SlotAssignment::assign(Node& hostChild, HTMLSlotElement& slot) |
| 84 { | 77 { |
| 85 m_assignment.add(&hostChild, &slot); | 78 m_assignment.add(&hostChild, &slot); |
| 86 slot.appendAssignedNode(hostChild); | 79 slot.appendAssignedNode(hostChild); |
| 87 if (isHTMLSlotElement(hostChild)) | 80 if (isHTMLSlotElement(hostChild)) |
| 88 slot.appendDistributedNodes(toHTMLSlotElement(hostChild).getDistributedN
odes()); | 81 slot.appendDistributedNodes(toHTMLSlotElement(hostChild).getDistributedN
odes()); |
| 89 else | 82 else |
| 90 slot.appendDistributedNode(hostChild); | 83 slot.appendDistributedNode(hostChild); |
| 91 } | 84 } |
| 92 | 85 |
| 93 DEFINE_TRACE(SlotAssignment) | 86 DEFINE_TRACE(SlotAssignment) |
| 94 { | 87 { |
| 95 #if ENABLE(OILPAN) | 88 #if ENABLE(OILPAN) |
| 96 visitor->trace(m_assignment); | 89 visitor->trace(m_assignment); |
| 97 #endif | 90 #endif |
| 98 } | 91 } |
| 99 | 92 |
| 100 } // namespace blink | 93 } // namespace blink |
| OLD | NEW |