diff --git a/layout/style/CSSStyleSheet.cpp b/layout/style/CSSStyleSheet.cpp index aa329295de6a..9b033e078998 100644 --- a/layout/style/CSSStyleSheet.cpp +++ b/layout/style/CSSStyleSheet.cpp @@ -600,19 +600,9 @@ CSSStyleSheet::HasRules() const } void -CSSStyleSheet::SetEnabled(bool aEnabled) +CSSStyleSheet::EnabledStateChangedInternal() { - // Internal method, so callers must handle BeginUpdate/EndUpdate - bool oldDisabled = mDisabled; - mDisabled = !aEnabled; - - if (mInner->mComplete && oldDisabled != mDisabled) { - ClearRuleCascades(); - - if (mDocument) { - mDocument->SetStyleSheetApplicableState(this, !mDisabled); - } - } + ClearRuleCascades(); } CSSStyleSheet* diff --git a/layout/style/CSSStyleSheet.h b/layout/style/CSSStyleSheet.h index f18d2c5bf9c1..4d2b52cbe645 100644 --- a/layout/style/CSSStyleSheet.h +++ b/layout/style/CSSStyleSheet.h @@ -115,17 +115,6 @@ public: bool HasRules() const; - /** - * Set the stylesheet to be enabled. This may or may not make it - * applicable. Note that this WILL inform the sheet's document of - * its new applicable state if the state changes but WILL NOT call - * BeginUpdate() or EndUpdate() on the document -- calling those is - * the caller's responsibility. This allows use of SetEnabled when - * batched updates are desired. If you want updates handled for - * you, see nsIDOMStyleSheet::SetDisabled(). - */ - void SetEnabled(bool aEnabled); - // style sheet owner info CSSStyleSheet* GetParentSheet() const; // may be null void SetOwningDocument(nsIDocument* aDocument); @@ -243,6 +232,8 @@ protected: uint32_t aIndex, ErrorResult& aRv); void DeleteRuleInternal(uint32_t aIndex, ErrorResult& aRv); + void EnabledStateChangedInternal(); + RefPtr mNext; CSSStyleSheet* mParent; // weak ref css::ImportRule* mOwnerRule; // weak ref diff --git a/layout/style/Loader.cpp b/layout/style/Loader.cpp index 4ace784530e4..0233c0fb7764 100644 --- a/layout/style/Loader.cpp +++ b/layout/style/Loader.cpp @@ -1307,7 +1307,7 @@ Loader::PrepareSheet(StyleSheet* aSheet, aSheet->SetMedia(mediaList); aSheet->SetTitle(aTitle); - sheet->SetEnabled(!aIsAlternate); + aSheet->SetEnabled(!aIsAlternate); sheet->SetScopeElement(aScopeElement); } diff --git a/layout/style/ServoStyleSheet.h b/layout/style/ServoStyleSheet.h index cb7c80cd0678..e1387ed69d74 100644 --- a/layout/style/ServoStyleSheet.h +++ b/layout/style/ServoStyleSheet.h @@ -84,6 +84,8 @@ protected: uint32_t aIndex, ErrorResult& aRv); void DeleteRuleInternal(uint32_t aIndex, ErrorResult& aRv); + void EnabledStateChangedInternal() {} + private: void DropSheet(); diff --git a/layout/style/StyleSheet.cpp b/layout/style/StyleSheet.cpp index 611f48efb097..b7cd6135d3c3 100644 --- a/layout/style/StyleSheet.cpp +++ b/layout/style/StyleSheet.cpp @@ -115,6 +115,22 @@ StyleSheet::SetComplete() } } +void +StyleSheet::SetEnabled(bool aEnabled) +{ + // Internal method, so callers must handle BeginUpdate/EndUpdate + bool oldDisabled = mDisabled; + mDisabled = !aEnabled; + + if (IsComplete() && oldDisabled != mDisabled) { + EnabledStateChanged(); + + if (mDocument) { + mDocument->SetStyleSheetApplicableState(this, !mDisabled); + } + } +} + StyleSheetInfo::StyleSheetInfo(CORSMode aCORSMode, ReferrerPolicy aReferrerPolicy, const dom::SRIMetadata& aIntegrity) @@ -282,6 +298,12 @@ StyleSheet::DeleteRule(uint32_t aIndex, FORWARD_INTERNAL(DeleteRuleInternal, (aIndex, aRv)) } +void +StyleSheet::EnabledStateChanged() +{ + FORWARD_INTERNAL(EnabledStateChangedInternal, ()) +} + #undef FORWARD_INTERNAL void diff --git a/layout/style/StyleSheet.h b/layout/style/StyleSheet.h index 45913259cdbe..b12200c75fd5 100644 --- a/layout/style/StyleSheet.h +++ b/layout/style/StyleSheet.h @@ -67,6 +67,17 @@ public: bool IsComplete() const; void SetComplete(); + /** + * Set the stylesheet to be enabled. This may or may not make it + * applicable. Note that this WILL inform the sheet's document of + * its new applicable state if the state changes but WILL NOT call + * BeginUpdate() or EndUpdate() on the document -- calling those is + * the caller's responsibility. This allows use of SetEnabled when + * batched updates are desired. If you want updates handled for + * you, see nsIDOMStyleSheet::SetDisabled(). + */ + void SetEnabled(bool aEnabled); + MOZ_DECL_STYLO_METHODS(CSSStyleSheet, ServoStyleSheet) // Whether the sheet is for an inline