Introduce CSS_RULE_TYPE_CASTS, and use it
authorgyuyoung.kim@samsung.com <gyuyoung.kim@samsung.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 8 Sep 2014 17:10:01 +0000 (17:10 +0000)
committergyuyoung.kim@samsung.com <gyuyoung.kim@samsung.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 8 Sep 2014 17:10:01 +0000 (17:10 +0000)
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):

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

13 files changed:
Source/WebCore/ChangeLog
Source/WebCore/css/CSSFontSelector.cpp
Source/WebCore/css/CSSImportRule.h
Source/WebCore/css/CSSMediaRule.h
Source/WebCore/css/CSSParser.cpp
Source/WebCore/css/CSSRule.h
Source/WebCore/css/CSSStyleRule.h
Source/WebCore/css/CSSSupportsRule.h
Source/WebCore/css/InspectorCSSOMWrappers.cpp
Source/WebCore/css/WebKitCSSRegionRule.h
Source/WebCore/inspector/InspectorCSSAgent.cpp
Source/WebCore/inspector/InspectorStyleSheet.cpp
Source/WebCore/page/PageSerializer.cpp

index c07049e..b7ae18e 100644 (file)
@@ -1,5 +1,40 @@
 2014-09-08  Gyuyoung Kim  <gyuyoung.kim@samsung.com>
 
+        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):
+
+2014-09-08  Gyuyoung Kim  <gyuyoung.kim@samsung.com>
+
         [EFL[WK2] MiniBrowser comes to crash on debug mode
         https://bugs.webkit.org/show_bug.cgi?id=136617
 
index 4648897..0ad9823 100644 (file)
@@ -251,7 +251,7 @@ void CSSFontSelector::addFontFaceRule(const StyleRuleFontFace* fontFaceRule)
     if (rangeList) {
         unsigned numRanges = rangeList->length();
         for (unsigned i = 0; i < numRanges; i++) {
-            CSSUnicodeRangeValue* range = static_cast<CSSUnicodeRangeValue*>(rangeList->itemWithoutBoundsCheck(i));
+            CSSUnicodeRangeValue* range = toCSSUnicodeRangeValue(rangeList->itemWithoutBoundsCheck(i));
             fontFace->addRange(range->from(), range->to());
         }
     }
index 83122b3..fbf261a 100644 (file)
@@ -53,6 +53,8 @@ private:
     mutable RefPtr<CSSStyleSheet> m_styleSheetCSSOMWrapper;
 };
 
+CSS_RULE_TYPE_CASTS(CSSImportRule, CSSRule::IMPORT_RULE)
+
 } // namespace WebCore
 
 #endif // CSSImportRule_h
index aeea9d2..7a6b534 100644 (file)
@@ -50,6 +50,8 @@ private:
     mutable RefPtr<MediaList> m_mediaCSSOMWrapper;
 };
 
+CSS_RULE_TYPE_CASTS(CSSMediaRule, CSSRule::MEDIA_RULE)
+
 } // namespace WebCore
 
 #endif // CSSMediaRule_h
index 42ee46b..2112cc3 100644 (file)
@@ -5007,7 +5007,7 @@ bool CSSParser::parseGridTemplateRowsAndAreas(PassRefPtr<CSSValue> templateColum
         if (m_valueList->current()->unit == CSSParserValue::ValueList) {
             if (trailingIdentWasAdded) {
                 // A row's trailing ident must be concatenated with the next row's leading one.
-                parseGridLineNames(*m_valueList, *templateRows, static_cast<CSSGridLineNamesValue*>(templateRows->item(templateRows->length() - 1)));
+                parseGridLineNames(*m_valueList, *templateRows, toCSSGridLineNamesValue(templateRows->item(templateRows->length() - 1)));
             } else
                 parseGridLineNames(*m_valueList, *templateRows);
         }
index e1c6be4..c758dcc 100644 (file)
@@ -112,6 +112,9 @@ private:
     };
 };
 
+#define CSS_RULE_TYPE_CASTS(ToValueTypeName, predicate) \
+    TYPE_CASTS_BASE(ToValueTypeName, CSSRule, rule, rule->type() == predicate, rule.type() == predicate)
+
 } // namespace WebCore
 
 #endif // CSSRule_h
index 31e2692..649bb06 100644 (file)
@@ -57,6 +57,8 @@ private:
     RefPtr<StyleRuleCSSStyleDeclaration> m_propertiesCSSOMWrapper;
 };
 
+CSS_RULE_TYPE_CASTS(CSSStyleRule, CSSRule::STYLE_RULE)
+
 } // namespace WebCore
 
 #endif // CSSStyleRule_h
index 8386851..654f19c 100644 (file)
@@ -56,6 +56,8 @@ private:
     CSSSupportsRule(StyleRuleSupports*, CSSStyleSheet*);
 };
 
+CSS_RULE_TYPE_CASTS(CSSSupportsRule, CSSRule::SUPPORTS_RULE)
+
 } // namespace WebCore
 
 #endif // ENABLE(CSS3_CONDITIONAL_RULES)
