1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
|
/*
* (C) 1999-2003 Lars Knoll (knoll@kde.org)
* (C) 2002-2003 Dirk Mueller (mueller@kde.org)
* Copyright (C) 2002, 2006, 2008, 2012, 2013 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef StyleRule_h
#define StyleRule_h
#include "core/css/CSSSelectorList.h"
#include "core/css/MediaList.h"
#include "platform/heap/Handle.h"
#include "wtf/RefPtr.h"
namespace blink {
class CSSRule;
class CSSStyleSheet;
class MutableStylePropertySet;
class StylePropertySet;
class StyleRuleBase : public RefCountedWillBeGarbageCollectedFinalized<StyleRuleBase> {
WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
public:
enum Type {
Unknown, // Not used.
Style,
Charset, // Not used. These are internally strings owned by the style sheet.
Import,
Media,
FontFace,
Page,
Keyframes,
Keyframe,
Supports = 12,
Viewport = 15,
Filter = 17
};
Type type() const { return static_cast<Type>(m_type); }
bool isFontFaceRule() const { return type() == FontFace; }
bool isKeyframesRule() const { return type() == Keyframes; }
bool isKeyframeRule() const { return type() == Keyframe; }
bool isMediaRule() const { return type() == Media; }
bool isPageRule() const { return type() == Page; }
bool isStyleRule() const { return type() == Style; }
bool isSupportsRule() const { return type() == Supports; }
bool isViewportRule() const { return type() == Viewport; }
bool isImportRule() const { return type() == Import; }
bool isFilterRule() const { return type() == Filter; }
PassRefPtrWillBeRawPtr<StyleRuleBase> copy() const;
#if !ENABLE(OILPAN)
void deref()
{
if (derefBase())
destroy();
}
#endif // !ENABLE(OILPAN)
// FIXME: There shouldn't be any need for the null parent version.
PassRefPtrWillBeRawPtr<CSSRule> createCSSOMWrapper(CSSStyleSheet* parentSheet = 0) const;
PassRefPtrWillBeRawPtr<CSSRule> createCSSOMWrapper(CSSRule* parentRule) const;
void trace(Visitor*);
void traceAfterDispatch(Visitor*) { };
void finalizeGarbageCollectedObject();
protected:
StyleRuleBase(Type type) : m_type(type) { }
StyleRuleBase(const StyleRuleBase& o) : m_type(o.m_type) { }
~StyleRuleBase() { }
private:
void destroy();
PassRefPtrWillBeRawPtr<CSSRule> createCSSOMWrapper(CSSStyleSheet* parentSheet, CSSRule* parentRule) const;
unsigned m_type : 5;
};
class StyleRule : public StyleRuleBase {
WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
public:
static PassRefPtrWillBeRawPtr<StyleRule> create() { return adoptRefWillBeNoop(new StyleRule()); }
~StyleRule();
const CSSSelectorList& selectorList() const { return m_selectorList; }
const StylePropertySet& properties() const { return *m_properties; }
MutableStylePropertySet& mutableProperties();
void parserAdoptSelectorVector(Vector<OwnPtr<CSSParserSelector> >& selectors) { m_selectorList.adoptSelectorVector(selectors); }
void wrapperAdoptSelectorList(CSSSelectorList& selectors) { m_selectorList.adopt(selectors); }
void setProperties(PassRefPtrWillBeRawPtr<StylePropertySet>);
PassRefPtrWillBeRawPtr<StyleRule> copy() const { return adoptRefWillBeNoop(new StyleRule(*this)); }
static unsigned averageSizeInBytes();
void traceAfterDispatch(Visitor*);
private:
StyleRule();
StyleRule(const StyleRule&);
RefPtrWillBeMember<StylePropertySet> m_properties; // Cannot be null.
CSSSelectorList m_selectorList;
};
class StyleRuleFontFace : public StyleRuleBase {
public:
static PassRefPtrWillBeRawPtr<StyleRuleFontFace> create() { return adoptRefWillBeNoop(new StyleRuleFontFace); }
~StyleRuleFontFace();
const StylePropertySet& properties() const { return *m_properties; }
MutableStylePropertySet& mutableProperties();
void setProperties(PassRefPtrWillBeRawPtr<StylePropertySet>);
PassRefPtrWillBeRawPtr<StyleRuleFontFace> copy() const { return adoptRefWillBeNoop(new StyleRuleFontFace(*this)); }
void traceAfterDispatch(Visitor*);
private:
StyleRuleFontFace();
StyleRuleFontFace(const StyleRuleFontFace&);
RefPtrWillBeMember<StylePropertySet> m_properties; // Cannot be null.
};
class StyleRulePage : public StyleRuleBase {
public:
static PassRefPtrWillBeRawPtr<StyleRulePage> create() { return adoptRefWillBeNoop(new StyleRulePage); }
~StyleRulePage();
const CSSSelector* selector() const { return m_selectorList.first(); }
const StylePropertySet& properties() const { return *m_properties; }
MutableStylePropertySet& mutableProperties();
void parserAdoptSelectorVector(Vector<OwnPtr<CSSParserSelector> >& selectors) { m_selectorList.adoptSelectorVector(selectors); }
void wrapperAdoptSelectorList(CSSSelectorList& selectors) { m_selectorList.adopt(selectors); }
void setProperties(PassRefPtrWillBeRawPtr<StylePropertySet>);
PassRefPtrWillBeRawPtr<StyleRulePage> copy() const { return adoptRefWillBeNoop(new StyleRulePage(*this)); }
void traceAfterDispatch(Visitor*);
private:
StyleRulePage();
StyleRulePage(const StyleRulePage&);
RefPtrWillBeMember<StylePropertySet> m_properties; // Cannot be null.
CSSSelectorList m_selectorList;
};
class StyleRuleGroup : public StyleRuleBase {
public:
const WillBeHeapVector<RefPtrWillBeMember<StyleRuleBase> >& childRules() const { return m_childRules; }
void wrapperInsertRule(unsigned, PassRefPtrWillBeRawPtr<StyleRuleBase>);
void wrapperRemoveRule(unsigned);
void traceAfterDispatch(Visitor*);
protected:
StyleRuleGroup(Type, WillBeHeapVector<RefPtrWillBeMember<StyleRuleBase> >& adoptRule);
StyleRuleGroup(const StyleRuleGroup&);
private:
WillBeHeapVector<RefPtrWillBeMember<StyleRuleBase> > m_childRules;
};
class StyleRuleMedia : public StyleRuleGroup {
public:
static PassRefPtrWillBeRawPtr<StyleRuleMedia> create(PassRefPtrWillBeRawPtr<MediaQuerySet> media, WillBeHeapVector<RefPtrWillBeMember<StyleRuleBase> >& adoptRules)
{
return adoptRefWillBeNoop(new StyleRuleMedia(media, adoptRules));
}
MediaQuerySet* mediaQueries() const { return m_mediaQueries.get(); }
PassRefPtrWillBeRawPtr<StyleRuleMedia> copy() const { return adoptRefWillBeNoop(new StyleRuleMedia(*this)); }
void traceAfterDispatch(Visitor*);
private:
StyleRuleMedia(PassRefPtrWillBeRawPtr<MediaQuerySet>, WillBeHeapVector<RefPtrWillBeMember<StyleRuleBase> >& adoptRules);
StyleRuleMedia(const StyleRuleMedia&);
RefPtrWillBeMember<MediaQuerySet> m_mediaQueries;
};
class StyleRuleSupports : public StyleRuleGroup {
public:
static PassRefPtrWillBeRawPtr<StyleRuleSupports> create(const String& conditionText, bool conditionIsSupported, WillBeHeapVector<RefPtrWillBeMember<StyleRuleBase> >& adoptRules)
{
return adoptRefWillBeNoop(new StyleRuleSupports(conditionText, conditionIsSupported, adoptRules));
}
String conditionText() const { return m_conditionText; }
bool conditionIsSupported() const { return m_conditionIsSupported; }
PassRefPtrWillBeRawPtr<StyleRuleSupports> copy() const { return adoptRefWillBeNoop(new StyleRuleSupports(*this)); }
void traceAfterDispatch(Visitor* visitor) { StyleRuleGroup::traceAfterDispatch(visitor); }
private:
StyleRuleSupports(const String& conditionText, bool conditionIsSupported, WillBeHeapVector<RefPtrWillBeMember<StyleRuleBase> >& adoptRules);
StyleRuleSupports(const StyleRuleSupports&);
String m_conditionText;
bool m_conditionIsSupported;
};
class StyleRuleViewport : public StyleRuleBase {
public:
static PassRefPtrWillBeRawPtr<StyleRuleViewport> create() { return adoptRefWillBeNoop(new StyleRuleViewport); }
~StyleRuleViewport();
const StylePropertySet& properties() const { return *m_properties; }
MutableStylePropertySet& mutableProperties();
void setProperties(PassRefPtrWillBeRawPtr<StylePropertySet>);
PassRefPtrWillBeRawPtr<StyleRuleViewport> copy() const { return adoptRefWillBeNoop(new StyleRuleViewport(*this)); }
void traceAfterDispatch(Visitor*);
private:
StyleRuleViewport();
StyleRuleViewport(const StyleRuleViewport&);
RefPtrWillBeMember<StylePropertySet> m_properties; // Cannot be null
};
class StyleRuleFilter : public StyleRuleBase {
public:
static PassRefPtrWillBeRawPtr<StyleRuleFilter> create(const String& filterName) { return adoptRefWillBeNoop(new StyleRuleFilter(filterName)); }
~StyleRuleFilter();
const String& filterName() const { return m_filterName; }
const StylePropertySet& properties() const { return *m_properties; }
MutableStylePropertySet& mutableProperties();
void setProperties(PassRefPtrWillBeRawPtr<StylePropertySet>);
PassRefPtrWillBeRawPtr<StyleRuleFilter> copy() const { return adoptRefWillBeNoop(new StyleRuleFilter(*this)); }
void traceAfterDispatch(Visitor*);
private:
StyleRuleFilter(const String&);
StyleRuleFilter(const StyleRuleFilter&);
String m_filterName;
RefPtrWillBeMember<StylePropertySet> m_properties;
};
#define DEFINE_STYLE_RULE_TYPE_CASTS(Type) \
DEFINE_TYPE_CASTS(StyleRule##Type, StyleRuleBase, rule, rule->is##Type##Rule(), rule.is##Type##Rule())
DEFINE_TYPE_CASTS(StyleRule, StyleRuleBase, rule, rule->isStyleRule(), rule.isStyleRule());
DEFINE_STYLE_RULE_TYPE_CASTS(FontFace);
DEFINE_STYLE_RULE_TYPE_CASTS(Page);
DEFINE_STYLE_RULE_TYPE_CASTS(Media);
DEFINE_STYLE_RULE_TYPE_CASTS(Supports);
DEFINE_STYLE_RULE_TYPE_CASTS(Viewport);
DEFINE_STYLE_RULE_TYPE_CASTS(Filter);
} // namespace blink
#endif // StyleRule_h
|