Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(225)

Side by Side Diff: Source/core/dom/CustomElementRegistry.h

Issue 14660019: Run Mutation Observer and Custom Element callbacks consistently at microtask checkpoint (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Patch for landing. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 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 14 matching lines...) Expand all
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
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 CustomElementRegistry_h 31 #ifndef CustomElementRegistry_h
32 #define CustomElementRegistry_h 32 #define CustomElementRegistry_h
33 33
34 #include "core/dom/ContextLifecycleObserver.h" 34 #include "core/dom/ContextLifecycleObserver.h"
35 #include "core/dom/CustomElementCallback.h"
36 #include "core/dom/CustomElementUpgradeCandidateMap.h" 35 #include "core/dom/CustomElementUpgradeCandidateMap.h"
37 #include "core/dom/ExceptionCode.h" 36 #include "core/dom/ExceptionCode.h"
38 #include "core/dom/QualifiedName.h" 37 #include "core/dom/QualifiedName.h"
39 #include "wtf/ListHashSet.h"
40 #include "wtf/PassRefPtr.h" 38 #include "wtf/PassRefPtr.h"
41 #include "wtf/RefCounted.h" 39 #include "wtf/RefCounted.h"
42 #include "wtf/RefPtr.h" 40 #include "wtf/RefPtr.h"
43 #include "wtf/Vector.h"
44 #include "wtf/text/AtomicString.h" 41 #include "wtf/text/AtomicString.h"
45 #include "wtf/text/AtomicStringHash.h" 42 #include "wtf/text/AtomicStringHash.h"
46 43
47 namespace WebCore { 44 namespace WebCore {
48 45
49 class CustomElementConstructorBuilder; 46 class CustomElementConstructorBuilder;
50 class CustomElementDefinition; 47 class CustomElementDefinition;
51 class Dictionary;
52 class Document; 48 class Document;
53 class Element; 49 class Element;
54 50
55 class CustomElementInvocation {
56 public:
57 CustomElementInvocation(PassRefPtr<CustomElementCallback>, PassRefPtr<Elemen t>);
58 ~CustomElementInvocation();
59
60 CustomElementCallback* callback() const { return m_callback.get(); }
61 Element* element() const { return m_element.get(); }
62
63 private:
64 RefPtr<CustomElementCallback> m_callback;
65 RefPtr<Element> m_element;
66 };
67
68 void setTypeExtension(Element*, const AtomicString& typeExtension); 51 void setTypeExtension(Element*, const AtomicString& typeExtension);
69 52
70 class CustomElementRegistry : public RefCounted<CustomElementRegistry>, public C ontextLifecycleObserver { 53 class CustomElementRegistry : public RefCounted<CustomElementRegistry>, public C ontextLifecycleObserver {
71 WTF_MAKE_NONCOPYABLE(CustomElementRegistry); WTF_MAKE_FAST_ALLOCATED; 54 WTF_MAKE_NONCOPYABLE(CustomElementRegistry); WTF_MAKE_FAST_ALLOCATED;
72 public: 55 public:
73 class CallbackDeliveryScope {
74 public:
75 CallbackDeliveryScope() { }
76 ~CallbackDeliveryScope() { CustomElementRegistry::deliverAllLifecycleCal lbacksIfNeeded(); }
77 };
78
79 explicit CustomElementRegistry(Document*); 56 explicit CustomElementRegistry(Document*);
80 ~CustomElementRegistry(); 57 virtual ~CustomElementRegistry() { }
81 58
82 void registerElement(CustomElementConstructorBuilder*, const AtomicString& n ame, ExceptionCode&); 59 void registerElement(CustomElementConstructorBuilder*, const AtomicString& n ame, ExceptionCode&);
83 60
84 bool isUnresolved(Element*) const; 61 bool isUnresolved(Element*) const;
85 PassRefPtr<CustomElementDefinition> findFor(Element*) const; 62 PassRefPtr<CustomElementDefinition> findFor(Element*) const;
86 63
87 PassRefPtr<Element> createCustomTagElement(const QualifiedName& localName); 64 PassRefPtr<Element> createCustomTagElement(const QualifiedName& localName);
88 65
89 Document* document() const; 66 Document* document() const;
90 67
91 void didGiveTypeExtension(Element*, const AtomicString&); 68 void didGiveTypeExtension(Element*, const AtomicString&);
92 void customElementWasDestroyed(Element*); 69 void customElementWasDestroyed(Element*);
93 70
94 static bool isCustomTagName(const AtomicString& name) { return isValidName(n ame); } 71 static bool isCustomTagName(const AtomicString& name) { return isValidName(n ame); }
95 72
96 static void deliverAllLifecycleCallbacks();
97 static void deliverAllLifecycleCallbacksIfNeeded();
98
99 private: 73 private:
100 typedef HashMap<AtomicString, RefPtr<CustomElementDefinition> > DefinitionMa p; 74 typedef HashMap<AtomicString, RefPtr<CustomElementDefinition> > DefinitionMa p;
101 typedef ListHashSet<CustomElementRegistry*> InstanceSet;
102
103 static bool isValidName(const AtomicString&); 75 static bool isValidName(const AtomicString&);
104 76
105 static InstanceSet& activeCustomElementRegistries();
106 void enqueueReadyCallback(CustomElementCallback*, Element*);
107 void deactivate();
108 void deliverLifecycleCallbacks();
109
110 PassRefPtr<CustomElementDefinition> findAndCheckNamespace(const AtomicString & type, const AtomicString& namespaceURI) const; 77 PassRefPtr<CustomElementDefinition> findAndCheckNamespace(const AtomicString & type, const AtomicString& namespaceURI) const;
111 78
112 void didCreateCustomTagElement(CustomElementDefinition*, Element*); 79 void didCreateCustomTagElement(CustomElementDefinition*, Element*);
113 void didCreateUnresolvedElement(CustomElementDefinition::CustomElementKind, const AtomicString& type, Element*); 80 void didCreateUnresolvedElement(CustomElementDefinition::CustomElementKind, const AtomicString& type, Element*);
114 81
115 DefinitionMap m_definitions; 82 DefinitionMap m_definitions;
116 CustomElementUpgradeCandidateMap m_candidates; 83 CustomElementUpgradeCandidateMap m_candidates;
117
118 Vector<CustomElementInvocation> m_invocations;
119 }; 84 };
120 85
121 inline void CustomElementRegistry::deliverAllLifecycleCallbacksIfNeeded()
122 {
123 if (!activeCustomElementRegistries().isEmpty())
124 deliverAllLifecycleCallbacks();
125 ASSERT(activeCustomElementRegistries().isEmpty());
126 }
127
128 inline CustomElementRegistry::InstanceSet& CustomElementRegistry::activeCustomEl ementRegistries()
129 {
130 DEFINE_STATIC_LOCAL(InstanceSet, activeInstances, ());
131 return activeInstances;
132 }
133
134
135 } // namespace WebCore 86 } // namespace WebCore
136 87
137 #endif 88 #endif
OLDNEW
« no previous file with comments | « Source/core/dom/CustomElementCallbackDispatcher.cpp ('k') | Source/core/dom/CustomElementRegistry.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698