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 #ifndef CustomElementDescriptor_h | 5 #ifndef CustomElementDescriptor_h |
6 #define CustomElementDescriptor_h | 6 #define CustomElementDescriptor_h |
7 | 7 |
8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
| 9 #include "core/dom/Element.h" |
9 #include "wtf/Allocator.h" | 10 #include "wtf/Allocator.h" |
10 #include "wtf/HashTableDeletedValueType.h" | 11 #include "wtf/HashTableDeletedValueType.h" |
11 #include "wtf/text/AtomicString.h" | 12 #include "wtf/text/AtomicString.h" |
12 | 13 |
13 namespace blink { | 14 namespace blink { |
14 | 15 |
15 // Describes what elements a custom element definition applies to. | 16 // Describes what elements a custom element definition applies to. |
| 17 // https://html.spec.whatwg.org/multipage/scripting.html#custom-elements-core-co
ncepts |
16 // | 18 // |
17 // There are two kinds of definitions: The first has its own tag name; | 19 // There are two kinds of definitions: |
18 // in this case the "name" (definition name) and local name (tag name) | |
19 // are the same. The second kind customizes a built-in element; in | |
20 // that case, the descriptor's local name will be a built-in element | |
21 // name, or an unknown element name that is *not* a valid custom | |
22 // element name. | |
23 // | 20 // |
24 // This type is used when the kind of custom element definition is | 21 // [Autonomous] These have their own tag name. In that case "name" |
25 // known, and generally the difference is important. For example, a | 22 // (the definition name) and local name (the tag name) are identical. |
26 // definition for "my-element", "my-element" must not be applied to an | 23 // |
27 // element <button is="my-element">. | 24 // [Customized built-in] The name is still a valid custom element |
| 25 // name; but the local name will be a built-in element name, or an |
| 26 // unknown element name that is *not* a valid custom element name. |
| 27 // |
| 28 // CustomElementDescriptor used when the kind of custom element |
| 29 // definition is known, and generally the difference is important. For |
| 30 // example, a definition for "my-element", "my-element" must not be |
| 31 // applied to an element <button is="my-element">. |
28 class CORE_EXPORT CustomElementDescriptor final { | 32 class CORE_EXPORT CustomElementDescriptor final { |
29 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 33 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
30 public: | 34 public: |
31 CustomElementDescriptor() | 35 CustomElementDescriptor() |
32 { | 36 { |
33 } | 37 } |
34 | 38 |
35 CustomElementDescriptor( | 39 CustomElementDescriptor( |
36 const AtomicString& name, | 40 const AtomicString& name, |
37 const AtomicString& localName) | 41 const AtomicString& localName) |
(...skipping 13 matching lines...) Expand all Loading... |
51 } | 55 } |
52 | 56 |
53 bool operator==(const CustomElementDescriptor& other) const | 57 bool operator==(const CustomElementDescriptor& other) const |
54 { | 58 { |
55 return m_name == other.m_name && m_localName == other.m_localName; | 59 return m_name == other.m_name && m_localName == other.m_localName; |
56 } | 60 } |
57 | 61 |
58 const AtomicString& name() const { return m_name; } | 62 const AtomicString& name() const { return m_name; } |
59 const AtomicString& localName() const { return m_localName; } | 63 const AtomicString& localName() const { return m_localName; } |
60 | 64 |
| 65 bool matches(const Element& element) const |
| 66 { |
| 67 return localName() == element.localName() |
| 68 && (isAutonomous() |
| 69 || name() == element.getAttribute(HTMLNames::isAttr)) |
| 70 && element.namespaceURI() == HTMLNames::xhtmlNamespaceURI; |
| 71 } |
| 72 |
| 73 bool isAutonomous() const { return m_name == m_localName; } |
| 74 |
61 private: | 75 private: |
62 AtomicString m_name; | 76 AtomicString m_name; |
63 AtomicString m_localName; | 77 AtomicString m_localName; |
64 }; | 78 }; |
65 | 79 |
66 } // namespace blink | 80 } // namespace blink |
67 | 81 |
68 #endif // CustomElementDescriptor_h | 82 #endif // CustomElementDescriptor_h |
OLD | NEW |