Kill StyleBase.
authorandreas.kling@nokia.com <andreas.kling@nokia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 31 Oct 2011 14:13:14 +0000 (14:13 +0000)
committerandreas.kling@nokia.com <andreas.kling@nokia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 31 Oct 2011 14:13:14 +0000 (14:13 +0000)
https://bugs.webkit.org/show_bug.cgi?id=71218

Reviewed by Antti Koivisto.

Remove the StyleBase class and make all subclasses stand alone. CSSRule and StyleSheet
now inherit from RefCounted<T> instead, and XSLImportRule doesn't even need that,
so StyleBase is replaced by nothing.

* css/StyleBase.cpp:
* css/StyleBase.h:

    Removed.

* css/CSSRule.cpp:
* css/CSSRule.h:
(WebCore::CSSRule::~CSSRule):
(WebCore::CSSRule::useStrictParsing):
(WebCore::CSSRule::setParentStyleSheet):
(WebCore::CSSRule::setParentRule):
(WebCore::CSSRule::parentStyleSheet):
(WebCore::CSSRule::parentRule):
(WebCore::CSSRule::baseURL):
(WebCore::CSSRule::CSSRule):

    CSSRule now inherits directly from RefCounted, and has either a CSSRule or a
    CSSStyleSheet as its parent. Made these getters/setters inline since they are
    trivial now.

* CMakeLists.txt:
* GNUmakefile.list.am:
* WebCore.gypi:
* WebCore.pro:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:

    Purge StyleBase.* from the build systems.

* bindings/js/JSDOMBinding.h:
(WebCore::root):

    New root() functions for CSSRule and StyleSheet.

* bindings/js/JSNodeCustom.h:

    Remove StyleBase.h include.

* css/CSSStyleSheet.h:
(WebCore::CSSStyleSheet::parentStyleSheet):

    Added CSS-specific parentStyleSheet() so we don't have to cast it to a
    CSSStyleSheet* at the call sites.

* css/StyleSheet.cpp:
(WebCore::StyleSheet::StyleSheet):
(WebCore::StyleSheet::parentStyleSheet):
(WebCore::StyleSheet::baseURL):
* css/StyleSheet.h:
(WebCore::StyleSheet::parentRule):
(WebCore::StyleSheet::setParentRule):
(WebCore::StyleSheet::isCSSStyleSheet):
(WebCore::StyleSheet::isXSLStyleSheet):

    StyleSheet now inherits directly from RefCounted and always has a parent CSSRule
    though it can be null. parentStyleSheet() returns that rule's parent style sheet.
    Moved the relevant guts from StyleBase down here.

* loader/cache/CachedStyleSheetClient.h:

    Remove unnecessary WTF_MAKE_FAST_ALLOCATED, we get it from CachedResourceClient.

* xml/XSLImportRule.cpp:
(WebCore::XSLImportRule::XSLImportRule):
(WebCore::XSLImportRule::~XSLImportRule):
(WebCore::XSLImportRule::parentStyleSheet):
(WebCore::XSLImportRule::setXSLStyleSheet):
(WebCore::XSLImportRule::loadSheet):
* xml/XSLImportRule.h:
(WebCore::XSLImportRule::create):
(WebCore::XSLImportRule::setParentStyleSheet):

    Remove inheritance from StyleBase, and have create() return a PassOwnPtr instead.
    This is fine, since XSLStyleSheet is the only object that ever manages these rules.

* svg/SVGFontFaceElement.cpp:
(WebCore::SVGFontFaceElement::insertedIntoDocument):
* css/CSSStyleSheet.cpp:
(WebCore::CSSStyleSheet::~CSSStyleSheet):
(WebCore::CSSStyleSheet::ownerRule):
(WebCore::CSSStyleSheet::deleteRule):
(WebCore::CSSStyleSheet::checkLoaded):
(WebCore::CSSStyleSheet::document):
(WebCore::CSSStyleSheet::styleSheetChanged):
* css/CSSImportRule.cpp:
(WebCore::CSSImportRule::~CSSImportRule):
(WebCore::CSSImportRule::setCSSStyleSheet):
(WebCore::CSSImportRule::insertedIntoParent):
* css/CSSMediaRule.cpp:
(WebCore::CSSMediaRule::CSSMediaRule):
(WebCore::CSSMediaRule::~CSSMediaRule):
(WebCore::CSSMediaRule::append):
(WebCore::CSSMediaRule::insertRule):
(WebCore::CSSMediaRule::deleteRule):
* css/CSSRegionStyleRule.cpp:
(WebCore::CSSRegionStyleRule::CSSRegionStyleRule):
(WebCore::CSSRegionStyleRule::~CSSRegionStyleRule):
* css/CSSRuleList.cpp:
(WebCore::CSSRuleList::deleteRule):
* css/CSSStyleDeclaration.h:
* css/WebKitCSSKeyframesRule.cpp:
(WebCore::WebKitCSSKeyframesRule::~WebKitCSSKeyframesRule):
(WebCore::WebKitCSSKeyframesRule::setName):
(WebCore::WebKitCSSKeyframesRule::append):
* dom/ProcessingInstruction.cpp:
(WebCore::ProcessingInstruction::parseStyleSheet):
* inspector/InspectorCSSAgent.cpp:
(WebCore::InspectorCSSAgent::parentStyleSheet):
* xml/XSLStyleSheet.h:
* xml/XSLStyleSheetLibxslt.cpp:
(WebCore::XSLStyleSheet::XSLStyleSheet):
(WebCore::XSLStyleSheet::~XSLStyleSheet):
(WebCore::XSLStyleSheet::checkLoaded):
(WebCore::XSLStyleSheet::loadChildSheet):
* xml/XSLStyleSheetQt.cpp:
(WebCore::XSLStyleSheet::~XSLStyleSheet):

    Use the new, more explicit, parenting functions of StyleSheet.

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

32 files changed:
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.list.am
Source/WebCore/WebCore.gypi
Source/WebCore/WebCore.pro
Source/WebCore/WebCore.vcproj/WebCore.vcproj
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/JSDOMBinding.h
Source/WebCore/bindings/js/JSNodeCustom.h
Source/WebCore/css/CSSImportRule.cpp
Source/WebCore/css/CSSMediaRule.cpp
Source/WebCore/css/CSSRegionStyleRule.cpp
Source/WebCore/css/CSSRule.cpp
Source/WebCore/css/CSSRule.h
Source/WebCore/css/CSSRuleList.cpp
Source/WebCore/css/CSSStyleDeclaration.h
Source/WebCore/css/CSSStyleSheet.cpp
Source/WebCore/css/CSSStyleSheet.h
Source/WebCore/css/StyleBase.cpp [deleted file]
Source/WebCore/css/StyleBase.h [deleted file]
Source/WebCore/css/StyleSheet.cpp
Source/WebCore/css/StyleSheet.h
Source/WebCore/css/WebKitCSSKeyframesRule.cpp
Source/WebCore/dom/ProcessingInstruction.cpp
Source/WebCore/inspector/InspectorCSSAgent.cpp
Source/WebCore/loader/cache/CachedStyleSheetClient.h
Source/WebCore/svg/SVGFontFaceElement.cpp
Source/WebCore/xml/XSLImportRule.cpp
Source/WebCore/xml/XSLImportRule.h
Source/WebCore/xml/XSLStyleSheet.h
Source/WebCore/xml/XSLStyleSheetLibxslt.cpp
Source/WebCore/xml/XSLStyleSheetQt.cpp

