| 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" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 return registry(element.document()); | 25 return registry(element.document()); |
| 26 } | 26 } |
| 27 | 27 |
| 28 CustomElementsRegistry* CustomElement::registry(const Document& document) | 28 CustomElementsRegistry* CustomElement::registry(const Document& document) |
| 29 { | 29 { |
| 30 if (LocalDOMWindow* window = document.domWindow()) | 30 if (LocalDOMWindow* window = document.domWindow()) |
| 31 return window->customElements(); | 31 return window->customElements(); |
| 32 return nullptr; | 32 return nullptr; |
| 33 } | 33 } |
| 34 | 34 |
| 35 CustomElementDefinition* CustomElement::definitionForElement(const Element& elem
ent) | 35 static CustomElementDefinition* definitionForElementWithoutCheck(const Element&
element) |
| 36 { | 36 { |
| 37 DCHECK_EQ(element.getCustomElementState(), CustomElementState::Custom); |
| 37 if (CustomElementsRegistry* registry = CustomElement::registry(element)) | 38 if (CustomElementsRegistry* registry = CustomElement::registry(element)) |
| 38 return registry->definitionForName(element.localName()); | 39 return registry->definitionForName(element.localName()); |
| 39 return nullptr; | 40 return nullptr; |
| 40 } | 41 } |
| 41 | 42 |
| 43 CustomElementDefinition* CustomElement::definitionForElement(const Element* elem
ent) |
| 44 { |
| 45 if (!element || element->getCustomElementState() != CustomElementState::Cust
om) |
| 46 return nullptr; |
| 47 return definitionForElementWithoutCheck(*element); |
| 48 } |
| 49 |
| 42 bool CustomElement::isValidName(const AtomicString& name) | 50 bool CustomElement::isValidName(const AtomicString& name) |
| 43 { | 51 { |
| 44 if (!name.length() || name[0] < 'a' || name[0] > 'z') | 52 if (!name.length() || name[0] < 'a' || name[0] > 'z') |
| 45 return false; | 53 return false; |
| 46 | 54 |
| 47 bool hasHyphens = false; | 55 bool hasHyphens = false; |
| 48 for (size_t i = 1; i < name.length(); ) { | 56 for (size_t i = 1; i < name.length(); ) { |
| 49 UChar32 ch; | 57 UChar32 ch; |
| 50 if (name.is8Bit()) | 58 if (name.is8Bit()) |
| 51 ch = name[i++]; | 59 ch = name[i++]; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 } | 181 } |
| 174 | 182 |
| 175 // If the custom element reactions stack is empty, then | 183 // If the custom element reactions stack is empty, then |
| 176 // Add element to the backup element queue. | 184 // Add element to the backup element queue. |
| 177 element->document().frameHost()->customElementReactionStack() | 185 element->document().frameHost()->customElementReactionStack() |
| 178 .enqueueToBackupQueue(element, reaction); | 186 .enqueueToBackupQueue(element, reaction); |
| 179 } | 187 } |
| 180 | 188 |
| 181 void CustomElement::enqueueConnectedCallback(Element* element) | 189 void CustomElement::enqueueConnectedCallback(Element* element) |
| 182 { | 190 { |
| 183 DCHECK_EQ(element->getCustomElementState(), CustomElementState::Custom); | 191 CustomElementDefinition* definition = definitionForElementWithoutCheck(*elem
ent); |
| 184 CustomElementDefinition* definition = definitionForElement(*element); | |
| 185 if (definition->hasConnectedCallback()) | 192 if (definition->hasConnectedCallback()) |
| 186 definition->enqueueConnectedCallback(element); | 193 definition->enqueueConnectedCallback(element); |
| 187 } | 194 } |
| 188 | 195 |
| 189 void CustomElement::enqueueDisconnectedCallback(Element* element) | 196 void CustomElement::enqueueDisconnectedCallback(Element* element) |
| 190 { | 197 { |
| 191 DCHECK_EQ(element->getCustomElementState(), CustomElementState::Custom); | 198 CustomElementDefinition* definition = definitionForElementWithoutCheck(*elem
ent); |
| 192 CustomElementDefinition* definition = definitionForElement(*element); | |
| 193 if (definition->hasDisconnectedCallback()) | 199 if (definition->hasDisconnectedCallback()) |
| 194 definition->enqueueDisconnectedCallback(element); | 200 definition->enqueueDisconnectedCallback(element); |
| 195 } | 201 } |
| 196 | 202 |
| 197 | 203 |
| 198 void CustomElement::enqueueAttributeChangedCallback(Element* element, | 204 void CustomElement::enqueueAttributeChangedCallback(Element* element, |
| 199 const QualifiedName& name, | 205 const QualifiedName& name, |
| 200 const AtomicString& oldValue, const AtomicString& newValue) | 206 const AtomicString& oldValue, const AtomicString& newValue) |
| 201 { | 207 { |
| 202 DCHECK_EQ(element->getCustomElementState(), CustomElementState::Custom); | 208 CustomElementDefinition* definition = definitionForElementWithoutCheck(*elem
ent); |
| 203 CustomElementDefinition* definition = definitionForElement(*element); | |
| 204 if (definition->hasAttributeChangedCallback(name)) | 209 if (definition->hasAttributeChangedCallback(name)) |
| 205 definition->enqueueAttributeChangedCallback(element, name, oldValue, new
Value); | 210 definition->enqueueAttributeChangedCallback(element, name, oldValue, new
Value); |
| 206 } | 211 } |
| 207 | 212 |
| 208 void CustomElement::tryToUpgrade(Element* element) | 213 void CustomElement::tryToUpgrade(Element* element) |
| 209 { | 214 { |
| 210 // Try to upgrade an element | 215 // Try to upgrade an element |
| 211 // https://html.spec.whatwg.org/multipage/scripting.html#concept-try-upgrade | 216 // https://html.spec.whatwg.org/multipage/scripting.html#concept-try-upgrade |
| 212 | 217 |
| 213 DCHECK_EQ(element->getCustomElementState(), CustomElementState::Undefined); | 218 DCHECK_EQ(element->getCustomElementState(), CustomElementState::Undefined); |
| 214 | 219 |
| 215 CustomElementsRegistry* registry = CustomElement::registry(*element); | 220 CustomElementsRegistry* registry = CustomElement::registry(*element); |
| 216 if (!registry) | 221 if (!registry) |
| 217 return; | 222 return; |
| 218 if (CustomElementDefinition* definition = registry->definitionForName(elemen
t->localName())) | 223 if (CustomElementDefinition* definition = registry->definitionForName(elemen
t->localName())) |
| 219 definition->enqueueUpgradeReaction(element); | 224 definition->enqueueUpgradeReaction(element); |
| 220 else | 225 else |
| 221 registry->addCandidate(element); | 226 registry->addCandidate(element); |
| 222 } | 227 } |
| 223 | 228 |
| 224 } // namespace blink | 229 } // namespace blink |
| OLD | NEW |