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/CustomElementDefinition.h" | 5 #include "core/dom/custom/CustomElementDefinition.h" |
6 | 6 |
7 #include "core/dom/Attr.h" | 7 #include "core/dom/Attr.h" |
8 #include "core/dom/ExceptionCode.h" | 8 #include "core/dom/ExceptionCode.h" |
9 #include "core/dom/custom/CustomElement.h" | 9 #include "core/dom/custom/CustomElement.h" |
10 #include "core/dom/custom/CustomElementAdoptedCallbackReaction.h" | 10 #include "core/dom/custom/CustomElementAdoptedCallbackReaction.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 CustomElementDefinition::~CustomElementDefinition() {} | 32 CustomElementDefinition::~CustomElementDefinition() {} |
33 | 33 |
34 DEFINE_TRACE(CustomElementDefinition) { | 34 DEFINE_TRACE(CustomElementDefinition) { |
35 visitor->trace(m_constructionStack); | 35 visitor->trace(m_constructionStack); |
36 } | 36 } |
37 | 37 |
38 static String errorMessageForConstructorResult(Element* element, | 38 static String errorMessageForConstructorResult(Element* element, |
39 Document& document, | 39 Document& document, |
40 const QualifiedName& tagName) { | 40 const QualifiedName& tagName) { |
41 // https://dom.spec.whatwg.org/#concept-create-element | 41 // https://dom.spec.whatwg.org/#concept-create-element |
42 // 6.1.4. If result's attribute list is not empty, then throw a NotSupportedEr
ror. | 42 // 6.1.4. If result's attribute list is not empty, then throw a |
| 43 // NotSupportedError. |
43 if (element->hasAttributes()) | 44 if (element->hasAttributes()) |
44 return "The result must not have attributes"; | 45 return "The result must not have attributes"; |
45 // 6.1.5. If result has children, then throw a NotSupportedError. | 46 // 6.1.5. If result has children, then throw a NotSupportedError. |
46 if (element->hasChildren()) | 47 if (element->hasChildren()) |
47 return "The result must not have children"; | 48 return "The result must not have children"; |
48 // 6.1.6. If result's parent is not null, then throw a NotSupportedError. | 49 // 6.1.6. If result's parent is not null, then throw a NotSupportedError. |
49 if (element->parentNode()) | 50 if (element->parentNode()) |
50 return "The result must not have a parent"; | 51 return "The result must not have a parent"; |
51 // 6.1.7. If result's node document is not document, then throw a NotSupported
Error. | 52 // 6.1.7. If result's node document is not document, then throw a |
| 53 // NotSupportedError. |
52 if (&element->document() != &document) | 54 if (&element->document() != &document) |
53 return "The result must be in the same document"; | 55 return "The result must be in the same document"; |
54 // 6.1.8. If result's namespace is not the HTML namespace, then throw a NotSup
portedError. | 56 // 6.1.8. If result's namespace is not the HTML namespace, then throw a |
| 57 // NotSupportedError. |
55 if (element->namespaceURI() != HTMLNames::xhtmlNamespaceURI) | 58 if (element->namespaceURI() != HTMLNames::xhtmlNamespaceURI) |
56 return "The result must have HTML namespace"; | 59 return "The result must have HTML namespace"; |
57 // 6.1.9. If result's local name is not equal to localName, then throw a NotSu
pportedError. | 60 // 6.1.9. If result's local name is not equal to localName, then throw a |
| 61 // NotSupportedError. |
58 if (element->localName() != tagName.localName()) | 62 if (element->localName() != tagName.localName()) |
59 return "The result must have the same localName"; | 63 return "The result must have the same localName"; |
60 return String(); | 64 return String(); |
61 } | 65 } |
62 | 66 |
63 void CustomElementDefinition::checkConstructorResult( | 67 void CustomElementDefinition::checkConstructorResult( |
64 Element* element, | 68 Element* element, |
65 Document& document, | 69 Document& document, |
66 const QualifiedName& tagName, | 70 const QualifiedName& tagName, |
67 ExceptionState& exceptionState) { | 71 ExceptionState& exceptionState) { |
68 // https://dom.spec.whatwg.org/#concept-create-element | 72 // https://dom.spec.whatwg.org/#concept-create-element |
69 // 6.1.3. If result does not implement the HTMLElement interface, throw a Type
Error. | 73 // 6.1.3. If result does not implement the HTMLElement interface, throw a |
| 74 // TypeError. |
70 // See https://github.com/whatwg/html/issues/1402 for more clarifications. | 75 // See https://github.com/whatwg/html/issues/1402 for more clarifications. |
71 if (!element || !element->isHTMLElement()) { | 76 if (!element || !element->isHTMLElement()) { |
72 exceptionState.throwTypeError( | 77 exceptionState.throwTypeError( |
73 "The result must implement HTMLElement interface"); | 78 "The result must implement HTMLElement interface"); |
74 return; | 79 return; |
75 } | 80 } |
76 | 81 |
77 // 6.1.4. through 6.1.9. | 82 // 6.1.4. through 6.1.9. |
78 const String message = | 83 const String message = |
79 errorMessageForConstructorResult(element, document, tagName); | 84 errorMessageForConstructorResult(element, document, tagName); |
80 if (!message.isEmpty()) | 85 if (!message.isEmpty()) |
81 exceptionState.throwDOMException(NotSupportedError, message); | 86 exceptionState.throwDOMException(NotSupportedError, message); |
82 } | 87 } |
83 | 88 |
84 HTMLElement* CustomElementDefinition::createElementForConstructor( | 89 HTMLElement* CustomElementDefinition::createElementForConstructor( |
85 Document& document) { | 90 Document& document) { |
86 // TODO(kojii): When HTMLElementFactory has an option not to queue | 91 // TODO(kojii): When HTMLElementFactory has an option not to queue |
87 // upgrade, call that instead of HTMLElement. HTMLElement is enough | 92 // upgrade, call that instead of HTMLElement. HTMLElement is enough |
88 // for now, but type extension will require HTMLElementFactory. | 93 // for now, but type extension will require HTMLElementFactory. |
89 HTMLElement* element = | 94 HTMLElement* element = |
90 HTMLElement::create(QualifiedName(nullAtom, descriptor().localName(), | 95 HTMLElement::create(QualifiedName(nullAtom, descriptor().localName(), |
91 HTMLNames::xhtmlNamespaceURI), | 96 HTMLNames::xhtmlNamespaceURI), |
92 document); | 97 document); |
93 // TODO(davaajav): write this as one call to setCustomElementState instead of
two | 98 // TODO(davaajav): write this as one call to setCustomElementState instead of |
| 99 // two |
94 element->setCustomElementState(CustomElementState::Undefined); | 100 element->setCustomElementState(CustomElementState::Undefined); |
95 element->setCustomElementDefinition(this); | 101 element->setCustomElementDefinition(this); |
96 return element; | 102 return element; |
97 } | 103 } |
98 | 104 |
99 HTMLElement* CustomElementDefinition::createElementAsync( | 105 HTMLElement* CustomElementDefinition::createElementAsync( |
100 Document& document, | 106 Document& document, |
101 const QualifiedName& tagName) { | 107 const QualifiedName& tagName) { |
102 // https://dom.spec.whatwg.org/#concept-create-element | 108 // https://dom.spec.whatwg.org/#concept-create-element |
103 // 6. If definition is non-null, then: | 109 // 6. If definition is non-null, then: |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 element->synchronizeAttribute(name); | 210 element->synchronizeAttribute(name); |
205 for (const auto& attribute : element->attributesWithoutUpdate()) { | 211 for (const auto& attribute : element->attributesWithoutUpdate()) { |
206 if (hasAttributeChangedCallback(attribute.name())) { | 212 if (hasAttributeChangedCallback(attribute.name())) { |
207 enqueueAttributeChangedCallback(element, attribute.name(), nullAtom, | 213 enqueueAttributeChangedCallback(element, attribute.name(), nullAtom, |
208 attribute.value()); | 214 attribute.value()); |
209 } | 215 } |
210 } | 216 } |
211 } | 217 } |
212 | 218 |
213 } // namespace blink | 219 } // namespace blink |
OLD | NEW |