Bug 1339629 Part 7: Ensure ServoStyleSets keep sheets informed of the stylesets they are part of. draft
authorBrad Werth <bwerth@mozilla.com>
Tue, 23 May 2017 17:02:51 -0700
changeset 584201 c5d413ace25161ef455f3e9eb8d7c81e3391316e
parent 584200 99c7e529150a679dfb3a8a35ee677773c8083e0c
child 584202 ee30e8bde771c866569858bda0b729aab57fae2e
push id60647
push userbwerth@mozilla.com
push dateThu, 25 May 2017 00:33:14 +0000
bugs1339629
milestone55.0a1
Bug 1339629 Part 7: Ensure ServoStyleSets keep sheets informed of the stylesets they are part of. MozReview-Commit-ID: EH9GO749LlN
layout/style/ServoStyleSet.cpp
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -43,16 +43,21 @@ ServoStyleSet::ServoStyleSet()
   , mAllowResolveStaleStyles(false)
   , mAuthorStyleDisabled(false)
   , mStylistState(StylistState::NotDirty)
 {
 }
 
 ServoStyleSet::~ServoStyleSet()
 {
+  for (auto& sheetArray : mSheets) {
+    for (auto& sheet : sheetArray) {
+      sheet->DropStyleSet(this);
+    }
+  }
 }
 
 void
 ServoStyleSet::Init(nsPresContext* aPresContext)
 {
   mPresContext = aPresContext;
   mRawSet.reset(Servo_StyleSet_Init(aPresContext));
 
@@ -643,18 +648,19 @@ ServoStyleSet::ReplaceSheets(SheetType a
   // Gecko uses a two-dimensional array keyed by sheet type, whereas Servo
   // stores a flattened list. This makes ReplaceSheets a pretty clunky thing
   // to express. If the need ever arises, we can easily make this more efficent,
   // probably by aligning the representations better between engines.
 
   SetStylistStyleSheetsDirty();
 
   // Remove all the existing sheets first.
-  if (mRawSet) {
-    for (const auto& sheet : mSheets[aType]) {
+  for (const auto& sheet : mSheets[aType]) {
+    sheet->DropStyleSet(this);
+    if (mRawSet) {
       Servo_StyleSet_RemoveStyleSheet(mRawSet.get(), UniqueIDForSheet(sheet));
     }
   }
   mSheets[aType].Clear();
 
   // Add in all the new sheets.
   for (auto& sheet : aNewSheets) {
     AppendSheetOfType(aType, sheet);
@@ -1096,45 +1102,49 @@ ServoStyleSet::UpdateStylist()
   }
   mStylistState = StylistState::NotDirty;
 }
 
 void
 ServoStyleSet::PrependSheetOfType(SheetType aType,
                                   ServoStyleSheet* aSheet)
 {
+  aSheet->AddStyleSet(this);
   mSheets[aType].InsertElementAt(0, aSheet);
 }
 
 void
 ServoStyleSet::AppendSheetOfType(SheetType aType,
                                  ServoStyleSheet* aSheet)
 {
+  aSheet->AddStyleSet(this);
   mSheets[aType].AppendElement(aSheet);
 }
 
 void
 ServoStyleSet::InsertSheetOfType(SheetType aType,
                                  ServoStyleSheet* aSheet,
                                  ServoStyleSheet* aBeforeSheet)
 {
   for (uint32_t i = 0; i < mSheets[aType].Length(); ++i) {
     if (mSheets[aType][i] == aBeforeSheet) {
+      aSheet->AddStyleSet(this);
       mSheets[aType].InsertElementAt(i, aSheet);
       return;
     }
   }
 }
 
 void
 ServoStyleSet::RemoveSheetOfType(SheetType aType,
                                  ServoStyleSheet* aSheet)
 {
   for (uint32_t i = 0; i < mSheets[aType].Length(); ++i) {
     if (mSheets[aType][i] == aSheet) {
+      aSheet->DropStyleSet(this);
       mSheets[aType].RemoveElementAt(i);
     }
   }
 }
 
 void
 ServoStyleSet::RunPostTraversalTasks()
 {