Merge "[CherryPick] [WEBGL] Rename WEBKIT_WEBGL_lose_context to WEBGL_lose_context...
[framework/web/webkit-efl.git] / Source / WebCore / css / StyleRule.h
1 /*
2  * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3  * (C) 2002-2003 Dirk Mueller (mueller@kde.org)
4  * Copyright (C) 2002, 2006, 2008, 2012 Apple Inc. All rights reserved.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB.  If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21
22 #ifndef StyleRule_h
23 #define StyleRule_h
24
25 #include "CSSSelectorList.h"
26 #include "MediaList.h"
27 #include <wtf/RefPtr.h>
28
29 namespace WebCore {
30
31 class CSSRule;
32 class CSSStyleRule;
33 class CSSStyleSheet;
34 class StylePropertySet;
35
36 class StyleRuleBase : public WTF::RefCountedBase {
37 public:
38     enum Type {
39         Unknown, // Not used.
40         Style,
41         Charset, // Not used. These are internally strings owned by the style sheet.
42         Import,
43         Media,
44         FontFace,
45         Page,
46         Keyframes,
47         Keyframe, // Not used. These are internally non-rule StyleKeyframe objects.
48         Region = 16
49     };
50     Type type() const { return static_cast<Type>(m_type); }
51     
52     bool isCharsetRule() const { return type() == Charset; }
53     bool isFontFaceRule() const { return type() == FontFace; }
54     bool isKeyframesRule() const { return type() == Keyframes; }
55     bool isMediaRule() const { return type() == Media; }
56     bool isPageRule() const { return type() == Page; }
57     bool isStyleRule() const { return type() == Style; }
58     bool isRegionRule() const { return type() == Region; }
59     bool isImportRule() const { return type() == Import; }
60
61     PassRefPtr<StyleRuleBase> copy() const;
62
63     int sourceLine() const { return m_sourceLine; }
64
65     void deref()
66     {
67         if (derefBase())
68             destroy();
69     }
70
71     // FIXME: There shouldn't be any need for the null parent version.
72     PassRefPtr<CSSRule> createCSSOMWrapper(CSSStyleSheet* parentSheet = 0) const;
73     PassRefPtr<CSSRule> createCSSOMWrapper(CSSRule* parentRule) const;
74
75 protected:
76     StyleRuleBase(Type type, signed sourceLine = 0) : m_type(type), m_sourceLine(sourceLine) { }
77     StyleRuleBase(const StyleRuleBase& o) : WTF::RefCountedBase(), m_type(o.m_type), m_sourceLine(o.m_sourceLine) { }
78
79     ~StyleRuleBase() { }
80
81 private:
82     void destroy();
83     
84     PassRefPtr<CSSRule> createCSSOMWrapper(CSSStyleSheet* parentSheet, CSSRule* parentRule) const;
85
86     unsigned m_type : 5;
87     signed m_sourceLine : 27;
88 };
89
90 class StyleRule : public StyleRuleBase {
91 public:
92     static PassRefPtr<StyleRule> create(int sourceLine) { return adoptRef(new StyleRule(sourceLine)); }
93     
94     ~StyleRule();
95
96     const CSSSelectorList& selectorList() const { return m_selectorList; }
97     const StylePropertySet* properties() const { return m_properties.get(); }
98     StylePropertySet* mutableProperties();
99     
100     void parserAdoptSelectorVector(Vector<OwnPtr<CSSParserSelector> >& selectors) { m_selectorList.adoptSelectorVector(selectors); }
101     void wrapperAdoptSelectorList(CSSSelectorList& selectors) { m_selectorList.adopt(selectors); }
102     void setProperties(PassRefPtr<StylePropertySet>);
103
104     PassRefPtr<StyleRule> copy() const { return adoptRef(new StyleRule(*this)); }
105
106     static unsigned averageSizeInBytes();
107
108 private:
109     StyleRule(int sourceLine);
110     StyleRule(const StyleRule&);
111
112     RefPtr<StylePropertySet> m_properties;
113     CSSSelectorList m_selectorList;
114 };
115
116 class StyleRuleFontFace : public StyleRuleBase {
117 public:
118     static PassRefPtr<StyleRuleFontFace> create() { return adoptRef(new StyleRuleFontFace); }
119     
120     ~StyleRuleFontFace();
121
122     const StylePropertySet* properties() const { return m_properties.get(); }
123     StylePropertySet* mutableProperties();
124
125     void setProperties(PassRefPtr<StylePropertySet>);
126
127     PassRefPtr<StyleRuleFontFace> copy() const { return adoptRef(new StyleRuleFontFace(*this)); }
128
129 private:
130     StyleRuleFontFace();
131     StyleRuleFontFace(const StyleRuleFontFace&);
132
133     RefPtr<StylePropertySet> m_properties;
134 };
135
136 class StyleRulePage : public StyleRuleBase {
137 public:
138     static PassRefPtr<StyleRulePage> create() { return adoptRef(new StyleRulePage); }
139
140     ~StyleRulePage();
141
142     const CSSSelector* selector() const { return m_selectorList.first(); }    
143     const StylePropertySet* properties() const { return m_properties.get(); }
144     StylePropertySet* mutableProperties();
145
146     void parserAdoptSelectorVector(Vector<OwnPtr<CSSParserSelector> >& selectors) { m_selectorList.adoptSelectorVector(selectors); }
147     void wrapperAdoptSelectorList(CSSSelectorList& selectors) { m_selectorList.adopt(selectors); }
148     void setProperties(PassRefPtr<StylePropertySet>);
149
150     PassRefPtr<StyleRulePage> copy() const { return adoptRef(new StyleRulePage(*this)); }
151
152 private:
153     StyleRulePage();
154     StyleRulePage(const StyleRulePage&);
155     
156     RefPtr<StylePropertySet> m_properties;
157     CSSSelectorList m_selectorList;
158 };
159
160 class StyleRuleBlock : public StyleRuleBase {
161 public:
162     const Vector<RefPtr<StyleRuleBase> >& childRules() const { return m_childRules; }
163     
164     void wrapperInsertRule(unsigned, PassRefPtr<StyleRuleBase>);
165     void wrapperRemoveRule(unsigned);
166     
167 protected:
168     StyleRuleBlock(Type, Vector<RefPtr<StyleRuleBase> >& adoptRule);
169     StyleRuleBlock(const StyleRuleBlock&);
170     
171 private:
172     Vector<RefPtr<StyleRuleBase> > m_childRules;
173 };
174
175 class StyleRuleMedia : public StyleRuleBlock {
176 public:
177     static PassRefPtr<StyleRuleMedia> create(PassRefPtr<MediaQuerySet> media, Vector<RefPtr<StyleRuleBase> >& adoptRules)
178     {
179         return adoptRef(new StyleRuleMedia(media, adoptRules));
180     }
181
182     MediaQuerySet* mediaQueries() const { return m_mediaQueries.get(); }
183
184     PassRefPtr<StyleRuleMedia> copy() const { return adoptRef(new StyleRuleMedia(*this)); }
185
186 private:
187     StyleRuleMedia(PassRefPtr<MediaQuerySet>, Vector<RefPtr<StyleRuleBase> >& adoptRules);
188     StyleRuleMedia(const StyleRuleMedia&);
189
190     RefPtr<MediaQuerySet> m_mediaQueries;
191 };
192
193 class StyleRuleRegion : public StyleRuleBlock {
194 public:
195     static PassRefPtr<StyleRuleRegion> create(Vector<OwnPtr<CSSParserSelector> >* selectors, Vector<RefPtr<StyleRuleBase> >& adoptRules)
196     {
197         return adoptRef(new StyleRuleRegion(selectors, adoptRules));
198     }
199
200     const CSSSelectorList& selectorList() const { return m_selectorList; }
201
202     PassRefPtr<StyleRuleRegion> copy() const { return adoptRef(new StyleRuleRegion(*this)); }
203
204 private:
205     StyleRuleRegion(Vector<OwnPtr<CSSParserSelector> >*, Vector<RefPtr<StyleRuleBase> >& adoptRules);
206     StyleRuleRegion(const StyleRuleRegion&);
207     
208     CSSSelectorList m_selectorList;
209 };
210
211 } // namespace WebCore
212
213 #endif // StyleRule_h