OLD | NEW |
---|---|
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/HTMLElementFactory.h" | |
8 #include "core/HTMLElementTypeHelpers.h" | |
7 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
8 #include "core/dom/QualifiedName.h" | 10 #include "core/dom/QualifiedName.h" |
9 #include "core/dom/custom/CEReactionsScope.h" | 11 #include "core/dom/custom/CEReactionsScope.h" |
10 #include "core/dom/custom/CustomElementDefinition.h" | 12 #include "core/dom/custom/CustomElementDefinition.h" |
11 #include "core/dom/custom/CustomElementReactionStack.h" | 13 #include "core/dom/custom/CustomElementReactionStack.h" |
12 #include "core/dom/custom/CustomElementRegistry.h" | 14 #include "core/dom/custom/CustomElementRegistry.h" |
13 #include "core/dom/custom/V0CustomElement.h" | 15 #include "core/dom/custom/V0CustomElement.h" |
14 #include "core/dom/custom/V0CustomElementRegistrationContext.h" | 16 #include "core/dom/custom/V0CustomElementRegistrationContext.h" |
15 #include "core/frame/LocalDOMWindow.h" | 17 #include "core/frame/LocalDOMWindow.h" |
16 #include "core/html/HTMLElement.h" | 18 #include "core/html/HTMLElement.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 static CustomElementDefinition* definitionFor( | 74 static CustomElementDefinition* definitionFor( |
73 const Document& document, | 75 const Document& document, |
74 const CustomElementDescriptor desc) { | 76 const CustomElementDescriptor desc) { |
75 if (CustomElementRegistry* registry = CustomElement::registry(document)) | 77 if (CustomElementRegistry* registry = CustomElement::registry(document)) |
76 return registry->definitionFor(desc); | 78 return registry->definitionFor(desc); |
77 return nullptr; | 79 return nullptr; |
78 } | 80 } |
79 | 81 |
80 HTMLElement* CustomElement::createCustomElementSync( | 82 HTMLElement* CustomElement::createCustomElementSync( |
81 Document& document, | 83 Document& document, |
82 const AtomicString& localName) { | 84 const AtomicString& localName, |
85 const AtomicString& is) { | |
83 return createCustomElementSync( | 86 return createCustomElementSync( |
84 document, | 87 document, |
85 QualifiedName(nullAtom, localName, HTMLNames::xhtmlNamespaceURI)); | 88 QualifiedName(nullAtom, localName, HTMLNames::xhtmlNamespaceURI), is); |
86 } | 89 } |
87 | 90 |
88 HTMLElement* CustomElement::createCustomElementSync( | 91 HTMLElement* CustomElement::createCustomElementSync( |
89 Document& document, | 92 Document& document, |
90 const QualifiedName& tagName) { | 93 const QualifiedName& tagName, |
91 DCHECK(shouldCreateCustomElement(tagName)); | 94 const AtomicString& is) { |
92 if (CustomElementDefinition* definition = definitionFor( | 95 const AtomicString& name = is.isNull() ? tagName.localName() : is; |
93 document, | 96 DCHECK(shouldCreateCustomElement(name)); |
94 CustomElementDescriptor(tagName.localName(), tagName.localName()))) | 97 const CustomElementDescriptor& desc = |
dominicc (has gone to gerrit)
2016/11/07 01:59:00
I think you could just make this
const CustomElem
| |
95 return definition->createElementSync(document, tagName); | 98 CustomElementDescriptor(name, tagName.localName()); |
96 return createUndefinedElement(document, tagName); | 99 CustomElementDefinition* definition = definitionFor(document, desc); |
100 HTMLElement* element; | |
101 | |
102 if (definition && desc.isAutonomous()) { | |
103 // 6. If definition is non-null and we have an autonomous custom element | |
dominicc (has gone to gerrit)
2016/11/07 01:59:00
Add a link to the spec this is implementing to giv
| |
104 element = definition->createElementSync(document, tagName); | |
105 element->setAttribute(HTMLNames::isAttr, is); | |
dominicc (has gone to gerrit)
2016/11/07 01:59:00
Hmm, this branch doesn't upgrade. When do these ge
| |
106 } else if (definition) { | |
107 // 5. If definition is non-null and we have a customized built-in element | |
108 element = createUndefinedElement(document, tagName); | |
109 element->setAttribute(HTMLNames::isAttr, name); | |
110 definition->upgrade(element); | |
111 } else { | |
112 // 7. Otherwise | |
113 element = createUndefinedElement(document, tagName); | |
114 } | |
115 return element; | |
97 } | 116 } |
98 | 117 |
99 HTMLElement* CustomElement::createCustomElementAsync( | 118 HTMLElement* CustomElement::createCustomElementAsync( |
100 Document& document, | 119 Document& document, |
101 const QualifiedName& tagName) { | 120 const QualifiedName& tagName) { |
102 DCHECK(shouldCreateCustomElement(tagName)); | 121 DCHECK(shouldCreateCustomElement(tagName)); |
103 | 122 |
104 // To create an element: | 123 // To create an element: |
105 // https://dom.spec.whatwg.org/#concept-create-element | 124 // https://dom.spec.whatwg.org/#concept-create-element |
106 // 6. If definition is non-null, then: | 125 // 6. If definition is non-null, then: |
107 // 6.2. If the synchronous custom elements flag is not set: | 126 // 6.2. If the synchronous custom elements flag is not set: |
108 if (CustomElementDefinition* definition = definitionFor( | 127 if (CustomElementDefinition* definition = definitionFor( |
109 document, | 128 document, |
110 CustomElementDescriptor(tagName.localName(), tagName.localName()))) | 129 CustomElementDescriptor(tagName.localName(), tagName.localName()))) |
111 return definition->createElementAsync(document, tagName); | 130 return definition->createElementAsync(document, tagName); |
112 | 131 |
113 return createUndefinedElement(document, tagName); | 132 return createUndefinedElement(document, tagName); |
114 } | 133 } |
115 | 134 |
135 // Create a HTMLElement | |
116 HTMLElement* CustomElement::createUndefinedElement( | 136 HTMLElement* CustomElement::createUndefinedElement( |
117 Document& document, | 137 Document& document, |
118 const QualifiedName& tagName) { | 138 const QualifiedName& tagName) { |
119 DCHECK(shouldCreateCustomElement(tagName)); | 139 int builtin = htmlElementTypeForTag(tagName.localName()) != |
dominicc (has gone to gerrit)
2016/11/07 01:59:00
int -> bool
Maybe add a word or two to give this
| |
140 HTMLElementType::kHTMLUnknownElement && | |
141 RuntimeEnabledFeatures::customElementsBuiltinEnabled(); | |
142 DCHECK(shouldCreateCustomElement(tagName) || builtin); | |
120 | 143 |
121 HTMLElement* element; | 144 HTMLElement* element; |
122 if (V0CustomElement::isValidName(tagName.localName()) && | 145 if (V0CustomElement::isValidName(tagName.localName()) && |
123 document.registrationContext()) { | 146 document.registrationContext()) { |
124 Element* v0element = document.registrationContext()->createCustomTagElement( | 147 Element* v0element = document.registrationContext()->createCustomTagElement( |
125 document, tagName); | 148 document, tagName); |
126 SECURITY_DCHECK(v0element->isHTMLElement()); | 149 SECURITY_DCHECK(v0element->isHTMLElement()); |
127 element = toHTMLElement(v0element); | 150 element = toHTMLElement(v0element); |
151 } else if (builtin) { | |
152 element = HTMLElementFactory::createHTMLElement( | |
153 tagName.localName(), document, 0, CreatedByCreateElement); | |
dominicc (has gone to gerrit)
2016/11/07 01:59:00
There's lots of code running around passing 0 for
| |
128 } else { | 154 } else { |
129 element = HTMLElement::create(tagName, document); | 155 element = HTMLElement::create(tagName, document); |
dominicc (has gone to gerrit)
2016/11/07 01:59:00
We're going to end up in a situation where some pe
| |
130 } | 156 } |
131 | 157 |
132 element->setCustomElementState(CustomElementState::Undefined); | 158 element->setCustomElementState(CustomElementState::Undefined); |
133 | 159 |
134 return element; | 160 return element; |
135 } | 161 } |
136 | 162 |
137 HTMLElement* CustomElement::createFailedElement(Document& document, | 163 HTMLElement* CustomElement::createFailedElement(Document& document, |
138 const QualifiedName& tagName) { | 164 const QualifiedName& tagName) { |
139 DCHECK(shouldCreateCustomElement(tagName)); | 165 DCHECK(shouldCreateCustomElement(tagName)); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 if (!registry) | 239 if (!registry) |
214 return; | 240 return; |
215 if (CustomElementDefinition* definition = registry->definitionFor( | 241 if (CustomElementDefinition* definition = registry->definitionFor( |
216 CustomElementDescriptor(element->localName(), element->localName()))) | 242 CustomElementDescriptor(element->localName(), element->localName()))) |
217 definition->enqueueUpgradeReaction(element); | 243 definition->enqueueUpgradeReaction(element); |
218 else | 244 else |
219 registry->addCandidate(element); | 245 registry->addCandidate(element); |
220 } | 246 } |
221 | 247 |
222 } // namespace blink | 248 } // namespace blink |
OLD | NEW |