Chromium Code Reviews| Index: third_party/WebKit/Source/core/html/HTMLSlotElement.cpp |
| diff --git a/third_party/WebKit/Source/core/html/HTMLSlotElement.cpp b/third_party/WebKit/Source/core/html/HTMLSlotElement.cpp |
| index e6e061fd43441c0744f6756e3e144a599401666e..cd7c0b5dedf1e69c5903d587591a3a0fff74a786 100644 |
| --- a/third_party/WebKit/Source/core/html/HTMLSlotElement.cpp |
| +++ b/third_party/WebKit/Source/core/html/HTMLSlotElement.cpp |
| @@ -31,9 +31,11 @@ |
| #include "core/html/HTMLSlotElement.h" |
| #include "core/HTMLNames.h" |
| +#include "core/dom/Microtask.h" |
| #include "core/dom/NodeTraversal.h" |
| #include "core/dom/shadow/ElementShadow.h" |
| #include "core/dom/shadow/InsertionPoint.h" |
| +#include "core/events/Event.h" |
| #include "core/html/AssignedNodesOptions.h" |
| namespace blink { |
| @@ -103,10 +105,23 @@ void HTMLSlotElement::appendDistributedNodesFrom(const HTMLSlotElement& other) |
| void HTMLSlotElement::clearDistribution() |
| { |
| m_assignedNodes.clear(); |
| + m_oldDistributedNodes.swap(m_distributedNodes); |
|
kochi
2016/02/18 03:40:56
Is there any possibility that clearDistribution()
hayato
2016/02/18 03:51:56
It could happen in the future. I'm aware the curre
|
| m_distributedNodes.clear(); |
| m_distributedIndices.clear(); |
| } |
| +bool HTMLSlotElement::hasSlotChangeEventListener() |
| +{ |
| + return eventTargetData() && eventTargetData()->eventListenerMap.find(EventTypeNames::slotchange); |
|
esprehn
2016/02/18 17:30:43
this is not correct per the semantics of events, y
|
| +} |
| + |
| +void HTMLSlotElement::dispatchSlotChangeEvent() |
| +{ |
| + RefPtrWillBeRawPtr<Event> event = Event::create(EventTypeNames::slotchange); |
| + event->setTarget(this); |
| + dispatchScopedEvent(event); |
| +} |
| + |
| Node* HTMLSlotElement::distributedNodeNextTo(const Node& node) const |
| { |
| const auto& it = m_distributedIndices.find(&node); |
| @@ -218,12 +233,22 @@ void HTMLSlotElement::updateDistributedNodesWithFallback() |
| } |
| } |
| +void HTMLSlotElement::didUpdateDistribution() |
| +{ |
| + if (hasSlotChangeEventListener() && m_distributedNodes != m_oldDistributedNodes) { |
| + // TODO(hayato): Do not enqueue a slotchange event for the same slot twice in the microtask queue |
| + Microtask::enqueueMicrotask(WTF::bind(&HTMLSlotElement::dispatchSlotChangeEvent, PassRefPtrWillBeRawPtr<HTMLSlotElement>(this))); |
|
esprehn
2016/02/18 17:30:43
the de-duplication here is just reinventing what M
|
| + } |
| + // TODO(hayato): Call setNeedsDistributionRecalc if the distribution changes due to the fallback elements |
| +} |
| + |
| DEFINE_TRACE(HTMLSlotElement) |
| { |
| #if ENABLE(OILPAN) |
| visitor->trace(m_assignedNodes); |
| visitor->trace(m_distributedNodes); |
| visitor->trace(m_distributedIndices); |
| + visitor->trace(m_oldDistributedNodes); |
| #endif |
| HTMLElement::trace(visitor); |
| } |