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

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

Issue 106903007: Let unresolved custom element go through CustomElementCallbackQueue. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Updated. Created 7 years 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 void CustomElementRegistrationContext::registerElement(Document* document, Custo mElementConstructorBuilder* constructorBuilder, const AtomicString& type, Custom Element::NameSet validNames, ExceptionState& exceptionState) 48 void CustomElementRegistrationContext::registerElement(Document* document, Custo mElementConstructorBuilder* constructorBuilder, const AtomicString& type, Custom Element::NameSet validNames, ExceptionState& exceptionState)
49 { 49 {
50 CustomElementDefinition* definition = m_registry.registerElement(document, c onstructorBuilder, type, validNames, exceptionState); 50 CustomElementDefinition* definition = m_registry.registerElement(document, c onstructorBuilder, type, validNames, exceptionState);
51 51
52 if (!definition) 52 if (!definition)
53 return; 53 return;
54 54
55 // Upgrade elements that were waiting for this definition. 55 // Upgrade elements that were waiting for this definition.
56 const CustomElementUpgradeCandidateMap::ElementSet& upgradeCandidates = m_ca ndidates.takeUpgradeCandidatesFor(definition->descriptor()); 56 const CustomElementUpgradeCandidateMap::ElementSet& upgradeCandidates = m_ca ndidates.takeUpgradeCandidatesFor(definition->descriptor());
57 for (CustomElementUpgradeCandidateMap::ElementSet::const_iterator it = upgra deCandidates.begin(); it != upgradeCandidates.end(); ++it) 57 for (CustomElementUpgradeCandidateMap::ElementSet::const_iterator it = upgra deCandidates.begin(); it != upgradeCandidates.end(); ++it)
58 didResolveElement(definition, *it); 58 CustomElement::define(*it, definition);
59 } 59 }
60 60
61 PassRefPtr<Element> CustomElementRegistrationContext::createCustomTagElement(Doc ument& document, const QualifiedName& tagName) 61 PassRefPtr<Element> CustomElementRegistrationContext::createCustomTagElement(Doc ument& document, const QualifiedName& tagName)
62 { 62 {
63 ASSERT(CustomElement::isValidName(tagName.localName())); 63 ASSERT(CustomElement::isValidName(tagName.localName()));
64 64
65 RefPtr<Element> element; 65 RefPtr<Element> element;
66 66
67 if (HTMLNames::xhtmlNamespaceURI == tagName.namespaceURI()) { 67 if (HTMLNames::xhtmlNamespaceURI == tagName.namespaceURI()) {
68 element = HTMLElement::create(tagName, document); 68 element = HTMLElement::create(tagName, document);
69 } else if (SVGNames::svgNamespaceURI == tagName.namespaceURI()) { 69 } else if (SVGNames::svgNamespaceURI == tagName.namespaceURI()) {
70 element = SVGUnknownElement::create(tagName, document); 70 element = SVGUnknownElement::create(tagName, document);
71 } else { 71 } else {
72 // XML elements are not custom elements, so return early. 72 // XML elements are not custom elements, so return early.
73 return Element::create(tagName, &document); 73 return Element::create(tagName, &document);
74 } 74 }
75 75
76 element->setCustomElementState(Element::WaitingForUpgrade); 76 element->setCustomElementState(Element::WaitingForUpgrade);
77 resolve(element.get(), nullAtom); 77 scheduleResolution(element.get(), nullAtom);
78 return element.release(); 78 return element.release();
79 } 79 }
80 80
81 void CustomElementRegistrationContext::didGiveTypeExtension(Element* element, co nst AtomicString& type) 81 void CustomElementRegistrationContext::didGiveTypeExtension(Element* element, co nst AtomicString& type)
82 { 82 {
83 resolve(element, type); 83 scheduleResolution(element, type);
84 } 84 }
85 85
86 void CustomElementRegistrationContext::resolve(Element* element, const AtomicStr ing& typeExtension) 86 void CustomElementRegistrationContext::scheduleResolution(Element* element, cons t AtomicString& typeExtension)
87 { 87 {
88 // If an element has a custom tag name it takes precedence over 88 // If an element has a custom tag name it takes precedence over
89 // the "is" attribute (if any). 89 // the "is" attribute (if any).
90 const AtomicString& type = CustomElement::isValidName(element->localName()) 90 const AtomicString& type = CustomElement::isValidName(element->localName())
91 ? element->localName() 91 ? element->localName()
92 : typeExtension; 92 : typeExtension;
93 ASSERT(!type.isNull()); 93 ASSERT(!type.isNull());
94 94
95 CustomElementDescriptor descriptor(type, element->namespaceURI(), element->l ocalName()); 95 CustomElementDescriptor descriptor(type, element->namespaceURI(), element->l ocalName());
96 CustomElementDefinition* definition = m_registry.find(descriptor); 96 ASSERT(element->customElementState() == Element::WaitingForUpgrade);
97 if (definition) 97 CustomElementCallbackScheduler::scheduleResolutionStep(descriptor, element);
98 didResolveElement(definition, element);
99 else
100 didCreateUnresolvedElement(descriptor, element);
101 } 98 }
102 99
103 void CustomElementRegistrationContext::didResolveElement(CustomElementDefinition * definition, Element* element) 100 void CustomElementRegistrationContext::resolve(Element* element, const CustomEle mentDescriptor& descriptor)
104 { 101 {
105 CustomElement::define(element, definition); 102 CustomElementDefinition* definition = m_registry.find(descriptor);
106 } 103 if (definition) {
107 104 CustomElement::define(element, definition);
dominicc (has gone to gerrit) 2013/12/18 08:46:41 I suppose the semantics of this works because the
108 void CustomElementRegistrationContext::didCreateUnresolvedElement(const CustomEl ementDescriptor& descriptor, Element* element) 105 } else {
109 { 106 ASSERT(element->customElementState() == Element::WaitingForUpgrade);
110 ASSERT(element->customElementState() == Element::WaitingForUpgrade); 107 m_candidates.add(descriptor, element);
111 m_candidates.add(descriptor, element); 108 }
112 } 109 }
113 110
114 PassRefPtr<CustomElementRegistrationContext> CustomElementRegistrationContext::c reate() 111 PassRefPtr<CustomElementRegistrationContext> CustomElementRegistrationContext::c reate()
115 { 112 {
116 return adoptRef(new CustomElementRegistrationContext()); 113 return adoptRef(new CustomElementRegistrationContext());
117 } 114 }
118 115
119 void CustomElementRegistrationContext::setIsAttributeAndTypeExtension(Element* e lement, const AtomicString& type) 116 void CustomElementRegistrationContext::setIsAttributeAndTypeExtension(Element* e lement, const AtomicString& type)
120 { 117 {
121 ASSERT(element); 118 ASSERT(element);
(...skipping 19 matching lines...) Expand all
141 // Custom tags take precedence over type extensions 138 // Custom tags take precedence over type extensions
142 ASSERT(!CustomElement::isValidName(element->localName())); 139 ASSERT(!CustomElement::isValidName(element->localName()));
143 140
144 element->setCustomElementState(Element::WaitingForUpgrade); 141 element->setCustomElementState(Element::WaitingForUpgrade);
145 142
146 if (CustomElementRegistrationContext* context = element->document().registra tionContext()) 143 if (CustomElementRegistrationContext* context = element->document().registra tionContext())
147 context->didGiveTypeExtension(element, type); 144 context->didGiveTypeExtension(element, type);
148 } 145 }
149 146
150 } // namespace WebCore 147 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698