Title: [97485] trunk/Source/WebCore
Revision
97485
Author
[email protected]
Date
2011-10-14 11:36:31 -0700 (Fri, 14 Oct 2011)

Log Message

CSSStyleSheet should only ever contain CSSRules.
https://bugs.webkit.org/show_bug.cgi?id=70116

Reviewed by Antti Koivisto.

Move child management from the StyleSheet class down into
CSSStyleSheet and XSLStyleSheet. XSLStyleSheet continues to
manage StyleBase objects, while CSSStyleSheet now only contains
CSSRule.

This is enforced at both compile time and runtime with explicit
types and assertions.

* css/CSSRule.h:
(WebCore::CSSRule::isRule):

    Promoted to a public method so we can use it in assertions.

* css/CSSRuleList.h:
(WebCore::CSSRuleList::create):
(WebCore::CSSRuleList::styleSheet):
* css/CSSRuleList.cpp:
(WebCore::CSSRuleList::CSSRuleList):
* bindings/js/JSCSSRuleListCustom.cpp:
(WebCore::JSCSSRuleListOwner::isReachableFromOpaqueRoots):

    Change backing to a CSSStyleSheet instead of a StyleSheet.

* css/CSSRuleList.cpp:
(WebCore::CSSRuleList::item):

    Remove redundant assertions.

* css/CSSStyleSheet.cpp:
(WebCore::CSSStyleSheet::isLoading):
(WebCore::CSSStyleSheet::addSubresourceStyleURLs):
* css/CSSStyleSelector.cpp:
(WebCore::RuleSet::addRulesFromSheet):
* inspector/InspectorCSSAgent.cpp:
(WebCore::InspectorCSSAgent::collectStyleSheets):
* page/PageSerializer.cpp:
(WebCore::PageSerializer::serializeCSSStyleSheet):

    Use more specific CSSRule* since that's what we get from
    CSSStyleSheet::item() now.

* css/StyleSheet.cpp:
(WebCore::StyleSheet::~StyleSheet):
* css/CSSStyleSheet.cpp:
(WebCore::CSSStyleSheet::~CSSStyleSheet):
* xml/XSLStyleSheetLibxslt.cpp:
(WebCore::XSLStyleSheet::~XSLStyleSheet):
* xml/XSLStyleSheetQt.cpp:
(WebCore::XSLStyleSheet::~XSLStyleSheet):

    Orphaning logic from ~StyleSheet() moved to subclass dtors.

* css/StyleSheet.h:
* css/CSSStyleSheet.h:
(WebCore::CSSStyleSheet::length):
(WebCore::CSSStyleSheet::item):
* css/CSSStyleSheet.cpp:
(WebCore::CSSStyleSheet::append):
(WebCore::CSSStyleSheet::insert):
(WebCore::CSSStyleSheet::remove):

    Moved from StyleSheet and changed to only accept CSSRules.

* css/StyleSheet.h:
* xml/XSLStyleSheet.h:
(WebCore::XSLStyleSheet::length):
(WebCore::XSLStyleSheet::item):
(WebCore::XSLStyleSheet::append):
(WebCore::XSLStyleSheet::insert):
(WebCore::XSLStyleSheet::remove):

    Moved from StyleSheet though still uses StyleBase.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (97484 => 97485)


