Bug 1449791 - Remove now unused InserElement. draft
authorBrendan Dahl <brendan.dahl@gmail.com>
Tue, 24 Apr 2018 15:15:51 -0700
changeset 787550 c6c2e0bc3ba460f3b3ee5cb5c5ebfdaaeea5b7f1
parent 787549 0469350131b58f9f0bd21a003bf1ca4f07cb7e18
push id107743
push userbmo:bdahl@mozilla.com
push dateTue, 24 Apr 2018 23:03:09 +0000
bugs1449791
milestone61.0a1
Bug 1449791 - Remove now unused InserElement. MozReview-Commit-ID: JOIXN6uD2Qg
dom/xul/XULDocument.cpp
dom/xul/XULDocument.h
--- a/dom/xul/XULDocument.cpp
+++ b/dom/xul/XULDocument.cpp
@@ -2972,105 +2972,16 @@ XULDocument::CheckBroadcasterHookup(Elem
                 broadcasteridC.get()));
     }
 
     *aNeedsHookup = false;
     *aDidResolve = true;
     return NS_OK;
 }
 
-nsresult
-XULDocument::InsertElement(nsINode* aParent, nsIContent* aChild, bool aNotify)
-{
-    // Insert aChild appropriately into aParent, accounting for a
-    // 'pos' attribute set on aChild.
-
-    nsAutoString posStr;
-    bool wasInserted = false;
-
-    // insert after an element of a given id
-    if (aChild->IsElement()) {
-        aChild->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::insertafter, posStr);
-    }
-
-    bool isInsertAfter = true;
-    if (posStr.IsEmpty()) {
-        if (aChild->IsElement()) {
-            aChild->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::insertbefore, posStr);
-        }
-        isInsertAfter = false;
-    }
-
-    if (!posStr.IsEmpty()) {
-        nsIDocument *document = aParent->OwnerDoc();
-
-        nsIContent *content = nullptr;
-
-        char* str = ToNewCString(posStr);
-        char* rest;
-        char* token = nsCRT::strtok(str, ", ", &rest);
-
-        while (token) {
-            content = document->GetElementById(NS_ConvertASCIItoUTF16(token));
-            if (content)
-                break;
-
-            token = nsCRT::strtok(rest, ", ", &rest);
-        }
-        free(str);
-
-        if (content) {
-            if (content->GetParent() == aParent) {
-                nsIContent* nodeToInsertBefore =
-                  isInsertAfter ? content->GetNextSibling() : content;
-                nsresult rv = aParent->InsertChildBefore(aChild,
-                                                         nodeToInsertBefore,
-                                                         aNotify);
-                if (NS_FAILED(rv)) {
-                    return rv;
-                }
-
-                wasInserted = true;
-            }
-        }
-    }
-
-    if (!wasInserted) {
-        if (aChild->IsElement() &&
-            aChild->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::position, posStr) &&
-            !posStr.IsEmpty()) {
-            nsresult rv;
-            // Positions are one-indexed.
-            int32_t pos = posStr.ToInteger(&rv);
-            // Note: if the insertion index (which is |pos - 1|) would be less
-            // than 0 or greater than the number of children aParent has, then
-            // don't insert, since the position is bogus.  Just skip on to
-            // appending.
-            if (NS_SUCCEEDED(rv) && pos > 0 &&
-                uint32_t(pos - 1) <= aParent->GetChildCount()) {
-                nsIContent* nodeToInsertBefore =
-                    aParent->GetChildAt_Deprecated(pos - 1);
-                rv = aParent->InsertChildBefore(aChild, nodeToInsertBefore,
-                                                aNotify);
-                if (NS_SUCCEEDED(rv))
-                    wasInserted = true;
-                // If the insertion fails, then we should still
-                // attempt an append.  Thus, rather than returning rv
-                // immediately, we fall through to the final
-                // "catch-all" case that just does an AppendChildTo.
-            }
-        }
-    }
-
-    if (!wasInserted) {
-        return aParent->AppendChildTo(aChild, aNotify);
-    }
-    return NS_OK;
-}
-
 //----------------------------------------------------------------------
 //
 // CachedChromeStreamListener
 //
 
 XULDocument::CachedChromeStreamListener::CachedChromeStreamListener(XULDocument* aDocument, bool aProtoLoaded)
     : mDocument(aDocument),
       mProtoLoaded(aProtoLoaded)
--- a/dom/xul/XULDocument.h
+++ b/dom/xul/XULDocument.h
@@ -454,22 +454,16 @@ protected:
                            bool* aNeedsHookup,
                            bool* aDidResolve);
 
     void
     SynchronizeBroadcastListener(Element *aBroadcaster,
                                  Element *aListener,
                                  const nsAString &aAttr);
 
-    // FIXME: This should probably be renamed, there's nothing guaranteeing that
-    // aChild is an Element as far as I can tell!
-    static
-    nsresult
-    InsertElement(nsINode* aParent, nsIContent* aChild, bool aNotify);
-
     /**
      * The current prototype that we are walking to construct the
      * content model.
      */
     RefPtr<nsXULPrototypeDocument> mCurrentPrototype;
 
     /**
      * Owning references to all of the prototype documents that were