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

Unified Diff: Source/core/dom/CustomElementCallbackDispatcher.cpp

Issue 18167006: Implement Custom Elements' entered and left document callbacks. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Feedback. Created 7 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: Source/core/dom/CustomElementCallbackDispatcher.cpp
diff --git a/Source/core/dom/CustomElementCallbackDispatcher.cpp b/Source/core/dom/CustomElementCallbackDispatcher.cpp
index 0ec60d440bd8b03df47ce2fff2753dbad8968da5..10db728152f884a3d8da06e60b8c97a65b8c19dd 100644
--- a/Source/core/dom/CustomElementCallbackDispatcher.cpp
+++ b/Source/core/dom/CustomElementCallbackDispatcher.cpp
@@ -49,34 +49,45 @@ CustomElementCallbackDispatcher& CustomElementCallbackDispatcher::instance()
void CustomElementCallbackDispatcher::enqueueAttributeChangedCallback(PassRefPtr<CustomElementLifecycleCallbacks> callbacks, PassRefPtr<Element> element, const AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue)
{
- if (!callbacks->hasAttributeChanged())
+ if (!callbacks->hasAttributeChangedCallback())
return;
- CustomElementCallbackQueue* queue = ensureCallbackQueue(callbacks, element);
- bool isInCurrentQueue = queue->owner() == currentElementQueue();
- if (!isInCurrentQueue) {
- queue->setOwner(currentElementQueue());
- m_flattenedProcessingStack.append(queue);
- s_elementQueueEnd++;
- }
-
- queue->append(CustomElementCallbackInvocation::createAttributeChangedInvocation(name, oldValue, newValue));
+ CustomElementCallbackQueue* queue = scheduleInCurrentElementQueue(element);
+ queue->append(CustomElementCallbackInvocation::createAttributeChangedInvocation(callbacks, name, oldValue, newValue));
}
void CustomElementCallbackDispatcher::enqueueCreatedCallback(PassRefPtr<CustomElementLifecycleCallbacks> callbacks, PassRefPtr<Element> element)
{
- if (!callbacks->hasCreated())
+ if (!callbacks->hasCreatedCallback())
return;
- CustomElementCallbackQueue* queue = createCallbackQueue(callbacks, element);
+ CustomElementCallbackQueue* queue = createCallbackQueue(element);
queue->setOwner(currentElementQueue());
// The created callback is unique in being prepended to the front
// of the element queue
m_flattenedProcessingStack.insert(inCallbackDeliveryScope() ? s_elementQueueStart : /* skip null sentinel */ 1, queue);
- s_elementQueueEnd++;
+ ++s_elementQueueEnd;
+
+ queue->append(CustomElementCallbackInvocation::createInvocation(callbacks, CustomElementLifecycleCallbacks::Created));
+}
+
+void CustomElementCallbackDispatcher::enqueueEnteredDocumentCallback(PassRefPtr<CustomElementLifecycleCallbacks> callbacks, PassRefPtr<Element> element)
+{
+ if (!callbacks->hasEnteredDocumentCallback())
+ return;
+
+ CustomElementCallbackQueue* queue = scheduleInCurrentElementQueue(element);
+ queue->append(CustomElementCallbackInvocation::createInvocation(callbacks, CustomElementLifecycleCallbacks::EnteredDocument));
+}
+
+void CustomElementCallbackDispatcher::enqueueLeftDocumentCallback(PassRefPtr<CustomElementLifecycleCallbacks> callbacks, PassRefPtr<Element> element)
+{
+ if (!callbacks->hasLeftDocumentCallback())
+ return;
- queue->append(CustomElementCallbackInvocation::createCreatedInvocation());
+ CustomElementCallbackQueue* queue = scheduleInCurrentElementQueue(element);
+ queue->append(CustomElementCallbackInvocation::createInvocation(callbacks, CustomElementLifecycleCallbacks::LeftDocument));
}
// Dispatches callbacks at microtask checkpoint.
@@ -135,21 +146,38 @@ void CustomElementCallbackDispatcher::processElementQueueAndPop(size_t start, si
m_elementCallbackQueueMap.clear();
}
-CustomElementCallbackQueue* CustomElementCallbackDispatcher::createCallbackQueue(PassRefPtr<CustomElementLifecycleCallbacks> callbacks, PassRefPtr<Element> element)
+CustomElementCallbackQueue* CustomElementCallbackDispatcher::createCallbackQueue(PassRefPtr<Element> element)
{
Element* key = element.get();
- ElementCallbackQueueMap::AddResult result = m_elementCallbackQueueMap.add(key, CustomElementCallbackQueue::create(callbacks, element));
+ ElementCallbackQueueMap::AddResult result = m_elementCallbackQueueMap.add(key, CustomElementCallbackQueue::create(element));
ASSERT(result.isNewEntry);
return result.iterator->value.get();
}
-CustomElementCallbackQueue* CustomElementCallbackDispatcher::ensureCallbackQueue(PassRefPtr<CustomElementLifecycleCallbacks> callbacks, PassRefPtr<Element> element)
+CustomElementCallbackQueue* CustomElementCallbackDispatcher::ensureCallbackQueue(PassRefPtr<Element> element)
{
Element* key = element.get();
ElementCallbackQueueMap::iterator it = m_elementCallbackQueueMap.find(key);
if (it == m_elementCallbackQueueMap.end())
- it = m_elementCallbackQueueMap.add(key, CustomElementCallbackQueue::create(callbacks, element)).iterator;
+ it = m_elementCallbackQueueMap.add(key, CustomElementCallbackQueue::create(element)).iterator;
return it->value.get();
}
+// Finds or creates the callback queue for element. If the element's
+// callback queue is scheduled in an earlier processing stack frame,
+// its owner is set to the element queue on the top of the processing
+// stack. Because callback queues are processed exhaustively, this
+// effectively moves the callback queue to the top of the stack.
+CustomElementCallbackQueue* CustomElementCallbackDispatcher::scheduleInCurrentElementQueue(PassRefPtr<Element> element)
+{
+ CustomElementCallbackQueue* queue = ensureCallbackQueue(element);
+ bool isInCurrentQueue = queue->owner() == currentElementQueue();
+ if (!isInCurrentQueue) {
+ queue->setOwner(currentElementQueue());
+ m_flattenedProcessingStack.append(queue);
+ ++s_elementQueueEnd;
+ }
+ return queue;
+}
+
} // namespace WebCore
« no previous file with comments | « Source/core/dom/CustomElementCallbackDispatcher.h ('k') | Source/core/dom/CustomElementCallbackInvocation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698