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