Bug 453858. Get rid of some XPCOM-ness in nsArraySH::GetItemAt. r+sr=jst

This commit is contained in:
Boris Zbarsky 2008-09-10 23:15:29 -04:00
parent 1bcc99f8b1
commit e3295081e1
18 changed files with 211 additions and 134 deletions

View File

@ -59,6 +59,7 @@ nsIMutationObserver.h \
nsINameSpaceManager.h \
nsINode.h \
nsINodeInfo.h \
nsINodeList.h \
nsIRange.h \
nsIRangeUtils.h \
nsIScriptElement.h \

View File

@ -0,0 +1,64 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla.org code.
*
* The Initial Developer of the Original Code is Mozilla.com.
* Portions created by the Initial Developer are Copyright (C) 2008
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Boris Zbarsky <bzbarsky@mit.edu> (Original Author)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsINodeList_h___
#define nsINodeList_h___
class nsINode;
// IID for the nsINodeList interface
#define NS_INODELIST_IID \
{ 0x06a6639a, 0x2d47, 0x4551, \
{ 0x94, 0xef, 0x93, 0xb8, 0xe1, 0x09, 0x3a, 0xb3 } }
/**
* An internal interface that allows QI-less getting of nodes from node lists
*/
class nsINodeList : public nsISupports {
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_INODELIST_IID)
/**
* Get the node at the index. Returns null if the index is out of bounds
*/
virtual nsINode* GetNodeAt(PRUint32 aIndex) = 0;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsINodeList, NS_INODELIST_IID)
#endif /* nsINodeList_h___ */

View File

