Bug 1348481 - Part 1b: Generalize FindDocStyleSheetInsertionPoint so it doesn't require an array of RefPtrs

Tag #1375
This commit is contained in:
Matt A. Tobin 2020-04-17 07:39:08 -04:00 • committed by Roy Tam
commit a36d367eeb
2 changed files with 10 additions and 9 deletions

View file

@ -1153,11 +1153,13 @@ public:
* sheets for this document, returns the index that aSheet should * sheets for this document, returns the index that aSheet should
* be inserted at to maintain document ordering. * be inserted at to maintain document ordering.
* *
* Type T has to cast to StyleSheet*.
*
* Defined in nsIDocumentInlines.h. * Defined in nsIDocumentInlines.h.
*/ */
template<typename T> template<typename T>
size_t FindDocStyleSheetInsertionPoint(const nsTArray<RefPtr<T>>& aDocSheets, size_t FindDocStyleSheetInsertionPoint(const nsTArray<T>& aDocSheets,
T* aSheet); mozilla::StyleSheet* aSheet);
/** /**
* Get this document's CSSLoader. This is guaranteed to not return null. * Get this document's CSSLoader. This is guaranteed to not return null.

View file

@ -19,8 +19,8 @@ nsIDocument::GetBodyElement()
template<typename T> template<typename T>
size_t size_t
nsIDocument::FindDocStyleSheetInsertionPoint( nsIDocument::FindDocStyleSheetInsertionPoint(
const nsTArray<RefPtr<T>>& aDocSheets, const nsTArray<T>& aDocSheets,
T* aSheet) mozilla::StyleSheet* aSheet)
{ {
nsStyleSheetService* sheetService = nsStyleSheetService::GetInstance(); nsStyleSheetService* sheetService = nsStyleSheetService::GetInstance();
@ -30,13 +30,12 @@ nsIDocument::FindDocStyleSheetInsertionPoint(
int32_t count = aDocSheets.Length(); int32_t count = aDocSheets.Length();
int32_t index; int32_t index;
for (index = 0; index < count; index++) { for (index = 0; index < count; index++) {
T* sheet = aDocSheets[index]; mozilla::StyleSheet* sheet = static_cast<mozilla::StyleSheet*>(
aDocSheets[index]);
int32_t sheetDocIndex = GetIndexOfStyleSheet(sheet); int32_t sheetDocIndex = GetIndexOfStyleSheet(sheet);
if (sheetDocIndex > newDocIndex) if (sheetDocIndex > newDocIndex)
break; break;
mozilla::StyleSheet* sheetHandle = sheet;
// If the sheet is not owned by the document it can be an author // If the sheet is not owned by the document it can be an author
// sheet registered at nsStyleSheetService or an additional author // sheet registered at nsStyleSheetService or an additional author
// sheet on the document, which means the new // sheet on the document, which means the new
@ -44,11 +43,11 @@ nsIDocument::FindDocStyleSheetInsertionPoint(
if (sheetDocIndex < 0) { if (sheetDocIndex < 0) {
if (sheetService) { if (sheetService) {
auto& authorSheets = *sheetService->AuthorStyleSheets(); auto& authorSheets = *sheetService->AuthorStyleSheets();
if (authorSheets.IndexOf(sheetHandle) != authorSheets.NoIndex) { if (authorSheets.IndexOf(sheet) != authorSheets.NoIndex) {
break; break;
} }
} }
if (sheetHandle == GetFirstAdditionalAuthorSheet()) { if (sheet == GetFirstAdditionalAuthorSheet()) {
break; break;
} }
} }