15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/*
25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2008, 2010 Apple Inc. All rights reserved.
35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2008 David Smith <catfish.man@gmail.com>
45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * This library is free software; you can redistribute it and/or
65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modify it under the terms of the GNU Library General Public
75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * License as published by the Free Software Foundation; either
85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * version 2 of the License, or (at your option) any later version.
95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * This library is distributed in the hope that it will be useful,
115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * but WITHOUT ANY WARRANTY; without even the implied warranty of
125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Library General Public License for more details.
145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * You should have received a copy of the GNU Library General Public License
165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * along with this library; see the file COPYING.LIB.  If not, write to
175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Boston, MA 02110-1301, USA.
195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */
215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifndef NodeRareData_h
235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define NodeRareData_h
245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/dom/MutationObserverRegistration.h"
26197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "core/dom/NodeListsNodeData.h"
2710f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch#include "platform/heap/Handle.h"
28591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch#include "wtf/HashSet.h"
29591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch#include "wtf/OwnPtr.h"
30591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch#include "wtf/PassOwnPtr.h"
315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
32c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink {
335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3410f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdochclass NodeMutationObserverData FINAL : public NoBaseWillBeGarbageCollected<NodeMutationObserverData> {
3510f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    WTF_MAKE_NONCOPYABLE(NodeMutationObserverData);
3610f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
37926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)public:
3810f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    WillBeHeapVector<OwnPtrWillBeMember<MutationObserverRegistration> > registry;
3910f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration> > transientRegistry;
405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
4110f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    static PassOwnPtrWillBeRawPtr<NodeMutationObserverData> create()
4210f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    {
4310f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch        return adoptPtrWillBeNoop(new NodeMutationObserverData);
4410f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    }
4510f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch
4610f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    void trace(Visitor* visitor)
4710f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    {
48197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#if ENABLE(OILPAN)
4910f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch        visitor->trace(registry);
5010f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch        visitor->trace(transientRegistry);
51197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#endif
5210f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    }
535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
54926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)private:
55926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    NodeMutationObserverData() { }
56926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)};
575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
58323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)class NodeRareData : public NoBaseWillBeGarbageCollectedFinalized<NodeRareData>, public NodeRareDataBase {
59323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    WTF_MAKE_NONCOPYABLE(NodeRareData);
60323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
61926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)public:
62323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    static NodeRareData* create(RenderObject* renderer)
6310f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    {
64323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)        return new NodeRareData(renderer);
6510f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    }
6610f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch
67926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    void clearNodeLists() { m_nodeLists.clear(); }
68926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    NodeListsNodeData* nodeLists() const { return m_nodeLists.get(); }
69f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)    NodeListsNodeData& ensureNodeLists()
705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    {
71926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        if (!m_nodeLists)
72926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)            m_nodeLists = NodeListsNodeData::create();
73f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)        return *m_nodeLists;
745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
76926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    NodeMutationObserverData* mutationObserverData() { return m_mutationObserverData.get(); }
77f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)    NodeMutationObserverData& ensureMutationObserverData()
785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    {
79926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        if (!m_mutationObserverData)
80926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)            m_mutationObserverData = NodeMutationObserverData::create();
81f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)        return *m_mutationObserverData;
825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
84926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    unsigned connectedSubframeCount() const { return m_connectedFrameCount; }
85926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    void incrementConnectedSubframeCount(unsigned amount)
86926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    {
87926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        m_connectedFrameCount += amount;
88926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    }
89926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    void decrementConnectedSubframeCount(unsigned amount)
90926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    {
91926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        ASSERT(m_connectedFrameCount);
92926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        ASSERT(amount <= m_connectedFrameCount);
93926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        m_connectedFrameCount -= amount;
94926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    }
955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
9607a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    bool hasElementFlag(ElementFlags mask) const { return m_elementFlags & mask; }
9707a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    void setElementFlag(ElementFlags mask, bool value) { m_elementFlags = (m_elementFlags & ~mask) | (-(int32_t)value & mask); }
9807a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    void clearElementFlag(ElementFlags mask) { m_elementFlags &= ~mask; }
9907a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch
10007a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    bool hasRestyleFlag(DynamicRestyleFlags mask) const { return m_restyleFlags & mask; }
10107a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    void setRestyleFlag(DynamicRestyleFlags mask) { m_restyleFlags |= mask; RELEASE_ASSERT(m_restyleFlags); }
10207a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    bool hasRestyleFlags() const { return m_restyleFlags; }
10307a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    void clearRestyleFlags() { m_restyleFlags = 0; }
10407a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch
10507a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    enum {
10607a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch        ConnectedFrameCountBits = 10, // Must fit Page::maxNumberOfFrames.
10707a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    };
10807a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch
109323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    void trace(Visitor*);
110323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)
111323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    void traceAfterDispatch(Visitor*);
112323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    void finalizeGarbageCollectedObject();
113323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)
1145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)protected:
115d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    explicit NodeRareData(RenderObject* renderer)
116926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        : NodeRareDataBase(renderer)
117926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        , m_connectedFrameCount(0)
11807a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch        , m_elementFlags(0)
11907a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch        , m_restyleFlags(0)
120323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)        , m_isElementRareData(false)
121926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    { }
1225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)private:
124d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    OwnPtrWillBeMember<NodeListsNodeData> m_nodeLists;
125323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    OwnPtrWillBeMember<NodeMutationObserverData> m_mutationObserverData;
12607a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch
12707a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    unsigned m_connectedFrameCount : ConnectedFrameCountBits;
12807a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    unsigned m_elementFlags : NumberOfElementFlags;
12907a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    unsigned m_restyleFlags : NumberOfDynamicRestyleFlags;
130323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)protected:
131323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    unsigned m_isElementRareData : 1;
1325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)};
1335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
134c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink
1355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif // NodeRareData_h
137