index 013f948..593e493 100644 (file)
@@ -493,7 +493,6 @@ SET(WebCore_SOURCES
     css/RGBColor.cpp
     css/SelectorChecker.cpp
     css/ShadowValue.cpp
-    css/StyleBase.cpp
     css/StyleMedia.cpp
     css/StyleSheet.cpp
     css/StyleSheetList.cpp
index d7ae954..39f53d5 100644 (file)
@@ -1,3 +1,133 @@
+2011-10-31  Andreas Kling  <kling@webkit.org>
+
+        Kill StyleBase.
+        https://bugs.webkit.org/show_bug.cgi?id=71218
+
+        Reviewed by Antti Koivisto.
+
+        Remove the StyleBase class and make all subclasses stand alone. CSSRule and StyleSheet
+        now inherit from RefCounted<T> instead, and XSLImportRule doesn't even need that,
+        so StyleBase is replaced by nothing.
+
+        * css/StyleBase.cpp:
+        * css/StyleBase.h:
+
+            Removed.
+
+        * css/CSSRule.cpp:
+        * css/CSSRule.h:
+        (WebCore::CSSRule::~CSSRule):
+        (WebCore::CSSRule::useStrictParsing):
+        (WebCore::CSSRule::setParentStyleSheet):
+        (WebCore::CSSRule::setParentRule):
+        (WebCore::CSSRule::parentStyleSheet):
+        (WebCore::CSSRule::parentRule):
+        (WebCore::CSSRule::baseURL):
+        (WebCore::CSSRule::CSSRule):
+
+            CSSRule now inherits directly from RefCounted, and has either a CSSRule or a
+            CSSStyleSheet as its parent. Made these getters/setters inline since they are
+            trivial now.
+
+        * CMakeLists.txt:
+        * GNUmakefile.list.am:
+        * WebCore.gypi:
+        * WebCore.pro:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.xcodeproj/project.pbxproj:
+
+            Purge StyleBase.* from the build systems.
+
+        * bindings/js/JSDOMBinding.h:
+        (WebCore::root):
+
+            New root() functions for CSSRule and StyleSheet.
+
+        * bindings/js/JSNodeCustom.h:
+
+            Remove StyleBase.h include.
+
+        * css/CSSStyleSheet.h:
+        (WebCore::CSSStyleSheet::parentStyleSheet):
+
+            Added CSS-specific parentStyleSheet() so we don't have to cast it to a
+            CSSStyleSheet* at the call sites.
+
+        * css/StyleSheet.cpp:
+        (WebCore::StyleSheet::StyleSheet):
+        (WebCore::StyleSheet::parentStyleSheet):
+        (WebCore::StyleSheet::baseURL):
+        * css/StyleSheet.h:
+        (WebCore::StyleSheet::parentRule):
+        (WebCore::StyleSheet::setParentRule):
+        (WebCore::StyleSheet::isCSSStyleSheet):
+        (WebCore::StyleSheet::isXSLStyleSheet):
+
+            StyleSheet now inherits directly from RefCounted and always has a parent CSSRule
+            though it can be null. parentStyleSheet() returns that rule's parent style sheet.
+            Moved the relevant guts from StyleBase down here.
+
+        * loader/cache/CachedStyleSheetClient.h:
+
+            Remove unnecessary WTF_MAKE_FAST_ALLOCATED, we get it from CachedResourceClient.
+
+        * xml/XSLImportRule.cpp:
+        (WebCore::XSLImportRule::XSLImportRule):
+        (WebCore::XSLImportRule::~XSLImportRule):
+        (WebCore::XSLImportRule::parentStyleSheet):
+        (WebCore::XSLImportRule::setXSLStyleSheet):
+        (WebCore::XSLImportRule::loadSheet):
+        * xml/XSLImportRule.h:
+        (WebCore::XSLImportRule::create):
+        (WebCore::XSLImportRule::setParentStyleSheet):
+
+            Remove inheritance from StyleBase, and have create() return a PassOwnPtr instead.
+            This is fine, since XSLStyleSheet is the only object that ever manages these rules.
+
+        * svg/SVGFontFaceElement.cpp:
+        (WebCore::SVGFontFaceElement::insertedIntoDocument):
+        * css/CSSStyleSheet.cpp:
+        (WebCore::CSSStyleSheet::~CSSStyleSheet):
+        (WebCore::CSSStyleSheet::ownerRule):
+        (WebCore::CSSStyleSheet::deleteRule):
+        (WebCore::CSSStyleSheet::checkLoaded):
+        (WebCore::CSSStyleSheet::document):
+        (WebCore::CSSStyleSheet::styleSheetChanged):
+        * css/CSSImportRule.cpp:
+        (WebCore::CSSImportRule::~CSSImportRule):
+        (WebCore::CSSImportRule::setCSSStyleSheet):
+        (WebCore::CSSImportRule::insertedIntoParent):
+        * css/CSSMediaRule.cpp:
+        (WebCore::CSSMediaRule::CSSMediaRule):
+        (WebCore::CSSMediaRule::~CSSMediaRule):
+        (WebCore::CSSMediaRule::append):
+        (WebCore::CSSMediaRule::insertRule):
+        (WebCore::CSSMediaRule::deleteRule):
+        * css/CSSRegionStyleRule.cpp:
+        (WebCore::CSSRegionStyleRule::CSSRegionStyleRule):
+        (WebCore::CSSRegionStyleRule::~CSSRegionStyleRule):
+        * css/CSSRuleList.cpp:
+        (WebCore::CSSRuleList::deleteRule):
+        * css/CSSStyleDeclaration.h:
+        * css/WebKitCSSKeyframesRule.cpp:
+        (WebCore::WebKitCSSKeyframesRule::~WebKitCSSKeyframesRule):
+        (WebCore::WebKitCSSKeyframesRule::setName):
+        (WebCore::WebKitCSSKeyframesRule::append):
+        * dom/ProcessingInstruction.cpp:
+        (WebCore::ProcessingInstruction::parseStyleSheet):
+        * inspector/InspectorCSSAgent.cpp:
+        (WebCore::InspectorCSSAgent::parentStyleSheet):
+        * xml/XSLStyleSheet.h:
+        * xml/XSLStyleSheetLibxslt.cpp:
+        (WebCore::XSLStyleSheet::XSLStyleSheet):
+        (WebCore::XSLStyleSheet::~XSLStyleSheet):
+        (WebCore::XSLStyleSheet::checkLoaded):
+        (WebCore::XSLStyleSheet::loadChildSheet):
+        * xml/XSLStyleSheetQt.cpp:
+        (WebCore::XSLStyleSheet::~XSLStyleSheet):
+
+            Use the new, more explicit, parenting functions of StyleSheet.
+
 2011-10-31  Nikolas Zimmermann  <nzimmermann@rim.com>
 
         CSS 2.1 failure: background-intrinsic-*
index ba3a297..5dac732 100644 (file)
@@ -1091,8 +1091,6 @@ webcore_sources += \
        Source/WebCore/css/SelectorChecker.h \
        Source/WebCore/css/ShadowValue.cpp \
        Source/WebCore/css/ShadowValue.h \
-       Source/WebCore/css/StyleBase.cpp \
-       Source/WebCore/css/StyleBase.h \
        Source/WebCore/css/StyleMedia.cpp \
        Source/WebCore/css/StyleMedia.h \
        Source/WebCore/css/StyleSheet.cpp \
index f91fcdd..1d671fc 100644 (file)
             'css/CSSValueList.h',
             'css/CSSWrapShapes.h',
             'css/Pair.h',
-            'css/StyleBase.h',
             'css/WebKitCSSFilterValue.h',
             'css/WebKitCSSTransformValue.h',
             'editing/ApplyBlockElementCommand.h',
             'css/SelectorChecker.h',
             'css/ShadowValue.cpp',
             'css/ShadowValue.h',
-            'css/StyleBase.cpp',
             'css/StyleMedia.cpp',
             'css/StyleMedia.h',
             'css/StyleSheet.cpp',
index e3b8ec7..ca027fd 100644 (file)
@@ -447,7 +447,6 @@ SOURCES += \
     css/RGBColor.cpp \
     css/SelectorChecker.cpp \
     css/ShadowValue.cpp \
-    css/StyleBase.cpp \
     css/StyleMedia.cpp \
     css/StyleSheet.cpp \
     css/StyleSheetList.cpp \
@@ -1527,7 +1526,6 @@ HEADERS += \
     css/RGBColor.h \
     css/SelectorChecker.h \
     css/ShadowValue.h \
-    css/StyleBase.h \
     css/StyleMedia.h \
     css/StyleSheet.h \
     css/StyleSheetList.h \
index cfa1767..2d3bd57 100755 (executable)
                                >
                        </File>
                        <File
-                               RelativePath="..\css\StyleBase.cpp"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\css\StyleBase.h"
-                               >
-                       </File>
-                       <File
                                RelativePath="..\css\StyleMedia.cpp"
                                >
                        </File>
index 17703b2..6f28195 100644 (file)
                A80E6E100A19911C007FB8C5 /* CSSStyleDeclaration.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A80E6E0E0A19911C007FB8C5 /* CSSStyleDeclaration.cpp */; };
                A80E734E0A199C77007FB8C5 /* CSSNamespace.h in Headers */ = {isa = PBXBuildFile; fileRef = A80E73470A199C77007FB8C5 /* CSSNamespace.h */; };
                A80E734F0A199C77007FB8C5 /* CSSSelector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A80E73480A199C77007FB8C5 /* CSSSelector.cpp */; };
