Bug 1348481 Part 1b: Generalize FindDocStyleSheetInsertionPoint so it doesn't require an array of RefPtrs.
MozReview-Commit-ID: Aqnow6hFw5i
--- a/dom/base/nsIDocument.h
+++ b/dom/base/nsIDocument.h
@@ -1229,21 +1229,23 @@ public:
nsIURI* sheetURI) = 0;
virtual mozilla::StyleSheet* GetFirstAdditionalAuthorSheet() = 0;
/**
* Assuming that aDocSheets is an array of document-level style
* sheets for this document, returns the index that aSheet should
* be inserted at to maintain document ordering.
*
+ * Type T has to cast to StyleSheet*.
+ *
* Defined in nsIDocumentInlines.h.
*/
template<typename T>
- size_t FindDocStyleSheetInsertionPoint(const nsTArray<RefPtr<T>>& aDocSheets,
- T* aSheet);
+ size_t FindDocStyleSheetInsertionPoint(const nsTArray<T>& aDocSheets,
+ mozilla::StyleSheet* aSheet);
/**
* Get this document's CSSLoader. This is guaranteed to not return null.
*/
mozilla::css::Loader* CSSLoader() const {
return mCSSLoader;
}
--- a/dom/base/nsIDocumentInlines.h
+++ b/dom/base/nsIDocumentInlines.h
@@ -14,47 +14,46 @@ inline mozilla::dom::HTMLBodyElement*
nsIDocument::GetBodyElement()
{
return static_cast<mozilla::dom::HTMLBodyElement*>(GetHtmlChildElement(nsGkAtoms::body));
}
template<typename T>
size_t
nsIDocument::FindDocStyleSheetInsertionPoint(
- const nsTArray<RefPtr<T>>& aDocSheets,
- T* aSheet)
+ const nsTArray<T>& aDocSheets,
+ mozilla::StyleSheet* aSheet)
{
nsStyleSheetService* sheetService = nsStyleSheetService::GetInstance();
// lowest index first
int32_t newDocIndex = GetIndexOfStyleSheet(aSheet);
int32_t count = aDocSheets.Length();
int32_t 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);
if (sheetDocIndex > newDocIndex)
break;
- mozilla::StyleSheet* sheetHandle = sheet;
-
// If the sheet is not owned by the document it can be an author
// 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) {
if (sheetService) {
auto& authorSheets =
*sheetService->AuthorStyleSheets(GetStyleBackendType());
- if (authorSheets.IndexOf(sheetHandle) != authorSheets.NoIndex) {
+ if (authorSheets.IndexOf(sheet) != authorSheets.NoIndex) {
break;
}
}
- if (sheetHandle == GetFirstAdditionalAuthorSheet()) {
+ if (sheet == GetFirstAdditionalAuthorSheet()) {
break;
}
}
}
return size_t(index);
}