| Index: Source/core/dom/CustomElementCallbackDispatcher.cpp
|
| diff --git a/Source/core/dom/CustomElementCallbackDispatcher.cpp b/Source/core/dom/CustomElementCallbackDispatcher.cpp
|
| index 8c463db36417e05302aa39dacaa4da6e1a83d180..bc3c3c6042a72639b34f298544b8181dc0bb32c5 100644
|
| --- a/Source/core/dom/CustomElementCallbackDispatcher.cpp
|
| +++ b/Source/core/dom/CustomElementCallbackDispatcher.cpp
|
| @@ -31,21 +31,41 @@
|
| #include "config.h"
|
| #include "core/dom/CustomElementCallbackDispatcher.h"
|
|
|
| -#include "core/dom/CustomElementCallback.h"
|
| #include "wtf/PassOwnPtr.h"
|
|
|
| namespace WebCore {
|
|
|
| -CustomElementCallbackDispatcher& CustomElementCallbackDispatcher::instance()
|
| +CustomElementCallbackDispatcher::Invocation::Invocation(CustomElementCallback::CallbackType type, PassRefPtr<CustomElementCallback> callback, PassRefPtr<Element> element)
|
| + : m_type(type)
|
| + , m_callback(callback)
|
| + , m_element(element)
|
| {
|
| - DEFINE_STATIC_LOCAL(CustomElementCallbackDispatcher, instance, ());
|
| - return instance;
|
| }
|
|
|
| -CustomElementCallbackDispatcher::ReadyInvocation::ReadyInvocation(PassRefPtr<CustomElementCallback> callback, PassRefPtr<Element> element)
|
| - : m_callback(callback)
|
| - , m_element(element)
|
| +void CustomElementCallbackDispatcher::Invocation::invoke()
|
| {
|
| + switch (m_type) {
|
| + case CustomElementCallback::Ready:
|
| + m_callback->ready(m_element.get());
|
| + break;
|
| +
|
| + case CustomElementCallback::Inserted:
|
| + m_callback->inserted(m_element.get());
|
| + break;
|
| +
|
| + case CustomElementCallback::Removed:
|
| + m_callback->removed(m_element.get());
|
| + break;
|
| +
|
| + default:
|
| + ASSERT_NOT_REACHED();
|
| + }
|
| +}
|
| +
|
| +CustomElementCallbackDispatcher& CustomElementCallbackDispatcher::instance()
|
| +{
|
| + DEFINE_STATIC_LOCAL(CustomElementCallbackDispatcher, instance, ());
|
| + return instance;
|
| }
|
|
|
| bool CustomElementCallbackDispatcher::dispatch()
|
| @@ -67,8 +87,9 @@ bool CustomElementCallbackDispatcher::dispatch()
|
| void CustomElementCallbackDispatcher::dispatchReadyCallback(Element* element)
|
| {
|
| for (size_t i = 0; i < m_invocations.size(); ++i) {
|
| - if (m_invocations[i].get()->element() == element) {
|
| - OwnPtr<ReadyInvocation> invocation = m_invocations[i].release();
|
| + Invocation* invocation = m_invocations[i].get();
|
| + if (invocation->element() == element && invocation->type() == CustomElementCallback::Ready) {
|
| + OwnPtr<Invocation> protect(m_invocations[i].release());
|
| m_invocations.remove(i);
|
| invocation->invoke();
|
| return;
|
| @@ -77,12 +98,34 @@ void CustomElementCallbackDispatcher::dispatchReadyCallback(Element* element)
|
| // The element is unresolved, or it has no ready callback.
|
| }
|
|
|
| -void CustomElementCallbackDispatcher::enqueueReadyCallback(CustomElementCallback* callback, Element* element)
|
| +void CustomElementCallbackDispatcher::enqueueCreationCallbacks(CustomElementCallback* callback, Element* element, bool createdByParser)
|
| +{
|
| + if (callback->hasReady()) {
|
| + OwnPtr<Invocation> readyInvocation = adoptPtr(new Invocation(CustomElementCallback::Ready, callback, element));
|
| + if (createdByParser)
|
| + m_invocations.prepend(readyInvocation.release());
|
| + else
|
| + m_invocations.append(readyInvocation.release());
|
| + }
|
| +
|
| + if (element->inDocument())
|
| + enqueueInsertedCallback(callback, element);
|
| +}
|
| +
|
| +void CustomElementCallbackDispatcher::enqueueInsertedCallback(CustomElementCallback* callback, Element* element)
|
| +{
|
| + if (!callback->hasInserted())
|
| + return;
|
| +
|
| + m_invocations.append(adoptPtr(new Invocation(CustomElementCallback::Inserted, callback, element)));
|
| +}
|
| +
|
| +void CustomElementCallbackDispatcher::enqueueRemovedCallback(CustomElementCallback* callback, Element* element)
|
| {
|
| - if (!callback->hasReady())
|
| + if (!callback->hasRemoved())
|
| return;
|
|
|
| - m_invocations.append(adoptPtr(new ReadyInvocation(callback, element)));
|
| + m_invocations.append(adoptPtr(new Invocation(CustomElementCallback::Removed, callback, element)));
|
| }
|
|
|
| } // namespace WebCore
|
|
|