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

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: Move callbacks reference into invocation. 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..22c282bf0afaed8203cde6de07928df4559c04b6 100644
--- a/Source/core/dom/CustomElementCallbackDispatcher.cpp
+++ b/Source/core/dom/CustomElementCallbackDispatcher.cpp
@@ -52,15 +52,8 @@ void CustomElementCallbackDispatcher::enqueueAttributeChangedCallback(PassRefPtr
if (!callbacks->hasAttributeChanged())
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)
@@ -68,7 +61,7 @@ void CustomElementCallbackDispatcher::enqueueCreatedCallback(PassRefPtr<CustomEl
if (!callbacks->hasCreated())
return;
- CustomElementCallbackQueue* queue = createCallbackQueue(callbacks, element);
+ CustomElementCallbackQueue* queue = createCallbackQueue(element);
queue->setOwner(currentElementQueue());
// The created callback is unique in being prepended to the front
@@ -76,7 +69,25 @@ void CustomElementCallbackDispatcher::enqueueCreatedCallback(PassRefPtr<CustomEl
m_flattenedProcessingStack.insert(inCallbackDeliveryScope() ? s_elementQueueStart : /* skip null sentinel */ 1, queue);
s_elementQueueEnd++;
- queue->append(CustomElementCallbackInvocation::createCreatedInvocation());
+ queue->append(CustomElementCallbackInvocation::createInvocation(callbacks, CustomElementLifecycleCallbacks::Created));
+}
+
+void CustomElementCallbackDispatcher::enqueueEnteredDocumentCallback(PassRefPtr<CustomElementLifecycleCallbacks> callbacks, PassRefPtr<Element> element)
+{
+ if (!callbacks->hasEnteredDocument())
+ return;
+
+ CustomElementCallbackQueue* queue = scheduleInCurrentElementQueue(element);
+ queue->append(CustomElementCallbackInvocation::createInvocation(callbacks, CustomElementLifecycleCallbacks::EnteredDocument));
+}
+
+void CustomElementCallbackDispatcher::enqueueLeftDocumentCallback(PassRefPtr<CustomElementLifecycleCallbacks> callbacks, PassRefPtr<Element> element)
+{
+ if (!callbacks->hasLeftDocument())
+ return;
+
+ CustomElementCallbackQueue* queue = scheduleInCurrentElementQueue(element);
+ queue->append(CustomElementCallbackInvocation::createInvocation(callbacks, CustomElementLifecycleCallbacks::LeftDocument));
}
// Dispatches callbacks at microtask checkpoint.
@@ -135,21 +146,33 @@ 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();
}
+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

Powered by Google App Engine
This is Rietveld 408576698