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

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: 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
« no previous file with comments | « Source/core/dom/CustomElementCallbackInvocation.h ('k') | Source/core/dom/CustomElementCallbackQueue.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/CustomElementCallbackInvocation.cpp
diff --git a/Source/core/dom/CustomElementCallbackInvocation.cpp b/Source/core/dom/CustomElementCallbackInvocation.cpp
index 3b6aab9befaf419897f181b78258a1c9b330a3ec..2d81c89953946a64900e178516a8f18b961ea094 100644
--- a/Source/core/dom/CustomElementCallbackInvocation.cpp
+++ b/Source/core/dom/CustomElementCallbackInvocation.cpp
@@ -31,54 +31,103 @@
#include "config.h"
#include "core/dom/CustomElementCallbackInvocation.h"
-#include "core/dom/CustomElementLifecycleCallbacks.h"
+#include "core/dom/CustomElementCallbackDispatcher.h"
namespace WebCore {
-class AttributeChangedInvocation : public CustomElementCallbackInvocation {
+class CreatedInvocation : public CustomElementCallbackInvocation {
public:
- AttributeChangedInvocation(const AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue);
+ CreatedInvocation(PassRefPtr<CustomElementLifecycleCallbacks> callbacks)
+ : CustomElementCallbackInvocation(callbacks)
+ {
+ }
private:
- virtual void dispatch(CustomElementLifecycleCallbacks*, Element*) OVERRIDE;
-
- AtomicString m_name;
- AtomicString m_oldValue;
- AtomicString m_newValue;
+ virtual void dispatch(Element*) OVERRIDE;
};
-class CreatedInvocation : public CustomElementCallbackInvocation {
+void CreatedInvocation::dispatch(Element* element)
+{
+ if (element->inDocument())
+ CustomElementCallbackDispatcher::instance().enqueueEnteredDocumentCallback(callbacks(), element);
+ callbacks()->created(element);
+}
+
+class EnteredLeftDocumentInvocation : public CustomElementCallbackInvocation {
public:
- CreatedInvocation() { }
+ EnteredLeftDocumentInvocation(PassRefPtr<CustomElementLifecycleCallbacks>, CustomElementLifecycleCallbacks::CallbackType which);
+
private:
- virtual void dispatch(CustomElementLifecycleCallbacks*, Element*) OVERRIDE;
+ virtual void dispatch(Element*) OVERRIDE;
+
+ CustomElementLifecycleCallbacks::CallbackType m_which;
};
-PassOwnPtr<CustomElementCallbackInvocation> CustomElementCallbackInvocation::createCreatedInvocation()
+EnteredLeftDocumentInvocation::EnteredLeftDocumentInvocation(PassRefPtr<CustomElementLifecycleCallbacks> callbacks, CustomElementLifecycleCallbacks::CallbackType which)
+ : CustomElementCallbackInvocation(callbacks)
+ , m_which(which)
{
- return adoptPtr(new CreatedInvocation());
+ ASSERT(m_which == CustomElementLifecycleCallbacks::EnteredDocument || m_which == CustomElementLifecycleCallbacks::LeftDocument);
}
-PassOwnPtr<CustomElementCallbackInvocation> CustomElementCallbackInvocation::createAttributeChangedInvocation(const AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue)
+void EnteredLeftDocumentInvocation::dispatch(Element* element)
{
- return adoptPtr(new AttributeChangedInvocation(name, oldValue, newValue));
+ switch (m_which) {
+ case CustomElementLifecycleCallbacks::EnteredDocument:
+ callbacks()->enteredDocument(element);
+ break;
+ case CustomElementLifecycleCallbacks::LeftDocument:
+ callbacks()->leftDocument(element);
+ break;
+ default:
+ ASSERT_NOT_REACHED();
+ }
}
-AttributeChangedInvocation::AttributeChangedInvocation(const AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue)
- : m_name(name)
+class AttributeChangedInvocation : public CustomElementCallbackInvocation {
+public:
+ AttributeChangedInvocation(PassRefPtr<CustomElementLifecycleCallbacks>, const AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue);
+
+private:
+ virtual void dispatch(Element*) OVERRIDE;
+
+ AtomicString m_name;
+ AtomicString m_oldValue;
+ AtomicString m_newValue;
+};
+
+AttributeChangedInvocation::AttributeChangedInvocation(PassRefPtr<CustomElementLifecycleCallbacks> callbacks, const AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue)
+ : CustomElementCallbackInvocation(callbacks)
+ , m_name(name)
, m_oldValue(oldValue)
, m_newValue(newValue)
{
}
-void AttributeChangedInvocation::dispatch(CustomElementLifecycleCallbacks* callbacks, Element* element)
+void AttributeChangedInvocation::dispatch(Element* element)
+{
+ callbacks()->attributeChanged(element, m_name, m_oldValue, m_newValue);
+}
+
+PassOwnPtr<CustomElementCallbackInvocation> CustomElementCallbackInvocation::createInvocation(PassRefPtr<CustomElementLifecycleCallbacks> callbacks, CustomElementLifecycleCallbacks::CallbackType which)
{
- callbacks->attributeChanged(element, m_name, m_oldValue, m_newValue);
+ switch (which) {
+ case CustomElementLifecycleCallbacks::Created:
+ return adoptPtr(new CreatedInvocation(callbacks));
+
+ case CustomElementLifecycleCallbacks::EnteredDocument:
+ case CustomElementLifecycleCallbacks::LeftDocument:
+ return adoptPtr(new EnteredLeftDocumentInvocation(callbacks, which));
+
+ default:
+ ASSERT_NOT_REACHED();
+ return PassOwnPtr<CustomElementCallbackInvocation>();
+ }
}
-void CreatedInvocation::dispatch(CustomElementLifecycleCallbacks* callbacks, Element* element)
+PassOwnPtr<CustomElementCallbackInvocation> CustomElementCallbackInvocation::createAttributeChangedInvocation(PassRefPtr<CustomElementLifecycleCallbacks> callbacks, const AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue)
{
- callbacks->created(element);
+ return adoptPtr(new AttributeChangedInvocation(callbacks, name, oldValue, newValue));
}
} // namespace WebCore
« no previous file with comments | « Source/core/dom/CustomElementCallbackInvocation.h ('k') | Source/core/dom/CustomElementCallbackQueue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698