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

Side by Side Diff: third_party/WebKit/Source/core/dom/custom/CustomElement.cpp

Issue 2446903008: Custom Elements: Lookup custom element definition algorithm (Closed)
Patch Set: Patch Created 4 years, 1 month 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/dom/custom/CustomElementRegistry.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 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/dom/custom/CustomElement.h" 5 #include "core/dom/custom/CustomElement.h"
6 6
7 #include "core/dom/Document.h" 7 #include "core/dom/Document.h"
8 #include "core/dom/QualifiedName.h" 8 #include "core/dom/QualifiedName.h"
9 #include "core/dom/custom/CEReactionsScope.h" 9 #include "core/dom/custom/CEReactionsScope.h"
10 #include "core/dom/custom/CustomElementDefinition.h" 10 #include "core/dom/custom/CustomElementDefinition.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 bool CustomElement::shouldCreateCustomElement(const AtomicString& localName) { 62 bool CustomElement::shouldCreateCustomElement(const AtomicString& localName) {
63 return RuntimeEnabledFeatures::customElementsV1Enabled() && 63 return RuntimeEnabledFeatures::customElementsV1Enabled() &&
64 isValidName(localName); 64 isValidName(localName);
65 } 65 }
66 66
67 bool CustomElement::shouldCreateCustomElement(const QualifiedName& tagName) { 67 bool CustomElement::shouldCreateCustomElement(const QualifiedName& tagName) {
68 return shouldCreateCustomElement(tagName.localName()) && 68 return shouldCreateCustomElement(tagName.localName()) &&
69 tagName.namespaceURI() == HTMLNames::xhtmlNamespaceURI; 69 tagName.namespaceURI() == HTMLNames::xhtmlNamespaceURI;
70 } 70 }
71 71
72 static CustomElementDefinition* definitionForName(const Document& document, 72 static CustomElementDefinition* definitionFor(
73 const QualifiedName& name) { 73 const Document& document,
74 const CustomElementDescriptor desc) {
74 if (CustomElementRegistry* registry = CustomElement::registry(document)) 75 if (CustomElementRegistry* registry = CustomElement::registry(document))
75 return registry->definitionForName(name.localName()); 76 return registry->definitionFor(desc);
76 return nullptr; 77 return nullptr;
77 } 78 }
78 79
79 HTMLElement* CustomElement::createCustomElementSync( 80 HTMLElement* CustomElement::createCustomElementSync(
80 Document& document, 81 Document& document,
81 const AtomicString& localName) { 82 const AtomicString& localName) {
82 return createCustomElementSync( 83 return createCustomElementSync(
83 document, 84 document,
84 QualifiedName(nullAtom, localName, HTMLNames::xhtmlNamespaceURI)); 85 QualifiedName(nullAtom, localName, HTMLNames::xhtmlNamespaceURI));
85 } 86 }
86 87
87 HTMLElement* CustomElement::createCustomElementSync( 88 HTMLElement* CustomElement::createCustomElementSync(
88 Document& document, 89 Document& document,
89 const QualifiedName& tagName) { 90 const QualifiedName& tagName) {
90 DCHECK(shouldCreateCustomElement(tagName)); 91 DCHECK(shouldCreateCustomElement(tagName));
91 if (CustomElementDefinition* definition = 92 if (CustomElementDefinition* definition = definitionFor(
92 definitionForName(document, tagName)) 93 document,
94 CustomElementDescriptor(tagName.localName(), tagName.localName())))
93 return definition->createElementSync(document, tagName); 95 return definition->createElementSync(document, tagName);
94 return createUndefinedElement(document, tagName); 96 return createUndefinedElement(document, tagName);
95 } 97 }
96 98
97 HTMLElement* CustomElement::createCustomElementAsync( 99 HTMLElement* CustomElement::createCustomElementAsync(
98 Document& document, 100 Document& document,
99 const QualifiedName& tagName) { 101 const QualifiedName& tagName) {
100 DCHECK(shouldCreateCustomElement(tagName)); 102 DCHECK(shouldCreateCustomElement(tagName));
101 103
102 // To create an element: 104 // To create an element:
103 // https://dom.spec.whatwg.org/#concept-create-element 105 // https://dom.spec.whatwg.org/#concept-create-element
104 // 6. If definition is non-null, then: 106 // 6. If definition is non-null, then:
105 // 6.2. If the synchronous custom elements flag is not set: 107 // 6.2. If the synchronous custom elements flag is not set:
106 if (CustomElementDefinition* definition = 108 if (CustomElementDefinition* definition = definitionFor(
107 definitionForName(document, tagName)) 109 document,
110 CustomElementDescriptor(tagName.localName(), tagName.localName())))
108 return definition->createElementAsync(document, tagName); 111 return definition->createElementAsync(document, tagName);
109 112
110 return createUndefinedElement(document, tagName); 113 return createUndefinedElement(document, tagName);
111 } 114 }
112 115
113 HTMLElement* CustomElement::createUndefinedElement( 116 HTMLElement* CustomElement::createUndefinedElement(
114 Document& document, 117 Document& document,
115 const QualifiedName& tagName) { 118 const QualifiedName& tagName) {
116 DCHECK(shouldCreateCustomElement(tagName)); 119 DCHECK(shouldCreateCustomElement(tagName));
117 120
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 205
203 void CustomElement::tryToUpgrade(Element* element) { 206 void CustomElement::tryToUpgrade(Element* element) {
204 // Try to upgrade an element 207 // Try to upgrade an element
205 // https://html.spec.whatwg.org/multipage/scripting.html#concept-try-upgrade 208 // https://html.spec.whatwg.org/multipage/scripting.html#concept-try-upgrade
206 209
207 DCHECK_EQ(element->getCustomElementState(), CustomElementState::Undefined); 210 DCHECK_EQ(element->getCustomElementState(), CustomElementState::Undefined);
208 211
209 CustomElementRegistry* registry = CustomElement::registry(*element); 212 CustomElementRegistry* registry = CustomElement::registry(*element);
210 if (!registry) 213 if (!registry)
211 return; 214 return;
212 if (CustomElementDefinition* definition = 215 if (CustomElementDefinition* definition = registry->definitionFor(
213 registry->definitionForName(element->localName())) 216 CustomElementDescriptor(element->localName(), element->localName())))
214 definition->enqueueUpgradeReaction(element); 217 definition->enqueueUpgradeReaction(element);
215 else 218 else
216 registry->addCandidate(element); 219 registry->addCandidate(element);
217 } 220 }
218 221
219 } // namespace blink 222 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/dom/custom/CustomElementRegistry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698