Bug 1339629 Part 10: Implement ServoStyleSet::EnsureUniqueInnerOnCSSSheets. draft
authorBrad Werth <bwerth@mozilla.com>
Mon, 15 May 2017 17:11:08 -0700
changeset 584204 ab2d879a9d76a4016c15599855fa07e09fd916cb
parent 584203 c7bd633953f04477d7ea7505c5130874258f5af9
child 584205 efb86a9896d11a65a2d22b87c20c04d1495bc1c7
push id60647
push userbwerth@mozilla.com
push dateThu, 25 May 2017 00:33:14 +0000
bugs1339629
milestone55.0a1
Bug 1339629 Part 10: Implement ServoStyleSet::EnsureUniqueInnerOnCSSSheets. MozReview-Commit-ID: GuUqKYrV60z
layout/style/CSSStyleSheet.cpp
layout/style/CSSStyleSheet.h
layout/style/ServoStyleSet.cpp
layout/style/StyleSheet.cpp
layout/style/StyleSheet.h
layout/style/nsStyleSet.cpp
--- a/layout/style/CSSStyleSheet.cpp
+++ b/layout/style/CSSStyleSheet.cpp
@@ -563,26 +563,16 @@ CSSStyleSheet::StyleRuleCount() const
 css::Rule*
 CSSStyleSheet::GetStyleRuleAt(int32_t aIndex) const
 {
   // Important: If this function is ever made scriptable, we must add
   // a security check here. See GetCssRules below for an example.
   return Inner()->mOrderedRules.SafeObjectAt(aIndex);
 }
 
-void
-CSSStyleSheet::AppendAllChildSheets(nsTArray<CSSStyleSheet*>& aArray)
-{
-  for (StyleSheet* child = GetFirstChild(); child;
-       child = child->mNext) {
-
-    aArray.AppendElement(child->AsGecko());
-  }
-}
-
 already_AddRefed<StyleSheet>
 CSSStyleSheet::Clone(StyleSheet* aCloneParent,
                      css::ImportRule* aCloneOwnerRule,
                      nsIDocument* aCloneDocument,
                      nsINode* aCloneOwningNode) const
 {
   RefPtr<StyleSheet> clone = new CSSStyleSheet(*this,
     static_cast<CSSStyleSheet*>(aCloneParent),
--- a/layout/style/CSSStyleSheet.h
+++ b/layout/style/CSSStyleSheet.h
@@ -135,19 +135,16 @@ public:
 
   nsresult AddRuleProcessor(nsCSSRuleProcessor* aProcessor);
   nsresult DropRuleProcessor(nsCSSRuleProcessor* aProcessor);
 
   // nsICSSLoaderObserver interface
   NS_IMETHOD StyleSheetLoaded(StyleSheet* aSheet, bool aWasAlternate,
                               nsresult aStatus) override;
 
-  // Append all of this sheet's child sheets to aArray.
-  void AppendAllChildSheets(nsTArray<CSSStyleSheet*>& aArray);
-
   bool UseForPresentation(nsPresContext* aPresContext,
                             nsMediaQueryResultCacheKey& aKey) const;
 
   nsresult ReparseSheet(const nsAString& aInput);
 
   void SetInRuleProcessorCache() { mInRuleProcessorCache = true; }
 
   // Function used as a callback to rebuild our inner's child sheet
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -982,19 +982,39 @@ ServoStyleSet::ComputeAnimationValue(
                                       aComputedValues.mCurrentStyle,
                                       aComputedValues.mParentStyle,
                                       mRawSet.get()).Consume();
 }
 
 bool
 ServoStyleSet::EnsureUniqueInnerOnCSSSheets()
 {
+  AutoTArray<StyleSheet*, 32> queue;
+  for (auto& entryArray : mSheets) {
+    for (auto& sheet : entryArray) {
+      queue.AppendElement(sheet);
+    }
+  }
   // This is a stub until more of the functionality of nsStyleSet is
   // replicated for Servo here.
 
+  // Bug 1290276 will replicate the nsStyleSet work of checking
+  // a nsBindingManager
+
+  while (!queue.IsEmpty()) {
+    uint32_t idx = queue.Length() - 1;
+    StyleSheet* sheet = queue[idx];
+    queue.RemoveElementAt(idx);
+
+    sheet->EnsureUniqueInner();
+
+    // Enqueue all the sheet's children.
+    sheet->AppendAllChildSheets(queue);
+  }
+
   bool res = mNeedsRestyleAfterEnsureUniqueInner;
   mNeedsRestyleAfterEnsureUniqueInner = false;
   return res;
 }
 
 void
 ServoStyleSet::RebuildData()
 {
--- a/layout/style/StyleSheet.cpp
+++ b/layout/style/StyleSheet.cpp
@@ -453,16 +453,24 @@ StyleSheet::EnsureUniqueInner()
   // let our containing style sets know that if we call
   // nsPresContext::EnsureSafeToHandOutCSSRules we will need to restyle the
   // document
   for (StyleSetHandle& setHandle : mStyleSets) {
     setHandle->SetNeedsRestyleAfterEnsureUniqueInner();
   }
 }
 
+void
+StyleSheet::AppendAllChildSheets(nsTArray<StyleSheet*>& aArray)
+{
+  for (StyleSheet* child = GetFirstChild(); child; child = child->mNext) {
+    aArray.AppendElement(child);
+  }
+}
+
 // WebIDL CSSStyleSheet API
 
 #define FORWARD_INTERNAL(method_, args_) \
   if (IsServo()) { \
     return AsServo()->method_ args_; \
   } \
   return AsGecko()->method_ args_;
 
--- a/layout/style/StyleSheet.h
+++ b/layout/style/StyleSheet.h
@@ -119,16 +119,19 @@ public:
                                              css::ImportRule* aCloneOwnerRule,
                                              nsIDocument* aCloneDocument,
                                              nsINode* aCloneOwningNode) const = 0;
 
   bool IsModified() const { return mDirty; }
 
   void EnsureUniqueInner();
 
