• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3  * (C) 2002-2003 Dirk Mueller (mueller@kde.org)
4  * Copyright (C) 2002, 2006, 2007, 2012 Apple Inc. All rights reserved.
5  * Copyright (C) 2011 Andreas Kling (kling@webkit.org)
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public License
18  * along with this library; see the file COPYING.LIB.  If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef CSSRule_h
24 #define CSSRule_h
25 
26 #include "platform/heap/Handle.h"
27 #include "wtf/RefCounted.h"
28 #include "wtf/text/WTFString.h"
29 
30 namespace WebCore {
31 
32 class CSSParserContext;
33 class CSSStyleSheet;
34 class StyleRuleBase;
35 
36 class CSSRule : public RefCountedWillBeGarbageCollectedFinalized<CSSRule> {
37 public:
~CSSRule()38     virtual ~CSSRule() { }
39 
40     enum Type {
41         UNKNOWN_RULE,
42         STYLE_RULE,
43         CHARSET_RULE,
44         IMPORT_RULE,
45         MEDIA_RULE,
46         FONT_FACE_RULE,
47         PAGE_RULE,
48         // 7 was VARIABLES_RULE; we now match other browsers with 7 as
49         // KEYFRAMES_RULE:
50         // <https://bugs.webkit.org/show_bug.cgi?id=71293>.
51         KEYFRAMES_RULE,
52         WEBKIT_KEYFRAMES_RULE = KEYFRAMES_RULE,
53         KEYFRAME_RULE,
54         WEBKIT_KEYFRAME_RULE = KEYFRAME_RULE,
55         SUPPORTS_RULE = 12,
56         VIEWPORT_RULE = 15,
57         WEBKIT_FILTER_RULE = 17
58     };
59 
60     virtual Type type() const = 0;
61     virtual String cssText() const = 0;
62     virtual void reattach(StyleRuleBase*) = 0;
63 
setParentStyleSheet(CSSStyleSheet * styleSheet)64     void setParentStyleSheet(CSSStyleSheet* styleSheet)
65     {
66         m_parentIsRule = false;
67         m_parentStyleSheet = styleSheet;
68     }
69 
setParentRule(CSSRule * rule)70     void setParentRule(CSSRule* rule)
71     {
72         m_parentIsRule = true;
73         m_parentRule = rule;
74     }
75 
76     virtual void trace(Visitor*);
77 
parentStyleSheet()78     CSSStyleSheet* parentStyleSheet() const
79     {
80         if (m_parentIsRule)
81             return m_parentRule ? m_parentRule->parentStyleSheet() : 0;
82         return m_parentStyleSheet;
83     }
84 
parentRule()85     CSSRule* parentRule() const { return m_parentIsRule ? m_parentRule : 0; }
86 
87     // NOTE: Just calls notImplemented().
88     void setCSSText(const String&);
89 
90 protected:
CSSRule(CSSStyleSheet * parent)91     CSSRule(CSSStyleSheet* parent)
92         : m_hasCachedSelectorText(false)
93         , m_parentIsRule(false)
94         , m_parentStyleSheet(parent)
95     {
96     }
97 
hasCachedSelectorText()98     bool hasCachedSelectorText() const { return m_hasCachedSelectorText; }
setHasCachedSelectorText(bool hasCachedSelectorText)99     void setHasCachedSelectorText(bool hasCachedSelectorText) const { m_hasCachedSelectorText = hasCachedSelectorText; }
100 
101     const CSSParserContext& parserContext() const;
102 
103 private:
104     mutable unsigned char m_hasCachedSelectorText : 1;
105     unsigned char m_parentIsRule : 1;
106 
107     // These should be Members, but no Members in unions.
108     union {
109         CSSRule* m_parentRule;
110         CSSStyleSheet* m_parentStyleSheet;
111     };
112 };
113 
114 #define DEFINE_CSS_RULE_TYPE_CASTS(ToType, TYPE_NAME) \
115     DEFINE_TYPE_CASTS(ToType, CSSRule, rule, rule->type() == CSSRule::TYPE_NAME, rule.type() == CSSRule::TYPE_NAME)
116 
117 } // namespace WebCore
118 
119 #endif // CSSRule_h
120