--- trunk/Source/WebCore/ChangeLog	2011-10-14 18:34:41 UTC (rev 97484)
+++ trunk/Source/WebCore/ChangeLog	2011-10-14 18:36:31 UTC (rev 97485)
@@ -1,3 +1,83 @@
+2011-10-14  Andreas Kling  <[email protected]>
+
+        CSSStyleSheet should only ever contain CSSRules.
+        https://bugs.webkit.org/show_bug.cgi?id=70116
+
+        Reviewed by Antti Koivisto.
+
+        Move child management from the StyleSheet class down into
+        CSSStyleSheet and XSLStyleSheet. XSLStyleSheet continues to
+        manage StyleBase objects, while CSSStyleSheet now only contains
+        CSSRule.
+
+        This is enforced at both compile time and runtime with explicit
+        types and assertions.
+
+        * css/CSSRule.h:
+        (WebCore::CSSRule::isRule):
+
+            Promoted to a public method so we can use it in assertions.
+
+        * css/CSSRuleList.h:
+        (WebCore::CSSRuleList::create):
+        (WebCore::CSSRuleList::styleSheet):
+        * css/CSSRuleList.cpp:
+        (WebCore::CSSRuleList::CSSRuleList):
+        * bindings/js/JSCSSRuleListCustom.cpp:
+        (WebCore::JSCSSRuleListOwner::isReachableFromOpaqueRoots):
+
+            Change backing to a CSSStyleSheet instead of a StyleSheet.
+
+        * css/CSSRuleList.cpp:
+        (WebCore::CSSRuleList::item):
+
+            Remove redundant assertions.
+
+        * css/CSSStyleSheet.cpp:
+        (WebCore::CSSStyleSheet::isLoading):
+        (WebCore::CSSStyleSheet::addSubresourceStyleURLs):
+        * css/CSSStyleSelector.cpp:
+        (WebCore::RuleSet::addRulesFromSheet):
+        * inspector/InspectorCSSAgent.cpp:
+        (WebCore::InspectorCSSAgent::collectStyleSheets):
+        * page/PageSerializer.cpp:
+        (WebCore::PageSerializer::serializeCSSStyleSheet):
+
+            Use more specific CSSRule* since that's what we get from
+            CSSStyleSheet::item() now.
+
+        * css/StyleSheet.cpp:
+        (WebCore::StyleSheet::~StyleSheet):
+        * css/CSSStyleSheet.cpp:
+        (WebCore::CSSStyleSheet::~CSSStyleSheet):
+        * xml/XSLStyleSheetLibxslt.cpp:
+        (WebCore::XSLStyleSheet::~XSLStyleSheet):
+        * xml/XSLStyleSheetQt.cpp:
+        (WebCore::XSLStyleSheet::~XSLStyleSheet):
+
+            Orphaning logic from ~StyleSheet() moved to subclass dtors.
+
+        * css/StyleSheet.h:
+        * css/CSSStyleSheet.h:
+        (WebCore::CSSStyleSheet::length):
+        (WebCore::CSSStyleSheet::item):
+        * css/CSSStyleSheet.cpp:
+        (WebCore::CSSStyleSheet::append):
+        (WebCore::CSSStyleSheet::insert):
+        (WebCore::CSSStyleSheet::remove):
+
+            Moved from StyleSheet and changed to only accept CSSRules.
+
+        * css/StyleSheet.h:
+        * xml/XSLStyleSheet.h:
+        (WebCore::XSLStyleSheet::length):
+        (WebCore::XSLStyleSheet::item):
+        (WebCore::XSLStyleSheet::append):
+        (WebCore::XSLStyleSheet::insert):
+        (WebCore::XSLStyleSheet::remove):
+
+            Moved from StyleSheet though still uses StyleBase.
+
 2011-10-14 Yuji Sanachan <[email protected]>
 
         Include dom/ExceptionCode.h instead of Filesystem APIs headers

Modified: trunk/Source/WebCore/bindings/js/JSCSSRuleListCustom.cpp (97484 => 97485)


--- trunk/Source/WebCore/bindings/js/JSCSSRuleListCustom.cpp	2011-10-14 18:34:41 UTC (rev 97484)
+++ trunk/Source/WebCore/bindings/js/JSCSSRuleListCustom.cpp	2011-10-14 18:36:31 UTC (rev 97485)
@@ -28,8 +28,8 @@
 
 #include "CSSRule.h"
 #include "CSSRuleList.h"
+#include "CSSStyleSheet.h"
 #include "JSNode.h"
-#include "StyleSheet.h"
 
 using namespace JSC;
 
@@ -40,7 +40,7 @@
     JSCSSRuleList* jsCSSRuleList = static_cast<JSCSSRuleList*>(handle.get().asCell());
     if (!jsCSSRuleList->hasCustomProperties())
         return false;
