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 CustomElementDefinition_h | 5 #ifndef CustomElementDefinition_h |
6 #define CustomElementDefinition_h | 6 #define CustomElementDefinition_h |
7 | 7 |
8 #include "bindings/core/v8/ScriptValue.h" | 8 #include "bindings/core/v8/ScriptValue.h" |
9 #include "core/CoreExport.h" | 9 #include "core/CoreExport.h" |
10 #include "core/dom/custom/CustomElementDescriptor.h" | 10 #include "core/dom/custom/CustomElementDescriptor.h" |
11 #include "platform/heap/Handle.h" | 11 #include "platform/heap/Handle.h" |
12 #include "wtf/HashSet.h" | |
13 #include "wtf/Noncopyable.h" | 12 #include "wtf/Noncopyable.h" |
14 #include "wtf/text/AtomicString.h" | |
15 #include "wtf/text/AtomicStringHash.h" | |
16 | 13 |
17 namespace blink { | 14 namespace blink { |
18 | 15 |
19 class Element; | 16 class Element; |
20 class ExceptionState; | 17 class ExceptionState; |
21 class HTMLElement; | 18 class HTMLElement; |
22 class QualifiedName; | 19 class QualifiedName; |
23 | 20 |
24 class CORE_EXPORT CustomElementDefinition | 21 class CORE_EXPORT CustomElementDefinition |
25 : public GarbageCollectedFinalized<CustomElementDefinition> { | 22 : public GarbageCollectedFinalized<CustomElementDefinition> { |
26 WTF_MAKE_NONCOPYABLE(CustomElementDefinition); | 23 WTF_MAKE_NONCOPYABLE(CustomElementDefinition); |
27 public: | 24 public: |
28 CustomElementDefinition(const CustomElementDescriptor&); | 25 CustomElementDefinition(const CustomElementDescriptor&); |
29 CustomElementDefinition(const CustomElementDescriptor&, | |
30 const HashSet<AtomicString>&); | |
31 virtual ~CustomElementDefinition(); | 26 virtual ~CustomElementDefinition(); |
32 | 27 |
33 DECLARE_VIRTUAL_TRACE(); | 28 DECLARE_VIRTUAL_TRACE(); |
34 | 29 |
35 const CustomElementDescriptor& descriptor() { return m_descriptor; } | 30 const CustomElementDescriptor& descriptor() { return m_descriptor; } |
36 | 31 |
37 // TODO(yosin): To support Web Modules, introduce an abstract | 32 // TODO(yosin): To support Web Modules, introduce an abstract |
38 // class |CustomElementConstructor| to allow us to have JavaScript | 33 // class |CustomElementConstructor| to allow us to have JavaScript |
39 // and C++ constructors and ask the binding layer to convert | 34 // and C++ constructors and ask the binding layer to convert |
40 // |CustomElementConstructor| to |ScriptValue|. Replace | 35 // |CustomElementConstructor| to |ScriptValue|. Replace |
41 // |getConstructorForScript()| by |getConstructor() -> | 36 // |getConstructorForScript()| by |getConstructor() -> |
42 // CustomElementConstructor|. | 37 // CustomElementConstructor|. |
43 virtual ScriptValue getConstructorForScript() = 0; | 38 virtual ScriptValue getConstructorForScript() = 0; |
44 | 39 |
45 using ConstructionStack = HeapVector<Member<Element>, 1>; | 40 using ConstructionStack = HeapVector<Member<Element>, 1>; |
46 ConstructionStack& constructionStack() | 41 ConstructionStack& constructionStack() |
47 { | 42 { |
48 return m_constructionStack; | 43 return m_constructionStack; |
49 } | 44 } |
50 | 45 |
51 virtual HTMLElement* createElementSync(Document&, const QualifiedName&) = 0; | 46 virtual HTMLElement* createElementSync(Document&, const QualifiedName&) = 0; |
52 virtual HTMLElement* createElementSync(Document&, const QualifiedName&, Exce
ptionState&) = 0; | 47 virtual HTMLElement* createElementSync(Document&, const QualifiedName&, Exce
ptionState&) = 0; |
53 HTMLElement* createElementAsync(Document&, const QualifiedName&); | 48 HTMLElement* createElementAsync(Document&, const QualifiedName&); |
54 | 49 |
55 void upgrade(Element*); | 50 void upgrade(Element*); |
56 | 51 |
57 virtual bool hasConnectedCallback() const = 0; | 52 // TODO(kojii): Change these methods to pure when script-side is implemented
. |
58 virtual bool hasDisconnectedCallback() const = 0; | 53 virtual bool hasConnectedCallback() const { return true; } |
59 bool hasAttributeChangedCallback(const QualifiedName&); | 54 virtual bool hasDisconnectedCallback() const { return true; } |
| 55 virtual bool hasAttributeChangedCallback(const QualifiedName&) const { retur
n true; } |
60 | 56 |
61 virtual void runConnectedCallback(Element*) = 0; | 57 virtual void runConnectedCallback(Element*) {} |
62 virtual void runDisconnectedCallback(Element*) = 0; | 58 virtual void runDisconnectedCallback(Element*) {} |
63 virtual void runAttributeChangedCallback(Element*, const QualifiedName&, | 59 virtual void runAttributeChangedCallback(Element*, const QualifiedName&, |
64 const AtomicString& oldValue, const AtomicString& newValue) = 0; | 60 const AtomicString& oldValue, const AtomicString& newValue) {} |
65 | 61 |
66 void enqueueUpgradeReaction(Element*); | 62 void enqueueUpgradeReaction(Element*); |
67 void enqueueConnectedCallback(Element*); | 63 void enqueueConnectedCallback(Element*); |
68 void enqueueDisconnectedCallback(Element*); | 64 void enqueueDisconnectedCallback(Element*); |
69 void enqueueAttributeChangedCallback(Element*, const QualifiedName&, | 65 void enqueueAttributeChangedCallback(Element*, const QualifiedName&, |
70 const AtomicString& oldValue, const AtomicString& newValue); | 66 const AtomicString& oldValue, const AtomicString& newValue); |
71 | 67 |
72 protected: | 68 protected: |
73 virtual bool runConstructor(Element*) = 0; | 69 virtual bool runConstructor(Element*) = 0; |
74 | 70 |
75 static void checkConstructorResult(Element*, Document&, const QualifiedName&
, ExceptionState&); | 71 static void checkConstructorResult(Element*, Document&, const QualifiedName&
, ExceptionState&); |
76 | 72 |
77 HashSet<AtomicString> m_observedAttributes; | |
78 | |
79 private: | 73 private: |
80 const CustomElementDescriptor m_descriptor; | 74 const CustomElementDescriptor m_descriptor; |
81 ConstructionStack m_constructionStack; | 75 ConstructionStack m_constructionStack; |
82 | |
83 void enqueueAttributeChangedCallbackForAllAttributes(Element*); | |
84 }; | 76 }; |
85 | 77 |
86 } // namespace blink | 78 } // namespace blink |
87 | 79 |
88 #endif // CustomElementDefinition_h | 80 #endif // CustomElementDefinition_h |
OLD | NEW |