This source file includes following definitions.
- scheduleCallback
- scheduleAttributeChangedCallback
- resolveOrScheduleResolution
- scheduleImport
- instance
- ensureCallbackQueue
- callbackDispatcherDidFinish
- microtaskDispatcherDidFinish
- clearElementCallbackQueueMap
- schedule
#include "config.h"
#include "core/dom/custom/CustomElementScheduler.h"
#include "core/dom/Document.h"
#include "core/dom/Element.h"
#include "core/dom/custom/CustomElementCallbackDispatcher.h"
#include "core/dom/custom/CustomElementCallbackInvocation.h"
#include "core/dom/custom/CustomElementLifecycleCallbacks.h"
#include "core/dom/custom/CustomElementMicrotaskDispatcher.h"
#include "core/dom/custom/CustomElementMicrotaskImportStep.h"
#include "core/dom/custom/CustomElementMicrotaskResolutionStep.h"
#include "core/dom/custom/CustomElementRegistrationContext.h"
#include "core/html/imports/HTMLImportChild.h"
namespace WebCore {
class HTMLImport;
void CustomElementScheduler::scheduleCallback(PassRefPtr<CustomElementLifecycleCallbacks> callbacks, PassRefPtr<Element> element, CustomElementLifecycleCallbacks::CallbackType type)
{
ASSERT(type != CustomElementLifecycleCallbacks::AttributeChanged);
if (!callbacks->hasCallback(type))
return;
CustomElementCallbackQueue& queue = instance().schedule(element);
queue.append(CustomElementCallbackInvocation::createInvocation(callbacks, type));
}
void CustomElementScheduler::scheduleAttributeChangedCallback(PassRefPtr<CustomElementLifecycleCallbacks> callbacks, PassRefPtr<Element> element, const AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue)
{
if (!callbacks->hasCallback(CustomElementLifecycleCallbacks::AttributeChanged))
return;
CustomElementCallbackQueue& queue = instance().schedule(element);
queue.append(CustomElementCallbackInvocation::createAttributeChangedInvocation(callbacks, name, oldValue, newValue));
}
void CustomElementScheduler::resolveOrScheduleResolution(PassRefPtr<CustomElementRegistrationContext> context, PassRefPtr<Element> element, const CustomElementDescriptor& descriptor)
{
if (CustomElementCallbackDispatcher::inCallbackDeliveryScope()) {
context->resolve(element.get(), descriptor);
return;
}
HTMLImport* import = element->document().import();
OwnPtr<CustomElementMicrotaskResolutionStep> step = CustomElementMicrotaskResolutionStep::create(context, element, descriptor);
CustomElementMicrotaskDispatcher::instance().enqueue(import, step.release());
}
CustomElementMicrotaskImportStep* CustomElementScheduler::scheduleImport(HTMLImportChild* import)
{
ASSERT(!import->isDone());
ASSERT(import->parent());
OwnPtr<CustomElementMicrotaskImportStep> step = CustomElementMicrotaskImportStep::create();
CustomElementMicrotaskImportStep* rawStep = step.get();
CustomElementMicrotaskDispatcher::instance().enqueue(import->parent(), step.release());
return rawStep;
}
CustomElementScheduler& CustomElementScheduler::instance()
{
DEFINE_STATIC_LOCAL(CustomElementScheduler, instance, ());
return instance;
}
CustomElementCallbackQueue& CustomElementScheduler::ensureCallbackQueue(PassRefPtr<Element> element)
{
ElementCallbackQueueMap::ValueType* it = m_elementCallbackQueueMap.add(element.get(), nullptr).storedValue;
if (!it->value)
it->value = CustomElementCallbackQueue::create(element);
return *it->value.get();
}
void CustomElementScheduler::callbackDispatcherDidFinish()
{
if (CustomElementMicrotaskDispatcher::instance().elementQueueIsEmpty())
instance().clearElementCallbackQueueMap();
}
void CustomElementScheduler::microtaskDispatcherDidFinish()
{
ASSERT(!CustomElementCallbackDispatcher::inCallbackDeliveryScope());
instance().clearElementCallbackQueueMap();
}
void CustomElementScheduler::clearElementCallbackQueueMap()
{
ElementCallbackQueueMap emptyMap;
m_elementCallbackQueueMap.swap(emptyMap);
}
CustomElementCallbackQueue& CustomElementScheduler::schedule(PassRefPtr<Element> passElement)
{
RefPtr<Element> element(passElement);
CustomElementCallbackQueue& callbackQueue = ensureCallbackQueue(element);
if (callbackQueue.inCreatedCallback()) {
return callbackQueue;
}
if (CustomElementCallbackDispatcher::inCallbackDeliveryScope()) {
CustomElementCallbackDispatcher::instance().enqueue(&callbackQueue);
return callbackQueue;
}
CustomElementMicrotaskDispatcher::instance().enqueue(&callbackQueue);
return callbackQueue;
}
}