Bug 1377196 Part 2 - Add AppendAllXBLStyleSheets to ServoStyleSet. draft
authorTing-Yu Lin <tlin@mozilla.com>
Thu, 29 Jun 2017 16:09:22 -0700
changeset 602361 15c0e6b07983c4d085ecca135018f2243c74ed7b
parent 602360 3a6110fd48418cb38f0fcb762d77181b7f1abfcc
child 635572 322cc44302c625df068d0ce757dd36a874652e25
push id66403
push userbmo:tlin@mozilla.com
push dateThu, 29 Jun 2017 23:22:09 +0000
bugs1377196
milestone56.0a1
Bug 1377196 Part 2 - Add AppendAllXBLStyleSheets to ServoStyleSet. MozReview-Commit-ID: HSQnBk8djil
layout/inspector/inDOMUtils.cpp
layout/style/ServoStyleSet.cpp
layout/style/ServoStyleSet.h
layout/style/StyleSetHandle.h
layout/style/StyleSetHandleInlines.h
layout/style/nsStyleSet.cpp
layout/style/nsStyleSet.h
--- a/layout/inspector/inDOMUtils.cpp
+++ b/layout/inspector/inDOMUtils.cpp
@@ -92,30 +92,27 @@ inDOMUtils::GetAllStyleSheets(nsIDOMDocu
     SheetType sheetType = SheetType::Agent;
     for (int32_t i = 0; i < styleSet->SheetCount(sheetType); i++) {
       sheets.AppendElement(styleSet->StyleSheetAt(sheetType, i));
     }
     sheetType = SheetType::User;
     for (int32_t i = 0; i < styleSet->SheetCount(sheetType); i++) {
       sheets.AppendElement(styleSet->StyleSheetAt(sheetType, i));
     }
-    if (styleSet->IsGecko()) {
-      AutoTArray<CSSStyleSheet*, 32> xblSheetArray;
-      styleSet->AsGecko()->AppendAllXBLStyleSheets(xblSheetArray);
+
+    AutoTArray<StyleSheet*, 32> xblSheetArray;
+    styleSet->AsGecko()->AppendAllXBLStyleSheets(xblSheetArray);
 
-      // The XBL stylesheet array will quite often be full of duplicates. Cope:
-      nsTHashtable<nsPtrHashKey<CSSStyleSheet>> sheetSet;
-      for (CSSStyleSheet* sheet : xblSheetArray) {
-        if (!sheetSet.Contains(sheet)) {
-          sheetSet.PutEntry(sheet);
-          sheets.AppendElement(sheet);
-        }
+    // The XBL stylesheet array will quite often be full of duplicates. Cope:
+    nsTHashtable<nsPtrHashKey<StyleSheet>> sheetSet;
+    for (StyleSheet* sheet : xblSheetArray) {
+      if (!sheetSet.Contains(sheet)) {
+        sheetSet.PutEntry(sheet);
+        sheets.AppendElement(sheet);
       }
-    } else {
-      NS_WARNING("stylo: XBL style sheets not supported yet");
     }
   }
 
   // Get the document sheets.
   for (int32_t i = 0; i < document->GetNumberOfStyleSheets(); i++) {
     sheets.AppendElement(document->GetStyleSheetAt(i));
   }
 
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -858,16 +858,24 @@ ServoStyleSet::SheetCount(SheetType aTyp
 ServoStyleSheet*
 ServoStyleSet::StyleSheetAt(SheetType aType,
                             int32_t aIndex) const
 {
   MOZ_ASSERT(nsStyleSet::IsCSSSheetType(aType));
   return mSheets[aType][aIndex];
 }
 
+void
+ServoStyleSet::AppendAllXBLStyleSheets(nsTArray<StyleSheet*>& aArray) const
+{
+  if (mBindingManager) {
+    mBindingManager->AppendAllSheets(aArray);
+  }
+}
+
 nsresult
 ServoStyleSet::RemoveDocStyleSheet(ServoStyleSheet* aSheet)
 {
   return RemoveStyleSheet(SheetType::Doc, aSheet);
 }
 
 nsresult
 ServoStyleSet::AddDocStyleSheet(ServoStyleSheet* aSheet,
--- a/layout/style/ServoStyleSet.h
+++ b/layout/style/ServoStyleSet.h
@@ -250,16 +250,18 @@ public:
   // 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;
 
+  void AppendAllXBLStyleSheets(nsTArray<StyleSheet*>& aArray) const;
+
   template<typename Func>
   void EnumerateStyleSheetArrays(Func aCallback) const {
     for (const auto& sheetArray : mSheets) {
       aCallback(sheetArray);
     }
   }
 
   nsresult RemoveDocStyleSheet(ServoStyleSheet* aSheet);
--- a/layout/style/StyleSetHandle.h
+++ b/layout/style/StyleSetHandle.h
@@ -148,16 +148,17 @@ public:
     inline nsresult RemoveStyleSheet(SheetType aType, StyleSheet* aSheet);
     inline nsresult ReplaceSheets(SheetType aType,
                            const nsTArray<RefPtr<StyleSheet>>& aNewSheets);
     inline nsresult InsertStyleSheetBefore(SheetType aType,
                                     StyleSheet* aNewSheet,
                                     StyleSheet* aReferenceSheet);
     inline int32_t SheetCount(SheetType aType) const;
     inline StyleSheet* StyleSheetAt(SheetType aType, int32_t aIndex) const;
+    inline void AppendAllXBLStyleSheets(nsTArray<StyleSheet*>& aArray) const;
     inline nsresult RemoveDocStyleSheet(StyleSheet* aSheet);
     inline nsresult AddDocStyleSheet(StyleSheet* aSheet, nsIDocument* aDocument);
     inline void RecordStyleSheetChange(StyleSheet* aSheet, StyleSheet::ChangeType);
     inline void RecordShadowStyleChange(mozilla::dom::ShadowRoot* aShadowRoot);
     inline bool StyleSheetsHaveChanged() const;
     inline void InvalidateStyleForCSSRuleChanges();
     inline bool MediumFeaturesChanged();
     inline already_AddRefed<nsStyleContext>
--- a/layout/style/StyleSetHandleInlines.h
+++ b/layout/style/StyleSetHandleInlines.h
@@ -201,16 +201,23 @@ StyleSetHandle::Ptr::SheetCount(SheetTyp
 }
 
 StyleSheet*
 StyleSetHandle::Ptr::StyleSheetAt(SheetType aType, int32_t aIndex) const
 {
   FORWARD(StyleSheetAt, (aType, aIndex));
 }
 
+void
+StyleSetHandle::Ptr::AppendAllXBLStyleSheets(nsTArray<StyleSheet*>& aArray) const
+{
+  FORWARD_CONCRETE(AppendAllXBLStyleSheets, (aArray),
+                                            (aArray));
+}
+
 nsresult
 StyleSetHandle::Ptr::RemoveDocStyleSheet(StyleSheet* aSheet)
 {
   FORWARD_CONCRETE(RemoveDocStyleSheet, (aSheet->AsGecko()),
                                         (aSheet->AsServo()));
 }
 
 nsresult
--- a/layout/style/nsStyleSet.cpp
+++ b/layout/style/nsStyleSet.cpp
@@ -740,29 +740,20 @@ nsStyleSet::AddDocStyleSheet(CSSStyleShe
   if (!present) {
     aSheet->AddStyleSet(StyleSetHandle(this));
   }
 
   return DirtyRuleProcessors(type);
 }
 
 void
-nsStyleSet::AppendAllXBLStyleSheets(nsTArray<mozilla::CSSStyleSheet*>& aArray) const
+nsStyleSet::AppendAllXBLStyleSheets(nsTArray<StyleSheet*>& aArray) const
 {
   if (mBindingManager) {
-    // XXXheycam stylo: AppendAllSheets will need to be able to return either
-    // CSSStyleSheets or ServoStyleSheets, on request (and then here requesting
-    // CSSStyleSheets).
-    AutoTArray<StyleSheet*, 32> sheets;
-    mBindingManager->AppendAllSheets(sheets);
-    for (StyleSheet* handle : sheets) {
-      MOZ_ASSERT(handle->IsGecko(), "stylo: AppendAllSheets shouldn't give us "
-                                    "ServoStyleSheets yet");
-      aArray.AppendElement(handle->AsGecko());
-    }
+    mBindingManager->AppendAllSheets(aArray);
   }
 }
 
 nsresult
 nsStyleSet::RemoveDocStyleSheet(CSSStyleSheet* aSheet)
 {
   bool isScoped = aSheet->GetScopeElement();
   return RemoveStyleSheet(isScoped ? SheetType::ScopedDoc : SheetType::Doc,
--- a/layout/style/nsStyleSet.h
+++ b/layout/style/nsStyleSet.h
@@ -407,17 +407,17 @@ class nsStyleSet final
     return mSheets[aType].Length();
   }
 
   mozilla::CSSStyleSheet* StyleSheetAt(mozilla::SheetType aType,
                                        int32_t aIndex) const {
     return mSheets[aType][aIndex];
   }
 
-  void AppendAllXBLStyleSheets(nsTArray<mozilla::CSSStyleSheet*>& aArray) const;
+  void AppendAllXBLStyleSheets(nsTArray<mozilla::StyleSheet*>& aArray) const;
 
   nsresult RemoveDocStyleSheet(mozilla::CSSStyleSheet* aSheet);
   nsresult AddDocStyleSheet(mozilla::CSSStyleSheet* aSheet,
                             nsIDocument* aDocument);
 
   void     BeginUpdate();
   nsresult EndUpdate();