Bug 1348481 Part 5: Gecko-side changes to call the regenerate function instead of all the prepend/append/insertBefore functions. draft
authorBrad Werth <bwerth@mozilla.com>
Tue, 25 Apr 2017 15:06:41 -0700
changeset 568280 e7e647e91012fed9c9541043d35c38b6b983b8e7
parent 568279 1ed0f961aae3304f994bda50363d7fd269cad6f5
child 568281 7d72d4d5214dac52586969b107f555b36d902d3b
push id55811
push userbwerth@mozilla.com
push dateTue, 25 Apr 2017 22:15:27 +0000
bugs1348481
milestone55.0a1
Bug 1348481 Part 5: Gecko-side changes to call the regenerate function instead of all the prepend/append/insertBefore functions. MozReview-Commit-ID: CqXBX8aPgjc
layout/style/ServoBindingList.h
layout/style/ServoStyleSet.cpp
--- a/layout/style/ServoBindingList.h
+++ b/layout/style/ServoBindingList.h
@@ -44,25 +44,16 @@ SERVO_BINDING_FUNC(Servo_StyleSheet_Clea
 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, RawGeckoPresContextOwned pres_context)
 SERVO_BINDING_FUNC(Servo_StyleSet_RebuildData, void,
                    RawServoStyleSetBorrowed set)
 SERVO_BINDING_FUNC(Servo_StyleSet_Drop, void, RawServoStyleSetOwned set)
