| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/dom/custom/CustomElementDefinition.h" | 5 #include "core/dom/custom/CustomElementDefinition.h" |
| 6 | 6 |
| 7 #include "core/dom/Attr.h" | 7 #include "core/dom/Attr.h" |
| 8 #include "core/dom/ExceptionCode.h" | 8 #include "core/dom/ExceptionCode.h" |
| 9 #include "core/dom/custom/CEReactionsScope.h" | |
| 10 #include "core/dom/custom/CustomElement.h" | 9 #include "core/dom/custom/CustomElement.h" |
| 11 #include "core/dom/custom/CustomElementAttributeChangedCallbackReaction.h" | 10 #include "core/dom/custom/CustomElementAttributeChangedCallbackReaction.h" |
| 12 #include "core/dom/custom/CustomElementConnectedCallbackReaction.h" | 11 #include "core/dom/custom/CustomElementConnectedCallbackReaction.h" |
| 13 #include "core/dom/custom/CustomElementDisconnectedCallbackReaction.h" | 12 #include "core/dom/custom/CustomElementDisconnectedCallbackReaction.h" |
| 14 #include "core/dom/custom/CustomElementUpgradeReaction.h" | 13 #include "core/dom/custom/CustomElementUpgradeReaction.h" |
| 15 #include "core/html/HTMLElement.h" | 14 #include "core/html/HTMLElement.h" |
| 16 | 15 |
| 17 namespace blink { | 16 namespace blink { |
| 18 | 17 |
| 19 CustomElementDefinition::CustomElementDefinition( | 18 CustomElementDefinition::CustomElementDefinition( |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 125 |
| 127 CHECK(element->getCustomElementState() == CustomElementState::Custom); | 126 CHECK(element->getCustomElementState() == CustomElementState::Custom); |
| 128 } | 127 } |
| 129 | 128 |
| 130 bool CustomElementDefinition::hasAttributeChangedCallback( | 129 bool CustomElementDefinition::hasAttributeChangedCallback( |
| 131 const QualifiedName& name) | 130 const QualifiedName& name) |
| 132 { | 131 { |
| 133 return m_observedAttributes.contains(name.localName()); | 132 return m_observedAttributes.contains(name.localName()); |
| 134 } | 133 } |
| 135 | 134 |
| 136 static void enqueueReaction(Element* element, CustomElementReaction* reaction) | |
| 137 { | |
| 138 // CEReactionsScope must be created by [CEReactions] in IDL, | |
| 139 // or callers must setup explicitly if it does not go through bindings. | |
| 140 DCHECK(CEReactionsScope::current()); | |
| 141 CEReactionsScope::current()->enqueue(element, reaction); | |
| 142 } | |
| 143 | |
| 144 void CustomElementDefinition::enqueueUpgradeReaction(Element* element) | 135 void CustomElementDefinition::enqueueUpgradeReaction(Element* element) |
| 145 { | 136 { |
| 146 enqueueReaction(element, new CustomElementUpgradeReaction(this)); | 137 CustomElement::enqueue(element, |
| 138 new CustomElementUpgradeReaction(this)); |
| 147 } | 139 } |
| 148 | 140 |
| 149 void CustomElementDefinition::enqueueConnectedCallback(Element* element) | 141 void CustomElementDefinition::enqueueConnectedCallback(Element* element) |
| 150 { | 142 { |
| 151 enqueueReaction(element, new CustomElementConnectedCallbackReaction(this)); | 143 CustomElement::enqueue(element, |
| 144 new CustomElementConnectedCallbackReaction(this)); |
| 152 } | 145 } |
| 153 | 146 |
| 154 void CustomElementDefinition::enqueueDisconnectedCallback(Element* element) | 147 void CustomElementDefinition::enqueueDisconnectedCallback(Element* element) |
| 155 { | 148 { |
| 156 enqueueReaction(element, new CustomElementDisconnectedCallbackReaction(this)
); | 149 CustomElement::enqueue(element, |
| 150 new CustomElementDisconnectedCallbackReaction(this)); |
| 157 } | 151 } |
| 158 | 152 |
| 159 void CustomElementDefinition::enqueueAttributeChangedCallback(Element* element, | 153 void CustomElementDefinition::enqueueAttributeChangedCallback(Element* element, |
| 160 const QualifiedName& name, | 154 const QualifiedName& name, |
| 161 const AtomicString& oldValue, const AtomicString& newValue) | 155 const AtomicString& oldValue, const AtomicString& newValue) |
| 162 { | 156 { |
| 163 enqueueReaction(element, new CustomElementAttributeChangedCallbackReaction(t
his, name, oldValue, newValue)); | 157 CustomElement::enqueue(element, |
| 158 new CustomElementAttributeChangedCallbackReaction(this, name, |
| 159 oldValue, newValue)); |
| 164 } | 160 } |
| 165 | 161 |
| 166 void CustomElementDefinition::enqueueAttributeChangedCallbackForAllAttributes( | 162 void CustomElementDefinition::enqueueAttributeChangedCallbackForAllAttributes( |
| 167 Element* element) | 163 Element* element) |
| 168 { | 164 { |
| 169 // Avoid synchronizing all attributes unless it is needed, while enqueing | 165 // Avoid synchronizing all attributes unless it is needed, while enqueing |
| 170 // callbacks "in order" as defined in the spec. | 166 // callbacks "in order" as defined in the spec. |
| 171 // https://html.spec.whatwg.org/multipage/scripting.html#concept-upgrade-an-
element | 167 // https://html.spec.whatwg.org/multipage/scripting.html#concept-upgrade-an-
element |
| 172 for (const AtomicString& name : m_observedAttributes) | 168 for (const AtomicString& name : m_observedAttributes) |
| 173 element->synchronizeAttribute(name); | 169 element->synchronizeAttribute(name); |
| 174 for (const auto& attribute : element->attributesWithoutUpdate()) { | 170 for (const auto& attribute : element->attributesWithoutUpdate()) { |
| 175 if (hasAttributeChangedCallback(attribute.name())) { | 171 if (hasAttributeChangedCallback(attribute.name())) { |
| 176 enqueueAttributeChangedCallback(element, attribute.name(), | 172 enqueueAttributeChangedCallback(element, attribute.name(), |
| 177 nullAtom, attribute.value()); | 173 nullAtom, attribute.value()); |
| 178 } | 174 } |
| 179 } | 175 } |
| 180 } | 176 } |
| 181 | 177 |
| 182 } // namespace blink | 178 } // namespace blink |
| OLD | NEW |