-               A80E73500A199C77007FB8C5 /* StyleBase.h in Headers */ = {isa = PBXBuildFile; fileRef = A80E73490A199C77007FB8C5 /* StyleBase.h */; settings = {ATTRIBUTES = (Private, ); }; };
                A80E73520A199C77007FB8C5 /* CSSSelector.h in Headers */ = {isa = PBXBuildFile; fileRef = A80E734B0A199C77007FB8C5 /* CSSSelector.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               A80E73530A199C77007FB8C5 /* StyleBase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A80E734C0A199C77007FB8C5 /* StyleBase.cpp */; };
                A80E7A170A19C3D6007FB8C5 /* JSHTMLMetaElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A80E7A150A19C3D6007FB8C5 /* JSHTMLMetaElement.cpp */; };
                A80E7A180A19C3D6007FB8C5 /* JSHTMLMetaElement.h in Headers */ = {isa = PBXBuildFile; fileRef = A80E7A160A19C3D6007FB8C5 /* JSHTMLMetaElement.h */; };
                A80E7B0C0A19D606007FB8C5 /* JSHTMLTitleElement.h in Headers */ = {isa = PBXBuildFile; fileRef = A80E7B020A19D606007FB8C5 /* JSHTMLTitleElement.h */; };
                A80E6E0E0A19911C007FB8C5 /* CSSStyleDeclaration.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = CSSStyleDeclaration.cpp; sourceTree = "<group>"; };
                A80E73470A199C77007FB8C5 /* CSSNamespace.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = CSSNamespace.h; sourceTree = "<group>"; };
                A80E73480A199C77007FB8C5 /* CSSSelector.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = CSSSelector.cpp; sourceTree = "<group>"; };
-               A80E73490A199C77007FB8C5 /* StyleBase.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = StyleBase.h; sourceTree = "<group>"; };
                A80E734B0A199C77007FB8C5 /* CSSSelector.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = CSSSelector.h; sourceTree = "<group>"; };
-               A80E734C0A199C77007FB8C5 /* StyleBase.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = StyleBase.cpp; sourceTree = "<group>"; };
                A80E79960A19BD21007FB8C5 /* Rect.idl */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = Rect.idl; sourceTree = "<group>"; };
                A80E79FC0A19C307007FB8C5 /* HTMLMetaElement.idl */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = HTMLMetaElement.idl; sourceTree = "<group>"; };
                A80E7A150A19C3D6007FB8C5 /* JSHTMLMetaElement.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSHTMLMetaElement.cpp; sourceTree = "<group>"; };
                                E44B4BB2141650D7002B1D8B /* SelectorChecker.h */,
                                A80E6CCA0A1989CA007FB8C5 /* ShadowValue.cpp */,
                                A80E6CBE0A1989CA007FB8C5 /* ShadowValue.h */,
-                               A80E734C0A199C77007FB8C5 /* StyleBase.cpp */,
-                               A80E73490A199C77007FB8C5 /* StyleBase.h */,
                                0FF5026E102BA9660066F39A /* StyleMedia.cpp */,
                                0FF5026F102BA96A0066F39A /* StyleMedia.h */,
                                0FF50270102BA96A0066F39A /* StyleMedia.idl */,
                                9B6C41531344949000085B62 /* StringWithDirection.h in Headers */,
                                849F77760EFEC6200090849D /* StrokeStyleApplier.h in Headers */,
                                BC5EB6A30E81DC4F00B25965 /* StyleBackgroundData.h in Headers */,
-                               A80E73500A199C77007FB8C5 /* StyleBase.h in Headers */,
                                BC5EB67B0E81D3BE00B25965 /* StyleBoxData.h in Headers */,
                                BCEF444D0E674628001C1287 /* StyleCachedImage.h in Headers */,
                                BC5EB67F0E81D4A700B25965 /* StyleDashboardRegion.h in Headers */,
                                B2AFFC960D00A5DF0030074D /* StringMac.mm in Sources */,
                                B23540F20D00782E002382FA /* StringTruncator.cpp in Sources */,
                                BC5EB6A20E81DC4F00B25965 /* StyleBackgroundData.cpp in Sources */,
