From 305a4881877c680ea38a4d48534efccb14613fdb Mon Sep 17 00:00:00 2001 From: "L. David Baron" Date: Thu, 31 Dec 2009 10:56:33 -0500 Subject: [PATCH] Add method to nsStyleSet to call EnsureUniqueInner on all CSS sheets. (Bug 536379) r=bzbarsky --- layout/style/nsCSSStyleSheet.cpp | 12 ++++++++++ layout/style/nsCSSStyleSheet.h | 4 ++++ layout/style/nsStyleSet.cpp | 38 ++++++++++++++++++++++++++++++++ layout/style/nsStyleSet.h | 6 +++-- 4 files changed, 58 insertions(+), 2 deletions(-) diff --git a/layout/style/nsCSSStyleSheet.cpp b/layout/style/nsCSSStyleSheet.cpp index c9646e4c345d..b2529fbb5e8d 100644 --- a/layout/style/nsCSSStyleSheet.cpp +++ b/layout/style/nsCSSStyleSheet.cpp @@ -1488,6 +1488,18 @@ nsCSSStyleSheet::EnsureUniqueInner() return eUniqueInner_ClonedInner; } +PRBool +nsCSSStyleSheet::AppendAllChildSheets(nsTArray& aArray) +{ + for (nsCSSStyleSheet* child = mInner->mFirstChild; child; + child = child->mNext) { + if (!aArray.AppendElement(child)) { + return PR_FALSE; + } + } + return PR_TRUE; +} + NS_IMETHODIMP nsCSSStyleSheet::Clone(nsICSSStyleSheet* aCloneParent, nsICSSImportRule* aCloneOwnerRule, diff --git a/layout/style/nsCSSStyleSheet.h b/layout/style/nsCSSStyleSheet.h index c6e67a99fb6b..c39b08a6a6a2 100644 --- a/layout/style/nsCSSStyleSheet.h +++ b/layout/style/nsCSSStyleSheet.h @@ -183,6 +183,10 @@ public: }; EnsureUniqueInnerResult EnsureUniqueInner(); + // Append all of this sheet's child sheets to aArray. Return PR_TRUE + // on success and PR_FALSE on allocation failure. + PRBool AppendAllChildSheets(nsTArray& aArray); + PRBool UseForPresentation(nsPresContext* aPresContext, nsMediaQueryResultCacheKey& aKey) const; diff --git a/layout/style/nsStyleSet.cpp b/layout/style/nsStyleSet.cpp index cfeb85808095..f60cb1d1424d 100644 --- a/layout/style/nsStyleSet.cpp +++ b/layout/style/nsStyleSet.cpp @@ -1161,3 +1161,41 @@ nsStyleSet::MediumFeaturesChanged(nsPresContext* aPresContext) return stylesChanged; } + +nsCSSStyleSheet::EnsureUniqueInnerResult +nsStyleSet::EnsureUniqueInnerOnCSSSheets() +{ + nsAutoTArray queue; + for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(gCSSSheetTypes); ++i) { + nsCOMArray &sheets = mSheets[gCSSSheetTypes[i]]; + for (PRUint32 j = 0, j_end = sheets.Count(); j < j_end; ++j) { + nsCSSStyleSheet *sheet = static_cast(sheets[j]); + if (!queue.AppendElement(sheet)) { + return nsCSSStyleSheet::eUniqueInner_CloneFailed; + } + } + } + + nsCSSStyleSheet::EnsureUniqueInnerResult res = + nsCSSStyleSheet::eUniqueInner_AlreadyUnique; + while (!queue.IsEmpty()) { + PRUint32 idx = queue.Length() - 1; + nsCSSStyleSheet *sheet = queue[idx]; + queue.RemoveElementAt(idx); + + nsCSSStyleSheet::EnsureUniqueInnerResult sheetRes = + sheet->EnsureUniqueInner(); + if (sheetRes == nsCSSStyleSheet::eUniqueInner_CloneFailed) { + return sheetRes; + } + if (sheetRes == nsCSSStyleSheet::eUniqueInner_ClonedInner) { + res = sheetRes; + } + + // Enqueue all the sheet's children. + if (!sheet->AppendAllChildSheets(queue)) { + return nsCSSStyleSheet::eUniqueInner_CloneFailed; + } + } + return res; +} diff --git a/layout/style/nsStyleSet.h b/layout/style/nsStyleSet.h index 30d1d4c44bc2..c57e28c1f54e 100644 --- a/layout/style/nsStyleSet.h +++ b/layout/style/nsStyleSet.h @@ -48,7 +48,7 @@ #define nsStyleSet_h_ #include "nsIStyleRuleProcessor.h" -#include "nsICSSStyleSheet.h" +#include "nsCSSStyleSheet.h" #include "nsBindingManager.h" #include "nsRuleNode.h" #include "nsTArray.h" @@ -277,7 +277,9 @@ class nsStyleSet void RuleNodeInUse() { --mUnusedRuleNodeCount; } - + + nsCSSStyleSheet::EnsureUniqueInnerResult EnsureUniqueInnerOnCSSSheets(); + private: // Not to be implemented nsStyleSet(const nsStyleSet& aCopy);