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" | |
8 #include "core/dom/Element.h" | |
9 #include "core/dom/QualifiedName.h" | |
10 #include "core/dom/custom/V0CustomElement.h" | |
11 #include "core/dom/custom/V0CustomElementRegistrationContext.h" | |
12 #include "core/html/HTMLElement.h" | |
7 #include "platform/text/Character.h" | 13 #include "platform/text/Character.h" |
8 #include "wtf/text/AtomicStringHash.h" | 14 #include "wtf/text/AtomicStringHash.h" |
9 | 15 |
10 namespace blink { | 16 namespace blink { |
11 | 17 |
12 bool CustomElement::isValidName(const AtomicString& name) | 18 bool CustomElement::isValidName(const AtomicString& name) |
13 { | 19 { |
14 if (!name.length() || name[0] < 'a' || name[0] > 'z') | 20 if (!name.length() || name[0] < 'a' || name[0] > 'z') |
15 return false; | 21 return false; |
16 | 22 |
(...skipping 21 matching lines...) Expand all Loading... | |
38 hyphenContainingElementNames.add("font-face-src"); | 44 hyphenContainingElementNames.add("font-face-src"); |
39 hyphenContainingElementNames.add("font-face-uri"); | 45 hyphenContainingElementNames.add("font-face-uri"); |
40 hyphenContainingElementNames.add("font-face-format"); | 46 hyphenContainingElementNames.add("font-face-format"); |
41 hyphenContainingElementNames.add("font-face-name"); | 47 hyphenContainingElementNames.add("font-face-name"); |
42 hyphenContainingElementNames.add("missing-glyph"); | 48 hyphenContainingElementNames.add("missing-glyph"); |
43 } | 49 } |
44 | 50 |
45 return !hyphenContainingElementNames.contains(name); | 51 return !hyphenContainingElementNames.contains(name); |
46 } | 52 } |
47 | 53 |
54 bool CustomElement::shouldCreateCustomElement(Document& document, const AtomicSt ring& localName) | |
55 { | |
56 return RuntimeEnabledFeatures::customElementsV1Enabled() | |
57 && document.frame() && isValidName(localName); | |
58 } | |
59 | |
60 bool CustomElement::shouldCreateCustomElement(Document& document, const Qualifie dName& tagName) | |
61 { | |
62 return shouldCreateCustomElement(document, tagName.localName()) | |
63 && tagName.namespaceURI() == HTMLNames::xhtmlNamespaceURI; | |
64 } | |
65 | |
66 HTMLElement* CustomElement::createCustomElement(Document& document, const Atomic String& localName) | |
67 { | |
68 return createCustomElement(document, | |
69 QualifiedName(nullAtom, document.convertLocalName(localName), HTMLNames: :xhtmlNamespaceURI)); | |
70 } | |
71 | |
72 HTMLElement* CustomElement::createCustomElement(Document& document, const Qualif iedName& tagName) | |
73 { | |
74 DCHECK(shouldCreateCustomElement(document, tagName)); | |
75 | |
76 // TODO(kojii): This does not lookup already defined custom elements yet. | |
dominicc (has gone to gerrit)
2016/05/25 05:25:52
Could you make this TODO(who) what/when so it is e
kojii
2016/05/25 05:58:24
Done.
| |
77 | |
78 HTMLElement* element; | |
79 if (V0CustomElement::isValidName(tagName.localName()) && document.registrati onContext()) { | |
80 Element* e = document.registrationContext()->createCustomTagElement(docu ment, tagName); | |
yosin_UTC9
2016/05/25 01:16:20
nit: Could you avoid to use one letter variable na
kojii
2016/05/25 02:44:53
Will do in the next patch.
kojii
2016/05/25 05:58:24
Done.
| |
81 SECURITY_DCHECK(e->isHTMLElement()); | |
82 element = toHTMLElement(e); | |
83 } else { | |
84 element = HTMLElement::create(tagName, document); | |
85 } | |
86 | |
87 element->setCustomElementState(CustomElementState::Undefined); | |
yosin_UTC9
2016/05/25 01:16:20
Can we set customer element state in HTML construc
kojii
2016/05/25 02:44:53
Shouldn't the default be "uncustomized"? That's th
yosin_UTC9
2016/05/25 04:18:15
I summarize initial state of "customer element sta
dominicc (has gone to gerrit)
2016/05/25 05:25:52
I guess "is" happens in parserSetAttributes?
kojii
2016/05/25 05:58:24
Yeah, for parser, I think we'll need to split crea
| |
88 | |
89 return element; | |
90 } | |
91 | |
48 } // namespace blink | 92 } // namespace blink |
OLD | NEW |