-                               A80E73530A199C77007FB8C5 /* StyleBase.cpp in Sources */,
                                BC5EB67D0E81D42000B25965 /* StyleBoxData.cpp in Sources */,
                                BCEF447A0E6747D0001C1287 /* StyleCachedImage.cpp in Sources */,
                                A8C4A7FE09D563270003AC8D /* StyledElement.cpp in Sources */,
index acf9487..61909e0 100644 (file)
@@ -30,7 +30,6 @@
 #include "Document.h"
 #include "Element.h"
 #include "MediaList.h"
-#include "StyleBase.h"
 #include <heap/Weak.h>
 #include <runtime/FunctionPrototype.h>
 #include <runtime/Lookup.h>
@@ -184,14 +183,24 @@ enum ParameterMissingPolicy {
         return node;
     }
 
-    inline void* root(StyleBase* styleBase)
+    inline void* root(StyleSheet*);
+
+    inline void* root(CSSRule* rule)
     {
-        while (styleBase->parent())
-            styleBase = styleBase->parent();
+        if (rule->parentRule())
+            return root(rule->parentRule());
+        if (rule->parentStyleSheet())
+            return root(rule->parentStyleSheet());
+        return rule;
+    }
 
-        if (Node* node = styleBase->node())
-            return root(node);
-        return styleBase;
+    inline void* root(StyleSheet* styleSheet)
+    {
+        if (styleSheet->parentRule())
+            return root(styleSheet->parentRule());
+        if (styleSheet->ownerNode())
+            return root(styleSheet->ownerNode());
+        return styleSheet;
     }
 
     inline void* root(CSSStyleDeclaration* style)
index 54c1a77..7688eea 100644 (file)
@@ -27,7 +27,6 @@
 #define JSNodeCustom_h
 
 #include "JSDOMBinding.h"
-#include "StyleBase.h"
 #include <wtf/AlwaysInline.h>
 
 namespace WebCore {
index 061486b..fd51fc5 100644 (file)
@@ -49,7 +49,7 @@ CSSImportRule::~CSSImportRule()
     if (m_lstMedia)
         m_lstMedia->setParentStyleSheet(0);
     if (m_styleSheet)
-        m_styleSheet->setParent(0);
+        m_styleSheet->setParentRule(0);
     if (m_cachedSheet)
         m_cachedSheet->removeClient(this);
 }
@@ -57,7 +57,7 @@ CSSImportRule::~CSSImportRule()
 void CSSImportRule::setCSSStyleSheet(const String& href, const KURL& baseURL, const String& charset, const CachedCSSStyleSheet* sheet)
 {
     if (m_styleSheet)
-        m_styleSheet->setParent(0);
+        m_styleSheet->setParentRule(0);
     m_styleSheet = CSSStyleSheet::create(this, href, baseURL, charset);
 
     bool crossOriginCSS = false;
@@ -126,12 +126,12 @@ void CSSImportRule::insertedIntoParent()
 
     // Check for a cycle in our import chain.  If we encounter a stylesheet
     // in our parent chain with the same URL, then just bail.
-    StyleBase* root = this;
-    for (StyleBase* curr = parent(); curr; curr = curr->parent()) {
+    CSSStyleSheet* rootSheet = parentSheet;
+    for (CSSStyleSheet* sheet = parentSheet; sheet; sheet = sheet->parentStyleSheet()) {
         // FIXME: This is wrong if the finalURL was updated via document::updateBaseURL.
-        if (curr->isCSSStyleSheet() && absHref == static_cast<CSSStyleSheet*>(curr)->finalURL().string())
+        if (absHref == sheet->finalURL().string())
             return;
-        root = curr;
+        rootSheet = sheet;
     }
 
     ResourceRequest request(parentSheet->document()->completeURL(absHref));
@@ -143,7 +143,7 @@ void CSSImportRule::insertedIntoParent()
         // if the import rule is issued dynamically, the sheet may be
         // removed from the pending sheet count, so let the doc know
         // the sheet being imported is pending.
-        if (parentSheet && parentSheet->loadCompleted() && root == parentSheet)
+        if (parentSheet && parentSheet->loadCompleted() && rootSheet == parentSheet)
             parentSheet->startLoadingDynamicSheet();
         m_loading = true;
         m_cachedSheet->addClient(this);
index 9da5c79..6fd1e18 100644 (file)
@@ -36,7 +36,7 @@ CSSMediaRule::CSSMediaRule(CSSStyleSheet* parent, PassRefPtr<MediaList> media, P
     m_lstMedia->setParentStyleSheet(parent);
     int length = m_lstCSSRules->length();
     for (int i = 0; i < length; i++)
-        m_lstCSSRules->item(i)->setParent(this);
+        m_lstCSSRules->item(i)->setParentRule(this);
 }
 
 CSSMediaRule::~CSSMediaRule()
@@ -46,7 +46,7 @@ CSSMediaRule::~CSSMediaRule()
 
     int length = m_lstCSSRules->length();
     for (int i = 0; i < length; i++)
-        m_lstCSSRules->item(i)->setParent(0);
+        m_lstCSSRules->item(i)->setParentRule(0);
 }
 
 unsigned CSSMediaRule::append(CSSRule* rule)
@@ -54,7 +54,7 @@ unsigned CSSMediaRule::append(CSSRule* rule)
     if (!rule)
         return 0;
 
-    rule->setParent(this);
+    rule->setParentRule(this);
     return m_lstCSSRules->insertRule(rule, m_lstCSSRules->length());
 }
 
@@ -86,11 +86,11 @@ unsigned CSSMediaRule::insertRule(const String& rule, unsigned index, ExceptionC
         return 0;
     }
 
-    newRule->setParent(this);
+    newRule->setParentRule(this);
     unsigned returnedIndex = m_lstCSSRules->insertRule(newRule.get(), index);
 
-    if (stylesheet())
-        stylesheet()->styleSheetChanged();
+    if (CSSStyleSheet* styleSheet = parentStyleSheet())
+        styleSheet->styleSheetChanged();
 
     return returnedIndex;
 }
@@ -106,8 +106,8 @@ void CSSMediaRule::deleteRule(unsigned index, ExceptionCode& ec)
 
     m_lstCSSRules->deleteRule(index);
 
-    if (stylesheet())
-        stylesheet()->styleSheetChanged();
+    if (CSSStyleSheet* styleSheet = parentStyleSheet())
+        styleSheet->styleSheetChanged();
 }
 
 String CSSMediaRule::cssText() const
