| 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/CustomElement.h" | 9 #include "core/dom/custom/CustomElement.h" |
| 10 #include "core/dom/custom/CustomElementAdoptedCallbackReaction.h" |
| 10 #include "core/dom/custom/CustomElementAttributeChangedCallbackReaction.h" | 11 #include "core/dom/custom/CustomElementAttributeChangedCallbackReaction.h" |
| 11 #include "core/dom/custom/CustomElementConnectedCallbackReaction.h" | 12 #include "core/dom/custom/CustomElementConnectedCallbackReaction.h" |
| 12 #include "core/dom/custom/CustomElementDisconnectedCallbackReaction.h" | 13 #include "core/dom/custom/CustomElementDisconnectedCallbackReaction.h" |
| 13 #include "core/dom/custom/CustomElementUpgradeReaction.h" | 14 #include "core/dom/custom/CustomElementUpgradeReaction.h" |
| 14 #include "core/html/HTMLElement.h" | 15 #include "core/html/HTMLElement.h" |
| 15 | 16 |
| 16 namespace blink { | 17 namespace blink { |
| 17 | 18 |
| 18 CustomElementDefinition::CustomElementDefinition( | 19 CustomElementDefinition::CustomElementDefinition( |
| 19 const CustomElementDescriptor& descriptor) | 20 const CustomElementDescriptor& descriptor) |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 DCHECK_EQ(m_constructionStack.last(), element); | 122 DCHECK_EQ(m_constructionStack.last(), element); |
| 122 DCHECK_EQ(m_constructionStack.size(), depth); // It's a *stack*. | 123 DCHECK_EQ(m_constructionStack.size(), depth); // It's a *stack*. |
| 123 m_constructionStack.removeLast(); | 124 m_constructionStack.removeLast(); |
| 124 | 125 |
| 125 if (!succeeded) { | 126 if (!succeeded) { |
| 126 element->setCustomElementState(CustomElementState::Failed); | 127 element->setCustomElementState(CustomElementState::Failed); |
| 127 return; | 128 return; |
| 128 } | 129 } |
| 129 | 130 |
| 130 element->setCustomElementState(CustomElementState::Custom); | 131 element->setCustomElementState(CustomElementState::Custom); |
| 132 element->setCustomElementDefinition(this); |
| 131 } | 133 } |
| 132 | 134 |
| 133 bool CustomElementDefinition::hasAttributeChangedCallback( | 135 bool CustomElementDefinition::hasAttributeChangedCallback( |
| 134 const QualifiedName& name) const | 136 const QualifiedName& name) const |
| 135 { | 137 { |
| 136 return m_observedAttributes.contains(name.localName()); | 138 return m_observedAttributes.contains(name.localName()); |
| 137 } | 139 } |
| 138 | 140 |
| 139 bool CustomElementDefinition::hasStyleAttributeChangedCallback() const | 141 bool CustomElementDefinition::hasStyleAttributeChangedCallback() const |
| 140 { | 142 { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 152 CustomElement::enqueue(element, | 154 CustomElement::enqueue(element, |
| 153 new CustomElementConnectedCallbackReaction(this)); | 155 new CustomElementConnectedCallbackReaction(this)); |
| 154 } | 156 } |
| 155 | 157 |
| 156 void CustomElementDefinition::enqueueDisconnectedCallback(Element* element) | 158 void CustomElementDefinition::enqueueDisconnectedCallback(Element* element) |
| 157 { | 159 { |
| 158 CustomElement::enqueue(element, | 160 CustomElement::enqueue(element, |
| 159 new CustomElementDisconnectedCallbackReaction(this)); | 161 new CustomElementDisconnectedCallbackReaction(this)); |
| 160 } | 162 } |
| 161 | 163 |
| 164 void CustomElementDefinition::enqueueAdoptedCallback(Element* element) |
| 165 { |
| 166 CustomElement::enqueue(element, |
| 167 new CustomElementAdoptedCallbackReaction(this)); |
| 168 } |
| 169 |
| 162 void CustomElementDefinition::enqueueAttributeChangedCallback(Element* element, | 170 void CustomElementDefinition::enqueueAttributeChangedCallback(Element* element, |
| 163 const QualifiedName& name, | 171 const QualifiedName& name, |
| 164 const AtomicString& oldValue, const AtomicString& newValue) | 172 const AtomicString& oldValue, const AtomicString& newValue) |
| 165 { | 173 { |
| 166 CustomElement::enqueue(element, | 174 CustomElement::enqueue(element, |
| 167 new CustomElementAttributeChangedCallbackReaction(this, name, | 175 new CustomElementAttributeChangedCallbackReaction(this, name, |
| 168 oldValue, newValue)); | 176 oldValue, newValue)); |
| 169 } | 177 } |
| 170 | 178 |
| 171 void CustomElementDefinition::enqueueAttributeChangedCallbackForAllAttributes( | 179 void CustomElementDefinition::enqueueAttributeChangedCallbackForAllAttributes( |
| 172 Element* element) | 180 Element* element) |
| 173 { | 181 { |
| 174 // Avoid synchronizing all attributes unless it is needed, while enqueing | 182 // Avoid synchronizing all attributes unless it is needed, while enqueing |
| 175 // callbacks "in order" as defined in the spec. | 183 // callbacks "in order" as defined in the spec. |
| 176 // https://html.spec.whatwg.org/multipage/scripting.html#concept-upgrade-an-
element | 184 // https://html.spec.whatwg.org/multipage/scripting.html#concept-upgrade-an-
element |
| 177 for (const AtomicString& name : m_observedAttributes) | 185 for (const AtomicString& name : m_observedAttributes) |
| 178 element->synchronizeAttribute(name); | 186 element->synchronizeAttribute(name); |
| 179 for (const auto& attribute : element->attributesWithoutUpdate()) { | 187 for (const auto& attribute : element->attributesWithoutUpdate()) { |
| 180 if (hasAttributeChangedCallback(attribute.name())) { | 188 if (hasAttributeChangedCallback(attribute.name())) { |
| 181 enqueueAttributeChangedCallback(element, attribute.name(), | 189 enqueueAttributeChangedCallback(element, attribute.name(), |
| 182 nullAtom, attribute.value()); | 190 nullAtom, attribute.value()); |
| 183 } | 191 } |
| 184 } | 192 } |
| 185 } | 193 } |
| 186 | 194 |
| 187 } // namespace blink | 195 } // namespace blink |
| OLD | NEW |