Adding support for DOM3 DOMStringList and DOMNameList. Bug 217159,

implementation by peterv, classinfo changes by me, r/sr=me on peterv's changes,
r/sr=peterv on my changes, r=caillon on the whole thing, sr=jst
This commit is contained in:
bzbarsky%mit.edu 2003-10-16 00:44:20 +00:00
parent 19efc5771e
commit af8ee5b35d
10 changed files with 432 additions and 15 deletions

View File

@ -78,6 +78,7 @@ CPPSRCS = \
nsDOMAttribute.cpp \
nsDOMAttributeMap.cpp \
nsDOMDocumentType.cpp \
nsDOMLists.cpp \
nsGeneratedIterator.cpp \
nsGenericDOMDataNode.cpp \
nsGenericDOMNodeList.cpp \

View File

@ -0,0 +1,142 @@
/* -*- 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
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2003
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Peter Van der Beken <peterv@netscape.com>
*
*
* 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 ***** */
#include "nsDOMLists.h"
#include "nsDOMError.h"
#include "nsIDOMClassInfo.h"
#include "nsContentUtils.h"
nsDOMStringList::nsDOMStringList()
{
}
nsDOMStringList::~nsDOMStringList()
{
}
NS_IMPL_ADDREF(nsDOMStringList)
NS_IMPL_RELEASE(nsDOMStringList)
NS_INTERFACE_MAP_BEGIN(nsDOMStringList)
NS_INTERFACE_MAP_ENTRY(nsIDOMDOMStringList)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(DOMStringList)
NS_INTERFACE_MAP_END
NS_IMETHODIMP
nsDOMStringList::Item(PRUint32 aIndex, nsAString& aResult)
{
if (aIndex >= (PRUint32)mNames.Count()) {
return NS_ERROR_DOM_INDEX_SIZE_ERR;
}
mNames.StringAt(aIndex, aResult);
return NS_OK;
}
NS_IMETHODIMP
nsDOMStringList::GetLength(PRUint32 *aLength)
{
*aLength = (PRUint32)mNames.Count();
return NS_OK;
}
nsNameList::nsNameList()
{
}
nsNameList::~nsNameList()
{
}
NS_IMPL_ADDREF(nsNameList)
NS_IMPL_RELEASE(nsNameList)
NS_INTERFACE_MAP_BEGIN(nsNameList)
NS_INTERFACE_MAP_ENTRY(nsIDOMNameList)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(NameList)
NS_INTERFACE_MAP_END
NS_IMETHODIMP
nsNameList::GetName(PRUint32 aIndex, nsAString& aResult)
{
if (aIndex >= (PRUint32)mNames.Count()) {
return NS_ERROR_DOM_INDEX_SIZE_ERR;
}
mNames.StringAt(aIndex, aResult);
return NS_OK;
}
NS_IMETHODIMP
nsNameList::GetNamespaceURI(PRUint32 aIndex, nsAString& aResult)
{
if (aIndex >= (PRUint32)mNames.Count()) {
return NS_ERROR_DOM_INDEX_SIZE_ERR;
}
mNamespaceURIs.StringAt(aIndex, aResult);
return NS_OK;
}
NS_IMETHODIMP
nsNameList::GetLength(PRUint32 *aLength)
{
*aLength = (PRUint32)mNames.Count();
return NS_OK;
}
PRBool
nsNameList::Add(const nsAString& aNamespaceURI, const nsAString& aName)
{
PRInt32 count = mNamespaceURIs.Count();
if (mNamespaceURIs.InsertStringAt(aNamespaceURI, count)) {
if (mNames.InsertStringAt(aName, count)) {
return PR_TRUE;
}
mNamespaceURIs.RemoveStringAt(count);
}
return PR_FALSE;
}

View File