@ -88,6 +88,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
// QueryInterface implementation for nsBaseContentList
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsBaseContentList)
NS_INTERFACE_MAP_ENTRY(nsINodeList)
NS_INTERFACE_MAP_ENTRY(nsIDOMNodeList)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMNodeList)
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(NodeList)
@ -109,7 +110,7 @@ nsBaseContentList::GetLength(PRUint32* aLength)
NS_IMETHODIMP
nsBaseContentList::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
{
nsISupports *tmp = mElements.SafeObjectAt(aIndex);
nsISupports *tmp = GetNodeAt(aIndex);
if (!tmp) {
*aReturn = nsnull;
@ -120,6 +121,12 @@ nsBaseContentList::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
return CallQueryInterface(tmp, aReturn);
}
nsINode*
nsBaseContentList::GetNodeAt(PRUint32 aIndex)
{
return mElements.SafeObjectAt(aIndex);
}
void
nsBaseContentList::AppendElement(nsIContent *aContent)
{
@ -467,10 +474,10 @@ nsContentList::GetLength(PRUint32* aLength)
NS_IMETHODIMP
nsContentList::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
{
nsIContent *content = Item(aIndex, PR_TRUE);
nsINode* node = GetNodeAt(aIndex);
if (content) {
return CallQueryInterface(content, aReturn);
if (node) {
return CallQueryInterface(node, aReturn);
}
*aReturn = nsnull;
@ -492,6 +499,12 @@ nsContentList::NamedItem(const nsAString& aName, nsIDOMNode** aReturn)
return NS_OK;
}
nsINode*
nsContentList::GetNodeAt(PRUint32 aIndex)
{
return Item(aIndex, PR_TRUE);
}
void
nsContentList::AttributeChanged(nsIDocument *aDocument, nsIContent* aContent,
PRInt32 aNameSpaceID, nsIAtom* aAttribute,

View File

@ -49,6 +49,7 @@
#include "nsString.h"
#include "nsIDOMHTMLCollection.h"
#include "nsIDOMNodeList.h"
#include "nsINodeList.h"
#include "nsStubMutationObserver.h"
#include "nsIAtom.h"
#include "nsINameSpaceManager.h"
@ -73,7 +74,8 @@ class nsIDocument;
class nsIDOMHTMLFormElement;
class nsBaseContentList : public nsIDOMNodeList
class nsBaseContentList : public nsIDOMNodeList,
public nsINodeList
{
public:
nsBaseContentList();
@ -83,7 +85,11 @@ public:
// nsIDOMNodeList
NS_DECL_NSIDOMNODELIST
NS_DECL_CYCLE_COLLECTION_CLASS(nsBaseContentList)
// nsINodeList
virtual nsINode* GetNodeAt(PRUint32 aIndex);
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsBaseContentList, nsIDOMNodeList)
void AppendElement(nsIContent *aContent);
void RemoveElement(nsIContent *aContent);
@ -232,6 +238,8 @@ public:
// nsBaseContentList overrides
virtual PRInt32 IndexOf(nsIContent *aContent, PRBool aDoFlush);
virtual nsINode* GetNodeAt(PRUint32 aIndex);
// nsContentList public methods
NS_HIDDEN_(nsISupports*) GetParentObject();

View File

@ -304,7 +304,7 @@ nsIdentifierMapEntry::Traverse(nsCycleCollectionTraversalCallback* aCallback)
if (mNameContentList != NAME_NOT_VALID) {
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*aCallback,
"mIdentifierMap mNameContentList");
aCallback->NoteXPCOMChild(mNameContentList);
aCallback->NoteXPCOMChild(static_cast<nsIDOMNodeList*>(mNameContentList));
}
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*aCallback, "mIdentifierMap mDocAllList");

View File

@ -58,9 +58,20 @@ NS_IMPL_RELEASE(nsGenericDOMNodeList)
// QueryInterface implementation for nsGenericDOMNodeList
NS_INTERFACE_MAP_BEGIN(nsGenericDOMNodeList)
NS_INTERFACE_MAP_ENTRY(nsINodeList)
NS_INTERFACE_MAP_ENTRY(nsIDOMNodeList)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMNodeList)
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(NodeList)
NS_INTERFACE_MAP_END
NS_IMETHODIMP
nsGenericDOMNodeList::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
{
nsINode* node = GetNodeAt(aIndex);
if (!node) {
*aReturn = nsnull;
return NS_OK;
}
return CallQueryInterface(node, aReturn);
}

View File

@ -36,17 +36,22 @@
* ***** END LICENSE BLOCK ***** */
/*
* A base class for simple DOM NodeLists which implements nsISupports
* and expects subclasess to implement GetLength() and Item()
* A base class for simple DOM NodeLists which implements nsISupports and Item()
* and expects subclasess to implement GetLength() and GetNodeAt()
*/
// XXXbz we don't use this for much... should we be using it more, or
// just nix it?
#ifndef nsGenericDOMNodeList_h__
#define nsGenericDOMNodeList_h__
#include "nsISupports.h"
#include "nsIDOMNodeList.h"
#include "nsINodeList.h"
class nsGenericDOMNodeList : public nsIDOMNodeList
class nsGenericDOMNodeList : public nsIDOMNodeList,
public nsINodeList
{
public:
nsGenericDOMNodeList();
@ -54,10 +59,14 @@ public:
NS_DECL_ISUPPORTS
NS_IMETHOD Item(PRUint32 aIndex, nsIDOMNode** aReturn);
// The following need to be defined in the subclass
// nsIDOMNodeList interface
NS_IMETHOD GetLength(PRUint32* aLength)=0;
NS_IMETHOD Item(PRUint32 aIndex, nsIDOMNode** aReturn)=0;
// nsINodeList interface
virtual nsINode* GetNodeAt(PRUint32 aIndex) = 0;
};
#endif // nsGenericDOMNodeList_h__

View File

@ -469,19 +469,14 @@ nsChildContentList::GetLength(PRUint32* aLength)
return NS_OK;
}
NS_IMETHODIMP
nsChildContentList::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
nsINode*
nsChildContentList::GetNodeAt(PRUint32 aIndex)
{
if (mNode) {
nsIContent *content = mNode->GetChildAt(aIndex);
if (content) {
return CallQueryInterface(content, aReturn);
}
return mNode->GetChildAt(aIndex);
}
*aReturn = nsnull;
return NS_OK;
return nsnull;
}
//----------------------------------------------------------------------
@ -1664,43 +1659,6 @@ nsNodeSelectorTearoff::QuerySelectorAll(const nsAString& aSelector,
return nsGenericElement::doQuerySelectorAll(mContent, aSelector, aReturn);
}
//----------------------------------------------------------------------
NS_IMPL_CYCLE_COLLECTION_CLASS(nsStaticContentList)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsStaticContentList)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mList)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsStaticContentList)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMARRAY(mList)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsStaticContentList)
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsStaticContentList)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsStaticContentList)
NS_INTERFACE_MAP_ENTRY(nsIDOMNodeList)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(NodeList)
NS_INTERFACE_MAP_END
NS_IMETHODIMP
nsStaticContentList::GetLength(PRUint32* aLength)
{
*aLength = mList.Count();
return NS_OK;
}
NS_IMETHODIMP
nsStaticContentList::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
{
nsIContent* c = mList.SafeObjectAt(aIndex);
if (!c) {
*aReturn = nsnull;
return NS_OK;
}
return CallQueryInterface(c, aReturn);
}
//----------------------------------------------------------------------
nsGenericElement::nsDOMSlots::nsDOMSlots(PtrBits aFlags)
: nsINode::nsSlots(aFlags),
@ -5274,7 +5232,7 @@ AppendAllMatchingElements(nsIContent* aMatchingElement,
void* aClosure)
{
NS_PRECONDITION(aMatchingElement && aClosure, "How did that happen?");
static_cast<nsStaticContentList*>(aClosure)->AppendContent(aMatchingElement);
static_cast<nsBaseContentList*>(aClosure)->AppendElement(aMatchingElement);
return PR_TRUE;
}
@ -5286,7 +5244,7 @@ nsGenericElement::doQuerySelectorAll(nsINode* aRoot,
{
NS_PRECONDITION(aReturn, "Null out param?");
nsStaticContentList* contentList = new nsStaticContentList();
nsBaseContentList* contentList = new nsBaseContentList();
NS_ENSURE_TRUE(contentList, NS_ERROR_OUT_OF_MEMORY);
NS_ADDREF(*aReturn = contentList);

View File

@ -101,7 +101,10 @@ public:
virtual ~nsChildContentList();
// nsIDOMNodeList interface
NS_DECL_NSIDOMNODELIST
NS_IMETHOD GetLength(PRUint32* aLength);
// nsINodeList interface
virtual nsINode* GetNodeAt(PRUint32 aIndex);
void DropReference()
{
@ -295,28 +298,6 @@ private:
nsCOMPtr<nsIContent> mContent;
};
/**
* A static NodeList class, which just holds a COMArray of nodes
*/
class nsStaticContentList : public nsIDOMNodeList {
public:
nsStaticContentList() {}
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_NSIDOMNODELIST
NS_DECL_CYCLE_COLLECTION_CLASS(nsStaticContentList)
PRBool AppendContent(nsIContent* aContent) {
return mList.AppendObject(aContent);
}
private:
~nsStaticContentList() {}
nsCOMArray<nsIContent> mList;
};
// Forward declare to allow being a friend
class nsNSElementTearoff;

View File

@ -350,7 +350,8 @@ PRBool nsHTMLFormElement::gPasswordManagerInitialized = PR_FALSE;
// nsFormControlList
class nsFormControlList : public nsIDOMNSHTMLFormControlList,
public nsIDOMHTMLCollection
public nsIDOMHTMLCollection,
public nsINodeList
{
public:
nsFormControlList(nsHTMLFormElement* aForm);
@ -368,6 +369,9 @@ public:
// nsIDOMNSHTMLFormControlList interface
NS_DECL_NSIDOMNSHTMLFORMCONTROLLIST
// nsINodeList interface
virtual nsINode* GetNodeAt(PRUint32 aIndex);
nsresult AddElementToTable(nsIFormControl* aChild,
const nsAString& aName);
nsresult RemoveElementFromTable(nsIFormControl* aChild,
@ -2114,8 +2118,9 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
// XPConnect interface list for nsFormControlList
NS_INTERFACE_TABLE_HEAD(nsFormControlList)
NS_INTERFACE_TABLE2(nsFormControlList,
NS_INTERFACE_TABLE3(nsFormControlList,
nsIDOMHTMLCollection,
nsINodeList,
nsIDOMNSHTMLFormControlList)
NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(nsFormControlList)
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLFormControlCollection)
@ -2141,16 +2146,15 @@ nsFormControlList::GetLength(PRUint32* aLength)
NS_IMETHODIMP
nsFormControlList::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
{
FlushPendingNotifications();
if (aIndex < mElements.Length()) {
return CallQueryInterface(mElements[aIndex], aReturn);
}
nsINode* node = GetNodeAt(aIndex);
if (!node) {
*aReturn = nsnull;
return NS_OK;
}
return CallQueryInterface(node, aReturn);
}
NS_IMETHODIMP
nsFormControlList::NamedItem(const nsAString& aName,
nsIDOMNode** aReturn)
@ -2194,6 +2198,18 @@ nsFormControlList::NamedItem(const nsAString& aName,
return NS_OK;
}
nsINode*
nsFormControlList::GetNodeAt(PRUint32 aIndex)
{
FlushPendingNotifications();
if (aIndex < mElements.Length()) {
mElements[aIndex];
}
return nsnull;
}
void
nsFormControlList::NamedItemInternal(const nsAString& aName,
PRBool aFlushContent,
@ -2246,7 +2262,8 @@ nsFormControlList::AddElementToTable(nsIFormControl* aChild,
// Add the new child too
list->AppendElement(newChild);
nsCOMPtr<nsISupports> listSupports = do_QueryInterface(list);
nsCOMPtr<nsISupports> listSupports =
do_QueryInterface(static_cast<nsIDOMNodeList*>(list));
// Replace the element with the list.
NS_ENSURE_TRUE(mNameLookupTable.Put(aName, listSupports),

View File

@ -94,7 +94,7 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(nsHTMLMapElement)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsHTMLMapElement,
nsGenericHTMLElement)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mAreas,
nsBaseContentList)
nsIDOMNodeList)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_ADDREF_INHERITED(nsHTMLMapElement, nsGenericElement)

View File

@ -144,7 +144,7 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(TableRowsCollection)
NS_IMPL_CYCLE_COLLECTION_UNLINK_0(TableRowsCollection)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(TableRowsCollection)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mOrphanRows,
nsBaseContentList)
nsIDOMNodeList)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(TableRowsCollection)
@ -354,7 +354,7 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(nsHTMLTableElement)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsHTMLTableElement,
nsGenericHTMLElement)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mTBodies,
nsBaseContentList)
nsIDOMNodeList)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mRows)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END