+  // Append all of this sheet's child sheets to aArray.
+  void AppendAllChildSheets(nsTArray<StyleSheet*>& aArray);
+
   // style sheet owner info
   enum DocumentAssociationMode {
     // OwnedByDocument means mDocument owns us (possibly via a chain of other
     // stylesheets).
     OwnedByDocument,
     // NotOwnedByDocument means we're owned by something that might have a
     // different lifetime than mDocument.
     NotOwnedByDocument
--- a/layout/style/nsStyleSet.cpp
+++ b/layout/style/nsStyleSet.cpp
@@ -2633,19 +2633,19 @@ nsStyleSet::MediumFeaturesChanged()
   }
 
   return stylesChanged;
 }
 
 bool
 nsStyleSet::EnsureUniqueInnerOnCSSSheets()
 {
-  AutoTArray<CSSStyleSheet*, 32> queue;
+  AutoTArray<StyleSheet*, 32> queue;
   for (SheetType type : gCSSSheetTypes) {
-    for (CSSStyleSheet* sheet : mSheets[type]) {
+    for (StyleSheet* sheet : mSheets[type]) {
       queue.AppendElement(sheet);
     }
   }
 
   if (mBindingManager) {
     AutoTArray<StyleSheet*, 32> sheets;
     // XXXheycam stylo: AppendAllSheets will need to be able to return either
     // CSSStyleSheets or ServoStyleSheets, on request (and then here requesting
@@ -2655,17 +2655,17 @@ nsStyleSet::EnsureUniqueInnerOnCSSSheets
       MOZ_ASSERT(sheet->IsGecko(), "stylo: AppendAllSheets shouldn't give us "
                                    "ServoStyleSheets yet");
       queue.AppendElement(sheet->AsGecko());
     }
   }
 
   while (!queue.IsEmpty()) {
     uint32_t idx = queue.Length() - 1;
-    CSSStyleSheet* sheet = queue[idx];
+    StyleSheet* sheet = queue[idx];
     queue.RemoveElementAt(idx);
 
     sheet->EnsureUniqueInner();
 
     // Enqueue all the sheet's children.
     sheet->AppendAllChildSheets(queue);
   }