| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef CustomElement_h | 31 #ifndef CustomElement_h |
| 32 #define CustomElement_h | 32 #define CustomElement_h |
| 33 | 33 |
| 34 #include "core/dom/CustomElementDefinition.h" | 34 #include "core/dom/CustomElementDefinition.h" |
| 35 #include "wtf/HashMap.h" | 35 #include "wtf/HashMap.h" |
| 36 #include "wtf/HashSet.h" |
| 36 #include "wtf/Noncopyable.h" | 37 #include "wtf/Noncopyable.h" |
| 37 #include "wtf/PassRefPtr.h" | 38 #include "wtf/PassRefPtr.h" |
| 38 #include "wtf/RefPtr.h" | 39 #include "wtf/RefPtr.h" |
| 39 #include "wtf/Vector.h" | 40 #include "wtf/Vector.h" |
| 40 #include "wtf/text/AtomicString.h" | 41 #include "wtf/text/AtomicString.h" |
| 41 | 42 |
| 42 namespace WebCore { | 43 namespace WebCore { |
| 43 | 44 |
| 44 class Document; | 45 class Document; |
| 45 class Element; | 46 class Element; |
| 46 | 47 |
| 47 class CustomElement { | 48 class CustomElement { |
| 48 public: | 49 public: |
| 49 // FIXME: CustomElementRegistry requires isValidTypeName to be a | 50 // FIXME: CustomElementRegistry requires isValidTypeName to be a |
| 50 // superset of isCustomTagName; consider either merging these or | 51 // superset of isCustomTagName; consider either merging these or |
| 51 // separating them completely into | 52 // separating them completely into |
| 52 // isCustomTagName/isTypeExtensionName. | 53 // isCustomTagName/isTypeExtensionName. |
| 53 static bool isValidTypeName(const AtomicString& type); | 54 static bool isValidTypeName(const AtomicString& type); |
| 54 static bool isCustomTagName(const AtomicString& localName); | 55 static bool isCustomTagName(const AtomicString& localName); |
| 55 static void allowTagName(const AtomicString& localName); | 56 static void allowTagName(const AtomicString& localName); |
| 56 | 57 |
| 57 // API for registration contexts | 58 // API for registration contexts |
| 59 static void setBeingParsed(Element*); |
| 58 static void define(Element*, PassRefPtr<CustomElementDefinition>); | 60 static void define(Element*, PassRefPtr<CustomElementDefinition>); |
| 59 | 61 |
| 60 // API for wrapper creation, which uses a definition as a key | 62 // API for wrapper creation, which uses a definition as a key |
| 61 static CustomElementDefinition* definitionFor(Element*); | 63 static CustomElementDefinition* definitionFor(Element*); |
| 62 | 64 |
| 63 // API for Element to kick off changes | 65 // API for Element to kick off changes |
| 64 | 66 |
| 67 static void finishedParsingChildren(Element*); |
| 65 static void attributeDidChange(Element*, const AtomicString& name, const Ato
micString& oldValue, const AtomicString& newValue); | 68 static void attributeDidChange(Element*, const AtomicString& name, const Ato
micString& oldValue, const AtomicString& newValue); |
| 66 static void didEnterDocument(Element*, Document*); | 69 static void didEnterDocument(Element*, Document*); |
| 67 static void didLeaveDocument(Element*, Document*); | 70 static void didLeaveDocument(Element*, Document*); |
| 68 static void wasDestroyed(Element*); | 71 static void wasDestroyed(Element*); |
| 69 | 72 |
| 70 private: | 73 private: |
| 71 CustomElement(); | 74 CustomElement(); |
| 72 | 75 |
| 73 static Vector<AtomicString>& allowedCustomTagNames(); | 76 static Vector<AtomicString>& allowedCustomTagNames(); |
| 74 | 77 |
| 75 // Maps resolved elements to their definitions | 78 // Maps resolved elements to their definitions |
| 76 | 79 |
| 77 class DefinitionMap { | 80 class DefinitionMap { |
| 78 WTF_MAKE_NONCOPYABLE(DefinitionMap); | 81 WTF_MAKE_NONCOPYABLE(DefinitionMap); |
| 79 public: | 82 public: |
| 80 DefinitionMap() { } | 83 DefinitionMap() { } |
| 81 ~DefinitionMap() { } | 84 ~DefinitionMap() { } |
| 82 | 85 |
| 83 void add(Element*, PassRefPtr<CustomElementDefinition>); | 86 void add(Element*, PassRefPtr<CustomElementDefinition>); |
| 84 void remove(Element*); | 87 void remove(Element*); |
| 85 CustomElementDefinition* get(Element*); | 88 CustomElementDefinition* get(Element*); |
| 86 | 89 |
| 87 private: | 90 private: |
| 88 typedef HashMap<Element*, RefPtr<CustomElementDefinition> > ElementDefin
itionHashMap; | 91 typedef HashMap<Element*, RefPtr<CustomElementDefinition> > ElementDefin
itionHashMap; |
| 89 ElementDefinitionHashMap m_definitions; | 92 ElementDefinitionHashMap m_definitions; |
| 90 }; | 93 }; |
| 91 static DefinitionMap& definitions(); | 94 static DefinitionMap& definitions(); |
| 95 |
| 96 typedef HashSet<Element*> ElementSet; |
| 97 static ElementSet& elementsBeingParsed(); |
| 98 static void setFinishedParsing(Element*); |
| 92 }; | 99 }; |
| 93 | 100 |
| 94 } | 101 } |
| 95 | 102 |
| 96 #endif // CustomElement_h | 103 #endif // CustomElement_h |
| OLD | NEW |