Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: third_party/WebKit/Source/core/html/HTMLSlotElement.cpp

Issue 1695163003: Support slotchange events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "core/html/HTMLSlotElement.h" 31 #include "core/html/HTMLSlotElement.h"
32 32
33 #include "core/HTMLNames.h" 33 #include "core/HTMLNames.h"
34 #include "core/dom/Microtask.h"
34 #include "core/dom/NodeTraversal.h" 35 #include "core/dom/NodeTraversal.h"
35 #include "core/dom/shadow/ElementShadow.h" 36 #include "core/dom/shadow/ElementShadow.h"
36 #include "core/dom/shadow/InsertionPoint.h" 37 #include "core/dom/shadow/InsertionPoint.h"
38 #include "core/events/Event.h"
37 #include "core/html/AssignedNodesOptions.h" 39 #include "core/html/AssignedNodesOptions.h"
38 40
39 namespace blink { 41 namespace blink {
40 42
41 using namespace HTMLNames; 43 using namespace HTMLNames;
42 44
43 inline HTMLSlotElement::HTMLSlotElement(Document& document) 45 inline HTMLSlotElement::HTMLSlotElement(Document& document)
44 : HTMLElement(slotTag, document) 46 : HTMLElement(slotTag, document)
45 { 47 {
46 } 48 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 m_distributedNodes.appendVector(other.m_distributedNodes); 98 m_distributedNodes.appendVector(other.m_distributedNodes);
97 for (const auto& it : other.m_distributedIndices) { 99 for (const auto& it : other.m_distributedIndices) {
98 const Node* node = it.key; 100 const Node* node = it.key;
99 m_distributedIndices.set(node, index++); 101 m_distributedIndices.set(node, index++);
100 } 102 }
101 } 103 }
102 104
103 void HTMLSlotElement::clearDistribution() 105 void HTMLSlotElement::clearDistribution()
104 { 106 {
105 m_assignedNodes.clear(); 107 m_assignedNodes.clear();
108 m_oldDistributedNodes.swap(m_distributedNodes);
106 m_distributedNodes.clear(); 109 m_distributedNodes.clear();
107 m_distributedIndices.clear(); 110 m_distributedIndices.clear();
108 } 111 }
109 112
113 bool HTMLSlotElement::hasSlotChangeEventListener()
114 {
115 return eventTargetData() && eventTargetData()->eventListenerMap.find(EventTy peNames::slotchange);
116 }
117
118 void HTMLSlotElement::dispatchSlotChangeEvent()
119 {
120 RefPtrWillBeRawPtr<Event> event = Event::create(EventTypeNames::slotchange);
121 event->setTarget(this);
122 dispatchScopedEvent(event);
123 }
124
110 Node* HTMLSlotElement::distributedNodeNextTo(const Node& node) const 125 Node* HTMLSlotElement::distributedNodeNextTo(const Node& node) const
111 { 126 {
112 const auto& it = m_distributedIndices.find(&node); 127 const auto& it = m_distributedIndices.find(&node);
113 if (it == m_distributedIndices.end()) 128 if (it == m_distributedIndices.end())
114 return nullptr; 129 return nullptr;
115 size_t index = it->value; 130 size_t index = it->value;
116 if (index + 1 == m_distributedNodes.size()) 131 if (index + 1 == m_distributedNodes.size())
117 return nullptr; 132 return nullptr;
118 return m_distributedNodes[index + 1].get(); 133 return m_distributedNodes[index + 1].get();
119 } 134 }
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 // Insertion points are not supported as slots fallback 226 // Insertion points are not supported as slots fallback
212 if (isActiveInsertionPoint(child)) 227 if (isActiveInsertionPoint(child))
213 continue; 228 continue;
214 if (isHTMLSlotElement(child)) 229 if (isHTMLSlotElement(child))
215 appendDistributedNodesFrom(toHTMLSlotElement(child)); 230 appendDistributedNodesFrom(toHTMLSlotElement(child));
216 else 231 else
217 appendDistributedNode(child); 232 appendDistributedNode(child);
218 } 233 }
219 } 234 }
220 235
236 void HTMLSlotElement::didUpdateDistribution()
237 {
238 if (hasSlotChangeEventListener() && m_distributedNodes != m_oldDistributedNo des) {
239 // TODO(hayato): Do not enqueue a slotchange event for the same slot twi ce in the microtask queue
240 Microtask::enqueueMicrotask(WTF::bind(&HTMLSlotElement::dispatchSlotChan geEvent, this));
yhirano 2016/02/17 05:23:12 ditto
hayato 2016/02/17 06:07:33 Done.
241 }
242 // TODO(hayato): Call setNeedsDistributionRecalc if the distribution changes due to the fallback elements
243 }
244
221 DEFINE_TRACE(HTMLSlotElement) 245 DEFINE_TRACE(HTMLSlotElement)
222 { 246 {
223 #if ENABLE(OILPAN) 247 #if ENABLE(OILPAN)
224 visitor->trace(m_assignedNodes); 248 visitor->trace(m_assignedNodes);
225 visitor->trace(m_distributedNodes); 249 visitor->trace(m_distributedNodes);
226 visitor->trace(m_distributedIndices); 250 visitor->trace(m_distributedIndices);
251 visitor->trace(m_oldDistributedNodes);
227 #endif 252 #endif
228 HTMLElement::trace(visitor); 253 HTMLElement::trace(visitor);
229 } 254 }
230 255
231 } // namespace blink 256 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698