index 891985b..f390f15 100644 (file)
@@ -58,23 +58,23 @@ void InspectorCSSOMWrappers::collect(ListType* listType)
         CSSRule* cssRule = listType->item(i);
         switch (cssRule->type()) {
         case CSSRule::IMPORT_RULE:
-            collect(static_cast<CSSImportRule*>(cssRule)->styleSheet());
+            collect(toCSSImportRule(cssRule)->styleSheet());
             break;
         case CSSRule::MEDIA_RULE:
-            collect(static_cast<CSSMediaRule*>(cssRule));
+            collect(toCSSMediaRule(cssRule));
             break;
 #if ENABLE(CSS3_CONDITIONAL_RULES)
         case CSSRule::SUPPORTS_RULE:
-            collect(static_cast<CSSSupportsRule*>(cssRule));
+            collect(toCSSSupportsRule(cssRule));
             break;
 #endif
 #if ENABLE(CSS_REGIONS)
         case CSSRule::WEBKIT_REGION_RULE:
-            collect(static_cast<WebKitCSSRegionRule*>(cssRule));
+            collect(toWebKitCSSRegionRule(cssRule));
             break;
 #endif
         case CSSRule::STYLE_RULE:
-            m_styleRuleToCSSOMWrapperMap.add(static_cast<CSSStyleRule*>(cssRule)->styleRule(), static_cast<CSSStyleRule*>(cssRule));
+            m_styleRuleToCSSOMWrapperMap.add(toCSSStyleRule(cssRule)->styleRule(), toCSSStyleRule(cssRule));
             break;
         default:
             break;
index ff35447..dfe89ca 100644 (file)
@@ -50,6 +50,8 @@ private:
     WebKitCSSRegionRule(StyleRuleRegion*, CSSStyleSheet* parent);
 };
 
+CSS_RULE_TYPE_CASTS(WebKitCSSRegionRule, CSSRule::WEBKIT_REGION_RULE)
+
 }
 
 #endif // ENABLE(CSS_REGIONS)
index 21e9955..bc69c58 100644 (file)
@@ -431,7 +431,7 @@ CSSStyleRule* InspectorCSSAgent::asCSSStyleRule(CSSRule* rule)
 {
     if (rule->type() != CSSRule::STYLE_RULE)
         return nullptr;
-    return static_cast<CSSStyleRule*>(rule);
+    return toCSSStyleRule(rule);
 }
 
 InspectorCSSAgent::InspectorCSSAgent(InstrumentingAgents* instrumentingAgents, InspectorDOMAgent* domAgent)
@@ -919,7 +919,7 @@ void InspectorCSSAgent::collectStyleSheets(CSSStyleSheet* styleSheet, Inspector:
     for (unsigned i = 0, size = styleSheet->length(); i < size; ++i) {
         CSSRule* rule = styleSheet->item(i);
         if (rule->type() == CSSRule::IMPORT_RULE) {
-            CSSStyleSheet* importedStyleSheet = static_cast<CSSImportRule*>(rule)->styleSheet();
+            CSSStyleSheet* importedStyleSheet = toCSSImportRule(rule)->styleSheet();
             if (importedStyleSheet)
                 collectStyleSheets(importedStyleSheet, result);
         }
index 1ffdd4c..012c538 100644 (file)
@@ -215,14 +215,14 @@ static PassRefPtr<CSSRuleList> asCSSRuleList(CSSRule* rule)
         return nullptr;
 
     if (rule->type() == CSSRule::MEDIA_RULE)
-        return static_cast<CSSMediaRule*>(rule)->cssRules();
+        return toCSSMediaRule(rule)->cssRules();
 
     if (rule->type() == CSSRule::WEBKIT_KEYFRAMES_RULE)
         return static_cast<WebKitCSSKeyframesRule*>(rule)->cssRules();
 
 #if ENABLE(CSS3_CONDITIONAL_RULES)
     if (rule->type() == CSSRule::SUPPORTS_RULE)
-        return static_cast<CSSSupportsRule*>(rule)->cssRules();
+        return toCSSSupportsRule(rule)->cssRules();
 #endif
 
     return nullptr;
@@ -237,11 +237,11 @@ static void fillMediaListChain(CSSRule* rule, Array<Inspector::Protocol::CSS::CS
         CSSStyleSheet* parentStyleSheet = nullptr;
         bool isMediaRule = true;
         if (parentRule->type() == CSSRule::MEDIA_RULE) {
-            CSSMediaRule* mediaRule = static_cast<CSSMediaRule*>(parentRule);
+            CSSMediaRule* mediaRule = toCSSMediaRule(parentRule);
             mediaList = mediaRule->media();
             parentStyleSheet = mediaRule->parentStyleSheet();
         } else if (parentRule->type() == CSSRule::IMPORT_RULE) {
-            CSSImportRule* importRule = static_cast<CSSImportRule*>(parentRule);
+            CSSImportRule* importRule = toCSSImportRule(parentRule);
             mediaList = importRule->media();
             parentStyleSheet = importRule->parentStyleSheet();
             isMediaRule = false;
index 2c9d0ff..7622f11 100644 (file)
@@ -266,7 +266,7 @@ void PageSerializer::serializeCSSStyleSheet(CSSStyleSheet* styleSheet, const URL
         Document* document = styleSheet->ownerDocument();
         // Some rules have resources associated with them that we need to retrieve.
         if (rule->type() == CSSRule::IMPORT_RULE) {
-            CSSImportRule* importRule = static_cast<CSSImportRule*>(rule);
+            CSSImportRule* importRule = toCSSImportRule(rule);
             URL importURL = document->completeURL(importRule->href());
             if (m_resourceURLs.contains(importURL))
                 continue;
@@ -275,7 +275,7 @@ void PageSerializer::serializeCSSStyleSheet(CSSStyleSheet* styleSheet, const URL
             // 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(static_cast<CSSStyleRule*>(rule)->styleRule(), document);
+            retrieveResourcesForRule(toCSSStyleRule(rule)->styleRule(), document);
     }
 
     if (url.isValid() && !m_resourceURLs.contains(url)) {