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/CoreExport.h"
26 #include "core/css/CSSSelectorList.h"
27 #include "core/css/MediaList.h"
28 #include "core/css/StylePropertySet.h"
29 #include "platform/heap/Handle.h"
30 #include "wtf/RefPtr.h"
37 class CORE_EXPORT StyleRuleBase
: public RefCountedWillBeGarbageCollectedFinalized
<StyleRuleBase
> {
38 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED(StyleRuleBase
);
54 Type
type() const { return static_cast<Type
>(m_type
); }
56 bool isCharsetRule() const { return type() == Charset
; }
57 bool isFontFaceRule() const { return type() == FontFace
; }
58 bool isKeyframesRule() const { return type() == Keyframes
; }
59 bool isKeyframeRule() const { return type() == Keyframe
; }
60 bool isNamespaceRule() const { return type() == Namespace
; }
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
; }
68 PassRefPtrWillBeRawPtr
<StyleRuleBase
> copy() const;
76 #endif // !ENABLE(OILPAN)
78 // FIXME: There shouldn't be any need for the null parent version.
79 PassRefPtrWillBeRawPtr
<CSSRule
> createCSSOMWrapper(CSSStyleSheet
* parentSheet
= 0) const;
80 PassRefPtrWillBeRawPtr
<CSSRule
> createCSSOMWrapper(CSSRule
* parentRule
) const;
83 DEFINE_INLINE_TRACE_AFTER_DISPATCH() { }
84 void finalizeGarbageCollectedObject();
86 // ~StyleRuleBase should be public, because non-public ~StyleRuleBase
87 // causes C2248 error : 'blink::StyleRuleBase::~StyleRuleBase' : cannot
88 // access protected member declared in class 'blink::StyleRuleBase' when
89 // compiling 'source\wtf\refcounted.h' by using msvc.
93 StyleRuleBase(Type type
) : m_type(type
) { }
94 StyleRuleBase(const StyleRuleBase
& o
) : m_type(o
.m_type
) { }
99 PassRefPtrWillBeRawPtr
<CSSRule
> createCSSOMWrapper(CSSStyleSheet
* parentSheet
, CSSRule
* parentRule
) const;
104 class StyleRule
: public StyleRuleBase
{
105 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED(StyleRule
);
107 // Adopts the selector list
108 static PassRefPtrWillBeRawPtr
<StyleRule
> create(CSSSelectorList
& selectorList
, PassRefPtrWillBeRawPtr
<StylePropertySet
> properties
)
110 return adoptRefWillBeNoop(new StyleRule(selectorList
, properties
));
115 const CSSSelectorList
& selectorList() const { return m_selectorList
; }
116 const StylePropertySet
& properties() const { return *m_properties
; }
117 MutableStylePropertySet
& mutableProperties();
119 void wrapperAdoptSelectorList(CSSSelectorList
& selectors
) { m_selectorList
.adopt(selectors
); }
121 PassRefPtrWillBeRawPtr
<StyleRule
> copy() const { return adoptRefWillBeNoop(new StyleRule(*this)); }
123 static unsigned averageSizeInBytes();
125 DECLARE_TRACE_AFTER_DISPATCH();
128 StyleRule(CSSSelectorList
&, PassRefPtrWillBeRawPtr
<StylePropertySet
>);
129 StyleRule(const StyleRule
&);
131 RefPtrWillBeMember
<StylePropertySet
> m_properties
; // Cannot be null.
132 CSSSelectorList m_selectorList
;
135 class StyleRuleFontFace
: public StyleRuleBase
{
137 static PassRefPtrWillBeRawPtr
<StyleRuleFontFace
> create(PassRefPtrWillBeRawPtr
<StylePropertySet
> properties
)
139 return adoptRefWillBeNoop(new StyleRuleFontFace(properties
));
142 ~StyleRuleFontFace();
144 const StylePropertySet
& properties() const { return *m_properties
; }
145 MutableStylePropertySet
& mutableProperties();
147 PassRefPtrWillBeRawPtr
<StyleRuleFontFace
> copy() const { return adoptRefWillBeNoop(new StyleRuleFontFace(*this)); }
149 DECLARE_TRACE_AFTER_DISPATCH();
152 StyleRuleFontFace(PassRefPtrWillBeRawPtr
<StylePropertySet
>);
153 StyleRuleFontFace(const StyleRuleFontFace
&);
155 RefPtrWillBeMember
<StylePropertySet
> m_properties
; // Cannot be null.
158 class StyleRulePage
: public StyleRuleBase
{
160 // Adopts the selector list
161 static PassRefPtrWillBeRawPtr
<StyleRulePage
> create(CSSSelectorList
& selectorList
, PassRefPtrWillBeRawPtr
<StylePropertySet
> properties
)
163 return adoptRefWillBeNoop(new StyleRulePage(selectorList
, properties
));
168 const CSSSelector
* selector() const { return m_selectorList
.first(); }
169 const StylePropertySet
& properties() const { return *m_properties
; }
170 MutableStylePropertySet
& mutableProperties();
172 void wrapperAdoptSelectorList(CSSSelectorList
& selectors
) { m_selectorList
.adopt(selectors
); }
174 PassRefPtrWillBeRawPtr
<StyleRulePage
> copy() const { return adoptRefWillBeNoop(new StyleRulePage(*this)); }
176 DECLARE_TRACE_AFTER_DISPATCH();
179 StyleRulePage(CSSSelectorList
&, PassRefPtrWillBeRawPtr
<StylePropertySet
>);
180 StyleRulePage(const StyleRulePage
&);
182 RefPtrWillBeMember
<StylePropertySet
> m_properties
; // Cannot be null.
183 CSSSelectorList m_selectorList
;
186 class StyleRuleGroup
: public StyleRuleBase
{
188 const WillBeHeapVector
<RefPtrWillBeMember
<StyleRuleBase
>>& childRules() const { return m_childRules
; }
190 void wrapperInsertRule(unsigned, PassRefPtrWillBeRawPtr
<StyleRuleBase
>);
191 void wrapperRemoveRule(unsigned);
193 DECLARE_TRACE_AFTER_DISPATCH();
196 StyleRuleGroup(Type
, WillBeHeapVector
<RefPtrWillBeMember
<StyleRuleBase
>>& adoptRule
);
197 StyleRuleGroup(const StyleRuleGroup
&);
200 WillBeHeapVector
<RefPtrWillBeMember
<StyleRuleBase
>> m_childRules
;
203 class StyleRuleMedia
: public StyleRuleGroup
{
205 static PassRefPtrWillBeRawPtr
<StyleRuleMedia
> create(PassRefPtrWillBeRawPtr
<MediaQuerySet
> media
, WillBeHeapVector
<RefPtrWillBeMember
<StyleRuleBase
>>& adoptRules
)
207 return adoptRefWillBeNoop(new StyleRuleMedia(media
, adoptRules
));
210 MediaQuerySet
* mediaQueries() const { return m_mediaQueries
.get(); }
212 PassRefPtrWillBeRawPtr
<StyleRuleMedia
> copy() const { return adoptRefWillBeNoop(new StyleRuleMedia(*this)); }
214 DECLARE_TRACE_AFTER_DISPATCH();
217 StyleRuleMedia(PassRefPtrWillBeRawPtr
<MediaQuerySet
>, WillBeHeapVector
<RefPtrWillBeMember
<StyleRuleBase
>>& adoptRules
);
218 StyleRuleMedia(const StyleRuleMedia
&);
220 RefPtrWillBeMember
<MediaQuerySet
> m_mediaQueries
;
223 class StyleRuleSupports
: public StyleRuleGroup
{
225 static PassRefPtrWillBeRawPtr
<StyleRuleSupports
> create(const String
& conditionText
, bool conditionIsSupported
, WillBeHeapVector
<RefPtrWillBeMember
<StyleRuleBase
>>& adoptRules
)
227 return adoptRefWillBeNoop(new StyleRuleSupports(conditionText
, conditionIsSupported
, adoptRules
));
230 String
conditionText() const { return m_conditionText
; }
231 bool conditionIsSupported() const { return m_conditionIsSupported
; }
232 PassRefPtrWillBeRawPtr
<StyleRuleSupports
> copy() const { return adoptRefWillBeNoop(new StyleRuleSupports(*this)); }
234 DEFINE_INLINE_TRACE_AFTER_DISPATCH() { StyleRuleGroup::traceAfterDispatch(visitor
); }
237 StyleRuleSupports(const String
& conditionText
, bool conditionIsSupported
, WillBeHeapVector
<RefPtrWillBeMember
<StyleRuleBase
>>& adoptRules
);
238 StyleRuleSupports(const StyleRuleSupports
&);
240 String m_conditionText
;
241 bool m_conditionIsSupported
;
244 class StyleRuleViewport
: public StyleRuleBase
{
246 static PassRefPtrWillBeRawPtr
<StyleRuleViewport
> create(PassRefPtrWillBeRawPtr
<StylePropertySet
> properties
)
248 return adoptRefWillBeNoop(new StyleRuleViewport(properties
));
251 ~StyleRuleViewport();
253 const StylePropertySet
& properties() const { return *m_properties
; }
254 MutableStylePropertySet
& mutableProperties();
256 PassRefPtrWillBeRawPtr
<StyleRuleViewport
> copy() const { return adoptRefWillBeNoop(new StyleRuleViewport(*this)); }
258 DECLARE_TRACE_AFTER_DISPATCH();
261 StyleRuleViewport(PassRefPtrWillBeRawPtr
<StylePropertySet
>);
262 StyleRuleViewport(const StyleRuleViewport
&);
264 RefPtrWillBeMember
<StylePropertySet
> m_properties
; // Cannot be null
267 // This should only be used within the CSS Parser
268 class StyleRuleCharset
: public StyleRuleBase
{
269 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED(StyleRuleCharset
);
271 static PassRefPtrWillBeRawPtr
<StyleRuleCharset
> create() { return adoptRefWillBeNoop(new StyleRuleCharset()); }
272 DEFINE_INLINE_TRACE_AFTER_DISPATCH() { StyleRuleBase::traceAfterDispatch(visitor
); }
275 StyleRuleCharset() : StyleRuleBase(Charset
) { }
279 #define DEFINE_STYLE_RULE_TYPE_CASTS(Type) \
280 DEFINE_TYPE_CASTS(StyleRule##Type, StyleRuleBase, rule, rule->is##Type##Rule(), rule.is##Type##Rule())
282 DEFINE_TYPE_CASTS(StyleRule
, StyleRuleBase
, rule
, rule
->isStyleRule(), rule
.isStyleRule());
283 DEFINE_STYLE_RULE_TYPE_CASTS(FontFace
);
284 DEFINE_STYLE_RULE_TYPE_CASTS(Page
);
285 DEFINE_STYLE_RULE_TYPE_CASTS(Media
);
286 DEFINE_STYLE_RULE_TYPE_CASTS(Supports
);
287 DEFINE_STYLE_RULE_TYPE_CASTS(Viewport
);
288 DEFINE_STYLE_RULE_TYPE_CASTS(Charset
);
292 #endif // StyleRule_h