2 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
31 #ifndef ShadowRootRareData_h
32 #define ShadowRootRareData_h
34 #include "core/dom/shadow/InsertionPoint.h"
35 #include "wtf/RefPtr.h"
36 #include "wtf/Vector.h"
40 class ShadowRootRareData : public NoBaseWillBeGarbageCollectedFinalized<ShadowRootRareData> {
43 : m_descendantShadowElementCount(0)
44 , m_descendantContentElementCount(0)
45 , m_childShadowRootCount(0)
49 HTMLShadowElement* shadowInsertionPointOfYoungerShadowRoot() const { return m_shadowInsertionPointOfYoungerShadowRoot.get(); }
50 void setShadowInsertionPointOfYoungerShadowRoot(PassRefPtr<HTMLShadowElement> shadowInsertionPoint) { m_shadowInsertionPointOfYoungerShadowRoot = shadowInsertionPoint; }
52 void didAddInsertionPoint(InsertionPoint*);
53 void didRemoveInsertionPoint(InsertionPoint*);
55 bool containsShadowElements() const { return m_descendantShadowElementCount; }
56 bool containsContentElements() const { return m_descendantContentElementCount; }
57 bool containsShadowRoots() const { return m_childShadowRootCount; }
59 unsigned descendantShadowElementCount() const { return m_descendantShadowElementCount; }
61 void didAddChildShadowRoot() { ++m_childShadowRootCount; }
62 void didRemoveChildShadowRoot() { ASSERT(m_childShadowRootCount > 0); --m_childShadowRootCount; }
64 unsigned childShadowRootCount() const { return m_childShadowRootCount; }
66 const Vector<RefPtr<InsertionPoint> >& descendantInsertionPoints() { return m_descendantInsertionPoints; }
67 void setDescendantInsertionPoints(Vector<RefPtr<InsertionPoint> >& list) { m_descendantInsertionPoints.swap(list); }
68 void clearDescendantInsertionPoints() { m_descendantInsertionPoints.clear(); }
70 StyleSheetList* styleSheets() { return m_styleSheetList.get(); }
71 void setStyleSheets(PassRefPtrWillBeRawPtr<StyleSheetList> styleSheetList) { m_styleSheetList = styleSheetList; }
73 void trace(Visitor* visitor) { visitor->trace(m_styleSheetList); }
76 RefPtr<HTMLShadowElement> m_shadowInsertionPointOfYoungerShadowRoot;
77 unsigned m_descendantShadowElementCount;
78 unsigned m_descendantContentElementCount;
79 unsigned m_childShadowRootCount;
80 Vector<RefPtr<InsertionPoint> > m_descendantInsertionPoints;
81 RefPtrWillBeMember<StyleSheetList> m_styleSheetList;
84 inline void ShadowRootRareData::didAddInsertionPoint(InsertionPoint* point)
87 if (isHTMLShadowElement(*point))
88 ++m_descendantShadowElementCount;
89 else if (isHTMLContentElement(*point))
90 ++m_descendantContentElementCount;
95 inline void ShadowRootRareData::didRemoveInsertionPoint(InsertionPoint* point)
98 if (isHTMLShadowElement(*point))
99 --m_descendantShadowElementCount;
100 else if (isHTMLContentElement(*point))
101 --m_descendantContentElementCount;
103 ASSERT_NOT_REACHED();
105 ASSERT(m_descendantContentElementCount >= 0);
106 ASSERT(m_descendantShadowElementCount >= 0);
109 } // namespace WebCore