Bug 1373193 Part 2: Create and call a new UpdateStyleSheet method on ServoStyleSet when a ServoStyleSheet has its inner cloned. draft
authorBrad Werth <bwerth@mozilla.com>
Mon, 19 Jun 2017 10:47:13 -0700
changeset 597743 13e99229b7deff71e57c2e6aa9b1028fbf2155a0
parent 597455 464b2a3c25aa1065760d9ecbb0870bca4a66c62e
child 597744 dda9d398f3b78f1acca21090fd22d494ba18c41a
push id65012
push userbwerth@mozilla.com
push dateTue, 20 Jun 2017 21:58:11 +0000
bugs1373193
milestone56.0a1
Bug 1373193 Part 2: Create and call a new UpdateStyleSheet method on ServoStyleSet when a ServoStyleSheet has its inner cloned. MozReview-Commit-ID: GKxnEiZvziS
layout/style/ServoBindingList.h
layout/style/ServoStyleSet.cpp
layout/style/ServoStyleSet.h
layout/style/StyleSheet.cpp
--- a/layout/style/ServoBindingList.h
+++ b/layout/style/ServoBindingList.h
@@ -71,16 +71,20 @@ SERVO_BINDING_FUNC(Servo_StyleSet_Prepen
 SERVO_BINDING_FUNC(Servo_StyleSet_RemoveStyleSheet, void,
                    RawServoStyleSetBorrowed set,
                    uint64_t unique_id)
 SERVO_BINDING_FUNC(Servo_StyleSet_InsertStyleSheetBefore, void,
                    RawServoStyleSetBorrowed set,
                    RawServoStyleSheetBorrowed sheet,
                    uint64_t unique_id,
                    uint64_t before_unique_id)
+SERVO_BINDING_FUNC(Servo_StyleSet_UpdateStyleSheet, void,
+                   RawServoStyleSetBorrowed set,
+                   RawServoStyleSheetBorrowed sheet,
+                   uint64_t unique_id)
 SERVO_BINDING_FUNC(Servo_StyleSet_FlushStyleSheets, void, RawServoStyleSetBorrowed set,
                    RawGeckoElementBorrowedOrNull doc_elem)
 SERVO_BINDING_FUNC(Servo_StyleSet_NoteStyleSheetsChanged, void,
                    RawServoStyleSetBorrowed set, bool author_style_disabled)
 SERVO_BINDING_FUNC(Servo_StyleSet_GetKeyframesForName, bool,
                    RawServoStyleSetBorrowed set,
                    const nsACString* property,
                    nsTimingFunctionBorrowed timing_function,
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -776,16 +776,32 @@ ServoStyleSet::InsertStyleSheetBefore(Sh
                                           UniqueIDForSheet(aNewSheet),
                                           UniqueIDForSheet(aReferenceSheet));
     SetStylistStyleSheetsDirty();
   }
 
   return NS_OK;
 }
 
+void
+ServoStyleSet::UpdateStyleSheet(ServoStyleSheet* aSheet)
+{
+  MOZ_ASSERT(aSheet);
+
+  if (mRawSet) {
+    // Inform servo that the underlying raw sheet has changed.
+    Servo_StyleSet_UpdateStyleSheet(mRawSet.get(),
+                                    aSheet->RawSheet(),
+                                    UniqueIDForSheet(aSheet));
+    // No need to set the stylesheets as dirty, since this is only
+    // used to notify servo of a cloned raw sheet. It styles the
+    // same until the sheet is changed through other methods.
+  }
+}
+
 int32_t
 ServoStyleSet::SheetCount(SheetType aType) const
 {
   MOZ_ASSERT(nsStyleSet::IsCSSSheetType(aType));
   return mSheets[aType].Length();
 }
 
 ServoStyleSheet*
--- a/layout/style/ServoStyleSet.h
+++ b/layout/style/ServoStyleSet.h
@@ -241,16 +241,21 @@ public:
   nsresult PrependStyleSheet(SheetType aType, ServoStyleSheet* aSheet);
   nsresult RemoveStyleSheet(SheetType aType, ServoStyleSheet* aSheet);
   nsresult ReplaceSheets(SheetType aType,
                          const nsTArray<RefPtr<ServoStyleSheet>>& aNewSheets);
   nsresult InsertStyleSheetBefore(SheetType aType,
                                   ServoStyleSheet* aNewSheet,
                                   ServoStyleSheet* aReferenceSheet);
 
+  // Notify servo that the underlying raw sheet has changed, through cloning.
+  // This should only be called on a just-cloned sheet, because it does not
+  // mark the stylesheets as dirty either here or in servo.
+  void UpdateStyleSheet(ServoStyleSheet* aSheet);
+
   int32_t SheetCount(SheetType aType) const;
   ServoStyleSheet* StyleSheetAt(SheetType aType, int32_t aIndex) const;
 
   template<typename Func>
   void EnumerateStyleSheetArrays(Func aCallback) const {
     for (const auto& sheetArray : mSheets) {
       aCallback(sheetArray);
     }
--- a/layout/style/StyleSheet.cpp
+++ b/layout/style/StyleSheet.cpp
@@ -466,16 +466,20 @@ StyleSheet::EnsureUniqueInner()
   if (CSSStyleSheet* geckoSheet = GetAsGecko()) {
     geckoSheet->ClearRuleCascades();
   }
 
   // let our containing style sets know that if we call
   // nsPresContext::EnsureSafeToHandOutCSSRules we will need to restyle the
   // document
   for (StyleSetHandle& setHandle : mStyleSets) {
+    if (ServoStyleSet* servoSet = setHandle->GetAsServo()) {
+      MOZ_ASSERT(IsServo(), "Only servo sheets should be in servo stylesets.");
+      servoSet->UpdateStyleSheet(GetAsServo());
+    }
     setHandle->SetNeedsRestyleAfterEnsureUniqueInner();
   }
 }
 
 void
 StyleSheet::AppendAllChildSheets(nsTArray<StyleSheet*>& aArray)
 {
   for (StyleSheet* child = GetFirstChild(); child; child = child->mNext) {