View File

@ -101,7 +101,7 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(nsHTMLTableRowElement)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsHTMLTableRowElement,
nsGenericHTMLElement)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mCells,
nsBaseContentList)
nsIDOMNodeList)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_ADDREF_INHERITED(nsHTMLTableRowElement, nsGenericElement)

View File

@ -99,7 +99,7 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(nsHTMLTableSectionElement)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsHTMLTableSectionElement,
nsGenericHTMLElement)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mRows,
nsBaseContentList)
nsIDOMNodeList)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_ADDREF_INHERITED(nsHTMLTableSectionElement, nsGenericElement)

View File

@ -92,17 +92,21 @@
{ 0xa29df1f8, 0xaeca, 0x4356, \
{ 0xa8, 0xc2, 0xa7, 0x24, 0xa2, 0x11, 0x73, 0xac } }
class nsAnonymousContentList : public nsIDOMNodeList
class nsAnonymousContentList : public nsIDOMNodeList,
public nsINodeList
{
public:
nsAnonymousContentList(nsInsertionPointList* aElements);
virtual ~nsAnonymousContentList();
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_CLASS(nsAnonymousContentList)
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsAnonymousContentList, nsIDOMNodeList)
// nsIDOMNodeList interface
NS_DECL_NSIDOMNODELIST
// nsINodeList interface
virtual nsINode* GetNodeAt(PRUint32 aIndex);
PRInt32 GetInsertionPointCount() { return mElements->Length(); }
nsXBLInsertionPoint* GetInsertionPointAt(PRInt32 i) { return static_cast<nsXBLInsertionPoint*>(mElements->ElementAt(i)); }
@ -136,9 +140,12 @@ NS_IMPL_CYCLE_COLLECTING_ADDREF(nsAnonymousContentList)
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsAnonymousContentList)
NS_INTERFACE_MAP_BEGIN(nsAnonymousContentList)
NS_INTERFACE_MAP_ENTRY(nsINodeList)
NS_INTERFACE_MAP_ENTRY(nsIDOMNodeList)
NS_INTERFACE_MAP_ENTRY(nsAnonymousContentList)
NS_INTERFACE_MAP_ENTRY(nsISupports)
if (aIID.Equals(NS_GET_IID(nsAnonymousContentList)))
foundInterface = static_cast<nsIDOMNodeList*>(this);
else
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMNodeList)
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(NodeList)
NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(nsAnonymousContentList)
NS_INTERFACE_MAP_END
@ -172,6 +179,16 @@ nsAnonymousContentList::GetLength(PRUint32* aLength)
NS_IMETHODIMP
nsAnonymousContentList::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
{
nsINode* item = GetNodeAt(aIndex);
if (!item)
return NS_ERROR_FAILURE;
return CallQueryInterface(item, aReturn);
}
nsINode*
nsAnonymousContentList::GetNodeAt(PRUint32 aIndex)
{
PRInt32 cnt = mElements->Length();
PRUint32 pointCount = 0;
@ -183,14 +200,11 @@ nsAnonymousContentList::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
pointCount = point->ChildCount();
if (aIndex < pointCount) {
nsCOMPtr<nsIContent> result = point->ChildAt(aIndex);
if (result)
return CallQueryInterface(result, aReturn);
return NS_ERROR_FAILURE;
return point->ChildAt(aIndex);
}
}
return NS_ERROR_FAILURE;
return nsnull;
}
//
@ -444,7 +458,10 @@ PR_CALLBACK RemoveInsertionParentCB(PLDHashTable* aTable, PLDHashEntryHdr* aEntr
static void
RemoveInsertionParentForNodeList(nsIDOMNodeList* aList, nsIContent* aParent)
{
nsCOMPtr<nsAnonymousContentList> list = do_QueryInterface(aList);
nsAnonymousContentList* list = nsnull;
if (aList) {
CallQueryInterface(aList, &list);
}
if (list) {
PRInt32 count = list->GetInsertionPointCount();
for (PRInt32 i = 0; i < count; ++i) {
@ -456,6 +473,7 @@ RemoveInsertionParentForNodeList(nsIDOMNodeList* aList, nsIContent* aParent)
#endif
currPoint->ClearInsertionParent();
}
NS_RELEASE(list);
}
}
@ -1509,8 +1527,9 @@ nsBindingManager::ContentRemoved(nsIDocument* aDocument,
// aChild from the pseudo insertion point it's in.
if (mContentListTable.ops) {
nsAnonymousContentList* insertionPointList =
static_cast<nsAnonymousContentList*>(LookupObject(mContentListTable,
aContainer));
static_cast<nsAnonymousContentList*>(
static_cast<nsIDOMNodeList*>(LookupObject(mContentListTable,
aContainer)));
if (insertionPointList) {
RemoveChildFromInsertionPoint(insertionPointList, aChild, PR_TRUE);
}

View File

@ -79,35 +79,28 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsXBLInsertionPoint, AddRef)
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsXBLInsertionPoint, Release)
already_AddRefed<nsIContent>
nsIContent*
nsXBLInsertionPoint::GetInsertionParent()
{
NS_IF_ADDREF(mParentElement);
return mParentElement;
}
already_AddRefed<nsIContent>
nsIContent*
nsXBLInsertionPoint::GetDefaultContent()
{
nsIContent* defaultContent = mDefaultContent;
NS_IF_ADDREF(defaultContent);
return defaultContent;
return mDefaultContent;
}
already_AddRefed<nsIContent>
nsIContent*
nsXBLInsertionPoint::GetDefaultContentTemplate()
{
nsIContent* defaultContent = mDefaultContentTemplate;
NS_IF_ADDREF(defaultContent);
return defaultContent;
return mDefaultContentTemplate;
}
already_AddRefed<nsIContent>
nsIContent*
nsXBLInsertionPoint::ChildAt(PRUint32 aIndex)
{
nsIContent* result = mElements.ObjectAt(aIndex);
NS_IF_ADDREF(result);
return result;
return mElements.ObjectAt(aIndex);
}
PRBool

View File

@ -62,16 +62,16 @@ public:
NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(nsXBLInsertionPoint)
already_AddRefed<nsIContent> GetInsertionParent();
nsIContent* GetInsertionParent();
void ClearInsertionParent() { mParentElement = nsnull; }
PRInt32 GetInsertionIndex() { return mIndex; }
void SetDefaultContent(nsIContent* aDefaultContent) { mDefaultContent = aDefaultContent; }
already_AddRefed<nsIContent> GetDefaultContent();
nsIContent* GetDefaultContent();
void SetDefaultContentTemplate(nsIContent* aDefaultContent) { mDefaultContentTemplate = aDefaultContent; }
already_AddRefed<nsIContent> GetDefaultContentTemplate();
nsIContent* GetDefaultContentTemplate();
void AddChild(nsIContent* aChildElement) { mElements.AppendObject(aChildElement); }
void InsertChildAt(PRInt32 aIndex, nsIContent* aChildElement) { mElements.InsertObjectAt(aChildElement, aIndex); }
@ -79,7 +79,7 @@ public:
PRInt32 ChildCount() { return mElements.Count(); }
already_AddRefed<nsIContent> ChildAt(PRUint32 aIndex);
nsIContent* ChildAt(PRUint32 aIndex);
PRBool Matches(nsIContent* aContent, PRUint32 aIndex);

View File

@ -7570,15 +7570,12 @@ nsresult
nsArraySH::GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsISupports **aResult)
{
nsCOMPtr<nsIDOMNodeList> list(do_QueryInterface(aNative));
nsCOMPtr<nsINodeList> list(do_QueryInterface(aNative));
NS_ENSURE_TRUE(list, NS_ERROR_UNEXPECTED);
nsIDOMNode *node = nsnull; // Weak, transfer the ownership over to aResult
nsresult rv = list->Item(aIndex, &node);
NS_IF_ADDREF(*aResult = list->GetNodeAt(aIndex));
*aResult = node;
return rv;
return NS_OK;
}
NS_IMETHODIMP
@ -7696,11 +7693,17 @@ nsresult
nsHTMLCollectionSH::GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsISupports **aResult)
{
// Common case is that we're also an nsINodeList
nsresult rv = nsArraySH::GetItemAt(aNative, aIndex, aResult);
if (NS_SUCCEEDED(rv)) {
return rv;
}
nsCOMPtr<nsIDOMHTMLCollection> collection(do_QueryInterface(aNative));
NS_ENSURE_TRUE(collection, NS_ERROR_UNEXPECTED);
nsIDOMNode *node = nsnull; // Weak, transfer the ownership over to aResult
nsresult rv = collection->Item(aIndex, &node);
rv = collection->Item(aIndex, &node);
*aResult = node;