Bug 1339629 Part 6: Uplift mStyleSets into StyleSheet.
MozReview-Commit-ID: G8xQ5gLJ3dr
--- a/layout/style/CSSStyleSheet.cpp
+++ b/layout/style/CSSStyleSheet.cpp
@@ -187,17 +187,16 @@ CSSStyleSheet::SizeOfIncludingThis(Mallo
if (s->Inner()->mSheets.LastElement() == s) {
n += s->Inner()->SizeOfIncludingThis(aMallocSizeOf);
}
// Measurement of the following members may be added later if DMD finds it
// is worthwhile:
// - s->mRuleCollection
// - s->mRuleProcessors
- // - s->mStyleSets
//
// The following members are not measured:
// - s->mOwnerRule, because it's non-owning
// - s->mScopeElement, because it's non-owning
s = s->mNext ? s->mNext->AsGecko() : nullptr;
}
return n;
@@ -477,31 +476,16 @@ CSSStyleSheet::DropRuleProcessor(nsCSSRu
{
if (!mRuleProcessors)
return NS_ERROR_FAILURE;
return mRuleProcessors->RemoveElement(aProcessor)
? NS_OK
: NS_ERROR_FAILURE;
}
-void
-CSSStyleSheet::AddStyleSet(nsStyleSet* aStyleSet)
-{
- NS_ASSERTION(!mStyleSets.Contains(aStyleSet),
- "style set already registered");
- mStyleSets.AppendElement(aStyleSet);
-}
-
-void
-CSSStyleSheet::DropStyleSet(nsStyleSet* aStyleSet)
-{
- DebugOnly<bool> found = mStyleSets.RemoveElement(aStyleSet);
- NS_ASSERTION(found, "didn't find style set");
-}
-
bool
CSSStyleSheet::UseForPresentation(nsPresContext* aPresContext,
nsMediaQueryResultCacheKey& aKey) const
{
if (mMedia) {
MOZ_ASSERT(aPresContext);
auto media = static_cast<nsMediaList*>(mMedia.get());
return media->Matches(aPresContext, &aKey);
--- a/layout/style/CSSStyleSheet.h
+++ b/layout/style/CSSStyleSheet.h
@@ -7,17 +7,16 @@
/* representation of a CSS style sheet */
#ifndef mozilla_CSSStyleSheet_h
#define mozilla_CSSStyleSheet_h
#include "mozilla/Attributes.h"
#include "mozilla/IncrementalClearCOMRuleArray.h"
#include "mozilla/MemoryReporting.h"
-#include "mozilla/StyleSetHandle.h"
#include "mozilla/StyleSheet.h"
#include "mozilla/StyleSheetInfo.h"
#include "mozilla/css/SheetParsingMode.h"
#include "nscore.h"
#include "nsCOMPtr.h"
#include "nsAutoPtr.h"
#include "nsTArrayForwardDeclare.h"
@@ -26,17 +25,16 @@
#include "nsCycleCollectionParticipant.h"
#include "mozilla/net/ReferrerPolicy.h"
#include "mozilla/dom/SRIMetadata.h"
class CSSRuleListImpl;
class nsCSSRuleProcessor;
class nsIURI;
class nsMediaQueryResultCacheKey;
-class nsStyleSet;
class nsPresContext;
class nsXMLNameSpaceMap;
namespace mozilla {
class CSSStyleSheet;
struct ChildSheetListBuilder;
namespace css {
@@ -133,19 +131,16 @@ public:
NS_ASSERTION(mDirty,
"sheet must be marked dirty before handing out child rules");
DidDirty();
}
nsresult AddRuleProcessor(nsCSSRuleProcessor* aProcessor);
nsresult DropRuleProcessor(nsCSSRuleProcessor* aProcessor);
- void AddStyleSet(nsStyleSet* aStyleSet);
- void DropStyleSet(nsStyleSet* aStyleSet);
-
// nsICSSLoaderObserver interface
NS_IMETHOD StyleSheetLoaded(StyleSheet* aSheet, bool aWasAlternate,
nsresult aStatus) override;
void EnsureUniqueInner() override;
// Append all of this sheet's child sheets to aArray.
void AppendAllChildSheets(nsTArray<CSSStyleSheet*>& aArray);
@@ -220,17 +215,16 @@ protected:
css::ImportRule* mOwnerRule; // weak ref
RefPtr<CSSRuleListImpl> mRuleCollection;
bool mInRuleProcessorCache;
RefPtr<dom::Element> mScopeElement;
AutoTArray<nsCSSRuleProcessor*, 8>* mRuleProcessors;
- nsTArray<StyleSetHandle> mStyleSets;
friend class mozilla::StyleSheet;
friend class ::nsCSSRuleProcessor;
};
NS_DEFINE_STATIC_IID_ACCESSOR(CSSStyleSheet, NS_CSS_STYLE_SHEET_IMPL_CID)
} // namespace mozilla
--- a/layout/style/StyleSheet.cpp
+++ b/layout/style/StyleSheet.cpp
@@ -402,16 +402,31 @@ void
StyleSheet::WillDirty()
{
if (mInner->mComplete) {
EnsureUniqueInner();
}
}
void
+StyleSheet::AddStyleSet(StyleSetHandle aStyleSet)
+{
+ NS_ASSERTION(!mStyleSets.Contains(aStyleSet),
+ "style set already registered");
+ mStyleSets.AppendElement(aStyleSet);
+}
+
+void
+StyleSheet::DropStyleSet(StyleSetHandle aStyleSet)
+{
+ DebugOnly<bool> found = mStyleSets.RemoveElement(aStyleSet);
+ NS_ASSERTION(found, "didn't find style set");
+}
+
+void
StyleSheet::EnsureUniqueInner()
{
MOZ_ASSERT(mInner->mSheets.Length() != 0,
"unexpected number of outers");
mDirty = true;
if (mInner->mSheets.Length() == 1) {
// already unique
@@ -670,16 +685,17 @@ StyleSheet::SizeOfIncludingThis(MallocSi
const StyleSheet* s = this;
while (s) {
n += aMallocSizeOf(s);
// Measurement of the following members may be added later if DMD finds it
// is worthwhile:
// - s->mTitle
// - s->mMedia
+ // - s->mStyleSets
s = s->mNext;
}
return n;
}
#ifdef DEBUG
void
--- a/layout/style/StyleSheet.h
+++ b/layout/style/StyleSheet.h
@@ -8,30 +8,32 @@
#define mozilla_StyleSheet_h
#include "mozilla/css/SheetParsingMode.h"
#include "mozilla/dom/CSSStyleSheetBinding.h"
#include "mozilla/net/ReferrerPolicy.h"
#include "mozilla/StyleBackendType.h"
#include "mozilla/CORSMode.h"
#include "mozilla/ServoUtils.h"
+#include "mozilla/StyleSetHandle.h"
#include "nsICSSLoaderObserver.h"
#include "nsIDOMCSSStyleSheet.h"
#include "nsWrapperCache.h"
class nsIDocument;
class nsINode;
class nsIPrincipal;
class nsCSSRuleProcessor;
namespace mozilla {
class CSSStyleSheet;
class ServoStyleSheet;
+class StyleSetHandle;
struct StyleSheetInfo;
struct CSSStyleSheetInner;
namespace dom {
class CSSRuleList;
class MediaList;
class SRIMetadata;
} // namespace dom
@@ -213,16 +215,19 @@ public:
NS_IMETHOD DeleteRule(uint32_t aIndex) final;
// Changes to sheets should be inside of a WillDirty-DidDirty pair.
// However, the calls do not need to be matched; it's ok to call
// WillDirty and then make no change and skip the DidDirty call.
void WillDirty();
virtual void DidDirty() {}
+ void AddStyleSet(StyleSetHandle aStyleSet);
+ void DropStyleSet(StyleSetHandle aStyleSet);
+
nsresult DeleteRuleFromGroup(css::GroupRule* aGroup, uint32_t aIndex);
nsresult InsertRuleIntoGroup(const nsAString& aRule,
css::GroupRule* aGroup, uint32_t aIndex);
private:
// Get a handle to the various stylesheet bits which live on the 'inner' for
// gecko stylesheets and live on the StyleSheet for Servo stylesheets.
inline StyleSheetInfo& SheetInfo();
@@ -290,16 +295,18 @@ protected:
DocumentAssociationMode mDocumentAssociationMode;
// Core information we get from parsed sheets, which are shared amongst
// StyleSheet clones.
StyleSheetInfo* mInner;
bool mDirty; // has been modified
+ nsTArray<StyleSetHandle> mStyleSets;
+
friend class ::nsCSSRuleProcessor;
// Make CSSStyleSheet and ServoStyleSheet friends so they can access
// protected members of other StyleSheet objects (useful for iterating
// through children).
friend class mozilla::CSSStyleSheet;
friend class mozilla::ServoStyleSheet;
--- a/layout/style/nsStyleSet.cpp
+++ b/layout/style/nsStyleSet.cpp
@@ -591,70 +591,70 @@ nsStyleSet::AppendStyleSheet(SheetType a
{
NS_PRECONDITION(aSheet, "null arg");
NS_ASSERTION(aSheet->IsApplicable(),
"Inapplicable sheet being placed in style set");
bool present = mSheets[aType].RemoveElement(aSheet);
mSheets[aType].AppendElement(aSheet);
if (!present && IsCSSSheetType(aType)) {
- aSheet->AddStyleSet(this);
+ aSheet->AddStyleSet(StyleSetHandle(this));
}
return DirtyRuleProcessors(aType);
}
nsresult
nsStyleSet::PrependStyleSheet(SheetType aType, CSSStyleSheet* aSheet)
{
NS_PRECONDITION(aSheet, "null arg");
NS_ASSERTION(aSheet->IsApplicable(),
"Inapplicable sheet being placed in style set");
bool present = mSheets[aType].RemoveElement(aSheet);
mSheets[aType].InsertElementAt(0, aSheet);
if (!present && IsCSSSheetType(aType)) {
- aSheet->AddStyleSet(this);
+ aSheet->AddStyleSet(StyleSetHandle(this));
}
return DirtyRuleProcessors(aType);
}
nsresult
nsStyleSet::RemoveStyleSheet(SheetType aType, CSSStyleSheet* aSheet)
{
NS_PRECONDITION(aSheet, "null arg");
NS_ASSERTION(aSheet->IsComplete(),
"Incomplete sheet being removed from style set");
if (mSheets[aType].RemoveElement(aSheet)) {
if (IsCSSSheetType(aType)) {
- aSheet->DropStyleSet(this);
+ aSheet->DropStyleSet(StyleSetHandle(this));
}
}
return DirtyRuleProcessors(aType);
}
nsresult
nsStyleSet::ReplaceSheets(SheetType aType,
const nsTArray<RefPtr<CSSStyleSheet>>& aNewSheets)
{
bool cssSheetType = IsCSSSheetType(aType);
if (cssSheetType) {
for (CSSStyleSheet* sheet : mSheets[aType]) {
- sheet->DropStyleSet(this);
+ sheet->DropStyleSet(StyleSetHandle(this));
}
}
mSheets[aType].Clear();
mSheets[aType].AppendElements(aNewSheets);
if (cssSheetType) {
for (CSSStyleSheet* sheet : mSheets[aType]) {
- sheet->AddStyleSet(this);
+ sheet->AddStyleSet(StyleSetHandle(this));
}
}
return DirtyRuleProcessors(aType);
}
nsresult
nsStyleSet::InsertStyleSheetBefore(SheetType aType, CSSStyleSheet* aNewSheet,
@@ -667,17 +667,17 @@ nsStyleSet::InsertStyleSheetBefore(Sheet
bool present = mSheets[aType].RemoveElement(aNewSheet);
int32_t idx = mSheets[aType].IndexOf(aReferenceSheet);
if (idx < 0)
return NS_ERROR_INVALID_ARG;
mSheets[aType].InsertElementAt(idx, aNewSheet);
if (!present && IsCSSSheetType(aType)) {
- aNewSheet->AddStyleSet(this);
+ aNewSheet->AddStyleSet(StyleSetHandle(this));
}
return DirtyRuleProcessors(aType);
}
static inline uint32_t
DirtyBit(SheetType aType)
{
@@ -729,17 +729,17 @@ nsStyleSet::AddDocStyleSheet(CSSStyleShe
nsTArray<RefPtr<CSSStyleSheet>>& sheets = mSheets[type];
bool present = sheets.RemoveElement(aSheet);
size_t index = aDocument->FindDocStyleSheetInsertionPoint(sheets, aSheet);
sheets.InsertElementAt(index, aSheet);
if (!present) {
- aSheet->AddStyleSet(this);
+ aSheet->AddStyleSet(StyleSetHandle(this));
}
return DirtyRuleProcessors(type);
}
void
nsStyleSet::AppendAllXBLStyleSheets(nsTArray<mozilla::CSSStyleSheet*>& aArray) const
{