| 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 "core/html/HTMLUnknownElement.h" |
| 19 #include "platform/text/Character.h" | 19 #include "platform/text/Character.h" |
| 20 #include "wtf/text/AtomicStringHash.h" | 20 #include "wtf/text/AtomicStringHash.h" |
| 21 | 21 |
| 22 namespace blink { | 22 namespace blink { |
| 23 | 23 |
| 24 CustomElementsRegistry* CustomElement::registry(const Element& element) | 24 CustomElementsRegistry* CustomElement::registry(const Element& element) |
| 25 { | 25 { |
| 26 return registry(element.document()); | 26 return registry(element.document()); |
| 27 } | 27 } |
| 28 | |
| 29 CustomElementsRegistry* CustomElement::registry(const Document& document) | 28 CustomElementsRegistry* CustomElement::registry(const Document& document) |
| 30 { | 29 { |
| 31 if (LocalDOMWindow* window = document.domWindow()) | 30 if (LocalDOMWindow* window = document.domWindow()) |
| 32 return window->customElements(); | 31 return window->customElements(); |
| 33 return nullptr; | 32 return nullptr; |
| 34 } | 33 } |
| 35 | 34 |
| 36 static CustomElementDefinition* definitionForElementWithoutCheck(const Element&
element) | 35 static CustomElementDefinition* definitionForElementWithoutCheck(const Element&
element) |
| 37 { | 36 { |
| 38 DCHECK_EQ(element.getCustomElementState(), CustomElementState::Custom); | 37 DCHECK_EQ(element.getCustomElementState(), CustomElementState::Custom); |
| 39 if (CustomElementsRegistry* registry = CustomElement::registry(element)) | 38 return element.customElementDefinition(); |
| 40 return registry->definitionForName(element.localName()); | |
| 41 return nullptr; | |
| 42 } | 39 } |
| 43 | 40 |
| 44 CustomElementDefinition* CustomElement::definitionForElement(const Element* elem
ent) | 41 CustomElementDefinition* CustomElement::definitionForElement(const Element* elem
ent) |
| 45 { | 42 { |
| 46 if (!element || element->getCustomElementState() != CustomElementState::Cust
om) | 43 if (!element || element->getCustomElementState() != CustomElementState::Cust
om) |
| 47 return nullptr; | 44 return nullptr; |
| 48 return definitionForElementWithoutCheck(*element); | 45 return definitionForElementWithoutCheck(*element); |
| 49 } | 46 } |
| 50 | 47 |
| 51 bool CustomElement::isValidName(const AtomicString& name) | 48 bool CustomElement::isValidName(const AtomicString& name) |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 definition->enqueueConnectedCallback(element); | 208 definition->enqueueConnectedCallback(element); |
| 212 } | 209 } |
| 213 | 210 |
| 214 void CustomElement::enqueueDisconnectedCallback(Element* element) | 211 void CustomElement::enqueueDisconnectedCallback(Element* element) |
| 215 { | 212 { |
| 216 CustomElementDefinition* definition = definitionForElementWithoutCheck(*elem
ent); | 213 CustomElementDefinition* definition = definitionForElementWithoutCheck(*elem
ent); |
| 217 if (definition->hasDisconnectedCallback()) | 214 if (definition->hasDisconnectedCallback()) |
| 218 definition->enqueueDisconnectedCallback(element); | 215 definition->enqueueDisconnectedCallback(element); |
| 219 } | 216 } |
| 220 | 217 |
| 218 void CustomElement::enqueueAdoptedCallback(Element* element) |
| 219 { |
| 220 DCHECK_EQ(element->getCustomElementState(), CustomElementState::Custom); |
| 221 CustomElementDefinition* definition = definitionForElementWithoutCheck(*elem
ent); |
| 222 if (definition->hasAdoptedCallback()) |
| 223 definition->enqueueAdoptedCallback(element); |
| 224 } |
| 221 | 225 |
| 222 void CustomElement::enqueueAttributeChangedCallback(Element* element, | 226 void CustomElement::enqueueAttributeChangedCallback(Element* element, |
| 223 const QualifiedName& name, | 227 const QualifiedName& name, |
| 224 const AtomicString& oldValue, const AtomicString& newValue) | 228 const AtomicString& oldValue, const AtomicString& newValue) |
| 225 { | 229 { |
| 226 CustomElementDefinition* definition = definitionForElementWithoutCheck(*elem
ent); | 230 CustomElementDefinition* definition = definitionForElementWithoutCheck(*elem
ent); |
| 227 if (definition->hasAttributeChangedCallback(name)) | 231 if (definition->hasAttributeChangedCallback(name)) |
| 228 definition->enqueueAttributeChangedCallback(element, name, oldValue, new
Value); | 232 definition->enqueueAttributeChangedCallback(element, name, oldValue, new
Value); |
| 229 } | 233 } |
| 230 | 234 |
| 231 void CustomElement::tryToUpgrade(Element* element) | 235 void CustomElement::tryToUpgrade(Element* element) |
| 232 { | 236 { |
| 233 // Try to upgrade an element | 237 // Try to upgrade an element |
| 234 // https://html.spec.whatwg.org/multipage/scripting.html#concept-try-upgrade | 238 // https://html.spec.whatwg.org/multipage/scripting.html#concept-try-upgrade |
| 235 | 239 |
| 236 DCHECK_EQ(element->getCustomElementState(), CustomElementState::Undefined); | 240 DCHECK_EQ(element->getCustomElementState(), CustomElementState::Undefined); |
| 237 | 241 |
| 238 CustomElementsRegistry* registry = CustomElement::registry(*element); | 242 CustomElementsRegistry* registry = CustomElement::registry(*element); |
| 239 if (!registry) | 243 if (!registry) |
| 240 return; | 244 return; |
| 241 if (CustomElementDefinition* definition = registry->definitionForName(elemen
t->localName())) | 245 if (CustomElementDefinition* definition = registry->definitionForName(elemen
t->localName())) |
| 242 definition->enqueueUpgradeReaction(element); | 246 definition->enqueueUpgradeReaction(element); |
| 243 else | 247 else |
| 244 registry->addCandidate(element); | 248 registry->addCandidate(element); |
| 245 } | 249 } |
| 246 | 250 |
| 247 } // namespace blink | 251 } // namespace blink |
| OLD | NEW |