-SERVO_BINDING_FUNC(Servo_StyleSet_AppendStyleSheet, void,
-                   RawServoStyleSetBorrowed set, RawServoStyleSheetBorrowed sheet, bool flush)
-SERVO_BINDING_FUNC(Servo_StyleSet_PrependStyleSheet, void,
-                   RawServoStyleSetBorrowed set, RawServoStyleSheetBorrowed sheet, bool flush)
-SERVO_BINDING_FUNC(Servo_StyleSet_RemoveStyleSheet, void,
-                   RawServoStyleSetBorrowed set, RawServoStyleSheetBorrowed sheet, bool flush)
-SERVO_BINDING_FUNC(Servo_StyleSet_InsertStyleSheetBefore, void,
-                   RawServoStyleSetBorrowed set, RawServoStyleSheetBorrowed sheet,
-                   RawServoStyleSheetBorrowed reference, bool flush)
 SERVO_BINDING_FUNC(Servo_StyleSet_Regenerate, void,
                    RawServoStyleSetBorrowed set, RawGeckoServoStyleSheetListBorrowed sheets)
 SERVO_BINDING_FUNC(Servo_StyleSet_FlushStyleSheets, void, RawServoStyleSetBorrowed set)
 SERVO_BINDING_FUNC(Servo_StyleSet_NoteStyleSheetsChanged, void,
                    RawServoStyleSetBorrowed set, bool author_style_disabled)
 SERVO_BINDING_FUNC(Servo_StyleSet_FillKeyframesForName, bool,
                    RawServoStyleSetBorrowed set,
                    const nsACString* property,
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -46,30 +46,17 @@ ServoStyleSet::Init(nsPresContext* aPres
   mPresContext = aPresContext;
   mRawSet.reset(Servo_StyleSet_Init(aPresContext));
 
   mPresContext->DeviceContext()->InitFontCache();
   gfxPlatformFontList::PlatformFontList()->InitLangService();
 
   // 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?).
-      MOZ_ASSERT(sheet->RawSheet(), "We should only append non-null raw sheets.");
-      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.
+  RegenerateServoStyleSetData();
 }
 
 void
 ServoStyleSet::BeginShutdown()
 {
   nsIDocument* doc = mPresContext->Document();
 
   // It's important to do this before mRawSet is released, since that will cause
@@ -160,17 +147,19 @@ ServoStyleSet::BeginUpdate()
 nsresult
 ServoStyleSet::EndUpdate()
 {
   MOZ_ASSERT(mBatching > 0);
   if (--mBatching > 0) {
     return NS_OK;
   }
 
-  Servo_StyleSet_FlushStyleSheets(mRawSet.get());
+  if (mRawSet) {
+    RegenerateServoStyleSetData();
+  }
   return NS_OK;
 }
 
 already_AddRefed<nsStyleContext>
 ServoStyleSet::ResolveStyleFor(Element* aElement,
                                nsStyleContext* aParentContext,
                                LazyComputeBehavior aMayCompute)
 {
@@ -533,19 +522,18 @@ ServoStyleSet::AppendStyleSheet(SheetTyp
   MOZ_ASSERT(aSheet);
   MOZ_ASSERT(aSheet->IsApplicable());
   MOZ_ASSERT(nsStyleSet::IsCSSSheetType(aType));
 
   MOZ_ASSERT(aSheet->RawSheet(), "Raw sheet should be in place before insertion.");
   mSheets[aType].RemoveElement(aSheet);
   mSheets[aType].AppendElement(aSheet);
 
-  if (mRawSet) {
-    // Maintain a mirrored list of sheets on the servo side.
-    Servo_StyleSet_AppendStyleSheet(mRawSet.get(), aSheet->RawSheet(), !mBatching);
+  if (mRawSet && !mBatching) {
+    RegenerateServoStyleSetData();
   }
 
   return NS_OK;
 }
 
 nsresult
 ServoStyleSet::PrependStyleSheet(SheetType aType,
                                  ServoStyleSheet* aSheet)
@@ -553,68 +541,53 @@ ServoStyleSet::PrependStyleSheet(SheetTy
   MOZ_ASSERT(aSheet);
   MOZ_ASSERT(aSheet->IsApplicable());
   MOZ_ASSERT(nsStyleSet::IsCSSSheetType(aType));
 
   MOZ_ASSERT(aSheet->RawSheet(), "Raw sheet should be in place before insertion.");
   mSheets[aType].RemoveElement(aSheet);
   mSheets[aType].InsertElementAt(0, aSheet);
 
-  if (mRawSet) {
-    // Maintain a mirrored list of sheets on the servo side.
-    Servo_StyleSet_PrependStyleSheet(mRawSet.get(), aSheet->RawSheet(), !mBatching);
+  if (mRawSet && !mBatching) {
+    RegenerateServoStyleSetData();
   }
 
   return NS_OK;
 }
 
 nsresult
 ServoStyleSet::RemoveStyleSheet(SheetType aType,
                                 ServoStyleSheet* aSheet)
 {
   MOZ_ASSERT(aSheet);
   MOZ_ASSERT(nsStyleSet::IsCSSSheetType(aType));
 
   mSheets[aType].RemoveElement(aSheet);
 
-  if (mRawSet) {
-    // Maintain a mirrored list of sheets on the servo side.
-    Servo_StyleSet_RemoveStyleSheet(mRawSet.get(), aSheet->RawSheet(), !mBatching);
+  if (mRawSet && !mBatching) {
+    RegenerateServoStyleSetData();
   }
 
   return NS_OK;
 }
 
 nsresult
 ServoStyleSet::ReplaceSheets(SheetType aType,
                              const nsTArray<RefPtr<ServoStyleSheet>>& aNewSheets)
 {
   // 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.
 
-  if (mRawSet) {
-    for (ServoStyleSheet* sheet : mSheets[aType]) {
-      Servo_StyleSet_RemoveStyleSheet(mRawSet.get(), sheet->RawSheet(), false);
-    }
-  }
-
   mSheets[aType].Clear();
   mSheets[aType].AppendElements(aNewSheets);
 
-  if (mRawSet) {
-    for (ServoStyleSheet* sheet : mSheets[aType]) {
-      MOZ_ASSERT(sheet->RawSheet(), "Raw sheet should be in place before replacement.");
-      Servo_StyleSet_AppendStyleSheet(mRawSet.get(), sheet->RawSheet(), false);
-    }
-  }
-
-  if (!mBatching) {
-    Servo_StyleSet_FlushStyleSheets(mRawSet.get());
+  if (mRawSet && !mBatching) {
+    RegenerateServoStyleSetData();
   }
 
   return NS_OK;
 }
 
 nsresult
 ServoStyleSet::InsertStyleSheetBefore(SheetType aType,
                                       ServoStyleSheet* aNewSheet,
@@ -629,20 +602,18 @@ ServoStyleSet::InsertStyleSheetBefore(Sh
   if (idx == mSheets[aType].NoIndex) {
     return NS_ERROR_INVALID_ARG;
   }
   MOZ_ASSERT(aReferenceSheet->RawSheet(), "Reference sheet should have a raw sheet.");
 
   MOZ_ASSERT(aNewSheet->RawSheet(), "Raw sheet should be in place before insertion.");
   mSheets[aType].InsertElementAt(idx, aNewSheet);
 
-  if (mRawSet) {
-    // Maintain a mirrored list of sheets on the servo side.
-    Servo_StyleSet_InsertStyleSheetBefore(mRawSet.get(), aNewSheet->RawSheet(),
-                                          aReferenceSheet->RawSheet(), !mBatching);
+  if (mRawSet && !mBatching) {
+    RegenerateServoStyleSetData();
   }
 
   return NS_OK;
 }
 
 int32_t
 ServoStyleSet::SheetCount(SheetType aType) const
 {
@@ -676,26 +647,18 @@ ServoStyleSet::AddDocStyleSheet(ServoSty
   nsTArray<RefPtr<ServoStyleSheet>>& sheetsArray = mSheets[SheetType::Doc];
 
   sheetsArray.RemoveElement(aSheet);
 
   size_t index =
     aDocument->FindDocStyleSheetInsertionPoint(sheetsArray, aSheet);
   sheetsArray.InsertElementAt(index, aSheet);
 
-  if (mRawSet) {
-    // Maintain a mirrored list of sheets on the servo side.
-    ServoStyleSheet* followingSheet = sheetsArray.SafeElementAt(index + 1);
-    if (followingSheet) {
-      MOZ_ASSERT(followingSheet->RawSheet(), "Every mSheets element should have a raw sheet");
-      Servo_StyleSet_InsertStyleSheetBefore(mRawSet.get(), aSheet->RawSheet(),
-                                            followingSheet->RawSheet(), !mBatching);
-    } else {
-      Servo_StyleSet_AppendStyleSheet(mRawSet.get(), aSheet->RawSheet(), !mBatching);
-    }
+  if (mRawSet && !mBatching) {
+    RegenerateServoStyleSetData();
   }
 
   return NS_OK;
 }
 
 already_AddRefed<nsStyleContext>
 ServoStyleSet::ProbePseudoElementStyle(Element* aOriginatingElement,
                                        CSSPseudoElementType aType,
@@ -919,16 +882,18 @@ ServoStyleSet::ResolveStyleLazily(Elemen
   sInServoTraversal = false;
 
   return computedValues.forget();
 }
 
 void
 ServoStyleSet::RegenerateServoStyleSetData()
 {
+  MOZ_ASSERT(mRawSet);
+
   // Build a flattened array from mSheets. Servo doesn't care about the
   // relative ordering of sheets from different cascade levels, only about
   // relative ordering within a cascade level, which this will preserve.
   nsTArray<const RawServoStyleSheet*> flattenedRawSheets;
 
   for (auto& sheetArray : mSheets) {
     for (auto& sheet : sheetArray) {
       flattenedRawSheets.AppendElement(sheet->RawSheet());