diff --git a/chrome/nsChromeRegistry.cpp b/chrome/nsChromeRegistry.cpp index 88dc67d3ac9..e12fd9555e2 100644 --- a/chrome/nsChromeRegistry.cpp +++ b/chrome/nsChromeRegistry.cpp @@ -401,14 +401,12 @@ nsresult nsChromeRegistry::RefreshWindow(nsPIDOMWindow* aWindow) nsCOMPtr shell = document->GetShell(); if (shell) { // Reload only the chrome URL agent style sheets. - nsCOMArray agentSheets; + nsTArray> agentSheets; rv = shell->GetAgentStyleSheets(agentSheets); NS_ENSURE_SUCCESS(rv, rv); - nsCOMArray newAgentSheets; - for (int32_t l = 0; l < agentSheets.Count(); ++l) { - nsIStyleSheet *sheet = agentSheets[l]; - + nsTArray> newAgentSheets; + for (CSSStyleSheet* sheet : agentSheets) { nsIURI* uri = sheet->GetSheetURI(); if (IsChromeURI(uri)) { @@ -418,12 +416,12 @@ nsresult nsChromeRegistry::RefreshWindow(nsPIDOMWindow* aWindow) getter_AddRefs(newSheet)); if (NS_FAILED(rv)) return rv; if (newSheet) { - rv = newAgentSheets.AppendObject(newSheet) ? NS_OK : NS_ERROR_FAILURE; + rv = newAgentSheets.AppendElement(newSheet) ? NS_OK : NS_ERROR_FAILURE; if (NS_FAILED(rv)) return rv; } } else { // Just use the same sheet. - rv = newAgentSheets.AppendObject(sheet) ? NS_OK : NS_ERROR_FAILURE; + rv = newAgentSheets.AppendElement(sheet) ? NS_OK : NS_ERROR_FAILURE; if (NS_FAILED(rv)) return rv; } } @@ -432,27 +430,22 @@ nsresult nsChromeRegistry::RefreshWindow(nsPIDOMWindow* aWindow) NS_ENSURE_SUCCESS(rv, rv); } - // Build an array of nsIURIs of style sheets we need to load. - nsCOMArray oldSheets; - nsCOMArray newSheets; - int32_t count = document->GetNumberOfStyleSheets(); - // Iterate over the style sheets. - int32_t i; - for (i = 0; i < count; i++) { - // Get the style sheet - nsIStyleSheet *styleSheet = document->GetStyleSheetAt(i); + // Build an array of style sheets we need to reload. + nsTArray> oldSheets(count); + nsTArray> newSheets(count); - if (!oldSheets.AppendObject(styleSheet)) { - return NS_ERROR_OUT_OF_MEMORY; - } + // Iterate over the style sheets. + for (int32_t i = 0; i < count; i++) { + // Get the style sheet + CSSStyleSheet* styleSheet = document->GetStyleSheetAt(i); + oldSheets.AppendElement(styleSheet); } // Iterate over our old sheets and kick off a sync load of the new // sheet if and only if it's a chrome URL. - for (i = 0; i < count; i++) { - RefPtr sheet = do_QueryObject(oldSheets[i]); + for (CSSStyleSheet* sheet : oldSheets) { nsIURI* uri = sheet ? sheet->GetOriginalURI() : nullptr; if (uri && IsChromeURI(uri)) { @@ -462,11 +455,10 @@ nsresult nsChromeRegistry::RefreshWindow(nsPIDOMWindow* aWindow) // only works by sheer dumb luck. document->LoadChromeSheetSync(uri, false, getter_AddRefs(newSheet)); // Even if it's null, we put in in there. - newSheets.AppendObject(newSheet); - } - else { + newSheets.AppendElement(newSheet); + } else { // Just use the same sheet. - newSheets.AppendObject(sheet); + newSheets.AppendElement(sheet); } } diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp index 0b6e90934e6..0b65f890bd8 100644 --- a/dom/base/nsDOMWindowUtils.cpp +++ b/dom/base/nsDOMWindowUtils.cpp @@ -99,7 +99,6 @@ #include "mozilla/Preferences.h" #include "nsIContentIterator.h" #include "nsIDOMStyleSheet.h" -#include "nsIStyleSheet.h" #include "nsIStyleSheetService.h" #include "nsContentPermissionHelper.h" #include "nsNetUtil.h" @@ -3244,7 +3243,7 @@ nsDOMWindowUtils::AddSheet(nsIDOMStyleSheet *aSheet, uint32_t aSheetType) NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE); nsIDocument::additionalSheetType type = convertSheetType(aSheetType); - nsCOMPtr sheet = do_QueryInterface(aSheet); + RefPtr sheet = do_QueryObject(aSheet); NS_ENSURE_TRUE(sheet, NS_ERROR_FAILURE); if (sheet->GetOwningDocument()) { return NS_ERROR_INVALID_ARG; diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 0d20a0d71a4..f91744d4249 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -725,15 +725,6 @@ nsDOMStyleSheetList::Length() // been added or removed. if (-1 == mLength) { mLength = mDocument->GetNumberOfStyleSheets(); - -#ifdef DEBUG - int32_t i; - for (i = 0; i < mLength; i++) { - nsIStyleSheet *sheet = mDocument->GetStyleSheetAt(i); - nsCOMPtr domss(do_QueryInterface(sheet)); - NS_ASSERTION(domss, "All \"normal\" sheets implement nsIDOMStyleSheet"); - } -#endif } return mLength; } @@ -747,7 +738,7 @@ nsDOMStyleSheetList::IndexedGetter(uint32_t aIndex, bool& aFound) } aFound = true; - nsIStyleSheet *sheet = mDocument->GetStyleSheetAt(aIndex); + CSSStyleSheet* sheet = mDocument->GetStyleSheetAt(aIndex); NS_ASSERTION(sheet, "Must have a sheet"); return static_cast(sheet); @@ -761,27 +752,21 @@ nsDOMStyleSheetList::NodeWillBeDestroyed(const nsINode *aNode) void nsDOMStyleSheetList::StyleSheetAdded(nsIDocument *aDocument, - nsIStyleSheet* aStyleSheet, + CSSStyleSheet* aStyleSheet, bool aDocumentSheet) { if (aDocumentSheet && -1 != mLength) { - nsCOMPtr domss(do_QueryInterface(aStyleSheet)); - if (domss) { - mLength++; - } + mLength++; } } void nsDOMStyleSheetList::StyleSheetRemoved(nsIDocument *aDocument, - nsIStyleSheet* aStyleSheet, + CSSStyleSheet* aStyleSheet, bool aDocumentSheet) { if (aDocumentSheet && -1 != mLength) { - nsCOMPtr domss(do_QueryInterface(aStyleSheet)); - if (domss) { - mLength--; - } + mLength--; } } @@ -1347,7 +1332,7 @@ nsDOMStyleSheetSetList::EnsureFresh() int32_t count = mDocument->GetNumberOfStyleSheets(); nsAutoString title; for (int32_t index = 0; index < count; index++) { - nsIStyleSheet* sheet = mDocument->GetStyleSheetAt(index); + CSSStyleSheet* sheet = mDocument->GetStyleSheetAt(index); NS_ASSERTION(sheet, "Null sheet in sheet list!"); sheet->GetTitle(title); if (!title.IsEmpty() && !mNames.Contains(title) && !Add(title)) { @@ -1624,9 +1609,7 @@ nsDocument::~nsDocument() nsAutoScriptBlocker scriptBlocker; - int32_t indx; // must be signed - uint32_t count = mChildren.ChildCount(); - for (indx = int32_t(count) - 1; indx >= 0; --indx) { + for (uint32_t indx = mChildren.ChildCount(); indx-- != 0; ) { mChildren.ChildAt(indx)->UnbindFromTree(); mChildren.RemoveChildAt(indx); } @@ -1634,9 +1617,8 @@ nsDocument::~nsDocument() mCachedRootElement = nullptr; // Let the stylesheets know we're going away - indx = mStyleSheets.Count(); - while (--indx >= 0) { - mStyleSheets[indx]->SetOwningDocument(nullptr); + for (CSSStyleSheet* sheet : mStyleSheets) { + sheet->SetOwningDocument(nullptr); } if (mAttrStyleSheet) { mAttrStyleSheet->SetOwningDocument(nullptr); @@ -2296,9 +2278,7 @@ void nsDocument::RemoveDocStyleSheetsFromStyleSets() { // The stylesheets should forget us - int32_t indx = mStyleSheets.Count(); - while (--indx >= 0) { - nsIStyleSheet* sheet = mStyleSheets[indx]; + for (CSSStyleSheet* sheet : Reversed(mStyleSheets)) { sheet->SetOwningDocument(nullptr); if (sheet->IsApplicable()) { @@ -2312,12 +2292,12 @@ nsDocument::RemoveDocStyleSheetsFromStyleSets() } void -nsDocument::RemoveStyleSheetsFromStyleSets(nsCOMArray& aSheets, SheetType aType) +nsDocument::RemoveStyleSheetsFromStyleSets( + nsTArray>& aSheets, + SheetType aType) { // The stylesheets should forget us - int32_t indx = aSheets.Count(); - while (--indx >= 0) { - nsIStyleSheet* sheet = aSheets[indx]; + for (CSSStyleSheet* sheet : Reversed(aSheets)) { sheet->SetOwningDocument(nullptr); if (sheet->IsApplicable()) { @@ -2326,10 +2306,8 @@ nsDocument::RemoveStyleSheetsFromStyleSets(nsCOMArray& aSheets, S shell->StyleSet()->RemoveStyleSheet(aType, sheet); } } - // XXX Tell observers? } - } void @@ -2379,21 +2357,13 @@ nsDocument::ResetStylesheetsToURI(nsIURI* aURI) } } -static bool -AppendAuthorSheet(nsIStyleSheet *aSheet, void *aData) -{ - nsStyleSet *styleSet = static_cast(aData); - styleSet->AppendStyleSheet(SheetType::Doc, aSheet); - return true; -} - static void AppendSheetsToStyleSet(nsStyleSet* aStyleSet, - const nsCOMArray& aSheets, + const nsTArray>& aSheets, SheetType aType) { - for (int32_t i = aSheets.Count() - 1; i >= 0; --i) { - aStyleSet->AppendStyleSheet(aType, aSheets[i]); + for (CSSStyleSheet* sheet : Reversed(aSheets)) { + aStyleSet->AppendStyleSheet(aType, sheet); } } @@ -2405,9 +2375,7 @@ nsDocument::FillStyleSet(nsStyleSet* aStyleSet) NS_PRECONDITION(aStyleSet->SheetCount(SheetType::Doc) == 0, "Style set already has document sheets?"); - int32_t i; - for (i = mStyleSheets.Count() - 1; i >= 0; --i) { - nsIStyleSheet* sheet = mStyleSheets[i]; + for (CSSStyleSheet* sheet : Reversed(mStyleSheets)) { if (sheet->IsApplicable()) { aStyleSet->AddDocStyleSheet(sheet, this); } @@ -2415,13 +2383,13 @@ nsDocument::FillStyleSet(nsStyleSet* aStyleSet) nsStyleSheetService *sheetService = nsStyleSheetService::GetInstance(); if (sheetService) { - sheetService->AuthorStyleSheets()->EnumerateForwards(AppendAuthorSheet, - aStyleSet); + for (CSSStyleSheet* sheet : *sheetService->AuthorStyleSheets()) { + aStyleSet->AppendStyleSheet(SheetType::Doc, sheet); + } } // Iterate backwards to maintain order - for (i = mOnDemandBuiltInUASheets.Count() - 1; i >= 0; --i) { - nsIStyleSheet* sheet = mOnDemandBuiltInUASheets[i]; + for (CSSStyleSheet* sheet : Reversed(mOnDemandBuiltInUASheets)) { if (sheet->IsApplicable()) { aStyleSet->PrependStyleSheet(SheetType::Agent, sheet); } @@ -4017,8 +3985,7 @@ nsDocument::RemoveChildAt(uint32_t aIndex, bool aNotify) void nsDocument::EnsureOnDemandBuiltInUASheet(CSSStyleSheet* aSheet) { - // Contains() takes nsISupport*, so annoyingly we have to cast here - if (mOnDemandBuiltInUASheets.Contains(static_cast(aSheet))) { + if (mOnDemandBuiltInUASheets.Contains(aSheet)) { return; } BeginUpdate(UPDATE_STYLE); @@ -4029,8 +3996,7 @@ nsDocument::EnsureOnDemandBuiltInUASheet(CSSStyleSheet* aSheet) void nsDocument::AddOnDemandBuiltInUASheet(CSSStyleSheet* aSheet) { - // Contains() takes nsISupport*, so annoyingly we have to cast here - MOZ_ASSERT(!mOnDemandBuiltInUASheets.Contains(static_cast(aSheet))); + MOZ_ASSERT(!mOnDemandBuiltInUASheets.Contains(aSheet)); // Prepend here so that we store the sheets in mOnDemandBuiltInUASheets in // the same order that they should end up in the style set. @@ -4054,24 +4020,23 @@ nsDocument::AddOnDemandBuiltInUASheet(CSSStyleSheet* aSheet) int32_t nsDocument::GetNumberOfStyleSheets() const { - return mStyleSheets.Count(); + return mStyleSheets.Length(); } -nsIStyleSheet* +CSSStyleSheet* nsDocument::GetStyleSheetAt(int32_t aIndex) const { - NS_ENSURE_TRUE(0 <= aIndex && aIndex < mStyleSheets.Count(), nullptr); - return mStyleSheets[aIndex]; + return mStyleSheets.SafeElementAt(aIndex, nullptr); } int32_t -nsDocument::GetIndexOfStyleSheet(nsIStyleSheet* aSheet) const +nsDocument::GetIndexOfStyleSheet(CSSStyleSheet* aSheet) const { return mStyleSheets.IndexOf(aSheet); } void -nsDocument::AddStyleSheetToStyleSets(nsIStyleSheet* aSheet) +nsDocument::AddStyleSheetToStyleSets(CSSStyleSheet* aSheet) { nsCOMPtr shell = GetShell(); if (shell) { @@ -4081,15 +4046,10 @@ nsDocument::AddStyleSheetToStyleSets(nsIStyleSheet* aSheet) #define DO_STYLESHEET_NOTIFICATION(className, type, memberName, argName) \ do { \ - RefPtr cssSheet = do_QueryObject(aSheet); \ - if (!cssSheet) { \ - return; \ - } \ - \ className##Init init; \ init.mBubbles = true; \ init.mCancelable = true; \ - init.mStylesheet = cssSheet; \ + init.mStylesheet = aSheet; \ init.memberName = argName; \ \ RefPtr event = \ @@ -4103,7 +4063,7 @@ nsDocument::AddStyleSheetToStyleSets(nsIStyleSheet* aSheet) } while (0); void -nsDocument::NotifyStyleSheetAdded(nsIStyleSheet* aSheet, bool aDocumentSheet) +nsDocument::NotifyStyleSheetAdded(CSSStyleSheet* aSheet, bool aDocumentSheet) { NS_DOCUMENT_NOTIFY_OBSERVERS(StyleSheetAdded, (this, aSheet, aDocumentSheet)); @@ -4116,7 +4076,7 @@ nsDocument::NotifyStyleSheetAdded(nsIStyleSheet* aSheet, bool aDocumentSheet) } void -nsDocument::NotifyStyleSheetRemoved(nsIStyleSheet* aSheet, bool aDocumentSheet) +nsDocument::NotifyStyleSheetRemoved(CSSStyleSheet* aSheet, bool aDocumentSheet) { NS_DOCUMENT_NOTIFY_OBSERVERS(StyleSheetRemoved, (this, aSheet, aDocumentSheet)); @@ -4129,10 +4089,10 @@ nsDocument::NotifyStyleSheetRemoved(nsIStyleSheet* aSheet, bool aDocumentSheet) } void -nsDocument::AddStyleSheet(nsIStyleSheet* aSheet) +nsDocument::AddStyleSheet(CSSStyleSheet* aSheet) { NS_PRECONDITION(aSheet, "null arg"); - mStyleSheets.AppendObject(aSheet); + mStyleSheets.AppendElement(aSheet); aSheet->SetOwningDocument(this); if (aSheet->IsApplicable()) { @@ -4143,7 +4103,7 @@ nsDocument::AddStyleSheet(nsIStyleSheet* aSheet) } void -nsDocument::RemoveStyleSheetFromStyleSets(nsIStyleSheet* aSheet) +nsDocument::RemoveStyleSheetFromStyleSets(CSSStyleSheet* aSheet) { nsCOMPtr shell = GetShell(); if (shell) { @@ -4152,12 +4112,12 @@ nsDocument::RemoveStyleSheetFromStyleSets(nsIStyleSheet* aSheet) } void -nsDocument::RemoveStyleSheet(nsIStyleSheet* aSheet) +nsDocument::RemoveStyleSheet(CSSStyleSheet* aSheet) { NS_PRECONDITION(aSheet, "null arg"); - nsCOMPtr sheet = aSheet; // hold ref so it won't die too soon + RefPtr sheet = aSheet; // hold ref so it won't die too soon - if (!mStyleSheets.RemoveObject(aSheet)) { + if (!mStyleSheets.RemoveElement(aSheet)) { NS_ASSERTION(mInUnlinkOrDeletion, "stylesheet not found"); return; } @@ -4174,17 +4134,17 @@ nsDocument::RemoveStyleSheet(nsIStyleSheet* aSheet) } void -nsDocument::UpdateStyleSheets(nsCOMArray& aOldSheets, - nsCOMArray& aNewSheets) +nsDocument::UpdateStyleSheets(nsTArray>& aOldSheets, + nsTArray>& aNewSheets) { BeginUpdate(UPDATE_STYLE); // XXX Need to set the sheet on the ownernode, if any - NS_PRECONDITION(aOldSheets.Count() == aNewSheets.Count(), + NS_PRECONDITION(aOldSheets.Length() == aNewSheets.Length(), "The lists must be the same length!"); - int32_t count = aOldSheets.Count(); + int32_t count = aOldSheets.Length(); - nsCOMPtr oldSheet; + RefPtr oldSheet; int32_t i; for (i = 0; i < count; ++i) { oldSheet = aOldSheets[i]; @@ -4195,9 +4155,9 @@ nsDocument::UpdateStyleSheets(nsCOMArray& aOldSheets, RemoveStyleSheet(oldSheet); // This does the right notifications // Now put the new one in its place. If it's null, just ignore it. - nsIStyleSheet* newSheet = aNewSheets[i]; + CSSStyleSheet* newSheet = aNewSheets[i]; if (newSheet) { - mStyleSheets.InsertObjectAt(newSheet, oldIndex); + mStyleSheets.InsertElementAt(oldIndex, newSheet); newSheet->SetOwningDocument(this); if (newSheet->IsApplicable()) { AddStyleSheetToStyleSets(newSheet); @@ -4211,10 +4171,11 @@ nsDocument::UpdateStyleSheets(nsCOMArray& aOldSheets, } void -nsDocument::InsertStyleSheetAt(nsIStyleSheet* aSheet, int32_t aIndex) +nsDocument::InsertStyleSheetAt(CSSStyleSheet* aSheet, int32_t aIndex) { NS_PRECONDITION(aSheet, "null ptr"); - mStyleSheets.InsertObjectAt(aSheet, aIndex); + + mStyleSheets.InsertElementAt(aIndex, aSheet); aSheet->SetOwningDocument(this); @@ -4227,13 +4188,13 @@ nsDocument::InsertStyleSheetAt(nsIStyleSheet* aSheet, int32_t aIndex) void -nsDocument::SetStyleSheetApplicableState(nsIStyleSheet* aSheet, +nsDocument::SetStyleSheetApplicableState(CSSStyleSheet* aSheet, bool aApplicable) { NS_PRECONDITION(aSheet, "null arg"); // If we're actually in the document style sheet list - if (-1 != mStyleSheets.IndexOf(aSheet)) { + if (mStyleSheets.IndexOf(aSheet) != mStyleSheets.NoIndex) { if (aApplicable) { AddStyleSheetToStyleSets(aSheet); } else { @@ -4294,9 +4255,9 @@ ConvertAdditionalSheetType(nsIDocument::additionalSheetType aType) } static int32_t -FindSheet(const nsCOMArray& aSheets, nsIURI* aSheetURI) +FindSheet(const nsTArray>& aSheets, nsIURI* aSheetURI) { - for (int32_t i = aSheets.Count() - 1; i >= 0; i-- ) { + for (int32_t i = aSheets.Length() - 1; i >= 0; i-- ) { bool bEqual; nsIURI* uri = aSheets[i]->GetSheetURI(); @@ -4350,7 +4311,7 @@ nsDocument::LoadAdditionalStyleSheet(additionalSheetType aType, } nsresult -nsDocument::AddAdditionalStyleSheet(additionalSheetType aType, nsIStyleSheet* aSheet) +nsDocument::AddAdditionalStyleSheet(additionalSheetType aType, CSSStyleSheet* aSheet) { if (mAdditionalSheets[aType].Contains(aSheet)) return NS_ERROR_INVALID_ARG; @@ -4358,7 +4319,7 @@ nsDocument::AddAdditionalStyleSheet(additionalSheetType aType, nsIStyleSheet* aS if (!aSheet->IsApplicable()) return NS_ERROR_INVALID_ARG; - mAdditionalSheets[aType].AppendObject(aSheet); + mAdditionalSheets[aType].AppendElement(aSheet); BeginUpdate(UPDATE_STYLE); nsCOMPtr shell = GetShell(); @@ -4379,12 +4340,12 @@ nsDocument::RemoveAdditionalStyleSheet(additionalSheetType aType, nsIURI* aSheet { MOZ_ASSERT(aSheetURI); - nsCOMArray& sheets = mAdditionalSheets[aType]; + nsTArray>& sheets = mAdditionalSheets[aType]; int32_t i = FindSheet(mAdditionalSheets[aType], aSheetURI); if (i >= 0) { - nsCOMPtr sheetRef = sheets[i]; - sheets.RemoveObjectAt(i); + RefPtr sheetRef = sheets[i]; + sheets.RemoveElementAt(i); BeginUpdate(UPDATE_STYLE); if (!mIsGoingAway) { @@ -4405,10 +4366,10 @@ nsDocument::RemoveAdditionalStyleSheet(additionalSheetType aType, nsIURI* aSheet } } -nsIStyleSheet* +CSSStyleSheet* nsDocument::FirstAdditionalAuthorSheet() { - return mAdditionalSheets[eAuthorSheet].SafeObjectAt(0); + return mAdditionalSheets[eAuthorSheet].SafeElementAt(0, nullptr); } nsIGlobalObject* @@ -5155,7 +5116,7 @@ nsDocument::DocumentStatesChanged(EventStates aStateMask) } void -nsDocument::StyleRuleChanged(nsIStyleSheet* aSheet, +nsDocument::StyleRuleChanged(CSSStyleSheet* aSheet, css::Rule* aOldStyleRule, css::Rule* aNewStyleRule) { @@ -5173,7 +5134,7 @@ nsDocument::StyleRuleChanged(nsIStyleSheet* aSheet, } void -nsDocument::StyleRuleAdded(nsIStyleSheet* aSheet, +nsDocument::StyleRuleAdded(CSSStyleSheet* aSheet, css::Rule* aStyleRule) { NS_DOCUMENT_NOTIFY_OBSERVERS(StyleRuleAdded, @@ -5189,7 +5150,7 @@ nsDocument::StyleRuleAdded(nsIStyleSheet* aSheet, } void -nsDocument::StyleRuleRemoved(nsIStyleSheet* aSheet, +nsDocument::StyleRuleRemoved(CSSStyleSheet* aSheet, css::Rule* aStyleRule) { NS_DOCUMENT_NOTIFY_OBSERVERS(StyleRuleRemoved, @@ -6428,13 +6389,11 @@ nsIDocument::GetSelectedStyleSheetSet(nsAString& aSheetSet) int32_t count = GetNumberOfStyleSheets(); nsAutoString title; for (int32_t index = 0; index < count; index++) { - nsIStyleSheet* sheet = GetStyleSheetAt(index); + CSSStyleSheet* sheet = GetStyleSheetAt(index); NS_ASSERTION(sheet, "Null sheet in sheet list!"); - nsCOMPtr domSheet = do_QueryInterface(sheet); - NS_ASSERTION(domSheet, "Sheet must QI to nsIDOMStyleSheet"); bool disabled; - domSheet->GetDisabled(&disabled); + sheet->GetDisabled(&disabled); if (disabled) { // Disabled sheets don't affect the currently selected set continue; @@ -6544,7 +6503,7 @@ nsDocument::EnableStyleSheetsForSetInternal(const nsAString& aSheetSet, int32_t count = GetNumberOfStyleSheets(); nsAutoString title; for (int32_t index = 0; index < count; index++) { - nsIStyleSheet* sheet = GetStyleSheetAt(index); + CSSStyleSheet* sheet = GetStyleSheetAt(index); NS_ASSERTION(sheet, "Null sheet in sheet list!"); sheet->GetTitle(title); if (!title.IsEmpty()) { @@ -10173,7 +10132,7 @@ nsIDocument::CreateStaticClone(nsIDocShell* aCloneContainer) int32_t sheetsCount = GetNumberOfStyleSheets(); for (int32_t i = 0; i < sheetsCount; ++i) { - RefPtr sheet = do_QueryObject(GetStyleSheetAt(i)); + RefPtr sheet = GetStyleSheetAt(i); if (sheet) { if (sheet->IsApplicable()) { RefPtr clonedSheet = @@ -10186,11 +10145,8 @@ nsIDocument::CreateStaticClone(nsIDocShell* aCloneContainer) } } - sheetsCount = thisAsDoc->mOnDemandBuiltInUASheets.Count(); // Iterate backwards to maintain order - for (int32_t i = sheetsCount - 1; i >= 0; --i) { - RefPtr sheet = - do_QueryObject(thisAsDoc->mOnDemandBuiltInUASheets[i]); + for (CSSStyleSheet* sheet : Reversed(thisAsDoc->mOnDemandBuiltInUASheets)) { if (sheet) { if (sheet->IsApplicable()) { RefPtr clonedSheet = @@ -12278,7 +12234,7 @@ nsDocument::OnAppThemeChanged() } for (int32_t i = 0; i < GetNumberOfStyleSheets(); i++) { - RefPtr sheet = do_QueryObject(GetStyleSheetAt(i)); + RefPtr sheet = GetStyleSheetAt(i); if (!sheet) { continue; } @@ -12645,15 +12601,19 @@ nsIDocument::DocAddSizeOfIncludingThis(nsWindowSizes* aWindowSizes) const } static size_t -SizeOfStyleSheetsElementIncludingThis(nsIStyleSheet* aStyleSheet, - MallocSizeOf aMallocSizeOf, - void* aData) +SizeOfOwnedSheetArrayExcludingThis(const nsTArray>& aSheets, + MallocSizeOf aMallocSizeOf) { - if (!aStyleSheet->GetOwningDocument()) { - // Avoid over-reporting shared sheets. - return 0; + size_t n = 0; + n += aSheets.ShallowSizeOfExcludingThis(aMallocSizeOf); + for (CSSStyleSheet* sheet : aSheets) { + if (!sheet->GetOwningDocument()) { + // Avoid over-reporting shared sheets. + continue; + } + n += sheet->SizeOfIncludingThis(aMallocSizeOf); } - return aStyleSheet->SizeOfIncludingThis(aMallocSizeOf); + return n; } size_t @@ -12704,26 +12664,18 @@ nsDocument::DocAddSizeOfExcludingThis(nsWindowSizes* aWindowSizes) const } aWindowSizes->mStyleSheetsSize += - mStyleSheets.SizeOfExcludingThis(SizeOfStyleSheetsElementIncludingThis, - aWindowSizes->mMallocSizeOf); + SizeOfOwnedSheetArrayExcludingThis(mStyleSheets, + aWindowSizes->mMallocSizeOf); // Note that we do not own the sheets pointed to by mOnDemandBuiltInUASheets - // (the nsLayoutStyleSheetCache singleton does) so pass nullptr as the - // aSizeOfElementIncludingThis callback argument. + // (the nsLayoutStyleSheetCache singleton does). aWindowSizes->mStyleSheetsSize += - mOnDemandBuiltInUASheets.SizeOfExcludingThis(nullptr, - aWindowSizes->mMallocSizeOf); - aWindowSizes->mStyleSheetsSize += - mAdditionalSheets[eAgentSheet]. - SizeOfExcludingThis(SizeOfStyleSheetsElementIncludingThis, - aWindowSizes->mMallocSizeOf); - aWindowSizes->mStyleSheetsSize += - mAdditionalSheets[eUserSheet]. - SizeOfExcludingThis(SizeOfStyleSheetsElementIncludingThis, - aWindowSizes->mMallocSizeOf); - aWindowSizes->mStyleSheetsSize += - mAdditionalSheets[eAuthorSheet]. - SizeOfExcludingThis(SizeOfStyleSheetsElementIncludingThis, - aWindowSizes->mMallocSizeOf); + mOnDemandBuiltInUASheets.ShallowSizeOfExcludingThis( + aWindowSizes->mMallocSizeOf); + for (auto& sheetArray : mAdditionalSheets) { + aWindowSizes->mStyleSheetsSize += + SizeOfOwnedSheetArrayExcludingThis(sheetArray, + aWindowSizes->mMallocSizeOf); + } // Lumping in the loader with the style-sheets size is not ideal, // but most of the things in there are in fact stylesheets, so it // doesn't seem worthwhile to separate it out. diff --git a/dom/base/nsDocument.h b/dom/base/nsDocument.h index 2cdeebd60c5..833815d09cb 100644 --- a/dom/base/nsDocument.h +++ b/dom/base/nsDocument.h @@ -801,24 +801,29 @@ public: * These are ordered, highest priority last */ virtual int32_t GetNumberOfStyleSheets() const override; - virtual nsIStyleSheet* GetStyleSheetAt(int32_t aIndex) const override; - virtual int32_t GetIndexOfStyleSheet(nsIStyleSheet* aSheet) const override; - virtual void AddStyleSheet(nsIStyleSheet* aSheet) override; - virtual void RemoveStyleSheet(nsIStyleSheet* aSheet) override; + virtual mozilla::CSSStyleSheet* GetStyleSheetAt(int32_t aIndex) const override; + virtual int32_t GetIndexOfStyleSheet(mozilla::CSSStyleSheet* aSheet) const override; + virtual void AddStyleSheet(mozilla::CSSStyleSheet* aSheet) override; + virtual void RemoveStyleSheet(mozilla::CSSStyleSheet* aSheet) override; - virtual void UpdateStyleSheets(nsCOMArray& aOldSheets, - nsCOMArray& aNewSheets) override; - virtual void AddStyleSheetToStyleSets(nsIStyleSheet* aSheet); - virtual void RemoveStyleSheetFromStyleSets(nsIStyleSheet* aSheet); + virtual void UpdateStyleSheets( + nsTArray>& aOldSheets, + nsTArray>& aNewSheets) override; + virtual void AddStyleSheetToStyleSets(mozilla::CSSStyleSheet* aSheet); + virtual void RemoveStyleSheetFromStyleSets(mozilla::CSSStyleSheet* aSheet); - virtual void InsertStyleSheetAt(nsIStyleSheet* aSheet, int32_t aIndex) override; - virtual void SetStyleSheetApplicableState(nsIStyleSheet* aSheet, + virtual void InsertStyleSheetAt(mozilla::CSSStyleSheet* aSheet, + int32_t aIndex) override; + virtual void SetStyleSheetApplicableState(mozilla::CSSStyleSheet* aSheet, bool aApplicable) override; - virtual nsresult LoadAdditionalStyleSheet(additionalSheetType aType, nsIURI* aSheetURI) override; - virtual nsresult AddAdditionalStyleSheet(additionalSheetType aType, nsIStyleSheet* aSheet) override; - virtual void RemoveAdditionalStyleSheet(additionalSheetType aType, nsIURI* sheetURI) override; - virtual nsIStyleSheet* FirstAdditionalAuthorSheet() override; + virtual nsresult LoadAdditionalStyleSheet(additionalSheetType aType, + nsIURI* aSheetURI) override; + virtual nsresult AddAdditionalStyleSheet(additionalSheetType aType, + mozilla::CSSStyleSheet* aSheet) override; + virtual void RemoveAdditionalStyleSheet(additionalSheetType aType, + nsIURI* sheetURI) override; + virtual mozilla::CSSStyleSheet* FirstAdditionalAuthorSheet() override; virtual nsIChannel* GetChannel() const override { return mChannel; @@ -878,12 +883,12 @@ public: virtual void DocumentStatesChanged( mozilla::EventStates aStateMask) override; - virtual void StyleRuleChanged(nsIStyleSheet* aStyleSheet, + virtual void StyleRuleChanged(mozilla::CSSStyleSheet* aStyleSheet, mozilla::css::Rule* aOldStyleRule, mozilla::css::Rule* aNewStyleRule) override; - virtual void StyleRuleAdded(nsIStyleSheet* aStyleSheet, + virtual void StyleRuleAdded(mozilla::CSSStyleSheet* aStyleSheet, mozilla::css::Rule* aStyleRule) override; - virtual void StyleRuleRemoved(nsIStyleSheet* aStyleSheet, + virtual void StyleRuleRemoved(mozilla::CSSStyleSheet* aStyleSheet, mozilla::css::Rule* aStyleRule) override; virtual void FlushPendingNotifications(mozFlushType aType) override; @@ -1494,8 +1499,9 @@ protected: nsCompatibility aCompatMode); void RemoveDocStyleSheetsFromStyleSets(); - void RemoveStyleSheetsFromStyleSets(nsCOMArray& aSheets, - mozilla::SheetType aType); + void RemoveStyleSheetsFromStyleSets( + nsTArray>& aSheets, + mozilla::SheetType aType); void ResetStylesheetsToURI(nsIURI* aURI); void FillStyleSet(nsStyleSet* aStyleSet); @@ -1548,9 +1554,9 @@ protected: // EndLoad() has already happened. nsWeakPtr mWeakSink; - nsCOMArray mStyleSheets; - nsCOMArray mOnDemandBuiltInUASheets; - nsCOMArray mAdditionalSheets[AdditionalSheetTypeCount]; + nsTArray> mStyleSheets; + nsTArray> mOnDemandBuiltInUASheets; + nsTArray> mAdditionalSheets[AdditionalSheetTypeCount]; // Array of observers nsTObserverArray mObservers; @@ -1709,8 +1715,8 @@ private: friend class nsUnblockOnloadEvent; // Recomputes the visibility state but doesn't set the new value. mozilla::dom::VisibilityState GetVisibilityState() const; - void NotifyStyleSheetAdded(nsIStyleSheet* aSheet, bool aDocumentSheet); - void NotifyStyleSheetRemoved(nsIStyleSheet* aSheet, bool aDocumentSheet); + void NotifyStyleSheetAdded(mozilla::CSSStyleSheet* aSheet, bool aDocumentSheet); + void NotifyStyleSheetRemoved(mozilla::CSSStyleSheet* aSheet, bool aDocumentSheet); void PostUnblockOnloadEvent(); void DoUnblockOnload(); diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h index 92ab63868a9..119e36e4c1b 100644 --- a/dom/base/nsIDocument.h +++ b/dom/base/nsIDocument.h @@ -72,7 +72,6 @@ class nsIRequest; class nsIRunnable; class nsIStreamListener; class nsIStructuredCloneContainer; -class nsIStyleSheet; class nsIURI; class nsIVariant; class nsLocation; @@ -156,8 +155,8 @@ typedef CallbackObjectHolder NodeFilterHolder; } // namespace mozilla #define NS_IDOCUMENT_IID \ -{ 0x4307abe8, 0x5386, 0x4024, \ - { 0xa2, 0xfe, 0x4a, 0x80, 0xe8, 0x47, 0x46, 0x90 } } +{ 0xecc9e376, 0x6c31, 0x4f04, \ + { 0xbe, 0xde, 0xd6, 0x27, 0x61, 0xd7, 0x00, 0x84 } } // Enum for requesting a particular type of document when creating a doc enum DocumentFlavor { @@ -925,7 +924,7 @@ public: * @return the stylesheet at aIndex. Null if aIndex is out of range. * @throws no exceptions */ - virtual nsIStyleSheet* GetStyleSheetAt(int32_t aIndex) const = 0; + virtual mozilla::CSSStyleSheet* GetStyleSheetAt(int32_t aIndex) const = 0; /** * Insert a sheet at a particular spot in the stylesheet list (zero-based) @@ -934,7 +933,8 @@ public: * adjusted for the "special" sheets. * @throws no exceptions */ - virtual void InsertStyleSheetAt(nsIStyleSheet* aSheet, int32_t aIndex) = 0; + virtual void InsertStyleSheetAt(mozilla::CSSStyleSheet* aSheet, + int32_t aIndex) = 0; /** * Get the index of a particular stylesheet. This will _always_ @@ -942,7 +942,7 @@ public: * @param aSheet the sheet to get the index of * @return aIndex the index of the sheet in the full list */ - virtual int32_t GetIndexOfStyleSheet(nsIStyleSheet* aSheet) const = 0; + virtual int32_t GetIndexOfStyleSheet(mozilla::CSSStyleSheet* aSheet) const = 0; /** * Replace the stylesheets in aOldSheets with the stylesheets in @@ -952,24 +952,25 @@ public: * may be null; if so the corresponding sheets in the first list * will simply be removed. */ - virtual void UpdateStyleSheets(nsCOMArray& aOldSheets, - nsCOMArray& aNewSheets) = 0; + virtual void UpdateStyleSheets( + nsTArray>& aOldSheets, + nsTArray>& aNewSheets) = 0; /** * Add a stylesheet to the document */ - virtual void AddStyleSheet(nsIStyleSheet* aSheet) = 0; + virtual void AddStyleSheet(mozilla::CSSStyleSheet* aSheet) = 0; /** * Remove a stylesheet from the document */ - virtual void RemoveStyleSheet(nsIStyleSheet* aSheet) = 0; + virtual void RemoveStyleSheet(mozilla::CSSStyleSheet* aSheet) = 0; /** * Notify the document that the applicable state of the sheet changed * and that observers should be notified and style sets updated */ - virtual void SetStyleSheetApplicableState(nsIStyleSheet* aSheet, + virtual void SetStyleSheetApplicableState(mozilla::CSSStyleSheet* aSheet, bool aApplicable) = 0; enum additionalSheetType { @@ -979,10 +980,13 @@ public: AdditionalSheetTypeCount }; - virtual nsresult LoadAdditionalStyleSheet(additionalSheetType aType, nsIURI* aSheetURI) = 0; - virtual nsresult AddAdditionalStyleSheet(additionalSheetType aType, nsIStyleSheet* aSheet) = 0; - virtual void RemoveAdditionalStyleSheet(additionalSheetType aType, nsIURI* sheetURI) = 0; - virtual nsIStyleSheet* FirstAdditionalAuthorSheet() = 0; + virtual nsresult LoadAdditionalStyleSheet(additionalSheetType aType, + nsIURI* aSheetURI) = 0; + virtual nsresult AddAdditionalStyleSheet(additionalSheetType aType, + mozilla::CSSStyleSheet* aSheet) = 0; + virtual void RemoveAdditionalStyleSheet(additionalSheetType aType, + nsIURI* sheetURI) = 0; + virtual mozilla::CSSStyleSheet* FirstAdditionalAuthorSheet() = 0; /** * Get this document's CSSLoader. This is guaranteed to not return null. @@ -1285,12 +1289,12 @@ public: // Observation hooks for style data to propagate notifications // to document observers - virtual void StyleRuleChanged(nsIStyleSheet* aStyleSheet, + virtual void StyleRuleChanged(mozilla::CSSStyleSheet* aStyleSheet, mozilla::css::Rule* aOldStyleRule, mozilla::css::Rule* aNewStyleRule) = 0; - virtual void StyleRuleAdded(nsIStyleSheet* aStyleSheet, + virtual void StyleRuleAdded(mozilla::CSSStyleSheet* aStyleSheet, mozilla::css::Rule* aStyleRule) = 0; - virtual void StyleRuleRemoved(nsIStyleSheet* aStyleSheet, + virtual void StyleRuleRemoved(mozilla::CSSStyleSheet* aStyleSheet, mozilla::css::Rule* aStyleRule) = 0; /** diff --git a/dom/base/nsIDocumentObserver.h b/dom/base/nsIDocumentObserver.h index 6b3d6d1893d..b4978c48214 100644 --- a/dom/base/nsIDocumentObserver.h +++ b/dom/base/nsIDocumentObserver.h @@ -11,18 +11,18 @@ #include "nsIMutationObserver.h" class nsIContent; -class nsIStyleSheet; class nsIDocument; namespace mozilla { +class CSSStyleSheet; namespace css { class Rule; } // namespace css } // namespace mozilla #define NS_IDOCUMENT_OBSERVER_IID \ -{ 0xce1d53d0, 0x4739, 0x44e5, \ - { 0xb4, 0xae, 0x60, 0xe8, 0x82, 0xcb, 0x73, 0x1b } } +{ 0x21c8ad67, 0x3a7d, 0x4881, \ + { 0xa5, 0x43, 0xcb, 0xa9, 0xbb, 0xe4, 0x9e, 0x39 } } typedef uint32_t nsUpdateType; @@ -102,7 +102,7 @@ public: * false if sheet is not (i.e., UA or user sheet) */ virtual void StyleSheetAdded(nsIDocument *aDocument, - nsIStyleSheet* aStyleSheet, + mozilla::CSSStyleSheet* aStyleSheet, bool aDocumentSheet) = 0; /** @@ -117,7 +117,7 @@ public: * false if sheet is not (i.e., UA or user sheet) */ virtual void StyleSheetRemoved(nsIDocument *aDocument, - nsIStyleSheet* aStyleSheet, + mozilla::CSSStyleSheet* aStyleSheet, bool aDocumentSheet) = 0; /** @@ -133,7 +133,7 @@ public: * it is not applicable */ virtual void StyleSheetApplicableStateChanged(nsIDocument *aDocument, - nsIStyleSheet* aStyleSheet, + mozilla::CSSStyleSheet* aStyleSheet, bool aApplicable) = 0; /** @@ -160,7 +160,7 @@ public: * @param aNewStyleRule The rule being added. */ virtual void StyleRuleChanged(nsIDocument *aDocument, - nsIStyleSheet* aStyleSheet, + mozilla::CSSStyleSheet* aStyleSheet, mozilla::css::Rule* aOldStyleRule, mozilla::css::Rule* aNewStyleRule) = 0; @@ -176,7 +176,7 @@ public: * @param aStyleRule the rule that was added */ virtual void StyleRuleAdded(nsIDocument *aDocument, - nsIStyleSheet* aStyleSheet, + mozilla::CSSStyleSheet* aStyleSheet, mozilla::css::Rule* aStyleRule) = 0; /** @@ -191,7 +191,7 @@ public: * @param aStyleRule the rule that was removed */ virtual void StyleRuleRemoved(nsIDocument *aDocument, - nsIStyleSheet* aStyleSheet, + mozilla::CSSStyleSheet* aStyleSheet, mozilla::css::Rule* aStyleRule) = 0; }; @@ -221,33 +221,34 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsIDocumentObserver, NS_IDOCUMENT_OBSERVER_IID) #define NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETADDED \ virtual void StyleSheetAdded(nsIDocument* aDocument, \ - nsIStyleSheet* aStyleSheet, \ + mozilla::CSSStyleSheet* aStyleSheet, \ bool aDocumentSheet) override; #define NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETREMOVED \ virtual void StyleSheetRemoved(nsIDocument* aDocument, \ - nsIStyleSheet* aStyleSheet, \ + mozilla::CSSStyleSheet* aStyleSheet, \ bool aDocumentSheet) override; #define NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETAPPLICABLESTATECHANGED \ - virtual void StyleSheetApplicableStateChanged(nsIDocument* aDocument, \ - nsIStyleSheet* aStyleSheet,\ - bool aApplicable) override; + virtual void StyleSheetApplicableStateChanged( \ + nsIDocument* aDocument, \ + mozilla::CSSStyleSheet* aStyleSheet, \ + bool aApplicable) override; #define NS_DECL_NSIDOCUMENTOBSERVER_STYLERULECHANGED \ virtual void StyleRuleChanged(nsIDocument* aDocument, \ - nsIStyleSheet* aStyleSheet, \ + mozilla::CSSStyleSheet* aStyleSheet, \ mozilla::css::Rule* aOldStyleRule, \ mozilla::css::Rule* aNewStyleRule) override; #define NS_DECL_NSIDOCUMENTOBSERVER_STYLERULEADDED \ virtual void StyleRuleAdded(nsIDocument* aDocument, \ - nsIStyleSheet* aStyleSheet, \ + mozilla::CSSStyleSheet* aStyleSheet, \ mozilla::css::Rule* aStyleRule) override; #define NS_DECL_NSIDOCUMENTOBSERVER_STYLERULEREMOVED \ virtual void StyleRuleRemoved(nsIDocument* aDocument, \ - nsIStyleSheet* aStyleSheet, \ + mozilla::CSSStyleSheet* aStyleSheet, \ mozilla::css::Rule* aStyleRule) override; #define NS_DECL_NSIDOCUMENTOBSERVER \ @@ -307,38 +308,38 @@ NS_IMPL_NSIMUTATIONOBSERVER_CONTENT(_class) #define NS_IMPL_NSIDOCUMENTOBSERVER_STYLE_STUB(_class) \ void \ _class::StyleSheetAdded(nsIDocument* aDocument, \ - nsIStyleSheet* aStyleSheet, \ - bool aDocumentSheet) \ + mozilla::CSSStyleSheet* aStyleSheet, \ + bool aDocumentSheet) \ { \ } \ void \ _class::StyleSheetRemoved(nsIDocument* aDocument, \ - nsIStyleSheet* aStyleSheet, \ - bool aDocumentSheet) \ + mozilla::CSSStyleSheet* aStyleSheet, \ + bool aDocumentSheet) \ { \ } \ void \ _class::StyleSheetApplicableStateChanged(nsIDocument* aDocument, \ - nsIStyleSheet* aStyleSheet, \ - bool aApplicable) \ + mozilla::CSSStyleSheet* aStyleSheet,\ + bool aApplicable) \ { \ } \ void \ _class::StyleRuleChanged(nsIDocument* aDocument, \ - nsIStyleSheet* aStyleSheet, \ + mozilla::CSSStyleSheet* aStyleSheet, \ mozilla::css::Rule* aOldStyleRule, \ mozilla::css::Rule* aNewStyleRule) \ { \ } \ void \ _class::StyleRuleAdded(nsIDocument* aDocument, \ - nsIStyleSheet* aStyleSheet, \ + mozilla::CSSStyleSheet* aStyleSheet, \ mozilla::css::Rule* aStyleRule) \ { \ } \ void \ _class::StyleRuleRemoved(nsIDocument* aDocument, \ - nsIStyleSheet* aStyleSheet, \ + mozilla::CSSStyleSheet* aStyleSheet, \ mozilla::css::Rule* aStyleRule) \ { \ } diff --git a/dom/base/nsStyleLinkElement.cpp b/dom/base/nsStyleLinkElement.cpp index 18e5f0b4265..60b6b5e6f0a 100644 --- a/dom/base/nsStyleLinkElement.cpp +++ b/dom/base/nsStyleLinkElement.cpp @@ -288,17 +288,6 @@ UpdateIsElementInStyleScopeFlagOnSubtree(Element* aElement) } } -static Element* -GetScopeElement(nsIStyleSheet* aSheet) -{ - RefPtr cssStyleSheet = do_QueryObject(aSheet); - if (!cssStyleSheet) { - return nullptr; - } - - return cssStyleSheet->GetScopeElement(); -} - nsresult nsStyleLinkElement::DoUpdateStyleSheet(nsIDocument* aOldDocument, ShadowRoot* aOldShadowRoot, @@ -330,7 +319,8 @@ nsStyleLinkElement::DoUpdateStyleSheet(nsIDocument* aOldDocument, return NS_OK; } - Element* oldScopeElement = GetScopeElement(mStyleSheet); + Element* oldScopeElement = + mStyleSheet ? mStyleSheet->GetScopeElement() : nullptr; if (mStyleSheet && (aOldDocument || aOldShadowRoot)) { MOZ_ASSERT(!(aOldDocument && aOldShadowRoot), diff --git a/dom/html/HTMLLinkElement.cpp b/dom/html/HTMLLinkElement.cpp index b004562c7f1..97e7f83393f 100644 --- a/dom/html/HTMLLinkElement.cpp +++ b/dom/html/HTMLLinkElement.cpp @@ -21,7 +21,6 @@ #include "nsIDOMEvent.h" #include "nsIDOMStyleSheet.h" #include "nsINode.h" -#include "nsIStyleSheet.h" #include "nsIStyleSheetLinkingElement.h" #include "nsIURL.h" #include "nsPIDOMWindow.h" diff --git a/dom/html/HTMLStyleElement.cpp b/dom/html/HTMLStyleElement.cpp index 4534aaa88d4..ec690fc0b4d 100644 --- a/dom/html/HTMLStyleElement.cpp +++ b/dom/html/HTMLStyleElement.cpp @@ -8,7 +8,6 @@ #include "nsGkAtoms.h" #include "nsStyleConsts.h" #include "nsIDOMStyleSheet.h" -#include "nsIStyleSheet.h" #include "nsIDocument.h" #include "nsUnicharUtils.h" #include "nsThreadUtils.h" diff --git a/dom/html/nsHTMLDocument.cpp b/dom/html/nsHTMLDocument.cpp index 365aaf6390f..13221443812 100644 --- a/dom/html/nsHTMLDocument.cpp +++ b/dom/html/nsHTMLDocument.cpp @@ -2641,12 +2641,12 @@ nsHTMLDocument::TearingDownEditor(nsIEditor *aEditor) if (!presShell) return; - nsCOMArray agentSheets; + nsTArray> agentSheets; presShell->GetAgentStyleSheets(agentSheets); - agentSheets.RemoveObject(nsLayoutStylesheetCache::ContentEditableSheet()); + agentSheets.RemoveElement(nsLayoutStylesheetCache::ContentEditableSheet()); if (oldState == eDesignMode) - agentSheets.RemoveObject(nsLayoutStylesheetCache::DesignModeSheet()); + agentSheets.RemoveElement(nsLayoutStylesheetCache::DesignModeSheet()); presShell->SetAgentStyleSheets(agentSheets); @@ -2780,18 +2780,15 @@ nsHTMLDocument::EditingStateChanged() // Before making this window editable, we need to modify UA style sheet // because new style may change whether focused element will be focusable // or not. - nsCOMArray agentSheets; + nsTArray> agentSheets; rv = presShell->GetAgentStyleSheets(agentSheets); NS_ENSURE_SUCCESS(rv, rv); CSSStyleSheet* contentEditableSheet = nsLayoutStylesheetCache::ContentEditableSheet(); - bool result; - if (!agentSheets.Contains(contentEditableSheet)) { - bool result = agentSheets.AppendObject(contentEditableSheet); - NS_ENSURE_TRUE(result, NS_ERROR_OUT_OF_MEMORY); + agentSheets.AppendElement(contentEditableSheet); } // Should we update the editable state of all the nodes in the document? We @@ -2802,8 +2799,7 @@ nsHTMLDocument::EditingStateChanged() CSSStyleSheet* designModeSheet = nsLayoutStylesheetCache::DesignModeSheet(); if (!agentSheets.Contains(designModeSheet)) { - result = agentSheets.AppendObject(designModeSheet); - NS_ENSURE_TRUE(result, NS_ERROR_OUT_OF_MEMORY); + agentSheets.AppendElement(designModeSheet); } updateState = true; @@ -2811,7 +2807,7 @@ nsHTMLDocument::EditingStateChanged() } else if (oldState == eDesignMode) { // designMode is being turned off (contentEditable is still on). - agentSheets.RemoveObject(nsLayoutStylesheetCache::DesignModeSheet()); + agentSheets.RemoveElement(nsLayoutStylesheetCache::DesignModeSheet()); updateState = true; } diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index cd8b9a36926..005c0a634d2 100755 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -36,6 +36,7 @@ #include "imgIContainer.h" #include "mozIApplication.h" #include "mozilla/ClearOnShutdown.h" +#include "mozilla/CSSStyleSheet.h" #include "mozilla/DataStorage.h" #include "mozilla/devtools/HeapSnapshotTempFileHelperParent.h" #include "mozilla/docshell/OfflineCacheUpdateParent.h" @@ -142,7 +143,6 @@ #include "nsIScriptSecurityManager.h" #include "nsISiteSecurityService.h" #include "nsISpellChecker.h" -#include "nsIStyleSheet.h" #include "nsISupportsPrimitives.h" #include "nsISystemMessagesInternal.h" #include "nsITimer.h" @@ -2576,24 +2576,21 @@ ContentParent::InitInternal(ProcessPriority aInitialPriority, // This looks like a lot of work, but in a normal browser session we just // send two loads. - nsCOMArray& agentSheets = *sheetService->AgentStyleSheets(); - for (uint32_t i = 0; i < agentSheets.Length(); i++) { + for (CSSStyleSheet* sheet : *sheetService->AgentStyleSheets()) { URIParams uri; - SerializeURI(agentSheets[i]->GetSheetURI(), uri); + SerializeURI(sheet->GetSheetURI(), uri); Unused << SendLoadAndRegisterSheet(uri, nsIStyleSheetService::AGENT_SHEET); } - nsCOMArray& userSheets = *sheetService->UserStyleSheets(); - for (uint32_t i = 0; i < userSheets.Length(); i++) { + for (CSSStyleSheet* sheet : *sheetService->UserStyleSheets()) { URIParams uri; - SerializeURI(userSheets[i]->GetSheetURI(), uri); + SerializeURI(sheet->GetSheetURI(), uri); Unused << SendLoadAndRegisterSheet(uri, nsIStyleSheetService::USER_SHEET); } - nsCOMArray& authorSheets = *sheetService->AuthorStyleSheets(); - for (uint32_t i = 0; i < authorSheets.Length(); i++) { + for (CSSStyleSheet* sheet : *sheetService->AuthorStyleSheets()) { URIParams uri; - SerializeURI(authorSheets[i]->GetSheetURI(), uri); + SerializeURI(sheet->GetSheetURI(), uri); Unused << SendLoadAndRegisterSheet(uri, nsIStyleSheetService::AUTHOR_SHEET); } } diff --git a/dom/xul/nsXULElement.cpp b/dom/xul/nsXULElement.cpp index 01636f635e4..6d2b17c1544 100644 --- a/dom/xul/nsXULElement.cpp +++ b/dom/xul/nsXULElement.cpp @@ -53,7 +53,6 @@ #include "nsIScriptSecurityManager.h" #include "nsIServiceManager.h" #include "mozilla/css/StyleRule.h" -#include "nsIStyleSheet.h" #include "nsIURL.h" #include "nsViewManager.h" #include "nsIWidget.h" diff --git a/editor/libeditor/nsStyleSheetTxns.cpp b/editor/libeditor/nsStyleSheetTxns.cpp index b46cb41c6d9..a7b2325ae82 100644 --- a/editor/libeditor/nsStyleSheetTxns.cpp +++ b/editor/libeditor/nsStyleSheetTxns.cpp @@ -19,10 +19,8 @@ using namespace mozilla; -class nsIStyleSheet; - static void -AddStyleSheet(nsIEditor* aEditor, nsIStyleSheet* aSheet) +AddStyleSheet(nsIEditor* aEditor, CSSStyleSheet* aSheet) { nsCOMPtr domDoc; aEditor->GetDocument(getter_AddRefs(domDoc)); @@ -35,7 +33,7 @@ AddStyleSheet(nsIEditor* aEditor, nsIStyleSheet* aSheet) } static void -RemoveStyleSheet(nsIEditor *aEditor, nsIStyleSheet *aSheet) +RemoveStyleSheet(nsIEditor* aEditor, CSSStyleSheet* aSheet) { nsCOMPtr domDoc; aEditor->GetDocument(getter_AddRefs(domDoc)); diff --git a/embedding/components/webbrowserpersist/nsWebBrowserPersist.h b/embedding/components/webbrowserpersist/nsWebBrowserPersist.h index 0b8687d7988..1816af0a698 100644 --- a/embedding/components/webbrowserpersist/nsWebBrowserPersist.h +++ b/embedding/components/webbrowserpersist/nsWebBrowserPersist.h @@ -16,7 +16,6 @@ #include "nsIOutputStream.h" #include "nsIInputStream.h" #include "nsIChannel.h" -#include "nsIStyleSheet.h" #include "nsIDocumentEncoder.h" #include "nsITransport.h" #include "nsIProgressEventSink.h" diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index 797e8035b50..dc177d85a13 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -2136,22 +2136,6 @@ nsDocumentViewer::RequestWindowClose(bool* aCanClose) return NS_OK; } -static bool -AppendAgentSheet(nsIStyleSheet *aSheet, void *aData) -{ - nsStyleSet *styleSet = static_cast(aData); - styleSet->AppendStyleSheet(SheetType::Agent, aSheet); - return true; -} - -static bool -PrependUserSheet(nsIStyleSheet *aSheet, void *aData) -{ - nsStyleSet *styleSet = static_cast(aData); - styleSet->PrependStyleSheet(SheetType::User, aSheet); - return true; -} - nsresult nsDocumentViewer::CreateStyleSet(nsIDocument* aDocument, nsStyleSet** aStyleSet) @@ -2315,12 +2299,14 @@ nsDocumentViewer::CreateStyleSet(nsIDocument* aDocument, } } - nsStyleSheetService *sheetService = nsStyleSheetService::GetInstance(); + nsStyleSheetService* sheetService = nsStyleSheetService::GetInstance(); if (sheetService) { - sheetService->AgentStyleSheets()->EnumerateForwards(AppendAgentSheet, - styleSet); - sheetService->UserStyleSheets()->EnumerateBackwards(PrependUserSheet, - styleSet); + for (CSSStyleSheet* sheet : *sheetService->AgentStyleSheets()) { + styleSet->AppendStyleSheet(SheetType::Agent, sheet); + } + for (CSSStyleSheet* sheet : Reversed(*sheetService->UserStyleSheets())) { + styleSet->PrependStyleSheet(SheetType::User, sheet); + } } // Caller will handle calling EndUpdate, per contract. diff --git a/layout/base/nsIPresShell.h b/layout/base/nsIPresShell.h index 1a7221216c2..fb8288db986 100644 --- a/layout/base/nsIPresShell.h +++ b/layout/base/nsIPresShell.h @@ -62,6 +62,7 @@ class nsAString; class nsCaret; namespace mozilla { class AccessibleCaretEventHub; +class CSSStyleSheet; class TouchCaret; class SelectionCarets; } // namespace mozilla @@ -70,7 +71,6 @@ class nsFrameManager; class nsILayoutHistoryState; class nsIReflowCallback; class nsIDOMNode; -class nsIStyleSheet; class nsCSSFrameConstructor; class nsISelection; template class nsCOMArray; @@ -140,10 +140,10 @@ typedef struct CapturingContentInfo { mozilla::StaticRefPtr mContent; } CapturingContentInfo; -// ae50e013-b2f1-4d4e-94c7-77cbcdab1c23 +// cf2a1f1f-ed15-42bd-b1ea-59e5d4602118 #define NS_IPRESSHELL_IID \ -{ 0xae50e013, 0xb2f1, 0x4d4e, \ - { 0x94, 0xc7, 0x77, 0xcb, 0xcd, 0xab, 0x1c, 0x23 } } +{ 0xcf2a1f1f, 0xed15, 0x42bd, \ + { 0xb1, 0xea, 0x59, 0xe5, 0xd4, 0x60, 0x21, 0x18 } } // debug VerifyReflow flags #define VERIFY_REFLOW_ON 0x01 @@ -958,22 +958,24 @@ public: /** * Get the set of agent style sheets for this presentation */ - virtual nsresult GetAgentStyleSheets(nsCOMArray& aSheets) = 0; + virtual nsresult GetAgentStyleSheets( + nsTArray>& aSheets) = 0; /** * Replace the set of agent style sheets */ - virtual nsresult SetAgentStyleSheets(const nsCOMArray& aSheets) = 0; + virtual nsresult SetAgentStyleSheets( + const nsTArray>& aSheets) = 0; /** * Add an override style sheet for this presentation */ - virtual nsresult AddOverrideStyleSheet(nsIStyleSheet *aSheet) = 0; + virtual nsresult AddOverrideStyleSheet(mozilla::CSSStyleSheet* aSheet) = 0; /** * Remove an override style sheet */ - virtual nsresult RemoveOverrideStyleSheet(nsIStyleSheet *aSheet) = 0; + virtual nsresult RemoveOverrideStyleSheet(mozilla::CSSStyleSheet* aSheet) = 0; /** * Reconstruct frames for all elements in the document diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index 293b5325cfd..b5d1657dba1 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -1426,19 +1426,18 @@ PresShell::AddUserSheet(nsISupports* aSheet) mStyleSet->BeginUpdate(); - nsStyleSheetService *sheetService = nsStyleSheetService::gInstance; - nsCOMArray & userSheets = *sheetService->UserStyleSheets(); - int32_t i; + nsStyleSheetService* sheetService = nsStyleSheetService::gInstance; + nsTArray>& userSheets = *sheetService->UserStyleSheets(); // Iterate forwards when removing so the searches for RemoveStyleSheet are as // short as possible. - for (i = 0; i < userSheets.Count(); ++i) { - mStyleSet->RemoveStyleSheet(SheetType::User, userSheets[i]); + for (CSSStyleSheet* sheet : userSheets) { + mStyleSet->RemoveStyleSheet(SheetType::User, sheet); } // Now iterate backwards, so that the order of userSheets will be the same as // the order of sheets from it in the style set. - for (i = userSheets.Count() - 1; i >= 0; --i) { - mStyleSet->PrependStyleSheet(SheetType::User, userSheets[i]); + for (CSSStyleSheet* sheet : Reversed(userSheets)) { + mStyleSet->PrependStyleSheet(SheetType::User, sheet); } mStyleSet->EndUpdate(); @@ -1451,7 +1450,7 @@ PresShell::AddAgentSheet(nsISupports* aSheet) { // Make sure this does what nsDocumentViewer::CreateStyleSet does // wrt ordering. - nsCOMPtr sheet = do_QueryInterface(aSheet); + RefPtr sheet = do_QueryObject(aSheet); if (!sheet) { return; } @@ -1463,14 +1462,14 @@ PresShell::AddAgentSheet(nsISupports* aSheet) void PresShell::AddAuthorSheet(nsISupports* aSheet) { - nsCOMPtr sheet = do_QueryInterface(aSheet); + RefPtr sheet = do_QueryObject(aSheet); if (!sheet) { return; } // Document specific "additional" Author sheets should be stronger than the ones // added with the StyleSheetService. - nsIStyleSheet* firstAuthorSheet = mDocument->FirstAdditionalAuthorSheet(); + CSSStyleSheet* firstAuthorSheet = mDocument->FirstAdditionalAuthorSheet(); if (firstAuthorSheet) { mStyleSet->InsertStyleSheetBefore(SheetType::Doc, sheet, firstAuthorSheet); } else { @@ -1483,7 +1482,7 @@ PresShell::AddAuthorSheet(nsISupports* aSheet) void PresShell::RemoveSheet(SheetType aType, nsISupports* aSheet) { - nsCOMPtr sheet = do_QueryInterface(aSheet); + RefPtr sheet = do_QueryObject(aSheet); if (!sheet) { return; } @@ -4501,7 +4500,7 @@ nsIPresShell::ReconstructStyleDataExternal() } void -PresShell::RecordStyleSheetChange(nsIStyleSheet* aStyleSheet) +PresShell::RecordStyleSheetChange(CSSStyleSheet* aStyleSheet) { // too bad we can't check that the update is UPDATE_STYLE NS_ASSERTION(mUpdateCount != 0, "must be in an update"); @@ -4522,8 +4521,8 @@ PresShell::RecordStyleSheetChange(nsIStyleSheet* aStyleSheet) } void -PresShell::StyleSheetAdded(nsIDocument *aDocument, - nsIStyleSheet* aStyleSheet, +PresShell::StyleSheetAdded(nsIDocument* aDocument, + CSSStyleSheet* aStyleSheet, bool aDocumentSheet) { // We only care when enabled sheets are added @@ -4535,8 +4534,8 @@ PresShell::StyleSheetAdded(nsIDocument *aDocument, } void -PresShell::StyleSheetRemoved(nsIDocument *aDocument, - nsIStyleSheet* aStyleSheet, +PresShell::StyleSheetRemoved(nsIDocument* aDocument, + CSSStyleSheet* aStyleSheet, bool aDocumentSheet) { // We only care when enabled sheets are removed @@ -4548,8 +4547,8 @@ PresShell::StyleSheetRemoved(nsIDocument *aDocument, } void -PresShell::StyleSheetApplicableStateChanged(nsIDocument *aDocument, - nsIStyleSheet* aStyleSheet, +PresShell::StyleSheetApplicableStateChanged(nsIDocument* aDocument, + CSSStyleSheet* aStyleSheet, bool aApplicable) { if (aStyleSheet->HasRules()) { @@ -4558,8 +4557,8 @@ PresShell::StyleSheetApplicableStateChanged(nsIDocument *aDocument, } void -PresShell::StyleRuleChanged(nsIDocument *aDocument, - nsIStyleSheet* aStyleSheet, +PresShell::StyleRuleChanged(nsIDocument* aDocument, + CSSStyleSheet* aStyleSheet, mozilla::css::Rule* aOldStyleRule, mozilla::css::Rule* aNewStyleRule) { @@ -4567,16 +4566,16 @@ PresShell::StyleRuleChanged(nsIDocument *aDocument, } void -PresShell::StyleRuleAdded(nsIDocument *aDocument, - nsIStyleSheet* aStyleSheet, +PresShell::StyleRuleAdded(nsIDocument* aDocument, + CSSStyleSheet* aStyleSheet, mozilla::css::Rule* aStyleRule) { RecordStyleSheetChange(aStyleSheet); } void -PresShell::StyleRuleRemoved(nsIDocument *aDocument, - nsIStyleSheet* aStyleSheet, +PresShell::StyleRuleRemoved(nsIDocument* aDocument, + CSSStyleSheet* aStyleSheet, mozilla::css::Rule* aStyleRule) { RecordStyleSheetChange(aStyleSheet); @@ -8602,34 +8601,37 @@ PresShell::IsVisible() } nsresult -PresShell::GetAgentStyleSheets(nsCOMArray& aSheets) +PresShell::GetAgentStyleSheets(nsTArray>& aSheets) { aSheets.Clear(); int32_t sheetCount = mStyleSet->SheetCount(SheetType::Agent); + if (!aSheets.SetCapacity(sheetCount, fallible)) { + return NS_ERROR_OUT_OF_MEMORY; + } + for (int32_t i = 0; i < sheetCount; ++i) { - nsIStyleSheet *sheet = mStyleSet->StyleSheetAt(SheetType::Agent, i); - if (!aSheets.AppendObject(sheet)) - return NS_ERROR_OUT_OF_MEMORY; + CSSStyleSheet* sheet = mStyleSet->StyleSheetAt(SheetType::Agent, i); + aSheets.AppendElement(sheet); } return NS_OK; } nsresult -PresShell::SetAgentStyleSheets(const nsCOMArray& aSheets) +PresShell::SetAgentStyleSheets(const nsTArray>& aSheets) { return mStyleSet->ReplaceSheets(SheetType::Agent, aSheets); } nsresult -PresShell::AddOverrideStyleSheet(nsIStyleSheet *aSheet) +PresShell::AddOverrideStyleSheet(CSSStyleSheet* aSheet) { return mStyleSet->PrependStyleSheet(SheetType::Override, aSheet); } nsresult -PresShell::RemoveOverrideStyleSheet(nsIStyleSheet *aSheet) +PresShell::RemoveOverrideStyleSheet(CSSStyleSheet* aSheet) { return mStyleSet->RemoveStyleSheet(SheetType::Override, aSheet); } @@ -9732,7 +9734,7 @@ PresShell::CloneStyleSet(nsStyleSet* aSet) int32_t i, n = aSet->SheetCount(SheetType::Override); for (i = 0; i < n; i++) { - nsIStyleSheet* ss = aSet->StyleSheetAt(SheetType::Override, i); + CSSStyleSheet* ss = aSet->StyleSheetAt(SheetType::Override, i); if (ss) clone->AppendStyleSheet(SheetType::Override, ss); } @@ -9741,7 +9743,7 @@ PresShell::CloneStyleSet(nsStyleSet* aSet) #if 0 n = aSet->SheetCount(SheetType::Doc); for (i = 0; i < n; i++) { - nsIStyleSheet* ss = aSet->StyleSheetAt(SheetType::Doc, i); + CSSStyleSheet* ss = aSet->StyleSheetAt(SheetType::Doc, i); if (ss) clone->AddDocStyleSheet(ss, mDocument); } @@ -9749,14 +9751,14 @@ PresShell::CloneStyleSet(nsStyleSet* aSet) n = aSet->SheetCount(SheetType::User); for (i = 0; i < n; i++) { - nsIStyleSheet* ss = aSet->StyleSheetAt(SheetType::User, i); + CSSStyleSheet* ss = aSet->StyleSheetAt(SheetType::User, i); if (ss) clone->AppendStyleSheet(SheetType::User, ss); } n = aSet->SheetCount(SheetType::Agent); for (i = 0; i < n; i++) { - nsIStyleSheet* ss = aSet->StyleSheetAt(SheetType::Agent, i); + CSSStyleSheet* ss = aSet->StyleSheetAt(SheetType::Agent, i); if (ss) clone->AppendStyleSheet(SheetType::Agent, ss); } diff --git a/layout/base/nsPresShell.h b/layout/base/nsPresShell.h index 34b40779b45..90d63ecd38f 100644 --- a/layout/base/nsPresShell.h +++ b/layout/base/nsPresShell.h @@ -161,11 +161,13 @@ public: virtual void UnsuppressPainting() override; - virtual nsresult GetAgentStyleSheets(nsCOMArray& aSheets) override; - virtual nsresult SetAgentStyleSheets(const nsCOMArray& aSheets) override; + virtual nsresult GetAgentStyleSheets( + nsTArray>& aSheets) override; + virtual nsresult SetAgentStyleSheets( + const nsTArray>& aSheets) override; - virtual nsresult AddOverrideStyleSheet(nsIStyleSheet *aSheet) override; - virtual nsresult RemoveOverrideStyleSheet(nsIStyleSheet *aSheet) override; + virtual nsresult AddOverrideStyleSheet(mozilla::CSSStyleSheet* aSheet) override; + virtual nsresult RemoveOverrideStyleSheet(mozilla::CSSStyleSheet* aSheet) override; virtual nsresult HandleEventWithTarget( mozilla::WidgetEvent* aEvent, @@ -516,7 +518,7 @@ protected: void ShowEventTargetDebug(); #endif - void RecordStyleSheetChange(nsIStyleSheet* aStyleSheet); + void RecordStyleSheetChange(mozilla::CSSStyleSheet* aStyleSheet); void RemovePreferenceStyles(); diff --git a/layout/base/nsStyleSheetService.cpp b/layout/base/nsStyleSheetService.cpp index 579f743a6fd..0817905fd67 100644 --- a/layout/base/nsStyleSheetService.cpp +++ b/layout/base/nsStyleSheetService.cpp @@ -7,7 +7,6 @@ /* implementation of interface for managing user and user-agent style sheets */ #include "nsStyleSheetService.h" -#include "nsIStyleSheet.h" #include "mozilla/CSSStyleSheet.h" #include "mozilla/MemoryReporting.h" #include "mozilla/unused.h" @@ -79,14 +78,14 @@ nsStyleSheetService::RegisterFromEnumerator(nsICategoryManager *aManager, } int32_t -nsStyleSheetService::FindSheetByURI(const nsCOMArray &sheets, - nsIURI *sheetURI) +nsStyleSheetService::FindSheetByURI(const nsTArray>& aSheets, + nsIURI* aSheetURI) { - for (int32_t i = sheets.Count() - 1; i >= 0; i-- ) { + for (int32_t i = aSheets.Length() - 1; i >= 0; i-- ) { bool bEqual; - nsIURI* uri = sheets[i]->GetSheetURI(); + nsIURI* uri = aSheets[i]->GetSheetURI(); if (uri - && NS_SUCCEEDED(uri->Equals(sheetURI, &bEqual)) + && NS_SUCCEEDED(uri->Equals(aSheetURI, &bEqual)) && bEqual) { return i; } @@ -153,8 +152,9 @@ nsStyleSheetService::LoadAndRegisterSheet(nsIURI *aSheetURI, if (serv) { // We're guaranteed that the new sheet is the last sheet in // mSheets[aSheetType] - const nsCOMArray & sheets = mSheets[aSheetType]; - serv->NotifyObservers(sheets[sheets.Count() - 1], message, nullptr); + CSSStyleSheet* sheet = mSheets[aSheetType].LastElement(); + serv->NotifyObservers(NS_ISUPPORTS_CAST(nsIDOMCSSStyleSheet*, sheet), + message, nullptr); } if (XRE_IsParentProcess()) { @@ -208,9 +208,7 @@ nsStyleSheetService::LoadAndRegisterSheetInternal(nsIURI *aSheetURI, getter_AddRefs(sheet)); NS_ENSURE_SUCCESS(rv, rv); - if (!mSheets[aSheetType].AppendObject(sheet)) { - rv = NS_ERROR_OUT_OF_MEMORY; - } + mSheets[aSheetType].AppendElement(sheet); return rv; } @@ -275,8 +273,8 @@ nsStyleSheetService::UnregisterSheet(nsIURI *aSheetURI, uint32_t aSheetType) int32_t foundIndex = FindSheetByURI(mSheets[aSheetType], aSheetURI); NS_ENSURE_TRUE(foundIndex >= 0, NS_ERROR_INVALID_ARG); - nsCOMPtr sheet = mSheets[aSheetType][foundIndex]; - mSheets[aSheetType].RemoveObjectAt(foundIndex); + RefPtr sheet = mSheets[aSheetType][foundIndex]; + mSheets[aSheetType].RemoveElementAt(foundIndex); const char* message; switch (aSheetType) { @@ -292,8 +290,10 @@ nsStyleSheetService::UnregisterSheet(nsIURI *aSheetURI, uint32_t aSheetType) } nsCOMPtr serv = services::GetObserverService(); - if (serv) - serv->NotifyObservers(sheet, message, nullptr); + if (serv) { + serv->NotifyObservers(NS_ISUPPORTS_CAST(nsIDOMCSSStyleSheet*, sheet), + message, nullptr); + } if (XRE_IsParentProcess()) { nsTArray children; @@ -329,13 +329,6 @@ nsStyleSheetService::GetInstance() return gInstance; } -static size_t -SizeOfElementIncludingThis(nsIStyleSheet* aElement, - MallocSizeOf aMallocSizeOf, void *aData) -{ - return aElement->SizeOfIncludingThis(aMallocSizeOf); -} - MOZ_DEFINE_MALLOC_SIZE_OF(StyleSheetServiceMallocSizeOf) NS_IMETHODIMP @@ -352,13 +345,11 @@ size_t nsStyleSheetService::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const { size_t n = aMallocSizeOf(this); - n += mSheets[AGENT_SHEET].SizeOfExcludingThis(SizeOfElementIncludingThis, - aMallocSizeOf); - n += mSheets[USER_SHEET].SizeOfExcludingThis(SizeOfElementIncludingThis, - aMallocSizeOf); - n += mSheets[AUTHOR_SHEET].SizeOfExcludingThis(SizeOfElementIncludingThis, - aMallocSizeOf); + for (auto& sheetArray : mSheets) { + n += sheetArray.ShallowSizeOfExcludingThis(aMallocSizeOf); + for (CSSStyleSheet* sheet : sheetArray) { + n += sheet->SizeOfIncludingThis(aMallocSizeOf); + } + } return n; } - - diff --git a/layout/base/nsStyleSheetService.h b/layout/base/nsStyleSheetService.h index e6703474865..ec128a6d6ca 100644 --- a/layout/base/nsStyleSheetService.h +++ b/layout/base/nsStyleSheetService.h @@ -16,13 +16,16 @@ #include "mozilla/Attributes.h" #include "mozilla/MemoryReporting.h" +namespace mozilla { +class CSSStyleSheet; +} class nsICategoryManager; class nsIMemoryReporter; class nsISimpleEnumerator; -class nsIStyleSheet; #define NS_STYLESHEETSERVICE_CID \ -{0xfcca6f83, 0x9f7d, 0x44e4, {0xa7, 0x4b, 0xb5, 0x94, 0x33, 0xe6, 0xc8, 0xc3}} +{ 0x3b55e72e, 0xab7e, 0x431b, \ + { 0x89, 0xc0, 0x3b, 0x06, 0xa8, 0xb1, 0x40, 0x16 } } #define NS_STYLESHEETSERVICE_CONTRACTID \ "@mozilla.org/content/style-sheet-service;1" @@ -40,9 +43,18 @@ class nsStyleSheetService final nsresult Init(); - nsCOMArray* AgentStyleSheets() { return &mSheets[AGENT_SHEET]; } - nsCOMArray* UserStyleSheets() { return &mSheets[USER_SHEET]; } - nsCOMArray* AuthorStyleSheets() { return &mSheets[AUTHOR_SHEET]; } + nsTArray>* AgentStyleSheets() + { + return &mSheets[AGENT_SHEET]; + } + nsTArray>* UserStyleSheets() + { + return &mSheets[USER_SHEET]; + } + nsTArray>* AuthorStyleSheets() + { + return &mSheets[AUTHOR_SHEET]; + } size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; @@ -57,15 +69,15 @@ class nsStyleSheetService final nsISimpleEnumerator *aEnumerator, uint32_t aSheetType); - int32_t FindSheetByURI(const nsCOMArray &sheets, - nsIURI *sheetURI); + int32_t FindSheetByURI(const nsTArray>& aSheets, + nsIURI* aSheetURI); // Like LoadAndRegisterSheet, but doesn't notify. If successful, the // new sheet will be the last sheet in mSheets[aSheetType]. nsresult LoadAndRegisterSheetInternal(nsIURI *aSheetURI, uint32_t aSheetType); - nsCOMArray mSheets[3]; + nsTArray> mSheets[3]; }; #endif diff --git a/layout/inspector/inDOMUtils.cpp b/layout/inspector/inDOMUtils.cpp index dccd7ccef02..7889c8026b3 100644 --- a/layout/inspector/inDOMUtils.cpp +++ b/layout/inspector/inDOMUtils.cpp @@ -74,7 +74,7 @@ inDOMUtils::GetAllStyleSheets(nsIDOMDocument *aDocument, uint32_t *aLength, { NS_ENSURE_ARG_POINTER(aDocument); - nsCOMArray sheets; + nsTArray> sheets; nsCOMPtr document = do_QueryInterface(aDocument); MOZ_ASSERT(document); @@ -109,14 +109,14 @@ inDOMUtils::GetAllStyleSheets(nsIDOMDocument *aDocument, uint32_t *aLength, sheets.AppendElement(document->GetStyleSheetAt(i)); } - nsISupports** ret = static_cast(moz_xmalloc(sheets.Count() * + nsISupports** ret = static_cast(moz_xmalloc(sheets.Length() * sizeof(nsISupports*))); - for (int32_t i = 0; i < sheets.Count(); i++) { - NS_ADDREF(ret[i] = sheets[i]); + for (size_t i = 0; i < sheets.Length(); i++) { + NS_ADDREF(ret[i] = NS_ISUPPORTS_CAST(nsIDOMCSSStyleSheet*, sheets[i])); } - *aLength = sheets.Count(); + *aLength = sheets.Length(); *aSheets = ret; return NS_OK; diff --git a/layout/style/CSSStyleSheet.cpp b/layout/style/CSSStyleSheet.cpp index 5a6d64148ef..e6a1353be64 100644 --- a/layout/style/CSSStyleSheet.cpp +++ b/layout/style/CSSStyleSheet.cpp @@ -1253,7 +1253,7 @@ CSSStyleSheet::TraverseInner(nsCycleCollectionTraversalCallback &cb) RefPtr* childSheetSlot = &mInner->mFirstChild; while (*childSheetSlot) { NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "child sheet"); - cb.NoteXPCOMChild(NS_ISUPPORTS_CAST(nsIStyleSheet*, childSheetSlot->get())); + cb.NoteXPCOMChild(NS_ISUPPORTS_CAST(nsIDOMCSSStyleSheet*, childSheetSlot->get())); childSheetSlot = &(*childSheetSlot)->mNext; } @@ -1267,11 +1267,10 @@ CSSStyleSheet::TraverseInner(nsCycleCollectionTraversalCallback &cb) // QueryInterface implementation for CSSStyleSheet NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CSSStyleSheet) NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY - NS_INTERFACE_MAP_ENTRY(nsIStyleSheet) NS_INTERFACE_MAP_ENTRY(nsIDOMStyleSheet) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleSheet) NS_INTERFACE_MAP_ENTRY(nsICSSLoaderObserver) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleSheet) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMCSSStyleSheet) if (aIID.Equals(NS_GET_IID(CSSStyleSheet))) foundInterface = reinterpret_cast(this); else @@ -1371,19 +1370,19 @@ CSSStyleSheet::SetPrincipal(nsIPrincipal* aPrincipal) } } -/* virtual */ nsIURI* +nsIURI* CSSStyleSheet::GetSheetURI() const { return mInner->mSheetURI; } -/* virtual */ nsIURI* +nsIURI* CSSStyleSheet::GetBaseURI() const { return mInner->mBaseURI; } -/* virtual */ void +void CSSStyleSheet::GetType(nsString& aType) const { aType.AssignLiteral("text/css"); @@ -1406,19 +1405,19 @@ CSSStyleSheet::SetMedia(nsMediaList* aMedia) mMedia = aMedia; } -/* virtual */ bool +bool CSSStyleSheet::HasRules() const { return StyleRuleCount() != 0; } -/* virtual */ bool +bool CSSStyleSheet::IsApplicable() const { return !mDisabled && mInner->mComplete; } -/* virtual */ void +void CSSStyleSheet::SetEnabled(bool aEnabled) { // Internal method, so callers must handle BeginUpdate/EndUpdate @@ -1434,13 +1433,13 @@ CSSStyleSheet::SetEnabled(bool aEnabled) } } -/* virtual */ bool +bool CSSStyleSheet::IsComplete() const { return mInner->mComplete; } -/* virtual */ void +void CSSStyleSheet::SetComplete() { NS_ASSERTION(!mDirty, "Can't set a dirty sheet complete!"); @@ -1460,19 +1459,19 @@ CSSStyleSheet::SetComplete() } } -/* virtual */ nsIStyleSheet* +CSSStyleSheet* CSSStyleSheet::GetParentSheet() const { return mParent; } -/* virtual */ nsIDocument* +nsIDocument* CSSStyleSheet::GetOwningDocument() const { return mDocument; } -/* virtual */ void +void CSSStyleSheet::SetOwningDocument(nsIDocument* aDocument) { // not ref counted mDocument = aDocument; @@ -1500,12 +1499,9 @@ CSSStyleSheet::FindOwningWindowInnerID() const } if (windowID == 0 && mOwnerRule) { - nsCOMPtr sheet = static_cast(mOwnerRule)->GetStyleSheet(); + RefPtr sheet = static_cast(mOwnerRule)->GetStyleSheet(); if (sheet) { - RefPtr cssSheet = do_QueryObject(sheet); - if (cssSheet) { - windowID = cssSheet->FindOwningWindowInnerID(); - } + windowID = sheet->FindOwningWindowInnerID(); } } @@ -1638,7 +1634,7 @@ struct ListEnumData { int32_t mIndent; }; -/* virtual */ void +void CSSStyleSheet::List(FILE* out, int32_t aIndent) const { @@ -1831,7 +1827,7 @@ CSSStyleSheet::GetHref(nsAString& aHref) return NS_OK; } -/* virtual */ void +void CSSStyleSheet::GetTitle(nsString& aTitle) const { aTitle = mTitle; diff --git a/layout/style/CSSStyleSheet.h b/layout/style/CSSStyleSheet.h index e535864ebd4..6b670699a55 100644 --- a/layout/style/CSSStyleSheet.h +++ b/layout/style/CSSStyleSheet.h @@ -17,7 +17,6 @@ #include "nscore.h" #include "nsCOMPtr.h" #include "nsAutoPtr.h" -#include "nsIStyleSheet.h" #include "nsIDOMCSSStyleSheet.h" #include "nsICSSLoaderObserver.h" #include "nsTArrayForwardDeclare.h" @@ -112,14 +111,13 @@ private: // // CID for the CSSStyleSheet class -// ca926f30-2a7e-477e-8467-803fb32af20a +// 7985c7ac-9ddc-444d-9899-0c86ec122f54 #define NS_CSS_STYLE_SHEET_IMPL_CID \ -{ 0xca926f30, 0x2a7e, 0x477e, \ - { 0x84, 0x67, 0x80, 0x3f, 0xb3, 0x2a, 0xf2, 0x0a } } +{ 0x7985c7ac, 0x9ddc, 0x444d, \ + { 0x98, 0x99, 0x0c, 0x86, 0xec, 0x12, 0x2f, 0x54 } } -class CSSStyleSheet final : public nsIStyleSheet, - public nsIDOMCSSStyleSheet, +class CSSStyleSheet final : public nsIDOMCSSStyleSheet, public nsICSSLoaderObserver, public nsWrapperCache { @@ -131,28 +129,50 @@ public: NS_DECL_CYCLE_COLLECTING_ISUPPORTS NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(CSSStyleSheet, - nsIStyleSheet) + nsIDOMCSSStyleSheet) NS_DECLARE_STATIC_IID_ACCESSOR(NS_CSS_STYLE_SHEET_IMPL_CID) - // nsIStyleSheet interface - virtual nsIURI* GetSheetURI() const override; - virtual nsIURI* GetBaseURI() const override; - virtual void GetTitle(nsString& aTitle) const override; - virtual void GetType(nsString& aType) const override; - virtual bool HasRules() const override; - virtual bool IsApplicable() const override; - virtual void SetEnabled(bool aEnabled) override; - virtual bool IsComplete() const override; - virtual void SetComplete() override; - virtual nsIStyleSheet* GetParentSheet() const override; // may be null - virtual nsIDocument* GetOwningDocument() const override; // may be null - virtual void SetOwningDocument(nsIDocument* aDocument) override; + nsIURI* GetSheetURI() const; + nsIURI* GetBaseURI() const; + void GetTitle(nsString& aTitle) const; + void GetType(nsString& aType) const; + bool HasRules() const; + + /** + * Whether the sheet is applicable. A sheet that is not applicable + * should never be inserted into a style set. A sheet may not be + * applicable for a variety of reasons including being disabled and + * being incomplete. + */ + bool IsApplicable() 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); + + /** + * Whether the sheet is complete. + */ + bool IsComplete() const; + void SetComplete(); + + // style sheet owner info + CSSStyleSheet* GetParentSheet() const; // may be null + nsIDocument* GetOwningDocument() const; // may be null + void SetOwningDocument(nsIDocument* aDocument); // Find the ID of the owner inner window. uint64_t FindOwningWindowInnerID() const; #ifdef DEBUG - virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; + void List(FILE* out = stdout, int32_t aIndent = 0) const; #endif void AppendStyleSheet(CSSStyleSheet* aSheet); @@ -250,7 +270,7 @@ public: // list after we clone a unique inner for ourselves. static bool RebuildChildList(css::Rule* aRule, void* aBuilder); - size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override; + size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const; // Get this style sheet's CORS mode CORSMode GetCORSMode() const { return mInner->mCORSMode; } @@ -268,7 +288,7 @@ public: } // WebIDL StyleSheet API - // Our nsIStyleSheet::GetType is a const method, so it ends up + // Our CSSStyleSheet::GetType is a const method, so it ends up // ambiguous with with the XPCOM version. Just disambiguate. void GetType(nsString& aType) { const_cast(this)->GetType(aType); @@ -276,7 +296,7 @@ public: // Our XPCOM GetHref is fine for WebIDL nsINode* GetOwnerNode() const { return mOwningNode; } CSSStyleSheet* GetParentStyleSheet() const { return mParent; } - // Our nsIStyleSheet::GetTitle is a const method, so it ends up + // Our CSSStyleSheet::GetTitle is a const method, so it ends up // ambiguous with with the XPCOM version. Just disambiguate. void GetTitle(nsString& aTitle) { const_cast(this)->GetTitle(aTitle); @@ -307,7 +327,7 @@ public: return dom::ParentObject(mOwningNode); } - return dom::ParentObject(static_cast(mParent), mParent); + return dom::ParentObject(static_cast(mParent), mParent); } virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; diff --git a/layout/style/Loader.cpp b/layout/style/Loader.cpp index ae2a5b6af1f..f75ee1be1eb 100644 --- a/layout/style/Loader.cpp +++ b/layout/style/Loader.cpp @@ -1348,12 +1348,10 @@ Loader::InsertSheetInDoc(CSSStyleSheet* aSheet, */ int32_t insertionPoint; for (insertionPoint = sheetCount - 1; insertionPoint >= 0; --insertionPoint) { - nsIStyleSheet *curSheet = aDocument->GetStyleSheetAt(insertionPoint); + CSSStyleSheet* curSheet = aDocument->GetStyleSheetAt(insertionPoint); NS_ASSERTION(curSheet, "There must be a sheet here!"); - nsCOMPtr domSheet = do_QueryInterface(curSheet); - NS_ASSERTION(domSheet, "All the \"normal\" sheets implement nsIDOMStyleSheet"); nsCOMPtr sheetOwner; - domSheet->GetOwnerNode(getter_AddRefs(sheetOwner)); + curSheet->GetOwnerNode(getter_AddRefs(sheetOwner)); if (sheetOwner && !aLinkingContent) { // Keep moving; all sheets with a sheetOwner come after all // sheets without a linkingNode @@ -2608,7 +2606,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Loader) !iter.Done(); iter.Next()) { NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "Sheet cache nsCSSLoader"); - cb.NoteXPCOMChild(NS_ISUPPORTS_CAST(nsIStyleSheet*, iter.UserData())); + cb.NoteXPCOMChild(NS_ISUPPORTS_CAST(nsIDOMCSSStyleSheet*, iter.UserData())); } } nsTObserverArray>::ForwardIterator diff --git a/layout/style/moz.build b/layout/style/moz.build index 2833d04701a..65490752e61 100644 --- a/layout/style/moz.build +++ b/layout/style/moz.build @@ -62,7 +62,6 @@ EXPORTS += [ 'nsICSSStyleRuleDOMWrapper.h', 'nsIStyleRule.h', 'nsIStyleRuleProcessor.h', - 'nsIStyleSheet.h', 'nsLayoutStylesheetCache.h', 'nsRuleData.h', 'nsRuleNode.h', diff --git a/layout/style/nsDOMCSSDeclaration.cpp b/layout/style/nsDOMCSSDeclaration.cpp index 56ce8319d0d..c06654b481c 100644 --- a/layout/style/nsDOMCSSDeclaration.cpp +++ b/layout/style/nsDOMCSSDeclaration.cpp @@ -292,9 +292,8 @@ nsDOMCSSDeclaration::RemoveProperty(const nsAString& aPropertyName, nsDOMCSSDeclaration::GetCSSParsingEnvironmentForRule(css::Rule* aRule, CSSParsingEnvironment& aCSSParseEnv) { - nsIStyleSheet* sheet = aRule ? aRule->GetStyleSheet() : nullptr; - RefPtr cssSheet(do_QueryObject(sheet)); - if (!cssSheet) { + CSSStyleSheet* sheet = aRule ? aRule->GetStyleSheet() : nullptr; + if (!sheet) { aCSSParseEnv.mPrincipal = nullptr; return; } @@ -302,7 +301,7 @@ nsDOMCSSDeclaration::GetCSSParsingEnvironmentForRule(css::Rule* aRule, nsIDocument* document = sheet->GetOwningDocument(); aCSSParseEnv.mSheetURI = sheet->GetSheetURI(); aCSSParseEnv.mBaseURI = sheet->GetBaseURI(); - aCSSParseEnv.mPrincipal = cssSheet->Principal(); + aCSSParseEnv.mPrincipal = sheet->Principal(); aCSSParseEnv.mCSSLoader = document ? document->CSSLoader() : nullptr; } diff --git a/layout/style/nsIStyleSheet.h b/layout/style/nsIStyleSheet.h deleted file mode 100644 index 23ccb58fd59..00000000000 --- a/layout/style/nsIStyleSheet.h +++ /dev/null @@ -1,87 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/* - * interface representing a collection of style data attached to a - * document, which may be or be combined into a style rule processor - */ - -#ifndef nsIStyleSheet_h___ -#define nsIStyleSheet_h___ - -#include "mozilla/MemoryReporting.h" -#include -#include "nsISupports.h" - -class nsString; -class nsIURI; -class nsIDocument; - -// IID for the nsIStyleSheet interface -// 3eb34a60-04bd-41d9-9f60-882694e61c38 -#define NS_ISTYLE_SHEET_IID \ -{ 0x3eb34a60, 0x04bd, 0x41d9, \ - { 0x9f, 0x60, 0x88, 0x26, 0x94, 0xe6, 0x1c, 0x38 } } - -/** - * A style sheet is a thing associated with a document that has style - * rules. Those style rules can be reached in one of two ways, depending - * on which level of the nsStyleSet it is in: - * 1) It can be |QueryInterface|d to nsIStyleRuleProcessor - * 2) It can be |QueryInterface|d to CSSStyleSheet, with which the - * |nsStyleSet| uses an |nsCSSRuleProcessor| to access the rules. - */ -class nsIStyleSheet : public nsISupports { -public: - NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISTYLE_SHEET_IID) - - // basic style sheet data - virtual nsIURI* GetSheetURI() const = 0; - virtual nsIURI* GetBaseURI() const = 0; - virtual void GetTitle(nsString& aTitle) const = 0; - virtual void GetType(nsString& aType) const = 0; - virtual bool HasRules() const = 0; - - /** - * Whether the sheet is applicable. A sheet that is not applicable - * should never be inserted into a style set. A sheet may not be - * applicable for a variety of reasons including being disabled and - * being incomplete. - * - */ - virtual bool IsApplicable() const = 0; - - /** - * 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(). - */ - virtual void SetEnabled(bool aEnabled) = 0; - - /** - * Whether the sheet is complete. - */ - virtual bool IsComplete() const = 0; - virtual void SetComplete() = 0; - - // style sheet owner info - virtual nsIStyleSheet* GetParentSheet() const = 0; // may be null - virtual nsIDocument* GetOwningDocument() const = 0; // may be null - virtual void SetOwningDocument(nsIDocument* aDocument) = 0; - -#ifdef DEBUG - virtual void List(FILE* out = stdout, int32_t aIndent = 0) const = 0; -#endif - - virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const = 0; -}; - -NS_DEFINE_STATIC_IID_ACCESSOR(nsIStyleSheet, NS_ISTYLE_SHEET_IID) - -#endif /* nsIStyleSheet_h___ */ diff --git a/layout/style/nsStyleSet.cpp b/layout/style/nsStyleSet.cpp index 2f470f6d46f..ca2ad0a63e6 100644 --- a/layout/style/nsStyleSet.cpp +++ b/layout/style/nsStyleSet.cpp @@ -197,8 +197,8 @@ nsStyleSet::nsStyleSet() nsStyleSet::~nsStyleSet() { for (SheetType type : gCSSSheetTypes) { - for (uint32_t i = 0, n = mSheets[type].Length(); i < n; i++) { - static_cast(mSheets[type][i])->DropStyleSet(this); + for (CSSStyleSheet* sheet : mSheets[type]) { + sheet->DropStyleSet(this); } } @@ -234,12 +234,9 @@ nsStyleSet::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const n += mRuleProcessors[type]->SizeOfIncludingThis(aMallocSizeOf); } } - // mSheets is a C-style array of nsCOMArrays. We do not own the sheets in - // the nsCOMArrays (either the nsLayoutStyleSheetCache singleton or our - // document owns them) so we do not count the sheets here (we pass nullptr - // as the aSizeOfElementIncludingThis argument). All we're doing here is - // counting the size of the nsCOMArrays' buffers. - n += mSheets[type].SizeOfExcludingThis(nullptr, aMallocSizeOf); + // We don't own the sheets (either the nsLayoutStyleSheetCache singleton + // or our document owns them). + n += mSheets[type].ShallowSizeOfExcludingThis(aMallocSizeOf); } for (uint32_t i = 0; i < mScopedDocSheetRuleProcessors.Length(); i++) { @@ -450,8 +447,7 @@ nsStyleSet::GatherRuleProcessors(SheetType aType) return NS_OK; } switch (aType) { - // handle the types for which have a rule processor that does not - // implement the style sheet interface. + // levels that do not contain CSS style sheets case SheetType::Animation: MOZ_ASSERT(mSheets[aType].IsEmpty()); mRuleProcessors[aType] = PresContext()->AnimationManager(); @@ -478,17 +474,16 @@ nsStyleSet::GatherRuleProcessors(SheetType aType) // keep going break; } + MOZ_ASSERT(IsCSSSheetType(aType)); if (aType == SheetType::ScopedDoc) { // Create a rule processor for each scope. - uint32_t count = mSheets[SheetType::ScopedDoc].Count(); + uint32_t count = mSheets[SheetType::ScopedDoc].Length(); if (count) { // Gather the scoped style sheets into an array as // CSSStyleSheets, and mark all of their scope elements // as scoped style roots. nsTArray sheets(count); - for (uint32_t i = 0; i < count; i++) { - RefPtr sheet = - do_QueryObject(mSheets[SheetType::ScopedDoc].ObjectAt(i)); + for (CSSStyleSheet* sheet : mSheets[SheetType::ScopedDoc]) { sheets.AppendElement(sheet); Element* scope = sheet->GetScopeElement(); @@ -537,27 +532,20 @@ nsStyleSet::GatherRuleProcessors(SheetType aType) } return NS_OK; } - if (mSheets[aType].Count()) { + if (!mSheets[aType].IsEmpty()) { switch (aType) { case SheetType::Agent: case SheetType::User: { // levels containing non-scoped CSS style sheets whose rule processors // we want to re-use - nsCOMArray& sheets = mSheets[aType]; - nsTArray> cssSheets(sheets.Count()); - for (int32_t i = 0, i_end = sheets.Count(); i < i_end; ++i) { - RefPtr cssSheet = do_QueryObject(sheets[i]); - NS_ASSERTION(cssSheet, "not a CSS sheet"); - cssSheets.AppendElement(cssSheet); - } - nsTArray cssSheetsRaw(cssSheets.Length()); - for (int32_t i = 0, i_end = cssSheets.Length(); i < i_end; ++i) { - cssSheetsRaw.AppendElement(cssSheets[i]); + nsTArray sheets(mSheets[aType].Length()); + for (CSSStyleSheet* sheet : mSheets[aType]) { + sheets.AppendElement(sheet); } nsCSSRuleProcessor* rp = - RuleProcessorCache::GetRuleProcessor(cssSheetsRaw, PresContext()); + RuleProcessorCache::GetRuleProcessor(sheets, PresContext()); if (!rp) { - rp = new nsCSSRuleProcessor(cssSheets, aType, nullptr, + rp = new nsCSSRuleProcessor(mSheets[aType], aType, nullptr, static_cast( oldRuleProcessor.get()), true /* aIsShared */); @@ -565,7 +553,7 @@ nsStyleSet::GatherRuleProcessors(SheetType aType) nsDocumentRuleResultCacheKey cacheKey; rp->TakeDocumentRulesAndCacheKey(PresContext(), documentRules, cacheKey); - RuleProcessorCache::PutRuleProcessor(cssSheetsRaw, + RuleProcessorCache::PutRuleProcessor(sheets, Move(documentRules), cacheKey, rp); } @@ -577,23 +565,14 @@ nsStyleSet::GatherRuleProcessors(SheetType aType) case SheetType::Override: { // levels containing non-scoped CSS stylesheets whose rule processors // we don't want to re-use - nsCOMArray& sheets = mSheets[aType]; - nsTArray> cssSheets(sheets.Count()); - for (int32_t i = 0, i_end = sheets.Count(); i < i_end; ++i) { - RefPtr cssSheet = do_QueryObject(sheets[i]); - NS_ASSERTION(cssSheet, "not a CSS sheet"); - cssSheets.AppendElement(cssSheet); - } mRuleProcessors[aType] = - new nsCSSRuleProcessor(cssSheets, aType, nullptr, + new nsCSSRuleProcessor(mSheets[aType], aType, nullptr, static_cast( oldRuleProcessor.get())); } break; default: - // levels containing non-CSS stylesheets - NS_ASSERTION(mSheets[aType].Count() == 1, "only one sheet per level"); - mRuleProcessors[aType] = do_QueryInterface(mSheets[aType][0]); + MOZ_ASSERT_UNREACHABLE("non-CSS sheet types should be handled above"); break; } } @@ -601,58 +580,47 @@ nsStyleSet::GatherRuleProcessors(SheetType aType) return NS_OK; } -static bool -IsScopedStyleSheet(nsIStyleSheet* aSheet) -{ - RefPtr cssSheet = do_QueryObject(aSheet); - NS_ASSERTION(cssSheet, "expected aSheet to be a CSSStyleSheet"); - - return cssSheet->GetScopeElement(); -} - nsresult -nsStyleSet::AppendStyleSheet(SheetType aType, nsIStyleSheet *aSheet) +nsStyleSet::AppendStyleSheet(SheetType aType, CSSStyleSheet* aSheet) { NS_PRECONDITION(aSheet, "null arg"); NS_ASSERTION(aSheet->IsApplicable(), "Inapplicable sheet being placed in style set"); - bool present = mSheets[aType].RemoveObject(aSheet); - if (!mSheets[aType].AppendObject(aSheet)) - return NS_ERROR_OUT_OF_MEMORY; + bool present = mSheets[aType].RemoveElement(aSheet); + mSheets[aType].AppendElement(aSheet); if (!present && IsCSSSheetType(aType)) { - static_cast(aSheet)->AddStyleSet(this); + aSheet->AddStyleSet(this); } return DirtyRuleProcessors(aType); } nsresult -nsStyleSet::PrependStyleSheet(SheetType aType, nsIStyleSheet *aSheet) +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].RemoveObject(aSheet); - if (!mSheets[aType].InsertObjectAt(aSheet, 0)) - return NS_ERROR_OUT_OF_MEMORY; + bool present = mSheets[aType].RemoveElement(aSheet); + mSheets[aType].InsertElementAt(0, aSheet); if (!present && IsCSSSheetType(aType)) { - static_cast(aSheet)->AddStyleSet(this); + aSheet->AddStyleSet(this); } return DirtyRuleProcessors(aType); } nsresult -nsStyleSet::RemoveStyleSheet(SheetType aType, nsIStyleSheet *aSheet) +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].RemoveObject(aSheet)) { + if (mSheets[aType].RemoveElement(aSheet)) { if (IsCSSSheetType(aType)) { - static_cast(aSheet)->DropStyleSet(this); + aSheet->DropStyleSet(this); } } @@ -661,22 +629,21 @@ nsStyleSet::RemoveStyleSheet(SheetType aType, nsIStyleSheet *aSheet) nsresult nsStyleSet::ReplaceSheets(SheetType aType, - const nsCOMArray &aNewSheets) + const nsTArray>& aNewSheets) { bool cssSheetType = IsCSSSheetType(aType); if (cssSheetType) { - for (uint32_t i = 0, n = mSheets[aType].Length(); i < n; i++) { - static_cast(mSheets[aType][i])->DropStyleSet(this); + for (CSSStyleSheet* sheet : mSheets[aType]) { + sheet->DropStyleSet(this); } } mSheets[aType].Clear(); - if (!mSheets[aType].AppendObjects(aNewSheets)) - return NS_ERROR_OUT_OF_MEMORY; + mSheets[aType].AppendElements(aNewSheets); if (cssSheetType) { - for (uint32_t i = 0, n = mSheets[aType].Length(); i < n; i++) { - static_cast(mSheets[aType][i])->AddStyleSet(this); + for (CSSStyleSheet* sheet : mSheets[aType]) { + sheet->AddStyleSet(this); } } @@ -684,23 +651,22 @@ nsStyleSet::ReplaceSheets(SheetType aType, } nsresult -nsStyleSet::InsertStyleSheetBefore(SheetType aType, nsIStyleSheet *aNewSheet, - nsIStyleSheet *aReferenceSheet) +nsStyleSet::InsertStyleSheetBefore(SheetType aType, CSSStyleSheet* aNewSheet, + CSSStyleSheet* aReferenceSheet) { NS_PRECONDITION(aNewSheet && aReferenceSheet, "null arg"); NS_ASSERTION(aNewSheet->IsApplicable(), "Inapplicable sheet being placed in style set"); - bool present = mSheets[aType].RemoveObject(aNewSheet); + bool present = mSheets[aType].RemoveElement(aNewSheet); int32_t idx = mSheets[aType].IndexOf(aReferenceSheet); if (idx < 0) return NS_ERROR_INVALID_ARG; - if (!mSheets[aType].InsertObjectAt(aNewSheet, idx)) - return NS_ERROR_OUT_OF_MEMORY; + mSheets[aType].InsertElementAt(idx, aNewSheet); if (!present && IsCSSSheetType(aType)) { - static_cast(aNewSheet)->AddStyleSet(this); + aNewSheet->AddStyleSet(this); } return DirtyRuleProcessors(aType); @@ -745,27 +711,27 @@ nsStyleSet::SetAuthorStyleDisabled(bool aStyleDisabled) // -------- Doc Sheets nsresult -nsStyleSet::AddDocStyleSheet(nsIStyleSheet* aSheet, nsIDocument* aDocument) +nsStyleSet::AddDocStyleSheet(CSSStyleSheet* aSheet, nsIDocument* aDocument) { NS_PRECONDITION(aSheet && aDocument, "null arg"); NS_ASSERTION(aSheet->IsApplicable(), "Inapplicable sheet being placed in style set"); - SheetType type = IsScopedStyleSheet(aSheet) ? + SheetType type = aSheet->GetScopeElement() ? SheetType::ScopedDoc : SheetType::Doc; - nsCOMArray& sheets = mSheets[type]; + nsTArray>& sheets = mSheets[type]; - bool present = sheets.RemoveObject(aSheet); + bool present = sheets.RemoveElement(aSheet); nsStyleSheetService *sheetService = nsStyleSheetService::GetInstance(); // lowest index first int32_t newDocIndex = aDocument->GetIndexOfStyleSheet(aSheet); - int32_t count = sheets.Count(); + int32_t count = sheets.Length(); int32_t index; for (index = 0; index < count; index++) { - nsIStyleSheet* sheet = sheets.ObjectAt(index); + CSSStyleSheet* sheet = sheets[index]; int32_t sheetDocIndex = aDocument->GetIndexOfStyleSheet(sheet); if (sheetDocIndex > newDocIndex) break; @@ -774,27 +740,32 @@ nsStyleSet::AddDocStyleSheet(nsIStyleSheet* aSheet, nsIDocument* aDocument) // sheet registered at nsStyleSheetService or an additional author // sheet on the document, which means the new // doc sheet should end up before it. - if (sheetDocIndex < 0 && - ((sheetService && - sheetService->AuthorStyleSheets()->IndexOf(sheet) >= 0) || - sheet == aDocument->FirstAdditionalAuthorSheet())) + if (sheetDocIndex < 0) { + if (sheetService) { + auto& authorSheets = *sheetService->AuthorStyleSheets(); + if (authorSheets.IndexOf(sheet) != authorSheets.NoIndex) { + break; + } + } + if (sheet == aDocument->FirstAdditionalAuthorSheet()) { break; + } + } } - if (!sheets.InsertObjectAt(aSheet, index)) - return NS_ERROR_OUT_OF_MEMORY; + + sheets.InsertElementAt(index, aSheet); if (!present) { - static_cast(aSheet)->AddStyleSet(this); + aSheet->AddStyleSet(this); } return DirtyRuleProcessors(type); } nsresult -nsStyleSet::RemoveDocStyleSheet(nsIStyleSheet *aSheet) +nsStyleSet::RemoveDocStyleSheet(CSSStyleSheet* aSheet) { - RefPtr cssSheet = do_QueryObject(aSheet); - bool isScoped = cssSheet && cssSheet->GetScopeElement(); + bool isScoped = aSheet->GetScopeElement(); return RemoveStyleSheet(isScoped ? SheetType::ScopedDoc : SheetType::Doc, aSheet); } @@ -2496,10 +2467,8 @@ bool nsStyleSet::EnsureUniqueInnerOnCSSSheets() { nsAutoTArray queue; - for (uint32_t i = 0; i < ArrayLength(gCSSSheetTypes); ++i) { - nsCOMArray &sheets = mSheets[gCSSSheetTypes[i]]; - for (uint32_t j = 0, j_end = sheets.Count(); j < j_end; ++j) { - CSSStyleSheet* sheet = static_cast(sheets[j]); + for (SheetType type : gCSSSheetTypes) { + for (CSSStyleSheet* sheet : mSheets[type]) { queue.AppendElement(sheet); } } diff --git a/layout/style/nsStyleSet.h b/layout/style/nsStyleSet.h index c96d536471d..a1bd602b2fc 100644 --- a/layout/style/nsStyleSet.h +++ b/layout/style/nsStyleSet.h @@ -39,6 +39,7 @@ struct nsFontFaceRuleContainer; struct TreeMatchContext; namespace mozilla { +class CSSStyleSheet; class EventStates; } // namespace mozilla @@ -311,25 +312,29 @@ class nsStyleSet final // APIs to manipulate the style sheet lists. The sheets in each // list are stored with the most significant sheet last. - nsresult AppendStyleSheet(mozilla::SheetType aType, nsIStyleSheet *aSheet); - nsresult PrependStyleSheet(mozilla::SheetType aType, nsIStyleSheet *aSheet); - nsresult RemoveStyleSheet(mozilla::SheetType aType, nsIStyleSheet *aSheet); + nsresult AppendStyleSheet(mozilla::SheetType aType, + mozilla::CSSStyleSheet* aSheet); + nsresult PrependStyleSheet(mozilla::SheetType aType, + mozilla::CSSStyleSheet* aSheet); + nsresult RemoveStyleSheet(mozilla::SheetType aType, + mozilla::CSSStyleSheet* aSheet); nsresult ReplaceSheets(mozilla::SheetType aType, - const nsCOMArray &aNewSheets); + const nsTArray>& aNewSheets); nsresult InsertStyleSheetBefore(mozilla::SheetType aType, - nsIStyleSheet *aNewSheet, - nsIStyleSheet *aReferenceSheet); + mozilla::CSSStyleSheet* aNewSheet, + mozilla::CSSStyleSheet* aReferenceSheet); // Enable/Disable entire author style level (Doc, ScopedDoc & PresHint levels) bool GetAuthorStyleDisabled(); nsresult SetAuthorStyleDisabled(bool aStyleDisabled); int32_t SheetCount(mozilla::SheetType aType) const { - return mSheets[aType].Count(); + return mSheets[aType].Length(); } - nsIStyleSheet* StyleSheetAt(mozilla::SheetType aType, int32_t aIndex) const { - return mSheets[aType].ObjectAt(aIndex); + mozilla::CSSStyleSheet* StyleSheetAt(mozilla::SheetType aType, + int32_t aIndex) const { + return mSheets[aType][aIndex]; } void AppendAllXBLStyleSheets(nsTArray& aArray) const { @@ -338,8 +343,9 @@ class nsStyleSet final } } - nsresult RemoveDocStyleSheet(nsIStyleSheet* aSheet); - nsresult AddDocStyleSheet(nsIStyleSheet* aSheet, nsIDocument* aDocument); + nsresult RemoveDocStyleSheet(mozilla::CSSStyleSheet* aSheet); + nsresult AddDocStyleSheet(mozilla::CSSStyleSheet* aSheet, + nsIDocument* aDocument); void BeginUpdate(); nsresult EndUpdate(); @@ -473,7 +479,7 @@ private: // eAnimationSheet and eSVGAttrAnimationSheet are always empty. // (FIXME: We should reduce the storage needed for them.) mozilla::EnumeratedArray> mSheets; + nsTArray>> mSheets; // mRuleProcessors[eScopedDocSheet] is always null; rule processors // for scoped style sheets are stored in mScopedDocSheetRuleProcessors.