Moved over to a new version of Level 1. NodeIterators and AttributeLists out. NodeLists and NamedNodeMaps in.

This commit is contained in:
vidur 1998-07-14 18:44:44 +00:00
Родитель 8a7ac050d5
Коммит 1900060e23
103 изменённых файлов: 4221 добавлений и 3861 удалений

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

@ -41,6 +41,7 @@ class nsIScriptContextOwner;
class nsIWebWidget;
class nsIDOMEvent;
class nsIDeviceContext;
class nsIParser;
// IID for the nsIDocument interface
#define NS_IDOCUMENT_IID \
@ -135,6 +136,14 @@ public:
virtual nsIScriptContextOwner *GetScriptContextOwner() = 0;
virtual void SetScriptContextOwner(nsIScriptContextOwner *aScriptContextOwner) = 0;
/**
* Pass the document a reference to its parser. The assumption is
* that the parser will only be set while document loading is
* being carried out.
*/
virtual nsIParser *GetParser() = 0;
virtual void SetParser(nsIParser *aParser) = 0;
//----------------------------------------------------------------------
// Document notification API's

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

@ -29,6 +29,7 @@
#include "nsEventListenerManager.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptContextOwner.h"
#include "nsIParser.h"
#include "nsSelection.h"
#include "nsIDOMText.h"
@ -129,6 +130,7 @@ nsDocument::nsDocument()
mScriptObject = nsnull;
mScriptContextOwner = nsnull;
mListenerManager = nsnull;
mParser = nsnull;
if (NS_OK != NS_NewSelection(&mSelection)) {
printf("*************** Error: nsDocument::nsDocument - Creation of Selection failed!\n");
@ -165,6 +167,7 @@ nsDocument::~nsDocument()
NS_IF_RELEASE(mArena);
NS_IF_RELEASE(mSelection);
NS_IF_RELEASE(mScriptContextOwner);
NS_IF_RELEASE(mParser);
}
nsresult nsDocument::QueryInterface(REFNSIID aIID, void** aInstancePtr)
@ -410,6 +413,22 @@ void nsDocument::SetScriptContextOwner(nsIScriptContextOwner *aScriptContextOwne
}
}
nsIParser *nsDocument::GetParser()
{
NS_IF_ADDREF(mParser);
return mParser;
}
void nsDocument::SetParser(nsIParser *aParser)
{
NS_IF_RELEASE(mParser);
mParser = aParser;
NS_IF_ADDREF(mParser);
}
// Note: We don't hold a reference to the document observer; we assume
// that it has a live reference to the document.
void nsDocument::AddObserver(nsIDocumentObserver* aObserver)
@ -536,142 +555,51 @@ nsresult nsDocument::ResetScriptObject()
//
// nsIDOMDocument interface
//
nsresult nsDocument::GetNodeType(PRInt32 *aType)
{
*aType = nsIDOMNode::DOCUMENT;
return NS_OK;
}
nsresult nsDocument::GetParentNode(nsIDOMNode **aNode)
{
return NS_ERROR_FAILURE;
}
nsresult nsDocument::GetChildNodes(nsIDOMNodeIterator **aIterator)
{
//XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsDocument::HasChildNodes(PRBool *aReturn)
{
if (nsnull != mRootContent) {
*aReturn = PR_TRUE;
}
else {
*aReturn = PR_FALSE;
}
return NS_OK;
}
nsresult nsDocument::GetFirstChild(nsIDOMNode **aNode)
{
if (nsnull != mRootContent) {
nsresult res = mRootContent->QueryInterface(kIDOMNodeIID, (void**)aNode);
NS_ASSERTION(NS_OK == res, "Must be a DOM Node");
return res;
}
return NS_ERROR_FAILURE;
}
nsresult nsDocument::GetPreviousSibling(nsIDOMNode **aNode)
{
// no siblings
return NS_ERROR_FAILURE;
}
nsresult nsDocument::GetNextSibling(nsIDOMNode **aNode)
{
// no siblings
return NS_ERROR_FAILURE;
}
nsresult nsDocument::InsertBefore(nsIDOMNode *newChild, nsIDOMNode *refChild)
{
// a document has only one child
return NS_ERROR_FAILURE;
}
nsresult nsDocument::ReplaceChild(nsIDOMNode *newChild, nsIDOMNode *oldChild)
{
NS_PRECONDITION(nsnull != newChild && nsnull != oldChild, "null arg");
nsIContent* content;
nsresult res = oldChild->QueryInterface(kIContentIID, (void**)&content);
if (NS_OK == res) {
// check that we are replacing the root content
if (content == mRootContent) {
nsIContent* newContent;
res = newChild->QueryInterface(kIContentIID, (void**)&newContent);
if (NS_OK == res) {
SetRootContent(newContent);
NS_RELEASE(newContent);
}
else NS_ASSERTION(0, "Must be an nsIContent"); // nsIContent not supported. Who are you?
}
NS_RELEASE(content);
}
else NS_ASSERTION(0, "Must be an nsIContent"); // nsIContent not supported. Who are you?
return res;
}
nsresult nsDocument::RemoveChild(nsIDOMNode *oldChild)
{
NS_PRECONDITION(nsnull != oldChild, "null arg");
nsIContent* content;
nsresult res = oldChild->QueryInterface(kIContentIID, (void**)&content);
if (NS_OK == res) {
if (content == mRootContent) {
NS_RELEASE(mRootContent);
mRootContent = nsnull;
}
}
return res;
}
nsresult nsDocument::GetMasterDoc(nsIDOMDocument **aDocument)
NS_IMETHODIMP
nsDocument::GetMasterDoc(nsIDOMDocument **aDocument)
{
AddRef();
*aDocument = (nsIDOMDocument*)this;
return NS_OK;
}
nsresult nsDocument::SetMasterDoc(nsIDOMDocument *aDocument)
NS_IMETHODIMP
nsDocument::GetDocumentType(nsIDOMDocumentType** aDocumentType)
{
//XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsDocument::GetDocumentType(nsIDOMNode **aDocType)
NS_IMETHODIMP
nsDocument::GetProlog(nsIDOMNodeList** aProlog)
{
//XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
*aProlog = nsnull;
return NS_OK;
}
nsresult nsDocument::SetDocumentType(nsIDOMNode *aNode)
NS_IMETHODIMP
nsDocument::GetEpilog(nsIDOMNodeList** aEpilog)
{
//XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
*aEpilog = nsnull;
return NS_OK;
}
nsresult nsDocument::GetDocumentElement(nsIDOMElement **aElement)
NS_IMETHODIMP
nsDocument::GetDocumentElement(nsIDOMElement** aDocumentElement)
{
nsresult res = NS_ERROR_FAILURE;
if (nsnull != mRootContent) {
res = mRootContent->QueryInterface(kIDOMElementIID, (void**)aElement);
res = mRootContent->QueryInterface(kIDOMElementIID, (void**)aDocumentElement);
NS_ASSERTION(NS_OK == res, "Must be a DOM Element");
}
return res;
}
nsresult nsDocument::SetDocumentElement(nsIDOMElement *aElement)
#if 0
NS_IMETHODIMP
nsDocument::SetDocumentElement(nsIDOMElement *aElement)
{
NS_PRECONDITION(nsnull != aElement, "null arg");
nsIContent* content;
@ -685,74 +613,183 @@ nsresult nsDocument::SetDocumentElement(nsIDOMElement *aElement)
return res;
}
#endif
nsresult nsDocument::GetDocumentContext(nsIDOMDocumentContext **aDocContext)
NS_IMETHODIMP
nsDocument::CreateElement(const nsString& aTagName,
nsIDOMNamedNodeMap* aAttributes,
nsIDOMElement** aReturn)
{
//XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDocument::CreateTextNode(const nsString& aData, nsIDOMText** aReturn)
{
//XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsDocument::SetDocumentContext(nsIDOMDocumentContext *aContext)
NS_IMETHODIMP
nsDocument::CreateDocumentFragment(nsIDOMDocumentFragment** aReturn)
{
//XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsDocument::CreateDocumentContext(nsIDOMDocumentContext **aDocContext)
NS_IMETHODIMP
nsDocument::CreateComment(const nsString& aData, nsIDOMComment** aReturn)
{
//XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsDocument::CreateElement(nsString &aTagName,
nsIDOMAttributeList *aAttributes,
nsIDOMElement **aElement)
{
//XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsDocument::CreateTextNode(nsString &aData, nsIDOMText** aTextNode)
NS_IMETHODIMP
nsDocument::CreateProcessingInstruction(const nsString& aTarget,
const nsString& aData,
nsIDOMProcessingInstruction** aReturn)
{
//XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsDocument::CreateComment(nsString &aData, nsIDOMComment **aComment)
NS_IMETHODIMP
nsDocument::CreateAttribute(const nsString& aName,
nsIDOMNode* aValue,
nsIDOMAttribute** aReturn)
{
//XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsDocument::CreatePI(nsString &aName, nsString &aData, nsIDOMPI **aPI)
NS_IMETHODIMP
nsDocument::GetElementsByTagName(const nsString& aTagname,
nsIDOMNodeList** aReturn)
{
//XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsDocument::CreateAttribute(nsString &aName,
nsIDOMNode *value,
nsIDOMAttribute **aAttribute)
//
// nsIDOMNode methods
//
NS_IMETHODIMP
nsDocument::GetNodeName(nsString& aNodeName)
{
//XXX TBI
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsDocument::CreateAttributeList(nsIDOMAttributeList **aAttributesList)
NS_IMETHODIMP
nsDocument::GetNodeValue(nsString& aNodeValue)
{
//XXX TBI
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsDocument::CreateTreeIterator(nsIDOMNode *aNode, nsIDOMTreeIterator **aTreeIterator)
NS_IMETHODIMP
nsDocument::SetNodeValue(const nsString& aNodeValue)
{
//XXX TBI
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsDocument::GetElementsByTagName(nsString &aTagname, nsIDOMNodeIterator **aIterator)
NS_IMETHODIMP
nsDocument::GetNodeType(PRInt32* aNodeType)
{
//XXX TBI
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDocument::GetParentNode(nsIDOMNode** aParentNode)
{
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDocument::GetChildNodes(nsIDOMNodeList** aChildNodes)
{
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDocument::GetHasChildNodes(PRBool* aHasChildNodes)
{
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDocument::GetFirstChild(nsIDOMNode** aFirstChild)
{
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDocument::GetLastChild(nsIDOMNode** aLastChild)
{
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDocument::GetPreviousSibling(nsIDOMNode** aPreviousSibling)
{
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDocument::GetNextSibling(nsIDOMNode** aNextSibling)
{
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDocument::GetAttributes(nsIDOMNamedNodeMap** aAttributes)
{
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDocument::InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, nsIDOMNode** aReturn)
{
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDocument::ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, nsIDOMNode** aReturn)
{
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDocument::RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn)
{
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDocument::CloneNode(nsIDOMNode** aReturn)
{
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDocument::Equals(nsIDOMNode* aNode, PRBool aDeep, PRBool* aReturn)
{
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}

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

@ -27,6 +27,7 @@
class nsISelection;
class nsIEventListenerManager;
class nsIParser;
class nsPostData : public nsIPostData {
public:
@ -115,6 +116,14 @@ public:
virtual nsIScriptContextOwner *GetScriptContextOwner();
virtual void SetScriptContextOwner(nsIScriptContextOwner *aScriptContextOwner);
/**
* Pass the document a reference to its parser. The assumption is
* that the parser will only be set while document loading is
* being carried out.
*/
virtual nsIParser *GetParser();
virtual void SetParser(nsIParser *aParser);
/**
* Add a new observer of document change notifications. Whenever
* content is changed, appended, inserted or removed the observers are
@ -182,37 +191,39 @@ public:
NS_IMETHOD ResetScriptObject();
// nsIDOMDocument interface
NS_IMETHOD GetNodeType(PRInt32 *aType);
NS_IMETHOD GetParentNode(nsIDOMNode **aNode);
NS_IMETHOD GetChildNodes(nsIDOMNodeIterator **aIterator);
NS_IMETHOD HasChildNodes(PRBool *aReturn);
NS_IMETHOD GetFirstChild(nsIDOMNode **aNode);
NS_IMETHOD GetPreviousSibling(nsIDOMNode **aNode);
NS_IMETHOD GetNextSibling(nsIDOMNode **aNode);
NS_IMETHOD InsertBefore(nsIDOMNode *newChild, nsIDOMNode *refChild);
NS_IMETHOD ReplaceChild(nsIDOMNode *newChild, nsIDOMNode *oldChild);
NS_IMETHOD RemoveChild(nsIDOMNode *oldChild);
NS_IMETHOD GetMasterDoc(nsIDOMDocument **aDocument);
NS_IMETHOD SetMasterDoc(nsIDOMDocument *aDocument);
NS_IMETHOD GetDocumentType(nsIDOMNode **aDocType);
NS_IMETHOD SetDocumentType(nsIDOMNode *aNode);
NS_IMETHOD GetDocumentElement(nsIDOMElement **aElement);
NS_IMETHOD SetDocumentElement(nsIDOMElement *aElement);
NS_IMETHOD GetDocumentContext(nsIDOMDocumentContext **aDocContext);
NS_IMETHOD SetDocumentContext(nsIDOMDocumentContext *aContext);
NS_IMETHOD CreateDocumentContext(nsIDOMDocumentContext **aDocContext);
NS_IMETHOD CreateElement(nsString &aTagName,
nsIDOMAttributeList *aAttributes,
nsIDOMElement **aElement);
NS_IMETHOD CreateTextNode(nsString &aData, nsIDOMText** aTextNode);
NS_IMETHOD CreateComment(nsString &aData, nsIDOMComment **aComment);
NS_IMETHOD CreatePI(nsString &aName, nsString &aData, nsIDOMPI **aPI);
NS_IMETHOD CreateAttribute(nsString &aName,
nsIDOMNode *value,
nsIDOMAttribute **aAttribute);
NS_IMETHOD CreateAttributeList(nsIDOMAttributeList **aAttributesList);
NS_IMETHOD CreateTreeIterator(nsIDOMNode *aNode, nsIDOMTreeIterator **aTreeIterator);
NS_IMETHOD GetElementsByTagName(nsString &aTagname, nsIDOMNodeIterator **aIterator);
NS_IMETHOD GetMasterDoc(nsIDOMDocument **aDocument);
NS_IMETHOD GetDocumentType(nsIDOMDocumentType** aDocumentType);
NS_IMETHOD GetProlog(nsIDOMNodeList** aProlog);
NS_IMETHOD GetEpilog(nsIDOMNodeList** aEpilog);
NS_IMETHOD GetDocumentElement(nsIDOMElement** aDocumentElement);
NS_IMETHOD CreateDocumentFragment(nsIDOMDocumentFragment** aReturn);
NS_IMETHOD CreateComment(const nsString& aData, nsIDOMComment** aReturn);
NS_IMETHOD CreateProcessingInstruction(const nsString& aTarget, const nsString& aData, nsIDOMProcessingInstruction** aReturn);
NS_IMETHOD CreateAttribute(const nsString& aName, nsIDOMNode* aValue, nsIDOMAttribute** aReturn);
NS_IMETHOD CreateElement(const nsString& aTagName,
nsIDOMNamedNodeMap* aAttributes,
nsIDOMElement** aReturn);
NS_IMETHOD CreateTextNode(const nsString& aData, nsIDOMText** aReturn);
NS_IMETHOD GetElementsByTagName(const nsString& aTagname, nsIDOMNodeList** aReturn);
// nsIDOMNode
NS_IMETHOD GetNodeName(nsString& aNodeName);
NS_IMETHOD GetNodeValue(nsString& aNodeValue);
NS_IMETHOD SetNodeValue(const nsString& aNodeValue);
NS_IMETHOD GetNodeType(PRInt32* aNodeType);
NS_IMETHOD GetParentNode(nsIDOMNode** aParentNode);
NS_IMETHOD GetChildNodes(nsIDOMNodeList** aChildNodes);
NS_IMETHOD GetHasChildNodes(PRBool* aHasChildNodes);
NS_IMETHOD GetFirstChild(nsIDOMNode** aFirstChild);
NS_IMETHOD GetLastChild(nsIDOMNode** aLastChild);
NS_IMETHOD GetPreviousSibling(nsIDOMNode** aPreviousSibling);
NS_IMETHOD GetNextSibling(nsIDOMNode** aNextSibling);
NS_IMETHOD GetAttributes(nsIDOMNamedNodeMap** aAttributes);
NS_IMETHOD InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, nsIDOMNode** aReturn);
NS_IMETHOD ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, nsIDOMNode** aReturn);
NS_IMETHOD RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn);
NS_IMETHOD CloneNode(nsIDOMNode** aReturn);
NS_IMETHOD Equals(nsIDOMNode* aNode, PRBool aDeep, PRBool* aReturn);
// nsIDOMEventCapturer interface
NS_IMETHOD CaptureEvent(nsIDOMEventListener *aListener);
@ -248,6 +259,7 @@ protected:
nsVoidArray mObservers;
void* mScriptObject;
nsIScriptContextOwner *mScriptContextOwner;
nsIParser *mParser;
nsIEventListenerManager* mListenerManager;
};

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

@ -244,22 +244,22 @@ void nsHTMLDocument::AddStyleSheetToSet(nsIStyleSheet* aSheet, nsIStyleSet* aSet
}
}
nsresult
nsHTMLDocument::CreateElement(nsString& aTagName,
nsIDOMAttributeList* aAttributes,
nsIDOMElement** aElement)
NS_IMETHODIMP
nsHTMLDocument::CreateElement(const nsString& aTagName,
nsIDOMNamedNodeMap* aAttributes,
nsIDOMElement** aReturn)
{
nsIHTMLContent* content;
nsresult rv = NS_CreateHTMLElement(&content, aTagName);
if (NS_OK != rv) {
return rv;
}
rv = content->QueryInterface(kIDOMElementIID, (void**)aElement);
rv = content->QueryInterface(kIDOMElementIID, (void**)aReturn);
return rv;
}
nsresult
nsHTMLDocument::CreateTextNode(nsString &aData, nsIDOMText** aTextNode)
NS_IMETHODIMP
nsHTMLDocument::CreateTextNode(const nsString& aData, nsIDOMText** aTextNode)
{
nsIHTMLContent* text = nsnull;
nsresult rv = NS_NewHTMLText(&text, aData, aData.Length());

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

@ -46,10 +46,10 @@ public:
return offsetof(nsHTMLDocument,mIHTMLDocument);
}
NS_IMETHOD CreateElement(nsString &aTagName,
nsIDOMAttributeList *aAttributes,
nsIDOMElement **aElement);
NS_IMETHOD CreateTextNode(nsString &aData, nsIDOMText** aTextNode);
NS_IMETHOD CreateElement(const nsString& aTagName,
nsIDOMNamedNodeMap* aAttributes,
nsIDOMElement** aReturn);
NS_IMETHOD CreateTextNode(const nsString& aData, nsIDOMText** aReturn);
protected:
virtual void AddStyleSheetToSet(nsIStyleSheet* aSheet, nsIStyleSet* aSet);

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

@ -17,15 +17,16 @@
#
nsIDOMAttribute.h
nsIDOMAttributeList.h
nsIDOMCDATASection.h
nsIDOMComment.h
nsIDOMData.h
nsIDOMDOM.h
nsIDOMDocument.h
nsIDOMDocumentContext.h
nsIDOMDocumentType.h
nsIDOMDocumentFragment.h
nsIDOMElement.h
nsIDOMNode.h
nsIDOMNodeIterator.h
nsIDOMPI.h
nsIDOMNamedNodeMap.h
nsIDOMNodeList.h
nsIDOMProcessingInstruction.h
nsIDOMText.h
nsIDOMTreeIterator.h

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

@ -21,18 +21,19 @@ DEFINES = -D_IMPL_NS_DOM
EXPORTS = \
nsIDOMAttribute.h \
nsIDOMAttributeList.h \
nsIDOMCDATASection.h \
nsIDOMComment.h \
nsIDOMData.h \
nsIDOMDOM.h \
nsIDOMDocument.h \
nsIDOMDocumentContext.h \
nsIDOMDocumentType.h \
nsIDOMDocumentFragment.h \
nsIDOMElement.h \
nsIDOMNode.h \
nsIDOMNodeIterator.h \
nsIDOMPI.h \
nsIDOMNamedNodeMap.h \
nsIDOMNodeList.h \
nsIDOMProcessingInstruction.h \
nsIDOMText.h \
nsIDOMTreeIterator.h \
$(NULL)
MODULE = dom

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

@ -19,10 +19,11 @@ DEPTH=..\..\..
IGNORE_MANIFEST=1
DEFINES=-D_IMPL_NS_DOM
EXPORTS=nsIDOMAttribute.h nsIDOMAttributeList.h nsIDOMComment.h \
nsIDOMDOM.h nsIDOMDocument.h nsIDOMDocumentContext.h \
EXPORTS=nsIDOMAttribute.h nsIDOMCDATASection.h nsIDOMComment.h nsIDOMData.h \
nsIDOMDOM.h nsIDOMDocument.h nsIDOMDocumentType.h \
nsIDOMDocumentFragment.h nsIDOMElement.h nsIDOMNode.h \
nsIDOMNodeIterator.h nsIDOMPI.h nsIDOMText.h nsIDOMTreeIterator.h
nsIDOMNamedNodeMap.h nsIDOMNodeList.h nsIDOMProcessingInstruction.h \
nsIDOMText.h
MODULE=dom

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

@ -23,6 +23,7 @@
#include "nsISupports.h"
#include "nsString.h"
#include "nsIScriptContext.h"
#include "nsIDOMNode.h"
class nsIDOMAttribute;
@ -30,22 +31,19 @@ class nsIDOMAttribute;
{ 0x6f7652e0, 0xee43, 0x11d1, \
{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }
class nsIDOMAttribute : public nsISupports {
class nsIDOMAttribute : public nsIDOMNode {
public:
NS_IMETHOD GetValue(nsString& aValue)=0;
NS_IMETHOD SetValue(nsString& aValue)=0;
NS_IMETHOD GetName(nsString& aName)=0;
NS_IMETHOD GetSpecified(PRBool* aSpecified)=0;
NS_IMETHOD SetSpecified(PRBool aSpecified)=0;
NS_IMETHOD GetName(nsString& aReturn)=0;
NS_IMETHOD ToString(nsString& aReturn)=0;
NS_IMETHOD GetValue(nsString& aValue)=0;
};
extern nsresult NS_InitAttributeClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM NS_NewScriptAttribute(nsIScriptContext *aContext, nsIDOMAttribute *aSupports, nsISupports *aParent, void **aReturn);
extern "C" NS_DOM nsresult NS_NewScriptAttribute(nsIScriptContext *aContext, nsIDOMAttribute *aSupports, nsISupports *aParent, void **aReturn);
#endif // nsIDOMAttribute_h__

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

@ -17,29 +17,26 @@
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#ifndef nsIDOMDocumentContext_h__
#define nsIDOMDocumentContext_h__
#ifndef nsIDOMCDATASection_h__
#define nsIDOMCDATASection_h__
#include "nsISupports.h"
#include "nsString.h"
#include "nsIScriptContext.h"
#include "nsIDOMText.h"
class nsIDOMDocument;
class nsIDOMDocumentContext;
class nsIDOMCDATASection;
#define NS_IDOMDOCUMENTCONTEXT_IID \
{ 0x6f7652e4, 0xee43, 0x11d1, \
#define NS_IDOMCDATASECTION_IID \
{ 0x6f7652e1, 0xee43, 0x11d1, \
{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }
class nsIDOMDocumentContext : public nsISupports {
class nsIDOMCDATASection : public nsIDOMText {
public:
NS_IMETHOD GetDocument(nsIDOMDocument** aDocument)=0;
NS_IMETHOD SetDocument(nsIDOMDocument* aDocument)=0;
};
extern nsresult NS_InitDocumentContextClass(nsIScriptContext *aContext, void **aPrototype);
extern nsresult NS_InitCDATASectionClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM NS_NewScriptDocumentContext(nsIScriptContext *aContext, nsIDOMDocumentContext *aSupports, nsISupports *aParent, void **aReturn);
extern "C" NS_DOM nsresult NS_NewScriptCDATASection(nsIScriptContext *aContext, nsIDOMCDATASection *aSupports, nsISupports *aParent, void **aReturn);
#endif // nsIDOMDocumentContext_h__
#endif // nsIDOMCDATASection_h__

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

@ -23,7 +23,7 @@
#include "nsISupports.h"
#include "nsString.h"
#include "nsIScriptContext.h"
#include "nsIDOMNode.h"
#include "nsIDOMData.h"
class nsIDOMComment;
@ -31,15 +31,12 @@ class nsIDOMComment;
{ 0x6f7652e2, 0xee43, 0x11d1, \
{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }
class nsIDOMComment : public nsIDOMNode {
class nsIDOMComment : public nsIDOMData {
public:
NS_IMETHOD GetData(nsString& aData)=0;
NS_IMETHOD SetData(nsString& aData)=0;
};
extern nsresult NS_InitCommentClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM NS_NewScriptComment(nsIScriptContext *aContext, nsIDOMComment *aSupports, nsISupports *aParent, void **aReturn);
extern "C" NS_DOM nsresult NS_NewScriptComment(nsIScriptContext *aContext, nsIDOMComment *aSupports, nsISupports *aParent, void **aReturn);
#endif // nsIDOMComment_h__

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

@ -28,19 +28,19 @@ class nsIDOMDocument;
class nsIDOMDOM;
#define NS_IDOMDOM_IID \
{ 0x6f7652e6, 0xee43, 0x11d1, \
{ 0x6f7652e7, 0xee43, 0x11d1, \
{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }
class nsIDOMDOM : public nsISupports {
public:
NS_IMETHOD CreateDocument(nsString& aType, nsIDOMDocument** aReturn)=0;
NS_IMETHOD CreateDocument(const nsString& aType, nsIDOMDocument** aReturn)=0;
NS_IMETHOD HasFeature(nsString& aFeature, PRBool* aReturn)=0;
NS_IMETHOD HasFeature(const nsString& aFeature, PRBool* aReturn)=0;
};
extern nsresult NS_InitDOMClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM NS_NewScriptDOM(nsIScriptContext *aContext, nsIDOMDOM *aSupports, nsISupports *aParent, void **aReturn);
extern "C" NS_DOM nsresult NS_NewScriptDOM(nsIScriptContext *aContext, nsIDOMDOM *aSupports, nsISupports *aParent, void **aReturn);
#endif // nsIDOMDOM_h__

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

@ -0,0 +1,57 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#ifndef nsIDOMData_h__
#define nsIDOMData_h__
#include "nsISupports.h"
#include "nsString.h"
#include "nsIScriptContext.h"
#include "nsIDOMNode.h"
class nsIDOMData;
#define NS_IDOMDATA_IID \
{ 0x6f7652e3, 0xee43, 0x11d1, \
{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }
class nsIDOMData : public nsIDOMNode {
public:
NS_IMETHOD GetData(nsString& aData)=0;
NS_IMETHOD SetData(const nsString& aData)=0;
NS_IMETHOD GetSize(PRUint32* aSize)=0;
NS_IMETHOD Substring(PRUint32 aStart, PRUint32 aEnd, nsString& aReturn)=0;
NS_IMETHOD Append(const nsString& aData)=0;
NS_IMETHOD Insert(PRUint32 aOffset, const nsString& aData)=0;
NS_IMETHOD Remove(PRUint32 aOffset, PRUint32 aCount)=0;
NS_IMETHOD Replace(PRUint32 aOffset, PRUint32 aCount, const nsString& aData)=0;
};
extern nsresult NS_InitDataClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM nsresult NS_NewScriptData(nsIScriptContext *aContext, nsIDOMData *aSupports, nsISupports *aParent, void **aReturn);
#endif // nsIDOMData_h__

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

@ -25,55 +25,50 @@
#include "nsIScriptContext.h"
#include "nsIDOMDocumentFragment.h"
class nsIDOMAttributeList;
class nsIDOMElement;
class nsIDOMPI;
class nsIDOMNodeIterator;
class nsIDOMDocument;
class nsIDOMTreeIterator;
class nsIDOMProcessingInstruction;
class nsIDOMNamedNodeMap;
class nsIDOMAttribute;
class nsIDOMNode;
class nsIDOMText;
class nsIDOMDocumentContext;
class nsIDOMDocumentType;
class nsIDOMDocumentFragment;
class nsIDOMComment;
class nsIDOMNodeList;
#define NS_IDOMDOCUMENT_IID \
{ 0x6f7652e3, 0xee43, 0x11d1, \
{ 0x6f7652e4, 0xee43, 0x11d1, \
{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }
class nsIDOMDocument : public nsIDOMDocumentFragment {
public:
NS_IMETHOD GetDocumentType(nsIDOMNode** aDocumentType)=0;
NS_IMETHOD SetDocumentType(nsIDOMNode* aDocumentType)=0;
NS_IMETHOD GetDocumentType(nsIDOMDocumentType** aDocumentType)=0;
NS_IMETHOD GetProlog(nsIDOMNodeList** aProlog)=0;
NS_IMETHOD GetEpilog(nsIDOMNodeList** aEpilog)=0;
NS_IMETHOD GetDocumentElement(nsIDOMElement** aDocumentElement)=0;
NS_IMETHOD SetDocumentElement(nsIDOMElement* aDocumentElement)=0;
NS_IMETHOD GetDocumentContext(nsIDOMDocumentContext** aDocumentContext)=0;
NS_IMETHOD SetDocumentContext(nsIDOMDocumentContext* aDocumentContext)=0;
NS_IMETHOD CreateElement(const nsString& aTagName, nsIDOMNamedNodeMap* aAttributes, nsIDOMElement** aReturn)=0;
NS_IMETHOD CreateDocumentContext(nsIDOMDocumentContext** aReturn)=0;
NS_IMETHOD CreateDocumentFragment(nsIDOMDocumentFragment** aReturn)=0;
NS_IMETHOD CreateElement(nsString& aTagName, nsIDOMAttributeList* aAttributes, nsIDOMElement** aReturn)=0;
NS_IMETHOD CreateTextNode(const nsString& aData, nsIDOMText** aReturn)=0;
NS_IMETHOD CreateTextNode(nsString& aData, nsIDOMText** aReturn)=0;
NS_IMETHOD CreateComment(const nsString& aData, nsIDOMComment** aReturn)=0;
NS_IMETHOD CreateComment(nsString& aData, nsIDOMComment** aReturn)=0;
NS_IMETHOD CreateProcessingInstruction(const nsString& aTarget, const nsString& aData, nsIDOMProcessingInstruction** aReturn)=0;
NS_IMETHOD CreatePI(nsString& aName, nsString& aData, nsIDOMPI** aReturn)=0;
NS_IMETHOD CreateAttribute(const nsString& aName, nsIDOMNode* aValue, nsIDOMAttribute** aReturn)=0;
NS_IMETHOD CreateAttribute(nsString& aName, nsIDOMNode* aValue, nsIDOMAttribute** aReturn)=0;
NS_IMETHOD CreateAttributeList(nsIDOMAttributeList** aReturn)=0;
NS_IMETHOD CreateTreeIterator(nsIDOMNode* aNode, nsIDOMTreeIterator** aReturn)=0;
NS_IMETHOD GetElementsByTagName(nsString& aTagname, nsIDOMNodeIterator** aReturn)=0;
NS_IMETHOD GetElementsByTagName(const nsString& aTagname, nsIDOMNodeList** aReturn)=0;
};
extern nsresult NS_InitDocumentClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM NS_NewScriptDocument(nsIScriptContext *aContext, nsIDOMDocument *aSupports, nsISupports *aParent, void **aReturn);
extern "C" NS_DOM nsresult NS_NewScriptDocument(nsIScriptContext *aContext, nsIDOMDocument *aSupports, nsISupports *aParent, void **aReturn);
#endif // nsIDOMDocument_h__

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

@ -36,11 +36,10 @@ class nsIDOMDocumentFragment : public nsIDOMNode {
public:
NS_IMETHOD GetMasterDoc(nsIDOMDocument** aMasterDoc)=0;
NS_IMETHOD SetMasterDoc(nsIDOMDocument* aMasterDoc)=0;
};
extern nsresult NS_InitDocumentFragmentClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM NS_NewScriptDocumentFragment(nsIScriptContext *aContext, nsIDOMDocumentFragment *aSupports, nsISupports *aParent, void **aReturn);
extern "C" NS_DOM nsresult NS_NewScriptDocumentFragment(nsIScriptContext *aContext, nsIDOMDocumentFragment *aSupports, nsISupports *aParent, void **aReturn);
#endif // nsIDOMDocumentFragment_h__

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

@ -17,36 +17,32 @@
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#ifndef nsIDOMAttributeList_h__
#define nsIDOMAttributeList_h__
#ifndef nsIDOMDocumentType_h__
#define nsIDOMDocumentType_h__
#include "nsISupports.h"
#include "nsString.h"
#include "nsIScriptContext.h"
class nsIDOMAttributeList;
class nsIDOMAttribute;
class nsIDOMNamedNodeMap;
class nsIDOMDocumentType;
#define NS_IDOMATTRIBUTELIST_IID \
{ 0x6f7652e1, 0xee43, 0x11d1, \
#define NS_IDOMDOCUMENTTYPE_IID \
{ 0x6f7652e6, 0xee43, 0x11d1, \
{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }
class nsIDOMAttributeList : public nsISupports {
class nsIDOMDocumentType : public nsISupports {
public:
NS_IMETHOD GetAttribute(nsString& aAttrName, nsIDOMAttribute** aReturn)=0;
NS_IMETHOD GetName(nsString& aName)=0;
NS_IMETHOD SetName(const nsString& aName)=0;
NS_IMETHOD SetAttribute(nsIDOMAttribute* aAttr)=0;
NS_IMETHOD Remove(nsString& aAttrName, nsIDOMAttribute** aReturn)=0;
NS_IMETHOD Item(PRUint32 aIndex, nsIDOMAttribute** aReturn)=0;
NS_IMETHOD GetLength(PRUint32* aReturn)=0;
NS_IMETHOD GetEntities(nsIDOMNamedNodeMap** aEntities)=0;
NS_IMETHOD SetEntities(nsIDOMNamedNodeMap* aEntities)=0;
};
extern nsresult NS_InitAttributeListClass(nsIScriptContext *aContext, void **aPrototype);
extern nsresult NS_InitDocumentTypeClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM NS_NewScriptAttributeList(nsIScriptContext *aContext, nsIDOMAttributeList *aSupports, nsISupports *aParent, void **aReturn);
extern "C" NS_DOM nsresult NS_NewScriptDocumentType(nsIScriptContext *aContext, nsIDOMDocumentType *aSupports, nsISupports *aParent, void **aReturn);
#endif // nsIDOMAttributeList_h__
#endif // nsIDOMDocumentType_h__

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

@ -25,41 +25,38 @@
#include "nsIScriptContext.h"
#include "nsIDOMNode.h"
class nsIDOMAttributeList;
class nsIDOMElement;
class nsIDOMNodeIterator;
class nsIDOMAttribute;
class nsIDOMNodeList;
#define NS_IDOMELEMENT_IID \
{ 0x6f7652e7, 0xee43, 0x11d1, \
{ 0x6f7652e8, 0xee43, 0x11d1, \
{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }
class nsIDOMElement : public nsIDOMNode {
public:
NS_IMETHOD GetTagName(nsString& aReturn)=0;
NS_IMETHOD GetTagName(nsString& aTagName)=0;
NS_IMETHOD GetAttributes(nsIDOMAttributeList** aReturn)=0;
NS_IMETHOD GetDOMAttribute(const nsString& aName, nsString& aReturn)=0;
NS_IMETHOD GetDOMAttribute(nsString& aName, nsString& aReturn)=0;
NS_IMETHOD SetDOMAttribute(const nsString& aName, const nsString& aValue)=0;
NS_IMETHOD SetDOMAttribute(nsString& aName, nsString& aValue)=0;
NS_IMETHOD RemoveAttribute(const nsString& aName)=0;
NS_IMETHOD RemoveAttribute(nsString& aName)=0;
NS_IMETHOD GetAttributeNode(nsString& aName, nsIDOMAttribute** aReturn)=0;
NS_IMETHOD GetAttributeNode(const nsString& aName, nsIDOMAttribute** aReturn)=0;
NS_IMETHOD SetAttributeNode(nsIDOMAttribute* aNewAttr)=0;
NS_IMETHOD RemoveAttributeNode(nsIDOMAttribute* aOldAttr)=0;
NS_IMETHOD GetElementsByTagName(nsString& aTagname, nsIDOMNodeIterator** aReturn)=0;
NS_IMETHOD GetElementsByTagName(const nsString& aTagname, nsIDOMNodeList** aReturn)=0;
NS_IMETHOD Normalize()=0;
};
extern nsresult NS_InitElementClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM NS_NewScriptElement(nsIScriptContext *aContext, nsIDOMElement *aSupports, nsISupports *aParent, void **aReturn);
extern "C" NS_DOM nsresult NS_NewScriptElement(nsIScriptContext *aContext, nsIDOMElement *aSupports, nsISupports *aParent, void **aReturn);
#endif // nsIDOMElement_h__

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

@ -17,40 +17,36 @@
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#ifndef nsIDOMNodeIterator_h__
#define nsIDOMNodeIterator_h__
#ifndef nsIDOMNamedNodeMap_h__
#define nsIDOMNamedNodeMap_h__
#include "nsISupports.h"
#include "nsString.h"
#include "nsIScriptContext.h"
class nsIDOMNodeIterator;
class nsIDOMNamedNodeMap;
class nsIDOMNode;
#define NS_IDOMNODEITERATOR_IID \
#define NS_IDOMNAMEDNODEMAP_IID \
{ 0x6f7652e9, 0xee43, 0x11d1, \
{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }
class nsIDOMNodeIterator : public nsISupports {
class nsIDOMNamedNodeMap : public nsISupports {
public:
NS_IMETHOD GetLength(PRUint32* aReturn)=0;
NS_IMETHOD GetLength(PRUint32* aLength)=0;
NS_IMETHOD GetCurrentNode(nsIDOMNode** aReturn)=0;
NS_IMETHOD GetNamedItem(const nsString& aName, nsIDOMNode** aReturn)=0;
NS_IMETHOD GetNextNode(nsIDOMNode** aReturn)=0;
NS_IMETHOD SetNamedItem(nsIDOMNode* aNode)=0;
NS_IMETHOD GetPreviousNode(nsIDOMNode** aReturn)=0;
NS_IMETHOD RemoveNamedItem(const nsString& aName, nsIDOMNode** aReturn)=0;
NS_IMETHOD ToFirst(nsIDOMNode** aReturn)=0;
NS_IMETHOD ToLast(nsIDOMNode** aReturn)=0;
NS_IMETHOD MoveTo(PRInt32 aN, nsIDOMNode** aReturn)=0;
NS_IMETHOD Item(PRUint32 aIndex, nsIDOMNode** aReturn)=0;
};
extern nsresult NS_InitNodeIteratorClass(nsIScriptContext *aContext, void **aPrototype);
extern nsresult NS_InitNamedNodeMapClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM NS_NewScriptNodeIterator(nsIScriptContext *aContext, nsIDOMNodeIterator *aSupports, nsISupports *aParent, void **aReturn);
extern "C" NS_DOM nsresult NS_NewScriptNamedNodeMap(nsIScriptContext *aContext, nsIDOMNamedNodeMap *aSupports, nsISupports *aParent, void **aReturn);
#endif // nsIDOMNodeIterator_h__
#endif // nsIDOMNamedNodeMap_h__

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

@ -24,11 +24,12 @@
#include "nsString.h"
#include "nsIScriptContext.h"
class nsIDOMNodeIterator;
class nsIDOMNamedNodeMap;
class nsIDOMNode;
class nsIDOMNodeList;
#define NS_IDOMNODE_IID \
{ 0x6f7652e8, 0xee43, 0x11d1, \
{ 0x6f7652ea, 0xee43, 0x11d1, \
{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }
class nsIDOMNode : public nsISupports {
@ -37,34 +38,51 @@ public:
DOCUMENT = 1,
ELEMENT = 2,
ATTRIBUTE = 3,
PI = 4,
PROCESSING_INSTRUCTION = 4,
COMMENT = 5,
TEXT = 6
TEXT = 6,
CDATA_SECTION = 7,
DOCUMENT_FRAGMENT = 8,
ENTITY_DECLARATION = 9,
ENTITY_REFERENCE = 10
};
NS_IMETHOD GetNodeType(PRInt32* aReturn)=0;
NS_IMETHOD GetNodeName(nsString& aNodeName)=0;
NS_IMETHOD GetParentNode(nsIDOMNode** aReturn)=0;
NS_IMETHOD GetNodeValue(nsString& aNodeValue)=0;
NS_IMETHOD SetNodeValue(const nsString& aNodeValue)=0;
NS_IMETHOD GetChildNodes(nsIDOMNodeIterator** aReturn)=0;
NS_IMETHOD GetNodeType(PRInt32* aNodeType)=0;
NS_IMETHOD HasChildNodes(PRBool* aReturn)=0;
NS_IMETHOD GetParentNode(nsIDOMNode** aParentNode)=0;
NS_IMETHOD GetFirstChild(nsIDOMNode** aReturn)=0;
NS_IMETHOD GetChildNodes(nsIDOMNodeList** aChildNodes)=0;
NS_IMETHOD GetPreviousSibling(nsIDOMNode** aReturn)=0;
NS_IMETHOD GetHasChildNodes(PRBool* aHasChildNodes)=0;
NS_IMETHOD GetNextSibling(nsIDOMNode** aReturn)=0;
NS_IMETHOD GetFirstChild(nsIDOMNode** aFirstChild)=0;
NS_IMETHOD InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild)=0;
NS_IMETHOD GetLastChild(nsIDOMNode** aLastChild)=0;
NS_IMETHOD ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild)=0;
NS_IMETHOD GetPreviousSibling(nsIDOMNode** aPreviousSibling)=0;
NS_IMETHOD RemoveChild(nsIDOMNode* aOldChild)=0;
NS_IMETHOD GetNextSibling(nsIDOMNode** aNextSibling)=0;
NS_IMETHOD GetAttributes(nsIDOMNamedNodeMap** aAttributes)=0;
NS_IMETHOD InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, nsIDOMNode** aReturn)=0;
NS_IMETHOD ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, nsIDOMNode** aReturn)=0;
NS_IMETHOD RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn)=0;
NS_IMETHOD CloneNode(nsIDOMNode** aReturn)=0;
NS_IMETHOD Equals(nsIDOMNode* aNode, PRBool aDeep, PRBool* aReturn)=0;
};
extern nsresult NS_InitNodeClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM NS_NewScriptNode(nsIScriptContext *aContext, nsIDOMNode *aSupports, nsISupports *aParent, void **aReturn);
extern "C" NS_DOM nsresult NS_NewScriptNode(nsIScriptContext *aContext, nsIDOMNode *aSupports, nsISupports *aParent, void **aReturn);
#endif // nsIDOMNode_h__

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

@ -17,32 +17,30 @@
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#ifndef nsIDOMPI_h__
#define nsIDOMPI_h__
#ifndef nsIDOMNodeList_h__
#define nsIDOMNodeList_h__
#include "nsISupports.h"
#include "nsString.h"
#include "nsIScriptContext.h"
#include "nsIDOMNode.h"
class nsIDOMPI;
class nsIDOMNode;
class nsIDOMNodeList;
#define NS_IDOMPI_IID \
{ 0x6f7652ea, 0xee43, 0x11d1, \
#define NS_IDOMNODELIST_IID \
{ 0x6f7652eb, 0xee43, 0x11d1, \
{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }
class nsIDOMPI : public nsIDOMNode {
class nsIDOMNodeList : public nsISupports {
public:
NS_IMETHOD GetName(nsString& aName)=0;
NS_IMETHOD SetName(nsString& aName)=0;
NS_IMETHOD GetLength(PRUint32* aLength)=0;
NS_IMETHOD GetData(nsString& aData)=0;
NS_IMETHOD SetData(nsString& aData)=0;
NS_IMETHOD Item(PRUint32 aIndex, nsIDOMNode** aReturn)=0;
};
extern nsresult NS_InitPIClass(nsIScriptContext *aContext, void **aPrototype);
extern nsresult NS_InitNodeListClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM NS_NewScriptPI(nsIScriptContext *aContext, nsIDOMPI *aSupports, nsISupports *aParent, void **aReturn);
extern "C" NS_DOM nsresult NS_NewScriptNodeList(nsIScriptContext *aContext, nsIDOMNodeList *aSupports, nsISupports *aParent, void **aReturn);
#endif // nsIDOMPI_h__
#endif // nsIDOMNodeList_h__

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

@ -0,0 +1,48 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#ifndef nsIDOMProcessingInstruction_h__
#define nsIDOMProcessingInstruction_h__
#include "nsISupports.h"
#include "nsString.h"
#include "nsIScriptContext.h"
#include "nsIDOMNode.h"
class nsIDOMProcessingInstruction;
#define NS_IDOMPROCESSINGINSTRUCTION_IID \
{ 0x6f7652ec, 0xee43, 0x11d1, \
{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }
class nsIDOMProcessingInstruction : public nsIDOMNode {
public:
NS_IMETHOD GetTarget(nsString& aTarget)=0;
NS_IMETHOD SetTarget(const nsString& aTarget)=0;
NS_IMETHOD GetData(nsString& aData)=0;
NS_IMETHOD SetData(const nsString& aData)=0;
};
extern nsresult NS_InitProcessingInstructionClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM nsresult NS_NewScriptProcessingInstruction(nsIScriptContext *aContext, nsIDOMProcessingInstruction *aSupports, nsISupports *aParent, void **aReturn);
#endif // nsIDOMProcessingInstruction_h__

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

@ -23,34 +23,24 @@
#include "nsISupports.h"
#include "nsString.h"
#include "nsIScriptContext.h"
#include "nsIDOMNode.h"
#include "nsIDOMData.h"
class nsIDOMElement;
class nsIDOMText;
#define NS_IDOMTEXT_IID \
{ 0x6f7652eb, 0xee43, 0x11d1, \
{ 0x6f7652ed, 0xee43, 0x11d1, \
{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }
class nsIDOMText : public nsIDOMNode {
class nsIDOMText : public nsIDOMData {
public:
NS_IMETHOD GetData(nsString& aData)=0;
NS_IMETHOD SetData(nsString& aData)=0;
NS_IMETHOD SplitText(PRUint32 aOffset, nsIDOMText** aReturn)=0;
NS_IMETHOD Append(nsString& aData)=0;
NS_IMETHOD Insert(PRInt32 aOffset, nsString& aData)=0;
NS_IMETHOD Delete(PRInt32 aOffset, PRInt32 aCount)=0;
NS_IMETHOD Replace(PRInt32 aOffset, PRInt32 aCount, nsString& aData)=0;
NS_IMETHOD Splice(nsIDOMElement* aElement, PRInt32 aOffset, PRInt32 aCount)=0;
NS_IMETHOD JoinText(nsIDOMText* aNode1, nsIDOMText* aNode2, nsIDOMText** aReturn)=0;
};
extern nsresult NS_InitTextClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM NS_NewScriptText(nsIScriptContext *aContext, nsIDOMText *aSupports, nsISupports *aParent, void **aReturn);
extern "C" NS_DOM nsresult NS_NewScriptText(nsIScriptContext *aContext, nsIDOMText *aSupports, nsISupports *aParent, void **aReturn);
#endif // nsIDOMText_h__

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

@ -1,61 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#ifndef nsIDOMTreeIterator_h__
#define nsIDOMTreeIterator_h__
#include "nsISupports.h"
#include "nsString.h"
#include "nsIScriptContext.h"
#include "nsIDOMNodeIterator.h"
class nsIDOMTreeIterator;
class nsIDOMNode;
#define NS_IDOMTREEITERATOR_IID \
{ 0x6f7652ec, 0xee43, 0x11d1, \
{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }
class nsIDOMTreeIterator : public nsIDOMNodeIterator {
public:
NS_IMETHOD NumChildren(PRUint32* aReturn)=0;
NS_IMETHOD NumPreviousSiblings(PRUint32* aReturn)=0;
NS_IMETHOD NumNextSiblings(PRUint32* aReturn)=0;
NS_IMETHOD ToParent(nsIDOMNode** aReturn)=0;
NS_IMETHOD ToPreviousSibling(nsIDOMNode** aReturn)=0;
NS_IMETHOD ToNextSibling(nsIDOMNode** aReturn)=0;
NS_IMETHOD ToFirstChild(nsIDOMNode** aReturn)=0;
NS_IMETHOD ToLastChild(nsIDOMNode** aReturn)=0;
NS_IMETHOD ToNthChild(PRInt32 aN, nsIDOMNode** aReturn)=0;
};
extern nsresult NS_InitTreeIteratorClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM NS_NewScriptTreeIterator(nsIScriptContext *aContext, nsIDOMTreeIterator *aSupports, nsISupports *aParent, void **aReturn);
#endif // nsIDOMTreeIterator_h__

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

@ -1,6 +1,5 @@
interface Attribute {
wstring getName();
attribute wstring value;
attribute boolean specified;
wstring toString();
};
interface Attribute : Node {
readonly attribute wstring name;
attribute boolean specified;
readonly attribute wstring value;
};

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

@ -1,9 +0,0 @@
interface AttributeList {
Attribute getAttribute(in wstring attrName);
void setAttribute(in Attribute attr);
Attribute remove(in wstring attrName) interface NoSuchAttributeException {};
Attribute item(in unsigned long index) interface NoSuchAttributeException {};
unsigned long getLength();
};

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

@ -0,0 +1,2 @@
interface CDATASection : Text {
};

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

@ -1,4 +1,3 @@
interface Comment : Node {
attribute wstring data;
};
interface Comment : Data {
};

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

@ -1,4 +1,5 @@
interface DOM {
Document createDocument(in wstring type);
boolean hasFeature(in wstring feature);
};
interface DOM {
Document createDocument(in wstring type)
raises DOMException;
boolean hasFeature(in wstring feature);
};

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

@ -0,0 +1,18 @@
interface Data : Node {
attribute wstring data;
readonly attribute unsigned long size;
wstring substring(in unsigned long start,
in unsigned long end)
raises DOMException;
void append(in wstring data);
void insert(in unsigned long offset,
in wstring data)
raises DOMException;
void remove(in unsigned long offset,
in unsigned long count)
raises DOMException;
void replace(in unsigned long offset,
in unsigned long count,
in wstring data)
raises DOMException;
};

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

@ -1,17 +1,16 @@
interface Document : DocumentFragment {
attribute Node documentType;
attribute Element documentElement;
attribute DocumentContext documentContext;
DocumentContext createDocumentContext();
Element createElement(in wstring tagName,
in AttributeList attributes);
Text createTextNode(in wstring data);
Comment createComment(in wstring data);
PI createPI(in wstring name,
in wstring data);
Attribute createAttribute(in wstring name,
in Node value);
AttributeList createAttributeList();
TreeIterator createTreeIterator(in Node node);
NodeIterator getElementsByTagName(in wstring tagname);
};
interface Document : DocumentFragment {
readonly attribute DocumentType documentType;
readonly attribute NodeList prolog;
readonly attribute NodeList epilog;
readonly attribute Element documentElement;
Element createElement(in wstring tagName,
in NamedNodeMap attributes);
DocumentFragment createDocumentFragment();
Text createTextNode(in wstring data);
Comment createComment(in wstring data);
ProcessingInstruction createProcessingInstruction(in wstring target,
in wstring data);
Attribute createAttribute(in wstring name,
in Node value);
NodeList getElementsByTagName(in wstring tagname);
};

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

@ -1,3 +0,0 @@
interface DocumentContext {
attribute Document document;
};

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

@ -1,3 +1,3 @@
interface DocumentFragment : Node {
attribute Document masterDoc;
};
interface DocumentFragment : Node {
readonly attribute Document masterDoc;
};

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

@ -0,0 +1,4 @@
interface DocumentType {
attribute wstring name;
attribute NamedNodeMap entities;
};

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

@ -1,14 +1,13 @@
interface Element : Node {
wstring getTagName();
AttributeList getAttributes();
wstring getDOMAttribute(in wstring name);
void setDOMAttribute(in string name,
in string value);
void removeAttribute(in wstring name);
Attribute getAttributeNode(in wstring name);
void setAttributeNode(in Attribute newAttr);
void removeAttributeNode(in Attribute oldAttr);
NodeIterator getElementsByTagName(in wstring tagname);
void normalize();
};
interface Element : Node {
readonly attribute wstring tagName;
wstring getDOMAttribute(in wstring name);
void setDOMAttribute(in string name,
in string value);
void removeAttribute(in wstring name);
Attribute getAttributeNode(in wstring name);
void setAttributeNode(in Attribute newAttr);
void removeAttributeNode(in Attribute oldAttr);
NodeList getElementsByTagName(in wstring tagname);
void normalize();
};

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

@ -0,0 +1,7 @@
interface NamedNodeMap {
Node getNamedItem(in wstring name);
void setNamedItem(in Node node);
Node removeNamedItem(in wstring name);
Node item(in unsigned long index);
readonly attribute unsigned long length;
};

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

@ -1,25 +1,38 @@
interface Node {
// NodeType
const int DOCUMENT = 1;
const int ELEMENT = 2;
const int ATTRIBUTE = 3;
const int PI = 4;
const int COMMENT = 5;
const int TEXT = 6;
interface Node {
// NodeType
const int DOCUMENT = 1;
const int ELEMENT = 2;
const int ATTRIBUTE = 3;
const int PROCESSING_INSTRUCTION = 4;
const int COMMENT = 5;
const int TEXT = 6;
const int CDATA_SECTION = 7;
const int DOCUMENT_FRAGMENT = 8;
const int ENTITY_DECLARATION = 9;
const int ENTITY_REFERENCE = 10;
int getNodeType();
Node getParentNode();
NodeIterator getChildNodes();
boolean hasChildNodes();
Node getFirstChild();
Node getPreviousSibling();
Node getNextSibling();
void insertBefore(in Node newChild,
in Node refChild) interface NotMyChildException {};
readonly attribute wstring nodeName;
attribute wstring nodeValue;
readonly attribute int nodeType;
readonly attribute Node parentNode;
readonly attribute NodeList childNodes;
readonly attribute boolean hasChildNodes;
readonly attribute Node firstChild;
readonly attribute Node lastChild;
readonly attribute Node previousSibling;
readonly attribute Node nextSibling;
readonly attribute NamedNodeMap attributes;
Node insertBefore(in Node newChild,
in Node refChild)
raises DOMException;
Node replaceChild(in Node newChild,
in Node oldChild)
raises DOMException;
Node removeChild(in Node oldChild)
raises DOMException;
Node cloneNode();
boolean equals(in Node node,
in boolean deep);
};
void replaceChild(in Node newChild,
in Node oldChild) interface NotMyChildException {};
void removeChild(in Node oldChild) interface NotMyChildException {};
};

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

@ -1,9 +0,0 @@
interface NodeIterator {
unsigned long getLength();
Node getCurrentNode();
Node getNextNode();
Node getPreviousNode();
Node toFirst();
Node toLast();
Node moveTo(in int n);
};

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

@ -0,0 +1,5 @@
interface NodeList {
Node item(in unsigned long index);
readonly attribute unsigned long length;
};

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

@ -1,4 +0,0 @@
interface PI : Node {
attribute wstring name;
attribute wstring data;
};

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

@ -0,0 +1,4 @@
interface ProcessingInstruction : Node {
attribute wstring target;
attribute wstring data;
};

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

@ -1,14 +1,5 @@
interface Text : Node {
attribute wstring data;
void append(in wstring data);
void insert(in int offset,
in wstring data);
void delete(in int offset,
in int count);
void replace(in int offset,
in int count,
in wstring data);
void splice(in Element element,
in int offset,
in int count);
};
interface Text : Data {
Text splitText(in unsigned long offset);
Text joinText(in Text node1,
in Text node2);
};

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

@ -1,11 +0,0 @@
interface TreeIterator : NodeIterator {
unsigned long numChildren();
unsigned long numPreviousSiblings();
unsigned long numNextSiblings();
Node toParent();
Node toPreviousSibling();
Node toNextSibling();
Node toFirstChild();
Node toLastChild();
Node toNthChild(in int n) interface NoSuchNodeException {};
};

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

@ -22,19 +22,22 @@ MODULE=raptor
IDLSRCS = \
Attribute.idl \
AttributeList.idl \
CDATASection.idl \
Comment.idl \
Data.idl \
DOM.idl \
Document.idl \
DocumentContext.idl \
DocumentFragment.idl \
DocumentType.idl \
Element.idl \
NamedNodeMap.idl \
Node.idl \
NodeIterator.idl \
PI.idl \
Text.idl \
TreeIterator.idl
NodeList.idl \
ProcessingInstruction.idl \
Text.idl
XPCOM_DESTDIR=$(DEPTH)\dom\public\coreDom
JSSTUB_DESTDIR=$(DEPTH)\dom\src
GENXDIR=genx
@ -58,4 +61,5 @@ export:: $(GENXDIR) $(GENJSDIR) $(IDLSRCS)
$(IDLC) -d $(GENJSDIR) -j $(IDLSRCS)
install::
for %g in ($(IDLSRCS:.idl=.h)) do $(MAKE_INSTALL:/=\) $(GENXDIR)\nsIDOM%g $(XPCOM_DESTDIR)
for %g in ($(IDLSRCS:.idl=.cpp)) do $(MAKE_INSTALL:/=\) $(GENJSDIR)\nsJS%g $(JSSTUB_DESTDIR)

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

@ -56,8 +56,8 @@ export:: $(GENXDIR) $(GENJSDIR) $(IDLSRCS)
$(PERL) $(GENIID) $(IIDDIRS)
install::
for %g in ($(DIRS)) do $(MAKE_INSTALL:/=\) %g\$(GENXDIR)\*.h $(XPCOM_DESTDIR)\%g
$(MAKE_INSTALL:/=\) $(GENXDIR)\*.h $(XPCOM_DESTDIR)
for %g in ($(IDLSRCS:.idl=.h)) do $(MAKE_INSTALL:/=\) $(GENXDIR)\nsIDOM%g $(XPCOM_DESTDIR)
$(MAKE_INSTALL:/=\) $(GENXDIR)\nsIDOM$(GLOBAL_IDLSRC:.idl=.h) $(XPCOM_DESTDIR)
for %g in ($(IDLSRCS:.idl=.cpp)) do $(MAKE_INSTALL:/=\) $(GENJSDIR)\nsJS%g $(JSSTUB_DESTDIR)
$(MAKE_INSTALL:/=\) $(GENJSDIR)\nsJS$(GLOBAL_IDLSRC:.idl=.cpp) $(JSSTUB_DESTDIR)

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

@ -27,7 +27,7 @@
class nsIDOMNavigator;
#define NS_IDOMNAVIGATOR_IID \
{ 0x6f7652ed, 0xee43, 0x11d1, \
{ 0x6f7652ee, 0xee43, 0x11d1, \
{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }
class nsIDOMNavigator : public nsISupports {
@ -52,6 +52,6 @@ public:
extern nsresult NS_InitNavigatorClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM NS_NewScriptNavigator(nsIScriptContext *aContext, nsIDOMNavigator *aSupports, nsISupports *aParent, void **aReturn);
extern "C" NS_DOM nsresult NS_NewScriptNavigator(nsIScriptContext *aContext, nsIDOMNavigator *aSupports, nsISupports *aParent, void **aReturn);
#endif // nsIDOMNavigator_h__

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

@ -30,7 +30,7 @@ class nsIDOMDocument;
class nsIDOMWindow;
#define NS_IDOMWINDOW_IID \
{ 0x6f7652ee, 0xee43, 0x11d1, \
{ 0x6f7652ef, 0xee43, 0x11d1, \
{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }
class nsIDOMWindow : public nsISupports {
@ -44,9 +44,9 @@ public:
NS_IMETHOD GetNavigator(nsIDOMNavigator** aNavigator)=0;
NS_IMETHOD Dump(nsString& aStr)=0;
NS_IMETHOD Dump(const nsString& aStr)=0;
NS_IMETHOD Alert(nsString& aStr)=0;
NS_IMETHOD Alert(const nsString& aStr)=0;
NS_IMETHOD ClearTimeout(PRInt32 aTimerID)=0;
@ -59,6 +59,6 @@ public:
extern nsresult NS_InitWindowClass(nsIScriptContext *aContext, nsIScriptGlobalObject *aGlobal);
extern "C" NS_DOM NS_NewScriptWindow(nsIScriptContext *aContext, nsIDOMWindow *aSupports, nsISupports *aParent, void **aReturn);
extern "C" NS_DOM nsresult NS_NewScriptWindow(nsIScriptContext *aContext, nsIDOMWindow *aSupports, nsISupports *aParent, void **aReturn);
#endif // nsIDOMWindow_h__

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

@ -86,7 +86,7 @@ public:
* Return a new Context
*
*/
extern "C" NS_DOM NS_CreateContext(nsIScriptGlobalObject *aGlobal, nsIScriptContext **aContext);
extern "C" NS_DOM nsresult NS_CreateContext(nsIScriptGlobalObject *aGlobal, nsIScriptContext **aContext);
#endif // nsIScriptContext_h__

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

@ -40,6 +40,6 @@ public:
NS_IMETHOD_(void) SetNewDocument(nsIDOMDocument *aDocument)=0;
};
extern "C" NS_DOM NS_NewScriptGlobalObject(nsIScriptGlobalObject **aGlobal);
extern "C" NS_DOM nsresult NS_NewScriptGlobalObject(nsIScriptGlobalObject **aGlobal);
#endif

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

@ -24,16 +24,17 @@ DEFINES = -D_IMPL_NS_DOM
CPPSRCS = \
nsJSEnvironment.cpp \
nsJSNode.cpp \
nsJSData.cpp \
nsJSDocument.cpp \
nsJSDocumentFragment.cpp\
nsJSElement.cpp \
nsJSNamedNodeMap.cpp \
nsJSNodeList.cpp \
nsJSText.cpp \
nsJSNodeIterator.cpp\
nsJSAttribute.cpp \
nsJSAttributeList.cpp\
nsJSWindow.cpp\
nsJSNavigator.cpp \
nsGlobalWindow.cpp \
nsJSWindow.cpp \
nsJSNavigator.cpp \
nsGlobalWindow.cpp \
$(NULL)
MODULE = raptor

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

@ -26,13 +26,14 @@ DEFINES=-D_IMPL_NS_DOM -DWIN32_LEAN_AND_MEAN
CPPSRCS = \
nsJSEnvironment.cpp \
nsJSNode.cpp \
nsJSData.cpp \
nsJSDocument.cpp \
nsJSDocumentFragment.cpp\
nsJSElement.cpp \
nsJSNamedNodeMap.cpp \
nsJSNodeList.cpp \
nsJSText.cpp \
nsJSNodeIterator.cpp \
nsJSAttribute.cpp \
nsJSAttributeList.cpp \
nsJSWindow.cpp \
nsJSNavigator.cpp \
nsGlobalWindow.cpp \
@ -44,10 +45,10 @@ REQUIRES=xpcom raptor js netlib
CPP_OBJS= .\$(OBJDIR)\nsJSEnvironment.obj .\$(OBJDIR)\nsJSNode.obj .\$(OBJDIR)\nsJSDocument.obj \
.\$(OBJDIR)\nsJSElement.obj .\$(OBJDIR)\nsJSText.obj \
.\$(OBJDIR)\nsJSNodeIterator.obj .\$(OBJDIR)\nsJSAttribute.obj \
.\$(OBJDIR)\nsJSAttributeList.obj .\$(OBJDIR)\nsJSWindow.obj \
.\$(OBJDIR)\nsJSNodeList.obj .\$(OBJDIR)\nsJSAttribute.obj \
.\$(OBJDIR)\nsJSNamedNodeMap.obj .\$(OBJDIR)\nsJSWindow.obj \
.\$(OBJDIR)\nsGlobalWindow.obj .\$(OBJDIR)\nsJSDocumentFragment.obj \
.\$(OBJDIR)\nsJSNavigator.obj
.\$(OBJDIR)\nsJSNavigator.obj .\$(OBJDIR)\nsJSData.obj
LINCS=-I$(XPDIST)\public\xpcom -I$(XPDIST)\public\raptor -I$(XPDIST)\public\dom -I$(XPDIST)\public\js -I$(PUBLIC)\netlib

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

@ -62,8 +62,8 @@ public:
NS_IMETHOD GetSelf(nsIDOMWindow** aSelf);
NS_IMETHOD GetDocument(nsIDOMDocument** aDocument);
NS_IMETHOD GetNavigator(nsIDOMNavigator** aNavigator);
NS_IMETHOD Dump(nsString& aStr);
NS_IMETHOD Alert(nsString& aStr);
NS_IMETHOD Dump(const nsString& aStr);
NS_IMETHOD Alert(const nsString& aStr);
NS_IMETHOD ClearTimeout(PRInt32 aTimerID);
NS_IMETHOD ClearInterval(PRInt32 aTimerID);
NS_IMETHOD SetTimeout(JSContext *cx, jsval *argv, PRUint32 argc,
@ -319,7 +319,7 @@ GlobalWindowImpl::GetNavigator(nsIDOMNavigator** aNavigator)
}
NS_IMETHODIMP
GlobalWindowImpl::Dump(nsString& aStr)
GlobalWindowImpl::Dump(const nsString& aStr)
{
char *cstr = aStr.ToNewCString();
@ -332,7 +332,7 @@ GlobalWindowImpl::Dump(nsString& aStr)
}
NS_IMETHODIMP
GlobalWindowImpl::Alert(nsString& aStr)
GlobalWindowImpl::Alert(const nsString& aStr)
{
// XXX Temporary
return Dump(aStr);
@ -760,7 +760,7 @@ GlobalWindowImpl::SetInterval(JSContext *cx,
return SetTimeoutOrInterval(cx, argv, argc, aReturn, PR_TRUE);
}
extern "C" NS_DOM
extern "C" NS_DOM nsresult
NS_NewScriptGlobalObject(nsIScriptGlobalObject **aResult)
{
if (nsnull == aResult) {

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

@ -39,8 +39,9 @@ NS_DEF_PTR(nsIDOMAttribute);
// Attribute property ids
//
enum Attribute_slots {
ATTRIBUTE_VALUE = -11,
ATTRIBUTE_SPECIFIED = -12
ATTRIBUTE_NAME = -11,
ATTRIBUTE_SPECIFIED = -12,
ATTRIBUTE_VALUE = -13
};
/***********************************************************************/
@ -59,10 +60,10 @@ GetAttributeProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case ATTRIBUTE_VALUE:
case ATTRIBUTE_NAME:
{
nsAutoString prop;
if (NS_OK == a->GetValue(prop)) {
if (NS_OK == a->GetName(prop)) {
JSString *jsstring = JS_NewUCStringCopyN(cx, prop, prop.Length());
// set the return value
*vp = STRING_TO_JSVAL(jsstring);
@ -83,6 +84,19 @@ GetAttributeProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
}
break;
}
case ATTRIBUTE_VALUE:
{
nsAutoString prop;
if (NS_OK == a->GetValue(prop)) {
JSString *jsstring = JS_NewUCStringCopyN(cx, prop, prop.Length());
// set the return value
*vp = STRING_TO_JSVAL(jsstring);
}
else {
return JS_FALSE;
}
break;
}
default:
{
nsIJSScriptObject *object;
@ -115,21 +129,6 @@ SetAttributeProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case ATTRIBUTE_VALUE:
{
nsAutoString prop;
JSString *jsstring;
if ((jsstring = JS_ValueToString(cx, *vp)) != nsnull) {
prop.SetString(JS_GetStringChars(jsstring));
}
else {
prop.SetString((const char *)nsnull);
}
a->SetValue(prop);
break;
}
case ATTRIBUTE_SPECIFIED:
{
PRBool prop;
@ -224,78 +223,6 @@ ResolveAttribute(JSContext *cx, JSObject *obj, jsval id)
}
//
// Native method GetName
//
PR_STATIC_CALLBACK(JSBool)
AttributeGetName(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMAttribute *nativeThis = (nsIDOMAttribute*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsAutoString nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->GetName(nativeRet)) {
return JS_FALSE;
}
JSString *jsstring = JS_NewUCStringCopyN(cx, nativeRet, nativeRet.Length());
// set the return value
*rval = STRING_TO_JSVAL(jsstring);
}
else {
JS_ReportError(cx, "Function getName requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method ToString
//
PR_STATIC_CALLBACK(JSBool)
AttributeToString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMAttribute *nativeThis = (nsIDOMAttribute*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsAutoString nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->ToString(nativeRet)) {
return JS_FALSE;
}
JSString *jsstring = JS_NewUCStringCopyN(cx, nativeRet, nativeRet.Length());
// set the return value
*rval = STRING_TO_JSVAL(jsstring);
}
else {
JS_ReportError(cx, "Function toString requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
/***********************************************************************/
//
// class for Attribute
@ -319,8 +246,9 @@ JSClass AttributeClass = {
//
static JSPropertySpec AttributeProperties[] =
{
{"value", ATTRIBUTE_VALUE, JSPROP_ENUMERATE},
{"name", ATTRIBUTE_NAME, JSPROP_ENUMERATE | JSPROP_READONLY},
{"specified", ATTRIBUTE_SPECIFIED, JSPROP_ENUMERATE},
{"value", ATTRIBUTE_VALUE, JSPROP_ENUMERATE | JSPROP_READONLY},
{0}
};
@ -330,8 +258,6 @@ static JSPropertySpec AttributeProperties[] =
//
static JSFunctionSpec AttributeMethods[] =
{
{"getName", AttributeGetName, 0},
{"toString", AttributeToString, 0},
{0}
};
@ -364,6 +290,9 @@ nsresult NS_InitAttributeClass(nsIScriptContext *aContext, void **aPrototype)
(PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) ||
!JSVAL_IS_OBJECT(vp)) {
if (NS_OK != NS_InitNodeClass(aContext, (void **)&parent_proto)) {
return NS_ERROR_FAILURE;
}
proto = JS_InitClass(jscontext, // context
global, // global object
parent_proto, // parent proto
@ -396,7 +325,7 @@ nsresult NS_InitAttributeClass(nsIScriptContext *aContext, void **aPrototype)
//
// Method for creating a new Attribute JavaScript object
//
extern "C" NS_DOM NS_NewScriptAttribute(nsIScriptContext *aContext, nsIDOMAttribute *aSupports, nsISupports *aParent, void **aReturn)
extern "C" NS_DOM nsresult NS_NewScriptAttribute(nsIScriptContext *aContext, nsIDOMAttribute *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptAttribute");
JSObject *proto;

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

@ -0,0 +1,304 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#include "jsapi.h"
#include "nscore.h"
#include "nsIScriptContext.h"
#include "nsIJSScriptObject.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsIPtr.h"
#include "nsString.h"
#include "nsIDOMCDATASection.h"
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
static NS_DEFINE_IID(kICDATASectionIID, NS_IDOMCDATASECTION_IID);
NS_DEF_PTR(nsIDOMCDATASection);
/***********************************************************************/
//
// CDATASection Properties Getter
//
PR_STATIC_CALLBACK(JSBool)
GetCDATASectionProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMCDATASection *a = (nsIDOMCDATASection*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case 0:
default:
{
nsIJSScriptObject *object;
if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {
PRBool rval;
rval = object->GetProperty(cx, id, vp);
NS_RELEASE(object);
return rval;
}
}
}
}
return PR_TRUE;
}
/***********************************************************************/
//
// CDATASection Properties Setter
//
PR_STATIC_CALLBACK(JSBool)
SetCDATASectionProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMCDATASection *a = (nsIDOMCDATASection*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case 0:
default:
{
nsIJSScriptObject *object;
if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {
PRBool rval;
rval = object->SetProperty(cx, id, vp);
NS_RELEASE(object);
return rval;
}
}
}
}
return PR_TRUE;
}
//
// CDATASection finalizer
//
PR_STATIC_CALLBACK(void)
FinalizeCDATASection(JSContext *cx, JSObject *obj)
{
nsIDOMCDATASection *a = (nsIDOMCDATASection*)JS_GetPrivate(cx, obj);
if (nsnull != a) {
// get the js object
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == a->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
owner->ResetScriptObject();
NS_RELEASE(owner);
}
NS_RELEASE(a);
}
}
//
// CDATASection enumerate
//
PR_STATIC_CALLBACK(JSBool)
EnumerateCDATASection(JSContext *cx, JSObject *obj)
{
nsIDOMCDATASection *a = (nsIDOMCDATASection*)JS_GetPrivate(cx, obj);
if (nsnull != a) {
// get the js object
nsIJSScriptObject *object;
if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {
object->EnumerateProperty(cx);
NS_RELEASE(object);
}
}
return JS_TRUE;
}
//
// CDATASection resolve
//
PR_STATIC_CALLBACK(JSBool)
ResolveCDATASection(JSContext *cx, JSObject *obj, jsval id)
{
nsIDOMCDATASection *a = (nsIDOMCDATASection*)JS_GetPrivate(cx, obj);
if (nsnull != a) {
// get the js object
nsIJSScriptObject *object;
if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {
object->Resolve(cx, id);
NS_RELEASE(object);
}
}
return JS_TRUE;
}
/***********************************************************************/
//
// class for CDATASection
//
JSClass CDATASectionClass = {
"CDATASection",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
GetCDATASectionProperty,
SetCDATASectionProperty,
EnumerateCDATASection,
ResolveCDATASection,
JS_ConvertStub,
FinalizeCDATASection
};
//
// CDATASection class properties
//
static JSPropertySpec CDATASectionProperties[] =
{
{0}
};
//
// CDATASection class methods
//
static JSFunctionSpec CDATASectionMethods[] =
{
{0}
};
//
// CDATASection constructor
//
PR_STATIC_CALLBACK(JSBool)
CDATASection(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
return JS_TRUE;
}
//
// CDATASection class initialization
//
nsresult NS_InitCDATASectionClass(nsIScriptContext *aContext, void **aPrototype)
{
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
JSObject *proto = nsnull;
JSObject *constructor = nsnull;
JSObject *parent_proto = nsnull;
JSObject *global = JS_GetGlobalObject(jscontext);
jsval vp;
if ((PR_TRUE != JS_LookupProperty(jscontext, global, "CDATASection", &vp)) ||
!JSVAL_IS_OBJECT(vp) ||
((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) ||
(PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) ||
!JSVAL_IS_OBJECT(vp)) {
if (NS_OK != NS_InitTextClass(aContext, (void **)&parent_proto)) {
return NS_ERROR_FAILURE;
}
proto = JS_InitClass(jscontext, // context
global, // global object
parent_proto, // parent proto
&CDATASectionClass, // JSClass
CDATASection, // JSNative ctor
0, // ctor args
CDATASectionProperties, // proto props
CDATASectionMethods, // proto funcs
nsnull, // ctor props (static)
nsnull); // ctor funcs (static)
if (nsnull == proto) {
return NS_ERROR_FAILURE;
}
}
else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) {
proto = JSVAL_TO_OBJECT(vp);
}
else {
return NS_ERROR_FAILURE;
}
if (aPrototype) {
*aPrototype = proto;
}
return NS_OK;
}
//
// Method for creating a new CDATASection JavaScript object
//
extern "C" NS_DOM nsresult NS_NewScriptCDATASection(nsIScriptContext *aContext, nsIDOMCDATASection *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptCDATASection");
JSObject *proto;
JSObject *parent;
nsIScriptObjectOwner *owner;
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
if (nsnull == aParent) {
parent = nsnull;
}
else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) {
NS_RELEASE(owner);
return NS_ERROR_FAILURE;
}
NS_RELEASE(owner);
}
else {
return NS_ERROR_FAILURE;
}
if (NS_OK != NS_InitCDATASectionClass(aContext, (void **)&proto)) {
return NS_ERROR_FAILURE;
}
// create a js object for this class
*aReturn = JS_NewObject(jscontext, &CDATASectionClass, proto, parent);
if (nsnull != *aReturn) {
// connect the native object to the js object
JS_SetPrivate(jscontext, (JSObject *)*aReturn, aSupports);
NS_ADDREF(aSupports);
}
else {
return NS_ERROR_FAILURE;
}
return NS_OK;
}

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

@ -35,12 +35,6 @@ static NS_DEFINE_IID(kICommentIID, NS_IDOMCOMMENT_IID);
NS_DEF_PTR(nsIDOMComment);
//
// Comment property ids
//
enum Comment_slots {
COMMENT_DATA = -11
};
/***********************************************************************/
//
@ -58,19 +52,7 @@ GetCommentProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case COMMENT_DATA:
{
nsAutoString prop;
if (NS_OK == a->GetData(prop)) {
JSString *jsstring = JS_NewUCStringCopyN(cx, prop, prop.Length());
// set the return value
*vp = STRING_TO_JSVAL(jsstring);
}
else {
return JS_FALSE;
}
break;
}
case 0:
default:
{
nsIJSScriptObject *object;
@ -103,21 +85,7 @@ SetCommentProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case COMMENT_DATA:
{
nsAutoString prop;
JSString *jsstring;
if ((jsstring = JS_ValueToString(cx, *vp)) != nsnull) {
prop.SetString(JS_GetStringChars(jsstring));
}
else {
prop.SetString((const char *)nsnull);
}
a->SetData(prop);
break;
}
case 0:
default:
{
nsIJSScriptObject *object;
@ -219,7 +187,6 @@ JSClass CommentClass = {
//
static JSPropertySpec CommentProperties[] =
{
{"data", COMMENT_DATA, JSPROP_ENUMERATE},
{0}
};
@ -261,7 +228,7 @@ nsresult NS_InitCommentClass(nsIScriptContext *aContext, void **aPrototype)
(PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) ||
!JSVAL_IS_OBJECT(vp)) {
if (NS_OK != NS_InitNodeClass(aContext, (void **)&parent_proto)) {
if (NS_OK != NS_InitDataClass(aContext, (void **)&parent_proto)) {
return NS_ERROR_FAILURE;
}
proto = JS_InitClass(jscontext, // context
@ -296,7 +263,7 @@ nsresult NS_InitCommentClass(nsIScriptContext *aContext, void **aPrototype)
//
// Method for creating a new Comment JavaScript object
//
extern "C" NS_DOM NS_NewScriptComment(nsIScriptContext *aContext, nsIDOMComment *aSupports, nsISupports *aParent, void **aReturn)
extern "C" NS_DOM nsresult NS_NewScriptComment(nsIScriptContext *aContext, nsIDOMComment *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptComment");
JSObject *proto;

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

@ -366,7 +366,7 @@ nsresult NS_InitDOMClass(nsIScriptContext *aContext, void **aPrototype)
//
// Method for creating a new DOM JavaScript object
//
extern "C" NS_DOM NS_NewScriptDOM(nsIScriptContext *aContext, nsIDOMDOM *aSupports, nsISupports *aParent, void **aReturn)
extern "C" NS_DOM nsresult NS_NewScriptDOM(nsIScriptContext *aContext, nsIDOMDOM *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptDOM");
JSObject *proto;

592
dom/src/nsJSData.cpp Normal file
Просмотреть файл

@ -0,0 +1,592 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#include "jsapi.h"
#include "nscore.h"
#include "nsIScriptContext.h"
#include "nsIJSScriptObject.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsIPtr.h"
#include "nsString.h"
#include "nsIDOMData.h"
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
static NS_DEFINE_IID(kIDataIID, NS_IDOMDATA_IID);
NS_DEF_PTR(nsIDOMData);
//
// Data property ids
//
enum Data_slots {
DATA_DATA = -11,
DATA_SIZE = -12
};
/***********************************************************************/
//
// Data Properties Getter
//
PR_STATIC_CALLBACK(JSBool)
GetDataProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMData *a = (nsIDOMData*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case DATA_DATA:
{
nsAutoString prop;
if (NS_OK == a->GetData(prop)) {
JSString *jsstring = JS_NewUCStringCopyN(cx, prop, prop.Length());
// set the return value
*vp = STRING_TO_JSVAL(jsstring);
}
else {
return JS_FALSE;
}
break;
}
case DATA_SIZE:
{
PRUint32 prop;
if (NS_OK == a->GetSize(&prop)) {
*vp = INT_TO_JSVAL(prop);
}
else {
return JS_FALSE;
}
break;
}
default:
{
nsIJSScriptObject *object;
if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {
PRBool rval;
rval = object->GetProperty(cx, id, vp);
NS_RELEASE(object);
return rval;
}
}
}
}
return PR_TRUE;
}
/***********************************************************************/
//
// Data Properties Setter
//
PR_STATIC_CALLBACK(JSBool)
SetDataProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMData *a = (nsIDOMData*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case DATA_DATA:
{
nsAutoString prop;
JSString *jsstring;
if ((jsstring = JS_ValueToString(cx, *vp)) != nsnull) {
prop.SetString(JS_GetStringChars(jsstring));
}
else {
prop.SetString((const char *)nsnull);
}
a->SetData(prop);
break;
}
default:
{
nsIJSScriptObject *object;
if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {
PRBool rval;
rval = object->SetProperty(cx, id, vp);
NS_RELEASE(object);
return rval;
}
}
}
}
return PR_TRUE;
}
//
// Data finalizer
//
PR_STATIC_CALLBACK(void)
FinalizeData(JSContext *cx, JSObject *obj)
{
nsIDOMData *a = (nsIDOMData*)JS_GetPrivate(cx, obj);
if (nsnull != a) {
// get the js object
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == a->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
owner->ResetScriptObject();
NS_RELEASE(owner);
}
NS_RELEASE(a);
}
}
//
// Data enumerate
//
PR_STATIC_CALLBACK(JSBool)
EnumerateData(JSContext *cx, JSObject *obj)
{
nsIDOMData *a = (nsIDOMData*)JS_GetPrivate(cx, obj);
if (nsnull != a) {
// get the js object
nsIJSScriptObject *object;
if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {
object->EnumerateProperty(cx);
NS_RELEASE(object);
}
}
return JS_TRUE;
}
//
// Data resolve
//
PR_STATIC_CALLBACK(JSBool)
ResolveData(JSContext *cx, JSObject *obj, jsval id)
{
nsIDOMData *a = (nsIDOMData*)JS_GetPrivate(cx, obj);
if (nsnull != a) {
// get the js object
nsIJSScriptObject *object;
if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {
object->Resolve(cx, id);
NS_RELEASE(object);
}
}
return JS_TRUE;
}
//
// Native method Substring
//
PR_STATIC_CALLBACK(JSBool)
DataSubstring(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMData *nativeThis = (nsIDOMData*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsAutoString nativeRet;
PRUint32 b0;
PRUint32 b1;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 2) {
if (!JS_ValueToInt32(cx, argv[0], (int32 *)&b0)) {
JS_ReportError(cx, "Parameter must be a number");
return JS_FALSE;
}
if (!JS_ValueToInt32(cx, argv[1], (int32 *)&b1)) {
JS_ReportError(cx, "Parameter must be a number");
return JS_FALSE;
}
if (NS_OK != nativeThis->Substring(b0, b1, nativeRet)) {
return JS_FALSE;
}
JSString *jsstring = JS_NewUCStringCopyN(cx, nativeRet, nativeRet.Length());
// set the return value
*rval = STRING_TO_JSVAL(jsstring);
}
else {
JS_ReportError(cx, "Function substring requires 2 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method Append
//
PR_STATIC_CALLBACK(JSBool)
DataAppend(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMData *nativeThis = (nsIDOMData*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsAutoString b0;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 1) {
JSString *jsstring0 = JS_ValueToString(cx, argv[0]);
if (nsnull != jsstring0) {
b0.SetString(JS_GetStringChars(jsstring0));
}
else {
b0.SetString(""); // Should this really be null??
}
if (NS_OK != nativeThis->Append(b0)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function append requires 1 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method Insert
//
PR_STATIC_CALLBACK(JSBool)
DataInsert(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMData *nativeThis = (nsIDOMData*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
PRUint32 b0;
nsAutoString b1;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 2) {
if (!JS_ValueToInt32(cx, argv[0], (int32 *)&b0)) {
JS_ReportError(cx, "Parameter must be a number");
return JS_FALSE;
}
JSString *jsstring1 = JS_ValueToString(cx, argv[1]);
if (nsnull != jsstring1) {
b1.SetString(JS_GetStringChars(jsstring1));
}
else {
b1.SetString(""); // Should this really be null??
}
if (NS_OK != nativeThis->Insert(b0, b1)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function insert requires 2 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method Remove
//
PR_STATIC_CALLBACK(JSBool)
DataRemove(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMData *nativeThis = (nsIDOMData*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
PRUint32 b0;
PRUint32 b1;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 2) {
if (!JS_ValueToInt32(cx, argv[0], (int32 *)&b0)) {
JS_ReportError(cx, "Parameter must be a number");
return JS_FALSE;
}
if (!JS_ValueToInt32(cx, argv[1], (int32 *)&b1)) {
JS_ReportError(cx, "Parameter must be a number");
return JS_FALSE;
}
if (NS_OK != nativeThis->Remove(b0, b1)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function remove requires 2 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method Replace
//
PR_STATIC_CALLBACK(JSBool)
DataReplace(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMData *nativeThis = (nsIDOMData*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
PRUint32 b0;
PRUint32 b1;
nsAutoString b2;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 3) {
if (!JS_ValueToInt32(cx, argv[0], (int32 *)&b0)) {
JS_ReportError(cx, "Parameter must be a number");
return JS_FALSE;
}
if (!JS_ValueToInt32(cx, argv[1], (int32 *)&b1)) {
JS_ReportError(cx, "Parameter must be a number");
return JS_FALSE;
}
JSString *jsstring2 = JS_ValueToString(cx, argv[2]);
if (nsnull != jsstring2) {
b2.SetString(JS_GetStringChars(jsstring2));
}
else {
b2.SetString(""); // Should this really be null??
}
if (NS_OK != nativeThis->Replace(b0, b1, b2)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function replace requires 3 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
/***********************************************************************/
//
// class for Data
//
JSClass DataClass = {
"Data",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
GetDataProperty,
SetDataProperty,
EnumerateData,
ResolveData,
JS_ConvertStub,
FinalizeData
};
//
// Data class properties
//
static JSPropertySpec DataProperties[] =
{
{"data", DATA_DATA, JSPROP_ENUMERATE},
{"size", DATA_SIZE, JSPROP_ENUMERATE | JSPROP_READONLY},
{0}
};
//
// Data class methods
//
static JSFunctionSpec DataMethods[] =
{
{"substring", DataSubstring, 2},
{"append", DataAppend, 1},
{"insert", DataInsert, 2},
{"remove", DataRemove, 2},
{"replace", DataReplace, 3},
{0}
};
//
// Data constructor
//
PR_STATIC_CALLBACK(JSBool)
Data(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
return JS_TRUE;
}
//
// Data class initialization
//
nsresult NS_InitDataClass(nsIScriptContext *aContext, void **aPrototype)
{
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
JSObject *proto = nsnull;
JSObject *constructor = nsnull;
JSObject *parent_proto = nsnull;
JSObject *global = JS_GetGlobalObject(jscontext);
jsval vp;
if ((PR_TRUE != JS_LookupProperty(jscontext, global, "Data", &vp)) ||
!JSVAL_IS_OBJECT(vp) ||
((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) ||
(PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) ||
!JSVAL_IS_OBJECT(vp)) {
if (NS_OK != NS_InitNodeClass(aContext, (void **)&parent_proto)) {
return NS_ERROR_FAILURE;
}
proto = JS_InitClass(jscontext, // context
global, // global object
parent_proto, // parent proto
&DataClass, // JSClass
Data, // JSNative ctor
0, // ctor args
DataProperties, // proto props
DataMethods, // proto funcs
nsnull, // ctor props (static)
nsnull); // ctor funcs (static)
if (nsnull == proto) {
return NS_ERROR_FAILURE;
}
}
else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) {
proto = JSVAL_TO_OBJECT(vp);
}
else {
return NS_ERROR_FAILURE;
}
if (aPrototype) {
*aPrototype = proto;
}
return NS_OK;
}
//
// Method for creating a new Data JavaScript object
//
extern "C" NS_DOM nsresult NS_NewScriptData(nsIScriptContext *aContext, nsIDOMData *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptData");
JSObject *proto;
JSObject *parent;
nsIScriptObjectOwner *owner;
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
if (nsnull == aParent) {
parent = nsnull;
}
else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) {
NS_RELEASE(owner);
return NS_ERROR_FAILURE;
}
NS_RELEASE(owner);
}
else {
return NS_ERROR_FAILURE;
}
if (NS_OK != NS_InitDataClass(aContext, (void **)&proto)) {
return NS_ERROR_FAILURE;
}
// create a js object for this class
*aReturn = JS_NewObject(jscontext, &DataClass, proto, parent);
if (nsnull != *aReturn) {
// connect the native object to the js object
JS_SetPrivate(jscontext, (JSObject *)*aReturn, aSupports);
NS_ADDREF(aSupports);
}
else {
return NS_ERROR_FAILURE;
}
return NS_OK;
}

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

@ -25,53 +25,54 @@
#include "nsIScriptGlobalObject.h"
#include "nsIPtr.h"
#include "nsString.h"
#include "nsIDOMAttributeList.h"
#include "nsIDOMElement.h"
#include "nsIDOMPI.h"
#include "nsIDOMNodeIterator.h"
#include "nsIDOMDocument.h"
#include "nsIDOMTreeIterator.h"
#include "nsIDOMProcessingInstruction.h"
#include "nsIDOMNamedNodeMap.h"
#include "nsIDOMAttribute.h"
#include "nsIDOMNode.h"
#include "nsIDOMText.h"
#include "nsIDOMDocumentContext.h"
#include "nsIDOMDocumentType.h"
#include "nsIDOMDocumentFragment.h"
#include "nsIDOMComment.h"
#include "nsIDOMNodeList.h"
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
static NS_DEFINE_IID(kIAttributeListIID, NS_IDOMATTRIBUTELIST_IID);
static NS_DEFINE_IID(kIElementIID, NS_IDOMELEMENT_IID);
static NS_DEFINE_IID(kIPIIID, NS_IDOMPI_IID);
static NS_DEFINE_IID(kINodeIteratorIID, NS_IDOMNODEITERATOR_IID);
static NS_DEFINE_IID(kIDocumentIID, NS_IDOMDOCUMENT_IID);
static NS_DEFINE_IID(kITreeIteratorIID, NS_IDOMTREEITERATOR_IID);
static NS_DEFINE_IID(kIProcessingInstructionIID, NS_IDOMPROCESSINGINSTRUCTION_IID);
static NS_DEFINE_IID(kINamedNodeMapIID, NS_IDOMNAMEDNODEMAP_IID);
static NS_DEFINE_IID(kIAttributeIID, NS_IDOMATTRIBUTE_IID);
static NS_DEFINE_IID(kINodeIID, NS_IDOMNODE_IID);
static NS_DEFINE_IID(kITextIID, NS_IDOMTEXT_IID);
static NS_DEFINE_IID(kIDocumentContextIID, NS_IDOMDOCUMENTCONTEXT_IID);
static NS_DEFINE_IID(kIDocumentTypeIID, NS_IDOMDOCUMENTTYPE_IID);
static NS_DEFINE_IID(kIDocumentFragmentIID, NS_IDOMDOCUMENTFRAGMENT_IID);
static NS_DEFINE_IID(kICommentIID, NS_IDOMCOMMENT_IID);
static NS_DEFINE_IID(kINodeListIID, NS_IDOMNODELIST_IID);
NS_DEF_PTR(nsIDOMAttributeList);
NS_DEF_PTR(nsIDOMElement);
NS_DEF_PTR(nsIDOMPI);
NS_DEF_PTR(nsIDOMNodeIterator);
NS_DEF_PTR(nsIDOMDocument);
NS_DEF_PTR(nsIDOMTreeIterator);
NS_DEF_PTR(nsIDOMProcessingInstruction);
NS_DEF_PTR(nsIDOMNamedNodeMap);
NS_DEF_PTR(nsIDOMAttribute);
NS_DEF_PTR(nsIDOMNode);
NS_DEF_PTR(nsIDOMText);
NS_DEF_PTR(nsIDOMDocumentContext);
NS_DEF_PTR(nsIDOMDocumentType);
NS_DEF_PTR(nsIDOMDocumentFragment);
NS_DEF_PTR(nsIDOMComment);
NS_DEF_PTR(nsIDOMNodeList);
//
// Document property ids
//
enum Document_slots {
DOCUMENT_DOCUMENTTYPE = -11,
DOCUMENT_DOCUMENTELEMENT = -12,
DOCUMENT_DOCUMENTCONTEXT = -13
DOCUMENT_PROLOG = -12,
DOCUMENT_EPILOG = -13,
DOCUMENT_DOCUMENTELEMENT = -14
};
/***********************************************************************/
@ -92,7 +93,7 @@ GetDocumentProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
switch(JSVAL_TO_INT(id)) {
case DOCUMENT_DOCUMENTTYPE:
{
nsIDOMNode* prop;
nsIDOMDocumentType* prop;
if (NS_OK == a->GetDocumentType(&prop)) {
// get the js object
if (prop != nsnull) {
@ -117,6 +118,60 @@ GetDocumentProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
}
break;
}
case DOCUMENT_PROLOG:
{
nsIDOMNodeList* prop;
if (NS_OK == a->GetProlog(&prop)) {
// get the js object
if (prop != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == prop->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*vp = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(prop);
}
else {
*vp = JSVAL_NULL;
}
}
else {
return JS_FALSE;
}
break;
}
case DOCUMENT_EPILOG:
{
nsIDOMNodeList* prop;
if (NS_OK == a->GetEpilog(&prop)) {
// get the js object
if (prop != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == prop->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*vp = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(prop);
}
else {
*vp = JSVAL_NULL;
}
}
else {
return JS_FALSE;
}
break;
}
case DOCUMENT_DOCUMENTELEMENT:
{
nsIDOMElement* prop;
@ -144,33 +199,6 @@ GetDocumentProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
}
break;
}
case DOCUMENT_DOCUMENTCONTEXT:
{
nsIDOMDocumentContext* prop;
if (NS_OK == a->GetDocumentContext(&prop)) {
// get the js object
if (prop != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == prop->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*vp = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(prop);
}
else {
*vp = JSVAL_NULL;
}
}
else {
return JS_FALSE;
}
break;
}
default:
{
nsIJSScriptObject *object;
@ -203,75 +231,7 @@ SetDocumentProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case DOCUMENT_DOCUMENTTYPE:
{
nsIDOMNode* prop;
if (JSVAL_IS_NULL(*vp)) {
prop = nsnull;
}
else if (JSVAL_IS_OBJECT(*vp)) {
JSObject *jsobj = JSVAL_TO_OBJECT(*vp);
nsISupports *supports = (nsISupports *)JS_GetPrivate(cx, jsobj);
if (NS_OK != supports->QueryInterface(kINodeIID, (void **)&prop)) {
JS_ReportError(cx, "Parameter must be of type Node");
return JS_FALSE;
}
}
else {
JS_ReportError(cx, "Parameter must be an object");
return JS_FALSE;
}
a->SetDocumentType(prop);
if (prop) NS_RELEASE(prop);
break;
}
case DOCUMENT_DOCUMENTELEMENT:
{
nsIDOMElement* prop;
if (JSVAL_IS_NULL(*vp)) {
prop = nsnull;
}
else if (JSVAL_IS_OBJECT(*vp)) {
JSObject *jsobj = JSVAL_TO_OBJECT(*vp);
nsISupports *supports = (nsISupports *)JS_GetPrivate(cx, jsobj);
if (NS_OK != supports->QueryInterface(kIElementIID, (void **)&prop)) {
JS_ReportError(cx, "Parameter must be of type Element");
return JS_FALSE;
}
}
else {
JS_ReportError(cx, "Parameter must be an object");
return JS_FALSE;
}
a->SetDocumentElement(prop);
if (prop) NS_RELEASE(prop);
break;
}
case DOCUMENT_DOCUMENTCONTEXT:
{
nsIDOMDocumentContext* prop;
if (JSVAL_IS_NULL(*vp)) {
prop = nsnull;
}
else if (JSVAL_IS_OBJECT(*vp)) {
JSObject *jsobj = JSVAL_TO_OBJECT(*vp);
nsISupports *supports = (nsISupports *)JS_GetPrivate(cx, jsobj);
if (NS_OK != supports->QueryInterface(kIDocumentContextIID, (void **)&prop)) {
JS_ReportError(cx, "Parameter must be of type DocumentContext");
return JS_FALSE;
}
}
else {
JS_ReportError(cx, "Parameter must be an object");
return JS_FALSE;
}
a->SetDocumentContext(prop);
if (prop) NS_RELEASE(prop);
break;
}
case 0:
default:
{
nsIJSScriptObject *object;
@ -350,55 +310,6 @@ ResolveDocument(JSContext *cx, JSObject *obj, jsval id)
}
//
// Native method CreateDocumentContext
//
PR_STATIC_CALLBACK(JSBool)
DocumentCreateDocumentContext(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMDocument *nativeThis = (nsIDOMDocument*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMDocumentContext* nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->CreateDocumentContext(&nativeRet)) {
return JS_FALSE;
}
if (nativeRet != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*rval = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(nativeRet);
}
else {
*rval = JSVAL_NULL;
}
}
else {
JS_ReportError(cx, "Function createDocumentContext requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method CreateElement
//
@ -409,7 +320,7 @@ DocumentCreateElement(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsv
JSBool rBool = JS_FALSE;
nsIDOMElement* nativeRet;
nsAutoString b0;
nsIDOMAttributeListPtr b1;
nsIDOMNamedNodeMapPtr b1;
*rval = JSVAL_NULL;
@ -436,8 +347,8 @@ DocumentCreateElement(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsv
NS_ASSERTION(nsnull != supports1, "null pointer");
if ((nsnull == supports1) ||
(NS_OK != supports1->QueryInterface(kIAttributeListIID, (void **)(b1.Query())))) {
JS_ReportError(cx, "Parameter must be of type AttributeList");
(NS_OK != supports1->QueryInterface(kINamedNodeMapIID, (void **)(b1.Query())))) {
JS_ReportError(cx, "Parameter must be of type NamedNodeMap");
return JS_FALSE;
}
}
@ -476,6 +387,55 @@ DocumentCreateElement(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsv
}
//
// Native method CreateDocumentFragment
//
PR_STATIC_CALLBACK(JSBool)
DocumentCreateDocumentFragment(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMDocument *nativeThis = (nsIDOMDocument*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMDocumentFragment* nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->CreateDocumentFragment(&nativeRet)) {
return JS_FALSE;
}
if (nativeRet != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*rval = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(nativeRet);
}
else {
*rval = JSVAL_NULL;
}
}
else {
JS_ReportError(cx, "Function createDocumentFragment requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method CreateTextNode
//
@ -593,14 +553,14 @@ DocumentCreateComment(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsv
//
// Native method CreatePI
// Native method CreateProcessingInstruction
//
PR_STATIC_CALLBACK(JSBool)
DocumentCreatePI(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
DocumentCreateProcessingInstruction(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMDocument *nativeThis = (nsIDOMDocument*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMPI* nativeRet;
nsIDOMProcessingInstruction* nativeRet;
nsAutoString b0;
nsAutoString b1;
@ -629,7 +589,7 @@ DocumentCreatePI(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *r
b1.SetString(""); // Should this really be null??
}
if (NS_OK != nativeThis->CreatePI(b0, b1, &nativeRet)) {
if (NS_OK != nativeThis->CreateProcessingInstruction(b0, b1, &nativeRet)) {
return JS_FALSE;
}
@ -651,7 +611,7 @@ DocumentCreatePI(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *r
}
}
else {
JS_ReportError(cx, "Function createPI requires 2 parameters");
JS_ReportError(cx, "Function createProcessingInstruction requires 2 parameters");
return JS_FALSE;
}
@ -736,123 +696,6 @@ DocumentCreateAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, j
}
//
// Native method CreateAttributeList
//
PR_STATIC_CALLBACK(JSBool)
DocumentCreateAttributeList(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMDocument *nativeThis = (nsIDOMDocument*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMAttributeList* nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->CreateAttributeList(&nativeRet)) {
return JS_FALSE;
}
if (nativeRet != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*rval = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(nativeRet);
}
else {
*rval = JSVAL_NULL;
}
}
else {
JS_ReportError(cx, "Function createAttributeList requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method CreateTreeIterator
//
PR_STATIC_CALLBACK(JSBool)
DocumentCreateTreeIterator(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMDocument *nativeThis = (nsIDOMDocument*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMTreeIterator* nativeRet;
nsIDOMNodePtr b0;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 1) {
if (JSVAL_IS_NULL(argv[0])){
b0 = nsnull;
}
else if (JSVAL_IS_OBJECT(argv[0])) {
nsISupports *supports0 = (nsISupports *)JS_GetPrivate(cx, JSVAL_TO_OBJECT(argv[0]));
NS_ASSERTION(nsnull != supports0, "null pointer");
if ((nsnull == supports0) ||
(NS_OK != supports0->QueryInterface(kINodeIID, (void **)(b0.Query())))) {
JS_ReportError(cx, "Parameter must be of type Node");
return JS_FALSE;
}
}
else {
JS_ReportError(cx, "Parameter must be an object");
return JS_FALSE;
}
if (NS_OK != nativeThis->CreateTreeIterator(b0, &nativeRet)) {
return JS_FALSE;
}
if (nativeRet != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*rval = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(nativeRet);
}
else {
*rval = JSVAL_NULL;
}
}
else {
JS_ReportError(cx, "Function createTreeIterator requires 1 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method GetElementsByTagName
//
@ -861,7 +704,7 @@ DocumentGetElementsByTagName(JSContext *cx, JSObject *obj, uintN argc, jsval *ar
{
nsIDOMDocument *nativeThis = (nsIDOMDocument*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMNodeIterator* nativeRet;
nsIDOMNodeList* nativeRet;
nsAutoString b0;
*rval = JSVAL_NULL;
@ -934,9 +777,10 @@ JSClass DocumentClass = {
//
static JSPropertySpec DocumentProperties[] =
{
{"documentType", DOCUMENT_DOCUMENTTYPE, JSPROP_ENUMERATE},
{"documentElement", DOCUMENT_DOCUMENTELEMENT, JSPROP_ENUMERATE},
{"documentContext", DOCUMENT_DOCUMENTCONTEXT, JSPROP_ENUMERATE},
{"documentType", DOCUMENT_DOCUMENTTYPE, JSPROP_ENUMERATE | JSPROP_READONLY},
{"prolog", DOCUMENT_PROLOG, JSPROP_ENUMERATE | JSPROP_READONLY},
{"epilog", DOCUMENT_EPILOG, JSPROP_ENUMERATE | JSPROP_READONLY},
{"documentElement", DOCUMENT_DOCUMENTELEMENT, JSPROP_ENUMERATE | JSPROP_READONLY},
{0}
};
@ -946,14 +790,12 @@ static JSPropertySpec DocumentProperties[] =
//
static JSFunctionSpec DocumentMethods[] =
{
{"createDocumentContext", DocumentCreateDocumentContext, 0},
{"createElement", DocumentCreateElement, 2},
{"createDocumentFragment", DocumentCreateDocumentFragment, 0},
{"createTextNode", DocumentCreateTextNode, 1},
{"createComment", DocumentCreateComment, 1},
{"createPI", DocumentCreatePI, 2},
{"createProcessingInstruction", DocumentCreateProcessingInstruction, 2},
{"createAttribute", DocumentCreateAttribute, 2},
{"createAttributeList", DocumentCreateAttributeList, 0},
{"createTreeIterator", DocumentCreateTreeIterator, 1},
{"getElementsByTagName", DocumentGetElementsByTagName, 1},
{0}
};
@ -1022,7 +864,7 @@ nsresult NS_InitDocumentClass(nsIScriptContext *aContext, void **aPrototype)
//
// Method for creating a new Document JavaScript object
//
extern "C" NS_DOM NS_NewScriptDocument(nsIScriptContext *aContext, nsIDOMDocument *aSupports, nsISupports *aParent, void **aReturn)
extern "C" NS_DOM nsresult NS_NewScriptDocument(nsIScriptContext *aContext, nsIDOMDocument *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptDocument");
JSObject *proto;

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

@ -120,29 +120,7 @@ SetDocumentFragmentProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case DOCUMENTFRAGMENT_MASTERDOC:
{
nsIDOMDocument* prop;
if (JSVAL_IS_NULL(*vp)) {
prop = nsnull;
}
else if (JSVAL_IS_OBJECT(*vp)) {
JSObject *jsobj = JSVAL_TO_OBJECT(*vp);
nsISupports *supports = (nsISupports *)JS_GetPrivate(cx, jsobj);
if (NS_OK != supports->QueryInterface(kIDocumentIID, (void **)&prop)) {
JS_ReportError(cx, "Parameter must be of type Document");
return JS_FALSE;
}
}
else {
JS_ReportError(cx, "Parameter must be an object");
return JS_FALSE;
}
a->SetMasterDoc(prop);
if (prop) NS_RELEASE(prop);
break;
}
case 0:
default:
{
nsIJSScriptObject *object;
@ -244,7 +222,7 @@ JSClass DocumentFragmentClass = {
//
static JSPropertySpec DocumentFragmentProperties[] =
{
{"masterDoc", DOCUMENTFRAGMENT_MASTERDOC, JSPROP_ENUMERATE},
{"masterDoc", DOCUMENTFRAGMENT_MASTERDOC, JSPROP_ENUMERATE | JSPROP_READONLY},
{0}
};
@ -321,7 +299,7 @@ nsresult NS_InitDocumentFragmentClass(nsIScriptContext *aContext, void **aProtot
//
// Method for creating a new DocumentFragment JavaScript object
//
extern "C" NS_DOM NS_NewScriptDocumentFragment(nsIScriptContext *aContext, nsIDOMDocumentFragment *aSupports, nsISupports *aParent, void **aReturn)
extern "C" NS_DOM nsresult NS_NewScriptDocumentFragment(nsIScriptContext *aContext, nsIDOMDocumentFragment *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptDocumentFragment");
JSObject *proto;

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

@ -25,34 +25,35 @@
#include "nsIScriptGlobalObject.h"
#include "nsIPtr.h"
#include "nsString.h"
#include "nsIDOMDocument.h"
#include "nsIDOMDocumentContext.h"
#include "nsIDOMNamedNodeMap.h"
#include "nsIDOMDocumentType.h"
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
static NS_DEFINE_IID(kIDocumentIID, NS_IDOMDOCUMENT_IID);
static NS_DEFINE_IID(kIDocumentContextIID, NS_IDOMDOCUMENTCONTEXT_IID);
static NS_DEFINE_IID(kINamedNodeMapIID, NS_IDOMNAMEDNODEMAP_IID);
static NS_DEFINE_IID(kIDocumentTypeIID, NS_IDOMDOCUMENTTYPE_IID);
NS_DEF_PTR(nsIDOMDocument);
NS_DEF_PTR(nsIDOMDocumentContext);
NS_DEF_PTR(nsIDOMNamedNodeMap);
NS_DEF_PTR(nsIDOMDocumentType);
//
// DocumentContext property ids
// DocumentType property ids
//
enum DocumentContext_slots {
DOCUMENTCONTEXT_DOCUMENT = -11
enum DocumentType_slots {
DOCUMENTTYPE_NAME = -11,
DOCUMENTTYPE_ENTITIES = -12
};
/***********************************************************************/
//
// DocumentContext Properties Getter
// DocumentType Properties Getter
//
PR_STATIC_CALLBACK(JSBool)
GetDocumentContextProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
GetDocumentTypeProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMDocumentContext *a = (nsIDOMDocumentContext*)JS_GetPrivate(cx, obj);
nsIDOMDocumentType *a = (nsIDOMDocumentType*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
@ -61,10 +62,23 @@ GetDocumentContextProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case DOCUMENTCONTEXT_DOCUMENT:
case DOCUMENTTYPE_NAME:
{
nsIDOMDocument* prop;
if (NS_OK == a->GetDocument(&prop)) {
nsAutoString prop;
if (NS_OK == a->GetName(prop)) {
JSString *jsstring = JS_NewUCStringCopyN(cx, prop, prop.Length());
// set the return value
*vp = STRING_TO_JSVAL(jsstring);
}
else {
return JS_FALSE;
}
break;
}
case DOCUMENTTYPE_ENTITIES:
{
nsIDOMNamedNodeMap* prop;
if (NS_OK == a->GetEntities(&prop)) {
// get the js object
if (prop != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
@ -106,12 +120,12 @@ GetDocumentContextProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
/***********************************************************************/
//
// DocumentContext Properties Setter
// DocumentType Properties Setter
//
PR_STATIC_CALLBACK(JSBool)
SetDocumentContextProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
SetDocumentTypeProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMDocumentContext *a = (nsIDOMDocumentContext*)JS_GetPrivate(cx, obj);
nsIDOMDocumentType *a = (nsIDOMDocumentType*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
@ -120,17 +134,32 @@ SetDocumentContextProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case DOCUMENTCONTEXT_DOCUMENT:
case DOCUMENTTYPE_NAME:
{
nsIDOMDocument* prop;
nsAutoString prop;
JSString *jsstring;
if ((jsstring = JS_ValueToString(cx, *vp)) != nsnull) {
prop.SetString(JS_GetStringChars(jsstring));
}
else {
prop.SetString((const char *)nsnull);
}
a->SetName(prop);
break;
}
case DOCUMENTTYPE_ENTITIES:
{
nsIDOMNamedNodeMap* prop;
if (JSVAL_IS_NULL(*vp)) {
prop = nsnull;
}
else if (JSVAL_IS_OBJECT(*vp)) {
JSObject *jsobj = JSVAL_TO_OBJECT(*vp);
nsISupports *supports = (nsISupports *)JS_GetPrivate(cx, jsobj);
if (NS_OK != supports->QueryInterface(kIDocumentIID, (void **)&prop)) {
JS_ReportError(cx, "Parameter must be of type Document");
if (NS_OK != supports->QueryInterface(kINamedNodeMapIID, (void **)&prop)) {
JS_ReportError(cx, "Parameter must be of type NamedNodeMap");
return JS_FALSE;
}
}
@ -139,7 +168,7 @@ SetDocumentContextProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
return JS_FALSE;
}
a->SetDocument(prop);
a->SetEntities(prop);
if (prop) NS_RELEASE(prop);
break;
}
@ -161,12 +190,12 @@ SetDocumentContextProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
//
// DocumentContext finalizer
// DocumentType finalizer
//
PR_STATIC_CALLBACK(void)
FinalizeDocumentContext(JSContext *cx, JSObject *obj)
FinalizeDocumentType(JSContext *cx, JSObject *obj)
{
nsIDOMDocumentContext *a = (nsIDOMDocumentContext*)JS_GetPrivate(cx, obj);
nsIDOMDocumentType *a = (nsIDOMDocumentType*)JS_GetPrivate(cx, obj);
if (nsnull != a) {
// get the js object
@ -182,12 +211,12 @@ FinalizeDocumentContext(JSContext *cx, JSObject *obj)
//
// DocumentContext enumerate
// DocumentType enumerate
//
PR_STATIC_CALLBACK(JSBool)
EnumerateDocumentContext(JSContext *cx, JSObject *obj)
EnumerateDocumentType(JSContext *cx, JSObject *obj)
{
nsIDOMDocumentContext *a = (nsIDOMDocumentContext*)JS_GetPrivate(cx, obj);
nsIDOMDocumentType *a = (nsIDOMDocumentType*)JS_GetPrivate(cx, obj);
if (nsnull != a) {
// get the js object
@ -202,12 +231,12 @@ EnumerateDocumentContext(JSContext *cx, JSObject *obj)
//
// DocumentContext resolve
// DocumentType resolve
//
PR_STATIC_CALLBACK(JSBool)
ResolveDocumentContext(JSContext *cx, JSObject *obj, jsval id)
ResolveDocumentType(JSContext *cx, JSObject *obj, jsval id)
{
nsIDOMDocumentContext *a = (nsIDOMDocumentContext*)JS_GetPrivate(cx, obj);
nsIDOMDocumentType *a = (nsIDOMDocumentType*)JS_GetPrivate(cx, obj);
if (nsnull != a) {
// get the js object
@ -223,55 +252,56 @@ ResolveDocumentContext(JSContext *cx, JSObject *obj, jsval id)
/***********************************************************************/
//
// class for DocumentContext
// class for DocumentType
//
JSClass DocumentContextClass = {
"DocumentContext",
JSClass DocumentTypeClass = {
"DocumentType",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
GetDocumentContextProperty,
SetDocumentContextProperty,
EnumerateDocumentContext,
ResolveDocumentContext,
GetDocumentTypeProperty,
SetDocumentTypeProperty,
EnumerateDocumentType,
ResolveDocumentType,
JS_ConvertStub,
FinalizeDocumentContext
FinalizeDocumentType
};
//
// DocumentContext class properties
// DocumentType class properties
//
static JSPropertySpec DocumentContextProperties[] =
static JSPropertySpec DocumentTypeProperties[] =
{
{"document", DOCUMENTCONTEXT_DOCUMENT, JSPROP_ENUMERATE},
{"name", DOCUMENTTYPE_NAME, JSPROP_ENUMERATE},
{"entities", DOCUMENTTYPE_ENTITIES, JSPROP_ENUMERATE},
{0}
};
//
// DocumentContext class methods
// DocumentType class methods
//
static JSFunctionSpec DocumentContextMethods[] =
static JSFunctionSpec DocumentTypeMethods[] =
{
{0}
};
//
// DocumentContext constructor
// DocumentType constructor
//
PR_STATIC_CALLBACK(JSBool)
DocumentContext(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
DocumentType(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
return JS_TRUE;
}
//
// DocumentContext class initialization
// DocumentType class initialization
//
nsresult NS_InitDocumentContextClass(nsIScriptContext *aContext, void **aPrototype)
nsresult NS_InitDocumentTypeClass(nsIScriptContext *aContext, void **aPrototype)
{
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
JSObject *proto = nsnull;
@ -280,7 +310,7 @@ nsresult NS_InitDocumentContextClass(nsIScriptContext *aContext, void **aPrototy
JSObject *global = JS_GetGlobalObject(jscontext);
jsval vp;
if ((PR_TRUE != JS_LookupProperty(jscontext, global, "DocumentContext", &vp)) ||
if ((PR_TRUE != JS_LookupProperty(jscontext, global, "DocumentType", &vp)) ||
!JSVAL_IS_OBJECT(vp) ||
((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) ||
(PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) ||
@ -289,11 +319,11 @@ nsresult NS_InitDocumentContextClass(nsIScriptContext *aContext, void **aPrototy
proto = JS_InitClass(jscontext, // context
global, // global object
parent_proto, // parent proto
&DocumentContextClass, // JSClass
DocumentContext, // JSNative ctor
&DocumentTypeClass, // JSClass
DocumentType, // JSNative ctor
0, // ctor args
DocumentContextProperties, // proto props
DocumentContextMethods, // proto funcs
DocumentTypeProperties, // proto props
DocumentTypeMethods, // proto funcs
nsnull, // ctor props (static)
nsnull); // ctor funcs (static)
if (nsnull == proto) {
@ -316,11 +346,11 @@ nsresult NS_InitDocumentContextClass(nsIScriptContext *aContext, void **aPrototy
//
// Method for creating a new DocumentContext JavaScript object
// Method for creating a new DocumentType JavaScript object
//
extern "C" NS_DOM NS_NewScriptDocumentContext(nsIScriptContext *aContext, nsIDOMDocumentContext *aSupports, nsISupports *aParent, void **aReturn)
extern "C" NS_DOM nsresult NS_NewScriptDocumentType(nsIScriptContext *aContext, nsIDOMDocumentType *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptDocumentContext");
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptDocumentType");
JSObject *proto;
JSObject *parent;
nsIScriptObjectOwner *owner;
@ -340,12 +370,12 @@ extern "C" NS_DOM NS_NewScriptDocumentContext(nsIScriptContext *aContext, nsIDOM
return NS_ERROR_FAILURE;
}
if (NS_OK != NS_InitDocumentContextClass(aContext, (void **)&proto)) {
if (NS_OK != NS_InitDocumentTypeClass(aContext, (void **)&proto)) {
return NS_ERROR_FAILURE;
}
// create a js object for this class
*aReturn = JS_NewObject(jscontext, &DocumentContextClass, proto, parent);
*aReturn = JS_NewObject(jscontext, &DocumentTypeClass, proto, parent);
if (nsnull != *aReturn) {
// connect the native object to the js object
JS_SetPrivate(jscontext, (JSObject *)*aReturn, aSupports);

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

@ -25,25 +25,28 @@
#include "nsIScriptGlobalObject.h"
#include "nsIPtr.h"
#include "nsString.h"
#include "nsIDOMAttributeList.h"
#include "nsIDOMElement.h"
#include "nsIDOMNodeIterator.h"
#include "nsIDOMAttribute.h"
#include "nsIDOMNodeList.h"
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
static NS_DEFINE_IID(kIAttributeListIID, NS_IDOMATTRIBUTELIST_IID);
static NS_DEFINE_IID(kIElementIID, NS_IDOMELEMENT_IID);
static NS_DEFINE_IID(kINodeIteratorIID, NS_IDOMNODEITERATOR_IID);
static NS_DEFINE_IID(kIAttributeIID, NS_IDOMATTRIBUTE_IID);
static NS_DEFINE_IID(kINodeListIID, NS_IDOMNODELIST_IID);
NS_DEF_PTR(nsIDOMAttributeList);
NS_DEF_PTR(nsIDOMElement);
NS_DEF_PTR(nsIDOMNodeIterator);
NS_DEF_PTR(nsIDOMAttribute);
NS_DEF_PTR(nsIDOMNodeList);
//
// Element property ids
//
enum Element_slots {
ELEMENT_TAGNAME = -11
};
/***********************************************************************/
//
@ -61,7 +64,19 @@ GetElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case 0:
case ELEMENT_TAGNAME:
{
nsAutoString prop;
if (NS_OK == a->GetTagName(prop)) {
JSString *jsstring = JS_NewUCStringCopyN(cx, prop, prop.Length());
// set the return value
*vp = STRING_TO_JSVAL(jsstring);
}
else {
return JS_FALSE;
}
break;
}
default:
{
nsIJSScriptObject *object;
@ -173,91 +188,6 @@ ResolveElement(JSContext *cx, JSObject *obj, jsval id)
}
//
// Native method GetTagName
//
PR_STATIC_CALLBACK(JSBool)
ElementGetTagName(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMElement *nativeThis = (nsIDOMElement*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsAutoString nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->GetTagName(nativeRet)) {
return JS_FALSE;
}
JSString *jsstring = JS_NewUCStringCopyN(cx, nativeRet, nativeRet.Length());
// set the return value
*rval = STRING_TO_JSVAL(jsstring);
}
else {
JS_ReportError(cx, "Function getTagName requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method GetAttributes
//
PR_STATIC_CALLBACK(JSBool)
ElementGetAttributes(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMElement *nativeThis = (nsIDOMElement*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMAttributeList* nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->GetAttributes(&nativeRet)) {
return JS_FALSE;
}
if (nativeRet != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*rval = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(nativeRet);
}
else {
*rval = JSVAL_NULL;
}
}
else {
JS_ReportError(cx, "Function getAttributes requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method GetDOMAttribute
//
@ -566,7 +496,7 @@ ElementGetElementsByTagName(JSContext *cx, JSObject *obj, uintN argc, jsval *arg
{
nsIDOMElement *nativeThis = (nsIDOMElement*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMNodeIterator* nativeRet;
nsIDOMNodeList* nativeRet;
nsAutoString b0;
*rval = JSVAL_NULL;
@ -672,6 +602,7 @@ JSClass ElementClass = {
//
static JSPropertySpec ElementProperties[] =
{
{"tagName", ELEMENT_TAGNAME, JSPROP_ENUMERATE | JSPROP_READONLY},
{0}
};
@ -681,8 +612,6 @@ static JSPropertySpec ElementProperties[] =
//
static JSFunctionSpec ElementMethods[] =
{
{"getTagName", ElementGetTagName, 0},
{"getAttributes", ElementGetAttributes, 0},
{"getDOMAttribute", ElementGetDOMAttribute, 1},
{"setDOMAttribute", ElementSetDOMAttribute, 2},
{"removeAttribute", ElementRemoveAttribute, 1},
@ -758,7 +687,7 @@ nsresult NS_InitElementClass(nsIScriptContext *aContext, void **aPrototype)
//
// Method for creating a new Element JavaScript object
//
extern "C" NS_DOM NS_NewScriptElement(nsIScriptContext *aContext, nsIDOMElement *aSupports, nsISupports *aParent, void **aReturn)
extern "C" NS_DOM nsresult NS_NewScriptElement(nsIScriptContext *aContext, nsIDOMElement *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptElement");
JSObject *proto;

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

@ -25,8 +25,8 @@
#include "nsIDOMDocument.h"
#include "nsIDOMText.h"
#include "nsIDOMAttribute.h"
#include "nsIDOMAttributeList.h"
#include "nsIDOMNodeIterator.h"
#include "nsIDOMNamedNodeMap.h"
#include "nsIDOMNodeList.h"
const uint32 gGCSize = 4L * 1024L * 1024L;
const size_t gStackSize = 8192;
@ -115,8 +115,8 @@ nsresult nsJSContext::InitClasses()
NS_OK == NS_InitDocumentClass(this, nsnull) &&
NS_OK == NS_InitTextClass(this, nsnull) &&
NS_OK == NS_InitAttributeClass(this, nsnull) &&
NS_OK == NS_InitAttributeListClass(this, nsnull) &&
NS_OK == NS_InitNodeIteratorClass(this, nsnull)) {
NS_OK == NS_InitNamedNodeMapClass(this, nsnull) &&
NS_OK == NS_InitNodeListClass(this, nsnull)) {
res = NS_OK;
}
@ -154,7 +154,7 @@ nsIScriptContext* nsJSEnvironment::GetNewContext()
}
extern "C" NS_DOM NS_CreateContext(nsIScriptGlobalObject *aGlobal, nsIScriptContext **aContext)
extern "C" NS_DOM nsresult NS_CreateContext(nsIScriptGlobalObject *aGlobal, nsIScriptContext **aContext)
{
nsJSEnvironment *environment = nsJSEnvironment::GetScriptingEnvironment();
*aContext = environment->GetNewContext();

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

@ -25,28 +25,34 @@
#include "nsIScriptGlobalObject.h"
#include "nsIPtr.h"
#include "nsString.h"
#include "nsIDOMAttributeList.h"
#include "nsIDOMAttribute.h"
#include "nsIDOMNamedNodeMap.h"
#include "nsIDOMNode.h"
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
static NS_DEFINE_IID(kIAttributeListIID, NS_IDOMATTRIBUTELIST_IID);
static NS_DEFINE_IID(kIAttributeIID, NS_IDOMATTRIBUTE_IID);
static NS_DEFINE_IID(kINamedNodeMapIID, NS_IDOMNAMEDNODEMAP_IID);
static NS_DEFINE_IID(kINodeIID, NS_IDOMNODE_IID);
NS_DEF_PTR(nsIDOMAttributeList);
NS_DEF_PTR(nsIDOMAttribute);
NS_DEF_PTR(nsIDOMNamedNodeMap);
NS_DEF_PTR(nsIDOMNode);
//
// NamedNodeMap property ids
//
enum NamedNodeMap_slots {
NAMEDNODEMAP_LENGTH = -11
};
/***********************************************************************/
//
// AttributeList Properties Getter
// NamedNodeMap Properties Getter
//
PR_STATIC_CALLBACK(JSBool)
GetAttributeListProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
GetNamedNodeMapProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMAttributeList *a = (nsIDOMAttributeList*)JS_GetPrivate(cx, obj);
nsIDOMNamedNodeMap *a = (nsIDOMNamedNodeMap*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
@ -55,7 +61,17 @@ GetAttributeListProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case 0:
case NAMEDNODEMAP_LENGTH:
{
PRUint32 prop;
if (NS_OK == a->GetLength(&prop)) {
*vp = INT_TO_JSVAL(prop);
}
else {
return JS_FALSE;
}
break;
}
default:
{
nsIJSScriptObject *object;
@ -74,12 +90,12 @@ GetAttributeListProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
/***********************************************************************/
//
// AttributeList Properties Setter
// NamedNodeMap Properties Setter
//
PR_STATIC_CALLBACK(JSBool)
SetAttributeListProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
SetNamedNodeMapProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMAttributeList *a = (nsIDOMAttributeList*)JS_GetPrivate(cx, obj);
nsIDOMNamedNodeMap *a = (nsIDOMNamedNodeMap*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
@ -107,12 +123,12 @@ SetAttributeListProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
//
// AttributeList finalizer
// NamedNodeMap finalizer
//
PR_STATIC_CALLBACK(void)
FinalizeAttributeList(JSContext *cx, JSObject *obj)
FinalizeNamedNodeMap(JSContext *cx, JSObject *obj)
{
nsIDOMAttributeList *a = (nsIDOMAttributeList*)JS_GetPrivate(cx, obj);
nsIDOMNamedNodeMap *a = (nsIDOMNamedNodeMap*)JS_GetPrivate(cx, obj);
if (nsnull != a) {
// get the js object
@ -128,12 +144,12 @@ FinalizeAttributeList(JSContext *cx, JSObject *obj)
//
// AttributeList enumerate
// NamedNodeMap enumerate
//
PR_STATIC_CALLBACK(JSBool)
EnumerateAttributeList(JSContext *cx, JSObject *obj)
EnumerateNamedNodeMap(JSContext *cx, JSObject *obj)
{
nsIDOMAttributeList *a = (nsIDOMAttributeList*)JS_GetPrivate(cx, obj);
nsIDOMNamedNodeMap *a = (nsIDOMNamedNodeMap*)JS_GetPrivate(cx, obj);
if (nsnull != a) {
// get the js object
@ -148,12 +164,12 @@ EnumerateAttributeList(JSContext *cx, JSObject *obj)
//
// AttributeList resolve
// NamedNodeMap resolve
//
PR_STATIC_CALLBACK(JSBool)
ResolveAttributeList(JSContext *cx, JSObject *obj, jsval id)
ResolveNamedNodeMap(JSContext *cx, JSObject *obj, jsval id)
{
nsIDOMAttributeList *a = (nsIDOMAttributeList*)JS_GetPrivate(cx, obj);
nsIDOMNamedNodeMap *a = (nsIDOMNamedNodeMap*)JS_GetPrivate(cx, obj);
if (nsnull != a) {
// get the js object
@ -168,14 +184,14 @@ ResolveAttributeList(JSContext *cx, JSObject *obj, jsval id)
//
// Native method GetAttribute
// Native method GetNamedItem
//
PR_STATIC_CALLBACK(JSBool)
AttributeListGetAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
NamedNodeMapGetNamedItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMAttributeList *nativeThis = (nsIDOMAttributeList*)JS_GetPrivate(cx, obj);
nsIDOMNamedNodeMap *nativeThis = (nsIDOMNamedNodeMap*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMAttribute* nativeRet;
nsIDOMNode* nativeRet;
nsAutoString b0;
*rval = JSVAL_NULL;
@ -195,7 +211,7 @@ AttributeListGetAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
b0.SetString(""); // Should this really be null??
}
if (NS_OK != nativeThis->GetAttribute(b0, &nativeRet)) {
if (NS_OK != nativeThis->GetNamedItem(b0, &nativeRet)) {
return JS_FALSE;
}
@ -217,7 +233,7 @@ AttributeListGetAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
}
}
else {
JS_ReportError(cx, "Function getAttribute requires 1 parameters");
JS_ReportError(cx, "Function getNamedItem requires 1 parameters");
return JS_FALSE;
}
@ -226,14 +242,14 @@ AttributeListGetAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
//
// Native method SetAttribute
// Native method SetNamedItem
//
PR_STATIC_CALLBACK(JSBool)
AttributeListSetAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
NamedNodeMapSetNamedItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMAttributeList *nativeThis = (nsIDOMAttributeList*)JS_GetPrivate(cx, obj);
nsIDOMNamedNodeMap *nativeThis = (nsIDOMNamedNodeMap*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMAttributePtr b0;
nsIDOMNodePtr b0;
*rval = JSVAL_NULL;
@ -252,8 +268,8 @@ AttributeListSetAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
NS_ASSERTION(nsnull != supports0, "null pointer");
if ((nsnull == supports0) ||
(NS_OK != supports0->QueryInterface(kIAttributeIID, (void **)(b0.Query())))) {
JS_ReportError(cx, "Parameter must be of type Attribute");
(NS_OK != supports0->QueryInterface(kINodeIID, (void **)(b0.Query())))) {
JS_ReportError(cx, "Parameter must be of type Node");
return JS_FALSE;
}
}
@ -262,14 +278,14 @@ AttributeListSetAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
return JS_FALSE;
}
if (NS_OK != nativeThis->SetAttribute(b0)) {
if (NS_OK != nativeThis->SetNamedItem(b0)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function setAttribute requires 1 parameters");
JS_ReportError(cx, "Function setNamedItem requires 1 parameters");
return JS_FALSE;
}
@ -278,14 +294,14 @@ AttributeListSetAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
//
// Native method Remove
// Native method RemoveNamedItem
//
PR_STATIC_CALLBACK(JSBool)
AttributeListRemove(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
NamedNodeMapRemoveNamedItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMAttributeList *nativeThis = (nsIDOMAttributeList*)JS_GetPrivate(cx, obj);
nsIDOMNamedNodeMap *nativeThis = (nsIDOMNamedNodeMap*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMAttribute* nativeRet;
nsIDOMNode* nativeRet;
nsAutoString b0;
*rval = JSVAL_NULL;
@ -305,7 +321,7 @@ AttributeListRemove(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval
b0.SetString(""); // Should this really be null??
}
if (NS_OK != nativeThis->Remove(b0, &nativeRet)) {
if (NS_OK != nativeThis->RemoveNamedItem(b0, &nativeRet)) {
return JS_FALSE;
}
@ -327,7 +343,7 @@ AttributeListRemove(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval
}
}
else {
JS_ReportError(cx, "Function remove requires 1 parameters");
JS_ReportError(cx, "Function removeNamedItem requires 1 parameters");
return JS_FALSE;
}
@ -339,11 +355,11 @@ AttributeListRemove(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval
// Native method Item
//
PR_STATIC_CALLBACK(JSBool)
AttributeListItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
NamedNodeMapItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMAttributeList *nativeThis = (nsIDOMAttributeList*)JS_GetPrivate(cx, obj);
nsIDOMNamedNodeMap *nativeThis = (nsIDOMNamedNodeMap*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMAttribute* nativeRet;
nsIDOMNode* nativeRet;
PRUint32 b0;
*rval = JSVAL_NULL;
@ -390,95 +406,61 @@ AttributeListItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *
}
//
// Native method GetLength
//
PR_STATIC_CALLBACK(JSBool)
AttributeListGetLength(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMAttributeList *nativeThis = (nsIDOMAttributeList*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
PRUint32 nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->GetLength(&nativeRet)) {
return JS_FALSE;
}
*rval = INT_TO_JSVAL(nativeRet);
}
else {
JS_ReportError(cx, "Function getLength requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
/***********************************************************************/
//
// class for AttributeList
// class for NamedNodeMap
//
JSClass AttributeListClass = {
"AttributeList",
JSClass NamedNodeMapClass = {
"NamedNodeMap",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
GetAttributeListProperty,
SetAttributeListProperty,
EnumerateAttributeList,
ResolveAttributeList,
GetNamedNodeMapProperty,
SetNamedNodeMapProperty,
EnumerateNamedNodeMap,
ResolveNamedNodeMap,
JS_ConvertStub,
FinalizeAttributeList
FinalizeNamedNodeMap
};
//
// AttributeList class properties
// NamedNodeMap class properties
//
static JSPropertySpec AttributeListProperties[] =
static JSPropertySpec NamedNodeMapProperties[] =
{
{"length", NAMEDNODEMAP_LENGTH, JSPROP_ENUMERATE | JSPROP_READONLY},
{0}
};
//
// AttributeList class methods
// NamedNodeMap class methods
//
static JSFunctionSpec AttributeListMethods[] =
static JSFunctionSpec NamedNodeMapMethods[] =
{
{"getAttribute", AttributeListGetAttribute, 1},
{"setAttribute", AttributeListSetAttribute, 1},
{"remove", AttributeListRemove, 1},
{"item", AttributeListItem, 1},
{"getLength", AttributeListGetLength, 0},
{"getNamedItem", NamedNodeMapGetNamedItem, 1},
{"setNamedItem", NamedNodeMapSetNamedItem, 1},
{"removeNamedItem", NamedNodeMapRemoveNamedItem, 1},
{"item", NamedNodeMapItem, 1},
{0}
};
//
// AttributeList constructor
// NamedNodeMap constructor
//
PR_STATIC_CALLBACK(JSBool)
AttributeList(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
NamedNodeMap(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
return JS_TRUE;
}
//
// AttributeList class initialization
// NamedNodeMap class initialization
//
nsresult NS_InitAttributeListClass(nsIScriptContext *aContext, void **aPrototype)
nsresult NS_InitNamedNodeMapClass(nsIScriptContext *aContext, void **aPrototype)
{
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
JSObject *proto = nsnull;
@ -487,7 +469,7 @@ nsresult NS_InitAttributeListClass(nsIScriptContext *aContext, void **aPrototype
JSObject *global = JS_GetGlobalObject(jscontext);
jsval vp;
if ((PR_TRUE != JS_LookupProperty(jscontext, global, "AttributeList", &vp)) ||
if ((PR_TRUE != JS_LookupProperty(jscontext, global, "NamedNodeMap", &vp)) ||
!JSVAL_IS_OBJECT(vp) ||
((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) ||
(PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) ||
@ -496,11 +478,11 @@ nsresult NS_InitAttributeListClass(nsIScriptContext *aContext, void **aPrototype
proto = JS_InitClass(jscontext, // context
global, // global object
parent_proto, // parent proto
&AttributeListClass, // JSClass
AttributeList, // JSNative ctor
&NamedNodeMapClass, // JSClass
NamedNodeMap, // JSNative ctor
0, // ctor args
AttributeListProperties, // proto props
AttributeListMethods, // proto funcs
NamedNodeMapProperties, // proto props
NamedNodeMapMethods, // proto funcs
nsnull, // ctor props (static)
nsnull); // ctor funcs (static)
if (nsnull == proto) {
@ -523,11 +505,11 @@ nsresult NS_InitAttributeListClass(nsIScriptContext *aContext, void **aPrototype
//
// Method for creating a new AttributeList JavaScript object
// Method for creating a new NamedNodeMap JavaScript object
//
extern "C" NS_DOM NS_NewScriptAttributeList(nsIScriptContext *aContext, nsIDOMAttributeList *aSupports, nsISupports *aParent, void **aReturn)
extern "C" NS_DOM nsresult NS_NewScriptNamedNodeMap(nsIScriptContext *aContext, nsIDOMNamedNodeMap *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptAttributeList");
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptNamedNodeMap");
JSObject *proto;
JSObject *parent;
nsIScriptObjectOwner *owner;
@ -547,12 +529,12 @@ extern "C" NS_DOM NS_NewScriptAttributeList(nsIScriptContext *aContext, nsIDOMAt
return NS_ERROR_FAILURE;
}
if (NS_OK != NS_InitAttributeListClass(aContext, (void **)&proto)) {
if (NS_OK != NS_InitNamedNodeMapClass(aContext, (void **)&proto)) {
return NS_ERROR_FAILURE;
}
// create a js object for this class
*aReturn = JS_NewObject(jscontext, &AttributeListClass, proto, parent);
*aReturn = JS_NewObject(jscontext, &NamedNodeMapClass, proto, parent);
if (nsnull != *aReturn) {
// connect the native object to the js object
JS_SetPrivate(jscontext, (JSObject *)*aReturn, aSupports);

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

@ -404,7 +404,7 @@ nsresult NS_InitNavigatorClass(nsIScriptContext *aContext, void **aPrototype)
//
// Method for creating a new Navigator JavaScript object
//
extern "C" NS_DOM NS_NewScriptNavigator(nsIScriptContext *aContext, nsIDOMNavigator *aSupports, nsISupports *aParent, void **aReturn)
extern "C" NS_DOM nsresult NS_NewScriptNavigator(nsIScriptContext *aContext, nsIDOMNavigator *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptNavigator");
JSObject *proto;

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

@ -25,19 +25,38 @@
#include "nsIScriptGlobalObject.h"
#include "nsIPtr.h"
#include "nsString.h"
#include "nsIDOMNodeIterator.h"
#include "nsIDOMNamedNodeMap.h"
#include "nsIDOMNode.h"
#include "nsIDOMNodeList.h"
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
static NS_DEFINE_IID(kINodeIteratorIID, NS_IDOMNODEITERATOR_IID);
static NS_DEFINE_IID(kINamedNodeMapIID, NS_IDOMNAMEDNODEMAP_IID);
static NS_DEFINE_IID(kINodeIID, NS_IDOMNODE_IID);
static NS_DEFINE_IID(kINodeListIID, NS_IDOMNODELIST_IID);
NS_DEF_PTR(nsIDOMNodeIterator);
NS_DEF_PTR(nsIDOMNamedNodeMap);
NS_DEF_PTR(nsIDOMNode);
NS_DEF_PTR(nsIDOMNodeList);
//
// Node property ids
//
enum Node_slots {
NODE_NODENAME = -11,
NODE_NODEVALUE = -12,
NODE_NODETYPE = -13,
NODE_PARENTNODE = -14,
NODE_CHILDNODES = -15,
NODE_HASCHILDNODES = -16,
NODE_FIRSTCHILD = -17,
NODE_LASTCHILD = -18,
NODE_PREVIOUSSIBLING = -19,
NODE_NEXTSIBLING = -110,
NODE_ATTRIBUTES = -111
};
/***********************************************************************/
//
@ -55,7 +74,243 @@ GetNodeProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case 0:
case NODE_NODENAME:
{
nsAutoString prop;
if (NS_OK == a->GetNodeName(prop)) {
JSString *jsstring = JS_NewUCStringCopyN(cx, prop, prop.Length());
// set the return value
*vp = STRING_TO_JSVAL(jsstring);
}
else {
return JS_FALSE;
}
break;
}
case NODE_NODEVALUE:
{
nsAutoString prop;
if (NS_OK == a->GetNodeValue(prop)) {
JSString *jsstring = JS_NewUCStringCopyN(cx, prop, prop.Length());
// set the return value
*vp = STRING_TO_JSVAL(jsstring);
}
else {
return JS_FALSE;
}
break;
}
case NODE_NODETYPE:
{
PRInt32 prop;
if (NS_OK == a->GetNodeType(&prop)) {
*vp = INT_TO_JSVAL(prop);
}
else {
return JS_FALSE;
}
break;
}
case NODE_PARENTNODE:
{
nsIDOMNode* prop;
if (NS_OK == a->GetParentNode(&prop)) {
// get the js object
if (prop != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == prop->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*vp = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(prop);
}
else {
*vp = JSVAL_NULL;
}
}
else {
return JS_FALSE;
}
break;
}
case NODE_CHILDNODES:
{
nsIDOMNodeList* prop;
if (NS_OK == a->GetChildNodes(&prop)) {
// get the js object
if (prop != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == prop->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*vp = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(prop);
}
else {
*vp = JSVAL_NULL;
}
}
else {
return JS_FALSE;
}
break;
}
case NODE_HASCHILDNODES:
{
PRBool prop;
if (NS_OK == a->GetHasChildNodes(&prop)) {
*vp = BOOLEAN_TO_JSVAL(prop);
}
else {
return JS_FALSE;
}
break;
}
case NODE_FIRSTCHILD:
{
nsIDOMNode* prop;
if (NS_OK == a->GetFirstChild(&prop)) {
// get the js object
if (prop != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == prop->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*vp = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(prop);
}
else {
*vp = JSVAL_NULL;
}
}
else {
return JS_FALSE;
}
break;
}
case NODE_LASTCHILD:
{
nsIDOMNode* prop;
if (NS_OK == a->GetLastChild(&prop)) {
// get the js object
if (prop != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == prop->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*vp = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(prop);
}
else {
*vp = JSVAL_NULL;
}
}
else {
return JS_FALSE;
}
break;
}
case NODE_PREVIOUSSIBLING:
{
nsIDOMNode* prop;
if (NS_OK == a->GetPreviousSibling(&prop)) {
// get the js object
if (prop != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == prop->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*vp = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(prop);
}
else {
*vp = JSVAL_NULL;
}
}
else {
return JS_FALSE;
}
break;
}
case NODE_NEXTSIBLING:
{
nsIDOMNode* prop;
if (NS_OK == a->GetNextSibling(&prop)) {
// get the js object
if (prop != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == prop->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*vp = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(prop);
}
else {
*vp = JSVAL_NULL;
}
}
else {
return JS_FALSE;
}
break;
}
case NODE_ATTRIBUTES:
{
nsIDOMNamedNodeMap* prop;
if (NS_OK == a->GetAttributes(&prop)) {
// get the js object
if (prop != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == prop->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*vp = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(prop);
}
else {
*vp = JSVAL_NULL;
}
}
else {
return JS_FALSE;
}
break;
}
default:
{
nsIJSScriptObject *object;
@ -88,7 +343,21 @@ SetNodeProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case 0:
case NODE_NODEVALUE:
{
nsAutoString prop;
JSString *jsstring;
if ((jsstring = JS_ValueToString(cx, *vp)) != nsnull) {
prop.SetString(JS_GetStringChars(jsstring));
}
else {
prop.SetString((const char *)nsnull);
}
a->SetNodeValue(prop);
break;
}
default:
{
nsIJSScriptObject *object;
@ -167,319 +436,6 @@ ResolveNode(JSContext *cx, JSObject *obj, jsval id)
}
//
// Native method GetNodeType
//
PR_STATIC_CALLBACK(JSBool)
NodeGetNodeType(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMNode *nativeThis = (nsIDOMNode*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
PRInt32 nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->GetNodeType(&nativeRet)) {
return JS_FALSE;
}
*rval = INT_TO_JSVAL(nativeRet);
}
else {
JS_ReportError(cx, "Function getNodeType requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method GetParentNode
//
PR_STATIC_CALLBACK(JSBool)
NodeGetParentNode(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMNode *nativeThis = (nsIDOMNode*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMNode* nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->GetParentNode(&nativeRet)) {
return JS_FALSE;
}
if (nativeRet != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*rval = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(nativeRet);
}
else {
*rval = JSVAL_NULL;
}
}
else {
JS_ReportError(cx, "Function getParentNode requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method GetChildNodes
//
PR_STATIC_CALLBACK(JSBool)
NodeGetChildNodes(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMNode *nativeThis = (nsIDOMNode*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMNodeIterator* nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->GetChildNodes(&nativeRet)) {
return JS_FALSE;
}
if (nativeRet != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*rval = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(nativeRet);
}
else {
*rval = JSVAL_NULL;
}
}
else {
JS_ReportError(cx, "Function getChildNodes requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method HasChildNodes
//
PR_STATIC_CALLBACK(JSBool)
NodeHasChildNodes(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMNode *nativeThis = (nsIDOMNode*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
PRBool nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->HasChildNodes(&nativeRet)) {
return JS_FALSE;
}
*rval = BOOLEAN_TO_JSVAL(nativeRet);
}
else {
JS_ReportError(cx, "Function hasChildNodes requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method GetFirstChild
//
PR_STATIC_CALLBACK(JSBool)
NodeGetFirstChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMNode *nativeThis = (nsIDOMNode*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMNode* nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->GetFirstChild(&nativeRet)) {
return JS_FALSE;
}
if (nativeRet != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*rval = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(nativeRet);
}
else {
*rval = JSVAL_NULL;
}
}
else {
JS_ReportError(cx, "Function getFirstChild requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method GetPreviousSibling
//
PR_STATIC_CALLBACK(JSBool)
NodeGetPreviousSibling(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMNode *nativeThis = (nsIDOMNode*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMNode* nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->GetPreviousSibling(&nativeRet)) {
return JS_FALSE;
}
if (nativeRet != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*rval = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(nativeRet);
}
else {
*rval = JSVAL_NULL;
}
}
else {
JS_ReportError(cx, "Function getPreviousSibling requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method GetNextSibling
//
PR_STATIC_CALLBACK(JSBool)
NodeGetNextSibling(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMNode *nativeThis = (nsIDOMNode*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMNode* nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->GetNextSibling(&nativeRet)) {
return JS_FALSE;
}
if (nativeRet != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*rval = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(nativeRet);
}
else {
*rval = JSVAL_NULL;
}
}
else {
JS_ReportError(cx, "Function getNextSibling requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method InsertBefore
//
@ -488,6 +444,7 @@ NodeInsertBefore(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *r
{
nsIDOMNode *nativeThis = (nsIDOMNode*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMNode* nativeRet;
nsIDOMNodePtr b0;
nsIDOMNodePtr b1;
@ -536,11 +493,26 @@ NodeInsertBefore(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *r
return JS_FALSE;
}
if (NS_OK != nativeThis->InsertBefore(b0, b1)) {
if (NS_OK != nativeThis->InsertBefore(b0, b1, &nativeRet)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
if (nativeRet != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*rval = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(nativeRet);
}
else {
*rval = JSVAL_NULL;
}
}
else {
JS_ReportError(cx, "Function insertBefore requires 2 parameters");
@ -559,6 +531,7 @@ NodeReplaceChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *r
{
nsIDOMNode *nativeThis = (nsIDOMNode*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMNode* nativeRet;
nsIDOMNodePtr b0;
nsIDOMNodePtr b1;
@ -607,11 +580,26 @@ NodeReplaceChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *r
return JS_FALSE;
}
if (NS_OK != nativeThis->ReplaceChild(b0, b1)) {
if (NS_OK != nativeThis->ReplaceChild(b0, b1, &nativeRet)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
if (nativeRet != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*rval = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(nativeRet);
}
else {
*rval = JSVAL_NULL;
}
}
else {
JS_ReportError(cx, "Function replaceChild requires 2 parameters");
@ -630,6 +618,7 @@ NodeRemoveChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rv
{
nsIDOMNode *nativeThis = (nsIDOMNode*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMNode* nativeRet;
nsIDOMNodePtr b0;
*rval = JSVAL_NULL;
@ -659,11 +648,26 @@ NodeRemoveChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rv
return JS_FALSE;
}
if (NS_OK != nativeThis->RemoveChild(b0)) {
if (NS_OK != nativeThis->RemoveChild(b0, &nativeRet)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
if (nativeRet != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*rval = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(nativeRet);
}
else {
*rval = JSVAL_NULL;
}
}
else {
JS_ReportError(cx, "Function removeChild requires 1 parameters");
@ -674,6 +678,114 @@ NodeRemoveChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rv
}
//
// Native method CloneNode
//
PR_STATIC_CALLBACK(JSBool)
NodeCloneNode(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMNode *nativeThis = (nsIDOMNode*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMNode* nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->CloneNode(&nativeRet)) {
return JS_FALSE;
}
if (nativeRet != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*rval = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(nativeRet);
}
else {
*rval = JSVAL_NULL;
}
}
else {
JS_ReportError(cx, "Function cloneNode requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method Equals
//
PR_STATIC_CALLBACK(JSBool)
NodeEquals(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMNode *nativeThis = (nsIDOMNode*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
PRBool nativeRet;
nsIDOMNodePtr b0;
PRBool b1;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 2) {
if (JSVAL_IS_NULL(argv[0])){
b0 = nsnull;
}
else if (JSVAL_IS_OBJECT(argv[0])) {
nsISupports *supports0 = (nsISupports *)JS_GetPrivate(cx, JSVAL_TO_OBJECT(argv[0]));
NS_ASSERTION(nsnull != supports0, "null pointer");
if ((nsnull == supports0) ||
(NS_OK != supports0->QueryInterface(kINodeIID, (void **)(b0.Query())))) {
JS_ReportError(cx, "Parameter must be of type Node");
return JS_FALSE;
}
}
else {
JS_ReportError(cx, "Parameter must be an object");
return JS_FALSE;
}
if (!JS_ValueToBoolean(cx, argv[1], &b1)) {
JS_ReportError(cx, "Parameter must be a boolean");
return JS_FALSE;
}
if (NS_OK != nativeThis->Equals(b0, b1, &nativeRet)) {
return JS_FALSE;
}
*rval = BOOLEAN_TO_JSVAL(nativeRet);
}
else {
JS_ReportError(cx, "Function equals requires 2 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
/***********************************************************************/
//
// class for Node
@ -697,6 +809,17 @@ JSClass NodeClass = {
//
static JSPropertySpec NodeProperties[] =
{
{"nodeName", NODE_NODENAME, JSPROP_ENUMERATE | JSPROP_READONLY},
{"nodeValue", NODE_NODEVALUE, JSPROP_ENUMERATE},
{"nodeType", NODE_NODETYPE, JSPROP_ENUMERATE | JSPROP_READONLY},
{"parentNode", NODE_PARENTNODE, JSPROP_ENUMERATE | JSPROP_READONLY},
{"childNodes", NODE_CHILDNODES, JSPROP_ENUMERATE | JSPROP_READONLY},
{"hasChildNodes", NODE_HASCHILDNODES, JSPROP_ENUMERATE | JSPROP_READONLY},
{"firstChild", NODE_FIRSTCHILD, JSPROP_ENUMERATE | JSPROP_READONLY},
{"lastChild", NODE_LASTCHILD, JSPROP_ENUMERATE | JSPROP_READONLY},
{"previousSibling", NODE_PREVIOUSSIBLING, JSPROP_ENUMERATE | JSPROP_READONLY},
{"nextSibling", NODE_NEXTSIBLING, JSPROP_ENUMERATE | JSPROP_READONLY},
{"attributes", NODE_ATTRIBUTES, JSPROP_ENUMERATE | JSPROP_READONLY},
{0}
};
@ -706,16 +829,11 @@ static JSPropertySpec NodeProperties[] =
//
static JSFunctionSpec NodeMethods[] =
{
{"getNodeType", NodeGetNodeType, 0},
{"getParentNode", NodeGetParentNode, 0},
{"getChildNodes", NodeGetChildNodes, 0},
{"hasChildNodes", NodeHasChildNodes, 0},
{"getFirstChild", NodeGetFirstChild, 0},
{"getPreviousSibling", NodeGetPreviousSibling, 0},
{"getNextSibling", NodeGetNextSibling, 0},
{"insertBefore", NodeInsertBefore, 2},
{"replaceChild", NodeReplaceChild, 2},
{"removeChild", NodeRemoveChild, 1},
{"cloneNode", NodeCloneNode, 0},
{"equals", NodeEquals, 2},
{0}
};
@ -774,8 +892,8 @@ nsresult NS_InitNodeClass(nsIScriptContext *aContext, void **aPrototype)
vp = INT_TO_JSVAL(nsIDOMNode::ATTRIBUTE);
JS_SetProperty(jscontext, constructor, "ATTRIBUTE", &vp);
vp = INT_TO_JSVAL(nsIDOMNode::PI);
JS_SetProperty(jscontext, constructor, "PI", &vp);
vp = INT_TO_JSVAL(nsIDOMNode::PROCESSING_INSTRUCTION);
JS_SetProperty(jscontext, constructor, "PROCESSING_INSTRUCTION", &vp);
vp = INT_TO_JSVAL(nsIDOMNode::COMMENT);
JS_SetProperty(jscontext, constructor, "COMMENT", &vp);
@ -783,6 +901,18 @@ nsresult NS_InitNodeClass(nsIScriptContext *aContext, void **aPrototype)
vp = INT_TO_JSVAL(nsIDOMNode::TEXT);
JS_SetProperty(jscontext, constructor, "TEXT", &vp);
vp = INT_TO_JSVAL(nsIDOMNode::CDATA_SECTION);
JS_SetProperty(jscontext, constructor, "CDATA_SECTION", &vp);
vp = INT_TO_JSVAL(nsIDOMNode::DOCUMENT_FRAGMENT);
JS_SetProperty(jscontext, constructor, "DOCUMENT_FRAGMENT", &vp);
vp = INT_TO_JSVAL(nsIDOMNode::ENTITY_DECLARATION);
JS_SetProperty(jscontext, constructor, "ENTITY_DECLARATION", &vp);
vp = INT_TO_JSVAL(nsIDOMNode::ENTITY_REFERENCE);
JS_SetProperty(jscontext, constructor, "ENTITY_REFERENCE", &vp);
}
}
@ -803,7 +933,7 @@ nsresult NS_InitNodeClass(nsIScriptContext *aContext, void **aPrototype)
//
// Method for creating a new Node JavaScript object
//
extern "C" NS_DOM NS_NewScriptNode(nsIScriptContext *aContext, nsIDOMNode *aSupports, nsISupports *aParent, void **aReturn)
extern "C" NS_DOM nsresult NS_NewScriptNode(nsIScriptContext *aContext, nsIDOMNode *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptNode");
JSObject *proto;

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

@ -1,645 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#include "jsapi.h"
#include "nscore.h"
#include "nsIScriptContext.h"
#include "nsIJSScriptObject.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsIPtr.h"
#include "nsString.h"
#include "nsIDOMNodeIterator.h"
#include "nsIDOMNode.h"
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
static NS_DEFINE_IID(kINodeIteratorIID, NS_IDOMNODEITERATOR_IID);
static NS_DEFINE_IID(kINodeIID, NS_IDOMNODE_IID);
NS_DEF_PTR(nsIDOMNodeIterator);
NS_DEF_PTR(nsIDOMNode);
/***********************************************************************/
//
// NodeIterator Properties Getter
//
PR_STATIC_CALLBACK(JSBool)
GetNodeIteratorProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMNodeIterator *a = (nsIDOMNodeIterator*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case 0:
default:
{
nsIJSScriptObject *object;
if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {
PRBool rval;
rval = object->GetProperty(cx, id, vp);
NS_RELEASE(object);
return rval;
}
}
}
}
return PR_TRUE;
}
/***********************************************************************/
//
// NodeIterator Properties Setter
//
PR_STATIC_CALLBACK(JSBool)
SetNodeIteratorProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMNodeIterator *a = (nsIDOMNodeIterator*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case 0:
default:
{
nsIJSScriptObject *object;
if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {
PRBool rval;
rval = object->SetProperty(cx, id, vp);
NS_RELEASE(object);
return rval;
}
}
}
}
return PR_TRUE;
}
//
// NodeIterator finalizer
//
PR_STATIC_CALLBACK(void)
FinalizeNodeIterator(JSContext *cx, JSObject *obj)
{
nsIDOMNodeIterator *a = (nsIDOMNodeIterator*)JS_GetPrivate(cx, obj);
if (nsnull != a) {
// get the js object
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == a->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
owner->ResetScriptObject();
NS_RELEASE(owner);
}
NS_RELEASE(a);
}
}
//
// NodeIterator enumerate
//
PR_STATIC_CALLBACK(JSBool)
EnumerateNodeIterator(JSContext *cx, JSObject *obj)
{
nsIDOMNodeIterator *a = (nsIDOMNodeIterator*)JS_GetPrivate(cx, obj);
if (nsnull != a) {
// get the js object
nsIJSScriptObject *object;
if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {
object->EnumerateProperty(cx);
NS_RELEASE(object);
}
}
return JS_TRUE;
}
//
// NodeIterator resolve
//
PR_STATIC_CALLBACK(JSBool)
ResolveNodeIterator(JSContext *cx, JSObject *obj, jsval id)
{
nsIDOMNodeIterator *a = (nsIDOMNodeIterator*)JS_GetPrivate(cx, obj);
if (nsnull != a) {
// get the js object
nsIJSScriptObject *object;
if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {
object->Resolve(cx, id);
NS_RELEASE(object);
}
}
return JS_TRUE;
}
//
// Native method GetLength
//
PR_STATIC_CALLBACK(JSBool)
NodeIteratorGetLength(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMNodeIterator *nativeThis = (nsIDOMNodeIterator*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
PRUint32 nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->GetLength(&nativeRet)) {
return JS_FALSE;
}
*rval = INT_TO_JSVAL(nativeRet);
}
else {
JS_ReportError(cx, "Function getLength requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method GetCurrentNode
//
PR_STATIC_CALLBACK(JSBool)
NodeIteratorGetCurrentNode(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMNodeIterator *nativeThis = (nsIDOMNodeIterator*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMNode* nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->GetCurrentNode(&nativeRet)) {
return JS_FALSE;
}
if (nativeRet != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*rval = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(nativeRet);
}
else {
*rval = JSVAL_NULL;
}
}
else {
JS_ReportError(cx, "Function getCurrentNode requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method GetNextNode
//
PR_STATIC_CALLBACK(JSBool)
NodeIteratorGetNextNode(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMNodeIterator *nativeThis = (nsIDOMNodeIterator*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMNode* nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->GetNextNode(&nativeRet)) {
return JS_FALSE;
}
if (nativeRet != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*rval = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(nativeRet);
}
else {
*rval = JSVAL_NULL;
}
}
else {
JS_ReportError(cx, "Function getNextNode requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method GetPreviousNode
//
PR_STATIC_CALLBACK(JSBool)
NodeIteratorGetPreviousNode(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMNodeIterator *nativeThis = (nsIDOMNodeIterator*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMNode* nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->GetPreviousNode(&nativeRet)) {
return JS_FALSE;
}
if (nativeRet != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*rval = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(nativeRet);
}
else {
*rval = JSVAL_NULL;
}
}
else {
JS_ReportError(cx, "Function getPreviousNode requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method ToFirst
//
PR_STATIC_CALLBACK(JSBool)
NodeIteratorToFirst(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMNodeIterator *nativeThis = (nsIDOMNodeIterator*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMNode* nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->ToFirst(&nativeRet)) {
return JS_FALSE;
}
if (nativeRet != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*rval = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(nativeRet);
}
else {
*rval = JSVAL_NULL;
}
}
else {
JS_ReportError(cx, "Function toFirst requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method ToLast
//
PR_STATIC_CALLBACK(JSBool)
NodeIteratorToLast(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMNodeIterator *nativeThis = (nsIDOMNodeIterator*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMNode* nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->ToLast(&nativeRet)) {
return JS_FALSE;
}
if (nativeRet != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*rval = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(nativeRet);
}
else {
*rval = JSVAL_NULL;
}
}
else {
JS_ReportError(cx, "Function toLast requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method MoveTo
//
PR_STATIC_CALLBACK(JSBool)
NodeIteratorMoveTo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMNodeIterator *nativeThis = (nsIDOMNodeIterator*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMNode* nativeRet;
PRInt32 b0;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 1) {
if (!JS_ValueToInt32(cx, argv[0], (int32 *)&b0)) {
JS_ReportError(cx, "Parameter must be a number");
return JS_FALSE;
}
if (NS_OK != nativeThis->MoveTo(b0, &nativeRet)) {
return JS_FALSE;
}
if (nativeRet != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*rval = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(nativeRet);
}
else {
*rval = JSVAL_NULL;
}
}
else {
JS_ReportError(cx, "Function moveTo requires 1 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
/***********************************************************************/
//
// class for NodeIterator
//
JSClass NodeIteratorClass = {
"NodeIterator",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
GetNodeIteratorProperty,
SetNodeIteratorProperty,
EnumerateNodeIterator,
ResolveNodeIterator,
JS_ConvertStub,
FinalizeNodeIterator
};
//
// NodeIterator class properties
//
static JSPropertySpec NodeIteratorProperties[] =
{
{0}
};
//
// NodeIterator class methods
//
static JSFunctionSpec NodeIteratorMethods[] =
{
{"getLength", NodeIteratorGetLength, 0},
{"getCurrentNode", NodeIteratorGetCurrentNode, 0},
{"getNextNode", NodeIteratorGetNextNode, 0},
{"getPreviousNode", NodeIteratorGetPreviousNode, 0},
{"toFirst", NodeIteratorToFirst, 0},
{"toLast", NodeIteratorToLast, 0},
{"moveTo", NodeIteratorMoveTo, 1},
{0}
};
//
// NodeIterator constructor
//
PR_STATIC_CALLBACK(JSBool)
NodeIterator(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
return JS_TRUE;
}
//
// NodeIterator class initialization
//
nsresult NS_InitNodeIteratorClass(nsIScriptContext *aContext, void **aPrototype)
{
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
JSObject *proto = nsnull;
JSObject *constructor = nsnull;
JSObject *parent_proto = nsnull;
JSObject *global = JS_GetGlobalObject(jscontext);
jsval vp;
if ((PR_TRUE != JS_LookupProperty(jscontext, global, "NodeIterator", &vp)) ||
!JSVAL_IS_OBJECT(vp) ||
((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) ||
(PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) ||
!JSVAL_IS_OBJECT(vp)) {
proto = JS_InitClass(jscontext, // context
global, // global object
parent_proto, // parent proto
&NodeIteratorClass, // JSClass
NodeIterator, // JSNative ctor
0, // ctor args
NodeIteratorProperties, // proto props
NodeIteratorMethods, // proto funcs
nsnull, // ctor props (static)
nsnull); // ctor funcs (static)
if (nsnull == proto) {
return NS_ERROR_FAILURE;
}
}
else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) {
proto = JSVAL_TO_OBJECT(vp);
}
else {
return NS_ERROR_FAILURE;
}
if (aPrototype) {
*aPrototype = proto;
}
return NS_OK;
}
//
// Method for creating a new NodeIterator JavaScript object
//
extern "C" NS_DOM NS_NewScriptNodeIterator(nsIScriptContext *aContext, nsIDOMNodeIterator *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptNodeIterator");
JSObject *proto;
JSObject *parent;
nsIScriptObjectOwner *owner;
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
if (nsnull == aParent) {
parent = nsnull;
}
else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) {
NS_RELEASE(owner);
return NS_ERROR_FAILURE;
}
NS_RELEASE(owner);
}
else {
return NS_ERROR_FAILURE;
}
if (NS_OK != NS_InitNodeIteratorClass(aContext, (void **)&proto)) {
return NS_ERROR_FAILURE;
}
// create a js object for this class
*aReturn = JS_NewObject(jscontext, &NodeIteratorClass, proto, parent);
if (nsnull != *aReturn) {
// connect the native object to the js object
JS_SetPrivate(jscontext, (JSObject *)*aReturn, aSupports);
NS_ADDREF(aSupports);
}
else {
return NS_ERROR_FAILURE;
}
return NS_OK;
}

377
dom/src/nsJSNodeList.cpp Normal file
Просмотреть файл

@ -0,0 +1,377 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#include "jsapi.h"
#include "nscore.h"
#include "nsIScriptContext.h"
#include "nsIJSScriptObject.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsIPtr.h"
#include "nsString.h"
#include "nsIDOMNode.h"
#include "nsIDOMNodeList.h"
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
static NS_DEFINE_IID(kINodeIID, NS_IDOMNODE_IID);
static NS_DEFINE_IID(kINodeListIID, NS_IDOMNODELIST_IID);
NS_DEF_PTR(nsIDOMNode);
NS_DEF_PTR(nsIDOMNodeList);
//
// NodeList property ids
//
enum NodeList_slots {
NODELIST_LENGTH = -11
};
/***********************************************************************/
//
// NodeList Properties Getter
//
PR_STATIC_CALLBACK(JSBool)
GetNodeListProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMNodeList *a = (nsIDOMNodeList*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case NODELIST_LENGTH:
{
PRUint32 prop;
if (NS_OK == a->GetLength(&prop)) {
*vp = INT_TO_JSVAL(prop);
}
else {
return JS_FALSE;
}
break;
}
default:
{
nsIJSScriptObject *object;
if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {
PRBool rval;
rval = object->GetProperty(cx, id, vp);
NS_RELEASE(object);
return rval;
}
}
}
}
return PR_TRUE;
}
/***********************************************************************/
//
// NodeList Properties Setter
//
PR_STATIC_CALLBACK(JSBool)
SetNodeListProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMNodeList *a = (nsIDOMNodeList*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case 0:
default:
{
nsIJSScriptObject *object;
if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {
PRBool rval;
rval = object->SetProperty(cx, id, vp);
NS_RELEASE(object);
return rval;
}
}
}
}
return PR_TRUE;
}
//
// NodeList finalizer
//
PR_STATIC_CALLBACK(void)
FinalizeNodeList(JSContext *cx, JSObject *obj)
{
nsIDOMNodeList *a = (nsIDOMNodeList*)JS_GetPrivate(cx, obj);
if (nsnull != a) {
// get the js object
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == a->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
owner->ResetScriptObject();
NS_RELEASE(owner);
}
NS_RELEASE(a);
}
}
//
// NodeList enumerate
//
PR_STATIC_CALLBACK(JSBool)
EnumerateNodeList(JSContext *cx, JSObject *obj)
{
nsIDOMNodeList *a = (nsIDOMNodeList*)JS_GetPrivate(cx, obj);
if (nsnull != a) {
// get the js object
nsIJSScriptObject *object;
if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {
object->EnumerateProperty(cx);
NS_RELEASE(object);
}
}
return JS_TRUE;
}
//
// NodeList resolve
//
PR_STATIC_CALLBACK(JSBool)
ResolveNodeList(JSContext *cx, JSObject *obj, jsval id)
{
nsIDOMNodeList *a = (nsIDOMNodeList*)JS_GetPrivate(cx, obj);
if (nsnull != a) {
// get the js object
nsIJSScriptObject *object;
if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {
object->Resolve(cx, id);
NS_RELEASE(object);
}
}
return JS_TRUE;
}
//
// Native method Item
//
PR_STATIC_CALLBACK(JSBool)
NodeListItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMNodeList *nativeThis = (nsIDOMNodeList*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMNode* nativeRet;
PRUint32 b0;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 1) {
if (!JS_ValueToInt32(cx, argv[0], (int32 *)&b0)) {
JS_ReportError(cx, "Parameter must be a number");
return JS_FALSE;
}
if (NS_OK != nativeThis->Item(b0, &nativeRet)) {
return JS_FALSE;
}
if (nativeRet != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*rval = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(nativeRet);
}
else {
*rval = JSVAL_NULL;
}
}
else {
JS_ReportError(cx, "Function item requires 1 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
/***********************************************************************/
//
// class for NodeList
//
JSClass NodeListClass = {
"NodeList",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
GetNodeListProperty,
SetNodeListProperty,
EnumerateNodeList,
ResolveNodeList,
JS_ConvertStub,
FinalizeNodeList
};
//
// NodeList class properties
//
static JSPropertySpec NodeListProperties[] =
{
{"length", NODELIST_LENGTH, JSPROP_ENUMERATE | JSPROP_READONLY},
{0}
};
//
// NodeList class methods
//
static JSFunctionSpec NodeListMethods[] =
{
{"item", NodeListItem, 1},
{0}
};
//
// NodeList constructor
//
PR_STATIC_CALLBACK(JSBool)
NodeList(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
return JS_TRUE;
}
//
// NodeList class initialization
//
nsresult NS_InitNodeListClass(nsIScriptContext *aContext, void **aPrototype)
{
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
JSObject *proto = nsnull;
JSObject *constructor = nsnull;
JSObject *parent_proto = nsnull;
JSObject *global = JS_GetGlobalObject(jscontext);
jsval vp;
if ((PR_TRUE != JS_LookupProperty(jscontext, global, "NodeList", &vp)) ||
!JSVAL_IS_OBJECT(vp) ||
((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) ||
(PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) ||
!JSVAL_IS_OBJECT(vp)) {
proto = JS_InitClass(jscontext, // context
global, // global object
parent_proto, // parent proto
&NodeListClass, // JSClass
NodeList, // JSNative ctor
0, // ctor args
NodeListProperties, // proto props
NodeListMethods, // proto funcs
nsnull, // ctor props (static)
nsnull); // ctor funcs (static)
if (nsnull == proto) {
return NS_ERROR_FAILURE;
}
}
else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) {
proto = JSVAL_TO_OBJECT(vp);
}
else {
return NS_ERROR_FAILURE;
}
if (aPrototype) {
*aPrototype = proto;
}
return NS_OK;
}
//
// Method for creating a new NodeList JavaScript object
//
extern "C" NS_DOM nsresult NS_NewScriptNodeList(nsIScriptContext *aContext, nsIDOMNodeList *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptNodeList");
JSObject *proto;
JSObject *parent;
nsIScriptObjectOwner *owner;
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
if (nsnull == aParent) {
parent = nsnull;
}
else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) {
NS_RELEASE(owner);
return NS_ERROR_FAILURE;
}
NS_RELEASE(owner);
}
else {
return NS_ERROR_FAILURE;
}
if (NS_OK != NS_InitNodeListClass(aContext, (void **)&proto)) {
return NS_ERROR_FAILURE;
}
// create a js object for this class
*aReturn = JS_NewObject(jscontext, &NodeListClass, proto, parent);
if (nsnull != *aReturn) {
// connect the native object to the js object
JS_SetPrivate(jscontext, (JSObject *)*aReturn, aSupports);
NS_ADDREF(aSupports);
}
else {
return NS_ERROR_FAILURE;
}
return NS_OK;
}

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

@ -25,32 +25,32 @@
#include "nsIScriptGlobalObject.h"
#include "nsIPtr.h"
#include "nsString.h"
#include "nsIDOMPI.h"
#include "nsIDOMProcessingInstruction.h"
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
static NS_DEFINE_IID(kIPIIID, NS_IDOMPI_IID);
static NS_DEFINE_IID(kIProcessingInstructionIID, NS_IDOMPROCESSINGINSTRUCTION_IID);
NS_DEF_PTR(nsIDOMPI);
NS_DEF_PTR(nsIDOMProcessingInstruction);
//
// PI property ids
// ProcessingInstruction property ids
//
enum PI_slots {
PI_NAME = -11,
PI_DATA = -12
enum ProcessingInstruction_slots {
PROCESSINGINSTRUCTION_TARGET = -11,
PROCESSINGINSTRUCTION_DATA = -12
};
/***********************************************************************/
//
// PI Properties Getter
// ProcessingInstruction Properties Getter
//
PR_STATIC_CALLBACK(JSBool)
GetPIProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
GetProcessingInstructionProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMPI *a = (nsIDOMPI*)JS_GetPrivate(cx, obj);
nsIDOMProcessingInstruction *a = (nsIDOMProcessingInstruction*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
@ -59,10 +59,10 @@ GetPIProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case PI_NAME:
case PROCESSINGINSTRUCTION_TARGET:
{
nsAutoString prop;
if (NS_OK == a->GetName(prop)) {
if (NS_OK == a->GetTarget(prop)) {
JSString *jsstring = JS_NewUCStringCopyN(cx, prop, prop.Length());
// set the return value
*vp = STRING_TO_JSVAL(jsstring);
@ -72,7 +72,7 @@ GetPIProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
}
break;
}
case PI_DATA:
case PROCESSINGINSTRUCTION_DATA:
{
nsAutoString prop;
if (NS_OK == a->GetData(prop)) {
@ -103,12 +103,12 @@ GetPIProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
/***********************************************************************/
//
// PI Properties Setter
// ProcessingInstruction Properties Setter
//
PR_STATIC_CALLBACK(JSBool)
SetPIProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
SetProcessingInstructionProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMPI *a = (nsIDOMPI*)JS_GetPrivate(cx, obj);
nsIDOMProcessingInstruction *a = (nsIDOMProcessingInstruction*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
@ -117,7 +117,7 @@ SetPIProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case PI_NAME:
case PROCESSINGINSTRUCTION_TARGET:
{
nsAutoString prop;
JSString *jsstring;
@ -128,11 +128,11 @@ SetPIProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
prop.SetString((const char *)nsnull);
}
a->SetName(prop);
a->SetTarget(prop);
break;
}
case PI_DATA:
case PROCESSINGINSTRUCTION_DATA:
{
nsAutoString prop;
JSString *jsstring;
@ -165,12 +165,12 @@ SetPIProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
//
// PI finalizer
// ProcessingInstruction finalizer
//
PR_STATIC_CALLBACK(void)
FinalizePI(JSContext *cx, JSObject *obj)
FinalizeProcessingInstruction(JSContext *cx, JSObject *obj)
{
nsIDOMPI *a = (nsIDOMPI*)JS_GetPrivate(cx, obj);
nsIDOMProcessingInstruction *a = (nsIDOMProcessingInstruction*)JS_GetPrivate(cx, obj);
if (nsnull != a) {
// get the js object
@ -186,12 +186,12 @@ FinalizePI(JSContext *cx, JSObject *obj)
//
// PI enumerate
// ProcessingInstruction enumerate
//
PR_STATIC_CALLBACK(JSBool)
EnumeratePI(JSContext *cx, JSObject *obj)
EnumerateProcessingInstruction(JSContext *cx, JSObject *obj)
{
nsIDOMPI *a = (nsIDOMPI*)JS_GetPrivate(cx, obj);
nsIDOMProcessingInstruction *a = (nsIDOMProcessingInstruction*)JS_GetPrivate(cx, obj);
if (nsnull != a) {
// get the js object
@ -206,12 +206,12 @@ EnumeratePI(JSContext *cx, JSObject *obj)
//
// PI resolve
// ProcessingInstruction resolve
//
PR_STATIC_CALLBACK(JSBool)
ResolvePI(JSContext *cx, JSObject *obj, jsval id)
ResolveProcessingInstruction(JSContext *cx, JSObject *obj, jsval id)
{
nsIDOMPI *a = (nsIDOMPI*)JS_GetPrivate(cx, obj);
nsIDOMProcessingInstruction *a = (nsIDOMProcessingInstruction*)JS_GetPrivate(cx, obj);
if (nsnull != a) {
// get the js object
@ -227,56 +227,56 @@ ResolvePI(JSContext *cx, JSObject *obj, jsval id)
/***********************************************************************/
//
// class for PI
// class for ProcessingInstruction
//
JSClass PIClass = {
"PI",
JSClass ProcessingInstructionClass = {
"ProcessingInstruction",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
GetPIProperty,
SetPIProperty,
EnumeratePI,
ResolvePI,
GetProcessingInstructionProperty,
SetProcessingInstructionProperty,
EnumerateProcessingInstruction,
ResolveProcessingInstruction,
JS_ConvertStub,
FinalizePI
FinalizeProcessingInstruction
};
//
// PI class properties
// ProcessingInstruction class properties
//
static JSPropertySpec PIProperties[] =
static JSPropertySpec ProcessingInstructionProperties[] =
{
{"name", PI_NAME, JSPROP_ENUMERATE},
{"data", PI_DATA, JSPROP_ENUMERATE},
{"target", PROCESSINGINSTRUCTION_TARGET, JSPROP_ENUMERATE},
{"data", PROCESSINGINSTRUCTION_DATA, JSPROP_ENUMERATE},
{0}
};
//
// PI class methods
// ProcessingInstruction class methods
//
static JSFunctionSpec PIMethods[] =
static JSFunctionSpec ProcessingInstructionMethods[] =
{
{0}
};
//
// PI constructor
// ProcessingInstruction constructor
//
PR_STATIC_CALLBACK(JSBool)
PI(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
ProcessingInstruction(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
return JS_TRUE;
}
//
// PI class initialization
// ProcessingInstruction class initialization
//
nsresult NS_InitPIClass(nsIScriptContext *aContext, void **aPrototype)
nsresult NS_InitProcessingInstructionClass(nsIScriptContext *aContext, void **aPrototype)
{
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
JSObject *proto = nsnull;
@ -285,7 +285,7 @@ nsresult NS_InitPIClass(nsIScriptContext *aContext, void **aPrototype)
JSObject *global = JS_GetGlobalObject(jscontext);
jsval vp;
if ((PR_TRUE != JS_LookupProperty(jscontext, global, "PI", &vp)) ||
if ((PR_TRUE != JS_LookupProperty(jscontext, global, "ProcessingInstruction", &vp)) ||
!JSVAL_IS_OBJECT(vp) ||
((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) ||
(PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) ||
@ -297,11 +297,11 @@ nsresult NS_InitPIClass(nsIScriptContext *aContext, void **aPrototype)
proto = JS_InitClass(jscontext, // context
global, // global object
parent_proto, // parent proto
&PIClass, // JSClass
PI, // JSNative ctor
&ProcessingInstructionClass, // JSClass
ProcessingInstruction, // JSNative ctor
0, // ctor args
PIProperties, // proto props
PIMethods, // proto funcs
ProcessingInstructionProperties, // proto props
ProcessingInstructionMethods, // proto funcs
nsnull, // ctor props (static)
nsnull); // ctor funcs (static)
if (nsnull == proto) {
@ -324,11 +324,11 @@ nsresult NS_InitPIClass(nsIScriptContext *aContext, void **aPrototype)
//
// Method for creating a new PI JavaScript object
// Method for creating a new ProcessingInstruction JavaScript object
//
extern "C" NS_DOM NS_NewScriptPI(nsIScriptContext *aContext, nsIDOMPI *aSupports, nsISupports *aParent, void **aReturn)
extern "C" NS_DOM nsresult NS_NewScriptProcessingInstruction(nsIScriptContext *aContext, nsIDOMProcessingInstruction *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptPI");
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptProcessingInstruction");
JSObject *proto;
JSObject *parent;
nsIScriptObjectOwner *owner;
@ -348,12 +348,12 @@ extern "C" NS_DOM NS_NewScriptPI(nsIScriptContext *aContext, nsIDOMPI *aSupports
return NS_ERROR_FAILURE;
}
if (NS_OK != NS_InitPIClass(aContext, (void **)&proto)) {
if (NS_OK != NS_InitProcessingInstructionClass(aContext, (void **)&proto)) {
return NS_ERROR_FAILURE;
}
// create a js object for this class
*aReturn = JS_NewObject(jscontext, &PIClass, proto, parent);
*aReturn = JS_NewObject(jscontext, &ProcessingInstructionClass, proto, parent);
if (nsnull != *aReturn) {
// connect the native object to the js object
JS_SetPrivate(jscontext, (JSObject *)*aReturn, aSupports);

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

@ -25,25 +25,16 @@
#include "nsIScriptGlobalObject.h"
#include "nsIPtr.h"
#include "nsString.h"
#include "nsIDOMElement.h"
#include "nsIDOMText.h"
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
static NS_DEFINE_IID(kIElementIID, NS_IDOMELEMENT_IID);
static NS_DEFINE_IID(kITextIID, NS_IDOMTEXT_IID);
NS_DEF_PTR(nsIDOMElement);
NS_DEF_PTR(nsIDOMText);
//
// Text property ids
//
enum Text_slots {
TEXT_DATA = -11
};
/***********************************************************************/
//
@ -61,19 +52,7 @@ GetTextProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case TEXT_DATA:
{
nsAutoString prop;
if (NS_OK == a->GetData(prop)) {
JSString *jsstring = JS_NewUCStringCopyN(cx, prop, prop.Length());
// set the return value
*vp = STRING_TO_JSVAL(jsstring);
}
else {
return JS_FALSE;
}
break;
}
case 0:
default:
{
nsIJSScriptObject *object;
@ -106,21 +85,7 @@ SetTextProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case TEXT_DATA:
{
nsAutoString prop;
JSString *jsstring;
if ((jsstring = JS_ValueToString(cx, *vp)) != nsnull) {
prop.SetString(JS_GetStringChars(jsstring));
}
else {
prop.SetString((const char *)nsnull);
}
a->SetData(prop);
break;
}
case 0:
default:
{
nsIJSScriptObject *object;
@ -200,14 +165,15 @@ ResolveText(JSContext *cx, JSObject *obj, jsval id)
//
// Native method Append
// Native method SplitText
//
PR_STATIC_CALLBACK(JSBool)
TextAppend(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
TextSplitText(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMText *nativeThis = (nsIDOMText*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsAutoString b0;
nsIDOMText* nativeRet;
PRUint32 b0;
*rval = JSVAL_NULL;
@ -218,22 +184,34 @@ TextAppend(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
if (argc >= 1) {
JSString *jsstring0 = JS_ValueToString(cx, argv[0]);
if (nsnull != jsstring0) {
b0.SetString(JS_GetStringChars(jsstring0));
}
else {
b0.SetString(""); // Should this really be null??
}
if (NS_OK != nativeThis->Append(b0)) {
if (!JS_ValueToInt32(cx, argv[0], (int32 *)&b0)) {
JS_ReportError(cx, "Parameter must be a number");
return JS_FALSE;
}
*rval = JSVAL_VOID;
if (NS_OK != nativeThis->SplitText(b0, &nativeRet)) {
return JS_FALSE;
}
if (nativeRet != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*rval = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(nativeRet);
}
else {
*rval = JSVAL_NULL;
}
}
else {
JS_ReportError(cx, "Function append requires 1 parameters");
JS_ReportError(cx, "Function splitText requires 1 parameters");
return JS_FALSE;
}
@ -242,15 +220,16 @@ TextAppend(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
//
// Native method Insert
// Native method JoinText
//
PR_STATIC_CALLBACK(JSBool)
TextInsert(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
TextJoinText(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMText *nativeThis = (nsIDOMText*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
PRInt32 b0;
nsAutoString b1;
nsIDOMText* nativeRet;
nsIDOMTextPtr b0;
nsIDOMTextPtr b1;
*rval = JSVAL_NULL;
@ -261,154 +240,6 @@ TextInsert(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
if (argc >= 2) {
if (!JS_ValueToInt32(cx, argv[0], (int32 *)&b0)) {
JS_ReportError(cx, "Parameter must be a number");
return JS_FALSE;
}
JSString *jsstring1 = JS_ValueToString(cx, argv[1]);
if (nsnull != jsstring1) {
b1.SetString(JS_GetStringChars(jsstring1));
}
else {
b1.SetString(""); // Should this really be null??
}
if (NS_OK != nativeThis->Insert(b0, b1)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function insert requires 2 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method Delete
//
PR_STATIC_CALLBACK(JSBool)
TextDelete(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMText *nativeThis = (nsIDOMText*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
PRInt32 b0;
PRInt32 b1;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 2) {
if (!JS_ValueToInt32(cx, argv[0], (int32 *)&b0)) {
JS_ReportError(cx, "Parameter must be a number");
return JS_FALSE;
}
if (!JS_ValueToInt32(cx, argv[1], (int32 *)&b1)) {
JS_ReportError(cx, "Parameter must be a number");
return JS_FALSE;
}
if (NS_OK != nativeThis->Delete(b0, b1)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function delete requires 2 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method Replace
//
PR_STATIC_CALLBACK(JSBool)
TextReplace(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMText *nativeThis = (nsIDOMText*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
PRInt32 b0;
PRInt32 b1;
nsAutoString b2;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 3) {
if (!JS_ValueToInt32(cx, argv[0], (int32 *)&b0)) {
JS_ReportError(cx, "Parameter must be a number");
return JS_FALSE;
}
if (!JS_ValueToInt32(cx, argv[1], (int32 *)&b1)) {
JS_ReportError(cx, "Parameter must be a number");
return JS_FALSE;
}
JSString *jsstring2 = JS_ValueToString(cx, argv[2]);
if (nsnull != jsstring2) {
b2.SetString(JS_GetStringChars(jsstring2));
}
else {
b2.SetString(""); // Should this really be null??
}
if (NS_OK != nativeThis->Replace(b0, b1, b2)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function replace requires 3 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method Splice
//
PR_STATIC_CALLBACK(JSBool)
TextSplice(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMText *nativeThis = (nsIDOMText*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMElementPtr b0;
PRInt32 b1;
PRInt32 b2;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 3) {
if (JSVAL_IS_NULL(argv[0])){
b0 = nsnull;
}
@ -417,8 +248,8 @@ TextSplice(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
NS_ASSERTION(nsnull != supports0, "null pointer");
if ((nsnull == supports0) ||
(NS_OK != supports0->QueryInterface(kIElementIID, (void **)(b0.Query())))) {
JS_ReportError(cx, "Parameter must be of type Element");
(NS_OK != supports0->QueryInterface(kITextIID, (void **)(b0.Query())))) {
JS_ReportError(cx, "Parameter must be of type Text");
return JS_FALSE;
}
}
@ -427,24 +258,47 @@ TextSplice(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
return JS_FALSE;
}
if (!JS_ValueToInt32(cx, argv[1], (int32 *)&b1)) {
JS_ReportError(cx, "Parameter must be a number");
if (JSVAL_IS_NULL(argv[1])){
b1 = nsnull;
}
else if (JSVAL_IS_OBJECT(argv[1])) {
nsISupports *supports1 = (nsISupports *)JS_GetPrivate(cx, JSVAL_TO_OBJECT(argv[1]));
NS_ASSERTION(nsnull != supports1, "null pointer");
if ((nsnull == supports1) ||
(NS_OK != supports1->QueryInterface(kITextIID, (void **)(b1.Query())))) {
JS_ReportError(cx, "Parameter must be of type Text");
return JS_FALSE;
}
}
else {
JS_ReportError(cx, "Parameter must be an object");
return JS_FALSE;
}
if (!JS_ValueToInt32(cx, argv[2], (int32 *)&b2)) {
JS_ReportError(cx, "Parameter must be a number");
if (NS_OK != nativeThis->JoinText(b0, b1, &nativeRet)) {
return JS_FALSE;
}
if (NS_OK != nativeThis->Splice(b0, b1, b2)) {
return JS_FALSE;
if (nativeRet != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*rval = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(nativeRet);
}
else {
*rval = JSVAL_NULL;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function splice requires 3 parameters");
JS_ReportError(cx, "Function joinText requires 2 parameters");
return JS_FALSE;
}
@ -475,7 +329,6 @@ JSClass TextClass = {
//
static JSPropertySpec TextProperties[] =
{
{"data", TEXT_DATA, JSPROP_ENUMERATE},
{0}
};
@ -485,11 +338,8 @@ static JSPropertySpec TextProperties[] =
//
static JSFunctionSpec TextMethods[] =
{
{"append", TextAppend, 1},
{"insert", TextInsert, 2},
{"delete", TextDelete, 2},
{"replace", TextReplace, 3},
{"splice", TextSplice, 3},
{"splitText", TextSplitText, 1},
{"joinText", TextJoinText, 2},
{0}
};
@ -522,7 +372,7 @@ nsresult NS_InitTextClass(nsIScriptContext *aContext, void **aPrototype)
(PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) ||
!JSVAL_IS_OBJECT(vp)) {
if (NS_OK != NS_InitNodeClass(aContext, (void **)&parent_proto)) {
if (NS_OK != NS_InitDataClass(aContext, (void **)&parent_proto)) {
return NS_ERROR_FAILURE;
}
proto = JS_InitClass(jscontext, // context
@ -557,7 +407,7 @@ nsresult NS_InitTextClass(nsIScriptContext *aContext, void **aPrototype)
//
// Method for creating a new Text JavaScript object
//
extern "C" NS_DOM NS_NewScriptText(nsIScriptContext *aContext, nsIDOMText *aSupports, nsISupports *aParent, void **aReturn)
extern "C" NS_DOM nsresult NS_NewScriptText(nsIScriptContext *aContext, nsIDOMText *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptText");
JSObject *proto;

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

@ -1,718 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#include "jsapi.h"
#include "nscore.h"
#include "nsIScriptContext.h"
#include "nsIJSScriptObject.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsIPtr.h"
#include "nsString.h"
#include "nsIDOMTreeIterator.h"
#include "nsIDOMNode.h"
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
static NS_DEFINE_IID(kITreeIteratorIID, NS_IDOMTREEITERATOR_IID);
static NS_DEFINE_IID(kINodeIID, NS_IDOMNODE_IID);
NS_DEF_PTR(nsIDOMTreeIterator);
NS_DEF_PTR(nsIDOMNode);
/***********************************************************************/
//
// TreeIterator Properties Getter
//
PR_STATIC_CALLBACK(JSBool)
GetTreeIteratorProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMTreeIterator *a = (nsIDOMTreeIterator*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case 0:
default:
{
nsIJSScriptObject *object;
if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {
PRBool rval;
rval = object->GetProperty(cx, id, vp);
NS_RELEASE(object);
return rval;
}
}
}
}
return PR_TRUE;
}
/***********************************************************************/
//
// TreeIterator Properties Setter
//
PR_STATIC_CALLBACK(JSBool)
SetTreeIteratorProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMTreeIterator *a = (nsIDOMTreeIterator*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case 0:
default:
{
nsIJSScriptObject *object;
if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {
PRBool rval;
rval = object->SetProperty(cx, id, vp);
NS_RELEASE(object);
return rval;
}
}
}
}
return PR_TRUE;
}
//
// TreeIterator finalizer
//
PR_STATIC_CALLBACK(void)
FinalizeTreeIterator(JSContext *cx, JSObject *obj)
{
nsIDOMTreeIterator *a = (nsIDOMTreeIterator*)JS_GetPrivate(cx, obj);
if (nsnull != a) {
// get the js object
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == a->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
owner->ResetScriptObject();
NS_RELEASE(owner);
}
NS_RELEASE(a);
}
}
//
// TreeIterator enumerate
//
PR_STATIC_CALLBACK(JSBool)
EnumerateTreeIterator(JSContext *cx, JSObject *obj)
{
nsIDOMTreeIterator *a = (nsIDOMTreeIterator*)JS_GetPrivate(cx, obj);
if (nsnull != a) {
// get the js object
nsIJSScriptObject *object;
if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {
object->EnumerateProperty(cx);
NS_RELEASE(object);
}
}
return JS_TRUE;
}
//
// TreeIterator resolve
//
PR_STATIC_CALLBACK(JSBool)
ResolveTreeIterator(JSContext *cx, JSObject *obj, jsval id)
{
nsIDOMTreeIterator *a = (nsIDOMTreeIterator*)JS_GetPrivate(cx, obj);
if (nsnull != a) {
// get the js object
nsIJSScriptObject *object;
if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {
object->Resolve(cx, id);
NS_RELEASE(object);
}
}
return JS_TRUE;
}
//
// Native method NumChildren
//
PR_STATIC_CALLBACK(JSBool)
TreeIteratorNumChildren(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMTreeIterator *nativeThis = (nsIDOMTreeIterator*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
PRUint32 nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->NumChildren(&nativeRet)) {
return JS_FALSE;
}
*rval = INT_TO_JSVAL(nativeRet);
}
else {
JS_ReportError(cx, "Function numChildren requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method NumPreviousSiblings
//
PR_STATIC_CALLBACK(JSBool)
TreeIteratorNumPreviousSiblings(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMTreeIterator *nativeThis = (nsIDOMTreeIterator*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
PRUint32 nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->NumPreviousSiblings(&nativeRet)) {
return JS_FALSE;
}
*rval = INT_TO_JSVAL(nativeRet);
}
else {
JS_ReportError(cx, "Function numPreviousSiblings requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method NumNextSiblings
//
PR_STATIC_CALLBACK(JSBool)
TreeIteratorNumNextSiblings(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMTreeIterator *nativeThis = (nsIDOMTreeIterator*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
PRUint32 nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->NumNextSiblings(&nativeRet)) {
return JS_FALSE;
}
*rval = INT_TO_JSVAL(nativeRet);
}
else {
JS_ReportError(cx, "Function numNextSiblings requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method ToParent
//
PR_STATIC_CALLBACK(JSBool)
TreeIteratorToParent(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMTreeIterator *nativeThis = (nsIDOMTreeIterator*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMNode* nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->ToParent(&nativeRet)) {
return JS_FALSE;
}
if (nativeRet != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*rval = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(nativeRet);
}
else {
*rval = JSVAL_NULL;
}
}
else {
JS_ReportError(cx, "Function toParent requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method ToPreviousSibling
//
PR_STATIC_CALLBACK(JSBool)
TreeIteratorToPreviousSibling(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMTreeIterator *nativeThis = (nsIDOMTreeIterator*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMNode* nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->ToPreviousSibling(&nativeRet)) {
return JS_FALSE;
}
if (nativeRet != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*rval = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(nativeRet);
}
else {
*rval = JSVAL_NULL;
}
}
else {
JS_ReportError(cx, "Function toPreviousSibling requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method ToNextSibling
//
PR_STATIC_CALLBACK(JSBool)
TreeIteratorToNextSibling(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMTreeIterator *nativeThis = (nsIDOMTreeIterator*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMNode* nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->ToNextSibling(&nativeRet)) {
return JS_FALSE;
}
if (nativeRet != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*rval = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(nativeRet);
}
else {
*rval = JSVAL_NULL;
}
}
else {
JS_ReportError(cx, "Function toNextSibling requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method ToFirstChild
//
PR_STATIC_CALLBACK(JSBool)
TreeIteratorToFirstChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMTreeIterator *nativeThis = (nsIDOMTreeIterator*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMNode* nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->ToFirstChild(&nativeRet)) {
return JS_FALSE;
}
if (nativeRet != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*rval = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(nativeRet);
}
else {
*rval = JSVAL_NULL;
}
}
else {
JS_ReportError(cx, "Function toFirstChild requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method ToLastChild
//
PR_STATIC_CALLBACK(JSBool)
TreeIteratorToLastChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMTreeIterator *nativeThis = (nsIDOMTreeIterator*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMNode* nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->ToLastChild(&nativeRet)) {
return JS_FALSE;
}
if (nativeRet != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*rval = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(nativeRet);
}
else {
*rval = JSVAL_NULL;
}
}
else {
JS_ReportError(cx, "Function toLastChild requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method ToNthChild
//
PR_STATIC_CALLBACK(JSBool)
TreeIteratorToNthChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMTreeIterator *nativeThis = (nsIDOMTreeIterator*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMNode* nativeRet;
PRInt32 b0;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 1) {
if (!JS_ValueToInt32(cx, argv[0], (int32 *)&b0)) {
JS_ReportError(cx, "Parameter must be a number");
return JS_FALSE;
}
if (NS_OK != nativeThis->ToNthChild(b0, &nativeRet)) {
return JS_FALSE;
}
if (nativeRet != nsnull) {
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == nativeRet->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
// set the return value
*rval = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(nativeRet);
}
else {
*rval = JSVAL_NULL;
}
}
else {
JS_ReportError(cx, "Function toNthChild requires 1 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
/***********************************************************************/
//
// class for TreeIterator
//
JSClass TreeIteratorClass = {
"TreeIterator",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
GetTreeIteratorProperty,
SetTreeIteratorProperty,
EnumerateTreeIterator,
ResolveTreeIterator,
JS_ConvertStub,
FinalizeTreeIterator
};
//
// TreeIterator class properties
//
static JSPropertySpec TreeIteratorProperties[] =
{
{0}
};
//
// TreeIterator class methods
//
static JSFunctionSpec TreeIteratorMethods[] =
{
{"numChildren", TreeIteratorNumChildren, 0},
{"numPreviousSiblings", TreeIteratorNumPreviousSiblings, 0},
{"numNextSiblings", TreeIteratorNumNextSiblings, 0},
{"toParent", TreeIteratorToParent, 0},
{"toPreviousSibling", TreeIteratorToPreviousSibling, 0},
{"toNextSibling", TreeIteratorToNextSibling, 0},
{"toFirstChild", TreeIteratorToFirstChild, 0},
{"toLastChild", TreeIteratorToLastChild, 0},
{"toNthChild", TreeIteratorToNthChild, 1},
{0}
};
//
// TreeIterator constructor
//
PR_STATIC_CALLBACK(JSBool)
TreeIterator(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
return JS_TRUE;
}
//
// TreeIterator class initialization
//
nsresult NS_InitTreeIteratorClass(nsIScriptContext *aContext, void **aPrototype)
{
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
JSObject *proto = nsnull;
JSObject *constructor = nsnull;
JSObject *parent_proto = nsnull;
JSObject *global = JS_GetGlobalObject(jscontext);
jsval vp;
if ((PR_TRUE != JS_LookupProperty(jscontext, global, "TreeIterator", &vp)) ||
!JSVAL_IS_OBJECT(vp) ||
((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) ||
(PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) ||
!JSVAL_IS_OBJECT(vp)) {
if (NS_OK != NS_InitNodeIteratorClass(aContext, (void **)&parent_proto)) {
return NS_ERROR_FAILURE;
}
proto = JS_InitClass(jscontext, // context
global, // global object
parent_proto, // parent proto
&TreeIteratorClass, // JSClass
TreeIterator, // JSNative ctor
0, // ctor args
TreeIteratorProperties, // proto props
TreeIteratorMethods, // proto funcs
nsnull, // ctor props (static)
nsnull); // ctor funcs (static)
if (nsnull == proto) {
return NS_ERROR_FAILURE;
}
}
else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) {
proto = JSVAL_TO_OBJECT(vp);
}
else {
return NS_ERROR_FAILURE;
}
if (aPrototype) {
*aPrototype = proto;
}
return NS_OK;
}
//
// Method for creating a new TreeIterator JavaScript object
//
extern "C" NS_DOM NS_NewScriptTreeIterator(nsIScriptContext *aContext, nsIDOMTreeIterator *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptTreeIterator");
JSObject *proto;
JSObject *parent;
nsIScriptObjectOwner *owner;
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
if (nsnull == aParent) {
parent = nsnull;
}
else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) {
NS_RELEASE(owner);
return NS_ERROR_FAILURE;
}
NS_RELEASE(owner);
}
else {
return NS_ERROR_FAILURE;
}
if (NS_OK != NS_InitTreeIteratorClass(aContext, (void **)&proto)) {
return NS_ERROR_FAILURE;
}
// create a js object for this class
*aReturn = JS_NewObject(jscontext, &TreeIteratorClass, proto, parent);
if (nsnull != *aReturn) {
// connect the native object to the js object
JS_SetPrivate(jscontext, (JSObject *)*aReturn, aSupports);
NS_ADDREF(aSupports);
}
else {
return NS_ERROR_FAILURE;
}
return NS_OK;
}

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

@ -579,7 +579,7 @@ nsresult NS_InitWindowClass(nsIScriptContext *aContext,
//
// Method for creating a new Window JavaScript object
//
extern "C" NS_DOM NS_NewScriptWindow(nsIScriptContext *aContext, nsIDOMWindow *aSupports, nsISupports *aParent, void **aReturn)
extern "C" NS_DOM nsresult NS_NewScriptWindow(nsIScriptContext *aContext, nsIDOMWindow *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null arg");
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();

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

@ -22,21 +22,21 @@
//
function html(node)
{
var type = node.getNodeType()
var type = node.nodeType;
if (type == Node.ELEMENT) {
// open tag
dump("<" + node.getTagName())
dump("<" + node.tagName)
// dump the attributes if any
attributes = node.getAttributes()
attributes = node.attributes;
if (null != attributes) {
var countAttrs = attributes.getLength()
var countAttrs = attributes.length;
var index = 0
while(index < countAttrs) {
att = attributes.item(index)
att = attributes.item(index);
if (null != att) {
dump(" " + att.toString())
dump(" " + att.value)
}
index++
}
@ -46,18 +46,17 @@ function html(node)
dump(">")
// recursively dump the children
if (node.hasChildNodes()) {
if (node.hasChildNodes) {
// get the children
var children = node.getChildNodes()
var length = children.getLength()
var child = children.getNextNode()
var children = node.childNodes;
var length = children.length;
var count = 0;
while(count < length) {
child = children.item(count)
html(child)
child = children.getNextNode()
count++
}
dump("</" + node.getTagName() + ">");
dump("</" + node.tagName + ">");
}

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

@ -24,22 +24,21 @@ function traverse(node, indent)
{
dump("\n")
indent += " "
var type = node.getNodeType()
var type = node.nodeType;
// if it's an element dump the tag and recurse the children
if (type == Node.ELEMENT) {
dump(indent + node.getTagName())
dump(indent + node.tagName)
// go through the children
if (node.hasChildNodes()) {
var children = node.getChildNodes()
var length = children.getLength()
var child = children.getNextNode()
if (node.hasChildNodes) {
var children = node.childNodes;
var length = children.length;
var count = 0;
while(count < length) {
child = children.item(count)
traverse(child, indent)
child = children.getNextNode()
count++
}
}

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

@ -25,17 +25,17 @@ function htmlString(node, indent)
var html = ""
indent += " "
var type = node.getNodeType()
var type = node.nodeType
if (type == Node.ELEMENT) {
// open tag
html += "\n" + indent + "<" + node.getTagName()
html += "\n" + indent + "<" + node.tagName
// dump the attributes if any
attributes = node.getAttributes()
attributes = node.attributes
if (null != attributes) {
html += " "
var countAttrs = attributes.getLength()
var countAttrs = attributes.length
var index = 0
while(index < countAttrs) {
att = attributes.item(index)
@ -50,21 +50,20 @@ function htmlString(node, indent)
html += ">"
// recursively dump the children
if (node.hasChildNodes()) {
if (node.hasChildNodes) {
// get the children
var children = node.getChildNodes()
var length = children.getLength()
var child = children.getNextNode()
var children = node.childNodes
var length = children.length
var count = 0;
while(count < length) {
child = children.item(count)
html += htmlString(child, indent)
child = children.getNextNode()
count++
}
}
// close tag
html += "\n" + indent + "</" + node.getTagName() + ">"
html += "\n" + indent + "</" + node.tagName + ">"
}
// if it's a piece of text just dump the text
else if (type == Node.TEXT) {

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

@ -18,39 +18,35 @@
var node = document.documentElement
node.getNodeType()
node.nodeType
node.getTagName()
node.tagName
var attrList = node.getAttributes()
var attrList = node.attributes
attrList.getLength()
attrList.length
var attr = attrList.item(0)
attr.getName()
attr.name
attr.value
attr.toString()
node.hasChildNodes
node.hasChildNodes()
var children = node.childNodes
var children = node.getChildNodes()
children.length
children.getLength()
node = children.item(1);
node.nodeType
node = children.getNextNode()
node.getNodeType()
node.tagName
node.getTagName()
node = node.firstChild
children.toFirst()
node = node.nextSibling
node = node.getFirstChild()
node = node.getNextSiblings()
node = node.getParentNode()
node = node.parentNode

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

@ -17,17 +17,31 @@
* Netscape Communications Corporation. All Rights Reserved.
*/
// Find the BODY element
function findBody(node)
{
// XXX A better way to do this would be to use getElementsByTagName(), but
// it isn't implemented yet...
if (node.getTagName() == "BODY") {
return node;
if (node.nodeType != Node.ELEMENT) {
return null;
}
var children = node.getChildNodes()
return findBody(children.getNextNode())
var children = node.childNodes;
if (children == null) {
return null;
}
var length = children.length;
var child = null;
var count = 0;
while (count < length) {
child = children.item(count);
if (child.tagName == "BODY") {
dump("BODY found");
return child;
}
var body = findBody(child);
if (null != body) {
return body;
}
count++;
}
return null;
}
// Given the body element, find the first table element
@ -35,19 +49,25 @@ function findTable(body)
{
// XXX A better way to do this would be to use getElementsByTagName(), but
// it isn't implemented yet...
var children = body.getChildNodes()
var child = children.getNextNode()
while (child) {
if (child.getNodeType() == 2) {
if (child.getTagName() == "TABLE") {
var children = body.childNodes
if (children == null) {
return null;
}
var length = children.length;
var child = null;
var count = 0;
while (count < length) {
child = children.item(count);
if (child.nodeType == Node.ELEMENT) {
if (child.tagName == "TABLE") {
dump("TABLE found");
break;
}
}
child = children.getNextNode()
count++;
}
return child;
return child;
}
// Change the table's caption
@ -55,10 +75,10 @@ function changeCaption(table)
{
// Get the first element. This is the caption (maybe). We really should
// check...
var caption = table.getFirstChild()
var caption = table.firstChild
// Get the caption text
var text = caption.getFirstChild()
var text = caption.firstChild
// Append some text
text.append(" NEW TEXT")

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

@ -17,17 +17,31 @@
* Netscape Communications Corporation. All Rights Reserved.
*/
// Find the BODY element
function findBody(node)
{
// XXX A better way to do this would be to use getElementsByTagName(), but
// it isn't implemented yet...
if (node.getTagName() == "BODY") {
return node;
if (node.nodeType != Node.ELEMENT) {
return null;
}
var children = node.getChildNodes()
return findBody(children.getNextNode())
var children = node.childNodes;
if (children == null) {
return null;
}
var length = children.length;
var child = null;
var count = 0;
while (count < length) {
child = children.item(count);
if (child.tagName == "BODY") {
dump("BODY found");
return child;
}
var body = findBody(child);
if (null != body) {
return body;
}
count++;
}
return null;
}
// Given the body element, find the first table element
@ -35,16 +49,22 @@ function findTable(body)
{
// XXX A better way to do this would be to use getElementsByTagName(), but
// it isn't implemented yet...
var children = body.getChildNodes()
var child = children.getNextNode()
while (child) {
if (child.getNodeType() == 2) {
if (child.getTagName() == "TABLE") {
var children = body.childNodes
if (children == null) {
return null;
}
var length = children.length;
var child = null;
var count = 0;
while (count < length) {
child = children.item(count);
if (child.nodeType == Node.ELEMENT) {
if (child.tagName == "TABLE") {
dump("TABLE found");
break;
}
}
child = children.getNextNode()
count++;
}
return child;
@ -55,16 +75,21 @@ function findTableBody(table)
{
// XXX A better way to do this would be to use getElementsByTagName(), but
// it isn't implemented yet...
var children = table.getChildNodes()
var child = children.getNextNode()
while (child) {
if (child.getNodeType() == 2) {
if (child.getTagName() == "TBODY") {
var children = table.childNodes
if (children == null) {
return null;
}
var length = children.length;
var child = null;
var count = 0;
while (count < length) {
child = children.item(count);
if (child.nodeType == Node.ELEMENT) {
if (child.tagName == "TBODY") {
break;
}
}
child = children.getNextNode()
count++;
}
return child;
@ -77,13 +102,13 @@ function changeCell(table)
var body = findTableBody(table)
// The table body's first child is a table row
var row = body.getFirstChild()
var row = body.firstChild
// The row's first child is a table cell
var cell = row.getFirstChild()
var cell = row.firstChild
// Get the cell's text
var text = cell.getFirstChild()
var text = cell.firstChild
// Append some text
text.append(" NEW TEXT")

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

@ -225,6 +225,15 @@ FileGen::GetParameterType(char *aBuffer, IdlParameter &aParameter)
GetVariableTypeForParameter(aBuffer, aParameter);
switch (aParameter.GetAttribute()) {
case IdlParameter::INPUT:
if (aParameter.GetType() == TYPE_STRING) {
char buf[256];
strcpy(buf, "const ");
strcat(buf, aBuffer);
strcpy(aBuffer, buf);
}
break;
case IdlParameter::OUTPUT:
case IdlParameter::INOUT:
if (aParameter.GetType() != TYPE_STRING) {

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

@ -757,31 +757,46 @@ IdlFunction* IdlParser::ParseFunction(IdlSpecification &aSpecification, Token &a
if (RAISES_TOKEN == token->id) {
mScanner->NextToken(); // eat "raises"
TrimComments();
token = mScanner->NextToken(); // must be '('
while (FUNC_PARAMS_SPEC_BEGIN_TOKEN == token->id ||
SEPARATOR_TOKEN == token->id) {
TrimComments();
token = mScanner->NextToken(); // must be the exception name
if (IDENTIFIER_TOKEN == token->id) {
token = mScanner->PeekToken();
if (IDENTIFIER_TOKEN == token->id) {
while (IDENTIFIER_TOKEN == token->id) {
mScanner->NextToken(); // eat exception name
funcObj->AddException(token->stringID);
TrimComments();
token = mScanner->NextToken(); // must be ',' or ')'
token = mScanner->PeekToken();
if (SEPARATOR_TOKEN == token->id) {
mScanner->NextToken(); // eat ','
TrimComments();
token = mScanner->PeekToken(); // should be next exception
}
}
else {
}
else {
mScanner->NextToken(); // Must be '('
while (FUNC_PARAMS_SPEC_BEGIN_TOKEN == token->id ||
SEPARATOR_TOKEN == token->id) {
TrimComments();
token = mScanner->NextToken(); // must be the exception name
if (IDENTIFIER_TOKEN == token->id) {
funcObj->AddException(token->stringID);
TrimComments();
token = mScanner->NextToken(); // must be ',' or ')'
}
else {
delete funcObj;
throw FunctionParsingException("Undeclared exception name.");
}
}
if (FUNC_PARAMS_SPEC_END_TOKEN != token->id) {
delete funcObj;
throw FunctionParsingException("Undeclared exception name.");
throw FunctionParsingException("Missing ')'. Exceptions declaration non terminated.");
}
}
if (FUNC_PARAMS_SPEC_END_TOKEN != token->id) {
delete funcObj;
throw FunctionParsingException("Missing ')'. Exceptions declaration non terminated.");
TrimComments();
token = mScanner->PeekToken();
}
TrimComments();
token = mScanner->PeekToken();
}
}
else {
delete funcObj;

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

@ -1260,7 +1260,7 @@ static const char *kNewGlobalJSObjectStr =
"\n\n//\n"
"// Method for creating a new %s JavaScript object\n"
"//\n"
"extern \"C\" NS_DOM NS_NewScript%s(nsIScriptContext *aContext, nsIDOM%s *aSupports, nsISupports *aParent, void **aReturn)\n"
"extern \"C\" NS_DOM nsresult NS_NewScript%s(nsIScriptContext *aContext, nsIDOM%s *aSupports, nsISupports *aParent, void **aReturn)\n"
"{\n"
" NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, \"null arg\");\n"
" JSContext *jscontext = (JSContext *)aContext->GetNativeContext();\n"
@ -1295,7 +1295,7 @@ static const char *kNewJSObjectStr =
"\n\n//\n"
"// Method for creating a new %s JavaScript object\n"
"//\n"
"extern \"C\" NS_DOM NS_NewScript%s(nsIScriptContext *aContext, nsIDOM%s *aSupports, nsISupports *aParent, void **aReturn)\n"
"extern \"C\" NS_DOM nsresult NS_NewScript%s(nsIScriptContext *aContext, nsIDOM%s *aSupports, nsISupports *aParent, void **aReturn)\n"
"{\n"
" NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, \"null argument to NS_NewScript%s\");\n"
" JSObject *proto;\n"

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

@ -54,7 +54,7 @@ static const char *kEnumDeclBeginStr = " enum {\n";
static const char *kEnumEntryStr = " %s = %d%s\n";
static const char *kEnumDeclEndStr = " };\n";
static const char *kGetterMethodDeclStr = "\n NS_IMETHOD Get%s(%s%s a%s)=0;\n";
static const char *kSetterMethodDeclStr = " NS_IMETHOD Set%s(%s a%s)=0;\n";
static const char *kSetterMethodDeclStr = " NS_IMETHOD Set%s(%s%s a%s)=0;\n";
static const char *kMethodDeclStr = "\n NS_IMETHOD %s(%s)=0;\n";
static const char *kParamStr = "%s a%s";
static const char *kDelimiterStr = ", ";
@ -63,7 +63,7 @@ static const char *kReturnStr = "%s%s aReturn";
static const char *kClassEpilogStr = "};\n\n";
static const char *kGlobalInitClassStr = "extern nsresult NS_Init%sClass(nsIScriptContext *aContext, nsIScriptGlobalObject *aGlobal);\n\n";
static const char *kInitClassStr = "extern nsresult NS_Init%sClass(nsIScriptContext *aContext, void **aPrototype);\n\n";
static const char *kNewObjStr = "extern \"C\" NS_DOM NS_NewScript%s(nsIScriptContext *aContext, nsIDOM%s *aSupports, nsISupports *aParent, void **aReturn);\n\n";
static const char *kNewObjStr = "extern \"C\" NS_DOM nsresult NS_NewScript%s(nsIScriptContext *aContext, nsIDOM%s *aSupports, nsISupports *aParent, void **aReturn);\n\n";
static const char *kEndifStr = "#endif // nsIDOM%s_h__\n";
@ -260,7 +260,8 @@ XPCOMGen::GenerateMethods(IdlInterface &aInterface)
*file << buf;
if (!attr->GetReadOnly()) {
sprintf(buf, kSetterMethodDeclStr, name_buf, type_buf,
sprintf(buf, kSetterMethodDeclStr, name_buf,
attr->GetType() == TYPE_STRING ? "const " : "", type_buf,
name_buf);
*file << buf;
}

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

@ -41,6 +41,7 @@ class nsIScriptContextOwner;
class nsIWebWidget;
class nsIDOMEvent;
class nsIDeviceContext;
class nsIParser;
// IID for the nsIDocument interface
#define NS_IDOCUMENT_IID \
@ -135,6 +136,14 @@ public:
virtual nsIScriptContextOwner *GetScriptContextOwner() = 0;
virtual void SetScriptContextOwner(nsIScriptContextOwner *aScriptContextOwner) = 0;
/**
* Pass the document a reference to its parser. The assumption is
* that the parser will only be set while document loading is
* being carried out.
*/
virtual nsIParser *GetParser() = 0;
virtual void SetParser(nsIParser *aParser) = 0;
//----------------------------------------------------------------------
// Document notification API's

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

@ -29,6 +29,7 @@
#include "nsEventListenerManager.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptContextOwner.h"
#include "nsIParser.h"
#include "nsSelection.h"
#include "nsIDOMText.h"
@ -129,6 +130,7 @@ nsDocument::nsDocument()
mScriptObject = nsnull;
mScriptContextOwner = nsnull;
mListenerManager = nsnull;
mParser = nsnull;
if (NS_OK != NS_NewSelection(&mSelection)) {
printf("*************** Error: nsDocument::nsDocument - Creation of Selection failed!\n");
@ -165,6 +167,7 @@ nsDocument::~nsDocument()
NS_IF_RELEASE(mArena);
NS_IF_RELEASE(mSelection);
NS_IF_RELEASE(mScriptContextOwner);
NS_IF_RELEASE(mParser);
}
nsresult nsDocument::QueryInterface(REFNSIID aIID, void** aInstancePtr)
@ -410,6 +413,22 @@ void nsDocument::SetScriptContextOwner(nsIScriptContextOwner *aScriptContextOwne
}
}
nsIParser *nsDocument::GetParser()
{
NS_IF_ADDREF(mParser);
return mParser;
}
void nsDocument::SetParser(nsIParser *aParser)
{
NS_IF_RELEASE(mParser);
mParser = aParser;
NS_IF_ADDREF(mParser);
}
// Note: We don't hold a reference to the document observer; we assume
// that it has a live reference to the document.
void nsDocument::AddObserver(nsIDocumentObserver* aObserver)
@ -536,142 +555,51 @@ nsresult nsDocument::ResetScriptObject()
//
// nsIDOMDocument interface
//
nsresult nsDocument::GetNodeType(PRInt32 *aType)
{
*aType = nsIDOMNode::DOCUMENT;
return NS_OK;
}
nsresult nsDocument::GetParentNode(nsIDOMNode **aNode)
{
return NS_ERROR_FAILURE;
}
nsresult nsDocument::GetChildNodes(nsIDOMNodeIterator **aIterator)
{
//XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsDocument::HasChildNodes(PRBool *aReturn)
{
if (nsnull != mRootContent) {
*aReturn = PR_TRUE;
}
else {
*aReturn = PR_FALSE;
}
return NS_OK;
}
nsresult nsDocument::GetFirstChild(nsIDOMNode **aNode)
{
if (nsnull != mRootContent) {
nsresult res = mRootContent->QueryInterface(kIDOMNodeIID, (void**)aNode);
NS_ASSERTION(NS_OK == res, "Must be a DOM Node");
return res;
}
return NS_ERROR_FAILURE;
}
nsresult nsDocument::GetPreviousSibling(nsIDOMNode **aNode)
{
// no siblings
return NS_ERROR_FAILURE;
}
nsresult nsDocument::GetNextSibling(nsIDOMNode **aNode)
{
// no siblings
return NS_ERROR_FAILURE;
}
nsresult nsDocument::InsertBefore(nsIDOMNode *newChild, nsIDOMNode *refChild)
{
// a document has only one child
return NS_ERROR_FAILURE;
}
nsresult nsDocument::ReplaceChild(nsIDOMNode *newChild, nsIDOMNode *oldChild)
{
NS_PRECONDITION(nsnull != newChild && nsnull != oldChild, "null arg");
nsIContent* content;
nsresult res = oldChild->QueryInterface(kIContentIID, (void**)&content);
if (NS_OK == res) {
// check that we are replacing the root content
if (content == mRootContent) {
nsIContent* newContent;
res = newChild->QueryInterface(kIContentIID, (void**)&newContent);
if (NS_OK == res) {
SetRootContent(newContent);
NS_RELEASE(newContent);
}
else NS_ASSERTION(0, "Must be an nsIContent"); // nsIContent not supported. Who are you?
}
NS_RELEASE(content);
}
else NS_ASSERTION(0, "Must be an nsIContent"); // nsIContent not supported. Who are you?
return res;
}
nsresult nsDocument::RemoveChild(nsIDOMNode *oldChild)
{
NS_PRECONDITION(nsnull != oldChild, "null arg");
nsIContent* content;
nsresult res = oldChild->QueryInterface(kIContentIID, (void**)&content);
if (NS_OK == res) {
if (content == mRootContent) {
NS_RELEASE(mRootContent);
mRootContent = nsnull;
}
}
return res;
}
nsresult nsDocument::GetMasterDoc(nsIDOMDocument **aDocument)
NS_IMETHODIMP
nsDocument::GetMasterDoc(nsIDOMDocument **aDocument)
{
AddRef();
*aDocument = (nsIDOMDocument*)this;
return NS_OK;
}
nsresult nsDocument::SetMasterDoc(nsIDOMDocument *aDocument)
NS_IMETHODIMP
nsDocument::GetDocumentType(nsIDOMDocumentType** aDocumentType)
{
//XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsDocument::GetDocumentType(nsIDOMNode **aDocType)
NS_IMETHODIMP
nsDocument::GetProlog(nsIDOMNodeList** aProlog)
{
//XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
*aProlog = nsnull;
return NS_OK;
}
nsresult nsDocument::SetDocumentType(nsIDOMNode *aNode)
NS_IMETHODIMP
nsDocument::GetEpilog(nsIDOMNodeList** aEpilog)
{
//XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
*aEpilog = nsnull;
return NS_OK;
}
nsresult nsDocument::GetDocumentElement(nsIDOMElement **aElement)
NS_IMETHODIMP
nsDocument::GetDocumentElement(nsIDOMElement** aDocumentElement)
{
nsresult res = NS_ERROR_FAILURE;
if (nsnull != mRootContent) {
res = mRootContent->QueryInterface(kIDOMElementIID, (void**)aElement);
res = mRootContent->QueryInterface(kIDOMElementIID, (void**)aDocumentElement);
NS_ASSERTION(NS_OK == res, "Must be a DOM Element");
}
return res;
}
nsresult nsDocument::SetDocumentElement(nsIDOMElement *aElement)
#if 0
NS_IMETHODIMP
nsDocument::SetDocumentElement(nsIDOMElement *aElement)
{
NS_PRECONDITION(nsnull != aElement, "null arg");
nsIContent* content;
@ -685,74 +613,183 @@ nsresult nsDocument::SetDocumentElement(nsIDOMElement *aElement)
return res;
}
#endif
nsresult nsDocument::GetDocumentContext(nsIDOMDocumentContext **aDocContext)
NS_IMETHODIMP
nsDocument::CreateElement(const nsString& aTagName,
nsIDOMNamedNodeMap* aAttributes,
nsIDOMElement** aReturn)
{
//XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDocument::CreateTextNode(const nsString& aData, nsIDOMText** aReturn)
{
//XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsDocument::SetDocumentContext(nsIDOMDocumentContext *aContext)
NS_IMETHODIMP
nsDocument::CreateDocumentFragment(nsIDOMDocumentFragment** aReturn)
{
//XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsDocument::CreateDocumentContext(nsIDOMDocumentContext **aDocContext)
NS_IMETHODIMP
nsDocument::CreateComment(const nsString& aData, nsIDOMComment** aReturn)
{
//XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsDocument::CreateElement(nsString &aTagName,
nsIDOMAttributeList *aAttributes,
nsIDOMElement **aElement)
{
//XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsDocument::CreateTextNode(nsString &aData, nsIDOMText** aTextNode)
NS_IMETHODIMP
nsDocument::CreateProcessingInstruction(const nsString& aTarget,
const nsString& aData,
nsIDOMProcessingInstruction** aReturn)
{
//XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsDocument::CreateComment(nsString &aData, nsIDOMComment **aComment)
NS_IMETHODIMP
nsDocument::CreateAttribute(const nsString& aName,
nsIDOMNode* aValue,
nsIDOMAttribute** aReturn)
{
//XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsDocument::CreatePI(nsString &aName, nsString &aData, nsIDOMPI **aPI)
NS_IMETHODIMP
nsDocument::GetElementsByTagName(const nsString& aTagname,
nsIDOMNodeList** aReturn)
{
//XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsDocument::CreateAttribute(nsString &aName,
nsIDOMNode *value,
nsIDOMAttribute **aAttribute)
//
// nsIDOMNode methods
//
NS_IMETHODIMP
nsDocument::GetNodeName(nsString& aNodeName)
{
//XXX TBI
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsDocument::CreateAttributeList(nsIDOMAttributeList **aAttributesList)
NS_IMETHODIMP
nsDocument::GetNodeValue(nsString& aNodeValue)
{
//XXX TBI
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsDocument::CreateTreeIterator(nsIDOMNode *aNode, nsIDOMTreeIterator **aTreeIterator)
NS_IMETHODIMP
nsDocument::SetNodeValue(const nsString& aNodeValue)
{
//XXX TBI
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsDocument::GetElementsByTagName(nsString &aTagname, nsIDOMNodeIterator **aIterator)
NS_IMETHODIMP
nsDocument::GetNodeType(PRInt32* aNodeType)
{
//XXX TBI
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDocument::GetParentNode(nsIDOMNode** aParentNode)
{
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDocument::GetChildNodes(nsIDOMNodeList** aChildNodes)
{
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDocument::GetHasChildNodes(PRBool* aHasChildNodes)
{
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDocument::GetFirstChild(nsIDOMNode** aFirstChild)
{
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDocument::GetLastChild(nsIDOMNode** aLastChild)
{
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDocument::GetPreviousSibling(nsIDOMNode** aPreviousSibling)
{
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDocument::GetNextSibling(nsIDOMNode** aNextSibling)
{
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDocument::GetAttributes(nsIDOMNamedNodeMap** aAttributes)
{
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDocument::InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, nsIDOMNode** aReturn)
{
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDocument::ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, nsIDOMNode** aReturn)
{
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDocument::RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn)
{
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDocument::CloneNode(nsIDOMNode** aReturn)
{
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDocument::Equals(nsIDOMNode* aNode, PRBool aDeep, PRBool* aReturn)
{
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}

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

@ -27,6 +27,7 @@
class nsISelection;
class nsIEventListenerManager;
class nsIParser;
class nsPostData : public nsIPostData {
public:
@ -115,6 +116,14 @@ public:
virtual nsIScriptContextOwner *GetScriptContextOwner();
virtual void SetScriptContextOwner(nsIScriptContextOwner *aScriptContextOwner);
/**
* Pass the document a reference to its parser. The assumption is
* that the parser will only be set while document loading is
* being carried out.
*/
virtual nsIParser *GetParser();
virtual void SetParser(nsIParser *aParser);
/**
* Add a new observer of document change notifications. Whenever
* content is changed, appended, inserted or removed the observers are
@ -182,37 +191,39 @@ public:
NS_IMETHOD ResetScriptObject();
// nsIDOMDocument interface
NS_IMETHOD GetNodeType(PRInt32 *aType);
NS_IMETHOD GetParentNode(nsIDOMNode **aNode);
NS_IMETHOD GetChildNodes(nsIDOMNodeIterator **aIterator);
NS_IMETHOD HasChildNodes(PRBool *aReturn);
NS_IMETHOD GetFirstChild(nsIDOMNode **aNode);
NS_IMETHOD GetPreviousSibling(nsIDOMNode **aNode);
NS_IMETHOD GetNextSibling(nsIDOMNode **aNode);
NS_IMETHOD InsertBefore(nsIDOMNode *newChild, nsIDOMNode *refChild);
NS_IMETHOD ReplaceChild(nsIDOMNode *newChild, nsIDOMNode *oldChild);
NS_IMETHOD RemoveChild(nsIDOMNode *oldChild);
NS_IMETHOD GetMasterDoc(nsIDOMDocument **aDocument);
NS_IMETHOD SetMasterDoc(nsIDOMDocument *aDocument);
NS_IMETHOD GetDocumentType(nsIDOMNode **aDocType);
NS_IMETHOD SetDocumentType(nsIDOMNode *aNode);
NS_IMETHOD GetDocumentElement(nsIDOMElement **aElement);
NS_IMETHOD SetDocumentElement(nsIDOMElement *aElement);
NS_IMETHOD GetDocumentContext(nsIDOMDocumentContext **aDocContext);
NS_IMETHOD SetDocumentContext(nsIDOMDocumentContext *aContext);
NS_IMETHOD CreateDocumentContext(nsIDOMDocumentContext **aDocContext);
NS_IMETHOD CreateElement(nsString &aTagName,
nsIDOMAttributeList *aAttributes,
nsIDOMElement **aElement);
NS_IMETHOD CreateTextNode(nsString &aData, nsIDOMText** aTextNode);
NS_IMETHOD CreateComment(nsString &aData, nsIDOMComment **aComment);
NS_IMETHOD CreatePI(nsString &aName, nsString &aData, nsIDOMPI **aPI);
NS_IMETHOD CreateAttribute(nsString &aName,
nsIDOMNode *value,
nsIDOMAttribute **aAttribute);
NS_IMETHOD CreateAttributeList(nsIDOMAttributeList **aAttributesList);
NS_IMETHOD CreateTreeIterator(nsIDOMNode *aNode, nsIDOMTreeIterator **aTreeIterator);
NS_IMETHOD GetElementsByTagName(nsString &aTagname, nsIDOMNodeIterator **aIterator);
NS_IMETHOD GetMasterDoc(nsIDOMDocument **aDocument);
NS_IMETHOD GetDocumentType(nsIDOMDocumentType** aDocumentType);
NS_IMETHOD GetProlog(nsIDOMNodeList** aProlog);
NS_IMETHOD GetEpilog(nsIDOMNodeList** aEpilog);
NS_IMETHOD GetDocumentElement(nsIDOMElement** aDocumentElement);
NS_IMETHOD CreateDocumentFragment(nsIDOMDocumentFragment** aReturn);
NS_IMETHOD CreateComment(const nsString& aData, nsIDOMComment** aReturn);
NS_IMETHOD CreateProcessingInstruction(const nsString& aTarget, const nsString& aData, nsIDOMProcessingInstruction** aReturn);
NS_IMETHOD CreateAttribute(const nsString& aName, nsIDOMNode* aValue, nsIDOMAttribute** aReturn);
NS_IMETHOD CreateElement(const nsString& aTagName,
nsIDOMNamedNodeMap* aAttributes,
nsIDOMElement** aReturn);
NS_IMETHOD CreateTextNode(const nsString& aData, nsIDOMText** aReturn);
NS_IMETHOD GetElementsByTagName(const nsString& aTagname, nsIDOMNodeList** aReturn);
// nsIDOMNode
NS_IMETHOD GetNodeName(nsString& aNodeName);
NS_IMETHOD GetNodeValue(nsString& aNodeValue);
NS_IMETHOD SetNodeValue(const nsString& aNodeValue);
NS_IMETHOD GetNodeType(PRInt32* aNodeType);
NS_IMETHOD GetParentNode(nsIDOMNode** aParentNode);
NS_IMETHOD GetChildNodes(nsIDOMNodeList** aChildNodes);
NS_IMETHOD GetHasChildNodes(PRBool* aHasChildNodes);
NS_IMETHOD GetFirstChild(nsIDOMNode** aFirstChild);
NS_IMETHOD GetLastChild(nsIDOMNode** aLastChild);
NS_IMETHOD GetPreviousSibling(nsIDOMNode** aPreviousSibling);
NS_IMETHOD GetNextSibling(nsIDOMNode** aNextSibling);
NS_IMETHOD GetAttributes(nsIDOMNamedNodeMap** aAttributes);
NS_IMETHOD InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, nsIDOMNode** aReturn);
NS_IMETHOD ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, nsIDOMNode** aReturn);
NS_IMETHOD RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn);
NS_IMETHOD CloneNode(nsIDOMNode** aReturn);
NS_IMETHOD Equals(nsIDOMNode* aNode, PRBool aDeep, PRBool* aReturn);
// nsIDOMEventCapturer interface
NS_IMETHOD CaptureEvent(nsIDOMEventListener *aListener);
@ -248,6 +259,7 @@ protected:
nsVoidArray mObservers;
void* mScriptObject;
nsIScriptContextOwner *mScriptContextOwner;
nsIParser *mParser;
nsIEventListenerManager* mListenerManager;
};

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

@ -46,7 +46,7 @@ CPPSRCS = \
nsSpacerPart.cpp \
nsTextContent.cpp \
nsWBRPart.cpp \
nsDOMIterator.cpp \
nsDOMNodeList.cpp \
nsDOMAttributes.cpp \
$(NULL)
EXPORTS = \

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

@ -48,7 +48,7 @@ CPPSRCS= \
nsSpacerPart.cpp \
nsTextContent.cpp \
nsWBRPart.cpp \
nsDOMIterator.cpp \
nsDOMNodeList.cpp \
nsDOMAttributes.cpp \
$(NULL)
@ -78,7 +78,7 @@ CPP_OBJS= \
.\$(OBJDIR)\nsSpacerPart.obj \
.\$(OBJDIR)\nsTextContent.obj \
.\$(OBJDIR)\nsWBRPart.obj \
.\$(OBJDIR)\nsDOMIterator.obj \
.\$(OBJDIR)\nsDOMNodeList.obj \
.\$(OBJDIR)\nsDOMAttributes.obj \
$(NULL)

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

@ -23,7 +23,7 @@
#include "nsIAtom.h"
#include "nsISupportsArray.h"
nsDOMAttribute::nsDOMAttribute(nsString &aName, nsString &aValue)
nsDOMAttribute::nsDOMAttribute(const nsString &aName, const nsString &aValue)
{
mName = new nsString(aName);
mValue = new nsString(aValue);
@ -100,13 +100,6 @@ nsresult nsDOMAttribute::GetValue(nsString &aValue)
return NS_OK;
}
nsresult nsDOMAttribute::SetValue(nsString &aValue)
{
delete mValue;
mValue = new nsString(aValue);
return NS_OK;
}
nsresult nsDOMAttribute::GetSpecified(PRBool *aSpecified)
{
return NS_ERROR_NOT_IMPLEMENTED;
@ -117,42 +110,153 @@ nsresult nsDOMAttribute::SetSpecified(PRBool specified)
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsDOMAttribute::ToString(nsString &aString)
// nsIDOMNode interface
NS_IMETHODIMP
nsDOMAttribute::GetNodeName(nsString& aNodeName)
{
aString = *mName;
aString += " = ";
aString += *mValue;
return GetName(aNodeName);
}
NS_IMETHODIMP
nsDOMAttribute::GetNodeValue(nsString& aNodeValue)
{
return GetValue(aNodeValue);
}
NS_IMETHODIMP
nsDOMAttribute::SetNodeValue(const nsString& aNodeValue)
{
// You can't actually do this, but we'll fail silently
return NS_OK;
}
NS_IMETHODIMP
nsDOMAttribute::GetNodeType(PRInt32* aNodeType)
{
*aNodeType = (PRInt32)nsIDOMNode::ATTRIBUTE;
return NS_OK;
}
NS_IMETHODIMP
nsDOMAttribute::GetParentNode(nsIDOMNode** aParentNode)
{
*aParentNode = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsDOMAttribute::GetChildNodes(nsIDOMNodeList** aChildNodes)
{
*aChildNodes = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsDOMAttribute::GetHasChildNodes(PRBool* aHasChildNodes)
{
*aHasChildNodes = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
nsDOMAttribute::GetFirstChild(nsIDOMNode** aFirstChild)
{
*aFirstChild = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsDOMAttribute::GetLastChild(nsIDOMNode** aLastChild)
{
*aLastChild = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsDOMAttribute::GetPreviousSibling(nsIDOMNode** aPreviousSibling)
{
*aPreviousSibling = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsDOMAttribute::GetNextSibling(nsIDOMNode** aNextSibling)
{
*aNextSibling = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsDOMAttribute::GetAttributes(nsIDOMNamedNodeMap** aAttributes)
{
*aAttributes = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsDOMAttribute::InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, nsIDOMNode** aReturn)
{
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsDOMAttribute::ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, nsIDOMNode** aReturn)
{
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsDOMAttribute::RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn)
{
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsDOMAttribute::CloneNode(nsIDOMNode** aReturn)
{
nsDOMAttribute *newAttr = new nsDOMAttribute(*mName, *mValue);
if (nsnull == newAttr) {
return NS_ERROR_OUT_OF_MEMORY;
}
*aReturn = newAttr;
return NS_OK;
}
NS_IMETHODIMP
nsDOMAttribute::Equals(nsIDOMNode* aNode, PRBool aDeep, PRBool* aReturn)
{
// XXX TBI
return NS_OK;
}
//
// nsDOMAttributeList interface
//
nsDOMAttributeList::nsDOMAttributeList(nsIHTMLContent &aContent) :
mContent(aContent)
nsDOMAttributeMap::nsDOMAttributeMap(nsIHTMLContent &aContent) :
mContent(aContent)
{
mRefCnt = 1;
mContent.AddRef();
mScriptObject = nsnull;
}
nsDOMAttributeList::~nsDOMAttributeList()
nsDOMAttributeMap::~nsDOMAttributeMap()
{
mContent.Release();
}
nsresult nsDOMAttributeList::QueryInterface(REFNSIID aIID, void** aInstancePtr)
nsresult nsDOMAttributeMap::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIDOMAttributeListIID, NS_IDOMATTRIBUTELIST_IID);
static NS_DEFINE_IID(kIDOMNamedNodeMapIID, NS_IDOMNAMEDNODEMAP_IID);
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
if (aIID.Equals(kIDOMAttributeListIID)) {
*aInstancePtr = (void*)(nsIDOMAttributeList*)this;
if (aIID.Equals(kIDOMNamedNodeMapIID)) {
*aInstancePtr = (void*)(nsIDOMNamedNodeMap*)this;
AddRef();
return NS_OK;
}
@ -162,61 +266,75 @@ nsresult nsDOMAttributeList::QueryInterface(REFNSIID aIID, void** aInstancePtr)
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
*aInstancePtr = (void*)(nsISupports*)(nsIDOMAttributeList*)this;
*aInstancePtr = (void*)(nsISupports*)(nsIDOMNamedNodeMap*)this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMPL_ADDREF(nsDOMAttributeList)
NS_IMPL_ADDREF(nsDOMAttributeMap)
NS_IMPL_RELEASE(nsDOMAttributeList)
NS_IMPL_RELEASE(nsDOMAttributeMap)
nsresult nsDOMAttributeList::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
nsresult nsDOMAttributeMap::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
{
nsresult res = NS_OK;
if (nsnull == mScriptObject) {
res = NS_NewScriptAttributeList(aContext, this, nsnull, (void**)&mScriptObject);
res = NS_NewScriptNamedNodeMap(aContext, this, nsnull, (void**)&mScriptObject);
}
*aScriptObject = mScriptObject;
return res;
}
nsresult nsDOMAttributeList::ResetScriptObject()
nsresult nsDOMAttributeMap::ResetScriptObject()
{
mScriptObject = nsnull;
return NS_OK;
}
nsresult nsDOMAttributeList::GetAttribute(nsString &aAttrName, nsIDOMAttribute** aAttribute)
nsresult nsDOMAttributeMap::GetNamedItem(const nsString &aAttrName, nsIDOMNode** aAttribute)
{
nsAutoString value;
mContent.GetAttribute(aAttrName, value);
*aAttribute = new nsDOMAttribute(aAttrName, value);
*aAttribute = (nsIDOMNode *)new nsDOMAttribute(aAttrName, value);
return NS_OK;
}
nsresult nsDOMAttributeList::SetAttribute(nsIDOMAttribute *aAttribute)
nsresult nsDOMAttributeMap::SetNamedItem(nsIDOMNode *aNode)
{
nsIDOMAttribute *attribute;
nsAutoString name, value;
aAttribute->GetName(name);
aAttribute->GetValue(value);
nsresult err;
static NS_DEFINE_IID(kIDOMAttributeIID, NS_IDOMATTRIBUTE_IID);
if (NS_OK != (err = aNode->QueryInterface(kIDOMAttributeIID, (void **)&attribute))) {
return err;
}
attribute->GetName(name);
attribute->GetValue(value);
NS_RELEASE(attribute);
mContent.SetAttribute(name, value);
return NS_OK;
}
nsresult nsDOMAttributeList::Remove(nsString &attrName, nsIDOMAttribute** aAttribute)
NS_IMETHODIMP
nsDOMAttributeMap::RemoveNamedItem(const nsString& aName, nsIDOMNode** aReturn)
{
nsAutoString name, upper;
(*aAttribute)->GetName(name);
name.ToUpperCase(upper);
nsIAtom* attr = NS_NewAtom(upper);
mContent.UnsetAttribute(attr);
return NS_OK;
nsresult res = GetNamedItem(aName, aReturn);
if (NS_OK == res) {
nsAutoString upper;
aName.ToUpperCase(upper);
nsIAtom* attr = NS_NewAtom(upper);
mContent.UnsetAttribute(attr);
}
return res;
}
nsresult nsDOMAttributeList::Item(PRUint32 aIndex, nsIDOMAttribute** aAttribute)
nsresult nsDOMAttributeMap::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
{
nsresult res = NS_ERROR_FAILURE;
nsAutoString name, value;
@ -231,7 +349,7 @@ nsresult nsDOMAttributeList::Item(PRUint32 aIndex, nsIDOMAttribute** aAttribute)
if (nsnull != att && NS_OK == att->QueryInterface(kIAtom, (void**)&atName)) {
atName->ToString(name);
if (eContentAttr_NotThere != mContent.GetAttribute(name, value)) {
*aAttribute = new nsDOMAttribute(name, value);
*aReturn = (nsIDOMNode *)new nsDOMAttribute(name, value);
res = NS_OK;
}
NS_RELEASE(atName);
@ -244,7 +362,7 @@ nsresult nsDOMAttributeList::Item(PRUint32 aIndex, nsIDOMAttribute** aAttribute)
return res;
}
nsresult nsDOMAttributeList::GetLength(PRUint32 *aLength)
nsresult nsDOMAttributeMap::GetLength(PRUint32 *aLength)
{
*aLength = mContent.GetAttributeCount();
return NS_OK;

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

@ -20,7 +20,7 @@
#define nsDOMAttributes_h__
#include "nsIDOMAttribute.h"
#include "nsIDOMAttributeList.h"
#include "nsIDOMNamedNodeMap.h"
#include "nsIScriptObjectOwner.h"
class nsIContent;
@ -28,7 +28,7 @@ class nsIHTMLContent;
class nsDOMAttribute : public nsIDOMAttribute, public nsIScriptObjectOwner {
public:
nsDOMAttribute(nsString &aName, nsString &aValue);
nsDOMAttribute(const nsString &aName, const nsString &aValue);
virtual ~nsDOMAttribute();
NS_DECL_ISUPPORTS
@ -37,12 +37,29 @@ public:
NS_IMETHOD ResetScriptObject();
// nsIDOMAttribute interface
NS_IMETHOD GetName(nsString &aName);
NS_IMETHOD GetValue(nsString &aValue);
NS_IMETHOD SetValue(nsString &aValue);
NS_IMETHOD GetSpecified(PRBool *aSpecified);
NS_IMETHOD SetSpecified(PRBool specified);
NS_IMETHOD ToString(nsString &aString);
NS_IMETHOD GetSpecified(PRBool* aSpecified);
NS_IMETHOD SetSpecified(PRBool aSpecified);
NS_IMETHOD GetName(nsString& aReturn);
NS_IMETHOD GetValue(nsString& aReturn);
// nsIDOMNode interface
NS_IMETHOD GetNodeName(nsString& aNodeName);
NS_IMETHOD GetNodeValue(nsString& aNodeValue);
NS_IMETHOD SetNodeValue(const nsString& aNodeValue);
NS_IMETHOD GetNodeType(PRInt32* aNodeType);
NS_IMETHOD GetParentNode(nsIDOMNode** aParentNode);
NS_IMETHOD GetChildNodes(nsIDOMNodeList** aChildNodes);
NS_IMETHOD GetHasChildNodes(PRBool* aHasChildNodes);
NS_IMETHOD GetFirstChild(nsIDOMNode** aFirstChild);
NS_IMETHOD GetLastChild(nsIDOMNode** aLastChild);
NS_IMETHOD GetPreviousSibling(nsIDOMNode** aPreviousSibling);
NS_IMETHOD GetNextSibling(nsIDOMNode** aNextSibling);
NS_IMETHOD GetAttributes(nsIDOMNamedNodeMap** aAttributes);
NS_IMETHOD InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, nsIDOMNode** aReturn);
NS_IMETHOD ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, nsIDOMNode** aReturn);
NS_IMETHOD RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn);
NS_IMETHOD CloneNode(nsIDOMNode** aReturn);
NS_IMETHOD Equals(nsIDOMNode* aNode, PRBool aDeep, PRBool* aReturn);
private:
nsString *mName;
@ -51,22 +68,22 @@ private:
};
class nsDOMAttributeList : public nsIDOMAttributeList, public nsIScriptObjectOwner {
class nsDOMAttributeMap : public nsIDOMNamedNodeMap, public nsIScriptObjectOwner {
public:
nsDOMAttributeList(nsIHTMLContent &aContent);
virtual ~nsDOMAttributeList();
nsDOMAttributeMap(nsIHTMLContent &aContent);
virtual ~nsDOMAttributeMap();
NS_DECL_ISUPPORTS
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD ResetScriptObject();
// nsIDOMAttributeList interface
NS_IMETHOD GetAttribute(nsString &aAttrName, nsIDOMAttribute** aAttribute);
NS_IMETHOD SetAttribute(nsIDOMAttribute *aAttribute);
NS_IMETHOD Remove(nsString &attrName, nsIDOMAttribute** aAttribute);
NS_IMETHOD Item(PRUint32 aIndex, nsIDOMAttribute** aAttribute);
NS_IMETHOD GetLength(PRUint32 *aLength);
// nsIDOMNamedNodeMap interface
NS_IMETHOD GetLength(PRUint32* aSize);
NS_IMETHOD GetNamedItem(const nsString& aName, nsIDOMNode** aReturn);
NS_IMETHOD SetNamedItem(nsIDOMNode* aNode);
NS_IMETHOD RemoveNamedItem(const nsString& aName, nsIDOMNode** aReturn);
NS_IMETHOD Item(PRUint32 aIndex, nsIDOMNode** aReturn);
private:
nsIHTMLContent &mContent;

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

@ -0,0 +1,113 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsDOMNodeList.h"
#include "nsIDOMNode.h"
static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID);
nsDOMNodeList::nsDOMNodeList(nsIContent &aContent) : mContent(aContent)
{
mRefCnt = 1;
// keep the content alive so the array of children
// does not go away without "this" to know
mContent.AddRef();
mScriptObject = nsnull;
}
nsDOMNodeList::~nsDOMNodeList()
{
mContent.Release();
}
nsresult nsDOMNodeList::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIDOMNodeListIID, NS_IDOMNODELIST_IID);
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
if (aIID.Equals(kIDOMNodeListIID)) {
*aInstancePtr = (void*)(nsIDOMNodeList*)this;
AddRef();
return NS_OK;
}
if (aIID.Equals(kIScriptObjectOwnerIID)) {
*aInstancePtr = (void*)(nsIScriptObjectOwner*)this;
AddRef();
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
*aInstancePtr = (void*)(nsISupports*)(nsIDOMNodeList*)this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMPL_ADDREF(nsDOMNodeList)
NS_IMPL_RELEASE(nsDOMNodeList)
nsresult nsDOMNodeList::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
{
nsresult res = NS_OK;
if (nsnull == mScriptObject) {
res = NS_NewScriptNodeList(aContext, this, nsnull, (void**)&mScriptObject);
}
*aScriptObject = mScriptObject;
return res;
}
nsresult nsDOMNodeList::ResetScriptObject()
{
mScriptObject = nsnull;
return NS_OK;
}
// nsIDOMNodeList interface
NS_IMETHODIMP
nsDOMNodeList::GetLength(PRUint32* aLength)
{
*aLength = mContent.ChildCount();
return NS_OK;
}
NS_IMETHODIMP
nsDOMNodeList::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
{
nsIContent *content = nsnull;
nsresult res = NS_OK;
content = mContent.ChildAt(aIndex);
if (nsnull != content) {
res = content->QueryInterface(kIDOMNodeIID, (void**)aReturn);
NS_RELEASE(content);
}
else {
*aReturn = nsnull;
}
return res;
}

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

@ -0,0 +1,48 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsDOMNodeList_h__
#define nsDOMNodeList_h__
#include "nsIDOMNodeList.h"
#include "nsIContent.h"
#include "nsIScriptObjectOwner.h"
class nsDOMNodeList : public nsIDOMNodeList, public nsIScriptObjectOwner {
public:
nsDOMNodeList(nsIContent &aContent);
virtual ~nsDOMNodeList();
NS_DECL_ISUPPORTS
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD ResetScriptObject();
// nsIDOMNodeList interface
NS_IMETHOD GetLength(PRUint32* aLength);
NS_IMETHOD Item(PRUint32 aIndex, nsIDOMNode** aReturn);
private:
nsIContent &mContent;
void *mScriptObject;
};
#endif

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

@ -27,7 +27,7 @@
#include "nsHTMLIIDs.h"
#include "nsHTMLAtoms.h"
#include "nsIHTMLAttributes.h"
#include "nsDOMIterator.h"
#include "nsDOMNodeList.h"
#include "nsUnitConversion.h"
#include "nsIURL.h"
#include "prprf.h"
@ -842,14 +842,16 @@ nsHTMLContainer::MapBackgroundAttributesInto(nsIStyleContext* aContext,
static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID);
static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID);
nsresult nsHTMLContainer::GetChildNodes(nsIDOMNodeIterator **aIterator)
NS_IMETHODIMP
nsHTMLContainer::GetChildNodes(nsIDOMNodeList** aChildNodes)
{
NS_PRECONDITION(nsnull != aIterator, "null pointer");
*aIterator = new nsDOMIterator(*this);
NS_PRECONDITION(nsnull != aChildNodes, "null pointer");
*aChildNodes = new nsDOMNodeList(*this);
return NS_OK;
}
nsresult nsHTMLContainer::HasChildNodes(PRBool *aReturn)
NS_IMETHODIMP
nsHTMLContainer::GetHasChildNodes(PRBool* aReturn)
{
if (0 != mChildren.Count()) {
*aReturn = PR_TRUE;
@ -860,7 +862,8 @@ nsresult nsHTMLContainer::HasChildNodes(PRBool *aReturn)
return NS_OK;
}
nsresult nsHTMLContainer::GetFirstChild(nsIDOMNode **aNode)
NS_IMETHODIMP
nsHTMLContainer::GetFirstChild(nsIDOMNode **aNode)
{
nsIContent *child = (nsIContent*) mChildren.ElementAt(0);
if (nsnull != child) {
@ -875,6 +878,22 @@ nsresult nsHTMLContainer::GetFirstChild(nsIDOMNode **aNode)
}
}
NS_IMETHODIMP
nsHTMLContainer::GetLastChild(nsIDOMNode** aNode)
{
nsIContent *child = (nsIContent*) mChildren.ElementAt(mChildren.Count()-1);
if (nsnull != child) {
nsresult res = child->QueryInterface(kIDOMNodeIID, (void**)aNode);
NS_ASSERTION(NS_OK == res, "Must be a DOM Node"); // must be a DOM Node
return res;
}
else {
aNode = nsnull;
return NS_OK;
}
}
static void
SetDocumentInChildrenOf(nsIContent* aContent, nsIDocument* aDocument)
{
@ -893,19 +912,22 @@ SetDocumentInChildrenOf(nsIContent* aContent, nsIDocument* aDocument)
// tree; if this is the case then we need to remove it from where it
// was before placing it in it's new home
nsresult
nsHTMLContainer::InsertBefore(nsIDOMNode* newChild, nsIDOMNode* refChild)
NS_IMETHODIMP
nsHTMLContainer::InsertBefore(nsIDOMNode* aNewChild,
nsIDOMNode* aRefChild,
nsIDOMNode** aReturn)
{
if (nsnull == newChild) {
if (nsnull == aNewChild) {
*aReturn = nsnull;
return NS_OK;/* XXX wrong error value */
}
// Get the nsIContent interface for the new content
nsIContent* newContent = nsnull;
nsresult res = newChild->QueryInterface(kIContentIID, (void**)&newContent);
nsresult res = aNewChild->QueryInterface(kIContentIID, (void**)&newContent);
NS_ASSERTION(NS_OK == res, "New child must be an nsIContent");
if (NS_OK == res) {
if (nsnull == refChild) {
if (nsnull == aRefChild) {
// Append the new child to the end
SetDocumentInChildrenOf(newContent, mDocument);
res = AppendChild(newContent, PR_TRUE);
@ -913,7 +935,7 @@ nsHTMLContainer::InsertBefore(nsIDOMNode* newChild, nsIDOMNode* refChild)
else {
// Get the index of where to insert the new child
nsIContent* refContent = nsnull;
res = refChild->QueryInterface(kIContentIID, (void**)&refContent);
res = aRefChild->QueryInterface(kIContentIID, (void**)&refContent);
NS_ASSERTION(NS_OK == res, "Ref child must be an nsIContent");
if (NS_OK == res) {
PRInt32 pos = IndexOf(refContent);
@ -925,44 +947,59 @@ nsHTMLContainer::InsertBefore(nsIDOMNode* newChild, nsIDOMNode* refChild)
}
}
NS_RELEASE(newContent);
*aReturn = aNewChild;
NS_ADDREF(aNewChild);
}
else {
*aReturn = nsnull;
}
return res;
}
nsresult
nsHTMLContainer::ReplaceChild(nsIDOMNode *newChild, nsIDOMNode *oldChild)
NS_IMETHODIMP
nsHTMLContainer::ReplaceChild(nsIDOMNode* aNewChild,
nsIDOMNode* aOldChild,
nsIDOMNode** aReturn)
{
nsIContent* content = nsnull;
nsresult res = oldChild->QueryInterface(kIContentIID, (void**)&content);
*aReturn = nsnull;
nsresult res = aOldChild->QueryInterface(kIContentIID, (void**)&content);
NS_ASSERTION(NS_OK == res, "Must be an nsIContent");
if (NS_OK == res) {
PRInt32 pos = IndexOf(content);
if (pos >= 0) {
nsIContent* newContent = nsnull;
nsresult res = newChild->QueryInterface(kIContentIID, (void**)&newContent);
nsresult res = aNewChild->QueryInterface(kIContentIID, (void**)&newContent);
NS_ASSERTION(NS_OK == res, "Must be an nsIContent");
if (NS_OK == res) {
res = ReplaceChildAt(newContent, pos, PR_TRUE);
NS_RELEASE(newContent);
}
*aReturn = aOldChild;
NS_ADDREF(aOldChild);
}
NS_RELEASE(content);
}
return res;
}
nsresult
nsHTMLContainer::RemoveChild(nsIDOMNode *oldChild)
NS_IMETHODIMP
nsHTMLContainer::RemoveChild(nsIDOMNode* aOldChild,
nsIDOMNode** aReturn)
{
nsIContent* content = nsnull;
nsresult res = oldChild->QueryInterface(kIContentIID, (void**)&content);
*aReturn = nsnull;
nsresult res = aOldChild->QueryInterface(kIContentIID, (void**)&content);
NS_ASSERTION(NS_OK == res, "Must be an nsIContent");
if (NS_OK == res) {
PRInt32 pos = IndexOf(content);
if (pos >= 0) {
res = RemoveChildAt(pos, PR_TRUE);
*aReturn = aOldChild;
NS_ADDREF(aOldChild);
}
NS_RELEASE(content);
}

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

@ -49,13 +49,18 @@ public:
virtual void MapAttributesInto(nsIStyleContext* aContext,
nsIPresContext* aPresContext);
NS_IMETHOD GetChildNodes(nsIDOMNodeIterator **aIterator);
NS_IMETHOD HasChildNodes(PRBool *aReturn);
NS_IMETHOD GetFirstChild(nsIDOMNode **aNode);
NS_IMETHOD InsertBefore(nsIDOMNode *newChild, nsIDOMNode *refChild);
NS_IMETHOD ReplaceChild(nsIDOMNode *newChild,
nsIDOMNode *oldChild);
NS_IMETHOD RemoveChild(nsIDOMNode *oldChild);
NS_IMETHOD GetChildNodes(nsIDOMNodeList** aChildNodes);
NS_IMETHOD GetHasChildNodes(PRBool* aHasChildNodes);
NS_IMETHOD GetFirstChild(nsIDOMNode **aFirstChild);
NS_IMETHOD GetLastChild(nsIDOMNode** aLastChild);
NS_IMETHOD InsertBefore(nsIDOMNode* aNewChild,
nsIDOMNode* aRefChild,
nsIDOMNode** aReturn);
NS_IMETHOD ReplaceChild(nsIDOMNode* aNewChild,
nsIDOMNode* aOldChild,
nsIDOMNode** aReturn);
NS_IMETHOD RemoveChild(nsIDOMNode* aOldChild,
nsIDOMNode** aReturn);
protected:
nsHTMLContainer();

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

@ -462,40 +462,54 @@ nsresult nsHTMLContent::ResetScriptObject()
return NS_OK;
}
// nsIDOMNode interface
nsresult nsHTMLContent::GetParentNode(nsIDOMNode **aNode)
//
// Implementation of nsIDOMNode interface
//
NS_IMETHODIMP
nsHTMLContent::GetParentNode(nsIDOMNode** aParentNode)
{
if (nsnull != mParent) {
nsresult res = mParent->QueryInterface(kIDOMNodeIID, (void**)aNode);
nsresult res = mParent->QueryInterface(kIDOMNodeIID, (void**)aParentNode);
NS_ASSERTION(NS_OK == res, "Must be a DOM Node");
return res;
}
else {
*aNode = nsnull;
*aParentNode = nsnull;
}
return NS_OK;
}
nsresult nsHTMLContent::GetChildNodes(nsIDOMNodeIterator **aIterator)
NS_IMETHODIMP
nsHTMLContent::GetChildNodes(nsIDOMNodeList** aChildNodes)
{
*aIterator = nsnull;
*aChildNodes = nsnull;
return NS_OK;
}
nsresult nsHTMLContent::HasChildNodes(PRBool *aReturn)
NS_IMETHODIMP
nsHTMLContent::GetHasChildNodes(PRBool* aHasChildNodes)
{
*aReturn = PR_FALSE;
*aHasChildNodes = PR_FALSE;
return NS_OK;
}
nsresult nsHTMLContent::GetFirstChild(nsIDOMNode **aNode)
NS_IMETHODIMP
nsHTMLContent::GetFirstChild(nsIDOMNode** aFirstChild)
{
*aNode = nsnull;
*aFirstChild = nsnull;
return NS_OK;
}
nsresult nsHTMLContent::GetPreviousSibling(nsIDOMNode **aNode)
NS_IMETHODIMP
nsHTMLContent::GetLastChild(nsIDOMNode** aLastChild)
{
*aLastChild = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsHTMLContent::GetPreviousSibling(nsIDOMNode** aNode)
{
if (nsnull != mParent) {
PRInt32 pos = mParent->IndexOf(this);
@ -515,14 +529,15 @@ nsresult nsHTMLContent::GetPreviousSibling(nsIDOMNode **aNode)
return NS_ERROR_FAILURE;
}
nsresult nsHTMLContent::GetNextSibling(nsIDOMNode **aNode)
NS_IMETHODIMP
nsHTMLContent::GetNextSibling(nsIDOMNode** aNextSibling)
{
if (nsnull != mParent) {
PRInt32 pos = mParent->IndexOf(this);
if (pos > -1 ) {
nsIContent* prev = mParent->ChildAt(++pos);
if (nsnull != prev) {
nsresult res = prev->QueryInterface(kIDOMNodeIID, (void**)aNode);
nsresult res = prev->QueryInterface(kIDOMNodeIID, (void**)aNextSibling);
NS_ASSERTION(NS_OK == res, "Must be a DOM Node");
NS_RELEASE(prev); // balance the AddRef in ChildAt()
@ -534,18 +549,27 @@ nsresult nsHTMLContent::GetNextSibling(nsIDOMNode **aNode)
return NS_ERROR_FAILURE;
}
nsresult nsHTMLContent::InsertBefore(nsIDOMNode *newChild, nsIDOMNode *refChild)
NS_IMETHODIMP
nsHTMLContent::GetAttributes(nsIDOMNamedNodeMap** aAttributes)
{
aAttributes = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsHTMLContent::InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, nsIDOMNode** aReturn)
{
return NS_ERROR_FAILURE;
}
nsresult nsHTMLContent::ReplaceChild(nsIDOMNode *newChild,
nsIDOMNode *oldChild)
NS_IMETHODIMP
nsHTMLContent::ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, nsIDOMNode** aReturn)
{
return NS_ERROR_FAILURE;
}
nsresult nsHTMLContent::RemoveChild(nsIDOMNode *oldChild)
NS_IMETHODIMP
nsHTMLContent::RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn)
{
return NS_ERROR_FAILURE;
}

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

@ -119,15 +119,17 @@ public:
NS_IMETHOD ResetScriptObject();
// nsIDOMNode interface
NS_IMETHOD GetParentNode(nsIDOMNode **aNode);
NS_IMETHOD GetChildNodes(nsIDOMNodeIterator **aIterator);
NS_IMETHOD HasChildNodes(PRBool *aReturn);
NS_IMETHOD GetFirstChild(nsIDOMNode **aNode);
NS_IMETHOD GetPreviousSibling(nsIDOMNode **aNode);
NS_IMETHOD GetNextSibling(nsIDOMNode **aNode);
NS_IMETHOD InsertBefore(nsIDOMNode *newChild, nsIDOMNode *refChild);
NS_IMETHOD ReplaceChild(nsIDOMNode *newChild, nsIDOMNode *oldChild);
NS_IMETHOD RemoveChild(nsIDOMNode *oldChild);
NS_IMETHOD GetParentNode(nsIDOMNode** aParentNode);
NS_IMETHOD GetChildNodes(nsIDOMNodeList** aChildNodes);
NS_IMETHOD GetHasChildNodes(PRBool* aHasChildNodes);
NS_IMETHOD GetFirstChild(nsIDOMNode** aFirstChild);
NS_IMETHOD GetLastChild(nsIDOMNode** aLastChild);
NS_IMETHOD GetPreviousSibling(nsIDOMNode** aPreviousSibling);
NS_IMETHOD GetNextSibling(nsIDOMNode** aNextSibling);
NS_IMETHOD GetAttributes(nsIDOMNamedNodeMap** aAttributes);
NS_IMETHOD InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, nsIDOMNode** aReturn);
NS_IMETHOD ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, nsIDOMNode** aReturn);
NS_IMETHOD RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn);
// nsIDOMEventReceiver interface
NS_IMETHOD AddEventListener(nsIDOMEventListener *aListener, const nsIID& aIID);

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

@ -26,6 +26,7 @@
#include "nsString.h"
#include "prprf.h"
#include "nsDOMAttributes.h"
#include "nsIDOMDocument.h"
#include "nsILinkHandler.h"
#include "nsIPresContext.h"
#include "nsIURL.h"
@ -35,6 +36,7 @@
static NS_DEFINE_IID(kIStyleRuleIID, NS_ISTYLE_RULE_IID);
static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID);
static NS_DEFINE_IID(kIDOMDocumentIID, NS_IDOMDOCUMENT_IID);
static NS_DEFINE_IID(kIScriptObjectOwner, NS_ISCRIPTOBJECTOWNER_IID);
nsHTMLTagContent::nsHTMLTagContent()
@ -384,6 +386,9 @@ nsIStyleRule* nsHTMLTagContent::GetStyleRule(void)
return result;
}
//
// Implementation of nsIScriptObjectOwner interface
//
nsresult nsHTMLTagContent::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
{
nsresult res = NS_OK;
@ -394,90 +399,179 @@ nsresult nsHTMLTagContent::GetScriptObject(nsIScriptContext *aContext, void** aS
return res;
}
nsresult nsHTMLTagContent::GetNodeType(PRInt32 *aType)
//
// Implementation of nsIDOMNode interface
//
NS_IMETHODIMP
nsHTMLTagContent::GetNodeName(nsString& aNodeName)
{
return GetTagName(aNodeName);
}
NS_IMETHODIMP
nsHTMLTagContent::GetNodeValue(nsString& aNodeValue)
{
*aType = nsHTMLContent::ELEMENT;
return NS_OK;
}
nsresult nsHTMLTagContent::GetParentNode(nsIDOMNode **aNode)
NS_IMETHODIMP
nsHTMLTagContent::SetNodeValue(const nsString& aNodeValue)
{
return nsHTMLContent::GetParentNode(aNode);
}
nsresult nsHTMLTagContent::GetChildNodes(nsIDOMNodeIterator **aIterator)
{
return nsHTMLContent::GetChildNodes(aIterator);
}
nsresult nsHTMLTagContent::HasChildNodes(PRBool *aReturn)
{
return nsHTMLContent::HasChildNodes(aReturn);
}
nsresult nsHTMLTagContent::GetFirstChild(nsIDOMNode **aNode)
{
return nsHTMLContent::GetFirstChild(aNode);
}
nsresult nsHTMLTagContent::GetPreviousSibling(nsIDOMNode **aNode)
{
return nsHTMLContent::GetPreviousSibling(aNode);
}
nsresult nsHTMLTagContent::GetNextSibling(nsIDOMNode **aNode)
{
return nsHTMLContent::GetNextSibling(aNode);
}
nsresult nsHTMLTagContent::InsertBefore(nsIDOMNode *newChild, nsIDOMNode *refChild)
{
return nsHTMLContent::InsertBefore(newChild, refChild);
}
nsresult nsHTMLTagContent::ReplaceChild(nsIDOMNode *newChild, nsIDOMNode *oldChild)
{
return nsHTMLContent::ReplaceChild(newChild, oldChild);
}
nsresult nsHTMLTagContent::RemoveChild(nsIDOMNode *oldChild)
{
return nsHTMLContent::RemoveChild(oldChild);
}
nsresult nsHTMLTagContent::GetTagName(nsString &aName)
{
if (nsnull != mTag) {
mTag->ToString(aName);
}
return NS_OK;
}
nsresult nsHTMLTagContent::GetAttributes(nsIDOMAttributeList **aAttributeList)
NS_IMETHODIMP
nsHTMLTagContent::GetNodeType(PRInt32* aNodeType)
{
NS_PRECONDITION(nsnull != aAttributeList, "null pointer argument");
*aNodeType = nsHTMLContent::ELEMENT;
return NS_OK;
}
NS_IMETHODIMP
nsHTMLTagContent::GetAttributes(nsIDOMNamedNodeMap** aAttributes)
{
NS_PRECONDITION(nsnull != aAttributes, "null pointer argument");
if (nsnull != mAttributes) {
*aAttributeList = new nsDOMAttributeList(*this);
// XXX Should we create a new one every time or should we
// cache one after we create it? If we find that this is
// something that's called often, we might need to do the
// latter.
*aAttributes = new nsDOMAttributeMap(*this);
}
else {
*aAttributeList = nsnull;
*aAttributes = nsnull;
}
return NS_OK;
}
nsresult nsHTMLTagContent::GetDOMAttribute(nsString &aName, nsString &aValue)
// XXX Currently implemented as a call to document.CreateElement().
// This requires that the content actually have a document, which
// might not be the case if it isn't yet part of the tree.
NS_IMETHODIMP
nsHTMLTagContent::CloneNode(nsIDOMNode** aReturn)
{
GetAttribute(aName, aValue);
nsIDOMDocument *doc;
nsresult res = NS_OK;
nsAutoString tag_name;
nsIDOMNamedNodeMap *attr_map;
if ((nsnull == mDocument) || (nsnull == mTag)) {
return NS_ERROR_FAILURE;
}
res = mDocument->QueryInterface(kIDOMDocumentIID, (void **)&doc);
if (NS_OK != res) {
return res;
}
mTag->ToString(tag_name);
// XXX Probably not the most efficient way to pass along attribute
// information.
GetAttributes(&attr_map);
res = doc->CreateElement(tag_name, attr_map, (nsIDOMElement **)aReturn);
NS_RELEASE(doc);
return res;
}
NS_IMETHODIMP
nsHTMLTagContent::Equals(nsIDOMNode* aNode, PRBool aDeep, PRBool* aReturn)
{
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsHTMLTagContent::GetParentNode(nsIDOMNode** aParentNode)
{
return nsHTMLContent::GetParentNode(aParentNode);
}
NS_IMETHODIMP
nsHTMLTagContent::GetChildNodes(nsIDOMNodeList** aChildNodes)
{
return nsHTMLContent::GetChildNodes(aChildNodes);
}
NS_IMETHODIMP
nsHTMLTagContent::GetHasChildNodes(PRBool* aHasChildNodes)
{
return nsHTMLContent::GetHasChildNodes(aHasChildNodes);
}
NS_IMETHODIMP
nsHTMLTagContent::GetFirstChild(nsIDOMNode** aFirstChild)
{
return nsHTMLContent::GetFirstChild(aFirstChild);
}
NS_IMETHODIMP
nsHTMLTagContent::GetLastChild(nsIDOMNode** aLastChild)
{
return nsHTMLContent::GetLastChild(aLastChild);
}
NS_IMETHODIMP
nsHTMLTagContent::GetPreviousSibling(nsIDOMNode** aPreviousSibling)
{
return nsHTMLContent::GetPreviousSibling(aPreviousSibling);
}
NS_IMETHODIMP
nsHTMLTagContent::GetNextSibling(nsIDOMNode** aNextSibling)
{
return nsHTMLContent::GetNextSibling(aNextSibling);
}
NS_IMETHODIMP
nsHTMLTagContent::InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, nsIDOMNode** aReturn)
{
return nsHTMLContent::InsertBefore(aNewChild, aRefChild, aReturn);
}
NS_IMETHODIMP
nsHTMLTagContent::ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, nsIDOMNode** aReturn)
{
return nsHTMLContent::ReplaceChild(aNewChild, aOldChild, aReturn);
}
NS_IMETHODIMP
nsHTMLTagContent::RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn)
{
return nsHTMLContent::RemoveChild(aOldChild, aReturn);
}
//
// Implementation of nsIDOMElement interface
//
NS_IMETHODIMP
nsHTMLTagContent::GetTagName(nsString& aTagName)
{
if (nsnull != mTag) {
mTag->ToString(aTagName);
}
return NS_OK;
}
nsresult nsHTMLTagContent::SetDOMAttribute(nsString &aName, nsString &aValue)
NS_IMETHODIMP
nsHTMLTagContent::GetDOMAttribute(const nsString& aName, nsString& aReturn)
{
GetAttribute(aName, aReturn);
return NS_OK;
}
NS_IMETHODIMP
nsHTMLTagContent::SetDOMAttribute(const nsString& aName, const nsString& aValue)
{
SetAttribute(aName, aValue);
return NS_OK;
}
nsresult nsHTMLTagContent::RemoveAttribute(nsString &aName)
NS_IMETHODIMP
nsHTMLTagContent::RemoveAttribute(const nsString& aName)
{
nsAutoString upper;
aName.ToUpperCase(upper);
@ -486,17 +580,19 @@ nsresult nsHTMLTagContent::RemoveAttribute(nsString &aName)
return NS_OK;
}
nsresult nsHTMLTagContent::GetAttributeNode(nsString &aName, nsIDOMAttribute **aAttribute)
NS_IMETHODIMP
nsHTMLTagContent::GetAttributeNode(const nsString& aName, nsIDOMAttribute** aReturn)
{
nsAutoString value;
if(eContentAttr_NotThere != GetAttribute(aName, value)) {
*aAttribute = new nsDOMAttribute(aName, value);
*aReturn = new nsDOMAttribute(aName, value);
}
return NS_OK;
}
nsresult nsHTMLTagContent::SetAttributeNode(nsIDOMAttribute *aAttribute)
NS_IMETHODIMP
nsHTMLTagContent::SetAttributeNode(nsIDOMAttribute* aAttribute)
{
NS_PRECONDITION(nsnull != aAttribute, "null attribute");
@ -516,7 +612,8 @@ nsresult nsHTMLTagContent::SetAttributeNode(nsIDOMAttribute *aAttribute)
return res;
}
nsresult nsHTMLTagContent::RemoveAttributeNode(nsIDOMAttribute *aAttribute)
NS_IMETHODIMP
nsHTMLTagContent::RemoveAttributeNode(nsIDOMAttribute* aAttribute)
{
NS_PRECONDITION(nsnull != aAttribute, "null attribute");
@ -536,12 +633,14 @@ nsresult nsHTMLTagContent::RemoveAttributeNode(nsIDOMAttribute *aAttribute)
return res;
}
nsresult nsHTMLTagContent::Normalize()
NS_IMETHODIMP
nsHTMLTagContent::GetElementsByTagName(const nsString& aTagname, nsIDOMNodeList** aReturn)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsHTMLTagContent::GetElementsByTagName(nsString &aName,nsIDOMNodeIterator **aIterator)
NS_IMETHODIMP
nsHTMLTagContent::Normalize()
{
return NS_ERROR_NOT_IMPLEMENTED;
}

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

@ -89,30 +89,40 @@ public:
// nsIScriptObjectOwner interface
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
// nsIDOMElement interface
// nsISupports interface
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
NS_IMETHOD GetNodeType(PRInt32 *aType);
NS_IMETHOD GetParentNode(nsIDOMNode **aNode);
NS_IMETHOD GetChildNodes(nsIDOMNodeIterator **aIterator);
NS_IMETHOD HasChildNodes(PRBool *aReturn);
NS_IMETHOD GetFirstChild(nsIDOMNode **aNode);
NS_IMETHOD GetPreviousSibling(nsIDOMNode **aNode);
NS_IMETHOD GetNextSibling(nsIDOMNode **aNode);
NS_IMETHOD InsertBefore(nsIDOMNode *newChild, nsIDOMNode *refChild);
NS_IMETHOD ReplaceChild(nsIDOMNode *newChild, nsIDOMNode *oldChild);
NS_IMETHOD RemoveChild(nsIDOMNode *oldChild);
NS_IMETHOD GetTagName(nsString &aName);
NS_IMETHOD GetAttributes(nsIDOMAttributeList **aAttributeList);
NS_IMETHOD GetDOMAttribute(nsString &aName, nsString &aValue);
NS_IMETHOD SetDOMAttribute(nsString &aName, nsString &aValue);
NS_IMETHOD RemoveAttribute(nsString &aName);
NS_IMETHOD GetAttributeNode(nsString &aName, nsIDOMAttribute **aAttribute);
NS_IMETHOD SetAttributeNode(nsIDOMAttribute *aAttribute);
NS_IMETHOD RemoveAttributeNode(nsIDOMAttribute *aAttribute);
NS_IMETHOD GetElementsByTagName(nsString &aName,nsIDOMNodeIterator **aIterator);
NS_IMETHOD Normalize();
// nsIDOMNode interface
NS_IMETHOD GetNodeName(nsString& aNodeName);
NS_IMETHOD GetNodeValue(nsString& aNodeValue);
NS_IMETHOD SetNodeValue(const nsString& aNodeValue);
NS_IMETHOD GetNodeType(PRInt32* aNodeType);
NS_IMETHOD GetAttributes(nsIDOMNamedNodeMap** aAttributes);
NS_IMETHOD CloneNode(nsIDOMNode** aReturn);
NS_IMETHOD Equals(nsIDOMNode* aNode, PRBool aDeep, PRBool* aReturn);
NS_IMETHOD GetParentNode(nsIDOMNode** aParentNode);
NS_IMETHOD GetChildNodes(nsIDOMNodeList** aChildNodes);
NS_IMETHOD GetHasChildNodes(PRBool* aHasChildNodes);
NS_IMETHOD GetFirstChild(nsIDOMNode** aFirstChild);
NS_IMETHOD GetLastChild(nsIDOMNode** aLastChild);
NS_IMETHOD GetPreviousSibling(nsIDOMNode** aPreviousSibling);
NS_IMETHOD GetNextSibling(nsIDOMNode** aNextSibling);
NS_IMETHOD InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, nsIDOMNode** aReturn);
NS_IMETHOD ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, nsIDOMNode** aReturn);
NS_IMETHOD RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn);
// nsIDOMElement interface
NS_IMETHOD GetTagName(nsString& aTagName);
NS_IMETHOD GetDOMAttribute(const nsString& aName, nsString& aReturn);
NS_IMETHOD SetDOMAttribute(const nsString& aName, const nsString& aValue);
NS_IMETHOD RemoveAttribute(const nsString& aName);
NS_IMETHOD GetAttributeNode(const nsString& aName, nsIDOMAttribute** aReturn);
NS_IMETHOD SetAttributeNode(nsIDOMAttribute* aNewAttr);
NS_IMETHOD RemoveAttributeNode(nsIDOMAttribute* aOldAttr);
NS_IMETHOD GetElementsByTagName(const nsString& aTagname, nsIDOMNodeList** aReturn);
NS_IMETHOD Normalize();
NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext,
nsGUIEvent* aEvent,

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

@ -251,25 +251,39 @@ public:
// nsIScriptObjectOwner interface
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
// nsIDOMNode interface
NS_IMETHOD GetNodeName(nsString& aNodeName);
NS_IMETHOD GetNodeValue(nsString& aNodeValue);
NS_IMETHOD SetNodeValue(const nsString& aNodeValue);
NS_IMETHOD GetNodeType(PRInt32* aNodeType);
NS_IMETHOD CloneNode(nsIDOMNode** aReturn);
NS_IMETHOD Equals(nsIDOMNode* aNode, PRBool aDeep, PRBool* aReturn);
NS_IMETHOD GetAttributes(nsIDOMNamedNodeMap** aAttributes);
NS_IMETHOD GetParentNode(nsIDOMNode** aParentNode);
NS_IMETHOD GetChildNodes(nsIDOMNodeList** aChildNodes);
NS_IMETHOD GetHasChildNodes(PRBool* aHasChildNodes);
NS_IMETHOD GetFirstChild(nsIDOMNode** aFirstChild);
NS_IMETHOD GetLastChild(nsIDOMNode** aLastChild);
NS_IMETHOD GetPreviousSibling(nsIDOMNode** aPreviousSibling);
NS_IMETHOD GetNextSibling(nsIDOMNode** aNextSibling);
NS_IMETHOD InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, nsIDOMNode** aReturn);
NS_IMETHOD ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, nsIDOMNode** aReturn);
NS_IMETHOD RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn);
// nsIDOMData interface
NS_IMETHOD GetData(nsString& aData);
NS_IMETHOD SetData(const nsString& aData);
NS_IMETHOD GetSize(PRUint32* aSize);
NS_IMETHOD Substring(PRUint32 aStart, PRUint32 aEnd, nsString& aReturn);
NS_IMETHOD Append(const nsString& aData);
NS_IMETHOD Insert(PRUint32 aOffset, const nsString& aData);
NS_IMETHOD Remove(PRUint32 aOffset, PRUint32 aCount);
NS_IMETHOD Replace(PRUint32 aOffset, PRUint32 aCount,
const nsString& aData);
// nsIDOMText interface
NS_IMETHOD GetNodeType(PRInt32 *aType);
NS_IMETHOD GetParentNode(nsIDOMNode **aNode);
NS_IMETHOD GetChildNodes(nsIDOMNodeIterator **aIterator);
NS_IMETHOD HasChildNodes(PRBool *aReturn);
NS_IMETHOD GetFirstChild(nsIDOMNode **aNode);
NS_IMETHOD GetPreviousSibling(nsIDOMNode **aNode);
NS_IMETHOD GetNextSibling(nsIDOMNode **aNode);
NS_IMETHOD InsertBefore(nsIDOMNode *newChild, nsIDOMNode *refChild);
NS_IMETHOD ReplaceChild(nsIDOMNode *newChild,
nsIDOMNode *oldChild);
NS_IMETHOD RemoveChild(nsIDOMNode *oldChild);
NS_IMETHOD GetData(nsString& aString);
NS_IMETHOD SetData(nsString& aString);
NS_IMETHOD Append(nsString& aData);
NS_IMETHOD Insert(PRInt32 offset, nsString& aData);
NS_IMETHOD Delete(PRInt32 offset, PRInt32 count);
NS_IMETHOD Replace(PRInt32 offset, PRInt32 count, nsString& aData);
NS_IMETHOD Splice(nsIDOMElement *element, PRInt32 offset, PRInt32 count);
NS_IMETHOD SplitText(PRUint32 aOffset, nsIDOMText** aReturn);
NS_IMETHOD JoinText(nsIDOMText* aNode1, nsIDOMText* aNode2, nsIDOMText** aReturn);
void ToCString(nsString& aBuf, PRInt32 aOffset, PRInt32 aLen) const;
@ -1328,6 +1342,7 @@ TextFrame::List(FILE* out, PRInt32 aIndent) const
//----------------------------------------------------------------------
static NS_DEFINE_IID(kIDOMTextIID, NS_IDOMTEXT_IID);
static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
Text::Text(const PRUnichar* aText, PRInt32 aLength)
@ -1373,6 +1388,11 @@ nsresult Text::QueryInterface(const nsIID& aIID, void** aInstancePtr)
nsHTMLContent::AddRef();
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
*aInstancePtr = (void*)(nsISupports*)(nsIDOMText*)this;
nsHTMLContent::AddRef();
return NS_OK;
}
return nsHTMLContent::QueryInterface(aIID, aInstancePtr);
}
@ -1477,76 +1497,147 @@ nsresult Text::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
//
// nsIDOMText interface
//
nsresult Text::GetNodeType(PRInt32 *aType)
NS_IMETHODIMP
Text::GetNodeName(nsString& aNodeName)
{
*aType = nsHTMLContent::TEXT;
aNodeName.SetString("#text");
return NS_OK;
}
nsresult Text::GetParentNode(nsIDOMNode **aNode)
NS_IMETHODIMP
Text::GetNodeValue(nsString& aNodeValue)
{
return nsHTMLContent::GetParentNode(aNode);
return GetData(aNodeValue);
}
nsresult Text::GetChildNodes(nsIDOMNodeIterator **aIterator)
NS_IMETHODIMP
Text::SetNodeValue(const nsString& aNodeValue)
{
return nsHTMLContent::GetChildNodes(aIterator);
return SetData(aNodeValue);
}
nsresult Text::HasChildNodes(PRBool *aReturn)
NS_IMETHODIMP
Text::GetNodeType(PRInt32* aNodeType)
{
return nsHTMLContent::HasChildNodes(aReturn);
*aNodeType = nsHTMLContent::TEXT;
return NS_OK;
}
nsresult Text::GetFirstChild(nsIDOMNode **aNode)
NS_IMETHODIMP
Text::CloneNode(nsIDOMNode** aReturn)
{
return nsHTMLContent::GetFirstChild(aNode);
Text *newText;
nsresult res;
res = NS_NewHTMLText((nsIHTMLContent**)&newText, mText, mLength);
if (NS_OK != res) {
return res;
}
res = newText->QueryInterface(kIDOMTextIID, (void **)aReturn);
NS_RELEASE(newText);
if (NS_OK != res) {
return res;
}
return NS_OK;
}
nsresult Text::GetPreviousSibling(nsIDOMNode **aNode)
NS_IMETHODIMP
Text::Equals(nsIDOMNode* aNode, PRBool aDeep, PRBool* aReturn)
{
return nsHTMLContent::GetPreviousSibling(aNode);
// XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult Text::GetNextSibling(nsIDOMNode **aNode)
NS_IMETHODIMP
Text::GetAttributes(nsIDOMNamedNodeMap** aAttributes)
{
return nsHTMLContent::GetNextSibling(aNode);
return nsHTMLContent::GetAttributes(aAttributes);
}
nsresult Text::InsertBefore(nsIDOMNode *newChild, nsIDOMNode *refChild)
NS_IMETHODIMP
Text::GetParentNode(nsIDOMNode** aParentNode)
{
return nsHTMLContent::InsertBefore(newChild, refChild);
return nsHTMLContent::GetParentNode(aParentNode);
}
nsresult Text::ReplaceChild(nsIDOMNode *newChild, nsIDOMNode *oldChild)
NS_IMETHODIMP
Text::GetChildNodes(nsIDOMNodeList** aChildNodes)
{
return nsHTMLContent::ReplaceChild(newChild, oldChild);
return nsHTMLContent::GetChildNodes(aChildNodes);
}
nsresult Text::RemoveChild(nsIDOMNode *oldChild)
NS_IMETHODIMP
Text::GetHasChildNodes(PRBool* aHasChildNodes)
{
return nsHTMLContent::RemoveChild(oldChild);
return nsHTMLContent::GetHasChildNodes(aHasChildNodes);
}
nsresult
Text::GetData(nsString& aString)
NS_IMETHODIMP
Text::GetFirstChild(nsIDOMNode** aFirstChild)
{
return nsHTMLContent::GetFirstChild(aFirstChild);
}
NS_IMETHODIMP
Text::GetLastChild(nsIDOMNode** aLastChild)
{
return nsHTMLContent::GetLastChild(aLastChild);
}
NS_IMETHODIMP
Text::GetPreviousSibling(nsIDOMNode** aPreviousSibling)
{
return nsHTMLContent::GetPreviousSibling(aPreviousSibling);
}
NS_IMETHODIMP
Text::GetNextSibling(nsIDOMNode** aNextSibling)
{
return nsHTMLContent::GetNextSibling(aNextSibling);
}
NS_IMETHODIMP
Text::InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, nsIDOMNode** aReturn)
{
return nsHTMLContent::InsertBefore(aNewChild, aRefChild, aReturn);
}
NS_IMETHODIMP
Text::ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, nsIDOMNode** aReturn)
{
return nsHTMLContent::ReplaceChild(aNewChild, aOldChild, aReturn);
}
NS_IMETHODIMP
Text::RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn)
{
return nsHTMLContent::RemoveChild(aOldChild, aReturn);
}
//
// nsIDOMData interface
//
NS_IMETHODIMP
Text::GetData(nsString& aData)
{
if (nsnull != mText) {
aString.SetString(mText, mLength);
aData.SetString(mText, mLength);
}
return NS_OK;
}
nsresult
Text::SetData(nsString& aString)
NS_IMETHODIMP
Text::SetData(const nsString& aData)
{
if (mText) {
delete[] mText;
mText = nsnull;
}
mLength = aString.Length();
mText = aString.ToNewUnicode();
mLength = aData.Length();
mText = aData.ToNewUnicode();
// Notify the document that the text changed
if (nsnull != mDocument) {
@ -1555,62 +1646,81 @@ Text::SetData(nsString& aString)
return NS_OK;
}
nsresult
Text::Append(nsString& aData)
NS_IMETHODIMP
Text::GetSize(PRUint32* aSize)
{
*aSize = mLength;
return NS_OK;
}
NS_IMETHODIMP
Text::Substring(PRUint32 aStart, PRUint32 aEnd, nsString& aReturn)
{
if (nsnull != mText) {
if ((aStart < (PRUint32)mLength) && (aEnd < (PRUint32)mLength)) {
aReturn.SetString(mText + aStart, (aEnd - aStart));
}
}
return NS_OK;
}
NS_IMETHODIMP
Text::Append(const nsString& aData)
{
return Replace(mLength, 0, aData);
}
nsresult
Text::Insert(PRInt32 offset, nsString& aData)
NS_IMETHODIMP
Text::Insert(PRUint32 aOffset, const nsString& aData)
{
return Replace(offset, 0, aData);
return Replace(aOffset, 0, aData);
}
nsresult
Text::Delete(PRInt32 offset, PRInt32 count)
NS_IMETHODIMP
Text::Remove(PRUint32 aOffset, PRUint32 aCount)
{
nsAutoString empty;
return Replace(offset, count, empty);
return Replace(aOffset, aCount, empty);
}
nsresult
Text::Replace(PRInt32 offset, PRInt32 count, nsString& aData)
NS_IMETHODIMP
Text::Replace(PRUint32 aOffset, PRUint32 aCount, const nsString& aData)
{
// sanitize arguments
if (offset < 0) {
offset = 0;
if (aOffset < 0) {
aOffset = 0;
}
if (offset > mLength) {
offset = mLength;
if (aOffset > (PRUint32)mLength) {
aOffset = mLength;
}
if (count < 0) {
count = 0;
if (aCount < 0) {
aCount = 0;
}
// Allocate new buffer
PRInt32 endOffset = offset + count;
PRInt32 endOffset = aOffset + aCount;
if (endOffset > mLength) {
count = mLength - offset;
aCount = mLength - aOffset;
endOffset = mLength;
}
PRInt32 dataLength = aData.Length();
PRInt32 newLength = mLength - count + dataLength;
PRInt32 newLength = mLength - aCount + dataLength;
PRUnichar* to = new PRUnichar[newLength ? newLength : 1];
if (nsnull == to) {
return NS_ERROR_OUT_OF_MEMORY;
}
// Copy over appropriate data
if (0 != offset) {
nsCRT::memcpy(to, mText, sizeof(PRUnichar) * offset);
if (0 != aOffset) {
nsCRT::memcpy(to, mText, sizeof(PRUnichar) * aOffset);
}
if (0 != dataLength) {
nsCRT::memcpy(to + offset, aData.GetUnicode(),
nsCRT::memcpy(to + aOffset, aData.GetUnicode(),
sizeof(PRUnichar) * dataLength);
}
if (endOffset != mLength) {
nsCRT::memcpy(to + offset + dataLength, mText + endOffset,
nsCRT::memcpy(to + aOffset + dataLength, mText + endOffset,
sizeof(PRUnichar) * (mLength - endOffset));
}
@ -1629,8 +1739,15 @@ Text::Replace(PRInt32 offset, PRInt32 count, nsString& aData)
return NS_OK;
}
nsresult
Text::Splice(nsIDOMElement* element, PRInt32 offset, PRInt32 count)
// nsIDOMText interface
NS_IMETHODIMP
Text::SplitText(PRUint32 aOffset, nsIDOMText** aReturn)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
Text::JoinText(nsIDOMText* aNode1, nsIDOMText* aNode2, nsIDOMText** aReturn)
{
return NS_ERROR_NOT_IMPLEMENTED;
}

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

@ -244,22 +244,22 @@ void nsHTMLDocument::AddStyleSheetToSet(nsIStyleSheet* aSheet, nsIStyleSet* aSet
}
}
nsresult
nsHTMLDocument::CreateElement(nsString& aTagName,
nsIDOMAttributeList* aAttributes,
nsIDOMElement** aElement)
NS_IMETHODIMP
nsHTMLDocument::CreateElement(const nsString& aTagName,
nsIDOMNamedNodeMap* aAttributes,
nsIDOMElement** aReturn)
{
nsIHTMLContent* content;
nsresult rv = NS_CreateHTMLElement(&content, aTagName);
if (NS_OK != rv) {
return rv;
}
rv = content->QueryInterface(kIDOMElementIID, (void**)aElement);
rv = content->QueryInterface(kIDOMElementIID, (void**)aReturn);
return rv;
}
nsresult
nsHTMLDocument::CreateTextNode(nsString &aData, nsIDOMText** aTextNode)
NS_IMETHODIMP
nsHTMLDocument::CreateTextNode(const nsString& aData, nsIDOMText** aTextNode)
{
nsIHTMLContent* text = nsnull;
nsresult rv = NS_NewHTMLText(&text, aData, aData.Length());

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

@ -46,10 +46,10 @@ public:
return offsetof(nsHTMLDocument,mIHTMLDocument);
}
NS_IMETHOD CreateElement(nsString &aTagName,
nsIDOMAttributeList *aAttributes,
nsIDOMElement **aElement);
NS_IMETHOD CreateTextNode(nsString &aData, nsIDOMText** aTextNode);
NS_IMETHOD CreateElement(const nsString& aTagName,
nsIDOMNamedNodeMap* aAttributes,
nsIDOMElement** aReturn);
NS_IMETHOD CreateTextNode(const nsString& aData, nsIDOMText** aReturn);
protected:
virtual void AddStyleSheetToSet(nsIStyleSheet* aSheet, nsIStyleSet* aSet);

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

@ -25,19 +25,19 @@ function trace(msg)
function findBody(node)
{
var children = node.getChildNodes();
var length = children.getLength();
var child = children.getNextNode();
var children = node.childNodes;
var length = children.length;
var child = null;
var count = 0;
while (count < length) {
if (child.getTagName() == "BODY") {
child = children.item(count);
if (child.tagName == "BODY") {
return child;
}
var body = findBody(child);
if (null != body) {
return body;
}
child = children.getNextNode();
count++;
}
return null;

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

@ -27,66 +27,54 @@ function dump2(msg, parent, child)
{
dump(msg);
dump(" parent=");
dump(parent.getTagName());
dump(parent.tagName);
dump(" child=");
dump((child.getNodeType() != Node.TEXT) ? child.getTagName() : "(text)");
dump((child.nodeType != Node.TEXT) ? child.tagName : "(text)");
dump(" kids: ");
var children = parent.getChildNodes();
var length = children.getLength();
var child = children.getNextNode();
var children = parent.childNodes;
var length = children.length;
var child = null;
var count = 0;
while (count < length) {
dump((child.getNodeType() != Node.TEXT) ? child.getTagName() : "(text)");
child = children.item(count);
dump((child.nodeType != Node.TEXT) ? child.tagName : "(text)");
dump(",");
count++;
child = children.getNextNode();
}
dump("\n");
}
function nthChildOf(node, n)
{
var children = node.getChildNodes();
var length = children.getLength();
var child = children.getNextNode();
var count = 0;
while ((count < length) && (count < n)) {
count++;
child = children.getNextNode();
}
return child;
}
function firstChildOf(node)
{
var children = node.getChildNodes();
return nthChildOf(node, 0);
return node.childNodes.item(0);
}
function middleChildOf(node)
{
var children = node.getChildNodes();
return nthChildOf(node, Math.floor(children.getLength() / 2));
var children = node.childNodes;
return children.item(Math.floor(children.length / 2));
}
function lastChildOf(node)
{
var children = node.getChildNodes();
return nthChildOf(node, children.getLength() - 1)
var children = node.childNodes;
return children.item(children.length - 1)
}
function findContainer(node, name)
{
dump("Looking in " + node.getTagName() + " for " + name + "\n");
var children = node.getChildNodes();
var length = children.getLength();
var child = children.getNextNode();
dump("Looking in " + node.tagName + " for " + name + "\n");
var children = node.childNodes;
var length = children.length;
var child = null;
var count = 0;
while (count < length) {
if (child.getNodeType() != Node.TEXT) {
if (child.getTagName() == name) {
child = children.item(count);
if (child.nodeType != Node.TEXT) {
if (child.tagName == name) {
return child;
}
var body = findContainer(child, name);
@ -94,7 +82,6 @@ function findContainer(node, name)
return body;
}
}
child = children.getNextNode();
count++;
}
return null;

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше