Use is<>() / downcast<>() for CSSRule subclasses
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 Oct 2014 01:40:12 +0000 (01:40 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 Oct 2014 01:40:12 +0000 (01:40 +0000)
https://bugs.webkit.org/show_bug.cgi?id=137364

Reviewed by Benjamin Poulain.

Use is<>() / downcast<>() functions for CSSRule subclasses.

No new tests, no behavior change.

* css/CSSFontFaceRule.h:
* css/CSSImportRule.h:
* css/CSSMediaRule.h:
* css/CSSRule.h:
* css/CSSStyleRule.h:
* css/CSSSupportsRule.h:
* css/InspectorCSSOMWrappers.cpp:
(WebCore::InspectorCSSOMWrappers::collect):
* css/WebKitCSSKeyframesRule.h:
* css/WebKitCSSRegionRule.h:
* inspector/InspectorCSSAgent.cpp:
(WebCore::InspectorCSSAgent::asCSSStyleRule):
(WebCore::InspectorCSSAgent::collectStyleSheets):
(WebCore::InspectorCSSAgent::buildArrayForRuleList):
* inspector/InspectorStyleSheet.cpp:
(WebCore::asCSSRuleList):
(WebCore::fillMediaListChain):
(WebCore::InspectorStyleSheet::addRule):
(WebCore::InspectorStyleSheet::collectFlatRules):
* page/PageSerializer.cpp:
(WebCore::PageSerializer::serializeCSSStyleSheet):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@174253 268f45cc-cd09-0410-ab3c-d52691b4dbfc

14 files changed:
Source/WebCore/ChangeLog
Source/WebCore/css/CSSFontFaceRule.h
Source/WebCore/css/CSSImportRule.h
Source/WebCore/css/CSSMediaRule.h
Source/WebCore/css/CSSRule.h
Source/WebCore/css/CSSStyleRule.h
Source/WebCore/css/CSSSupportsRule.h
Source/WebCore/css/InspectorCSSOMWrappers.cpp
Source/WebCore/css/WebKitCSSKeyframesRule.h
Source/WebCore/css/WebKitCSSRegionRule.h
Source/WebCore/inspector/InspectorCSSAgent.cpp
Source/WebCore/inspector/InspectorCSSAgent.h
Source/WebCore/inspector/InspectorStyleSheet.cpp
Source/WebCore/page/PageSerializer.cpp

index d799dae..93bd084 100644 (file)
@@ -1,3 +1,36 @@
+2014-10-02  Christophe Dumez  <cdumez@apple.com>
+
+        Use is<>() / downcast<>() for CSSRule subclasses
+        https://bugs.webkit.org/show_bug.cgi?id=137364
+
+        Reviewed by Benjamin Poulain.
+
+        Use is<>() / downcast<>() functions for CSSRule subclasses.
+
+        No new tests, no behavior change.
+
+        * css/CSSFontFaceRule.h:
+        * css/CSSImportRule.h:
+        * css/CSSMediaRule.h:
+        * css/CSSRule.h:
+        * css/CSSStyleRule.h:
+        * css/CSSSupportsRule.h:
+        * css/InspectorCSSOMWrappers.cpp:
+        (WebCore::InspectorCSSOMWrappers::collect):
+        * css/WebKitCSSKeyframesRule.h:
+        * css/WebKitCSSRegionRule.h:
+        * inspector/InspectorCSSAgent.cpp:
+        (WebCore::InspectorCSSAgent::asCSSStyleRule):
+        (WebCore::InspectorCSSAgent::collectStyleSheets):
+        (WebCore::InspectorCSSAgent::buildArrayForRuleList):
+        * inspector/InspectorStyleSheet.cpp:
+        (WebCore::asCSSRuleList):
+        (WebCore::fillMediaListChain):
+        (WebCore::InspectorStyleSheet::addRule):
+        (WebCore::InspectorStyleSheet::collectFlatRules):
+        * page/PageSerializer.cpp:
+        (WebCore::PageSerializer::serializeCSSStyleSheet):
+
 2014-10-02  Dan Bernstein  <mitz@apple.com>
 
         <rdar://problem/18531395> REGRESSION (r173272): Crash in ResourceResponse::platformSuggestedFilename() when called on the null response
 2014-10-02  Dan Bernstein  <mitz@apple.com>
 
         <rdar://problem/18531395> REGRESSION (r173272): Crash in ResourceResponse::platformSuggestedFilename() when called on the null response
index 3631be7..638e898 100644 (file)
@@ -51,4 +51,6 @@ private:
 
 } // namespace WebCore
 
 
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_CSS_RULE(CSSFontFaceRule, CSSRule::FONT_FACE_RULE)
+
 #endif // CSSFontFaceRule_h
 #endif // CSSFontFaceRule_h
index 18bedac..4c4f262 100644 (file)
@@ -53,8 +53,8 @@ private:
     mutable RefPtr<CSSStyleSheet> m_styleSheetCSSOMWrapper;
 };
 
     mutable RefPtr<CSSStyleSheet> m_styleSheetCSSOMWrapper;
 };
 
-CSS_RULE_TYPE_CASTS(CSSImportRule, CSSRule::IMPORT_RULE)
-
 } // namespace WebCore
 
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_CSS_RULE(CSSImportRule, CSSRule::IMPORT_RULE)
+
 #endif // CSSImportRule_h
 #endif // CSSImportRule_h
index 7a6b534..a422070 100644 (file)
@@ -50,8 +50,8 @@ private:
     mutable RefPtr<MediaList> m_mediaCSSOMWrapper;
 };
 
     mutable RefPtr<MediaList> m_mediaCSSOMWrapper;
 };
 
-CSS_RULE_TYPE_CASTS(CSSMediaRule, CSSRule::MEDIA_RULE)
-
 } // namespace WebCore
 
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_CSS_RULE(CSSMediaRule, CSSRule::MEDIA_RULE)
+
 #endif // CSSMediaRule_h
 #endif // CSSMediaRule_h
index c758dcc..2945b98 100644 (file)
@@ -24,6 +24,7 @@
 #define CSSRule_h
 
 #include <wtf/RefCounted.h>
 #define CSSRule_h
 
 #include <wtf/RefCounted.h>
+#include <wtf/TypeCasts.h>
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {
@@ -112,9 +113,11 @@ private:
     };
 };
 
     };
 };
 
-#define CSS_RULE_TYPE_CASTS(ToValueTypeName, predicate) \
-    TYPE_CASTS_BASE(ToValueTypeName, CSSRule, rule, rule->type() == predicate, rule.type() == predicate)
-
 } // namespace WebCore
 
 } // namespace WebCore
 
+#define SPECIALIZE_TYPE_TRAITS_CSS_RULE(ToValueTypeName, predicate) \
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ToValueTypeName) \
+    static bool isType(const WebCore::CSSRule& rule) { return rule.type() == WebCore::predicate; } \
+SPECIALIZE_TYPE_TRAITS_END()
+
 #endif // CSSRule_h
 #endif // CSSRule_h
index 52c9546..4d50fea 100644 (file)
@@ -57,8 +57,8 @@ private:
     RefPtr<StyleRuleCSSStyleDeclaration> m_propertiesCSSOMWrapper;
 };
 
     RefPtr<StyleRuleCSSStyleDeclaration> m_propertiesCSSOMWrapper;
 };
 
-CSS_RULE_TYPE_CASTS(CSSStyleRule, CSSRule::STYLE_RULE)
-
 } // namespace WebCore
 
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_CSS_RULE(CSSStyleRule, CSSRule::STYLE_RULE)
+
 #endif // CSSStyleRule_h
 #endif // CSSStyleRule_h
index 654f19c..efe5ce6 100644 (file)
@@ -56,10 +56,10 @@ private:
     CSSSupportsRule(StyleRuleSupports*, CSSStyleSheet*);
 };
 
     CSSSupportsRule(StyleRuleSupports*, CSSStyleSheet*);
 };
 
-CSS_RULE_TYPE_CASTS(CSSSupportsRule, CSSRule::SUPPORTS_RULE)
-
 } // namespace WebCore
 
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_CSS_RULE(CSSSupportsRule, CSSRule::SUPPORTS_RULE)
+
 #endif // ENABLE(CSS3_CONDITIONAL_RULES)
 
 #endif // CSSSupportsRule_h
 #endif // ENABLE(CSS3_CONDITIONAL_RULES)
 
 #endif // CSSSupportsRule_h
