Bug 1298588 part 2, gecko piece. Pass through an nsPresContext to the PerDocumentStyleData constructor. r=bholley

This commit is contained in:
Boris Zbarsky 2017-01-04 14:52:26 -05:00
parent d6ee8eb8a9
commit a3a6e58c68
3 changed files with 56 additions and 23 deletions

View File

@ -50,7 +50,7 @@ SERVO_BINDING_FUNC(Servo_StyleSheet_HasRules, bool,
RawServoStyleSheetBorrowed sheet)
SERVO_BINDING_FUNC(Servo_StyleSheet_GetRules, ServoCssRulesStrong,
RawServoStyleSheetBorrowed sheet)
SERVO_BINDING_FUNC(Servo_StyleSet_Init, RawServoStyleSetOwned)
SERVO_BINDING_FUNC(Servo_StyleSet_Init, RawServoStyleSetOwned, RawGeckoPresContextBorrowed pres_context)
SERVO_BINDING_FUNC(Servo_StyleSet_Drop, void, RawServoStyleSetOwned set)
SERVO_BINDING_FUNC(Servo_StyleSet_AppendStyleSheet, void,
RawServoStyleSetBorrowed set, RawServoStyleSheetBorrowed sheet, bool flush)

View File

@ -27,6 +27,7 @@ class StyleChildrenIterator;
class nsCSSValue;
class nsIDocument;
class nsINode;
class nsPresContext;
using mozilla::dom::StyleChildrenIterator;
using mozilla::ServoElementSnapshot;
@ -34,6 +35,7 @@ using mozilla::ServoElementSnapshot;
typedef nsINode RawGeckoNode;
typedef mozilla::dom::Element RawGeckoElement;
typedef nsIDocument RawGeckoDocument;
typedef nsPresContext RawGeckoPresContext;
// We have these helper types so that we can directly generate
// things like &T or Borrowed<T> on the Rust side in the function, providing
@ -100,6 +102,7 @@ DECL_BORROWED_MUT_REF_TYPE_FOR(StyleChildrenIterator)
DECL_BORROWED_MUT_REF_TYPE_FOR(ServoElementSnapshot)
DECL_BORROWED_REF_TYPE_FOR(nsCSSValue)
DECL_BORROWED_MUT_REF_TYPE_FOR(nsCSSValue)
DECL_BORROWED_REF_TYPE_FOR(RawGeckoPresContext)
#undef DECL_ARC_REF_TYPE_FOR
#undef DECL_OWNED_REF_TYPE_FOR

View File

