| 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 CustomElement_h | 5 #ifndef CustomElement_h |
| 6 #define CustomElement_h | 6 #define CustomElement_h |
| 7 | 7 |
| 8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
| 9 #include "core/HTMLNames.h" | 9 #include "core/HTMLNames.h" |
| 10 #include "core/dom/Element.h" | 10 #include "core/dom/Element.h" |
| 11 #include "platform/text/Character.h" |
| 12 #include "wtf/ASCIICType.h" |
| 11 #include "wtf/Allocator.h" | 13 #include "wtf/Allocator.h" |
| 12 #include "wtf/text/AtomicString.h" | 14 #include "wtf/text/AtomicString.h" |
| 13 | 15 |
| 14 namespace blink { | 16 namespace blink { |
| 15 | 17 |
| 16 class Document; | 18 class Document; |
| 17 class Element; | 19 class Element; |
| 18 class HTMLElement; | 20 class HTMLElement; |
| 19 class QualifiedName; | 21 class QualifiedName; |
| 20 class CustomElementDefinition; | 22 class CustomElementDefinition; |
| 21 class CustomElementReaction; | 23 class CustomElementReaction; |
| 22 class CustomElementRegistry; | 24 class CustomElementRegistry; |
| 23 | 25 |
| 24 class CORE_EXPORT CustomElement { | 26 class CORE_EXPORT CustomElement { |
| 25 STATIC_ONLY(CustomElement); | 27 STATIC_ONLY(CustomElement); |
| 26 public: | 28 public: |
| 27 // Retrieves the CustomElementRegistry for Element, if any. This | 29 // Retrieves the CustomElementRegistry for Element, if any. This |
| 28 // may be a different object for a given element over its lifetime | 30 // may be a different object for a given element over its lifetime |
| 29 // as it moves between documents. | 31 // as it moves between documents. |
| 30 static CustomElementRegistry* registry(const Element&); | 32 static CustomElementRegistry* registry(const Element&); |
| 31 static CustomElementRegistry* registry(const Document&); | 33 static CustomElementRegistry* registry(const Document&); |
| 32 | 34 |
| 33 static CustomElementDefinition* definitionForElement(const Element*); | 35 static CustomElementDefinition* definitionForElement(const Element*); |
| 34 | 36 |
| 35 static bool isValidName(const AtomicString& name); | 37 static bool isValidName(const AtomicString& name) |
| 38 { |
| 39 // This quickly rejects all common built-in element names. |
| 40 if (name.find('-', 1) == kNotFound) |
| 41 return false; |
| 42 |
| 43 if (!isASCIILower(name[0])) |
| 44 return false; |
| 45 |
| 46 if (name.is8Bit()) { |
| 47 const LChar* characters = name.characters8(); |
| 48 for (size_t i = 1; i < name.length(); ++i) { |
| 49 if (!Character::isPotentialCustomElementName8BitChar(characters[
i])) |
| 50 return false; |
| 51 } |
| 52 } else { |
| 53 const UChar* characters = name.characters16(); |
| 54 for (size_t i = 1; i < name.length(); ) { |
| 55 UChar32 ch; |
| 56 U16_NEXT(characters, i, name.length(), ch); |
| 57 if (!Character::isPotentialCustomElementNameChar(ch)) |
| 58 return false; |
| 59 } |
| 60 } |
| 61 |
| 62 return !isHyphenatedSpecElementName(name); |
| 63 } |
| 36 | 64 |
| 37 static bool shouldCreateCustomElement(const AtomicString& localName); | 65 static bool shouldCreateCustomElement(const AtomicString& localName); |
| 38 static bool shouldCreateCustomElement(const QualifiedName&); | 66 static bool shouldCreateCustomElement(const QualifiedName&); |
| 39 | 67 |
| 40 static HTMLElement* createCustomElementSync(Document&, const AtomicString& l
ocalName, ExceptionState&); | 68 static HTMLElement* createCustomElementSync(Document&, const AtomicString& l
ocalName, ExceptionState&); |
| 41 static HTMLElement* createCustomElementSync(Document&, const QualifiedName&,
ExceptionState&); | 69 static HTMLElement* createCustomElementSync(Document&, const QualifiedName&,
ExceptionState&); |
| 42 static HTMLElement* createCustomElementSync(Document&, const QualifiedName&)
; | 70 static HTMLElement* createCustomElementSync(Document&, const QualifiedName&)
; |
| 43 static HTMLElement* createCustomElementAsync(Document&, const QualifiedName&
); | 71 static HTMLElement* createCustomElementAsync(Document&, const QualifiedName&
); |
| 44 | 72 |
| 45 static HTMLElement* createFailedElement(Document&, const QualifiedName&); | 73 static HTMLElement* createFailedElement(Document&, const QualifiedName&); |
| 46 | 74 |
| 47 static void enqueue(Element*, CustomElementReaction*); | 75 static void enqueue(Element*, CustomElementReaction*); |
| 48 static void enqueueConnectedCallback(Element*); | 76 static void enqueueConnectedCallback(Element*); |
| 49 static void enqueueDisconnectedCallback(Element*); | 77 static void enqueueDisconnectedCallback(Element*); |
| 50 static void enqueueAdoptedCallback(Element*); | 78 static void enqueueAdoptedCallback(Element*); |
| 51 static void enqueueAttributeChangedCallback(Element*, const QualifiedName&, | 79 static void enqueueAttributeChangedCallback(Element*, const QualifiedName&, |
| 52 const AtomicString& oldValue, const AtomicString& newValue); | 80 const AtomicString& oldValue, const AtomicString& newValue); |
| 53 | 81 |
| 54 static void tryToUpgrade(Element*); | 82 static void tryToUpgrade(Element*); |
| 55 | 83 |
| 56 private: | 84 private: |
| 85 // Some existing specs have element names with hyphens in them, |
| 86 // like font-face in SVG. The custom elements spec explicitly |
| 87 // disallows these as custom element names. |
| 88 // https://html.spec.whatwg.org/#valid-custom-element-name |
| 89 static bool isHyphenatedSpecElementName(const AtomicString&); |
| 57 static HTMLElement* createUndefinedElement(Document&, const QualifiedName&); | 90 static HTMLElement* createUndefinedElement(Document&, const QualifiedName&); |
| 58 }; | 91 }; |
| 59 | 92 |
| 60 } // namespace blink | 93 } // namespace blink |
| 61 | 94 |
| 62 #endif // CustomElement_h | 95 #endif // CustomElement_h |
| OLD | NEW |