Bug 153519 -- parent ContentLists to their root elements. r=peterv, sr=jst

This commit is contained in:
bzbarsky%mit.edu 2002-07-09 00:44:20 +00:00
Родитель 57d575aeb7
Коммит ab1e5e8701
6 изменённых файлов: 88 добавлений и 2 удалений

Просмотреть файл

@ -56,6 +56,11 @@ public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ICONTENTLIST_IID)
/**
* Returns the object that the content list should be parented to.
*/
NS_IMETHOD GetParentObject(nsISupports** aParentObject) = 0;
// Callers will want to pass in PR_TRUE for aDoFlush unless they
// are explicitly avoiding an FlushPendingNotifications. The
// flush guarantees that the list will be up to date.

Просмотреть файл

@ -449,7 +449,7 @@ nsContentList::~nsContentList()
NS_INTERFACE_MAP_BEGIN(nsContentList)
NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLCollection)
NS_INTERFACE_MAP_ENTRY(nsIContentList)
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLCollection)
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(ContentList)
NS_INTERFACE_MAP_END_INHERITING(nsBaseContentList)
@ -457,6 +457,19 @@ NS_IMPL_ADDREF_INHERITED(nsContentList, nsBaseContentList)
NS_IMPL_RELEASE_INHERITED(nsContentList, nsBaseContentList)
NS_IMETHODIMP
nsContentList::GetParentObject(nsISupports** aParentObject)
{
if (mRootContent) {
*aParentObject = mRootContent;
} else {
*aParentObject = mDocument;
}
NS_IF_ADDREF(*aParentObject);
return NS_OK;
}
NS_IMETHODIMP
nsContentList::GetLength(PRUint32* aLength, PRBool aDoFlush)
{

Просмотреть файл

@ -171,6 +171,7 @@ public:
NS_IMETHOD NamedItem(const nsAString& aName, nsIDOMNode** aReturn);
/// nsIContentList
NS_IMETHOD GetParentObject(nsISupports** aParentObject);
NS_IMETHOD GetLength(PRUint32* aLength, PRBool aDoFlush);
NS_IMETHOD Item(PRUint32 aIndex, nsIDOMNode** aReturn,
PRBool aDoFlush);

Просмотреть файл

@ -254,8 +254,13 @@ enum nsDOMClassInfoID {
eDOMClassInfo_RangeException_id,
// CSSValueList object that represents an nsIDOMCSSValueList, used
// by DOM CSS
eDOMClassInfo_CSSValueList_id,
// ContentList object used for various live NodeLists
eDOMClassInfo_ContentList_id,
// This one better be the last one in this list
eDOMClassInfoIDCount
};

Просмотреть файл

@ -134,6 +134,9 @@
#include "nsIDOMHTMLOptionElement.h"
#include "nsIDOMNSHTMLOptionCollectn.h"
// ContentList includes
#include "nsIContentList.h"
// Event related includes
#include "nsIEventListenerManager.h"
#include "nsIDOMEventReceiver.h"
@ -792,6 +795,10 @@ static nsDOMClassInfoData sClassInfoData[] = {
NS_DEFINE_CLASSINFO_DATA(CSSValueList, nsCSSValueListSH,
ARRAY_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA_WITH_NAME(ContentList, HTMLCollection,
nsContentListSH,
ARRAY_SCRIPTABLE_FLAGS |
nsIXPCScriptable::WANT_PRECREATE)
};
nsIXPConnect *nsDOMClassInfo::sXPConnect = nsnull;
@ -2093,6 +2100,11 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIException)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(ContentList, nsIDOMHTMLCollection)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNodeList)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMHTMLCollection)
DOM_CLASSINFO_MAP_END
#ifdef NS_DEBUG
{
PRUint32 i = sizeof(sClassInfoData) / sizeof(sClassInfoData[0]);
@ -4468,7 +4480,32 @@ nsHTMLCollectionSH::GetNamedItem(nsISupports *aNative,
}
// FomrControlList helper
// ContentList helper
nsresult
nsContentListSH::PreCreate(nsISupports *nativeObj, JSContext *cx,
JSObject *globalObj, JSObject **parentObj)
{
nsCOMPtr<nsIContentList> contentList(do_QueryInterface(nativeObj));
NS_ASSERTION(contentList, "Why does something not implementing nsIContentList use nsContentListSH??");
nsCOMPtr<nsISupports> native_parent;
contentList->GetParentObject(getter_AddRefs(native_parent));
if (!native_parent) {
*parentObj = globalObj;
return NS_OK;
}
jsval v;
nsresult rv = WrapNative(cx, ::JS_GetGlobalObject(cx), native_parent,
NS_GET_IID(nsISupports), &v);
*parentObj = JSVAL_TO_OBJECT(v);
return rv;
}
// FormControlList helper
nsresult
nsFormControlListSH::GetNamedItem(nsISupports *aNative,

Просмотреть файл

@ -524,6 +524,31 @@ public:
};
// ContentList helper
class nsContentListSH : public nsHTMLCollectionSH
{
protected:
nsContentListSH(nsDOMClassInfoData* aData) : nsHTMLCollectionSH(aData)
{
}
virtual ~nsContentListSH()
{
}
public:
NS_IMETHOD PreCreate(nsISupports *nativeObj, JSContext *cx,
JSObject *globalObj, JSObject **parentObj);
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
{
return new nsContentListSH(aData);
}
};
// FomrControlList helper
class nsFormControlListSH : public nsHTMLCollectionSH