@ -0,0 +1,81 @@
/* -*- 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
* Peter Van der Beken.
* Portions created by the Initial Developer are Copyright (C) 2003
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Peter Van der Beken <peterv@propagandism.org>
*
*
* 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 nsDOMLists_h___
#define nsDOMLists_h___
#include "nsIDOMDOMStringList.h"
#include "nsIDOMNameList.h"
#include "nsVoidArray.h"
class nsDOMStringList : public nsIDOMDOMStringList
{
public:
nsDOMStringList();
virtual ~nsDOMStringList();
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMDOMSTRINGLIST
PRBool Add(const nsAString& aName)
{
return mNames.AppendString(aName);
}
private:
nsStringArray mNames;
};
class nsNameList : public nsIDOMNameList
{
public:
nsNameList();
virtual ~nsNameList();
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMNAMELIST
PRBool Add(const nsAString& aNamespaceURI, const nsAString& aName);
private:
nsStringArray mNamespaceURIs;
nsStringArray mNames;
};
#endif /* nsDOMLists_h___ */

View File

@ -78,6 +78,8 @@ interface nsIDOMNodeList;
interface nsIDOMNotation;
interface nsIDOMProcessingInstruction;
interface nsIDOMText;
interface nsIDOMDOMStringList;
interface nsIDOMNameList;
// Needed for raises() in our IDL
interface DOMException;

View File

@ -51,12 +51,14 @@ SDK_XPIDLSRCS = \
nsIDOMText.idl \
$(NULL)
XPIDLSRCS = \
nsIDOM3Document.idl \
nsIDOM3Node.idl \
nsIDOM3Document.idl \
nsIDOMDOMStringList.idl \
nsIDOMNameList.idl \
nsIDOMNSDocument.idl \
nsIDOMXMLDocument.idl \
nsIDOMUserDataHandler.idl \
nsIDOMDOMConfiguration.idl \
nsIDOMUserDataHandler.idl \
nsIDOMDOMConfiguration.idl \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@ -0,0 +1,51 @@
/* -*- Mode: IDL; 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
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2003
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Peter Van der Beken <peterv@netscape.com>
*
*
* 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 ***** */
/**
* Corresponds to http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030609
*/
#include "domstubs.idl"
[scriptable, uuid(893f2075-b62b-11d7-af68-000a95687b38)]
interface nsIDOMDOMStringList : nsISupports
{
DOMString item(in unsigned long index);
readonly attribute unsigned long length;
};

View File

@ -0,0 +1,54 @@
/* -*- Mode: IDL; 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
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2003
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Peter Van der Beken <peterv@netscape.com>
*
*
* 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 ***** */
/**
* Corresponds to http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030609
*/
#include "domstubs.idl"
[scriptable, uuid(e9ceba95-b62b-11d7-af68-000a95687b38)]
interface nsIDOMNameList : nsISupports
{
DOMString getName(in unsigned long index)
raises(DOMException);
DOMString getNamespaceURI(in unsigned long index)
raises(DOMException);
readonly attribute unsigned long length;
};

View File

@ -274,6 +274,12 @@ enum nsDOMClassInfoID {
eDOMClassInfo_XULTreeBuilder_id,
#endif
// DOMStringList object
eDOMClassInfo_DOMStringList_id,
// NameList object used by the DOM
eDOMClassInfo_NameList_id,
// This one better be the last one in this list
eDOMClassInfoIDCount
};

View File

