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