-    if (StyleSheet* styleSheet = jsCSSRuleList->impl()->styleSheet())
+    if (CSSStyleSheet* styleSheet = jsCSSRuleList->impl()->styleSheet())
         return visitor.containsOpaqueRoot(root(styleSheet));
     if (CSSRule* cssRule = jsCSSRuleList->impl()->item(0))
         return visitor.containsOpaqueRoot(root(cssRule));

Modified: trunk/Source/WebCore/css/CSSRule.h (97484 => 97485)


--- trunk/Source/WebCore/css/CSSRule.h	2011-10-14 18:34:41 UTC (rev 97484)
+++ trunk/Source/WebCore/css/CSSRule.h	2011-10-14 18:36:31 UTC (rev 97485)
@@ -56,14 +56,13 @@
 
     virtual void addSubresourceStyleURLs(ListHashSet<KURL>&) { }
 
+    virtual bool isRule() const { return true; }
+
 protected:
     CSSRule(CSSStyleSheet* parent)
         : StyleBase(parent)
     {
     }
-
-private:
-    virtual bool isRule() const { return true; }
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/css/CSSRuleList.cpp (97484 => 97485)


--- trunk/Source/WebCore/css/CSSRuleList.cpp	2011-10-14 18:34:41 UTC (rev 97484)
+++ trunk/Source/WebCore/css/CSSRuleList.cpp	2011-10-14 18:36:31 UTC (rev 97485)
@@ -22,10 +22,8 @@
 #include "config.h"
 #include "CSSRuleList.h"
 
-#include "CSSMutableStyleDeclaration.h"
 #include "CSSRule.h"
