Bug 1348481 Part 1b: Generalize FindDocStyleSheetInsertionPoint so it doesn't require an array of RefPtrs. draft
authorBrad Werth <bwerth@mozilla.com>
Mon, 01 May 2017 16:12:04 -0700
changeset 571470 13a3b97a2597fa5e72a640a09dc2fdc7728e6d42
parent 571414 bfc7b187005cabbc828ed9f5b61daf139c3cfd90
child 571471 de49cdb244f63a10c8608bf293cf3a7419921484
push id56805
push userbwerth@mozilla.com
push dateTue, 02 May 2017 18:03:06 +0000
bugs1348481
milestone55.0a1
Bug 1348481 Part 1b: Generalize FindDocStyleSheetInsertionPoint so it doesn't require an array of RefPtrs. MozReview-Commit-ID: Aqnow6hFw5i
dom/base/nsIDocument.h
dom/base/nsIDocumentInlines.h
--- 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);
 }