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

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

Issue 23009004: Process Custom Elements in post-order. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 4 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 bool CustomElement::isCustomTagName(const AtomicString& localName) 86 bool CustomElement::isCustomTagName(const AtomicString& localName)
87 { 87 {
88 return isValidTypeName(localName); 88 return isValidTypeName(localName);
89 } 89 }
90 90
91 void CustomElement::define(Element* element, PassRefPtr<CustomElementDefinition> passDefinition) 91 void CustomElement::define(Element* element, PassRefPtr<CustomElementDefinition> passDefinition)
92 { 92 {
93 RefPtr<CustomElementDefinition> definition(passDefinition); 93 RefPtr<CustomElementDefinition> definition(passDefinition);
94 element->setCustomElementState(Element::Defined); 94 element->setCustomElementState(Element::Defined);
95 definitions().add(element, definition); 95 definitions().add(element, definition);
96 CustomElementCallbackScheduler::scheduleCreatedCallback(definition->callback s(), element); 96 if (!elementsBeingParsed().contains(element))
dglazkov 2013/08/13 16:22:06 I am trying to figure out why we need this check a
97 CustomElementCallbackScheduler::scheduleCreatedCallback(definition->call backs(), element);
97 } 98 }
98 99
99 CustomElementDefinition* CustomElement::definitionFor(Element* element) 100 CustomElementDefinition* CustomElement::definitionFor(Element* element)
100 { 101 {
101 return definitions().get(element); 102 return definitions().get(element);
102 } 103 }
103 104
105 void CustomElement::finishedParsingChildren(Element* element)
106 {
107 switch (element->customElementState()) {
108 case Node::NotCustomElement:
109 case Node::Upgraded:
110 ASSERT_NOT_REACHED();
111 return;
112
113 case Node::UpgradeCandidate:
114 CustomElementUpgradeCandidateMap::elementFinishedParsingChildren(element );
115 setFinishedParsing(element);
116 return;
117
118 case Node::Defined:
119 setFinishedParsing(element);
120 CustomElementCallbackScheduler::scheduleCreatedCallback(definitionFor(el ement)->callbacks(), element);
121 return;
122 }
123 }
124
104 void CustomElement::attributeDidChange(Element* element, const AtomicString& nam e, const AtomicString& oldValue, const AtomicString& newValue) 125 void CustomElement::attributeDidChange(Element* element, const AtomicString& nam e, const AtomicString& oldValue, const AtomicString& newValue)
105 { 126 {
106 ASSERT(element->customElementState() == Element::Upgraded); 127 ASSERT(element->customElementState() == Element::Upgraded);
107 CustomElementCallbackScheduler::scheduleAttributeChangedCallback(definitions ().get(element)->callbacks(), element, name, oldValue, newValue); 128 CustomElementCallbackScheduler::scheduleAttributeChangedCallback(definitions ().get(element)->callbacks(), element, name, oldValue, newValue);
108 } 129 }
109 130
110 void CustomElement::didEnterDocument(Element* element, Document* document) 131 void CustomElement::didEnterDocument(Element* element, Document* document)
111 { 132 {
112 ASSERT(element->customElementState() == Element::Upgraded); 133 ASSERT(element->customElementState() == Element::Upgraded);
113 if (!document->defaultView()) 134 if (!document->defaultView())
(...skipping 11 matching lines...) Expand all
125 146
126 void CustomElement::wasDestroyed(Element* element) 147 void CustomElement::wasDestroyed(Element* element)
127 { 148 {
128 switch (element->customElementState()) { 149 switch (element->customElementState()) {
129 case Element::NotCustomElement: 150 case Element::NotCustomElement:
130 ASSERT_NOT_REACHED(); 151 ASSERT_NOT_REACHED();
131 break; 152 break;
132 153
133 case Element::UpgradeCandidate: 154 case Element::UpgradeCandidate:
134 CustomElementUpgradeCandidateMap::elementWasDestroyed(element); 155 CustomElementUpgradeCandidateMap::elementWasDestroyed(element);
156 elementsBeingParsed().remove(element);
135 break; 157 break;
136 158
137 case Element::Defined: 159 case Element::Defined:
160 elementsBeingParsed().remove(element);
161 definitions().remove(element);
162 break;
163
138 case Element::Upgraded: 164 case Element::Upgraded:
139 definitions().remove(element); 165 definitions().remove(element);
140 break; 166 break;
141 } 167 }
142 } 168 }
143 169
144 void CustomElement::DefinitionMap::add(Element* element, PassRefPtr<CustomElemen tDefinition> definition) 170 void CustomElement::DefinitionMap::add(Element* element, PassRefPtr<CustomElemen tDefinition> definition)
145 { 171 {
146 ASSERT(definition.get()); 172 ASSERT(definition.get());
147 DefinitionMap::ElementDefinitionHashMap::AddResult result = m_definitions.ad d(element, definition); 173 DefinitionMap::ElementDefinitionHashMap::AddResult result = m_definitions.ad d(element, definition);
(...skipping 11 matching lines...) Expand all
159 ASSERT(it != m_definitions.end()); 185 ASSERT(it != m_definitions.end());
160 return it->value.get(); 186 return it->value.get();
161 } 187 }
162 188
163 CustomElement::DefinitionMap& CustomElement::definitions() 189 CustomElement::DefinitionMap& CustomElement::definitions()
164 { 190 {
165 DEFINE_STATIC_LOCAL(DefinitionMap, map, ()); 191 DEFINE_STATIC_LOCAL(DefinitionMap, map, ());
166 return map; 192 return map;
167 } 193 }
168 194
195 CustomElement::ElementSet& CustomElement::elementsBeingParsed()
196 {
197 DEFINE_STATIC_LOCAL(ElementSet, set, ());
198 return set;
199 }
200
201 void CustomElement::setBeingParsed(Element* element)
202 {
203 ElementSet::AddResult result = elementsBeingParsed().add(element);
204 ASSERT(result.isNewEntry);
205 }
206
207 void CustomElement::setFinishedParsing(Element* element)
208 {
209 ElementSet::iterator it = elementsBeingParsed().find(element);
210 ASSERT(it != elementsBeingParsed().end());
211 elementsBeingParsed().remove(it);
212 }
213
169 } // namespace WebCore 214 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698