Correctly fix up the parentage of child sheets when removing the primary nsCSSStyleSheet from an nsCSSStyleSheetInner. (Bug 623351) r=bzbarsky a2.0=blocking
authorL. David Baron <dbaron@dbaron.org>
Fri, 14 Jan 2011 19:57:53 -0800
changeset 60640 3d46204494379ba37443ee54bcf3c9b2d6f8a239
parent 60639 fe3f812af314da1e34eab655acb88326d4716516
child 60641 ee45778d91fa18e9e1c2a03ff8e47906460f2755
push id18054
push userdbaron@mozilla.com
push dateSat, 15 Jan 2011 03:58:42 +0000
treeherdermozilla-central@3d4620449437 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs623351
milestone2.0b10pre
first release with
nightly linux32
3d4620449437 / 4.0b10pre / 20110115030345 / files
nightly linux64
3d4620449437 / 4.0b10pre / 20110115030345 / files
nightly mac
3d4620449437 / 4.0b10pre / 20110115030345 / files
nightly win32
3d4620449437 / 4.0b10pre / 20110115030345 / files
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
Correctly fix up the parentage of child sheets when removing the primary nsCSSStyleSheet from an nsCSSStyleSheetInner. (Bug 623351) r=bzbarsky a2.0=blocking
layout/style/nsCSSStyleSheet.cpp
--- a/layout/style/nsCSSStyleSheet.cpp
+++ b/layout/style/nsCSSStyleSheet.cpp
@@ -828,16 +828,25 @@ CloneRuleInto(nsICSSRule* aRule, void* a
 struct ChildSheetListBuilder {
   nsRefPtr<nsCSSStyleSheet>* sheetSlot;
   nsCSSStyleSheet* parent;
 
   void SetParentLinks(nsCSSStyleSheet* aSheet) {
     aSheet->mParent = parent;
     aSheet->SetOwningDocument(parent->mDocument);
   }
+
+  static void ReparentChildList(nsCSSStyleSheet* aPrimarySheet,
+                                nsCSSStyleSheet* aFirstChild)
+  {
+    for (nsCSSStyleSheet *child = aFirstChild; child; child = child->mNext) {
+      child->mParent = aPrimarySheet;
+      child->SetOwningDocument(aPrimarySheet->mDocument);
+    }
+  }
 };
   
 PRBool
 nsCSSStyleSheet::RebuildChildList(nsICSSRule* aRule, void* aBuilder)
 {
   PRInt32 type = aRule->GetType();
   if (type < nsICSSRule::IMPORT_RULE) {
     // Keep going till we get to the import rules.
@@ -923,16 +932,18 @@ nsCSSStyleSheetInner::RemoveSheet(nsCSSS
     delete this;
     return;
   }
   if (aSheet == mSheets.ElementAt(0)) {
     mSheets.RemoveElementAt(0);
     NS_ASSERTION(mSheets.Length(), "no parents");
     mOrderedRules.EnumerateForwards(SetStyleSheetReference,
                                     mSheets.ElementAt(0));
+
+    ChildSheetListBuilder::ReparentChildList(mSheets[0], mFirstChild);
   }
   else {
     mSheets.RemoveElement(aSheet);
   }
 }
 
 static void
 AddNamespaceRuleToMap(nsICSSRule* aRule, nsXMLNameSpaceMap* aMap)