@ -23,7 +23,6 @@ using namespace mozilla::dom;
ServoStyleSet::ServoStyleSet()
: mPresContext(nullptr)
, mRawSet(Servo_StyleSet_Init())
, mBatching(0)
{
}
@ -32,6 +31,23 @@ void
ServoStyleSet::Init(nsPresContext* aPresContext)
{
mPresContext = aPresContext;
mRawSet.reset(Servo_StyleSet_Init(aPresContext));
// Now that we have an mRawSet, go ahead and notify about whatever stylesheets
// we have so far.
for (auto& sheetArray : mSheets) {
for (auto& sheet : sheetArray) {
// There's no guarantee this will create a list on the servo side whose
// ordering matches the list that would have been created had all those
// sheets been appended/prepended/etc after we had mRawSet. But hopefully
// that's OK (e.g. because servo doesn't care about the relative ordering
// of sheets from different cascade levels in the list?).
Servo_StyleSet_AppendStyleSheet(mRawSet.get(), sheet->RawSheet(), false);
}
}
// No need to Servo_StyleSet_FlushStyleSheets because we just created the
// mRawSet, so there was nothing to flush.
}
void
@ -274,8 +290,10 @@ ServoStyleSet::AppendStyleSheet(SheetType aType,
mSheets[aType].RemoveElement(aSheet);
mSheets[aType].AppendElement(aSheet);
// Maintain a mirrored list of sheets on the servo side.
Servo_StyleSet_AppendStyleSheet(mRawSet.get(), aSheet->RawSheet(), !mBatching);
if (mRawSet) {
// Maintain a mirrored list of sheets on the servo side.
Servo_StyleSet_AppendStyleSheet(mRawSet.get(), aSheet->RawSheet(), !mBatching);
}
return NS_OK;
}
@ -291,8 +309,10 @@ ServoStyleSet::PrependStyleSheet(SheetType aType,
mSheets[aType].RemoveElement(aSheet);
mSheets[aType].InsertElementAt(0, aSheet);
// Maintain a mirrored list of sheets on the servo side.
Servo_StyleSet_PrependStyleSheet(mRawSet.get(), aSheet->RawSheet(), !mBatching);
if (mRawSet) {
// Maintain a mirrored list of sheets on the servo side.
Servo_StyleSet_PrependStyleSheet(mRawSet.get(), aSheet->RawSheet(), !mBatching);
}
return NS_OK;
}
@ -307,8 +327,10 @@ ServoStyleSet::RemoveStyleSheet(SheetType aType,
mSheets[aType].RemoveElement(aSheet);
// Maintain a mirrored list of sheets on the servo side.
Servo_StyleSet_RemoveStyleSheet(mRawSet.get(), aSheet->RawSheet(), !mBatching);
if (mRawSet) {
// Maintain a mirrored list of sheets on the servo side.
Servo_StyleSet_RemoveStyleSheet(mRawSet.get(), aSheet->RawSheet(), !mBatching);
}
return NS_OK;
}
@ -322,15 +344,19 @@ ServoStyleSet::ReplaceSheets(SheetType aType,
// to express. If the need ever arises, we can easily make this more efficent,
// probably by aligning the representations better between engines.
for (ServoStyleSheet* sheet : mSheets[aType]) {
Servo_StyleSet_RemoveStyleSheet(mRawSet.get(), sheet->RawSheet(), false);
if (mRawSet) {
for (ServoStyleSheet* sheet : mSheets[aType]) {
Servo_StyleSet_RemoveStyleSheet(mRawSet.get(), sheet->RawSheet(), false);
}
}
mSheets[aType].Clear();
mSheets[aType].AppendElements(aNewSheets);
for (ServoStyleSheet* sheet : mSheets[aType]) {
Servo_StyleSet_AppendStyleSheet(mRawSet.get(), sheet->RawSheet(), false);
if (mRawSet) {
for (ServoStyleSheet* sheet : mSheets[aType]) {
Servo_StyleSet_AppendStyleSheet(mRawSet.get(), sheet->RawSheet(), false);
}
}
if (!mBatching) {
@ -357,9 +383,11 @@ ServoStyleSet::InsertStyleSheetBefore(SheetType aType,
mSheets[aType].InsertElementAt(idx, aNewSheet);
// Maintain a mirrored list of sheets on the servo side.
Servo_StyleSet_InsertStyleSheetBefore(mRawSet.get(), aNewSheet->RawSheet(),
aReferenceSheet->RawSheet(), !mBatching);
if (mRawSet) {
// Maintain a mirrored list of sheets on the servo side.
Servo_StyleSet_InsertStyleSheetBefore(mRawSet.get(), aNewSheet->RawSheet(),
aReferenceSheet->RawSheet(), !mBatching);
}
return NS_OK;
}
@ -397,14 +425,16 @@ ServoStyleSet::AddDocStyleSheet(ServoStyleSheet* aSheet,
aDocument->FindDocStyleSheetInsertionPoint(mSheets[SheetType::Doc], aSheet);
mSheets[SheetType::Doc].InsertElementAt(index, aSheet);
// Maintain a mirrored list of sheets on the servo side.
ServoStyleSheet* followingSheet =
mSheets[SheetType::Doc].SafeElementAt(index + 1);
if (followingSheet) {
Servo_StyleSet_InsertStyleSheetBefore(mRawSet.get(), aSheet->RawSheet(),
followingSheet->RawSheet(), !mBatching);
} else {
Servo_StyleSet_AppendStyleSheet(mRawSet.get(), aSheet->RawSheet(), !mBatching);
if (mRawSet) {
// Maintain a mirrored list of sheets on the servo side.
ServoStyleSheet* followingSheet =
mSheets[SheetType::Doc].SafeElementAt(index + 1);
if (followingSheet) {
Servo_StyleSet_InsertStyleSheetBefore(mRawSet.get(), aSheet->RawSheet(),
followingSheet->RawSheet(), !mBatching);
} else {
Servo_StyleSet_AppendStyleSheet(mRawSet.get(), aSheet->RawSheet(), !mBatching);
}
}
return NS_OK;