зеркало из https://github.com/mozilla/gecko-dev.git
Make element and document RemoveChild methods share code. Bug 312522, patch by
Alex Vincent <ajvincent@gmail.com>, r=sicking, sr=bzbarsky
This commit is contained in:
Родитель
5a2ae03f16
Коммит
c34a138b91
|
@ -3595,34 +3595,8 @@ nsDocument::ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild,
|
|||
NS_IMETHODIMP
|
||||
nsDocument::RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn)
|
||||
{
|
||||
*aReturn = nsnull; // do we need to do this?
|
||||
|
||||
NS_ENSURE_TRUE(aOldChild, NS_ERROR_NULL_POINTER);
|
||||
|
||||
nsCOMPtr<nsIContent> content(do_QueryInterface(aOldChild));
|
||||
if (!content) {
|
||||
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
|
||||
}
|
||||
|
||||
PRInt32 indx = mChildren.IndexOfChild(content);
|
||||
if (indx == -1) {
|
||||
return NS_ERROR_DOM_NOT_FOUND_ERR;
|
||||
}
|
||||
|
||||
ContentRemoved(nsnull, content, indx);
|
||||
|
||||
mChildren.RemoveChildAt(indx);
|
||||
if (content == mRootContent) {
|
||||
DestroyLinkMap();
|
||||
mRootContent = nsnull;
|
||||
}
|
||||
|
||||
content->UnbindFromTree();
|
||||
|
||||
*aReturn = aOldChild;
|
||||
NS_ADDREF(aOldChild);
|
||||
|
||||
return NS_OK;
|
||||
return nsGenericElement::doRemoveChild(aOldChild, nsnull, this,
|
||||
mChildren, aReturn);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -3025,6 +3025,13 @@ nsGenericElement::ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild,
|
|||
mAttrsAndChildren, aReturn);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGenericElement::RemoveChild(nsIDOMNode *aOldChild, nsIDOMNode **aReturn)
|
||||
{
|
||||
return doRemoveChild(aOldChild, this, GetCurrentDoc(),
|
||||
mAttrsAndChildren, aReturn);
|
||||
}
|
||||
|
||||
// When replacing, aRefContent is the content being replaced; when
|
||||
// inserting it's the content before which we're inserting. In the
|
||||
// latter case it may be null.
|
||||
|
@ -3688,42 +3695,35 @@ nsGenericElement::doReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild,
|
|||
return CallQueryInterface(replacedChild, aReturn);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGenericElement::RemoveChild(nsIDOMNode *aOldChild, nsIDOMNode **aReturn)
|
||||
/* static */
|
||||
nsresult
|
||||
nsGenericElement::doRemoveChild(nsIDOMNode* aOldChild,
|
||||
nsIContent* aParent, nsIDocument* aDocument,
|
||||
nsAttrAndChildArray& aChildArray,
|
||||
nsIDOMNode** aReturn)
|
||||
{
|
||||
NS_PRECONDITION(aParent || aDocument, "Must have document if no parent!");
|
||||
NS_PRECONDITION(!aParent || aParent->GetCurrentDoc() == aDocument,
|
||||
"Incorrect aDocument");
|
||||
|
||||
*aReturn = nsnull;
|
||||
NS_ENSURE_TRUE(aOldChild, NS_ERROR_NULL_POINTER);
|
||||
|
||||
if (!aOldChild) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
nsresult res;
|
||||
|
||||
nsCOMPtr<nsIContent> content(do_QueryInterface(aOldChild, &res));
|
||||
|
||||
if (NS_FAILED(res)) {
|
||||
/*
|
||||
* If we're asked to remove something that doesn't support nsIContent
|
||||
* it can not be one of our children, i.e. we return NOT_FOUND_ERR.
|
||||
*/
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(aOldChild);
|
||||
// fix children to be a passed argument
|
||||
PRInt32 index = aChildArray.IndexOfChild(content);
|
||||
if (index == -1) {
|
||||
// aOldChild isn't one of our children.
|
||||
return NS_ERROR_DOM_NOT_FOUND_ERR;
|
||||
}
|
||||
|
||||
PRInt32 pos = IndexOf(content);
|
||||
|
||||
if (pos < 0) {
|
||||
/*
|
||||
* aOldChild isn't one of our children.
|
||||
*/
|
||||
return NS_ERROR_DOM_NOT_FOUND_ERR;
|
||||
}
|
||||
|
||||
res = RemoveChildAt(pos, PR_TRUE);
|
||||
nsContentOrDocument container(aParent, aDocument);
|
||||
nsresult rv = container.RemoveChildAt(index, PR_TRUE, aChildArray);
|
||||
|
||||
*aReturn = aOldChild;
|
||||
NS_ADDREF(aOldChild);
|
||||
|
||||
return res;
|
||||
return rv;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
|
|
@ -662,6 +662,23 @@ public:
|
|||
nsAttrAndChildArray& aChildArray,
|
||||
nsIDOMNode** aReturn);
|
||||
|
||||
/**
|
||||
* Actual implementation of the DOM RemoveChild method. Shared by
|
||||
* nsDocument. When called from nsDocument, aParent will be null.
|
||||
*
|
||||
* @param aOldChild The child to remove
|
||||
* @param aParent The parent to use for the new child
|
||||
* @param aDocument The document to use for the new child.
|
||||
* Must be non-null if aParent is null and must match
|
||||
* aParent->GetCurrentDoc() if aParent is not null.
|
||||
* @param aChildArray The child array to work with
|
||||
* @param aReturn [out] the child we remove
|
||||
*/
|
||||
static nsresult doRemoveChild(nsIDOMNode* aOldChild,
|
||||
nsIContent* aParent, nsIDocument* aDocument,
|
||||
nsAttrAndChildArray& aChildArray,
|
||||
nsIDOMNode** aReturn);
|
||||
|
||||
static nsresult InitHashes();
|
||||
|
||||
static PLDHashTable sEventListenerManagersHash;
|
||||
|
|
Загрузка…
Ссылка в новой задаче