| 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/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" |
| 11 #include "core/dom/custom/CustomElementReactionStack.h" | 11 #include "core/dom/custom/CustomElementReactionStack.h" |
| 12 #include "core/dom/custom/CustomElementsRegistry.h" | 12 #include "core/dom/custom/CustomElementsRegistry.h" |
| 13 #include "core/dom/custom/V0CustomElement.h" | 13 #include "core/dom/custom/V0CustomElement.h" |
| 14 #include "core/dom/custom/V0CustomElementRegistrationContext.h" | 14 #include "core/dom/custom/V0CustomElementRegistrationContext.h" |
| 15 #include "core/frame/FrameHost.h" | 15 #include "core/frame/FrameHost.h" |
| 16 #include "core/frame/LocalDOMWindow.h" | 16 #include "core/frame/LocalDOMWindow.h" |
| 17 #include "core/html/HTMLElement.h" | 17 #include "core/html/HTMLElement.h" |
| 18 #include "core/html/HTMLUnknownElement.h" |
| 18 #include "platform/text/Character.h" | 19 #include "platform/text/Character.h" |
| 19 #include "wtf/text/AtomicStringHash.h" | 20 #include "wtf/text/AtomicStringHash.h" |
| 20 | 21 |
| 21 namespace blink { | 22 namespace blink { |
| 22 | 23 |
| 23 CustomElementsRegistry* CustomElement::registry(const Element& element) | 24 CustomElementsRegistry* CustomElement::registry(const Element& element) |
| 24 { | 25 { |
| 25 return registry(element.document()); | 26 return registry(element.document()); |
| 26 } | 27 } |
| 27 | 28 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 "font-face", | 67 "font-face", |
| 67 "font-face-src", | 68 "font-face-src", |
| 68 "font-face-uri", | 69 "font-face-uri", |
| 69 "font-face-format", | 70 "font-face-format", |
| 70 "font-face-name", | 71 "font-face-name", |
| 71 "missing-glyph", | 72 "missing-glyph", |
| 72 })); | 73 })); |
| 73 return !hyphenContainingElementNames.contains(name); | 74 return !hyphenContainingElementNames.contains(name); |
| 74 } | 75 } |
| 75 | 76 |
| 77 bool CustomElement::isDefined(CustomElementState state) |
| 78 { |
| 79 // https://dom.spec.whatwg.org/#concept-element-defined |
| 80 return !(static_cast<int>(state) |
| 81 & static_cast<int>(CustomElementState::NotDefinedFlag)); |
| 82 } |
| 83 |
| 76 bool CustomElement::shouldCreateCustomElement(Document& document, const AtomicSt
ring& localName) | 84 bool CustomElement::shouldCreateCustomElement(Document& document, const AtomicSt
ring& localName) |
| 77 { | 85 { |
| 78 return RuntimeEnabledFeatures::customElementsV1Enabled() | 86 return RuntimeEnabledFeatures::customElementsV1Enabled() |
| 79 && document.frame() && isValidName(localName); | 87 && document.frame() && isValidName(localName); |
| 80 } | 88 } |
| 81 | 89 |
| 82 bool CustomElement::shouldCreateCustomElement(Document& document, const Qualifie
dName& tagName) | 90 bool CustomElement::shouldCreateCustomElement(Document& document, const Qualifie
dName& tagName) |
| 83 { | 91 { |
| 84 return shouldCreateCustomElement(document, tagName.localName()) | 92 return shouldCreateCustomElement(document, tagName.localName()) |
| 85 && tagName.namespaceURI() == HTMLNames::xhtmlNamespaceURI; | 93 && tagName.namespaceURI() == HTMLNames::xhtmlNamespaceURI; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 element = toHTMLElement(v0element); | 161 element = toHTMLElement(v0element); |
| 154 } else { | 162 } else { |
| 155 element = HTMLElement::create(tagName, document); | 163 element = HTMLElement::create(tagName, document); |
| 156 } | 164 } |
| 157 | 165 |
| 158 element->setCustomElementState(CustomElementState::Undefined); | 166 element->setCustomElementState(CustomElementState::Undefined); |
| 159 | 167 |
| 160 return element; | 168 return element; |
| 161 } | 169 } |
| 162 | 170 |
| 171 HTMLElement* CustomElement::createFailedElement(Document& document, const Qualif
iedName& tagName) |
| 172 { |
| 173 DCHECK(shouldCreateCustomElement(document, tagName)); |
| 174 |
| 175 // "create an element for a token": |
| 176 // https://html.spec.whatwg.org/multipage/syntax.html#create-an-element-for-
the-token |
| 177 |
| 178 // 7. If this step throws an exception, let element be instead a new element |
| 179 // that implements HTMLUnknownElement, with no attributes, namespace set to |
| 180 // given namespace, namespace prefix set to null, custom element state set |
| 181 // to "failed", and node document set to document. |
| 182 |
| 183 HTMLElement* element = HTMLUnknownElement::create(tagName, document); |
| 184 element->setCustomElementState(CustomElementState::Failed); |
| 185 return element; |
| 186 } |
| 187 |
| 163 void CustomElement::enqueue(Element* element, CustomElementReaction* reaction) | 188 void CustomElement::enqueue(Element* element, CustomElementReaction* reaction) |
| 164 { | 189 { |
| 165 // To enqueue an element on the appropriate element queue | 190 // To enqueue an element on the appropriate element queue |
| 166 // https://html.spec.whatwg.org/multipage/scripting.html#enqueue-an-element-
on-the-appropriate-element-queue | 191 // https://html.spec.whatwg.org/multipage/scripting.html#enqueue-an-element-
on-the-appropriate-element-queue |
| 167 | 192 |
| 168 // If the custom element reactions stack is not empty, then | 193 // If the custom element reactions stack is not empty, then |
| 169 // Add element to the current element queue. | 194 // Add element to the current element queue. |
| 170 if (CEReactionsScope* current = CEReactionsScope::current()) { | 195 if (CEReactionsScope* current = CEReactionsScope::current()) { |
| 171 current->enqueueToCurrentQueue(element, reaction); | 196 current->enqueueToCurrentQueue(element, reaction); |
| 172 return; | 197 return; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 CustomElementsRegistry* registry = CustomElement::registry(*element); | 240 CustomElementsRegistry* registry = CustomElement::registry(*element); |
| 216 if (!registry) | 241 if (!registry) |
| 217 return; | 242 return; |
| 218 if (CustomElementDefinition* definition = registry->definitionForName(elemen
t->localName())) | 243 if (CustomElementDefinition* definition = registry->definitionForName(elemen
t->localName())) |
| 219 definition->enqueueUpgradeReaction(element); | 244 definition->enqueueUpgradeReaction(element); |
| 220 else | 245 else |
| 221 registry->addCandidate(element); | 246 registry->addCandidate(element); |
| 222 } | 247 } |
| 223 | 248 |
| 224 } // namespace blink | 249 } // namespace blink |
| OLD | NEW |