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/ElementShadow.h" | 10 #include "core/dom/shadow/ElementShadow.h" |
11 #include "core/dom/shadow/InsertionPoint.h" | 11 #include "core/dom/shadow/InsertionPoint.h" |
12 #include "core/dom/shadow/ShadowRoot.h" | 12 #include "core/dom/shadow/ShadowRoot.h" |
13 #include "core/html/HTMLSlotElement.h" | 13 #include "core/html/HTMLSlotElement.h" |
14 | 14 |
15 namespace blink { | 15 namespace blink { |
16 | 16 |
17 HTMLSlotElement* SlotAssignment::assignedSlotFor(const Node& node) const | 17 HTMLSlotElement* SlotAssignment::assignedSlotFor(const Node& node) const |
18 { | 18 { |
19 return m_assignment.get(const_cast<Node*>(&node)); | 19 return m_assignment.get(const_cast<Node*>(&node)); |
20 } | 20 } |
21 | 21 |
22 static void detachNotAssignedNode(Node& node) | 22 static void detachNotAssignedNode(Node& node) |
23 { | 23 { |
24 if (node.layoutObject()) | 24 if (node.layoutObject()) |
25 node.lazyReattachIfAttached(); | 25 node.lazyReattachIfAttached(); |
26 } | 26 } |
27 | 27 |
| 28 inline static bool isDefaultSlotName(const AtomicString& name) |
| 29 { |
| 30 return name.isNull() || name.isEmpty(); |
| 31 } |
| 32 |
28 void SlotAssignment::resolveAssignment(ShadowRoot& shadowRoot) | 33 void SlotAssignment::resolveAssignment(ShadowRoot& shadowRoot) |
29 { | 34 { |
30 m_assignment.clear(); | 35 m_assignment.clear(); |
31 | 36 |
32 using Name2Slot = WillBeHeapHashMap<AtomicString, RefPtrWillBeMember<HTMLSlo
tElement>>; | 37 using Name2Slot = WillBeHeapHashMap<AtomicString, RefPtrWillBeMember<HTMLSlo
tElement>>; |
33 Name2Slot name2slot; | 38 Name2Slot name2slot; |
34 HTMLSlotElement* defaultSlot = nullptr; | 39 HTMLSlotElement* defaultSlot = nullptr; |
35 | 40 |
36 const WillBeHeapVector<RefPtrWillBeMember<HTMLSlotElement>>& slots = shadowR
oot.descendantSlots(); | 41 const WillBeHeapVector<RefPtrWillBeMember<HTMLSlotElement>>& slots = shadowR
oot.descendantSlots(); |
37 | 42 |
38 for (RefPtrWillBeMember<HTMLSlotElement> slot : slots) { | 43 for (RefPtrWillBeMember<HTMLSlotElement> slot : slots) { |
39 slot->clearDistribution(); | 44 slot->clearDistribution(); |
40 AtomicString name = slot->fastGetAttribute(HTMLNames::nameAttr); | 45 AtomicString name = slot->fastGetAttribute(HTMLNames::nameAttr); |
41 if (name.isNull() || name.isEmpty()) { | 46 if (isDefaultSlotName(name)) { |
42 if (!defaultSlot) | 47 if (!defaultSlot) |
43 defaultSlot = slot.get(); | 48 defaultSlot = slot.get(); |
44 } else { | 49 } else { |
45 name2slot.add(name, slot.get()); | 50 name2slot.add(name, slot.get()); |
46 } | 51 } |
47 } | 52 } |
48 | 53 |
49 for (Node& child : NodeTraversal::childrenOf(*shadowRoot.host())) { | 54 for (Node& child : NodeTraversal::childrenOf(*shadowRoot.host())) { |
50 if (child.isElementNode()) { | 55 if (child.isElementNode()) { |
51 if (isActiveInsertionPoint(child)) { | 56 if (isActiveInsertionPoint(child)) { |
52 // TODO(hayato): Support re-distribution across v0 and v1 shadow
trees | 57 // TODO(hayato): Support re-distribution across v0 and v1 shadow
trees |
53 detachNotAssignedNode(child); | 58 detachNotAssignedNode(child); |
54 continue; | 59 continue; |
55 } | 60 } |
56 AtomicString slotName = toElement(child).fastGetAttribute(HTMLNames:
:slotAttr); | 61 AtomicString slotName = toElement(child).fastGetAttribute(HTMLNames:
:slotAttr); |
57 if (slotName.isNull() || slotName.isEmpty()) { | 62 if (isDefaultSlotName(slotName)) { |
58 if (defaultSlot) | 63 if (defaultSlot) |
59 assign(child, *defaultSlot); | 64 assign(child, *defaultSlot); |
60 else | 65 else |
61 detachNotAssignedNode(child); | 66 detachNotAssignedNode(child); |
62 } else { | 67 } else { |
63 HTMLSlotElement* slot = name2slot.get(slotName); | 68 HTMLSlotElement* slot = name2slot.get(slotName); |
64 if (slot) | 69 if (slot) |
65 assign(child, *slot); | 70 assign(child, *slot); |
66 else | 71 else |
67 detachNotAssignedNode(child); | 72 detachNotAssignedNode(child); |
(...skipping 26 matching lines...) Expand all Loading... |
94 } | 99 } |
95 | 100 |
96 DEFINE_TRACE(SlotAssignment) | 101 DEFINE_TRACE(SlotAssignment) |
97 { | 102 { |
98 #if ENABLE(OILPAN) | 103 #if ENABLE(OILPAN) |
99 visitor->trace(m_assignment); | 104 visitor->trace(m_assignment); |
100 #endif | 105 #endif |
101 } | 106 } |
102 | 107 |
103 } // namespace blink | 108 } // namespace blink |
OLD | NEW |