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.
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 "CSSSelectorList.h"
26 #include "MediaList.h"
27 #include <wtf/RefPtr.h>
34 class StylePropertySet;
36 class StyleRuleBase : public WTF::RefCountedBase {
41 Charset, // Not used. These are internally strings owned by the style sheet.
47 Keyframe, // Not used. These are internally non-rule StyleKeyframe objects.
50 Type type() const { return static_cast<Type>(m_type); }
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; }
61 PassRefPtr<StyleRuleBase> copy() const;
63 int sourceLine() const { return m_sourceLine; }
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;
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) { }
84 PassRefPtr<CSSRule> createCSSOMWrapper(CSSStyleSheet* parentSheet, CSSRule* parentRule) const;
87 signed m_sourceLine : 27;
90 class StyleRule : public StyleRuleBase {
92 static PassRefPtr<StyleRule> create(int sourceLine) { return adoptRef(new StyleRule(sourceLine)); }
96 const CSSSelectorList& selectorList() const { return m_selectorList; }
97 const StylePropertySet* properties() const { return m_properties.get(); }
98 StylePropertySet* mutableProperties();
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>);
104 PassRefPtr<StyleRule> copy() const { return adoptRef(new StyleRule(*this)); }
106 static unsigned averageSizeInBytes();
109 StyleRule(int sourceLine);
110 StyleRule(const StyleRule&);
112 RefPtr<StylePropertySet> m_properties;
113 CSSSelectorList m_selectorList;
116 class StyleRuleFontFace : public StyleRuleBase {
118 static PassRefPtr<StyleRuleFontFace> create() { return adoptRef(new StyleRuleFontFace); }
120 ~StyleRuleFontFace();
122 const StylePropertySet* properties() const { return m_properties.get(); }
123 StylePropertySet* mutableProperties();
125 void setProperties(PassRefPtr<StylePropertySet>);
127 PassRefPtr<StyleRuleFontFace> copy() const { return adoptRef(new StyleRuleFontFace(*this)); }
131 StyleRuleFontFace(const StyleRuleFontFace&);
133 RefPtr<StylePropertySet> m_properties;
136 class StyleRulePage : public StyleRuleBase {
138 static PassRefPtr<StyleRulePage> create() { return adoptRef(new StyleRulePage); }
142 const CSSSelector* selector() const { return m_selectorList.first(); }
143 const StylePropertySet* properties() const { return m_properties.get(); }
144 StylePropertySet* mutableProperties();
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>);
150 PassRefPtr<StyleRulePage> copy() const { return adoptRef(new StyleRulePage(*this)); }
154 StyleRulePage(const StyleRulePage&);
156 RefPtr<StylePropertySet> m_properties;
157 CSSSelectorList m_selectorList;
160 class StyleRuleBlock : public StyleRuleBase {
162 const Vector<RefPtr<StyleRuleBase> >& childRules() const { return m_childRules; }
164 void wrapperInsertRule(unsigned, PassRefPtr<StyleRuleBase>);
165 void wrapperRemoveRule(unsigned);
168 StyleRuleBlock(Type, Vector<RefPtr<StyleRuleBase> >& adoptRule);
169 StyleRuleBlock(const StyleRuleBlock&);
172 Vector<RefPtr<StyleRuleBase> > m_childRules;
175 class StyleRuleMedia : public StyleRuleBlock {
177 static PassRefPtr<StyleRuleMedia> create(PassRefPtr<MediaQuerySet> media, Vector<RefPtr<StyleRuleBase> >& adoptRules)
179 return adoptRef(new StyleRuleMedia(media, adoptRules));
182 MediaQuerySet* mediaQueries() const { return m_mediaQueries.get(); }
184 PassRefPtr<StyleRuleMedia> copy() const { return adoptRef(new StyleRuleMedia(*this)); }
187 StyleRuleMedia(PassRefPtr<MediaQuerySet>, Vector<RefPtr<StyleRuleBase> >& adoptRules);
188 StyleRuleMedia(const StyleRuleMedia&);
190 RefPtr<MediaQuerySet> m_mediaQueries;
193 class StyleRuleRegion : public StyleRuleBlock {
195 static PassRefPtr<StyleRuleRegion> create(Vector<OwnPtr<CSSParserSelector> >* selectors, Vector<RefPtr<StyleRuleBase> >& adoptRules)
197 return adoptRef(new StyleRuleRegion(selectors, adoptRules));
200 const CSSSelectorList& selectorList() const { return m_selectorList; }
202 PassRefPtr<StyleRuleRegion> copy() const { return adoptRef(new StyleRuleRegion(*this)); }
205 StyleRuleRegion(Vector<OwnPtr<CSSParserSelector> >*, Vector<RefPtr<StyleRuleBase> >& adoptRules);
206 StyleRuleRegion(const StyleRuleRegion&);
208 CSSSelectorList m_selectorList;
211 } // namespace WebCore
213 #endif // StyleRule_h