Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / dom / shadow / ShadowRootRareData.h
1 /*
2  * Copyright (C) 2013 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
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
13  * distribution.
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.
17  *
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.
29  */
30
31 #ifndef ShadowRootRareData_h
32 #define ShadowRootRareData_h
33
34 #include "core/dom/shadow/InsertionPoint.h"
35 #include "wtf/RefPtr.h"
36 #include "wtf/Vector.h"
37
38 namespace WebCore {
39
40 class ShadowRootRareData : public NoBaseWillBeGarbageCollectedFinalized<ShadowRootRareData> {
41 public:
42     ShadowRootRareData()
43         : m_descendantShadowElementCount(0)
44         , m_descendantContentElementCount(0)
45         , m_childShadowRootCount(0)
46     {
47     }
48
49     HTMLShadowElement* shadowInsertionPointOfYoungerShadowRoot() const { return m_shadowInsertionPointOfYoungerShadowRoot.get(); }
50     void setShadowInsertionPointOfYoungerShadowRoot(PassRefPtr<HTMLShadowElement> shadowInsertionPoint) { m_shadowInsertionPointOfYoungerShadowRoot = shadowInsertionPoint; }
51
52     void didAddInsertionPoint(InsertionPoint*);
53     void didRemoveInsertionPoint(InsertionPoint*);
54
55     bool containsShadowElements() const { return m_descendantShadowElementCount; }
56     bool containsContentElements() const { return m_descendantContentElementCount; }
57     bool containsShadowRoots() const { return m_childShadowRootCount; }
58
59     unsigned descendantShadowElementCount() const { return m_descendantShadowElementCount; }
60
61     void didAddChildShadowRoot() { ++m_childShadowRootCount; }
62     void didRemoveChildShadowRoot() { ASSERT(m_childShadowRootCount > 0); --m_childShadowRootCount; }
63
64     unsigned childShadowRootCount() const { return m_childShadowRootCount; }
65
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(); }
69
70     StyleSheetList* styleSheets() { return m_styleSheetList.get(); }
71     void setStyleSheets(PassRefPtrWillBeRawPtr<StyleSheetList> styleSheetList) { m_styleSheetList = styleSheetList; }
72
73     void trace(Visitor* visitor) { visitor->trace(m_styleSheetList); }
74
75 private:
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;
82 };
83
84 inline void ShadowRootRareData::didAddInsertionPoint(InsertionPoint* point)
85 {
86     ASSERT(point);
87     if (isHTMLShadowElement(*point))
88         ++m_descendantShadowElementCount;
89     else if (isHTMLContentElement(*point))
90         ++m_descendantContentElementCount;
91     else
92         ASSERT_NOT_REACHED();
93 }
94
95 inline void ShadowRootRareData::didRemoveInsertionPoint(InsertionPoint* point)
96 {
97     ASSERT(point);
98     if (isHTMLShadowElement(*point))
99         --m_descendantShadowElementCount;
100     else if (isHTMLContentElement(*point))
101         --m_descendantContentElementCount;
102     else
103         ASSERT_NOT_REACHED();
104
105     ASSERT(m_descendantContentElementCount >= 0);
106     ASSERT(m_descendantShadowElementCount >= 0);
107 }
108
109 } // namespace WebCore
110
111 #endif