| 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 cdc2f6db42a93e3b572c711c789ead694a4004db..04e25104a2ab5b0711d18dfd066c93c93f5e89db 100644
|
| --- a/third_party/WebKit/Source/core/dom/custom/CustomElementDefinition.cpp
|
| +++ b/third_party/WebKit/Source/core/dom/custom/CustomElementDefinition.cpp
|
| @@ -4,6 +4,7 @@
|
|
|
| #include "core/dom/custom/CustomElementDefinition.h"
|
|
|
| +#include "core/dom/Attr.h"
|
| #include "core/dom/custom/CEReactionsScope.h"
|
| #include "core/dom/custom/CustomElement.h"
|
| #include "core/dom/custom/CustomElementAttributeChangedCallbackReaction.h"
|
| @@ -19,6 +20,14 @@ CustomElementDefinition::CustomElementDefinition(
|
| {
|
| }
|
|
|
| +CustomElementDefinition::CustomElementDefinition(
|
| + const CustomElementDescriptor& descriptor,
|
| + const HashSet<AtomicString>& observedAttributes)
|
| + : m_descriptor(descriptor)
|
| + , m_observedAttributes(observedAttributes)
|
| +{
|
| +}
|
| +
|
| CustomElementDefinition::~CustomElementDefinition()
|
| {
|
| }
|
| @@ -31,14 +40,8 @@ DEFINE_TRACE(CustomElementDefinition)
|
| // https://html.spec.whatwg.org/multipage/scripting.html#concept-upgrade-an-element
|
| void CustomElementDefinition::upgrade(Element* element)
|
| {
|
| - // 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 (!m_observedAttributes.isEmpty())
|
| + enqueueAttributeChangedCallbackForAllAttributes(element);
|
|
|
| if (element->inShadowIncludingDocument() && hasConnectedCallback())
|
| enqueueConnectedCallback(element);
|
| @@ -60,6 +63,12 @@ void CustomElementDefinition::upgrade(Element* element)
|
| CHECK(element->getCustomElementState() == CustomElementState::Custom);
|
| }
|
|
|
| +bool CustomElementDefinition::hasAttributeChangedCallback(
|
| + const QualifiedName& name)
|
| +{
|
| + return m_observedAttributes.contains(name.localName());
|
| +}
|
| +
|
| static void enqueueReaction(Element* element, CustomElementReaction* reaction)
|
| {
|
| // CEReactionsScope must be created by [CEReactions] in IDL,
|
| @@ -90,4 +99,20 @@ void CustomElementDefinition::enqueueAttributeChangedCallback(Element* element,
|
| enqueueReaction(element, new CustomElementAttributeChangedCallbackReaction(this, name, oldValue, newValue));
|
| }
|
|
|
| +void CustomElementDefinition::enqueueAttributeChangedCallbackForAllAttributes(
|
| + Element* element)
|
| +{
|
| + // Avoid synchronizing all attributes unless it is needed, while enqueing
|
| + // callbacks "in order" as defined in the spec.
|
| + // https://html.spec.whatwg.org/multipage/scripting.html#concept-upgrade-an-element
|
| + for (const AtomicString& name : m_observedAttributes)
|
| + element->synchronizeAttribute(name);
|
| + for (const auto& attribute : element->attributesWithoutUpdate()) {
|
| + if (hasAttributeChangedCallback(attribute.name())) {
|
| + enqueueAttributeChangedCallback(element, attribute.name(),
|
| + nullAtom, attribute.value());
|
| + }
|
| + }
|
| +}
|
| +
|
| } // namespace blink
|
|
|