Bug 1339629 Part 7: Ensure ServoStyleSets keep sheets informed of the stylesets they are part of.
MozReview-Commit-ID: EH9GO749LlN
--- 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()
{