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, 2013 Apple Inc. All rights reserved.
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.
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.
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.
25 #include "core/css/CSSSelectorList.h"
26 #include "core/css/MediaList.h"
27 #include "wtf/RefPtr.h"
34 class MutableStylePropertySet;
35 class StylePropertySet;
37 class StyleRuleBase : public WTF::RefCountedBase {
38 WTF_MAKE_FAST_ALLOCATED;
43 Charset, // Not used. These are internally strings owned by the style sheet.
49 Keyframe, // Not used. These are internally non-rule StyleKeyframe objects.
55 Type type() const { return static_cast<Type>(m_type); }
57 bool isCharsetRule() const { return type() == Charset; }
58 bool isFontFaceRule() const { return type() == FontFace; }
59 bool isKeyframesRule() const { return type() == Keyframes; }
60 bool isMediaRule() const { return type() == Media; }
61 bool isPageRule() const { return type() == Page; }
62 bool isStyleRule() const { return type() == Style; }
63 bool isSupportsRule() const { return type() == Supports; }
64 bool isViewportRule() const { return type() == Viewport; }
65 bool isImportRule() const { return type() == Import; }
66 bool isFilterRule() const { return type() == Filter; }
68 PassRefPtr<StyleRuleBase> copy() const;
76 // FIXME: There shouldn't be any need for the null parent version.
77 PassRefPtr<CSSRule> createCSSOMWrapper(CSSStyleSheet* parentSheet = 0) const;
78 PassRefPtr<CSSRule> createCSSOMWrapper(CSSRule* parentRule) const;
81 StyleRuleBase(Type type) : m_type(type) { }
82 StyleRuleBase(const StyleRuleBase& o) : WTF::RefCountedBase(), m_type(o.m_type) { }
89 PassRefPtr<CSSRule> createCSSOMWrapper(CSSStyleSheet* parentSheet, CSSRule* parentRule) const;
94 class StyleRule : public StyleRuleBase {
95 WTF_MAKE_FAST_ALLOCATED;
97 static PassRefPtr<StyleRule> create() { return adoptRef(new StyleRule()); }
101 const CSSSelectorList& selectorList() const { return m_selectorList; }
102 const StylePropertySet* properties() const { return m_properties.get(); }
103 MutableStylePropertySet* mutableProperties();
105 void parserAdoptSelectorVector(Vector<OwnPtr<CSSParserSelector> >& selectors) { m_selectorList.adoptSelectorVector(selectors); }
106 void wrapperAdoptSelectorList(CSSSelectorList& selectors) { m_selectorList.adopt(selectors); }
107 void setProperties(PassRefPtr<StylePropertySet>);
109 PassRefPtr<StyleRule> copy() const { return adoptRef(new StyleRule(*this)); }
111 static unsigned averageSizeInBytes();
115 StyleRule(const StyleRule&);
117 RefPtr<StylePropertySet> m_properties;
118 CSSSelectorList m_selectorList;
121 class StyleRuleFontFace : public StyleRuleBase {
123 static PassRefPtr<StyleRuleFontFace> create() { return adoptRef(new StyleRuleFontFace); }
125 ~StyleRuleFontFace();
127 const StylePropertySet* properties() const { return m_properties.get(); }
128 MutableStylePropertySet* mutableProperties();
130 void setProperties(PassRefPtr<StylePropertySet>);
132 PassRefPtr<StyleRuleFontFace> copy() const { return adoptRef(new StyleRuleFontFace(*this)); }
136 StyleRuleFontFace(const StyleRuleFontFace&);
138 RefPtr<StylePropertySet> m_properties;
141 class StyleRulePage : public StyleRuleBase {
143 static PassRefPtr<StyleRulePage> create() { return adoptRef(new StyleRulePage); }
147 const CSSSelector* selector() const { return m_selectorList.first(); }
148 const StylePropertySet* properties() const { return m_properties.get(); }
149 MutableStylePropertySet* mutableProperties();
151 void parserAdoptSelectorVector(Vector<OwnPtr<CSSParserSelector> >& selectors) { m_selectorList.adoptSelectorVector(selectors); }
152 void wrapperAdoptSelectorList(CSSSelectorList& selectors) { m_selectorList.adopt(selectors); }
153 void setProperties(PassRefPtr<StylePropertySet>);
155 PassRefPtr<StyleRulePage> copy() const { return adoptRef(new StyleRulePage(*this)); }
159 StyleRulePage(const StyleRulePage&);
161 RefPtr<StylePropertySet> m_properties;
162 CSSSelectorList m_selectorList;
165 class StyleRuleGroup : public StyleRuleBase {
167 const Vector<RefPtr<StyleRuleBase> >& childRules() const { return m_childRules; }
169 void wrapperInsertRule(unsigned, PassRefPtr<StyleRuleBase>);
170 void wrapperRemoveRule(unsigned);
173 StyleRuleGroup(Type, Vector<RefPtr<StyleRuleBase> >& adoptRule);
174 StyleRuleGroup(const StyleRuleGroup&);
177 Vector<RefPtr<StyleRuleBase> > m_childRules;
180 class StyleRuleMedia : public StyleRuleGroup {
182 static PassRefPtr<StyleRuleMedia> create(PassRefPtr<MediaQuerySet> media, Vector<RefPtr<StyleRuleBase> >& adoptRules)
184 return adoptRef(new StyleRuleMedia(media, adoptRules));
187 MediaQuerySet* mediaQueries() const { return m_mediaQueries.get(); }
189 PassRefPtr<StyleRuleMedia> copy() const { return adoptRef(new StyleRuleMedia(*this)); }
192 StyleRuleMedia(PassRefPtr<MediaQuerySet>, Vector<RefPtr<StyleRuleBase> >& adoptRules);
193 StyleRuleMedia(const StyleRuleMedia&);
195 RefPtr<MediaQuerySet> m_mediaQueries;
198 class StyleRuleSupports : public StyleRuleGroup {
200 static PassRefPtr<StyleRuleSupports> create(const String& conditionText, bool conditionIsSupported, Vector<RefPtr<StyleRuleBase> >& adoptRules)
202 return adoptRef(new StyleRuleSupports(conditionText, conditionIsSupported, adoptRules));
205 String conditionText() const { return m_conditionText; }
206 bool conditionIsSupported() const { return m_conditionIsSupported; }
207 PassRefPtr<StyleRuleSupports> copy() const { return adoptRef(new StyleRuleSupports(*this)); }
210 StyleRuleSupports(const String& conditionText, bool conditionIsSupported, Vector<RefPtr<StyleRuleBase> >& adoptRules);
211 StyleRuleSupports(const StyleRuleSupports&);
213 String m_conditionText;
214 bool m_conditionIsSupported;
217 class StyleRuleViewport : public StyleRuleBase {
219 static PassRefPtr<StyleRuleViewport> create() { return adoptRef(new StyleRuleViewport); }
221 ~StyleRuleViewport();
223 const StylePropertySet* properties() const { return m_properties.get(); }
224 MutableStylePropertySet* mutableProperties();
226 void setProperties(PassRefPtr<StylePropertySet>);
228 PassRefPtr<StyleRuleViewport> copy() const { return adoptRef(new StyleRuleViewport(*this)); }
232 StyleRuleViewport(const StyleRuleViewport&);
234 RefPtr<StylePropertySet> m_properties;
237 class StyleRuleFilter : public StyleRuleBase {
239 static PassRefPtr<StyleRuleFilter> create(const String& filterName) { return adoptRef(new StyleRuleFilter(filterName)); }
243 const String& filterName() const { return m_filterName; }
245 const StylePropertySet* properties() const { return m_properties.get(); }
246 MutableStylePropertySet* mutableProperties();
248 void setProperties(PassRefPtr<StylePropertySet>);
250 PassRefPtr<StyleRuleFilter> copy() const { return adoptRef(new StyleRuleFilter(*this)); }
253 StyleRuleFilter(const String&);
254 StyleRuleFilter(const StyleRuleFilter&);
257 RefPtr<StylePropertySet> m_properties;
260 #define DEFINE_STYLE_RULE_TYPE_CASTS(Type) \
261 DEFINE_TYPE_CASTS(StyleRule##Type, StyleRuleBase, rule, rule->is##Type##Rule(), rule.is##Type##Rule())
263 DEFINE_TYPE_CASTS(StyleRule, StyleRuleBase, rule, rule->isStyleRule(), rule.isStyleRule());
264 DEFINE_STYLE_RULE_TYPE_CASTS(FontFace);
265 DEFINE_STYLE_RULE_TYPE_CASTS(Page);
266 DEFINE_STYLE_RULE_TYPE_CASTS(Media);
267 DEFINE_STYLE_RULE_TYPE_CASTS(Supports);
268 DEFINE_STYLE_RULE_TYPE_CASTS(Viewport);
269 DEFINE_STYLE_RULE_TYPE_CASTS(Filter);
271 } // namespace WebCore
273 #endif // StyleRule_h