From f6221f440e05030ee500c0a0a887ffa823c7e14c Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 17 Apr 2020 07:39:36 -0400 Subject: Bug 1322661 - Expose (non-XBL) style sheets to devtools Tag #1375 --- layout/inspector/inDOMUtils.cpp | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/layout/inspector/inDOMUtils.cpp b/layout/inspector/inDOMUtils.cpp index e212e20df..8e547cc24 100644 --- a/layout/inspector/inDOMUtils.cpp +++ b/layout/inspector/inDOMUtils.cpp @@ -48,7 +48,8 @@ #include "nsCSSProps.h" #include "nsCSSValue.h" #include "nsColor.h" -#include "nsStyleSet.h" +#include "mozilla/StyleSetHandle.h" +#include "mozilla/StyleSetHandleInlines.h" #include "nsStyleUtil.h" #include "nsQueryObject.h" @@ -77,7 +78,7 @@ inDOMUtils::GetAllStyleSheets(nsIDOMDocument *aDocument, uint32_t *aLength, { NS_ENSURE_ARG_POINTER(aDocument); - nsTArray> sheets; + nsTArray> sheets; nsCOMPtr document = do_QueryInterface(aDocument); MOZ_ASSERT(document); @@ -85,15 +86,8 @@ inDOMUtils::GetAllStyleSheets(nsIDOMDocument *aDocument, uint32_t *aLength, // Get the agent, then user and finally xbl sheets in the style set. nsIPresShell* presShell = document->GetShell(); - if (presShell && presShell->StyleSet()->IsServo()) { - // XXXheycam ServoStyleSets don't have the ability to expose their - // sheets in a script-accessible way yet. - NS_ERROR("stylo: ServoStyleSets cannot expose their sheets to script yet"); - return NS_ERROR_FAILURE; - } - if (presShell) { - nsStyleSet* styleSet = presShell->StyleSet()->AsGecko(); + StyleSetHandle styleSet = presShell->StyleSet(); SheetType sheetType = SheetType::Agent; for (int32_t i = 0; i < styleSet->SheetCount(sheetType); i++) { sheets.AppendElement(styleSet->StyleSheetAt(sheetType, i)); @@ -102,24 +96,26 @@ inDOMUtils::GetAllStyleSheets(nsIDOMDocument *aDocument, uint32_t *aLength, for (int32_t i = 0; i < styleSet->SheetCount(sheetType); i++) { sheets.AppendElement(styleSet->StyleSheetAt(sheetType, i)); } - AutoTArray xblSheetArray; - styleSet->AppendAllXBLStyleSheets(xblSheetArray); - - // The XBL stylesheet array will quite often be full of duplicates. Cope: - nsTHashtable> sheetSet; - for (CSSStyleSheet* sheet : xblSheetArray) { - if (!sheetSet.Contains(sheet)) { - sheetSet.PutEntry(sheet); - sheets.AppendElement(sheet); + if (styleSet->IsGecko()) { + AutoTArray xblSheetArray; + styleSet->AsGecko()->AppendAllXBLStyleSheets(xblSheetArray); + + // The XBL stylesheet array will quite often be full of duplicates. Cope: + nsTHashtable> sheetSet; + for (CSSStyleSheet* 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++) { - // XXXheycam ServoStyleSets don't have the ability to expose their - // sheets in a script-accessible way yet. - sheets.AppendElement(document->GetStyleSheetAt(i)->AsGecko()); + sheets.AppendElement(document->GetStyleSheetAt(i)); } nsISupports** ret = static_cast(moz_xmalloc(sheets.Length() * -- cgit v1.2.3