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

Side by Side Diff: Source/core/dom/CustomElementRegistry.cpp

Issue 14660019: Run Mutation Observer and Custom Element callbacks consistently at microtask checkpoint (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Patch for landing. Created 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/CustomElementRegistry.h ('k') | Source/core/dom/Microtask.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 11 matching lines...) Expand all
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32
33 #include "core/dom/CustomElementRegistry.h" 32 #include "core/dom/CustomElementRegistry.h"
34 33
35 #include "HTMLNames.h" 34 #include "HTMLNames.h"
36 #include "SVGNames.h" 35 #include "SVGNames.h"
37 #include "bindings/v8/CustomElementConstructorBuilder.h" 36 #include "bindings/v8/CustomElementConstructorBuilder.h"
38 #include "bindings/v8/CustomElementHelpers.h" 37 #include "core/dom/CustomElementCallbackDispatcher.h"
39 #include "core/dom/CustomElementDefinition.h" 38 #include "core/dom/CustomElementDefinition.h"
40 #include "core/dom/Document.h" 39 #include "core/dom/Document.h"
41 #include "core/dom/Element.h" 40 #include "core/dom/Element.h"
42 #include "core/html/HTMLElement.h" 41 #include "core/html/HTMLElement.h"
43 #include "core/svg/SVGElement.h" 42 #include "core/svg/SVGElement.h"
44 43
45 namespace WebCore { 44 namespace WebCore {
46 45
47 CustomElementInvocation::CustomElementInvocation(PassRefPtr<CustomElementCallbac k> callback, PassRefPtr<Element> element)
48 : m_callback(callback)
49 , m_element(element)
50 {
51 }
52
53 CustomElementInvocation::~CustomElementInvocation()
54 {
55 }
56
57 void setTypeExtension(Element* element, const AtomicString& typeExtension) 46 void setTypeExtension(Element* element, const AtomicString& typeExtension)
58 { 47 {
59 ASSERT(element); 48 ASSERT(element);
60 if (!typeExtension.isEmpty()) 49 if (!typeExtension.isEmpty())
61 element->setAttribute(HTMLNames::isAttr, typeExtension); 50 element->setAttribute(HTMLNames::isAttr, typeExtension);
62 } 51 }
63 52
64 CustomElementRegistry::CustomElementRegistry(Document* document) 53 CustomElementRegistry::CustomElementRegistry(Document* document)
65 : ContextLifecycleObserver(document) 54 : ContextLifecycleObserver(document)
66 { 55 {
67 } 56 }
68 57
69 CustomElementRegistry::~CustomElementRegistry()
70 {
71 deactivate();
72 }
73
74 static inline bool nameIncludesHyphen(const AtomicString& name) 58 static inline bool nameIncludesHyphen(const AtomicString& name)
75 { 59 {
76 size_t hyphenPosition = name.find('-'); 60 size_t hyphenPosition = name.find('-');
77 return (hyphenPosition != notFound); 61 return (hyphenPosition != notFound);
78 } 62 }
79 63
80 bool CustomElementRegistry::isValidName(const AtomicString& name) 64 bool CustomElementRegistry::isValidName(const AtomicString& name)
81 { 65 {
82 if (!nameIncludesHyphen(name)) 66 if (!nameIncludesHyphen(name))
83 return false; 67 return false;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 131
148 m_definitions.add(definition->type(), definition); 132 m_definitions.add(definition->type(), definition);
149 133
150 // Upgrade elements that were waiting for this definition. 134 // Upgrade elements that were waiting for this definition.
151 CustomElementUpgradeCandidateMap::ElementSet upgradeCandidates = m_candidate s.takeUpgradeCandidatesFor(definition.get()); 135 CustomElementUpgradeCandidateMap::ElementSet upgradeCandidates = m_candidate s.takeUpgradeCandidatesFor(definition.get());
152 constructorBuilder->didRegisterDefinition(definition.get(), upgradeCandidate s); 136 constructorBuilder->didRegisterDefinition(definition.get(), upgradeCandidate s);
153 137
154 for (CustomElementUpgradeCandidateMap::ElementSet::iterator it = upgradeCand idates.begin(); it != upgradeCandidates.end(); ++it) { 138 for (CustomElementUpgradeCandidateMap::ElementSet::iterator it = upgradeCand idates.begin(); it != upgradeCandidates.end(); ++it) {
155 (*it)->setNeedsStyleRecalc(); // :unresolved has changed 139 (*it)->setNeedsStyleRecalc(); // :unresolved has changed
156 140
157 enqueueReadyCallback(lifecycleCallbacks.get(), *it); 141 CustomElementCallbackDispatcher::instance().enqueueReadyCallback(lifecyc leCallbacks.get(), *it);
158 } 142 }
159 } 143 }
160 144
161 bool CustomElementRegistry::isUnresolved(Element* element) const 145 bool CustomElementRegistry::isUnresolved(Element* element) const
162 { 146 {
163 return m_candidates.contains(element); 147 return m_candidates.contains(element);
164 } 148 }
165 149
166 PassRefPtr<CustomElementDefinition> CustomElementRegistry::findFor(Element* elem ent) const 150 PassRefPtr<CustomElementDefinition> CustomElementRegistry::findFor(Element* elem ent) const
167 { 151 {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 { 216 {
233 if (!element->isHTMLElement() && !element->isSVGElement()) 217 if (!element->isHTMLElement() && !element->isSVGElement())
234 return; 218 return;
235 element->setIsCustomElement(); 219 element->setIsCustomElement();
236 RefPtr<CustomElementDefinition> definition = findFor(element); 220 RefPtr<CustomElementDefinition> definition = findFor(element);
237 if (!definition || !definition->isTypeExtension()) { 221 if (!definition || !definition->isTypeExtension()) {
238 // If a definition for a custom tag was available, this type 222 // If a definition for a custom tag was available, this type
239 // extension element will be unresolved in perpetuity. 223 // extension element will be unresolved in perpetuity.
240 didCreateUnresolvedElement(CustomElementDefinition::TypeExtension, type, element); 224 didCreateUnresolvedElement(CustomElementDefinition::TypeExtension, type, element);
241 } else { 225 } else {
242 enqueueReadyCallback(definition->callback(), element); 226 CustomElementCallbackDispatcher::instance().enqueueReadyCallback(definit ion->callback(), element);
243 } 227 }
244 } 228 }
245 229
246 void CustomElementRegistry::didCreateCustomTagElement(CustomElementDefinition* d efinition, Element* element) 230 void CustomElementRegistry::didCreateCustomTagElement(CustomElementDefinition* d efinition, Element* element)
247 { 231 {
248 enqueueReadyCallback(definition->callback(), element); 232 CustomElementCallbackDispatcher::instance().enqueueReadyCallback(definition- >callback(), element);
249 } 233 }
250 234
251 void CustomElementRegistry::didCreateUnresolvedElement(CustomElementDefinition:: CustomElementKind kind, const AtomicString& type, Element* element) 235 void CustomElementRegistry::didCreateUnresolvedElement(CustomElementDefinition:: CustomElementKind kind, const AtomicString& type, Element* element)
252 { 236 {
253 m_candidates.add(kind, type, element); 237 m_candidates.add(kind, type, element);
254 } 238 }
255 239
256 void CustomElementRegistry::customElementWasDestroyed(Element* element) 240 void CustomElementRegistry::customElementWasDestroyed(Element* element)
257 { 241 {
258 ASSERT(element->isCustomElement()); 242 ASSERT(element->isCustomElement());
259 m_candidates.remove(element); 243 m_candidates.remove(element);
260 } 244 }
261 245
262 void CustomElementRegistry::enqueueReadyCallback(CustomElementCallback* callback , Element* element)
263 {
264 if (!callback->hasReady())
265 return;
266
267 bool wasInactive = m_invocations.isEmpty();
268 m_invocations.append(CustomElementInvocation(callback, element));
269 if (wasInactive)
270 activeCustomElementRegistries().add(this);
271 }
272
273 void CustomElementRegistry::deactivate()
274 {
275 ASSERT(m_invocations.isEmpty());
276 if (activeCustomElementRegistries().contains(this))
277 activeCustomElementRegistries().remove(this);
278 }
279
280 inline Document* CustomElementRegistry::document() const 246 inline Document* CustomElementRegistry::document() const
281 { 247 {
282 return toDocument(m_scriptExecutionContext); 248 return toDocument(m_scriptExecutionContext);
283 } 249 }
284 250
285 void CustomElementRegistry::deliverLifecycleCallbacks()
286 {
287 ASSERT(!m_invocations.isEmpty());
288
289 if (!m_invocations.isEmpty()) {
290 Vector<CustomElementInvocation> invocations;
291 m_invocations.swap(invocations);
292
293 for (Vector<CustomElementInvocation>::iterator it = invocations.begin(); it != invocations.end(); ++it)
294 it->callback()->ready(it->element());
295 }
296
297 ASSERT(m_invocations.isEmpty());
298 deactivate();
299 } 251 }
300
301 void CustomElementRegistry::deliverAllLifecycleCallbacks()
302 {
303 while (!activeCustomElementRegistries().isEmpty()) {
304 Vector<RefPtr<CustomElementRegistry> > registries;
305 copyToVector(activeCustomElementRegistries(), registries);
306 activeCustomElementRegistries().clear();
307 for (size_t i = 0; i < registries.size(); ++i)
308 registries[i]->deliverLifecycleCallbacks();
309 }
310 }
311
312 }
OLDNEW
« no previous file with comments | « Source/core/dom/CustomElementRegistry.h ('k') | Source/core/dom/Microtask.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698