source: trunk/Source/WebCore/css/CSSRule.h @ 174190

Revision 173382, 3.4 KB checked in by gyuyoung.kim@samsung.com, 3 weeks ago (diff)

Introduce CSS_RULE_TYPE_CASTS, and use it
https://bugs.webkit.org/show_bug.cgi?id=136628

Reviewed by Darin Adler.

As a step to use toFoo, this patch introduces toCSSFooRule(). This will help to detect
wrong type cast. Additionally some missing type casts are clean up as well.

No new tests, no behavior changes.

  • bindings/gobject/WebKitDOMPrivate.cpp:

(WebKit::wrap):

  • css/CSSFontSelector.cpp:

(WebCore::CSSFontSelector::addFontFaceRule):

  • css/CSSImportRule.h:
  • css/CSSMediaRule.h:
  • css/CSSParser.cpp:

(WebCore::CSSParser::parseGridTemplateRowsAndAreas):

  • css/CSSRule.h:
  • css/CSSStyleRule.h:
  • css/CSSSupportsRule.h:
  • css/InspectorCSSOMWrappers.cpp:

(WebCore::InspectorCSSOMWrappers::collect):

  • css/WebKitCSSRegionRule.h:
  • inspector/InspectorCSSAgent.cpp:

(WebCore::InspectorCSSAgent::asCSSStyleRule):
(WebCore::InspectorCSSAgent::collectStyleSheets):

  • inspector/InspectorStyleSheet.cpp:

(WebCore::asCSSRuleList):
(WebCore::fillMediaListChain):

  • page/PageSerializer.cpp:

(WebCore::PageSerializer::serializeCSSStyleSheet):

  • Property svn:eol-style set to native
Line 
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 <wtf/RefCounted.h>
27#include <wtf/text/WTFString.h>
28
29namespace WebCore {
30
31class CSSStyleSheet;
32class StyleRuleBase;
33struct CSSParserContext;
34typedef int ExceptionCode;
35
36class CSSRule : public RefCounted<CSSRule> {
37public:
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        WEBKIT_KEYFRAMES_RULE,
52        WEBKIT_KEYFRAME_RULE,
53#if ENABLE(CSS3_CONDITIONAL_RULES)
54        SUPPORTS_RULE = 12,
55#endif
56#if ENABLE(CSS_DEVICE_ADAPTATION)
57        WEBKIT_VIEWPORT_RULE = 15,
58#endif
59#if ENABLE(CSS_REGIONS)
60        WEBKIT_REGION_RULE = 16,
61#endif
62    };
63
64    virtual Type type() const = 0;
65    virtual String cssText() const = 0;
66    virtual void reattach(StyleRuleBase*) = 0;
67
68    void setParentStyleSheet(CSSStyleSheet* styleSheet)
69    {
70        m_parentIsRule = false;
71        m_parentStyleSheet = styleSheet;
72    }
73
74    void setParentRule(CSSRule* rule)
75    {
76        m_parentIsRule = true;
77        m_parentRule = rule;
78    }
79
80    CSSStyleSheet* parentStyleSheet() const
81    {
82        if (m_parentIsRule)
83            return m_parentRule ? m_parentRule->parentStyleSheet() : 0;
84        return m_parentStyleSheet;
85    }
86
87    CSSRule* parentRule() const { return m_parentIsRule ? m_parentRule : 0; }
88
89    // NOTE: Just calls notImplemented().
90    void setCssText(const String&, ExceptionCode&);
91
92protected:
93    CSSRule(CSSStyleSheet* parent)
94        : m_hasCachedSelectorText(false)
95        , m_parentIsRule(false)
96        , m_parentStyleSheet(parent)
97    {
98    }
99
100    bool hasCachedSelectorText() const { return m_hasCachedSelectorText; }
101    void setHasCachedSelectorText(bool hasCachedSelectorText) const { m_hasCachedSelectorText = hasCachedSelectorText; }
102
103    const CSSParserContext& parserContext() const;
104
105private:
106    mutable unsigned char m_hasCachedSelectorText : 1;
107    unsigned char m_parentIsRule : 1;
108
109    union {
110        CSSRule* m_parentRule;
111        CSSStyleSheet* m_parentStyleSheet;
112    };
113};
114
115#define CSS_RULE_TYPE_CASTS(ToValueTypeName, predicate) \
116    TYPE_CASTS_BASE(ToValueTypeName, CSSRule, rule, rule->type() == predicate, rule.type() == predicate)
117
118} // namespace WebCore
119
120#endif // CSSRule_h
Note: See TracBrowser for help on using the repository browser.