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 "platform/heap/Handle.h"
28 #include "wtf/RefPtr.h"
35 class MutableStylePropertySet;
36 class StylePropertySet;
38 class StyleRuleBase : public RefCountedWillBeGarbageCollectedFinalized<StyleRuleBase> {
39 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
44 Charset, // Not used. These are internally strings owned by the style sheet.
50 Keyframe, // Not used. These are internally non-rule StyleKeyframe objects.
56 Type type() const { return static_cast<Type>(m_type); }
58 bool isCharsetRule() const { return type() == Charset; }
59 bool isFontFaceRule() const { return type() == FontFace; }
60 bool isKeyframesRule() const { return type() == Keyframes; }
61 bool isMediaRule() const { return type() == Media; }
62 bool isPageRule() const { return type() == Page; }
63 bool isStyleRule() const { return type() == Style; }
64 bool isSupportsRule() const { return type() == Supports; }
65 bool isViewportRule() const { return type() == Viewport; }
66 bool isImportRule() const { return type() == Import; }
67 bool isFilterRule() const { return type() == Filter; }
69 PassRefPtrWillBeRawPtr<StyleRuleBase> copy() const;
77 #endif // !ENABLE(OILPAN)
79 // FIXME: There shouldn't be any need for the null parent version.
80 PassRefPtrWillBeRawPtr<CSSRule> createCSSOMWrapper(CSSStyleSheet* parentSheet = 0) const;
81 PassRefPtrWillBeRawPtr<CSSRule> createCSSOMWrapper(CSSRule* parentRule) const;
84 void traceAfterDispatch(Visitor*) { };
85 void finalizeGarbageCollectedObject();
88 StyleRuleBase(Type type) : m_type(type) { }
89 StyleRuleBase(const StyleRuleBase& o) : m_type(o.m_type) { }
96 PassRefPtrWillBeRawPtr<CSSRule> createCSSOMWrapper(CSSStyleSheet* parentSheet, CSSRule* parentRule) const;
101 class StyleRule : public StyleRuleBase {
102 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
104 static PassRefPtrWillBeRawPtr<StyleRule> create() { return adoptRefWillBeNoop(new StyleRule()); }
108 const CSSSelectorList& selectorList() const { return m_selectorList; }
109 const StylePropertySet& properties() const { return *m_properties; }
110 MutableStylePropertySet& mutableProperties();
112 void parserAdoptSelectorVector(Vector<OwnPtr<CSSParserSelector> >& selectors) { m_selectorList.adoptSelectorVector(selectors); }
113 void wrapperAdoptSelectorList(CSSSelectorList& selectors) { m_selectorList.adopt(selectors); }
114 void setProperties(PassRefPtrWillBeRawPtr<StylePropertySet>);
116 PassRefPtrWillBeRawPtr<StyleRule> copy() const { return adoptRefWillBeNoop(new StyleRule(*this)); }
118 static unsigned averageSizeInBytes();
120 void traceAfterDispatch(Visitor*);
124 StyleRule(const StyleRule&);
126 RefPtrWillBeMember<StylePropertySet> m_properties; // Cannot be null.
127 CSSSelectorList m_selectorList;
130 class StyleRuleFontFace : public StyleRuleBase {
132 static PassRefPtrWillBeRawPtr<StyleRuleFontFace> create() { return adoptRefWillBeNoop(new StyleRuleFontFace); }
134 ~StyleRuleFontFace();
136 const StylePropertySet& properties() const { return *m_properties; }
137 MutableStylePropertySet& mutableProperties();
139 void setProperties(PassRefPtrWillBeRawPtr<StylePropertySet>);
141 PassRefPtrWillBeRawPtr<StyleRuleFontFace> copy() const { return adoptRefWillBeNoop(new StyleRuleFontFace(*this)); }
143 void traceAfterDispatch(Visitor*);
147 StyleRuleFontFace(const StyleRuleFontFace&);
149 RefPtrWillBeMember<StylePropertySet> m_properties; // Cannot be null.
152 class StyleRulePage : public StyleRuleBase {
154 static PassRefPtrWillBeRawPtr<StyleRulePage> create() { return adoptRefWillBeNoop(new StyleRulePage); }
158 const CSSSelector* selector() const { return m_selectorList.first(); }
159 const StylePropertySet& properties() const { return *m_properties; }
160 MutableStylePropertySet& mutableProperties();
162 void parserAdoptSelectorVector(Vector<OwnPtr<CSSParserSelector> >& selectors) { m_selectorList.adoptSelectorVector(selectors); }
163 void wrapperAdoptSelectorList(CSSSelectorList& selectors) { m_selectorList.adopt(selectors); }
164 void setProperties(PassRefPtrWillBeRawPtr<StylePropertySet>);
166 PassRefPtrWillBeRawPtr<StyleRulePage> copy() const { return adoptRefWillBeNoop(new StyleRulePage(*this)); }
168 void traceAfterDispatch(Visitor*);
172 StyleRulePage(const StyleRulePage&);
174 RefPtrWillBeMember<StylePropertySet> m_properties; // Cannot be null.
175 CSSSelectorList m_selectorList;
178 class StyleRuleGroup : public StyleRuleBase {
180 const WillBeHeapVector<RefPtrWillBeMember<StyleRuleBase> >& childRules() const { return m_childRules; }
182 void wrapperInsertRule(unsigned, PassRefPtrWillBeRawPtr<StyleRuleBase>);
183 void wrapperRemoveRule(unsigned);
185 void traceAfterDispatch(Visitor*);
188 StyleRuleGroup(Type, WillBeHeapVector<RefPtrWillBeMember<StyleRuleBase> >& adoptRule);
189 StyleRuleGroup(const StyleRuleGroup&);
192 WillBeHeapVector<RefPtrWillBeMember<StyleRuleBase> > m_childRules;
195 class StyleRuleMedia : public StyleRuleGroup {
197 static PassRefPtrWillBeRawPtr<StyleRuleMedia> create(PassRefPtrWillBeRawPtr<MediaQuerySet> media, WillBeHeapVector<RefPtrWillBeMember<StyleRuleBase> >& adoptRules)
199 return adoptRefWillBeNoop(new StyleRuleMedia(media, adoptRules));
202 MediaQuerySet* mediaQueries() const { return m_mediaQueries.get(); }
204 PassRefPtrWillBeRawPtr<StyleRuleMedia> copy() const { return adoptRefWillBeNoop(new StyleRuleMedia(*this)); }
206 void traceAfterDispatch(Visitor*);
209 StyleRuleMedia(PassRefPtrWillBeRawPtr<MediaQuerySet>, WillBeHeapVector<RefPtrWillBeMember<StyleRuleBase> >& adoptRules);
210 StyleRuleMedia(const StyleRuleMedia&);
212 RefPtrWillBeMember<MediaQuerySet> m_mediaQueries;
215 class StyleRuleSupports : public StyleRuleGroup {
217 static PassRefPtrWillBeRawPtr<StyleRuleSupports> create(const String& conditionText, bool conditionIsSupported, WillBeHeapVector<RefPtrWillBeMember<StyleRuleBase> >& adoptRules)
219 return adoptRefWillBeNoop(new StyleRuleSupports(conditionText, conditionIsSupported, adoptRules));
222 String conditionText() const { return m_conditionText; }
223 bool conditionIsSupported() const { return m_conditionIsSupported; }
224 PassRefPtrWillBeRawPtr<StyleRuleSupports> copy() const { return adoptRefWillBeNoop(new StyleRuleSupports(*this)); }
226 void traceAfterDispatch(Visitor* visitor) { StyleRuleGroup::traceAfterDispatch(visitor); }
229 StyleRuleSupports(const String& conditionText, bool conditionIsSupported, WillBeHeapVector<RefPtrWillBeMember<StyleRuleBase> >& adoptRules);
230 StyleRuleSupports(const StyleRuleSupports&);
232 String m_conditionText;
233 bool m_conditionIsSupported;
236 class StyleRuleViewport : public StyleRuleBase {
238 static PassRefPtrWillBeRawPtr<StyleRuleViewport> create() { return adoptRefWillBeNoop(new StyleRuleViewport); }
240 ~StyleRuleViewport();
242 const StylePropertySet& properties() const { return *m_properties; }
243 MutableStylePropertySet& mutableProperties();
245 void setProperties(PassRefPtrWillBeRawPtr<StylePropertySet>);
247 PassRefPtrWillBeRawPtr<StyleRuleViewport> copy() const { return adoptRefWillBeNoop(new StyleRuleViewport(*this)); }
249 void traceAfterDispatch(Visitor*);
253 StyleRuleViewport(const StyleRuleViewport&);
255 RefPtrWillBeMember<StylePropertySet> m_properties; // Cannot be null
258 class StyleRuleFilter : public StyleRuleBase {
260 static PassRefPtrWillBeRawPtr<StyleRuleFilter> create(const String& filterName) { return adoptRefWillBeNoop(new StyleRuleFilter(filterName)); }
264 const String& filterName() const { return m_filterName; }
266 const StylePropertySet& properties() const { return *m_properties; }
267 MutableStylePropertySet& mutableProperties();
269 void setProperties(PassRefPtrWillBeRawPtr<StylePropertySet>);
271 PassRefPtrWillBeRawPtr<StyleRuleFilter> copy() const { return adoptRefWillBeNoop(new StyleRuleFilter(*this)); }
273 void traceAfterDispatch(Visitor*);
276 StyleRuleFilter(const String&);
277 StyleRuleFilter(const StyleRuleFilter&);
280 RefPtrWillBeMember<StylePropertySet> m_properties;
283 #define DEFINE_STYLE_RULE_TYPE_CASTS(Type) \
284 DEFINE_TYPE_CASTS(StyleRule##Type, StyleRuleBase, rule, rule->is##Type##Rule(), rule.is##Type##Rule())
286 DEFINE_TYPE_CASTS(StyleRule, StyleRuleBase, rule, rule->isStyleRule(), rule.isStyleRule());
287 DEFINE_STYLE_RULE_TYPE_CASTS(FontFace);
288 DEFINE_STYLE_RULE_TYPE_CASTS(Page);
289 DEFINE_STYLE_RULE_TYPE_CASTS(Media);
290 DEFINE_STYLE_RULE_TYPE_CASTS(Supports);
291 DEFINE_STYLE_RULE_TYPE_CASTS(Viewport);
292 DEFINE_STYLE_RULE_TYPE_CASTS(Filter);
296 #endif // StyleRule_h