-#include "StyleSheet.h"
-#include "WebKitCSSKeyframeRule.h"
+#include "CSSStyleSheet.h"
 
 namespace WebCore {
 
@@ -33,15 +31,15 @@
 {
 }
 
-CSSRuleList::CSSRuleList(StyleSheet* styleSheet, bool omitCharsetRules)
+CSSRuleList::CSSRuleList(CSSStyleSheet* styleSheet, bool omitCharsetRules)
     : m_styleSheet(styleSheet)
 {
     if (styleSheet && omitCharsetRules) {
         m_styleSheet = 0;
         for (unsigned i = 0; i < styleSheet->length(); ++i) {
-            StyleBase* style = styleSheet->item(i);
-            if (style->isRule() && !style->isCharsetRule())
-                append(static_cast<CSSRule*>(style));
+            CSSRule* rule = styleSheet->item(i);
+            if (!rule->isCharsetRule())
+                append(static_cast<CSSRule*>(rule));
         }
     }
 }
@@ -57,11 +55,8 @@
 
 CSSRule* CSSRuleList::item(unsigned index)
 {
-    if (m_styleSheet) {
-        StyleBase* rule = m_styleSheet->item(index);
-        ASSERT(!rule || rule->isRule());
-        return static_cast<CSSRule*>(rule);
-    }
+    if (m_styleSheet)
+        return m_styleSheet->item(index);
 
     if (index < m_lstCSSRules.size())
         return m_lstCSSRules[index].get();

Modified: trunk/Source/WebCore/css/CSSRuleList.h (97484 => 97485)


--- trunk/Source/WebCore/css/CSSRuleList.h	2011-10-14 18:34:41 UTC (rev 97484)
+++ trunk/Source/WebCore/css/CSSRuleList.h	2011-10-14 18:36:31 UTC (rev 97485)
@@ -30,11 +30,11 @@
 namespace WebCore {
 
 class CSSRule;
-class StyleSheet;
+class CSSStyleSheet;
 
 class CSSRuleList : public RefCounted<CSSRuleList> {
 public:
-    static PassRefPtr<CSSRuleList> create(StyleSheet* styleSheet, bool omitCharsetRules = false)
+    static PassRefPtr<CSSRuleList> create(CSSStyleSheet* styleSheet, bool omitCharsetRules = false)
     {
         return adoptRef(new CSSRuleList(styleSheet, omitCharsetRules));
     }
@@ -53,13 +53,13 @@
 
     void append(CSSRule*);
 
-    StyleSheet* styleSheet() { return m_styleSheet.get(); }
+    CSSStyleSheet* styleSheet() { return m_styleSheet.get(); }
 
 private:
     CSSRuleList();
-    CSSRuleList(StyleSheet*, bool omitCharsetRules);
+    CSSRuleList(CSSStyleSheet*, bool omitCharsetRules);
 
-    RefPtr<StyleSheet> m_styleSheet;
+    RefPtr<CSSStyleSheet> m_styleSheet;
     Vector<RefPtr<CSSRule> > m_lstCSSRules; // FIXME: Want to eliminate, but used by IE rules() extension and still used by media rules.
 };
 

Modified: trunk/Source/WebCore/css/CSSStyleSelector.cpp (97484 => 97485)


--- trunk/Source/WebCore/css/CSSStyleSelector.cpp	2011-10-14 18:34:41 UTC (rev 97484)
+++ trunk/Source/WebCore/css/CSSStyleSelector.cpp	2011-10-14 18:36:31 UTC (rev 97485)
@@ -1994,16 +1994,16 @@
     int len = sheet->length();
 
     for (int i = 0; i < len; i++) {
-        StyleBase* item = sheet->item(i);
-        if (item->isStyleRule())
-            addStyleRule(static_cast<CSSStyleRule*>(item));
-        else if (item->isImportRule()) {
-            CSSImportRule* import = static_cast<CSSImportRule*>(item);
+        CSSRule* rule = sheet->item(i);
+        if (rule->isStyleRule())
+            addStyleRule(static_cast<CSSStyleRule*>(rule));
+        else if (rule->isImportRule()) {
+            CSSImportRule* import = static_cast<CSSImportRule*>(rule);
             if (!import->media() || medium.eval(import->media(), styleSelector))
                 addRulesFromSheet(import->styleSheet(), medium, styleSelector);
         }
-        else if (item->isMediaRule()) {
-            CSSMediaRule* r = static_cast<CSSMediaRule*>(item);
+        else if (rule->isMediaRule()) {
+            CSSMediaRule* r = static_cast<CSSMediaRule*>(rule);
             CSSRuleList* rules = r->cssRules();
 
             if ((!r->media() || medium.eval(r->media(), styleSelector)) && rules) {
@@ -2023,12 +2023,12 @@
                     }
                 }   // for rules
             }   // if rules
-        } else if (item->isFontFaceRule() && styleSelector) {
+        } else if (rule->isFontFaceRule() && styleSelector) {
             // Add this font face to our set.
-            const CSSFontFaceRule* fontFaceRule = static_cast<CSSFontFaceRule*>(item);
+            const CSSFontFaceRule* fontFaceRule = static_cast<CSSFontFaceRule*>(rule);
             styleSelector->fontSelector()->addFontFaceRule(fontFaceRule);
-        } else if (item->isKeyframesRule())
-            styleSelector->addKeyframeStyle(static_cast<WebKitCSSKeyframesRule*>(item));
+        } else if (rule->isKeyframesRule())
+            styleSelector->addKeyframeStyle(static_cast<WebKitCSSKeyframesRule*>(rule));
     }
     if (m_autoShrinkToFitEnabled)
         shrinkToFit();

Modified: trunk/Source/WebCore/css/CSSStyleSheet.cpp (97484 => 97485)


--- trunk/Source/WebCore/css/CSSStyleSheet.cpp	2011-10-14 18:34:41 UTC (rev 97484)
+++ trunk/Source/WebCore/css/CSSStyleSheet.cpp	2011-10-14 18:36:31 UTC (rev 97485)
@@ -85,8 +85,41 @@
 
 CSSStyleSheet::~CSSStyleSheet()
 {
+    // For style rules outside the document, .parentStyleSheet can become null even if the style rule
+    // 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);
+    }
 }
 
+void CSSStyleSheet::append(PassRefPtr<CSSRule> child)
+{
+    CSSRule* c = child.get();
+    ASSERT(c->isRule());
+    m_children.append(child);
+    c->insertedIntoParent();
+}
+
+void CSSStyleSheet::insert(unsigned index, PassRefPtr<CSSRule> child)
+{
+    CSSRule* c = child.get();
+    ASSERT(c->isRule());
+    if (index >= length())
+        m_children.append(child);
+    else
+        m_children.insert(index, child);
+    c->insertedIntoParent();
+}
+
+void CSSStyleSheet::remove(unsigned index)
+{
+    if (index >= length())
+        return;
+    m_children.remove(index);
+}
+
 CSSRule *CSSStyleSheet::ownerRule() const
 {
     return (parent() && parent()->isRule()) ? static_cast<CSSRule*>(parent()) : 0;
@@ -209,7 +242,7 @@
 {
     unsigned len = length();
     for (unsigned i = 0; i < len; ++i) {
-        StyleBase* rule = item(i);
+        CSSRule* rule = item(i);
         if (rule->isImportRule() && static_cast<CSSImportRule*>(rule)->isLoading())
             return true;
     }
@@ -289,11 +322,7 @@
         CSSStyleSheet* styleSheet = styleSheetQueue.takeFirst();
 
         for (unsigned i = 0; i < styleSheet->length(); ++i) {
-            StyleBase* styleBase = styleSheet->item(i);
-            if (!styleBase->isRule())
-                continue;
-            
-            CSSRule* rule = static_cast<CSSRule*>(styleBase);
+            CSSRule* rule = styleSheet->item(i);
             if (rule->isImportRule()) {
                 if (CSSStyleSheet* ruleStyleSheet = static_cast<CSSImportRule*>(rule)->styleSheet())
                     styleSheetQueue.append(ruleStyleSheet);

Modified: trunk/Source/WebCore/css/CSSStyleSheet.h (97484 => 97485)


--- trunk/Source/WebCore/css/CSSStyleSheet.h	2011-10-14 18:34:41 UTC (rev 97484)
+++ trunk/Source/WebCore/css/CSSStyleSheet.h	2011-10-14 18:36:31 UTC (rev 97485)
@@ -105,6 +105,13 @@
     void setHasSyntacticallyValidCSSHeader(bool b) { m_hasSyntacticallyValidCSSHeader = b; }
     bool hasSyntacticallyValidCSSHeader() const { return m_hasSyntacticallyValidCSSHeader; }
 
+    void append(PassRefPtr<CSSRule>);
+    void insert(unsigned index, PassRefPtr<CSSRule>);
+    void remove(unsigned index);
+
+    unsigned length() const { return m_children.size(); }
+    CSSRule* item(unsigned index) { return index < length() ? m_children.at(index).get() : 0; }
+
 private:
     CSSStyleSheet(Node* ownerNode, const String& originalURL, const KURL& finalURL, const String& charset);
     CSSStyleSheet(CSSStyleSheet* parentSheet, const String& originalURL, const KURL& finalURL, const String& charset);
@@ -113,6 +120,7 @@
     virtual bool isCSSStyleSheet() const { return true; }
     virtual String type() const { return "text/css"; }
 
+    Vector<RefPtr<CSSRule> > m_children;
     OwnPtr<CSSNamespace> m_namespaces;
     String m_charset;
     bool m_loadCompleted : 1;

Modified: trunk/Source/WebCore/css/StyleSheet.cpp (97484 => 97485)


--- trunk/Source/WebCore/css/StyleSheet.cpp	2011-10-14 18:34:41 UTC (rev 97484)
+++ trunk/Source/WebCore/css/StyleSheet.cpp	2011-10-14 18:36:31 UTC (rev 97485)
@@ -56,40 +56,8 @@
 {
     if (m_media)
         m_media->setParent(0);
-
-    // For style rules outside the document, .parentStyleSheet can become null even if the style rule
-    // 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);
-    }
 }
 
-void StyleSheet::append(PassRefPtr<StyleBase> child)
-{
-    StyleBase* c = child.get();
-    m_children.append(child);
-    c->insertedIntoParent();
-}
-
-void StyleSheet::insert(unsigned index, PassRefPtr<StyleBase> child)
-{
-    StyleBase* c = child.get();
-    if (index >= length())
-        m_children.append(child);
-    else
-        m_children.insert(index, child);
-    c->insertedIntoParent();
-}
-
-void StyleSheet::remove(unsigned index)
-{
-    if (index >= length())
-        return;
-    m_children.remove(index);
-}
-
 StyleSheet* StyleSheet::parentStyleSheet() const
 {
     return (parent() && parent()->isStyleSheet()) ? static_cast<StyleSheet*>(parent()) : 0;

Modified: trunk/Source/WebCore/css/StyleSheet.h (97484 => 97485)


--- trunk/Source/WebCore/css/StyleSheet.h	2011-10-14 18:34:41 UTC (rev 97484)
+++ trunk/Source/WebCore/css/StyleSheet.h	2011-10-14 18:36:31 UTC (rev 97485)
@@ -36,13 +36,6 @@
 public:
     virtual ~StyleSheet();
 
-    unsigned length() const { return m_children.size(); }
-    StyleBase* item(unsigned index) { return index < length() ? m_children.at(index).get() : 0; }
-
-    void append(PassRefPtr<StyleBase>);
-    void insert(unsigned index, PassRefPtr<StyleBase>);
-    void remove(unsigned index);
-
     bool disabled() const { return m_disabled; }
     void setDisabled(bool disabled) { m_disabled = disabled; styleSheetChanged(); }
 
@@ -80,7 +73,6 @@
 private:
     virtual bool isStyleSheet() const { return true; }
 
-    Vector<RefPtr<StyleBase> > m_children;
     Node* m_parentNode;
     String m_originalURL;
     KURL m_finalURL;

Modified: trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp (97484 => 97485)


--- trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp	2011-10-14 18:34:41 UTC (rev 97484)
+++ trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp	2011-10-14 18:36:31 UTC (rev 97485)
@@ -490,11 +490,11 @@
     InspectorStyleSheet* inspectorStyleSheet = bindStyleSheet(static_cast<CSSStyleSheet*>(styleSheet));
     result->pushObject(inspectorStyleSheet->buildObjectForStyleSheetInfo());
     for (unsigned i = 0, size = styleSheet->length(); i < size; ++i) {
-        StyleBase* styleBase = styleSheet->item(i);
-        if (styleBase->isImportRule()) {
-            StyleBase* importedStyleSheet = static_cast<CSSImportRule*>(styleBase)->styleSheet();
-            if (importedStyleSheet && importedStyleSheet->isCSSStyleSheet())
-                collectStyleSheets(static_cast<CSSStyleSheet*>(importedStyleSheet), result);
+        CSSRule* rule = styleSheet->item(i);
+        if (rule->isImportRule()) {
+            CSSStyleSheet* importedStyleSheet = static_cast<CSSImportRule*>(rule)->styleSheet();
+            if (importedStyleSheet)
+                collectStyleSheets(importedStyleSheet, result);
         }
     }
 }

Modified: trunk/Source/WebCore/page/PageSerializer.cpp (97484 => 97485)


--- trunk/Source/WebCore/page/PageSerializer.cpp	2011-10-14 18:34:41 UTC (rev 97484)
+++ trunk/Source/WebCore/page/PageSerializer.cpp	2011-10-14 18:36:31 UTC (rev 97485)
@@ -256,25 +256,25 @@
 {
     StringBuilder cssText;
     for (unsigned i = 0; i < styleSheet->length(); ++i) {
-        StyleBase* item = styleSheet->item(i);
-        String itemText = item->cssText();
+        CSSRule* rule = styleSheet->item(i);
+        String itemText = rule->cssText();
         if (!itemText.isEmpty()) {
             cssText.append(itemText);
             if (i < styleSheet->length() - 1)
                 cssText.append("\n\n");
         }
         // Some rules have resources associated with them that we need to retrieve.
-        if (item->isImportRule()) {
-            CSSImportRule* importRule = static_cast<CSSImportRule*>(item);
+        if (rule->isImportRule()) {
+            CSSImportRule* importRule = static_cast<CSSImportRule*>(rule);
             KURL importURL = styleSheet->document()->completeURL(importRule->href());
             if (m_resourceURLs.contains(importURL))
                 continue;
             serializeCSSStyleSheet(importRule->styleSheet(), importURL);
-        } else if (item->isFontFaceRule()) {
+        } else if (rule->isFontFaceRule()) {
             // 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 (item->isStyleRule())
-            retrieveResourcesForCSSRule(static_cast<CSSStyleRule*>(item));
+        } else if (rule->isStyleRule())
+            retrieveResourcesForCSSRule(static_cast<CSSStyleRule*>(rule));
     }
 
     if (url.isValid() && !m_resourceURLs.contains(url)) {

Modified: trunk/Source/WebCore/xml/XSLStyleSheet.h (97484 => 97485)


--- trunk/Source/WebCore/xml/XSLStyleSheet.h	2011-10-14 18:34:41 UTC (rev 97484)
+++ trunk/Source/WebCore/xml/XSLStyleSheet.h	2011-10-14 18:36:31 UTC (rev 97485)
@@ -56,6 +56,9 @@
         return adoptRef(new XSLStyleSheet(parentNode, finalURL.string(), finalURL, true));
     }
 
+    unsigned length() const { return m_children.size(); }
+    StyleBase* item(unsigned index) { return index < length() ? m_children.at(index).get() : 0; }
+
     // Taking an arbitrary node is unsafe, because owner node pointer can become stale.
     // XSLTProcessor ensures that the stylesheet doesn't outlive its parent, in part by not exposing it to _javascript_.
     static PassRefPtr<XSLStyleSheet> createForXSLTProcessor(Node* parentNode, const String& originalURL, const KURL& finalURL)
@@ -97,11 +100,37 @@
     bool processed() const { return m_processed; }
 
 private:
+    void append(PassRefPtr<StyleBase> child)
+    {
+        StyleBase* c = child.get();
+        m_children.append(child);
+        c->insertedIntoParent();
+    }
+
+    void insert(unsigned index, PassRefPtr<StyleBase> child)
+    {
+        StyleBase* c = child.get();
+        if (index >= length())
+            m_children.append(child);
+        else
+            m_children.insert(index, child);
+        c->insertedIntoParent();
+    }
+
+    void remove(unsigned index)
+    {
+        if (index >= length())
+            return;
+        m_children.remove(index);
+    }
+
     XSLStyleSheet(Node* parentNode, const String& originalURL, const KURL& finalURL, bool embedded);
 #if !USE(QXMLQUERY)
     XSLStyleSheet(XSLImportRule* parentImport, const String& originalURL, const KURL& finalURL);
 #endif
 
+    Vector<RefPtr<StyleBase> > m_children;
+
     Document* m_ownerDocument;
     bool m_embedded;
     bool m_processed;

Modified: trunk/Source/WebCore/xml/XSLStyleSheetLibxslt.cpp (97484 => 97485)


--- trunk/Source/WebCore/xml/XSLStyleSheetLibxslt.cpp	2011-10-14 18:34:41 UTC (rev 97484)
+++ trunk/Source/WebCore/xml/XSLStyleSheetLibxslt.cpp	2011-10-14 18:36:31 UTC (rev 97485)
@@ -78,6 +78,11 @@
 {
     if (!m_stylesheetDocTaken)
         xmlFreeDoc(m_stylesheetDoc);
+
+    for (unsigned i = 0; i < length(); ++i) {
+        ASSERT(item(i)->parent() == this);
+        item(i)->setParent(0);
+    }
 }
 
 bool XSLStyleSheet::isLoading()

Modified: trunk/Source/WebCore/xml/XSLStyleSheetQt.cpp (97484 => 97485)


--- trunk/Source/WebCore/xml/XSLStyleSheetQt.cpp	2011-10-14 18:34:41 UTC (rev 97484)
+++ trunk/Source/WebCore/xml/XSLStyleSheetQt.cpp	2011-10-14 18:36:31 UTC (rev 97485)
@@ -40,6 +40,10 @@
 
 XSLStyleSheet::~XSLStyleSheet()
 {
+    for (unsigned i = 0; i < length(); ++i) {
+        ASSERT(item(i)->parent() == this);
+        item(i)->setParent(0);
+    }
 }
 
 bool XSLStyleSheet::isLoading()
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to