Bug 1290209 - Part 8: Move CSSStyleSheet::SetEnabled up to StyleSheet. r?xidorn
MozReview-Commit-ID: 7shpy5ghnVR
--- a/layout/style/CSSStyleSheet.cpp
+++ b/layout/style/CSSStyleSheet.cpp
@@ -595,29 +595,19 @@ CSSStyleSheet::UseForPresentation(nsPres
bool
CSSStyleSheet::HasRules() const
{
return StyleRuleCount() != 0;
}
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*
CSSStyleSheet::GetParentSheet() const
{
return mParent;
}
--- a/layout/style/CSSStyleSheet.h
+++ b/layout/style/CSSStyleSheet.h
@@ -110,27 +110,16 @@ public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(CSSStyleSheet, StyleSheet)
NS_DECLARE_STATIC_IID_ACCESSOR(NS_CSS_STYLE_SHEET_IMPL_CID)
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);
// Find the ID of the owner inner window.
uint64_t FindOwningWindowInnerID() const;
#ifdef DEBUG
void List(FILE* out = stdout, int32_t aIndent = 0) const;
@@ -238,16 +227,18 @@ protected:
protected:
// Internal methods which do not have security check and completeness check.
dom::CSSRuleList* GetCssRulesInternal(ErrorResult& aRv);
uint32_t InsertRuleInternal(const nsAString& aRule,
uint32_t aIndex, ErrorResult& aRv);
void DeleteRuleInternal(uint32_t aIndex, ErrorResult& aRv);
+ void EnabledStateChangedInternal();
+
RefPtr<CSSStyleSheet> mNext;
CSSStyleSheet* mParent; // weak ref
css::ImportRule* mOwnerRule; // weak ref
RefPtr<CSSRuleListImpl> mRuleCollection;
bool mDirty; // has been modified
bool mInRuleProcessorCache;
RefPtr<dom::Element> mScopeElement;
--- a/layout/style/Loader.cpp
+++ b/layout/style/Loader.cpp
@@ -1302,17 +1302,17 @@ Loader::PrepareSheet(StyleSheet* aSheet,
// We have aMediaString only when linked from link elements, style
// elements, or PIs, so pass true.
mediumParser.ParseMediaList(aMediaString, nullptr, 0, mediaList);
}
aSheet->SetMedia(mediaList);
aSheet->SetTitle(aTitle);
- sheet->SetEnabled(!aIsAlternate);
+ aSheet->SetEnabled(!aIsAlternate);
sheet->SetScopeElement(aScopeElement);
}
/**
* InsertSheetInDoc handles ordering of sheets in the document. Here
* we have two types of sheets -- those with linking elements and
* those without. The latter are loaded by Link: headers.
* The following constraints are observed:
--- a/layout/style/ServoStyleSheet.h
+++ b/layout/style/ServoStyleSheet.h
@@ -79,16 +79,18 @@ protected:
virtual ~ServoStyleSheet();
// Internal methods which do not have security check and completeness check.
dom::CSSRuleList* GetCssRulesInternal(ErrorResult& aRv);
uint32_t InsertRuleInternal(const nsAString& aRule,
uint32_t aIndex, ErrorResult& aRv);
void DeleteRuleInternal(uint32_t aIndex, ErrorResult& aRv);
+ void EnabledStateChangedInternal() {}
+
private:
void DropSheet();
RefPtr<RawServoStyleSheet> mSheet;
RefPtr<ServoCSSRuleList> mRuleList;
StyleSheetInfo mSheetInfo;
friend class StyleSheet;
--- a/layout/style/StyleSheet.cpp
+++ b/layout/style/StyleSheet.cpp
@@ -113,16 +113,32 @@ StyleSheet::SetComplete()
if (mOwningNode && !mDisabled &&
mOwningNode->HasFlag(NODE_IS_IN_SHADOW_TREE) &&
mOwningNode->IsContent()) {
dom::ShadowRoot* shadowRoot = mOwningNode->AsContent()->GetContainingShadow();
shadowRoot->StyleSheetChanged();
}
}
+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)
: mPrincipal(nsNullPrincipal::Create())
, mCORSMode(aCORSMode)
, mReferrerPolicy(aReferrerPolicy)
, mIntegrity(aIntegrity)
, mComplete(false)
@@ -280,16 +296,22 @@ StyleSheet::DeleteRule(uint32_t aIndex,
ErrorResult& aRv)
{
if (!AreRulesAvailable(aSubjectPrincipal, aRv)) {
return;
}
FORWARD_INTERNAL(DeleteRuleInternal, (aIndex, aRv))
}
+void
+StyleSheet::EnabledStateChanged()
+{
+ FORWARD_INTERNAL(EnabledStateChangedInternal, ())
+}
+
#undef FORWARD_INTERNAL
void
StyleSheet::SubjectSubsumesInnerPrincipal(nsIPrincipal& aSubjectPrincipal,
ErrorResult& aRv)
{
StyleSheetInfo& info = SheetInfo();
--- a/layout/style/StyleSheet.h
+++ b/layout/style/StyleSheet.h
@@ -62,16 +62,27 @@ public:
nsIDocument* GetDocument() const { return mDocument; }
/**
* Whether the sheet is complete.
*/
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 <style> element.
inline bool IsInline() const;
inline nsIURI* GetSheetURI() const;
/* Get the URI this sheet was originally loaded from, if any. Can
return null */
@@ -193,16 +204,19 @@ protected:
// UniversalXPConnect or if access is allowed by CORS. In the latter case,
// it will set the principal of the inner to the subject principal.
void SubjectSubsumesInnerPrincipal(nsIPrincipal& aSubjectPrincipal,
ErrorResult& aRv);
// Drop our reference to mMedia
void DropMedia();
+ // Called from SetEnabled when the enabled state changed.
+ void EnabledStateChanged();
+
nsString mTitle;
nsIDocument* mDocument; // weak ref; parents maintain this for their children
nsINode* mOwningNode; // weak ref
RefPtr<nsMediaList> mMedia;
// mParsingMode controls access to nonstandard style constructs that
// are not safe for use on the public Web but necessary in UA sheets