Chromium Code Reviews| 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 #ifndef SlotAssignment_h | 5 #ifndef SlotAssignment_h |
| 6 #define SlotAssignment_h | 6 #define SlotAssignment_h |
| 7 | 7 |
| 8 #include "core/dom/DocumentOrderedList.h" | |
| 8 #include "platform/heap/Handle.h" | 9 #include "platform/heap/Handle.h" |
| 10 #include "wtf/HashMap.h" | |
| 11 #include "wtf/text/AtomicString.h" | |
| 12 #include "wtf/text/AtomicStringHash.h" | |
| 9 | 13 |
| 10 namespace blink { | 14 namespace blink { |
| 11 | 15 |
| 12 class HTMLSlotElement; | 16 class HTMLSlotElement; |
| 13 class Node; | 17 class Node; |
| 14 class ShadowRoot; | 18 class ShadowRoot; |
| 15 | 19 |
| 20 class SlotEntry final : public GarbageCollected<SlotEntry> { | |
| 21 public: | |
| 22 static SlotEntry* create() | |
| 23 { | |
| 24 return new SlotEntry; | |
| 25 } | |
| 26 void add(HTMLSlotElement&); | |
| 27 void remove(HTMLSlotElement&); | |
| 28 HTMLSlotElement* firstSlot() const; | |
| 29 | |
| 30 private: | |
| 31 unsigned size() const { return m_slots.size(); } | |
| 32 DocumentOrderedList m_slots; | |
| 33 DECLARE_TRACE(); | |
|
esprehn
2016/05/23 06:41:00
I don't think traces are usually private?
| |
| 34 }; | |
| 35 | |
| 36 // TODO(hayato): Support SlotAssignment for non-shadow trees, e.g. a document tr ee. | |
| 16 class SlotAssignment final : public GarbageCollected<SlotAssignment> { | 37 class SlotAssignment final : public GarbageCollected<SlotAssignment> { |
| 17 public: | 38 public: |
| 18 static SlotAssignment* create() | 39 static SlotAssignment* create(ShadowRoot& owner) |
| 19 { | 40 { |
| 20 return new SlotAssignment; | 41 return new SlotAssignment(owner); |
| 21 } | 42 } |
| 22 | 43 |
| 23 HTMLSlotElement* assignedSlotFor(const Node&) const; | 44 // Relevant DOM Standard: https://dom.spec.whatwg.org/#find-a-slot |
| 24 void resolveAssignment(ShadowRoot&); | 45 HTMLSlotElement* findSlot(const Node&); |
|
esprehn
2016/05/23 06:41:00
what does the first one do? How does it find a slo
hayato
2016/05/24 13:23:39
It uses the node's slot attribute. I chose this me
| |
| 25 void resolveDistribution(ShadowRoot&); | 46 HTMLSlotElement* findSlotByName(const AtomicString& slotName); |
| 26 | 47 |
| 27 void didAddSlot() { ++m_descendantSlotCount; } | 48 // DOM Standaard defines these two procedures: |
| 28 void didRemoveSlot() { DCHECK_GT(m_descendantSlotCount, 0u); --m_descendantS lotCount; } | 49 // 1. https://dom.spec.whatwg.org/#assignTo-slotables |
|
kochi
2016/05/23 06:08:43
Can't navigate to this URL hash.
hayato
2016/05/24 13:23:39
Fixed
| |
| 29 unsigned descendantSlotCount() const { return m_descendantSlotCount; } | 50 // void assignSlot(const Node& slottable); |
| 51 // 2. https://dom.spec.whatwg.org/#assignTo-a-slot | |
|
kochi
2016/05/23 06:08:43
Ditto. (the 2 merged to https://dom.spec.whatwg.or
hayato
2016/05/24 13:23:39
Fixed
| |
| 52 // void assignSlotables(HTMLSlotElement&); | |
| 53 // As an optimization, Blink does not implement these literally. | |
| 54 // Instead, provide alternative, HTMLSlotElement::isAssignedNodesEmptySynchr onoulsy | |
|
kochi
2016/05/23 06:08:42
nit: s/Synchronoulsy/Synchronously/
| |
| 55 // so that slotchange can be detected. | |
| 30 | 56 |
| 31 const HeapVector<Member<HTMLSlotElement>>& descendantSlots() const { return m_descendantSlots; } | 57 void resolveDistribution(); |
| 58 const HeapVector<Member<HTMLSlotElement>>& slots(); | |
| 32 | 59 |
| 33 void setDescendantSlots(HeapVector<Member<HTMLSlotElement>>& slots) { m_desc endantSlots.swap(slots); } | 60 void slotAdded(HTMLSlotElement&); |
| 34 void clearDescendantSlots() { m_descendantSlots.clear(); } | 61 void slotRemoved(HTMLSlotElement&); |
| 62 void slotRenamed(const AtomicString& oldName, HTMLSlotElement&); | |
| 63 void hostChildSlotNameChanged(const AtomicString& oldValue, const AtomicStri ng& newValue); | |
| 64 | |
| 65 bool findHostChildBySlotName(const AtomicString& slotName) const; | |
| 35 | 66 |
| 36 DECLARE_TRACE(); | 67 DECLARE_TRACE(); |
| 37 | 68 |
| 38 private: | 69 private: |
| 39 SlotAssignment() { }; | 70 SlotAssignment(ShadowRoot& owner); |
|
esprehn
2016/05/23 06:41:00
explicit, even private constructors need it or you
| |
| 40 | 71 |
| 41 void assign(Node&, HTMLSlotElement&); | 72 SlotEntry& entry(const AtomicString&); |
| 42 void distribute(Node&, HTMLSlotElement&); | 73 void collectSlots(); |
| 43 | 74 |
| 44 unsigned m_descendantSlotCount = 0; | 75 void resolveAssignment(); |
| 45 HeapVector<Member<HTMLSlotElement>> m_descendantSlots; | 76 void assignTo(Node&, HTMLSlotElement&); |
| 46 HeapHashMap<Member<Node>, Member<HTMLSlotElement>> m_assignment; | 77 void distributeTo(Node&, HTMLSlotElement&); |
| 78 | |
| 79 HeapVector<Member<HTMLSlotElement>> m_slots; | |
| 80 HeapHashMap<AtomicString, Member<SlotEntry>> m_slotEntryMap; | |
| 81 WeakMember<ShadowRoot> m_owner; | |
| 82 bool m_needsCollectSlots = false; | |
| 83 unsigned m_slotCount = 0; | |
|
esprehn
2016/05/23 06:41:00
we could combine these together to make this thing
hayato
2016/05/24 13:23:39
Done
| |
| 47 }; | 84 }; |
| 48 | 85 |
| 49 } // namespace blink | 86 } // namespace blink |
| 50 | 87 |
| 51 #endif // HTMLSlotAssignment_h | 88 #endif // HTMLSlotAssignment_h |
| OLD | NEW |