Use is<>() / downcast<>() for StyleSheet subclasses
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 6 Oct 2014 00:23:58 +0000 (00:23 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 6 Oct 2014 00:23:58 +0000 (00:23 +0000)
https://bugs.webkit.org/show_bug.cgi?id=137429

Reviewed by Benjamin Poulain.

Use is<>() / downcast<>() for StyleSheet subclasses.

No new tests, no behavior change.

* bindings/gobject/WebKitDOMPrivate.cpp:
(WebKit::wrap):
* css/CSSStyleSheet.h:
(isType):
* css/StyleSheet.h:
* dom/Document.cpp:
(WebCore::Document::applyXSLTransform):
* dom/DocumentStyleSheetCollection.cpp:
(WebCore::filterEnabledNonemptyCSSStyleSheets):
* dom/ProcessingInstruction.cpp:
(WebCore::ProcessingInstruction::parseStyleSheet):
* inspector/InspectorCSSAgent.cpp:
(WebCore::InspectorCSSAgent::getAllStyleSheets):
* xml/XSLStyleSheet.h:
(isType):

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

Source/WebCore/ChangeLog
Source/WebCore/bindings/gobject/WebKitDOMPrivate.cpp
Source/WebCore/css/CSSStyleSheet.h
Source/WebCore/css/StyleSheet.h
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/DocumentStyleSheetCollection.cpp
Source/WebCore/dom/ProcessingInstruction.cpp
Source/WebCore/inspector/InspectorCSSAgent.cpp
Source/WebCore/xml/XSLStyleSheet.h

index 5fdb013..31ff3bf 100644 (file)
@@ -1,5 +1,32 @@
 2014-10-05  Christophe Dumez  <cdumez@apple.com>
 
+        Use is<>() / downcast<>() for StyleSheet subclasses
+        https://bugs.webkit.org/show_bug.cgi?id=137429
+
+        Reviewed by Benjamin Poulain.
+
+        Use is<>() / downcast<>() for StyleSheet subclasses.
+
+        No new tests, no behavior change.
+
+        * bindings/gobject/WebKitDOMPrivate.cpp:
+        (WebKit::wrap):
+        * css/CSSStyleSheet.h:
+        (isType):
+        * css/StyleSheet.h:
+        * dom/Document.cpp:
+        (WebCore::Document::applyXSLTransform):
+        * dom/DocumentStyleSheetCollection.cpp:
+        (WebCore::filterEnabledNonemptyCSSStyleSheets):
+        * dom/ProcessingInstruction.cpp:
+        (WebCore::ProcessingInstruction::parseStyleSheet):
+        * inspector/InspectorCSSAgent.cpp:
+        (WebCore::InspectorCSSAgent::getAllStyleSheets):
+        * xml/XSLStyleSheet.h:
+        (isType):
+
+2014-10-05  Christophe Dumez  <cdumez@apple.com>
+
         Use is<>() / downcast<>() for CryptoAlgorithmParameters subclasses
         https://bugs.webkit.org/show_bug.cgi?id=137432
 
index 80cc6d6..374c29f 100644 (file)
@@ -140,8 +140,8 @@ WebKitDOMStyleSheet* wrap(StyleSheet* styleSheet)
 {
     ASSERT(styleSheet);
 
-    if (styleSheet->isCSSStyleSheet())
-        return WEBKIT_DOM_STYLE_SHEET(wrapCSSStyleSheet(toCSSStyleSheet(styleSheet)));
+    if (is<CSSStyleSheet>(*styleSheet))
+        return WEBKIT_DOM_STYLE_SHEET(wrapCSSStyleSheet(downcast<CSSStyleSheet>(styleSheet)));
     return wrapStyleSheet(styleSheet);
 }
 
index a54d17d..20593a1 100644 (file)
@@ -27,6 +27,7 @@
 #include <memory>
 #include <wtf/HashMap.h>
 #include <wtf/Noncopyable.h>
+#include <wtf/TypeCasts.h>
 #include <wtf/text/AtomicStringHash.h>
 
 namespace WebCore {
@@ -139,8 +140,10 @@ private:
     mutable std::unique_ptr<CSSRuleList> m_ruleListCSSOMWrapper;
 };
 
-STYLE_SHEET_TYPE_CASTS(CSSStyleSheet)
+} // namespace WebCore
 
-} // namespace
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::CSSStyleSheet)
+    static bool isType(const WebCore::StyleSheet& styleSheet) { return styleSheet.isCSSStyleSheet(); }
+SPECIALIZE_TYPE_TRAITS_END()
 
-#endif
+#endif // CSSStyleSheet_h
index 5d9b9bb..ae5aa73 100644 (file)
@@ -55,10 +55,6 @@ public:
     virtual bool isXSLStyleSheet() const { return false; }
 };
 
-#define STYLE_SHEET_TYPE_CASTS(ToClassName) \
-    template<typename T> inline ToClassName* to##ToClassName(const RefPtr<T>& styleSheet) { return to##ToClassName(styleSheet.get()); } \
-    TYPE_CASTS_BASE(ToClassName, StyleSheet, styleSheet, styleSheet->is##ToClassName(), styleSheet.is##ToClassName())
+} // namespace WebCore
 