@ -105,6 +105,8 @@
#include "nsIDOM3Node.h"
#include "nsIDOMNodeList.h"
#include "nsIDOMNamedNodeMap.h"
#include "nsIDOMDOMStringList.h"
#include "nsIDOMNameList.h"
// HTMLFormElement helper includes
#include "nsIForm.h"
@ -831,6 +833,12 @@ static nsDOMClassInfoData sClassInfoData[] = {
NS_DEFINE_CLASSINFO_DATA(XULTreeBuilder, nsDOMGenericSH,
DEFAULT_SCRIPTABLE_FLAGS)
#endif
NS_DEFINE_CLASSINFO_DATA(DOMStringList, nsStringListSH,
ARRAY_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(NameList, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
};
nsIXPConnect *nsDOMClassInfo::sXPConnect = nsnull;
@ -2243,6 +2251,15 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_END
#endif
DOM_CLASSINFO_MAP_BEGIN(DOMStringList, nsIDOMDOMStringList)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMDOMStringList)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(NameList, nsIDOMNameList)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNameList)
DOM_CLASSINFO_MAP_END
#ifdef NS_DEBUG
{
PRUint32 i = sizeof(sClassInfoData) / sizeof(sClassInfoData[0]);
@ -4684,12 +4701,11 @@ nsElementSH::PostCreate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
return NS_OK;
}
// NodeList scriptable helper
// Generic array scriptable helper.
NS_IMETHODIMP
nsArraySH::Enumerate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, PRBool *_retval)
nsGenericArraySH::Enumerate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, PRBool *_retval)
{
// Recursion protection in case someone tries to be smart and call
// the enumerate hook from a user defined .length getter, or
@ -4724,6 +4740,8 @@ nsArraySH::Enumerate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
return ok ? NS_OK : NS_ERROR_UNEXPECTED;
}
// NodeList scriptable helper
nsresult
nsArraySH::GetItemAt(nsISupports *aNative, PRUint32 aIndex,
nsISupports **aResult)
@ -4770,6 +4788,19 @@ nsArraySH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
}
// StringList scriptable helper
nsresult
nsStringListSH::GetStringAt(nsISupports *aNative, PRInt32 aIndex,
nsAString& aResult)
{
nsCOMPtr<nsIDOMDOMStringList> list(do_QueryInterface(aNative));
NS_ENSURE_TRUE(list, NS_ERROR_UNEXPECTED);
return list->Item(aIndex, aResult);
}
// Named Array helper
NS_IMETHODIMP

View File

@ -434,12 +434,36 @@ public:
};
// NodeList scriptable helper
// Generic array scriptable helper
class nsArraySH : public nsDOMClassInfo
class nsGenericArraySH : public nsDOMClassInfo
{
protected:
nsArraySH(nsDOMClassInfoData* aData) : nsDOMClassInfo(aData)
nsGenericArraySH(nsDOMClassInfoData* aData) : nsDOMClassInfo(aData)
{
}
virtual ~nsGenericArraySH()
{
}
public:
NS_IMETHOD Enumerate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, PRBool *_retval);
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
{
return new nsGenericArraySH(aData);
}
};
// NodeList scriptable helper
class nsArraySH : public nsGenericArraySH
{
protected:
nsArraySH(nsDOMClassInfoData* aData) : nsGenericArraySH(aData)
{
}
@ -453,8 +477,6 @@ protected:
public:
NS_IMETHOD GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsval id, jsval *vp, PRBool *_retval);
NS_IMETHOD Enumerate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, PRBool *_retval);
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
{
@ -959,12 +981,12 @@ public:
};
// History helper
// String array helper
class nsStringArraySH : public nsDOMClassInfo
class nsStringArraySH : public nsGenericArraySH
{
protected:
nsStringArraySH(nsDOMClassInfoData* aData) : nsDOMClassInfo(aData)
nsStringArraySH(nsDOMClassInfoData* aData) : nsGenericArraySH(aData)
{
}
@ -1007,6 +1029,31 @@ public:
}
};
// StringList scriptable helper
class nsStringListSH : public nsStringArraySH
{
protected:
nsStringListSH(nsDOMClassInfoData* aData) : nsStringArraySH(aData)
{
}
virtual ~nsStringListSH()
{
}
virtual nsresult GetStringAt(nsISupports *aNative, PRInt32 aIndex,
nsAString& aResult);
public:
// Inherit GetProperty, Enumerate from nsStringArraySH
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
{
return new nsStringListSH(aData);
}
};
// MediaList helper