index f390f15..db93154 100644 (file)
@@ -58,23 +58,23 @@ void InspectorCSSOMWrappers::collect(ListType* listType)
         CSSRule* cssRule = listType->item(i);
         switch (cssRule->type()) {
         case CSSRule::IMPORT_RULE:
         CSSRule* cssRule = listType->item(i);
         switch (cssRule->type()) {
         case CSSRule::IMPORT_RULE:
-            collect(toCSSImportRule(cssRule)->styleSheet());
+            collect(downcast<CSSImportRule>(*cssRule).styleSheet());
             break;
         case CSSRule::MEDIA_RULE:
             break;
         case CSSRule::MEDIA_RULE:
-            collect(toCSSMediaRule(cssRule));
+            collect(downcast<CSSMediaRule>(cssRule));
             break;
 #if ENABLE(CSS3_CONDITIONAL_RULES)
         case CSSRule::SUPPORTS_RULE:
             break;
 #if ENABLE(CSS3_CONDITIONAL_RULES)
         case CSSRule::SUPPORTS_RULE:
-            collect(toCSSSupportsRule(cssRule));
+            collect(downcast<CSSSupportsRule>(cssRule));
             break;
 #endif
 #if ENABLE(CSS_REGIONS)
         case CSSRule::WEBKIT_REGION_RULE:
             break;
 #endif
 #if ENABLE(CSS_REGIONS)
         case CSSRule::WEBKIT_REGION_RULE:
-            collect(toWebKitCSSRegionRule(cssRule));
+            collect(downcast<WebKitCSSRegionRule>(cssRule));
             break;
 #endif
         case CSSRule::STYLE_RULE:
             break;
 #endif
         case CSSRule::STYLE_RULE:
-            m_styleRuleToCSSOMWrapperMap.add(toCSSStyleRule(cssRule)->styleRule(), toCSSStyleRule(cssRule));
+            m_styleRuleToCSSOMWrapperMap.add(downcast<CSSStyleRule>(*cssRule).styleRule(), downcast<CSSStyleRule>(cssRule));
             break;
         default:
             break;
             break;
         default:
             break;
index eb1f104..93f86be 100644 (file)
@@ -99,4 +99,6 @@ private:
 
 } // namespace WebCore
 
 
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_CSS_RULE(WebKitCSSKeyframesRule, CSSRule::WEBKIT_KEYFRAMES_RULE)
+
 #endif // WebKitCSSKeyframesRule_h
 #endif // WebKitCSSKeyframesRule_h
index dfe89ca..4785842 100644 (file)
@@ -50,9 +50,9 @@ private:
     WebKitCSSRegionRule(StyleRuleRegion*, CSSStyleSheet* parent);
 };
 
     WebKitCSSRegionRule(StyleRuleRegion*, CSSStyleSheet* parent);
 };
 
-CSS_RULE_TYPE_CASTS(WebKitCSSRegionRule, CSSRule::WEBKIT_REGION_RULE)
+} // namespace WebCore
 
 
-}
+SPECIALIZE_TYPE_TRAITS_CSS_RULE(WebKitCSSRegionRule, CSSRule::WEBKIT_REGION_RULE)
 
 #endif // ENABLE(CSS_REGIONS)
 
 
 #endif // ENABLE(CSS_REGIONS)
 
index 6eecd5d..9e5687d 100644 (file)
@@ -427,11 +427,11 @@ private:
 };
 
 // static
 };
 
 // static
-CSSStyleRule* InspectorCSSAgent::asCSSStyleRule(CSSRule* rule)
+CSSStyleRule* InspectorCSSAgent::asCSSStyleRule(CSSRule& rule)
 {
 {
-    if (rule->type() != CSSRule::STYLE_RULE)
+    if (!is<CSSStyleRule>(rule))
         return nullptr;
         return nullptr;
-    return toCSSStyleRule(rule);
+    return downcast<CSSStyleRule>(&rule);
 }
 
 InspectorCSSAgent::InspectorCSSAgent(InstrumentingAgents* instrumentingAgents, InspectorDOMAgent* domAgent)
 }
 
 InspectorCSSAgent::InspectorCSSAgent(InstrumentingAgents* instrumentingAgents, InspectorDOMAgent* domAgent)