-} // namespace
-
-#endif
+#endif // StyleSheet_h
index e39fc3a..38bd73f 100644 (file)
@@ -4383,7 +4383,7 @@ void Document::popCurrentScript()
 void Document::applyXSLTransform(ProcessingInstruction* pi)
 {
     RefPtr<XSLTProcessor> processor = XSLTProcessor::create();
-    processor->setXSLStyleSheet(static_cast<XSLStyleSheet*>(pi->sheet()));
+    processor->setXSLStyleSheet(downcast<XSLStyleSheet>(pi->sheet()));
     String resultMIMEType;
     String newSource;
     String resultEncoding;
index 7a6dfb9..b200f12 100644 (file)
@@ -409,14 +409,14 @@ static bool styleSheetsUseRemUnits(const Vector<RefPtr<CSSStyleSheet>>& sheets)
 static void filterEnabledNonemptyCSSStyleSheets(Vector<RefPtr<CSSStyleSheet>>& result, const Vector<RefPtr<StyleSheet>>& sheets)
 {
     for (unsigned i = 0; i < sheets.size(); ++i) {
-        if (!sheets[i]->isCSSStyleSheet())
+        if (!is<CSSStyleSheet>(*sheets[i]))
             continue;
-        if (sheets[i]->disabled())
+        CSSStyleSheet& sheet = downcast<CSSStyleSheet>(*sheets[i]);
+        if (sheet.disabled())
             continue;
-        CSSStyleSheet* sheet = toCSSStyleSheet(sheets[i]);
-        if (!sheet->length())
+        if (!sheet.length())
             continue;
-        result.append(sheet);
+        result.append(&sheet);
     }
 }
 
index b37ae84..fea2626 100644 (file)
@@ -222,10 +222,10 @@ void ProcessingInstruction::setXSLStyleSheet(const String& href, const URL& base
 void ProcessingInstruction::parseStyleSheet(const String& sheet)
 {
     if (m_isCSS)
-        toCSSStyleSheet(*m_sheet).contents().parseString(sheet);
+        downcast<CSSStyleSheet>(*m_sheet).contents().parseString(sheet);
 #if ENABLE(XSLT)
     else if (m_isXSL)
-        static_cast<XSLStyleSheet*>(m_sheet.get())->parseString(sheet);
+        downcast<XSLStyleSheet>(*m_sheet).parseString(sheet);
 #endif
 
     if (m_cachedSheet)
@@ -235,10 +235,10 @@ void ProcessingInstruction::parseStyleSheet(const String& sheet)
     m_loading = false;
 
     if (m_isCSS)
-        toCSSStyleSheet(*m_sheet).contents().checkLoaded();
+        downcast<CSSStyleSheet>(*m_sheet).contents().checkLoaded();
 #if ENABLE(XSLT)
     else if (m_isXSL)
-        static_cast<XSLStyleSheet*>(m_sheet.get())->checkLoaded();
+        downcast<XSLStyleSheet>(*m_sheet).checkLoaded();
 #endif
 }
 
index 9e5687d..c53e7c5 100644 (file)
@@ -684,8 +684,8 @@ void InspectorCSSAgent::getAllStyleSheets(ErrorString&, RefPtr<Inspector::Protoc
         StyleSheetList& list = (*it)->styleSheets();
         for (unsigned i = 0; i < list.length(); ++i) {
             StyleSheet& styleSheet = *list.item(i);
-            if (styleSheet.isCSSStyleSheet())
-                collectStyleSheets(&toCSSStyleSheet(styleSheet), styleInfos.get());
+            if (is<CSSStyleSheet>(styleSheet))
+                collectStyleSheets(&downcast<CSSStyleSheet>(styleSheet), styleInfos.get());
         }
     }
 }
index 0e0043e..57fcf5b 100644 (file)
@@ -32,6 +32,7 @@
 #include <libxslt/transform.h>
 
 #include <wtf/PassRefPtr.h>
+#include <wtf/TypeCasts.h>
 
 namespace WebCore {
 
@@ -97,11 +98,11 @@ public:
     virtual URL baseURL() const override { return m_finalURL; }
     virtual bool isLoading() const override;
 
-    virtual bool isXSLStyleSheet() const override { return true; }
-
 private:
     XSLStyleSheet(Node* parentNode, const String& originalURL, const URL& finalURL, bool embedded);
     XSLStyleSheet(XSLImportRule* parentImport, const String& originalURL, const URL& finalURL);
+
+    virtual bool isXSLStyleSheet() const override { return true; }
     
     Node* m_ownerNode;
     String m_originalURL;
@@ -121,6 +122,10 @@ private:
 
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::XSLStyleSheet)
+    static bool isType(const WebCore::StyleSheet& styleSheet) { return styleSheet.isXSLStyleSheet(); }
+SPECIALIZE_TYPE_TRAITS_END()
+
 #endif // ENABLE(XSLT)
 
 #endif // XSLStyleSheet_h