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

Unified Diff: third_party/WebKit/Source/core/dom/custom/CustomElementDefinition.cpp

Issue 2058823002: Implement callback reactions for Custom Elements V1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@stack-ce
Patch Set: dominicc review Created 4 years, 6 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: third_party/WebKit/Source/core/dom/custom/CustomElementDefinition.cpp
diff --git a/third_party/WebKit/Source/core/dom/custom/CustomElementDefinition.cpp b/third_party/WebKit/Source/core/dom/custom/CustomElementDefinition.cpp
index b261c80514f8de4966a4f07f43eb41362d471fe0..cdc2f6db42a93e3b572c711c789ead694a4004db 100644
--- a/third_party/WebKit/Source/core/dom/custom/CustomElementDefinition.cpp
+++ b/third_party/WebKit/Source/core/dom/custom/CustomElementDefinition.cpp
@@ -4,6 +4,13 @@
#include "core/dom/custom/CustomElementDefinition.h"
+#include "core/dom/custom/CEReactionsScope.h"
+#include "core/dom/custom/CustomElement.h"
+#include "core/dom/custom/CustomElementAttributeChangedCallbackReaction.h"
+#include "core/dom/custom/CustomElementConnectedCallbackReaction.h"
+#include "core/dom/custom/CustomElementDisconnectedCallbackReaction.h"
+#include "core/dom/custom/CustomElementUpgradeReaction.h"
+
namespace blink {
CustomElementDefinition::CustomElementDefinition(
@@ -24,10 +31,17 @@ DEFINE_TRACE(CustomElementDefinition)
// https://html.spec.whatwg.org/multipage/scripting.html#concept-upgrade-an-element
void CustomElementDefinition::upgrade(Element* element)
{
- // TODO(dominicc): When the attributeChangedCallback is implemented,
- // enqueue reactions for attributes here.
- // TODO(dominicc): When the connectedCallback is implemented, enqueue
- // reactions here, if applicable.
+ // TODO(kojii): This should be reversed by exposing observedAttributes from
+ // ScriptCustomElementDefinition, because Element::attributes() requires
+ // attribute synchronizations, and generally elements have more attributes
+ // than custom elements observe.
+ for (const auto& attribute : element->attributes()) {
+ if (hasAttributeChangedCallback(attribute.name()))
+ enqueueAttributeChangedCallback(element, attribute.name(), nullAtom, attribute.value());
+ }
+
+ if (element->inShadowIncludingDocument() && hasConnectedCallback())
+ enqueueConnectedCallback(element);
m_constructionStack.append(element);
size_t depth = m_constructionStack.size();
@@ -46,4 +60,34 @@ void CustomElementDefinition::upgrade(Element* element)
CHECK(element->getCustomElementState() == CustomElementState::Custom);
}
+static void enqueueReaction(Element* element, CustomElementReaction* reaction)
+{
+ // CEReactionsScope must be created by [CEReactions] in IDL,
+ // or callers must setup explicitly if it does not go through bindings.
+ DCHECK(CEReactionsScope::current());
+ CEReactionsScope::current()->enqueue(element, reaction);
+}
+
+void CustomElementDefinition::enqueueUpgradeReaction(Element* element)
+{
+ enqueueReaction(element, new CustomElementUpgradeReaction(this));
+}
+
+void CustomElementDefinition::enqueueConnectedCallback(Element* element)
+{
+ enqueueReaction(element, new CustomElementConnectedCallbackReaction(this));
+}
+
+void CustomElementDefinition::enqueueDisconnectedCallback(Element* element)
+{
+ enqueueReaction(element, new CustomElementDisconnectedCallbackReaction(this));
+}
+
+void CustomElementDefinition::enqueueAttributeChangedCallback(Element* element,
+ const QualifiedName& name,
+ const AtomicString& oldValue, const AtomicString& newValue)
+{
+ enqueueReaction(element, new CustomElementAttributeChangedCallbackReaction(this, name, oldValue, newValue));
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698