mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-07 11:56:51 +00:00
Bug 1452143: Make InspectorUtils.getAllStyleSheets handle Shadow DOM, and also optionally not return UA / User sheets. r=bholley
We don't want to reparse over and over shared sheets, and that confused code pretty heavily. MozReview-Commit-ID: 7qkXoCoPNFW
This commit is contained in:
parent
8fc8563d65
commit
ec2824c99f
@ -11,7 +11,8 @@
|
||||
*/
|
||||
[ChromeOnly]
|
||||
namespace InspectorUtils {
|
||||
sequence<StyleSheet> getAllStyleSheets(Document document);
|
||||
// documentOnly tells whether user and UA sheets should get included.
|
||||
sequence<StyleSheet> getAllStyleSheets(Document document, optional boolean documentOnly = false);
|
||||
sequence<CSSRule> getCSSStyleRules(
|
||||
Element element,
|
||||
[TreatNullAs=EmptyString] optional DOMString pseudo = "");
|
||||
|
@ -61,6 +61,7 @@ namespace dom {
|
||||
/* static */ void
|
||||
InspectorUtils::GetAllStyleSheets(GlobalObject& aGlobalObject,
|
||||
nsIDocument& aDocument,
|
||||
bool aDocumentOnly,
|
||||
nsTArray<RefPtr<StyleSheet>>& aResult)
|
||||
{
|
||||
// Get the agent, then user and finally xbl sheets in the style set.
|
||||
@ -68,19 +69,24 @@ InspectorUtils::GetAllStyleSheets(GlobalObject& aGlobalObject,
|
||||
|
||||
if (presShell) {
|
||||
ServoStyleSet* styleSet = presShell->StyleSet();
|
||||
SheetType sheetType = SheetType::Agent;
|
||||
for (int32_t i = 0; i < styleSet->SheetCount(sheetType); i++) {
|
||||
aResult.AppendElement(styleSet->StyleSheetAt(sheetType, i));
|
||||
}
|
||||
sheetType = SheetType::User;
|
||||
for (int32_t i = 0; i < styleSet->SheetCount(sheetType); i++) {
|
||||
aResult.AppendElement(styleSet->StyleSheetAt(sheetType, i));
|
||||
|
||||
if (!aDocumentOnly) {
|
||||
SheetType sheetType = SheetType::Agent;
|
||||
for (int32_t i = 0; i < styleSet->SheetCount(sheetType); i++) {
|
||||
aResult.AppendElement(styleSet->StyleSheetAt(sheetType, i));
|
||||
}
|
||||
sheetType = SheetType::User;
|
||||
for (int32_t i = 0; i < styleSet->SheetCount(sheetType); i++) {
|
||||
aResult.AppendElement(styleSet->StyleSheetAt(sheetType, i));
|
||||
}
|
||||
}
|
||||
|
||||
AutoTArray<StyleSheet*, 32> xblSheetArray;
|
||||
styleSet->AppendAllXBLStyleSheets(xblSheetArray);
|
||||
styleSet->AppendAllNonDocumentAuthorSheets(xblSheetArray);
|
||||
|
||||
// The XBL stylesheet array will quite often be full of duplicates. Cope:
|
||||
//
|
||||
// FIXME(emilio, bug 1454467): I think this is not true since bug 1452525.
|
||||
nsTHashtable<nsPtrHashKey<StyleSheet>> sheetSet;
|
||||
for (StyleSheet* sheet : xblSheetArray) {
|
||||
if (!sheetSet.Contains(sheet)) {
|
||||
@ -1048,16 +1054,8 @@ InspectorUtils::ParseStyleSheet(GlobalObject& aGlobalObject,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
|
||||
RefPtr<ServoStyleSheet> servoSheet = do_QueryObject(&aSheet);
|
||||
if (servoSheet) {
|
||||
nsresult rv = servoSheet->ReparseSheet(aInput);
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
aRv.Throw(NS_ERROR_INVALID_POINTER);
|
||||
RefPtr<ServoStyleSheet> servoSheet = aSheet.AsServo();
|
||||
aRv = servoSheet->ReparseSheet(aInput);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -37,6 +37,7 @@ class InspectorUtils
|
||||
public:
|
||||
static void GetAllStyleSheets(GlobalObject& aGlobal,
|
||||
nsIDocument& aDocument,
|
||||
bool aDocumentOnly,
|
||||
nsTArray<RefPtr<StyleSheet>>& aResult);
|
||||
static void GetCSSStyleRules(GlobalObject& aGlobal,
|
||||
Element& aElement,
|
||||
|
@ -146,6 +146,7 @@ ErrorReporter::ErrorReporter(const StyleSheet* aSheet,
|
||||
|
||||
ErrorReporter::~ErrorReporter()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
// Schedule deferred cleanup for cached data. We want to strike a
|
||||
// balance between performance and memory usage, so we only allow
|
||||
// short-term caching.
|
||||
|
@ -869,10 +869,15 @@ ServoStyleSet::StyleSheetAt(SheetType aType, int32_t aIndex) const
|
||||
}
|
||||
|
||||
void
|
||||
ServoStyleSet::AppendAllXBLStyleSheets(nsTArray<StyleSheet*>& aArray) const
|
||||
ServoStyleSet::AppendAllNonDocumentAuthorSheets(nsTArray<StyleSheet*>& aArray) const
|
||||
{
|
||||
if (mDocument) {
|
||||
mDocument->BindingManager()->AppendAllSheets(aArray);
|
||||
EnumerateShadowRoots(*mDocument, [&](ShadowRoot& aShadowRoot) {
|
||||
for (auto index : IntegerRange(aShadowRoot.SheetCount())) {
|
||||
aArray.AppendElement(aShadowRoot.SheetAt(index));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -244,7 +244,7 @@ public:
|
||||
int32_t SheetCount(SheetType aType) const;
|
||||
ServoStyleSheet* StyleSheetAt(SheetType aType, int32_t aIndex) const;
|
||||
|
||||
void AppendAllXBLStyleSheets(nsTArray<StyleSheet*>& aArray) const;
|
||||
void AppendAllNonDocumentAuthorSheets(nsTArray<StyleSheet*>& aArray) const;
|
||||
|
||||
template<typename Func>
|
||||
void EnumerateStyleSheetArrays(Func aCallback) const {
|
||||
|
Loading…
Reference in New Issue
Block a user