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

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

Issue 14846002: Implement the Custom Elements :unresolved pseudoclass (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Adds a test and fixes style sharing. Created 7 years, 7 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) 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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 if (!CustomElementHelpers::initializeConstructorWrapper(constructor.get(), p rototypeValue, state)) { 163 if (!CustomElementHelpers::initializeConstructorWrapper(constructor.get(), p rototypeValue, state)) {
164 ec = INVALID_STATE_ERR; 164 ec = INVALID_STATE_ERR;
165 return 0; 165 return 0;
166 } 166 }
167 167
168 m_definitions.add(definition->type(), definition); 168 m_definitions.add(definition->type(), definition);
169 169
170 return constructor.release(); 170 return constructor.release();
171 } 171 }
172 172
173 bool CustomElementRegistry::isUnresolved(Element* element) const
174 {
175 return m_unresolvedElements.contains(element);
176 }
177
173 PassRefPtr<CustomElementDefinition> CustomElementRegistry::findFor(Element* elem ent) const 178 PassRefPtr<CustomElementDefinition> CustomElementRegistry::findFor(Element* elem ent) const
174 { 179 {
175 ASSERT(element->document()->registry() == this); 180 ASSERT(element->document()->registry() == this);
176 181
177 if (!element->isCustomElement()) 182 if (!element->isCustomElement())
178 return 0; 183 return 0;
179 184
180 // When a custom tag and a type extension are provided as element 185 // When a custom tag and a type extension are provided as element
181 // names at the same time, the custom tag takes precedence. 186 // names at the same time, the custom tag takes precedence.
182 if (isCustomTagName(element->localName())) { 187 if (isCustomTagName(element->localName())) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 #if ENABLE(SVG) 224 #if ENABLE(SVG)
220 else if (SVGNames::svgNamespaceURI == tagName.namespaceURI()) 225 else if (SVGNames::svgNamespaceURI == tagName.namespaceURI())
221 element = SVGElement::create(tagName, document()); 226 element = SVGElement::create(tagName, document());
222 #endif 227 #endif
223 else 228 else
224 element = Element::create(tagName, document()); 229 element = Element::create(tagName, document());
225 230
226 element->setIsCustomElement(); 231 element->setIsCustomElement();
227 232
228 RefPtr<CustomElementDefinition> definition = findAndCheckNamespace(tagName.l ocalName(), tagName.namespaceURI()); 233 RefPtr<CustomElementDefinition> definition = findAndCheckNamespace(tagName.l ocalName(), tagName.namespaceURI());
229 if (definition && !definition->isTypeExtension()) 234 if (!definition || definition->isTypeExtension()) {
235 // If a definition for a type extension was available, this
236 // custom tag element will be unresolved in perpetuity.
237 didCreateUnresolvedElement(element.get());
238 } else {
230 didCreateCustomTagElement(element.get()); 239 didCreateCustomTagElement(element.get());
240 }
231 241
232 return element.release(); 242 return element.release();
233 } 243 }
234 244
235 void CustomElementRegistry::didGiveTypeExtension(Element* element) 245 void CustomElementRegistry::didGiveTypeExtension(Element* element)
236 { 246 {
237 element->setIsCustomElement(); 247 element->setIsCustomElement();
238 RefPtr<CustomElementDefinition> definition = findFor(element); 248 RefPtr<CustomElementDefinition> definition = findFor(element);
239 if (!definition || !definition->isTypeExtension()) 249 if (!definition || !definition->isTypeExtension()) {
240 return; 250 // If a definition for a custom tag was available, this type
241 activate(CustomElementInvocation(element)); 251 // extension element will be unresolved in perpetuity.
252 didCreateUnresolvedElement(element);
253 } else {
254 activate(CustomElementInvocation(element));
255 }
242 } 256 }
243 257
244 void CustomElementRegistry::didCreateCustomTagElement(Element* element) 258 void CustomElementRegistry::didCreateCustomTagElement(Element* element)
245 { 259 {
246 activate(CustomElementInvocation(element)); 260 activate(CustomElementInvocation(element));
247 } 261 }
248 262
263 void CustomElementRegistry::didCreateUnresolvedElement(Element* element)
264 {
265 m_unresolvedElements.add(element);
266 }
267
268 void CustomElementRegistry::customElementWasDestroyed(Element* element)
269 {
270 ASSERT(element->isCustomElement());
271 m_unresolvedElements.remove(element);
272 }
273
249 void CustomElementRegistry::activate(const CustomElementInvocation& invocation) 274 void CustomElementRegistry::activate(const CustomElementInvocation& invocation)
250 { 275 {
251 bool wasInactive = m_invocations.isEmpty(); 276 bool wasInactive = m_invocations.isEmpty();
252 m_invocations.append(invocation); 277 m_invocations.append(invocation);
253 if (wasInactive) 278 if (wasInactive)
254 activeCustomElementRegistries().add(this); 279 activeCustomElementRegistries().add(this);
255 } 280 }
256 281
257 void CustomElementRegistry::deactivate() 282 void CustomElementRegistry::deactivate()
258 { 283 {
(...skipping 26 matching lines...) Expand all
285 while (!activeCustomElementRegistries().isEmpty()) { 310 while (!activeCustomElementRegistries().isEmpty()) {
286 Vector<RefPtr<CustomElementRegistry> > registries; 311 Vector<RefPtr<CustomElementRegistry> > registries;
287 copyToVector(activeCustomElementRegistries(), registries); 312 copyToVector(activeCustomElementRegistries(), registries);
288 activeCustomElementRegistries().clear(); 313 activeCustomElementRegistries().clear();
289 for (size_t i = 0; i < registries.size(); ++i) 314 for (size_t i = 0; i < registries.size(); ++i)
290 registries[i]->deliverLifecycleCallbacks(); 315 registries[i]->deliverLifecycleCallbacks();
291 } 316 }
292 } 317 }
293 318
294 } 319 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698