@@ -918,9 +918,8 @@ void InspectorCSSAgent::collectStyleSheets(CSSStyleSheet* styleSheet, Inspector:
     result->addItem(inspectorStyleSheet->buildObjectForStyleSheetInfo());
     for (unsigned i = 0, size = styleSheet->length(); i < size; ++i) {
         CSSRule* rule = styleSheet->item(i);
     result->addItem(inspectorStyleSheet->buildObjectForStyleSheetInfo());
     for (unsigned i = 0, size = styleSheet->length(); i < size; ++i) {
         CSSRule* rule = styleSheet->item(i);
-        if (rule->type() == CSSRule::IMPORT_RULE) {
-            CSSStyleSheet* importedStyleSheet = toCSSImportRule(rule)->styleSheet();
-            if (importedStyleSheet)
+        if (is<CSSImportRule>(*rule)) {
+            if (CSSStyleSheet* importedStyleSheet = downcast<CSSImportRule>(*rule).styleSheet())
                 collectStyleSheets(importedStyleSheet, result);
         }
     }
                 collectStyleSheets(importedStyleSheet, result);
         }
     }
@@ -1046,7 +1045,7 @@ PassRefPtr<Inspector::Protocol::Array<Inspector::Protocol::CSS::CSSRule>> Inspec
         return result.release();
 
     for (unsigned i = 0, size = ruleList->length(); i < size; ++i) {
         return result.release();
 
     for (unsigned i = 0, size = ruleList->length(); i < size; ++i) {
-        CSSStyleRule* rule = asCSSStyleRule(ruleList->item(i));
+        CSSStyleRule* rule = asCSSStyleRule(*ruleList->item(i));
         RefPtr<Inspector::Protocol::CSS::CSSRule> ruleObject = buildObjectForRule(rule);
         if (!ruleObject)
             continue;
         RefPtr<Inspector::Protocol::CSS::CSSRule> ruleObject = buildObjectForRule(rule);
         if (!ruleObject)
             continue;
index 08a888b..82a38ed 100644 (file)
@@ -92,7 +92,7 @@ public:
     InspectorCSSAgent(InstrumentingAgents*, InspectorDOMAgent*);
     ~InspectorCSSAgent();
 
     InspectorCSSAgent(InstrumentingAgents*, InspectorDOMAgent*);
     ~InspectorCSSAgent();
 
-    static CSSStyleRule* asCSSStyleRule(CSSRule*);
+    static CSSStyleRule* asCSSStyleRule(CSSRule&);
 
     bool forcePseudoState(Element*, CSSSelector::PseudoClassType);
     virtual void didCreateFrontendAndBackend(Inspector::InspectorFrontendChannel*, Inspector::InspectorBackendDispatcher*) override;
 
     bool forcePseudoState(Element*, CSSSelector::PseudoClassType);
     virtual void didCreateFrontendAndBackend(Inspector::InspectorFrontendChannel*, Inspector::InspectorBackendDispatcher*) override;
index 5b7fa6e..6830f6f 100644 (file)
@@ -214,15 +214,15 @@ static PassRefPtr<CSSRuleList> asCSSRuleList(CSSRule* rule)
     if (!rule)
         return nullptr;
 
     if (!rule)
         return nullptr;
 
-    if (rule->type() == CSSRule::MEDIA_RULE)
-        return &toCSSMediaRule(rule)->cssRules();
+    if (is<CSSMediaRule>(*rule))
+        return &downcast<CSSMediaRule>(*rule).cssRules();
 
 
-    if (rule->type() == CSSRule::WEBKIT_KEYFRAMES_RULE)
-        return &static_cast<WebKitCSSKeyframesRule*>(rule)->cssRules();
+    if (is<WebKitCSSKeyframesRule>(*rule))
+        return &downcast<WebKitCSSKeyframesRule>(*rule).cssRules();
 
 #if ENABLE(CSS3_CONDITIONAL_RULES)
 
 #if ENABLE(CSS3_CONDITIONAL_RULES)
-    if (rule->type() == CSSRule::SUPPORTS_RULE)
-        return &toCSSSupportsRule(rule)->cssRules();
+    if (is<CSSSupportsRule>(*rule))
+        return &downcast<CSSSupportsRule>(*rule).cssRules();
 #endif
 
     return nullptr;
 #endif
 
     return nullptr;
@@ -236,14 +236,14 @@ static void fillMediaListChain(CSSRule* rule, Array<Inspector::Protocol::CSS::CS
     while (parentRule) {
         CSSStyleSheet* parentStyleSheet = nullptr;
         bool isMediaRule = true;
     while (parentRule) {
         CSSStyleSheet* parentStyleSheet = nullptr;
         bool isMediaRule = true;
-        if (parentRule->type() == CSSRule::MEDIA_RULE) {
-            CSSMediaRule* mediaRule = toCSSMediaRule(parentRule);
-            mediaList = mediaRule->media();
-            parentStyleSheet = mediaRule->parentStyleSheet();
-        } else if (parentRule->type() == CSSRule::IMPORT_RULE) {
-            CSSImportRule* importRule = toCSSImportRule(parentRule);
-            mediaList = &importRule->media();
-            parentStyleSheet = importRule->parentStyleSheet();
+        if (is<CSSMediaRule>(*parentRule)) {
+            CSSMediaRule& mediaRule = downcast<CSSMediaRule>(*parentRule);
+            mediaList = mediaRule.media();
+            parentStyleSheet = mediaRule.parentStyleSheet();
+        } else if (is<CSSImportRule>(*parentRule)) {
+            CSSImportRule& importRule = downcast<CSSImportRule>(*parentRule);
+            mediaList = &importRule.media();
+            parentStyleSheet = importRule.parentStyleSheet();
             isMediaRule = false;
         } else
             mediaList = nullptr;
             isMediaRule = false;
         } else
             mediaList = nullptr;
@@ -892,7 +892,7 @@ CSSStyleRule* InspectorStyleSheet::addRule(const String& selector, ExceptionCode
     CSSRule* rule = m_pageStyleSheet->item(lastRuleIndex);
     ASSERT(rule);
 
     CSSRule* rule = m_pageStyleSheet->item(lastRuleIndex);
     ASSERT(rule);
 
-    CSSStyleRule* styleRule = InspectorCSSAgent::asCSSStyleRule(rule);
+    CSSStyleRule* styleRule = InspectorCSSAgent::asCSSStyleRule(*rule);
     if (!styleRule) {
         // What we just added has to be a CSSStyleRule - we cannot handle other types of rules yet.
         // If it is not a style rule, pretend we never touched the stylesheet.
     if (!styleRule) {
         // What we just added has to be a CSSStyleRule - we cannot handle other types of rules yet.
         // If it is not a style rule, pretend we never touched the stylesheet.
@@ -1421,7 +1421,7 @@ void InspectorStyleSheet::collectFlatRules(PassRefPtr<CSSRuleList> ruleList, CSS
 
     for (unsigned i = 0, size = ruleList->length(); i < size; ++i) {
         CSSRule* rule = ruleList->item(i);
 
     for (unsigned i = 0, size = ruleList->length(); i < size; ++i) {
         CSSRule* rule = ruleList->item(i);
-        CSSStyleRule* styleRule = InspectorCSSAgent::asCSSStyleRule(rule);
+        CSSStyleRule* styleRule = InspectorCSSAgent::asCSSStyleRule(*rule);
         if (styleRule)
             result->append(styleRule);
         else {
         if (styleRule)
             result->append(styleRule);
         else {
index 8d4758a..bac4f21 100644 (file)
@@ -31,6 +31,7 @@
 #include "config.h"
 #include "PageSerializer.h"
 
 #include "config.h"
 #include "PageSerializer.h"
 
+#include "CSSFontFaceRule.h"
 #include "CSSImageValue.h"
 #include "CSSImportRule.h"
 #include "CSSStyleRule.h"
 #include "CSSImageValue.h"
 #include "CSSImportRule.h"
 #include "CSSStyleRule.h"
@@ -265,17 +266,17 @@ void PageSerializer::serializeCSSStyleSheet(CSSStyleSheet* styleSheet, const URL
         }
         Document* document = styleSheet->ownerDocument();
         // Some rules have resources associated with them that we need to retrieve.
         }
         Document* document = styleSheet->ownerDocument();
         // Some rules have resources associated with them that we need to retrieve.
-        if (rule->type() == CSSRule::IMPORT_RULE) {
-            CSSImportRule* importRule = toCSSImportRule(rule);
-            URL importURL = document->completeURL(importRule->href());
+        if (is<CSSImportRule>(*rule)) {
+            CSSImportRule& importRule = downcast<CSSImportRule>(*rule);
+            URL importURL = document->completeURL(importRule.href());
             if (m_resourceURLs.contains(importURL))
                 continue;
             if (m_resourceURLs.contains(importURL))
                 continue;
-            serializeCSSStyleSheet(importRule->styleSheet(), importURL);
-        } else if (rule->type() == CSSRule::FONT_FACE_RULE) {
+            serializeCSSStyleSheet(importRule.styleSheet(), importURL);
+        } else if (is<CSSFontFaceRule>(*rule)) {
             // FIXME: Add support for font face rule. It is not clear to me at this point if the actual otf/eot file can
             // be retrieved from the CSSFontFaceRule object.
             // FIXME: Add support for font face rule. It is not clear to me at this point if the actual otf/eot file can
             // be retrieved from the CSSFontFaceRule object.
-        } else if (rule->type() == CSSRule::STYLE_RULE)
-            retrieveResourcesForRule(toCSSStyleRule(rule)->styleRule(), document);
+        } else if (is<CSSStyleRule>(*rule))
+            retrieveResourcesForRule(downcast<CSSStyleRule>(*rule).styleRule(), document);
     }
 
     if (url.isValid() && !m_resourceURLs.contains(url)) {
     }
 
     if (url.isValid() && !m_resourceURLs.contains(url)) {