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/CustomElementRegistry.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/LocalDOMWindow.h" | 15 #include "core/frame/LocalDOMWindow.h" |
16 #include "core/html/HTMLElement.h" | 16 #include "core/html/HTMLElement.h" |
17 #include "core/html/HTMLUnknownElement.h" | 17 #include "core/html/HTMLUnknownElement.h" |
18 #include "platform/text/Character.h" | 18 #include "platform/text/Character.h" |
19 #include "wtf/text/AtomicStringHash.h" | 19 #include "wtf/text/AtomicStringHash.h" |
20 | 20 |
21 namespace blink { | 21 namespace blink { |
22 | 22 |
23 CustomElementsRegistry* CustomElement::registry(const Element& element) | 23 CustomElementRegistry* CustomElement::registry(const Element& element) |
24 { | 24 { |
25 return registry(element.document()); | 25 return registry(element.document()); |
26 } | 26 } |
27 | 27 |
28 CustomElementsRegistry* CustomElement::registry(const Document& document) | 28 CustomElementRegistry* CustomElement::registry(const Document& document) |
29 { | 29 { |
30 if (LocalDOMWindow* window = document.executingWindow()) | 30 if (LocalDOMWindow* window = document.executingWindow()) |
31 return window->customElements(); | 31 return window->customElements(); |
32 return nullptr; | 32 return nullptr; |
33 } | 33 } |
34 | 34 |
35 static CustomElementDefinition* definitionForElementWithoutCheck(const Element&
element) | 35 static CustomElementDefinition* definitionForElementWithoutCheck(const Element&
element) |
36 { | 36 { |
37 DCHECK_EQ(element.getCustomElementState(), CustomElementState::Custom); | 37 DCHECK_EQ(element.getCustomElementState(), CustomElementState::Custom); |
38 return element.customElementDefinition(); | 38 return element.customElementDefinition(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 } | 86 } |
87 | 87 |
88 bool CustomElement::shouldCreateCustomElement(const QualifiedName& tagName) | 88 bool CustomElement::shouldCreateCustomElement(const QualifiedName& tagName) |
89 { | 89 { |
90 return shouldCreateCustomElement(tagName.localName()) | 90 return shouldCreateCustomElement(tagName.localName()) |
91 && tagName.namespaceURI() == HTMLNames::xhtmlNamespaceURI; | 91 && tagName.namespaceURI() == HTMLNames::xhtmlNamespaceURI; |
92 } | 92 } |
93 | 93 |
94 static CustomElementDefinition* definitionForName(const Document& document, cons
t QualifiedName& name) | 94 static CustomElementDefinition* definitionForName(const Document& document, cons
t QualifiedName& name) |
95 { | 95 { |
96 if (CustomElementsRegistry* registry = CustomElement::registry(document)) | 96 if (CustomElementRegistry* registry = CustomElement::registry(document)) |
97 return registry->definitionForName(name.localName()); | 97 return registry->definitionForName(name.localName()); |
98 return nullptr; | 98 return nullptr; |
99 } | 99 } |
100 | 100 |
101 HTMLElement* CustomElement::createCustomElementSync(Document& document, const At
omicString& localName, ExceptionState& exceptionState) | 101 HTMLElement* CustomElement::createCustomElementSync(Document& document, const At
omicString& localName, ExceptionState& exceptionState) |
102 { | 102 { |
103 return createCustomElementSync(document, | 103 return createCustomElementSync(document, |
104 QualifiedName(nullAtom, localName, HTMLNames::xhtmlNamespaceURI), | 104 QualifiedName(nullAtom, localName, HTMLNames::xhtmlNamespaceURI), |
105 exceptionState); | 105 exceptionState); |
106 } | 106 } |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 definition->enqueueAttributeChangedCallback(element, name, oldValue, new
Value); | 231 definition->enqueueAttributeChangedCallback(element, name, oldValue, new
Value); |
232 } | 232 } |
233 | 233 |
234 void CustomElement::tryToUpgrade(Element* element) | 234 void CustomElement::tryToUpgrade(Element* element) |
235 { | 235 { |
236 // Try to upgrade an element | 236 // Try to upgrade an element |
237 // https://html.spec.whatwg.org/multipage/scripting.html#concept-try-upgrade | 237 // https://html.spec.whatwg.org/multipage/scripting.html#concept-try-upgrade |
238 | 238 |
239 DCHECK_EQ(element->getCustomElementState(), CustomElementState::Undefined); | 239 DCHECK_EQ(element->getCustomElementState(), CustomElementState::Undefined); |
240 | 240 |
241 CustomElementsRegistry* registry = CustomElement::registry(*element); | 241 CustomElementRegistry* registry = CustomElement::registry(*element); |
242 if (!registry) | 242 if (!registry) |
243 return; | 243 return; |
244 if (CustomElementDefinition* definition = registry->definitionForName(elemen
t->localName())) | 244 if (CustomElementDefinition* definition = registry->definitionForName(elemen
t->localName())) |
245 definition->enqueueUpgradeReaction(element); | 245 definition->enqueueUpgradeReaction(element); |
246 else | 246 else |
247 registry->addCandidate(element); | 247 registry->addCandidate(element); |
248 } | 248 } |
249 | 249 |
250 } // namespace blink | 250 } // namespace blink |
OLD | NEW |