OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2015 Google Inc. All rights reserved. | 2 * Copyright (C) 2015 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 25 matching lines...) Expand all Loading... |
36 | 36 |
37 namespace blink { | 37 namespace blink { |
38 | 38 |
39 class AssignedNodesOptions; | 39 class AssignedNodesOptions; |
40 | 40 |
41 class CORE_EXPORT HTMLSlotElement final : public HTMLElement { | 41 class CORE_EXPORT HTMLSlotElement final : public HTMLElement { |
42 DEFINE_WRAPPERTYPEINFO(); | 42 DEFINE_WRAPPERTYPEINFO(); |
43 public: | 43 public: |
44 DECLARE_NODE_FACTORY(HTMLSlotElement); | 44 DECLARE_NODE_FACTORY(HTMLSlotElement); |
45 | 45 |
46 const HeapVector<Member<Node>>& assignedNodes() const { return m_assignedNod
es; } | 46 const HeapVector<Member<Node>>& assignedNodes(); |
47 const HeapVector<Member<Node>>& getDistributedNodes(); | 47 const HeapVector<Member<Node>>& getDistributedNodes(); |
48 const HeapVector<Member<Node>> assignedNodesForBinding(const AssignedNodesOp
tions&); | 48 const HeapVector<Member<Node>> assignedNodesForBinding(const AssignedNodesOp
tions&); |
49 | 49 |
50 Node* firstDistributedNode() const { return m_distributedNodes.isEmpty() ? n
ullptr : m_distributedNodes.first().get(); } | 50 Node* firstDistributedNode() const { return m_distributedNodes.isEmpty() ? n
ullptr : m_distributedNodes.first().get(); } |
51 Node* lastDistributedNode() const { return m_distributedNodes.isEmpty() ? nu
llptr : m_distributedNodes.last().get(); } | 51 Node* lastDistributedNode() const { return m_distributedNodes.isEmpty() ? nu
llptr : m_distributedNodes.last().get(); } |
52 | 52 |
53 Node* distributedNodeNextTo(const Node&) const; | 53 Node* distributedNodeNextTo(const Node&) const; |
54 Node* distributedNodePreviousTo(const Node&) const; | 54 Node* distributedNodePreviousTo(const Node&) const; |
55 | 55 |
56 void appendAssignedNode(Node&); | 56 void appendAssignedNode(Node&); |
57 void willUpdateAssignment(); | 57 |
| 58 void resolveDistributedNodes(); |
58 void appendDistributedNode(Node&); | 59 void appendDistributedNode(Node&); |
59 void appendDistributedNodesFrom(const HTMLSlotElement& other); | 60 void appendDistributedNodesFrom(const HTMLSlotElement& other); |
60 void willUpdateDistribution(); | |
61 void appendFallbackNode(Node&); | |
62 void willUpdateFallback(); | |
63 | 61 |
64 void didUpdateAssignment(); | |
65 void updateFallbackNodes(); | |
66 void updateDistributedNodesWithFallback(); | 62 void updateDistributedNodesWithFallback(); |
67 void didUpdateDistribution(); | |
68 | |
69 void fireSlotChangeEvent(); | |
70 | 63 |
71 void attach(const AttachContext& = AttachContext()) final; | 64 void attach(const AttachContext& = AttachContext()) final; |
72 void detach(const AttachContext& = AttachContext()) final; | 65 void detach(const AttachContext& = AttachContext()) final; |
73 | 66 |
74 void attributeChanged(const QualifiedName&, const AtomicString& oldValue, co
nst AtomicString& newValue, AttributeModificationReason = ModifiedDirectly) fina
l; | 67 void attributeChanged(const QualifiedName&, const AtomicString& oldValue, co
nst AtomicString& newValue, AttributeModificationReason = ModifiedDirectly) fina
l; |
75 | 68 |
76 short tabIndex() const override; | 69 short tabIndex() const override; |
77 AtomicString name() const; | 70 AtomicString name() const; |
78 | 71 |
| 72 // This method can be slow because this has to traverse the children of a sh
adow host. |
| 73 // This method should be used only when m_assignedNodes is dirty. |
| 74 // e.g. To detect a slotchange event in DOM mutations. |
| 75 bool hasAssignedNodesSlow() const; |
| 76 bool findHostChildWithSameSlotName() const; |
| 77 |
| 78 void enqueueSlotChangeEvent(); |
| 79 |
| 80 void clearDistribution(); |
| 81 |
| 82 static AtomicString normalizeSlotName(const AtomicString&); |
| 83 |
79 DECLARE_VIRTUAL_TRACE(); | 84 DECLARE_VIRTUAL_TRACE(); |
80 | 85 |
81 private: | 86 private: |
82 HTMLSlotElement(Document&); | 87 HTMLSlotElement(Document&); |
83 | 88 |
84 enum AssignmentState { | |
85 AssignmentOnGoing, | |
86 AssignmentDone, | |
87 AssignmentChanged, | |
88 AssignmentUnchanged | |
89 }; | |
90 | |
91 enum DistributionState { | |
92 DistributionOnGoing, | |
93 DistributionDone, | |
94 DistributionChanged, | |
95 DistributionUnchanged | |
96 }; | |
97 | |
98 void clearDistribution(); | |
99 void childrenChanged(const ChildrenChange&) final; | |
100 InsertionNotificationRequest insertedInto(ContainerNode*) final; | 89 InsertionNotificationRequest insertedInto(ContainerNode*) final; |
101 void removedFrom(ContainerNode*) final; | 90 void removedFrom(ContainerNode*) final; |
102 void willRecalcStyle(StyleRecalcChange) final; | 91 void willRecalcStyle(StyleRecalcChange) final; |
103 | 92 |
104 void dispatchSlotChangeEvent(); | 93 void dispatchSlotChangeEvent(); |
105 bool assignmentChanged(); | |
106 bool distributionChanged(); | |
107 bool fallbackChanged(); | |
108 | 94 |
109 HeapVector<Member<Node>> m_assignedNodes; | 95 HeapVector<Member<Node>> m_assignedNodes; |
110 HeapVector<Member<Node>> m_distributedNodes; | 96 HeapVector<Member<Node>> m_distributedNodes; |
111 HeapVector<Member<Node>> m_fallbackNodes; | |
112 HeapHashMap<Member<const Node>, size_t> m_distributedIndices; | 97 HeapHashMap<Member<const Node>, size_t> m_distributedIndices; |
113 HeapVector<Member<Node>> m_oldAssignedNodes; | 98 bool m_slotchangeEventEnqueued = false; |
114 // TODO(hayato): Remove m_oldDistibutedNodes and make SlotAssignment check t
he diffirence between old and new distributed nodes for each slot to save the me
mories. | |
115 HeapVector<Member<Node>> m_oldDistributedNodes; | |
116 HeapVector<Member<Node>> m_oldFallbackNodes; | |
117 DistributionState m_distributionState; | |
118 AssignmentState m_assignmentState; | |
119 bool m_slotchangeEventAdded; | |
120 }; | 99 }; |
121 | 100 |
122 } // namespace blink | 101 } // namespace blink |
123 | 102 |
124 #endif // HTMLSlotElement_h | 103 #endif // HTMLSlotElement_h |
OLD | NEW |