diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp index 5af6f29ecb75..0333428486e0 100644 --- a/dom/base/Document.cpp +++ b/dom/base/Document.cpp @@ -6587,23 +6587,7 @@ void Document::StyleSheetApplicableStateChanged(StyleSheet& aSheet) { } } - if (StyleSheetChangeEventsEnabled()) { - StyleSheetApplicableStateChangeEventInit init; - init.mBubbles = true; - init.mCancelable = true; - init.mStylesheet = &aSheet; - init.mApplicable = applicable; - - RefPtr event = - StyleSheetApplicableStateChangeEvent::Constructor( - this, u"StyleSheetApplicableStateChanged"_ns, init); - event->SetTrusted(true); - event->SetTarget(this); - RefPtr asyncDispatcher = - new AsyncEventDispatcher(this, event); - asyncDispatcher->mOnlyChromeDispatch = ChromeOnlyDispatch::eYes; - asyncDispatcher->PostDOMEvent(); - } + PostStyleSheetApplicableStateChangeEvent(aSheet); if (!mSSApplicableStateNotificationPending) { MOZ_RELEASE_ASSERT(NS_IsMainThread()); @@ -6615,6 +6599,28 @@ void Document::StyleSheetApplicableStateChanged(StyleSheet& aSheet) { } } +void Document::PostStyleSheetApplicableStateChangeEvent(StyleSheet& aSheet) { + if (!StyleSheetChangeEventsEnabled()) { + return; + } + + StyleSheetApplicableStateChangeEventInit init; + init.mBubbles = true; + init.mCancelable = true; + init.mStylesheet = &aSheet; + init.mApplicable = aSheet.IsApplicable(); + + RefPtr event = + StyleSheetApplicableStateChangeEvent::Constructor( + this, u"StyleSheetApplicableStateChanged"_ns, init); + event->SetTrusted(true); + event->SetTarget(this); + RefPtr asyncDispatcher = + new AsyncEventDispatcher(this, event); + asyncDispatcher->mOnlyChromeDispatch = ChromeOnlyDispatch::eYes; + asyncDispatcher->PostDOMEvent(); +} + void Document::NotifyStyleSheetApplicableStateChanged() { mSSApplicableStateNotificationPending = false; nsCOMPtr observerService = diff --git a/dom/base/Document.h b/dom/base/Document.h index 9d49678f336a..24e169435156 100644 --- a/dom/base/Document.h +++ b/dom/base/Document.h @@ -1679,6 +1679,8 @@ class Document : public nsINode, */ void StyleSheetApplicableStateChanged(StyleSheet&); + void PostStyleSheetApplicableStateChangeEvent(StyleSheet&); + enum additionalSheetType { eAgentSheet, eUserSheet, diff --git a/layout/style/SharedStyleSheetCache.cpp b/layout/style/SharedStyleSheetCache.cpp index 82bb19e40a28..6cfa56cb4b80 100644 --- a/layout/style/SharedStyleSheetCache.cpp +++ b/layout/style/SharedStyleSheetCache.cpp @@ -317,6 +317,12 @@ void SharedStyleSheetCache::LoadCompletedInternal( "should not get a forced unique inner during parsing"); data->mSheet->SetComplete(); data->ScheduleLoadEventIfNeeded(); + } else if (data->mSheet->IsApplicable()) { + if (dom::Document* doc = data->mLoader->GetDocument()) { + // We post these events for devtools, even though the applicable state + // has not actually changed, to make the cache not observable. + doc->PostStyleSheetApplicableStateChangeEvent(*data->mSheet); + } } aDatasToNotify.AppendElement(data);