1 | /*
|
---|
2 | * (C) 1999-2003 Lars Knoll ([email protected])
|
---|
3 | * (C) 2002-2003 Dirk Mueller ([email protected])
|
---|
4 | * Copyright (C) 2002-2021 Apple Inc. All rights reserved.
|
---|
5 | * Copyright (C) 2011 Andreas Kling ([email protected])
|
---|
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 | #pragma once
|
---|
24 |
|
---|
25 | #include "ExceptionOr.h"
|
---|
26 | #include "StyleRuleType.h"
|
---|
27 | #include <wtf/TypeCasts.h>
|
---|
28 |
|
---|
29 | namespace WebCore {
|
---|
30 |
|
---|
31 | class CSSStyleSheet;
|
---|
32 | class StyleRuleBase;
|
---|
33 |
|
---|
34 | struct CSSParserContext;
|
---|
35 |
|
---|
36 | class CSSRule : public RefCounted<CSSRule> {
|
---|
37 | public:
|
---|
38 | virtual ~CSSRule() = default;
|
---|
39 |
|
---|
40 | unsigned short type() const { return static_cast<unsigned short>(styleRuleType()); }
|
---|
41 |
|
---|
42 | virtual StyleRuleType styleRuleType() const = 0;
|
---|
43 | virtual String cssText() const = 0;
|
---|
44 | virtual void reattach(StyleRuleBase&) = 0;
|
---|
45 |
|
---|
46 | void setParentStyleSheet(CSSStyleSheet*);
|
---|
47 | void setParentRule(CSSRule*);
|
---|
48 | CSSStyleSheet* parentStyleSheet() const;
|
---|
49 | CSSRule* parentRule() const { return m_parentIsRule ? m_parentRule : nullptr; }
|
---|
50 |
|
---|
51 | WEBCORE_EXPORT ExceptionOr<void> setCssText(const String&);
|
---|
52 |
|
---|
53 | protected:
|
---|
54 | explicit CSSRule(CSSStyleSheet*);
|
---|
55 |
|
---|
56 | bool hasCachedSelectorText() const { return m_hasCachedSelectorText; }
|
---|
57 | void setHasCachedSelectorText(bool hasCachedSelectorText) const { m_hasCachedSelectorText = hasCachedSelectorText; }
|
---|
58 |
|
---|
59 | const CSSParserContext& parserContext() const;
|
---|
60 |
|
---|
61 | private:
|
---|
62 | mutable unsigned char m_hasCachedSelectorText : 1;
|
---|
63 | unsigned char m_parentIsRule : 1;
|
---|
64 | union {
|
---|
65 | CSSRule* m_parentRule;
|
---|
66 | CSSStyleSheet* m_parentStyleSheet;
|
---|
67 | };
|
---|
68 | };
|
---|
69 |
|
---|
70 | inline CSSRule::CSSRule(CSSStyleSheet* parent)
|
---|
71 | : m_hasCachedSelectorText(false)
|
---|
72 | , m_parentIsRule(false)
|
---|
73 | , m_parentStyleSheet(parent)
|
---|
74 | {
|
---|
75 | }
|
---|
76 |
|
---|
77 | inline void CSSRule::setParentStyleSheet(CSSStyleSheet* styleSheet)
|
---|
78 | {
|
---|
79 | m_parentIsRule = false;
|
---|
80 | m_parentStyleSheet = styleSheet;
|
---|
81 | }
|
---|
82 |
|
---|
83 | inline void CSSRule::setParentRule(CSSRule* rule)
|
---|
84 | {
|
---|
85 | m_parentIsRule = true;
|
---|
86 | m_parentRule = rule;
|
---|
87 | }
|
---|
88 |
|
---|
89 | inline CSSStyleSheet* CSSRule::parentStyleSheet() const
|
---|
90 | {
|
---|
91 | if (m_parentIsRule)
|
---|
92 | return m_parentRule ? m_parentRule->parentStyleSheet() : nullptr;
|
---|
93 | return m_parentStyleSheet;
|
---|
94 | }
|
---|
95 |
|
---|
96 | } // namespace WebCore
|
---|
97 |
|
---|
98 | #define SPECIALIZE_TYPE_TRAITS_CSS_RULE(ToValueTypeName, predicate) \
|
---|
99 | SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ToValueTypeName) \
|
---|
100 | static bool isType(const WebCore::CSSRule& rule) { return rule.styleRuleType() == WebCore::predicate; } \
|
---|
101 | SPECIALIZE_TYPE_TRAITS_END()
|
---|