source: webkit/trunk/Source/WebCore/css/CSSRule.h

Last change on this file was 286916, checked in by Antti Koivisto, 3 years ago

Remove redundant StyleRule::Type enum
https://bugs.webkit.org/show_bug.cgi?id=234156

Reviewed by Alan Bujtas.

Source/WebCore:

Remove redundant CSSRule::STYLE_RULE etc enum values and just use StyleRuleType enum class.

  • bindings/js/JSCSSRuleCustom.cpp:

(WebCore::toJSNewlyCreated):

  • bindings/scripts/CodeGenerator.pm:

(GenerateCompileTimeCheckForEnumsIfNeeded):

Add 'ConstantsEnum' attribute to generate static_asserts for constants that match an enum class.

  • bindings/scripts/IDLAttributes.json:
  • css/CSSCounterStyleRule.h:
  • css/CSSFontFaceRule.h:
  • css/CSSFontPaletteValuesRule.h:
  • css/CSSImportRule.h:
  • css/CSSKeyframeRule.h:
  • css/CSSKeyframesRule.h:
  • css/CSSLayerBlockRule.h:
  • css/CSSLayerStatementRule.h:
  • css/CSSMediaRule.h:
  • css/CSSNamespaceRule.h:
  • css/CSSPageRule.h:
  • css/CSSRule.cpp:
  • css/CSSRule.h:

(WebCore::CSSRule::typeForBindings const):

  • css/CSSRule.idl:
  • css/CSSStyleRule.h:
  • css/CSSSupportsRule.h:
  • css/CSSUnknownRule.h:
  • css/StyleRuleType.h:
  • style/InspectorCSSOMWrappers.cpp:

(WebCore::Style::InspectorCSSOMWrappers::collect):

Source/WebKitLegacy/mac:

  • DOM/DOMCSS.mm:

(kitClass):

  • DOM/DOMCSSRule.mm:

(-[DOMCSSRule type]):

  • Property svn:eol-style set to native
File size: 3.1 KB
Line 
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
29namespace WebCore {
30
31class CSSStyleSheet;
32class StyleRuleBase;
33
34struct CSSParserContext;
35
36class CSSRule : public RefCounted<CSSRule> {
37public:
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
53protected:
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
61private:
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
70inline CSSRule::CSSRule(CSSStyleSheet* parent)
71 : m_hasCachedSelectorText(false)
72 , m_parentIsRule(false)
73 , m_parentStyleSheet(parent)
74{
75}
76
77inline void CSSRule::setParentStyleSheet(CSSStyleSheet* styleSheet)
78{
79 m_parentIsRule = false;
80 m_parentStyleSheet = styleSheet;
81}
82
83inline void CSSRule::setParentRule(CSSRule* rule)
84{
85 m_parentIsRule = true;
86 m_parentRule = rule;
87}
88
89inline 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) \
99SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ToValueTypeName) \
100 static bool isType(const WebCore::CSSRule& rule) { return rule.styleRuleType() == WebCore::predicate; } \
101SPECIALIZE_TYPE_TRAITS_END()
Note: See TracBrowser for help on using the repository browser.