index 2bdd5e7..36b818c 100644 (file)
@@ -40,7 +40,7 @@ CSSRegionStyleRule::CSSRegionStyleRule(CSSStyleSheet* parent, Vector<OwnPtr<CSSP
     , m_ruleList(rules)
 {
     for (unsigned index = 0; index < m_ruleList->length(); ++index)
-        m_ruleList->item(index)->setParent(this);
+        m_ruleList->item(index)->setParentRule(this);
 
     m_selectorList.adoptSelectorVector(*selectors);
 }
@@ -48,7 +48,7 @@ CSSRegionStyleRule::CSSRegionStyleRule(CSSStyleSheet* parent, Vector<OwnPtr<CSSP
 CSSRegionStyleRule::~CSSRegionStyleRule()
 {
     for (unsigned index = 0; index < m_ruleList->length(); ++index)
-        m_ruleList->item(index)->setParent(0);
+        m_ruleList->item(index)->setParentRule(0);
 }
 
 String CSSRegionStyleRule::cssText() const
index 43d8eac..915cc35 100644 (file)
 
 namespace WebCore {
 
-CSSStyleSheet* CSSRule::parentStyleSheet() const
-{
-    StyleBase* curr = parent();
-    while (curr && !curr->isCSSStyleSheet())
-        curr = curr->parent();
-    return curr ? static_cast<CSSStyleSheet*>(curr) : 0;
-}
-
-CSSRule* CSSRule::parentRule() const
-{
-    return (parent() && parent()->isRule()) ? static_cast<CSSRule*>(parent()) : 0;
-}
-
 void CSSRule::setCssText(const String& /*cssText*/, ExceptionCode& /*ec*/)
 {
     notImplemented();
index 039384a..508566e 100644 (file)
@@ -2,6 +2,7 @@
  * (C) 1999-2003 Lars Knoll (knoll@kde.org)
  * (C) 2002-2003 Dirk Mueller (mueller@kde.org)
  * Copyright (C) 2002, 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2011 Andreas Kling (kling@webkit.org)
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -30,8 +31,10 @@ namespace WebCore {
 
 typedef int ExceptionCode;
 
-class CSSRule : public StyleBase {
+class CSSRule : public RefCounted<CSSRule> {
 public:
+    virtual ~CSSRule() { }
+
     // FIXME: Change name to Type.
     enum CSSRuleType {
         UNKNOWN_RULE,
@@ -59,8 +62,35 @@ public:
     virtual bool isRegionStyleRule() const { return false; }
     virtual bool isImportRule() const { return false; }
 
-    CSSStyleSheet* parentStyleSheet() const;
-    CSSRule* parentRule() const;
+    bool useStrictParsing() const
+    {
+        if (parentRule())
+            return parentRule()->useStrictParsing();
+        if (parentStyleSheet())
+            return parentStyleSheet()->useStrictParsing();
+        return true;
+    }
+
+    void setParentStyleSheet(CSSStyleSheet* styleSheet)
+    {
+        m_parentIsRule = false;
+        m_parentStyleSheet = styleSheet;
+    }
+
+    void setParentRule(CSSRule* rule)
+    {
+        m_parentIsRule = true;
+        m_parentRule = rule;
+    }
+
+    CSSStyleSheet* parentStyleSheet() const
+    {
+        if (m_parentIsRule)
+            return m_parentRule ? m_parentRule->parentStyleSheet() : 0;
+        return m_parentStyleSheet;
+    }
+
+    CSSRule* parentRule() const { return m_parentIsRule ? m_parentRule : 0; }
 
     virtual String cssText() const = 0;
     void setCssText(const String&, ExceptionCode&);
@@ -69,14 +99,26 @@ public:
 
     virtual void insertedIntoParent() { }
 
+    KURL baseURL() const
+    {
+        if (CSSStyleSheet* parentSheet = parentStyleSheet())
+            return parentSheet->baseURL();
+        return KURL();
+    }
+
 protected:
     CSSRule(CSSStyleSheet* parent)
-        : StyleBase(parent)
+        : m_parentIsRule(false)
+        , m_parentStyleSheet(parent)
     {
     }
 
 private:
-    virtual bool isRule() const { return true; }
+    bool m_parentIsRule;
+    union {
+        CSSRule* m_parentRule;
+        CSSStyleSheet* m_parentStyleSheet;
+    };
 };
 
 } // namespace WebCore
index 7839369..a8a9dee 100644 (file)
@@ -71,7 +71,8 @@ void CSSRuleList::deleteRule(unsigned index)
     if (index >= m_lstCSSRules.size())
         return;
 
-    m_lstCSSRules[index]->setParent(0);
+    // FIXME: Orphaning should be the caller's responsibility.
+    m_lstCSSRules[index]->setParentRule(0);
     m_lstCSSRules.remove(index);
 }
 
index 556d10e..9db84cc 100644 (file)
@@ -22,7 +22,6 @@
 #define CSSStyleDeclaration_h
 
 #include "CSSRule.h"
-#include "StyleBase.h"
 #include <wtf/Forward.h>
 
 namespace WebCore {
index 57b3396..002fcbb 100644 (file)
@@ -79,8 +79,8 @@ CSSStyleSheet::~CSSStyleSheet()
     // is still observable from JavaScript. This matches the behavior of .parentNode for nodes, but
     // it's not ideal because it makes the CSSOM's behavior depend on the timing of garbage collection.
     for (unsigned i = 0; i < length(); ++i) {
-        ASSERT(item(i)->parent() == this);
-        item(i)->setParent(0);
+        ASSERT(item(i)->parentStyleSheet() == this);
+        item(i)->setParentStyleSheet(0);
     }
 }
 
@@ -98,7 +98,7 @@ void CSSStyleSheet::remove(unsigned index)
 
 CSSRule *CSSStyleSheet::ownerRule() const
 {
-    return (parent() && parent()->isRule()) ? static_cast<CSSRule*>(parent()) : 0;
+    return parentRule();
 }
 
 unsigned CSSStyleSheet::insertRule(const String& rule, unsigned index, ExceptionCode& ec)
@@ -172,7 +172,7 @@ void CSSStyleSheet::deleteRule(unsigned index, ExceptionCode& ec)
     }
 
     ec = 0;
-    item(index)->setParent(0);
+    item(index)->setParentStyleSheet(0);
     m_children.remove(index);
     styleSheetChanged();
 }
@@ -236,8 +236,8 @@ void CSSStyleSheet::checkLoaded()
     // ScriptableDocumentParser::executeScriptsWaitingForStylesheets().
     // See <rdar://problem/6622300>.
     RefPtr<CSSStyleSheet> protector(this);
-    if (parent())
-        parent()->checkLoaded();
+    if (CSSStyleSheet* styleSheet = parentStyleSheet())
+        styleSheet->checkLoaded();
     m_loadCompleted = ownerNode() ? ownerNode()->sheetLoaded() : true;
 }
 
@@ -249,34 +249,24 @@ void CSSStyleSheet::startLoadingDynamicSheet()
 
 Document* CSSStyleSheet::document()
 {
-    StyleBase* styleObject = this;
-    while (styleObject) {
-        if (styleObject->isCSSStyleSheet()) {
-            Node* ownerNode = static_cast<CSSStyleSheet*>(styleObject)->ownerNode();
-            if (ownerNode)
-                return ownerNode->document();
-        }
-        if (styleObject->isRule())
-            styleObject = static_cast<CSSRule*>(styleObject)->parentStyleSheet();
-        else
-            styleObject = styleObject->parent();
+    for (CSSStyleSheet* sheet = this; sheet; sheet = sheet->parentStyleSheet()) {
+        if (Node* ownerNode = sheet->ownerNode())
+            return ownerNode->document();
     }
-
     return 0;
 }
 
 void CSSStyleSheet::styleSheetChanged()
 {
-    StyleBase* root = this;
-    while (StyleBase* parent = root->parent())
-        root = parent;
-    Document* documentToUpdate = root->isCSSStyleSheet() ? static_cast<CSSStyleSheet*>(root)->document() : 0;
+    CSSStyleSheet* rootSheet = this;
+    while (CSSStyleSheet* parent = rootSheet->parentStyleSheet())
+        rootSheet = parent;
 
     /* FIXME: We don't need to do everything updateStyleSelector does,
      * basically we just need to recreate the document's selector with the
      * already existing style sheets.
      */
-    if (documentToUpdate)
+    if (Document* documentToUpdate = rootSheet->document())
         documentToUpdate->styleSelectorChanged(DeferRecalcStyle);
 }
 
index 36785ae..aa86cc9 100644 (file)
@@ -63,6 +63,13 @@ public:
 
     virtual ~CSSStyleSheet();
 
+    CSSStyleSheet* parentStyleSheet() const
+    {
+        StyleSheet* parentSheet = StyleSheet::parentStyleSheet();
+        ASSERT(!parentSheet || parentSheet->isCSSStyleSheet());
+        return static_cast<CSSStyleSheet*>(parentSheet);
+    }
+
     CSSRule* ownerRule() const;
     PassRefPtr<CSSRuleList> cssRules(bool omitCharsetRules = false);
     unsigned insertRule(const String& rule, unsigned index, ExceptionCode&);
diff --git a/Source/WebCore/css/StyleBase.cpp b/Source/WebCore/css/StyleBase.cpp
deleted file mode 100644 (file)
index 83e9059..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (C) 1999-2003 Lars Knoll (knoll@kde.org)
- *               1999 Waldo Bastian (bastian@kde.org)
- *               2001 Andreas Schlapbach (schlpbch@iam.unibe.ch)
- *               2001-2003 Dirk Mueller (mueller@kde.org)
- * Copyright (C) 2002, 2006, 2008 Apple Inc. All rights reserved.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB.  If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-#include "config.h"
-#include "StyleBase.h"
-
-#include "CSSMutableStyleDeclaration.h"
-#include "Document.h"
-#include "Node.h"
-#include "StyleSheet.h"
-
-namespace WebCore {
-
-void StyleBase::checkLoaded()
-{
-    if (parent())
-        parent()->checkLoaded();
-}
-
-Node* StyleBase::node()
-{
-    if (isStyleSheet())
-        return static_cast<StyleSheet*>(this)->ownerNode();
-
-    return 0;
-}
-
-StyleSheet* StyleBase::stylesheet()
-{
-    StyleBase *b = this;
-    while (b && !b->isStyleSheet())
-        b = b->parent();
-    return static_cast<StyleSheet*>(b);
-}
-
-KURL StyleBase::baseURL() const
-{
-    // Try to find the style sheet. If found look for its URL.
-    // If it has none, get the URL from the parent sheet or the parent node.
-
-    StyleSheet* sheet = const_cast<StyleBase*>(this)->stylesheet();
-    if (!sheet)
-        return KURL();
-    if (!sheet->finalURL().isNull())
-        return sheet->finalURL();
-    if (sheet->parent())
-        return sheet->parent()->baseURL();
-    if (!sheet->ownerNode())
-        return KURL();
-    return sheet->ownerNode()->document()->baseURL();
-}
-
-}
diff --git a/Source/WebCore/css/StyleBase.h b/Source/WebCore/css/StyleBase.h
deleted file mode 100644 (file)
index 91fc680..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (C) 1999-2003 Lars Knoll (knoll@kde.org)
- * Copyright (C) 1999 Waldo Bastian (bastian@kde.org)
- * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmial.com)
- * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB.  If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#ifndef StyleBase_h
-#define StyleBase_h
-
-#include <wtf/Forward.h>
-#include <wtf/RefCounted.h>
-
-namespace WebCore {
-
-    class KURL;
-    class Node;
-    class StyleSheet;
-
-    // Base class for most CSS DOM objects.
-
-    // FIXME: We don't need these to all share one base class.
-    // Refactor so they don't any more.
-
-    class StyleBase : public RefCounted<StyleBase> {
-    public:
-        virtual ~StyleBase() { }
-
-        StyleBase* parent() const { return m_parent; }
-        void setParent(StyleBase* parent) { m_parent = parent; }
-
-        // returns the url of the style sheet this object belongs to
-        KURL baseURL() const;
-
-        virtual bool isRule() const { return false; }
-
-        virtual bool isStyleSheet() const { return false; }
-        virtual bool isCSSStyleSheet() const { return false; }
-        virtual bool isXSLStyleSheet() const { return false; }
-
-        virtual void checkLoaded();
-
-        bool useStrictParsing() const { return !m_parent || m_parent->useStrictParsing(); }
-
-        StyleSheet* stylesheet();
-        Node* node();
-
-    protected:
-        StyleBase(StyleBase* parent)
-            : m_parent(parent)
-        {
-        }
-
-    private:
-        StyleBase* m_parent;
-    };
-}
-
-#endif
index d40d36c..64ca1f6 100644 (file)
 
 #include "CSSRule.h"
 #include "CSSStyleSheet.h"
+#include "Document.h"
 #include "MediaList.h"
 #include "Node.h"
 
 namespace WebCore {
 
 StyleSheet::StyleSheet(Node* parentNode, const String& originalURL, const KURL& finalURL)
-    : StyleBase(0)
+    : m_parentRule(0)
     , m_parentNode(parentNode)
     , m_originalURL(originalURL)
     , m_finalURL(finalURL)
@@ -36,8 +37,8 @@ StyleSheet::StyleSheet(Node* parentNode, const String& originalURL, const KURL&
 {
 }
 
-StyleSheet::StyleSheet(StyleBase* owner, const String& originalURL, const KURL& finalURL)
-    : StyleBase(owner)
+StyleSheet::StyleSheet(CSSRule* parentRule, const String& originalURL, const KURL& finalURL)
+    : m_parentRule(parentRule)
     , m_parentNode(0)
     , m_originalURL(originalURL)
     , m_finalURL(finalURL)
@@ -53,10 +54,8 @@ StyleSheet::~StyleSheet()
 
 StyleSheet* StyleSheet::parentStyleSheet() const
 {
-    if (!parent())
-        return 0;
-    ASSERT(parent()->isRule());
-    return static_cast<CSSRule*>(parent())->parentStyleSheet();
+    ASSERT(isCSSStyleSheet());
+    return m_parentRule ? m_parentRule->parentStyleSheet() : 0;
 }
 
 void StyleSheet::setMedia(PassRefPtr<MediaList> media)
@@ -71,6 +70,17 @@ void StyleSheet::setMedia(PassRefPtr<MediaList> media)
     m_media->setParentStyleSheet(static_cast<CSSStyleSheet*>(this));
 }
 
+KURL StyleSheet::baseURL() const
+{
+    if (!m_finalURL.isNull())
+        return m_finalURL;
+    if (StyleSheet* parentSheet = parentStyleSheet())
+        return parentSheet->baseURL();
+    if (!m_parentNode)
+        return KURL();
+    return m_parentNode->document()->baseURL();
+}
+
 KURL StyleSheet::completeURL(const String& url) const
 {
     // Always return a null URL when passed a null string.
index 40908d0..cfe27fd 100644 (file)
 
 #include "KURLHash.h"
 #include "PlatformString.h"
-#include "StyleBase.h"
 #include <wtf/ListHashSet.h>
+#include <wtf/RefCounted.h>
 
 namespace WebCore {
 
+class CSSRule;
 class CachedCSSStyleSheet;
 class MediaList;
 class Node;
 
-class StyleSheet : public StyleBase {
+class StyleSheet : public RefCounted<StyleSheet> {
 public:
     virtual ~StyleSheet();
 
@@ -41,7 +42,11 @@ public:
 
     Node* ownerNode() const { return m_parentNode; }
     void clearOwnerNode() { m_parentNode = 0; }
-    StyleSheet *parentStyleSheet() const;
+
+    StyleSheet* parentStyleSheet() const;
+
+    CSSRule* parentRule() const { return m_parentRule; }
+    void setParentRule(CSSRule* rule) { m_parentRule = rule; }
 
     // Note that href is the URL that started the redirect chain that led to
     // this style sheet. This property probably isn't useful for much except
@@ -63,13 +68,17 @@ public:
     virtual KURL completeURL(const String& url) const;
     virtual bool parseString(const String&, bool strict = true) = 0;
 
+    virtual bool isCSSStyleSheet() const { return false; }
+    virtual bool isXSLStyleSheet() const { return false; }
+
+    KURL baseURL() const;
+
 protected:
     StyleSheet(Node* ownerNode, const String& href, const KURL& finalURL);
-    StyleSheet(StyleBase* owner, const String& href, const KURL& finalURL);
+    StyleSheet(CSSRule* parentRule, const String& href, const KURL& finalURL);
 
 private:
-    virtual bool isStyleSheet() const { return true; }
-
+    CSSRule* m_parentRule;
     Node* m_parentNode;
     String m_originalURL;
     KURL m_finalURL;
index 7d76e17..77d33b9 100644 (file)
@@ -46,7 +46,7 @@ WebKitCSSKeyframesRule::~WebKitCSSKeyframesRule()
         WebKitCSSKeyframeRule* rule = item(i);
         if (CSSMutableStyleDeclaration* style = rule->style())
             style->setParentRule(0);
-        rule->setParent(0);
+        rule->setParentRule(0);
     }
 }
 
@@ -61,8 +61,8 @@ void WebKitCSSKeyframesRule::setName(const String& name)
 
     // Since the name is used in the keyframe map list in CSSStyleSelector, we need
     // to recompute the style sheet to get the updated name.
-    if (stylesheet())
-        stylesheet()->styleSheetChanged();
+    if (CSSStyleSheet* styleSheet = parentStyleSheet())
+        styleSheet->styleSheetChanged();
 }
 
 unsigned WebKitCSSKeyframesRule::length() const
@@ -90,7 +90,7 @@ void WebKitCSSKeyframesRule::append(WebKitCSSKeyframeRule* rule)
         return;
 
     m_lstCSSRules->append(rule);
-    rule->setParent(this);
+    rule->setParentRule(this);
 
     if (CSSMutableStyleDeclaration* style = rule->style())
         style->setParentRule(this);
index 5db0071..5b0a2f8 100644 (file)
@@ -242,7 +242,13 @@ void ProcessingInstruction::parseStyleSheet(const String& sheet)
     m_cachedSheet = 0;
 
     m_loading = false;
-    m_sheet->checkLoaded();
+
+    if (m_isCSS)
+        static_cast<CSSStyleSheet*>(m_sheet.get())->checkLoaded();
+#if ENABLE(XSLT)
+    else if (m_isXSL)
+        static_cast<XSLStyleSheet*>(m_sheet.get())->checkLoaded();
+#endif
 }
 
 void ProcessingInstruction::setCSSStyleSheet(PassRefPtr<CSSStyleSheet> sheet)
index 0836cd3..8eb374a 100644 (file)
@@ -173,11 +173,7 @@ CSSStyleSheet* InspectorCSSAgent::parentStyleSheet(CSSRule* rule)
     if (!rule)
         return 0;
 
-    StyleSheet* styleSheet = rule->stylesheet();
-    if (styleSheet && styleSheet->isCSSStyleSheet())
-        return static_cast<CSSStyleSheet*>(styleSheet);
-
-    return 0;
+    return rule->parentStyleSheet();
 }
 
 // static
index 6fda613..1a29258 100644 (file)
 #define CachedStyleSheetClient_h
 
 #include "CachedResourceClient.h"
-#include <wtf/FastAllocBase.h>
 #include <wtf/Forward.h>
 
 namespace WebCore {
 class CachedCSSStyleSheet;
 
 class CachedStyleSheetClient : public CachedResourceClient {
-    WTF_MAKE_FAST_ALLOCATED;
 public:
     virtual ~CachedStyleSheetClient() { }
     static CachedResourceClientType expectedType() { return StyleSheetType; }
index da2ceb2..8885ad8 100644 (file)
@@ -321,7 +321,7 @@ void SVGFontFaceElement::insertedIntoDocument()
 {
     SVGElement::insertedIntoDocument();
     document()->mappedElementSheet()->append(m_fontFaceRule);
-    m_fontFaceRule->setParent(document()->mappedElementSheet());
+    m_fontFaceRule->setParentStyleSheet(document()->mappedElementSheet());
     rebuildFontFace();
 }
 
index d23f182..596c409 100644 (file)
@@ -32,7 +32,7 @@
 namespace WebCore {
 
 XSLImportRule::XSLImportRule(XSLStyleSheet* parent, const String& href)
-    : StyleBase(parent)
+    : m_parentStyleSheet(parent)
     , m_strHref(href)
     , m_cachedSheet(0)
     , m_loading(false)
@@ -42,7 +42,7 @@ XSLImportRule::XSLImportRule(XSLStyleSheet* parent, const String& href)
 XSLImportRule::~XSLImportRule()
 {
     if (m_styleSheet)
-        m_styleSheet->setParent(0);
+        m_styleSheet->setParentStyleSheet(0);
     
     if (m_cachedSheet)
         m_cachedSheet->removeClient(this);
@@ -50,13 +50,13 @@ XSLImportRule::~XSLImportRule()
 
 XSLStyleSheet* XSLImportRule::parentStyleSheet() const
 {
-    return (parent() && parent()->isXSLStyleSheet()) ? static_cast<XSLStyleSheet*>(parent()) : 0;
+    return m_parentStyleSheet;
 }
 
 void XSLImportRule::setXSLStyleSheet(const String& href, const KURL& baseURL, const String& sheet)
 {
     if (m_styleSheet)
-        m_styleSheet->setParent(0);
+        m_styleSheet->setParentStyleSheet(0);
 
     m_styleSheet = XSLStyleSheet::create(this, href, baseURL);
 
@@ -79,12 +79,16 @@ bool XSLImportRule::isLoading()
 void XSLImportRule::loadSheet()
 {
     CachedResourceLoader* cachedResourceLoader = 0;
-    StyleBase* root = this;
-    StyleBase* parent;
-    while ((parent = root->parent()))
-        root = parent;
-    if (root->isXSLStyleSheet())
-        cachedResourceLoader = static_cast<XSLStyleSheet*>(root)->cachedResourceLoader();
+
+    XSLStyleSheet* rootSheet = parentStyleSheet();
+
+    if (rootSheet) {
+        while (XSLStyleSheet* parentSheet = rootSheet->parentStyleSheet())
+            rootSheet = parentSheet;
+    }
+
+    if (rootSheet)
+        cachedResourceLoader = rootSheet->cachedResourceLoader();
     
     String absHref = m_strHref;
     XSLStyleSheet* parentSheet = parentStyleSheet();
@@ -94,8 +98,8 @@ void XSLImportRule::loadSheet()
     
     // Check for a cycle in our import chain.  If we encounter a stylesheet
     // in our parent chain with the same URL, then just bail.
-    for (parent = this->parent(); parent; parent = parent->parent()) {
-        if (parent->isXSLStyleSheet() && absHref == static_cast<XSLStyleSheet*>(parent)->finalURL().string())
+    for (XSLStyleSheet* parentSheet = parentStyleSheet(); parentSheet; parentSheet = parentSheet->parentStyleSheet()) {
+        if (absHref == parentSheet->finalURL().string())
             return;
     }
     
index 8d94e4c..bc826b5 100644 (file)
 
 #include "CachedResourceHandle.h"
 #include "CachedStyleSheetClient.h"
-#include "StyleBase.h"
 #include "XSLStyleSheet.h"
+#include <wtf/PassOwnPtr.h>
 
 namespace WebCore {
 
 class CachedXSLStyleSheet;
 
-class XSLImportRule : public StyleBase, private CachedStyleSheetClient {
+class XSLImportRule : private CachedStyleSheetClient {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    static PassRefPtr<XSLImportRule> create(XSLStyleSheet* parentSheet, const String& href)
+    static PassOwnPtr<XSLImportRule> create(XSLStyleSheet* parentSheet, const String& href)
     {
-        return adoptRef(new XSLImportRule(parentSheet, href));
+        return adoptPtr(new XSLImportRule(parentSheet, href));
     }
 
     virtual ~XSLImportRule();
@@ -48,6 +48,7 @@ public:
     XSLStyleSheet* styleSheet() const { return m_styleSheet.get(); }
 
     XSLStyleSheet* parentStyleSheet() const;
+    void setParentStyleSheet(XSLStyleSheet* styleSheet) { m_parentStyleSheet = styleSheet; }
 
     bool isLoading();
     void loadSheet();
@@ -57,6 +58,7 @@ private:
 
     virtual void setXSLStyleSheet(const String& href, const KURL& baseURL, const String& sheet);
     
+    XSLStyleSheet* m_parentStyleSheet;
     String m_strHref;
     RefPtr<XSLStyleSheet> m_styleSheet;
     CachedResourceHandle<CachedXSLStyleSheet> m_cachedSheet;
index 54f5232..3933202 100644 (file)
@@ -102,7 +102,7 @@ private:
     XSLStyleSheet(XSLImportRule* parentImport, const String& originalURL, const KURL& finalURL);
 #endif
 
-    Vector<RefPtr<XSLImportRule> > m_children;
+    Vector<OwnPtr<XSLImportRule> > m_children;
 
     Document* m_ownerDocument;
     bool m_embedded;
index 5680a3e..7521b6d 100644 (file)
@@ -55,12 +55,12 @@ SOFT_LINK(libxslt, xsltLoadStylesheetPI, xsltStylesheetPtr, (xmlDocPtr doc), (do
 namespace WebCore {
 
 XSLStyleSheet::XSLStyleSheet(XSLImportRule* parentRule, const String& originalURL, const KURL& finalURL)
-    : StyleSheet(parentRule, originalURL, finalURL)
+    : StyleSheet(static_cast<Node*>(0), originalURL, finalURL)
     , m_embedded(false)
     , m_processed(false) // Child sheets get marked as processed when the libxslt engine has finally seen them.
     , m_stylesheetDoc(0)
     , m_stylesheetDocTaken(false)
-    , m_parentStyleSheet(0)
+    , m_parentStyleSheet(parentRule ? parentRule->parentStyleSheet() : 0)
 {
 }
 
@@ -80,8 +80,8 @@ XSLStyleSheet::~XSLStyleSheet()
         xmlFreeDoc(m_stylesheetDoc);
 
     for (unsigned i = 0; i < m_children.size(); ++i) {
-        ASSERT(m_children.at(i)->parent() == this);
-        m_children.at(i)->setParent(0);
+        ASSERT(m_children.at(i)->parentStyleSheet() == this);
+        m_children.at(i)->setParentStyleSheet(0);
     }
 }
 
@@ -98,8 +98,8 @@ void XSLStyleSheet::checkLoaded()
 {
     if (isLoading())
         return;
-    if (parent())
-        parent()->checkLoaded();
+    if (XSLStyleSheet* styleSheet = parentStyleSheet())
+        styleSheet->checkLoaded();
     if (ownerNode())
         ownerNode()->sheetLoaded();
 }
@@ -229,9 +229,10 @@ void XSLStyleSheet::loadChildSheets()
 
 void XSLStyleSheet::loadChildSheet(const String& href)
 {
-    RefPtr<XSLImportRule> childRule = XSLImportRule::create(this, href);
-    m_children.append(childRule);
-    childRule->loadSheet();
+    OwnPtr<XSLImportRule> childRule = XSLImportRule::create(this, href);
+    XSLImportRule* c = childRule.get();
+    m_children.append(childRule.release());
+    c->loadSheet();
 }
 
 xsltStylesheetPtr XSLStyleSheet::compileStyleSheet()
index 2ce976b..8a10fd9 100644 (file)
@@ -42,8 +42,8 @@ XSLStyleSheet::XSLStyleSheet(Node* parentNode, const String& originalURL, const
 XSLStyleSheet::~XSLStyleSheet()
 {
     for (unsigned i = 0; i < m_children.size(); ++i) {
-        ASSERT(m_children.at(i)->parent() == this);
-        m_children.at(i)->setParent(0);
+        ASSERT(m_children.at(i)->parentStyleSheet() == this);
+        m_children.at(i)->setParentStyleSheet(0);
     }
 }