diff --git a/content/base/public/nsIContentList.h b/content/base/public/nsIContentList.h index 17b4a7d96fe4..67d417147fd3 100644 --- a/content/base/public/nsIContentList.h +++ b/content/base/public/nsIContentList.h @@ -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. diff --git a/content/base/src/nsContentList.cpp b/content/base/src/nsContentList.cpp index 4c27d62175f3..711d1bd7ad1e 100644 --- a/content/base/src/nsContentList.cpp +++ b/content/base/src/nsContentList.cpp @@ -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) { diff --git a/content/base/src/nsContentList.h b/content/base/src/nsContentList.h index d6d6e37114f1..0a29880d60ac 100644 --- a/content/base/src/nsContentList.h +++ b/content/base/src/nsContentList.h @@ -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); diff --git a/dom/public/nsIDOMClassInfo.h b/dom/public/nsIDOMClassInfo.h index 17ed04d66556..10b8291df015 100644 --- a/dom/public/nsIDOMClassInfo.h +++ b/dom/public/nsIDOMClassInfo.h @@ -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 }; diff --git a/dom/src/base/nsDOMClassInfo.cpp b/dom/src/base/nsDOMClassInfo.cpp index 81d60642291e..4b75a905f7d9 100644 --- a/dom/src/base/nsDOMClassInfo.cpp +++ b/dom/src/base/nsDOMClassInfo.cpp @@ -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 contentList(do_QueryInterface(nativeObj)); + NS_ASSERTION(contentList, "Why does something not implementing nsIContentList use nsContentListSH??"); + + nsCOMPtr 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, diff --git a/dom/src/base/nsDOMClassInfo.h b/dom/src/base/nsDOMClassInfo.h index 2082cd91d995..2b33816abedc 100644 --- a/dom/src/base/nsDOMClassInfo.h +++ b/dom/src/base/nsDOMClassInfo.h @@ -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