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

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

Issue 19900002: Use the two Custom Elements node bits to explicitly represent four states. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Play nice with MSVC. Created 7 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 | Annotate | Revision Log
« no previous file with comments | « Source/bindings/v8/V8CustomElementLifecycleCallbacks.cpp ('k') | Source/core/dom/Element.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) 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 138
139 if (HTMLNames::xhtmlNamespaceURI == tagName.namespaceURI()) { 139 if (HTMLNames::xhtmlNamespaceURI == tagName.namespaceURI()) {
140 element = HTMLElement::create(tagName, document); 140 element = HTMLElement::create(tagName, document);
141 } else if (SVGNames::svgNamespaceURI == tagName.namespaceURI()) { 141 } else if (SVGNames::svgNamespaceURI == tagName.namespaceURI()) {
142 element = SVGElement::create(tagName, document); 142 element = SVGElement::create(tagName, document);
143 } else { 143 } else {
144 // XML elements are not custom elements, so return early. 144 // XML elements are not custom elements, so return early.
145 return Element::create(tagName, document); 145 return Element::create(tagName, document);
146 } 146 }
147 147
148 element->setIsCustomElement();
149 resolve(element.get()); 148 resolve(element.get());
150 return element.release(); 149 return element.release();
151 } 150 }
152 151
153 void ActiveRegistrationContext::didGiveTypeExtension(Element* element) 152 void ActiveRegistrationContext::didGiveTypeExtension(Element* element)
154 { 153 {
155 resolve(element); 154 resolve(element);
156 } 155 }
157 156
158 void ActiveRegistrationContext::resolve(Element* element) 157 void ActiveRegistrationContext::resolve(Element* element)
159 { 158 {
160 ASSERT(element->isCustomElement());
161 ASSERT(!element->isUpgradedCustomElement());
162 const CustomElementDescriptor& descriptor = describe(element); 159 const CustomElementDescriptor& descriptor = describe(element);
163 CustomElementDefinition* definition = m_registry.find(descriptor); 160 CustomElementDefinition* definition = m_registry.find(descriptor);
164 if (definition) 161 if (definition)
165 didResolveElement(definition, element); 162 didResolveElement(definition, element);
166 else 163 else
167 didCreateUnresolvedElement(descriptor, element); 164 didCreateUnresolvedElement(descriptor, element);
168 } 165 }
169 166
170 void ActiveRegistrationContext::didResolveElement(CustomElementDefinition* defin ition, Element* element) 167 void ActiveRegistrationContext::didResolveElement(CustomElementDefinition* defin ition, Element* element)
171 { 168 {
169 element->setCustomElementState(Element::Defined);
172 CustomElementCallbackScheduler::scheduleCreatedCallback(definition->callback s(), element); 170 CustomElementCallbackScheduler::scheduleCreatedCallback(definition->callback s(), element);
173 } 171 }
174 172
175 void ActiveRegistrationContext::didCreateUnresolvedElement(const CustomElementDe scriptor& descriptor, Element* element) 173 void ActiveRegistrationContext::didCreateUnresolvedElement(const CustomElementDe scriptor& descriptor, Element* element)
176 { 174 {
175 element->setCustomElementState(Element::UpgradeCandidate);
177 m_candidates.add(descriptor, element); 176 m_candidates.add(descriptor, element);
178 } 177 }
179 178
180 CustomElementDefinition* ActiveRegistrationContext::definitionFor(Element* eleme nt) const 179 CustomElementDefinition* ActiveRegistrationContext::definitionFor(Element* eleme nt) const
181 { 180 {
181 ASSERT(element->customElementState() == Element::Defined || element->customE lementState() == Element::Upgraded);
182 ASSERT(element->document()->registrationContext() == this); 182 ASSERT(element->document()->registrationContext() == this);
183 const CustomElementDescriptor& descriptor = describe(element); 183 const CustomElementDescriptor& descriptor = describe(element);
184 return m_registry.find(descriptor); 184 return m_registry.find(descriptor);
185 } 185 }
186 186
187 void ActiveRegistrationContext::customElementAttributeDidChange(Element* element , const AtomicString& name, const AtomicString& oldValue, const AtomicString& ne wValue) 187 void ActiveRegistrationContext::customElementAttributeDidChange(Element* element , const AtomicString& name, const AtomicString& oldValue, const AtomicString& ne wValue)
188 { 188 {
189 ASSERT(element->isUpgradedCustomElement()); 189 ASSERT(element->customElementState() == Element::Upgraded);
190 CustomElementDefinition* definition = definitionFor(element); 190 CustomElementDefinition* definition = definitionFor(element);
191 CustomElementCallbackScheduler::scheduleAttributeChangedCallback(definition- >callbacks(), element, name, oldValue, newValue); 191 CustomElementCallbackScheduler::scheduleAttributeChangedCallback(definition- >callbacks(), element, name, oldValue, newValue);
192 } 192 }
193 193
194 void ActiveRegistrationContext::customElementDidEnterDocument(Element* element) 194 void ActiveRegistrationContext::customElementDidEnterDocument(Element* element)
195 { 195 {
196 ASSERT(element->isUpgradedCustomElement()); 196 ASSERT(element->customElementState() == Element::Upgraded);
197 CustomElementDefinition* definition = definitionFor(element); 197 CustomElementDefinition* definition = definitionFor(element);
198 CustomElementCallbackScheduler::scheduleEnteredDocumentCallback(definition-> callbacks(), element); 198 CustomElementCallbackScheduler::scheduleEnteredDocumentCallback(definition-> callbacks(), element);
199 } 199 }
200 200
201 void ActiveRegistrationContext::customElementDidLeaveDocument(Element* element) 201 void ActiveRegistrationContext::customElementDidLeaveDocument(Element* element)
202 { 202 {
203 ASSERT(element->isUpgradedCustomElement()); 203 ASSERT(element->customElementState() == Element::Upgraded);
204 CustomElementDefinition* definition = definitionFor(element); 204 CustomElementDefinition* definition = definitionFor(element);
205 CustomElementCallbackScheduler::scheduleLeftDocumentCallback(definition->cal lbacks(), element); 205 CustomElementCallbackScheduler::scheduleLeftDocumentCallback(definition->cal lbacks(), element);
206 } 206 }
207 207
208 void ActiveRegistrationContext::customElementIsBeingDestroyed(Element* element) 208 void ActiveRegistrationContext::customElementIsBeingDestroyed(Element* element)
209 { 209 {
210 m_candidates.remove(element); 210 m_candidates.remove(element);
211 CustomElementRegistrationContext::customElementIsBeingDestroyed(element); 211 CustomElementRegistrationContext::customElementIsBeingDestroyed(element);
212 } 212 }
213 213
(...skipping 25 matching lines...) Expand all
239 return Document::isValidName(name.string()); 239 return Document::isValidName(name.string());
240 } 240 }
241 241
242 bool CustomElementRegistrationContext::isCustomTagName(const AtomicString& local Name) 242 bool CustomElementRegistrationContext::isCustomTagName(const AtomicString& local Name)
243 { 243 {
244 return isValidTypeName(localName); 244 return isValidTypeName(localName);
245 } 245 }
246 246
247 CustomElementDescriptor CustomElementRegistrationContext::describe(Element* elem ent) 247 CustomElementDescriptor CustomElementRegistrationContext::describe(Element* elem ent)
248 { 248 {
249 ASSERT(element->isCustomElement());
250
251 // If an element has a custom tag name it takes precedence over 249 // If an element has a custom tag name it takes precedence over
252 // the "is" attribute (if any). 250 // the "is" attribute (if any).
253 const AtomicString& type = isCustomTagName(element->localName()) 251 const AtomicString& type = isCustomTagName(element->localName())
254 ? element->localName() 252 ? element->localName()
255 : typeExtension(element); 253 : typeExtension(element);
256 254
257 return CustomElementDescriptor(type, element->namespaceURI(), element->local Name()); 255 return CustomElementDescriptor(type, element->namespaceURI(), element->local Name());
258 } 256 }
259 257
260 void CustomElementRegistrationContext::setIsAttributeAndTypeExtension(Element* e lement, const AtomicString& type) 258 void CustomElementRegistrationContext::setIsAttributeAndTypeExtension(Element* e lement, const AtomicString& type)
261 { 259 {
262 ASSERT(element); 260 ASSERT(element);
263 ASSERT(!type.isEmpty()); 261 ASSERT(!type.isEmpty());
264 element->setAttribute(HTMLNames::isAttr, type); 262 element->setAttribute(HTMLNames::isAttr, type);
265 setTypeExtension(element, type); 263 setTypeExtension(element, type);
266 } 264 }
267 265
268 void CustomElementRegistrationContext::setTypeExtension(Element* element, const AtomicString& type) 266 void CustomElementRegistrationContext::setTypeExtension(Element* element, const AtomicString& type)
269 { 267 {
270 if (!element->isHTMLElement() && !element->isSVGElement()) 268 if (!element->isHTMLElement() && !element->isSVGElement())
271 return; 269 return;
272 270
273 if (isCustomTagName(element->localName())) 271 if (isCustomTagName(element->localName()))
274 return; // custom tags take precedence over type extensions 272 return; // custom tags take precedence over type extensions
275 273
276 TypeExtensionMap::AddResult result = typeExtensionMap()->add(element, type); 274 TypeExtensionMap::AddResult result = typeExtensionMap()->add(element, type);
277 ASSERT(result.isNewEntry); // Type extensions should only be set once 275 ASSERT(result.isNewEntry); // Type extensions should only be set once
278 element->setIsCustomElement();
279 element->document()->registrationContext()->didGiveTypeExtension(element); 276 element->document()->registrationContext()->didGiveTypeExtension(element);
280 } 277 }
281 278
282 void CustomElementRegistrationContext::customElementIsBeingDestroyed(Element* el ement) 279 void CustomElementRegistrationContext::customElementIsBeingDestroyed(Element* el ement)
283 { 280 {
284 ASSERT(element->isCustomElement()); 281 ASSERT(element->isCustomElement());
285 typeExtensionMap()->remove(element); 282 typeExtensionMap()->remove(element);
286 } 283 }
287 284
288 const AtomicString& CustomElementRegistrationContext::typeExtension(Element* ele ment) 285 const AtomicString& CustomElementRegistrationContext::typeExtension(Element* ele ment)
289 { 286 {
290 TypeExtensionMap::const_iterator it = typeExtensionMap()->find(element); 287 TypeExtensionMap::const_iterator it = typeExtensionMap()->find(element);
291 ASSERT(it != typeExtensionMap()->end()); 288 ASSERT(it != typeExtensionMap()->end());
292 return it->value; 289 return it->value;
293 } 290 }
294 291
295 CustomElementRegistrationContext::TypeExtensionMap* CustomElementRegistrationCon text::typeExtensionMap() 292 CustomElementRegistrationContext::TypeExtensionMap* CustomElementRegistrationCon text::typeExtensionMap()
296 { 293 {
297 DEFINE_STATIC_LOCAL(TypeExtensionMap, typeExtensionMap, ()); 294 DEFINE_STATIC_LOCAL(TypeExtensionMap, typeExtensionMap, ());
298 return &typeExtensionMap; 295 return &typeExtensionMap;
299 } 296 }
300 297
301 } // namespace WebCore 298 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/bindings/v8/V8CustomElementLifecycleCallbacks.cpp ('k') | Source/core/dom/Element.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698