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

Unified Diff: Source/core/dom/CustomElementCallbackInvocation.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/CustomElementCallbackInvocation.cpp
diff --git a/Source/core/dom/CustomElementCallbackInvocation.cpp b/Source/core/dom/CustomElementCallbackInvocation.cpp
index 3b6aab9befaf419897f181b78258a1c9b330a3ec..ae9f6bb05343fc29c0b14e1c8d6effb7867102c3 100644
--- a/Source/core/dom/CustomElementCallbackInvocation.cpp
+++ b/Source/core/dom/CustomElementCallbackInvocation.cpp
@@ -31,54 +31,72 @@
#include "config.h"
#include "core/dom/CustomElementCallbackInvocation.h"
-#include "core/dom/CustomElementLifecycleCallbacks.h"
+#include "core/dom/CustomElementCallbackDispatcher.h"
namespace WebCore {
class AttributeChangedInvocation : public CustomElementCallbackInvocation {
public:
- AttributeChangedInvocation(const AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue);
+ AttributeChangedInvocation(PassRefPtr<CustomElementLifecycleCallbacks>, const AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue);
private:
- virtual void dispatch(CustomElementLifecycleCallbacks*, Element*) OVERRIDE;
+ virtual void dispatch(Element*) OVERRIDE;
AtomicString m_name;
AtomicString m_oldValue;
AtomicString m_newValue;
};
-class CreatedInvocation : public CustomElementCallbackInvocation {
-public:
- CreatedInvocation() { }
-private:
- virtual void dispatch(CustomElementLifecycleCallbacks*, Element*) OVERRIDE;
-};
-
-PassOwnPtr<CustomElementCallbackInvocation> CustomElementCallbackInvocation::createCreatedInvocation()
+PassOwnPtr<CustomElementCallbackInvocation> CustomElementCallbackInvocation::createInvocation(PassRefPtr<CustomElementLifecycleCallbacks> callbacks, CustomElementLifecycleCallbacks::CallbackType which)
{
- return adoptPtr(new CreatedInvocation());
+ switch (which) {
+ case CustomElementLifecycleCallbacks::Created:
+ case CustomElementLifecycleCallbacks::EnteredDocument:
+ case CustomElementLifecycleCallbacks::LeftDocument:
+ return adoptPtr(new CustomElementCallbackInvocation(callbacks, which));
+
+ case CustomElementLifecycleCallbacks::AttributeChanged: // Use createAttributeChangedInvocation
+ default:
+ ASSERT_NOT_REACHED();
+ return PassOwnPtr<CustomElementCallbackInvocation>();
+ }
}
-PassOwnPtr<CustomElementCallbackInvocation> CustomElementCallbackInvocation::createAttributeChangedInvocation(const AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue)
+void CustomElementCallbackInvocation::dispatch(Element* element)
{
- return adoptPtr(new AttributeChangedInvocation(name, oldValue, newValue));
+ switch (m_which) {
+ case CustomElementLifecycleCallbacks::Created:
+ if (element->inDocument())
+ CustomElementCallbackDispatcher::instance().enqueueEnteredDocumentCallback(m_callbacks, element);
+ m_callbacks->created(element);
+ break;
+ case CustomElementLifecycleCallbacks::EnteredDocument:
+ m_callbacks->enteredDocument(element);
+ break;
+ case CustomElementLifecycleCallbacks::LeftDocument:
+ m_callbacks->leftDocument(element);
+ break;
+ default:
+ ASSERT_NOT_REACHED();
+ }
}
-AttributeChangedInvocation::AttributeChangedInvocation(const AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue)
- : m_name(name)
- , m_oldValue(oldValue)
- , m_newValue(newValue)
+PassOwnPtr<CustomElementCallbackInvocation> CustomElementCallbackInvocation::createAttributeChangedInvocation(PassRefPtr<CustomElementLifecycleCallbacks> callbacks, const AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue)
{
+ return adoptPtr(new AttributeChangedInvocation(callbacks, name, oldValue, newValue));
}
-void AttributeChangedInvocation::dispatch(CustomElementLifecycleCallbacks* callbacks, Element* element)
+AttributeChangedInvocation::AttributeChangedInvocation(PassRefPtr<CustomElementLifecycleCallbacks> callbacks, const AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue)
+ : CustomElementCallbackInvocation(callbacks, CustomElementLifecycleCallbacks::AttributeChanged)
+ , m_name(name)
+ , m_oldValue(oldValue)
+ , m_newValue(newValue)
{
- callbacks->attributeChanged(element, m_name, m_oldValue, m_newValue);
}
-void CreatedInvocation::dispatch(CustomElementLifecycleCallbacks* callbacks, Element* element)
+void AttributeChangedInvocation::dispatch(Element* element)
{
- callbacks->created(element);
+ callbacks()->attributeChanged(element, m_name, m_oldValue, m_newValue);
}
} // namespace WebCore

Powered by Google App Engine
This is Rietveld 408576698