Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / core / dom / NodeRareData.h
blob2f43c45bba6eb350bf430375e770d011dd3c581e
1 /*
2 * Copyright (C) 2008, 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 David Smith <catfish.man@gmail.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
22 #ifndef NodeRareData_h
23 #define NodeRareData_h
25 #include "core/dom/MutationObserverRegistration.h"
26 #include "core/dom/NodeListsNodeData.h"
27 #include "platform/heap/Handle.h"
28 #include "wtf/HashSet.h"
29 #include "wtf/OwnPtr.h"
30 #include "wtf/PassOwnPtr.h"
32 namespace blink {
34 class NodeMutationObserverData final : public NoBaseWillBeGarbageCollected<NodeMutationObserverData> {
35 WTF_MAKE_NONCOPYABLE(NodeMutationObserverData);
36 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED(NodeMutationObserverData);
37 public:
38 WillBeHeapVector<OwnPtrWillBeMember<MutationObserverRegistration>> registry;
39 WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration>> transientRegistry;
41 static PassOwnPtrWillBeRawPtr<NodeMutationObserverData> create()
43 return adoptPtrWillBeNoop(new NodeMutationObserverData);
46 DEFINE_INLINE_TRACE()
48 #if ENABLE(OILPAN)
49 visitor->trace(registry);
50 visitor->trace(transientRegistry);
51 #endif
54 private:
55 NodeMutationObserverData() { }
58 class NodeRareData : public NoBaseWillBeGarbageCollectedFinalized<NodeRareData>, public NodeRareDataBase {
59 WTF_MAKE_NONCOPYABLE(NodeRareData);
60 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED(NodeRareData);
61 public:
62 static NodeRareData* create(LayoutObject* layoutObject)
64 return new NodeRareData(layoutObject);
67 void clearNodeLists() { m_nodeLists.clear(); }
68 NodeListsNodeData* nodeLists() const { return m_nodeLists.get(); }
69 NodeListsNodeData& ensureNodeLists()
71 if (!m_nodeLists)
72 m_nodeLists = NodeListsNodeData::create();
73 return *m_nodeLists;
76 NodeMutationObserverData* mutationObserverData() { return m_mutationObserverData.get(); }
77 NodeMutationObserverData& ensureMutationObserverData()
79 if (!m_mutationObserverData)
80 m_mutationObserverData = NodeMutationObserverData::create();
81 return *m_mutationObserverData;
84 unsigned connectedSubframeCount() const { return m_connectedFrameCount; }
85 void incrementConnectedSubframeCount(unsigned amount);
86 void decrementConnectedSubframeCount(unsigned amount)
88 ASSERT(m_connectedFrameCount);
89 ASSERT(amount <= m_connectedFrameCount);
90 m_connectedFrameCount -= amount;
93 bool hasElementFlag(ElementFlags mask) const { return m_elementFlags & mask; }
94 void setElementFlag(ElementFlags mask, bool value) { m_elementFlags = (m_elementFlags & ~mask) | (-(int32_t)value & mask); }
95 void clearElementFlag(ElementFlags mask) { m_elementFlags &= ~mask; }
97 bool hasRestyleFlag(DynamicRestyleFlags mask) const { return m_restyleFlags & mask; }
98 void setRestyleFlag(DynamicRestyleFlags mask) { m_restyleFlags |= mask; RELEASE_ASSERT(m_restyleFlags); }
99 bool hasRestyleFlags() const { return m_restyleFlags; }
100 void clearRestyleFlags() { m_restyleFlags = 0; }
102 enum {
103 ConnectedFrameCountBits = 10, // Must fit Page::maxNumberOfFrames.
106 DECLARE_TRACE();
108 DECLARE_TRACE_AFTER_DISPATCH();
109 void finalizeGarbageCollectedObject();
111 protected:
112 explicit NodeRareData(LayoutObject* layoutObject)
113 : NodeRareDataBase(layoutObject)
114 , m_connectedFrameCount(0)
115 , m_elementFlags(0)
116 , m_restyleFlags(0)
117 , m_isElementRareData(false)
120 private:
121 OwnPtrWillBeMember<NodeListsNodeData> m_nodeLists;
122 OwnPtrWillBeMember<NodeMutationObserverData> m_mutationObserverData;
124 unsigned m_connectedFrameCount : ConnectedFrameCountBits;
125 unsigned m_elementFlags : NumberOfElementFlags;
126 unsigned m_restyleFlags : NumberOfDynamicRestyleFlags;
127 protected:
128 unsigned m_isElementRareData : 1;
131 } // namespace blink
133 #endif // NodeRareData_h