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

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

Issue 2097463002: Add backup element queue to CustomElementReactionStack (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests Created 4 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 unified diff | Download patch
OLDNEW
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"
13 #include "core/dom/custom/CustomElementReactionStack.h"
14 #include "core/dom/custom/CustomElementUpgradeReaction.h" 14 #include "core/dom/custom/CustomElementUpgradeReaction.h"
15 #include "core/html/HTMLElement.h" 15 #include "core/html/HTMLElement.h"
16 16
17 namespace blink { 17 namespace blink {
18 18
19 CustomElementDefinition::CustomElementDefinition( 19 CustomElementDefinition::CustomElementDefinition(
20 const CustomElementDescriptor& descriptor) 20 const CustomElementDescriptor& descriptor)
21 : m_descriptor(descriptor) 21 : m_descriptor(descriptor)
22 { 22 {
23 } 23 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 126
127 CHECK(element->getCustomElementState() == CustomElementState::Custom); 127 CHECK(element->getCustomElementState() == CustomElementState::Custom);
128 } 128 }
129 129
130 bool CustomElementDefinition::hasAttributeChangedCallback( 130 bool CustomElementDefinition::hasAttributeChangedCallback(
131 const QualifiedName& name) 131 const QualifiedName& name)
132 { 132 {
133 return m_observedAttributes.contains(name.localName()); 133 return m_observedAttributes.contains(name.localName());
134 } 134 }
135 135
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) 136 void CustomElementDefinition::enqueueUpgradeReaction(Element* element)
145 { 137 {
146 enqueueReaction(element, new CustomElementUpgradeReaction(this)); 138 CustomElementReactionStack::enqueue(element,
139 new CustomElementUpgradeReaction(this));
147 } 140 }
148 141
149 void CustomElementDefinition::enqueueConnectedCallback(Element* element) 142 void CustomElementDefinition::enqueueConnectedCallback(Element* element)
150 { 143 {
151 enqueueReaction(element, new CustomElementConnectedCallbackReaction(this)); 144 CustomElementReactionStack::enqueue(element,
145 new CustomElementConnectedCallbackReaction(this));
152 } 146 }
153 147
154 void CustomElementDefinition::enqueueDisconnectedCallback(Element* element) 148 void CustomElementDefinition::enqueueDisconnectedCallback(Element* element)
155 { 149 {
156 enqueueReaction(element, new CustomElementDisconnectedCallbackReaction(this) ); 150 CustomElementReactionStack::enqueue(element,
151 new CustomElementDisconnectedCallbackReaction(this));
157 } 152 }
158 153
159 void CustomElementDefinition::enqueueAttributeChangedCallback(Element* element, 154 void CustomElementDefinition::enqueueAttributeChangedCallback(Element* element,
160 const QualifiedName& name, 155 const QualifiedName& name,
161 const AtomicString& oldValue, const AtomicString& newValue) 156 const AtomicString& oldValue, const AtomicString& newValue)
162 { 157 {
163 enqueueReaction(element, new CustomElementAttributeChangedCallbackReaction(t his, name, oldValue, newValue)); 158 CustomElementReactionStack::enqueue(element,
159 new CustomElementAttributeChangedCallbackReaction(this, name,
160 oldValue, newValue));
164 } 161 }
165 162
166 void CustomElementDefinition::enqueueAttributeChangedCallbackForAllAttributes( 163 void CustomElementDefinition::enqueueAttributeChangedCallbackForAllAttributes(
167 Element* element) 164 Element* element)
168 { 165 {
169 // Avoid synchronizing all attributes unless it is needed, while enqueing 166 // Avoid synchronizing all attributes unless it is needed, while enqueing
170 // callbacks "in order" as defined in the spec. 167 // callbacks "in order" as defined in the spec.
171 // https://html.spec.whatwg.org/multipage/scripting.html#concept-upgrade-an- element 168 // https://html.spec.whatwg.org/multipage/scripting.html#concept-upgrade-an- element
172 for (const AtomicString& name : m_observedAttributes) 169 for (const AtomicString& name : m_observedAttributes)
173 element->synchronizeAttribute(name); 170 element->synchronizeAttribute(name);
174 for (const auto& attribute : element->attributesWithoutUpdate()) { 171 for (const auto& attribute : element->attributesWithoutUpdate()) {
175 if (hasAttributeChangedCallback(attribute.name())) { 172 if (hasAttributeChangedCallback(attribute.name())) {
176 enqueueAttributeChangedCallback(element, attribute.name(), 173 enqueueAttributeChangedCallback(element, attribute.name(),
177 nullAtom, attribute.value()); 174 nullAtom, attribute.value());
178 } 175 }
179 } 176 }
180 } 177 }
181 178
182 } // namespace blink 179 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698