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
Родитель 33ff9893e2
Коммит ef2bd5eb2a
109 изменённых файлов: 5389 добавлений и 3257 удалений

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

@ -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__

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

@ -0,0 +1,42 @@
/* -*- 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 nsIDOMCDATASection_h__
#define nsIDOMCDATASection_h__
#include "nsISupports.h"
#include "nsString.h"
#include "nsIScriptContext.h"
#include "nsIDOMText.h"
class nsIDOMCDATASection;
#define NS_IDOMCDATASECTION_IID \
{ 0x6f7652e1, 0xee43, 0x11d1, \
{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }
class nsIDOMCDATASection : public nsIDOMText {
public:
};
extern nsresult NS_InitCDATASectionClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM nsresult NS_NewScriptCDATASection(nsIScriptContext *aContext, nsIDOMCDATASection *aSupports, nsISupports *aParent, void **aReturn);
#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__

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

@ -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 nsIDOMDocumentType_h__
#define nsIDOMDocumentType_h__
#include "nsISupports.h"
#include "nsString.h"
#include "nsIScriptContext.h"
class nsIDOMNamedNodeMap;
class nsIDOMDocumentType;
#define NS_IDOMDOCUMENTTYPE_IID \
{ 0x6f7652e6, 0xee43, 0x11d1, \
{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }
class nsIDOMDocumentType : public nsISupports {
public:
NS_IMETHOD GetName(nsString& aName)=0;
NS_IMETHOD SetName(const nsString& aName)=0;
NS_IMETHOD GetEntities(nsIDOMNamedNodeMap** aEntities)=0;
NS_IMETHOD SetEntities(nsIDOMNamedNodeMap* aEntities)=0;
};
extern nsresult NS_InitDocumentTypeClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM nsresult NS_NewScriptDocumentType(nsIScriptContext *aContext, nsIDOMDocumentType *aSupports, nsISupports *aParent, void **aReturn);
#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__

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

@ -0,0 +1,52 @@
/* -*- 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 nsIDOMNamedNodeMap_h__
#define nsIDOMNamedNodeMap_h__
#include "nsISupports.h"
#include "nsString.h"
#include "nsIScriptContext.h"
class nsIDOMNamedNodeMap;
class nsIDOMNode;
#define NS_IDOMNAMEDNODEMAP_IID \
{ 0x6f7652e9, 0xee43, 0x11d1, \
{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }
class nsIDOMNamedNodeMap : public nsISupports {
public:
NS_IMETHOD GetLength(PRUint32* aLength)=0;
NS_IMETHOD GetNamedItem(const nsString& aName, nsIDOMNode** aReturn)=0;
NS_IMETHOD SetNamedItem(nsIDOMNode* aNode)=0;
NS_IMETHOD RemoveNamedItem(const nsString& aName, nsIDOMNode** aReturn)=0;
NS_IMETHOD Item(PRUint32 aIndex, nsIDOMNode** aReturn)=0;
};
extern nsresult NS_InitNamedNodeMapClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM nsresult NS_NewScriptNamedNodeMap(nsIScriptContext *aContext, nsIDOMNamedNodeMap *aSupports, nsISupports *aParent, void **aReturn);
#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__

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

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

@ -0,0 +1,46 @@
/* -*- 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 nsIDOMNodeList_h__
#define nsIDOMNodeList_h__
#include "nsISupports.h"
#include "nsString.h"
#include "nsIScriptContext.h"
class nsIDOMNode;
class nsIDOMNodeList;
#define NS_IDOMNODELIST_IID \
{ 0x6f7652eb, 0xee43, 0x11d1, \
{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }
class nsIDOMNodeList : public nsISupports {
public:
NS_IMETHOD GetLength(PRUint32* aLength)=0;
NS_IMETHOD Item(PRUint32 aIndex, nsIDOMNode** aReturn)=0;
};
extern nsresult NS_InitNodeListClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM nsresult NS_NewScriptNodeList(nsIScriptContext *aContext, nsIDOMNodeList *aSupports, nsISupports *aParent, void **aReturn);
#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,6 +0,0 @@
interface Attribute {
wstring getName();
attribute wstring value;
attribute boolean specified;
wstring toString();
};

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

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

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

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

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

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

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

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

@ -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 +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 {};
};

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

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

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

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

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

@ -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);
};

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

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

@ -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

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

@ -1,988 +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.
*/
#include "nscore.h"
#include "prmem.h"
#include "prtime.h"
#include "plstr.h"
#include "prinrval.h"
#include "nsIFactory.h"
#include "nsISupports.h"
#include "nsIScriptContext.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsIDOMWindow.h"
#include "nsIDOMDocument.h"
#include "nsIDOMNavigator.h"
#include "nsINetService.h"
#include "nsINetContainerApplication.h"
#include "nsITimer.h"
#include "jsapi.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIDOMWindowIID, NS_IDOMWINDOW_IID);
static NS_DEFINE_IID(kIDOMNavigatorIID, NS_IDOMNAVIGATOR_IID);
typedef struct nsTimeoutImpl nsTimeoutImpl;
// Global object for scripting
class GlobalWindowImpl : public nsIScriptObjectOwner, public nsIScriptGlobalObject, public nsIDOMWindow
{
public:
GlobalWindowImpl();
~GlobalWindowImpl();
NS_DECL_ISUPPORTS
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD ResetScriptObject();
NS_IMETHOD_(void) SetContext(nsIScriptContext *aContext);
NS_IMETHOD_(void) SetNewDocument(nsIDOMDocument *aDocument);
NS_IMETHOD GetWindow(nsIDOMWindow** aWindow);
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 ClearTimeout(PRInt32 aTimerID);
NS_IMETHOD ClearInterval(PRInt32 aTimerID);
NS_IMETHOD SetTimeout(JSContext *cx, jsval *argv, PRUint32 argc,
PRInt32* aReturn);
NS_IMETHOD SetInterval(JSContext *cx, jsval *argv, PRUint32 argc,
PRInt32* aReturn);
friend void nsGlobalWindow_RunTimeout(nsITimer *aTimer, void *aClosure);
protected:
void RunTimeout(nsTimeoutImpl *aTimeout);
nsresult ClearTimeoutOrInterval(PRInt32 aTimerID);
nsresult SetTimeoutOrInterval(JSContext *cx, jsval *argv,
PRUint32 argc, PRInt32* aReturn,
PRBool aIsInterval);
void InsertTimeoutIntoList(nsTimeoutImpl **aInsertionPoint,
nsTimeoutImpl *aTimeout);
void ClearAllTimeouts();
void DropTimeout(nsTimeoutImpl *aTimeout);
void HoldTimeout(nsTimeoutImpl *aTimeout);
nsIScriptContext *mContext;
void *mScriptObject;
nsIDOMDocument *mDocument;
nsIDOMNavigator *mNavigator;
nsTimeoutImpl *mTimeouts;
nsTimeoutImpl **mTimeoutInsertionPoint;
nsTimeoutImpl *mRunningTimeout;
PRUint32 mTimeoutPublicIdCounter;
};
/*
* Timeout struct that holds information about each JavaScript
* timeout.
*/
struct nsTimeoutImpl {
PRInt32 ref_count; /* reference count to shared usage */
GlobalWindowImpl *window; /* window for which this timeout fires */
char *expr; /* the JS expression to evaluate */
JSObject *funobj; /* or function to call, if !expr */
nsITimer *timer; /* The actual timer object */
jsval *argv; /* function actual arguments */
PRUint16 argc; /* and argument count */
PRUint16 spare; /* alignment padding */
PRUint32 public_id; /* Returned as value of setTimeout() */
PRInt32 interval; /* Non-zero if repetitive timeout */
PRInt64 when; /* nominal time to run this timeout */
JSVersion version; /* Version of JavaScript to execute */
JSPrincipals *principals; /* principals with which to execute */
char *filename; /* filename of setTimeout call */
PRUint32 lineno; /* line number of setTimeout call */
nsTimeoutImpl *next;
};
// Script "navigator" object
class NavigatorImpl : public nsIScriptObjectOwner, public nsIDOMNavigator {
public:
NavigatorImpl();
~NavigatorImpl();
NS_DECL_ISUPPORTS
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD ResetScriptObject();
NS_IMETHOD GetUserAgent(nsString& aUserAgent);
NS_IMETHOD GetAppCodeName(nsString& aAppCodeName);
NS_IMETHOD GetAppVersion(nsString& aAppVersion);
NS_IMETHOD GetAppName(nsString& aAppName);
NS_IMETHOD GetLanguage(nsString& aLanguage);
NS_IMETHOD GetPlatform(nsString& aPlatform);
NS_IMETHOD GetSecurityPolicy(nsString& aSecurityPolicy);
NS_IMETHOD JavaEnabled(PRBool* aReturn);
protected:
void *mScriptObject;
};
GlobalWindowImpl::GlobalWindowImpl()
{
mContext = nsnull;
mScriptObject = nsnull;
mDocument = nsnull;
mNavigator = nsnull;
mTimeouts = nsnull;
mTimeoutInsertionPoint = nsnull;
mRunningTimeout = nsnull;
mTimeoutPublicIdCounter = 1;
}
GlobalWindowImpl::~GlobalWindowImpl()
{
if (nsnull != mScriptObject) {
JS_RemoveRoot((JSContext *)mContext->GetNativeContext(), &mScriptObject);
mScriptObject = nsnull;
}
if (nsnull != mContext) {
NS_RELEASE(mContext);
}
if (nsnull != mDocument) {
NS_RELEASE(mDocument);
}
NS_IF_RELEASE(mNavigator);
}
NS_IMPL_ADDREF(GlobalWindowImpl)
NS_IMPL_RELEASE(GlobalWindowImpl)
nsresult
GlobalWindowImpl::QueryInterface(const nsIID& aIID,
void** aInstancePtrResult)
{
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
if (nsnull == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kIScriptObjectOwnerIID)) {
*aInstancePtrResult = (void*) ((nsIScriptObjectOwner*)this);
AddRef();
return NS_OK;
}
if (aIID.Equals(kIScriptGlobalObjectIID)) {
*aInstancePtrResult = (void*) ((nsIScriptGlobalObject*)this);
AddRef();
return NS_OK;
}
if (aIID.Equals(kIDOMWindowIID)) {
*aInstancePtrResult = (void*) ((nsIDOMWindow*)this);
AddRef();
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
*aInstancePtrResult = (void*)(nsISupports*)(nsIScriptGlobalObject*)this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
nsresult
GlobalWindowImpl::ResetScriptObject()
{
mScriptObject = nsnull;
return NS_OK;
}
nsresult
GlobalWindowImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
{
NS_PRECONDITION(nsnull != aScriptObject, "null arg");
nsresult res = NS_OK;
if (nsnull == mScriptObject) {
res = NS_NewScriptWindow(aContext, this, nsnull, &mScriptObject);
JS_AddNamedRoot((JSContext *)aContext->GetNativeContext(),
&mScriptObject, "window_object");
}
*aScriptObject = mScriptObject;
return res;
}
NS_IMETHODIMP_(void)
GlobalWindowImpl::SetContext(nsIScriptContext *aContext)
{
if (mContext) {
NS_RELEASE(mContext);
}
mContext = aContext;
NS_ADDREF(mContext);
}
NS_IMETHODIMP_(void)
GlobalWindowImpl::SetNewDocument(nsIDOMDocument *aDocument)
{
if (nsnull != mDocument) {
ClearAllTimeouts();
if (nsnull != mScriptObject) {
JS_ClearScope((JSContext *)mContext->GetNativeContext(),
(JSObject *)mScriptObject);
}
NS_RELEASE(mDocument);
}
mDocument = aDocument;
if (nsnull != mDocument) {
NS_ADDREF(mDocument);
if (nsnull != mContext) {
mContext->InitContext(this);
}
}
JS_GC((JSContext *)mContext->GetNativeContext());
}
NS_IMETHODIMP
GlobalWindowImpl::GetWindow(nsIDOMWindow** aWindow)
{
*aWindow = this;
NS_ADDREF(this);
return NS_OK;
}
NS_IMETHODIMP
GlobalWindowImpl::GetSelf(nsIDOMWindow** aWindow)
{
*aWindow = this;
NS_ADDREF(this);
return NS_OK;
}
NS_IMETHODIMP
GlobalWindowImpl::GetDocument(nsIDOMDocument** aDocument)
{
*aDocument = mDocument;
NS_ADDREF(mDocument);
return NS_OK;
}
NS_IMETHODIMP
GlobalWindowImpl::GetNavigator(nsIDOMNavigator** aNavigator)
{
if (nsnull == mNavigator) {
mNavigator = new NavigatorImpl();
NS_IF_ADDREF(mNavigator);
}
*aNavigator = mNavigator;
NS_IF_ADDREF(mNavigator);
return NS_OK;
}
NS_IMETHODIMP
GlobalWindowImpl::Dump(nsString& aStr)
{
char *cstr = aStr.ToNewCString();
if (nsnull != cstr) {
printf("%s", cstr);
delete [] cstr;
}
return NS_OK;
}
NS_IMETHODIMP
GlobalWindowImpl::Alert(nsString& aStr)
{
// XXX Temporary
return Dump(aStr);
}
nsresult
GlobalWindowImpl::ClearTimeoutOrInterval(PRInt32 aTimerID)
{
PRUint32 public_id;
nsTimeoutImpl **top, *timeout;
public_id = (PRUint32)aTimerID;
if (!public_id) /* id of zero is reserved for internal use */
return NS_ERROR_FAILURE;
for (top = &mTimeouts; ((timeout = *top) != NULL); top = &timeout->next) {
if (timeout->public_id == public_id) {
if (mRunningTimeout == timeout) {
/* We're running from inside the timeout. Mark this
timeout for deferred deletion by the code in
win_run_timeout() */
timeout->interval = 0;
}
else {
/* Delete the timeout from the pending timeout list */
*top = timeout->next;
if (timeout->timer) {
timeout->timer->Cancel();
NS_RELEASE(timeout->timer);
DropTimeout(timeout);
}
DropTimeout(timeout);
}
break;
}
}
return NS_OK;
}
NS_IMETHODIMP
GlobalWindowImpl::ClearTimeout(PRInt32 aTimerID)
{
return ClearTimeoutOrInterval(aTimerID);
}
NS_IMETHODIMP
GlobalWindowImpl::ClearInterval(PRInt32 aTimerID)
{
return ClearTimeoutOrInterval(aTimerID);
}
void
GlobalWindowImpl::ClearAllTimeouts()
{
nsTimeoutImpl *timeout, *next;
for (timeout = mTimeouts; timeout; timeout = next) {
/* If RunTimeout() is higher up on the stack for this
window, e.g. as a result of document.write from a timeout,
then we need to reset the list insertion point for
newly-created timeouts in case the user adds a timeout,
before we pop the stack back to RunTimeout. */
if (mRunningTimeout == timeout)
mTimeoutInsertionPoint = nsnull;
next = timeout->next;
if (timeout->timer) {
timeout->timer->Cancel();
NS_RELEASE(timeout->timer);
// Drop the count since the timer isn't going to hold on
// anymore.
DropTimeout(timeout);
}
// Drop the count since we're removing it from the list.
DropTimeout(timeout);
}
mTimeouts = NULL;
}
void
GlobalWindowImpl::HoldTimeout(nsTimeoutImpl *aTimeout)
{
aTimeout->ref_count++;
}
void
GlobalWindowImpl::DropTimeout(nsTimeoutImpl *aTimeout)
{
JSContext *cx;
if (--aTimeout->ref_count > 0) {
return;
}
cx = (JSContext *)mContext->GetNativeContext();
if (aTimeout->expr) {
PR_FREEIF(aTimeout->expr);
}
else if (aTimeout->funobj) {
JS_RemoveRoot(cx, &aTimeout->funobj);
if (aTimeout->argv) {
int i;
for (i = 0; i < aTimeout->argc; i++)
JS_RemoveRoot(cx, &aTimeout->argv[i]);
PR_FREEIF(aTimeout->argv);
}
}
NS_IF_RELEASE(aTimeout->timer);
PR_FREEIF(aTimeout->filename);
NS_IF_RELEASE(aTimeout->window);
PR_DELETE(aTimeout);
}
void
GlobalWindowImpl::InsertTimeoutIntoList(nsTimeoutImpl **aList,
nsTimeoutImpl *aTimeout)
{
nsTimeoutImpl *to;
while ((to = *aList) != nsnull) {
if (LL_CMP(to->when, >, aTimeout->when))
break;
aList = &to->next;
}
aTimeout->next = to;
*aList = aTimeout;
// Increment the ref_count since we're in the list
HoldTimeout(aTimeout);
}
void
nsGlobalWindow_RunTimeout(nsITimer *aTimer, void *aClosure)
{
nsTimeoutImpl *timeout = (nsTimeoutImpl *)aClosure;
timeout->window->RunTimeout(timeout);
// Drop the ref_count since the timer won't be holding on to the
// timeout struct anymore
timeout->window->DropTimeout(timeout);
}
void
GlobalWindowImpl::RunTimeout(nsTimeoutImpl *aTimeout)
{
nsTimeoutImpl *next, *timeout;
nsTimeoutImpl *last_expired_timeout;
nsTimeoutImpl dummy_timeout;
JSContext *cx;
PRInt64 now;
jsval result;
nsITimer *timer;
timer = aTimeout->timer;
cx = (JSContext *)mContext->GetNativeContext();
/*
* A native timer has gone off. See which of our timeouts need
* servicing
*/
LL_I2L(now, PR_IntervalNow());
/* The timeout list is kept in deadline order. Discover the
latest timeout whose deadline has expired. On some platforms,
native timeout events fire "early", so we need to test the
timer as well as the deadline. */
last_expired_timeout = nsnull;
for (timeout = mTimeouts; timeout; timeout = timeout->next) {
if ((timeout == aTimeout) || !LL_CMP(timeout->when, >, now))
last_expired_timeout = timeout;
}
/* Maybe the timeout that the event was fired for has been deleted
and there are no others timeouts with deadlines that make them
eligible for execution yet. Go away. */
if (!last_expired_timeout)
return;
/* Insert a dummy timeout into the list of timeouts between the portion
of the list that we are about to process now and those timeouts that
will be processed in a future call to win_run_timeout(). This dummy
timeout serves as the head of the list for any timeouts inserted as
a result of running a timeout. */
dummy_timeout.timer = NULL;
dummy_timeout.public_id = 0;
dummy_timeout.next = last_expired_timeout->next;
last_expired_timeout->next = &dummy_timeout;
/* Don't let ClearWindowTimeouts throw away our stack-allocated
dummy timeout. */
dummy_timeout.ref_count = 2;
mTimeoutInsertionPoint = &dummy_timeout.next;
for (timeout = mTimeouts; timeout != &dummy_timeout; timeout = next) {
next = timeout->next;
/* Hold the timeout in case expr or funobj releases its doc. */
mRunningTimeout = timeout;
if (timeout->expr) {
/* Evaluate the timeout expression. */
JS_EvaluateScript(cx, (JSObject *)mScriptObject,
timeout->expr,
PL_strlen(timeout->expr),
timeout->filename, timeout->lineno,
&result);
}
else {
PRInt64 lateness64;
PRInt32 lateness;
/* Add "secret" final argument that indicates timeout
lateness in milliseconds */
LL_SUB(lateness64, now, timeout->when);
LL_L2I(lateness, lateness64);
lateness = PR_IntervalToMilliseconds(lateness);
timeout->argv[timeout->argc] = INT_TO_JSVAL((jsint)lateness);
JS_CallFunctionValue(cx, (JSObject *)mScriptObject,
OBJECT_TO_JSVAL(timeout->funobj),
timeout->argc + 1, timeout->argv, &result);
}
mRunningTimeout = nsnull;
/* If we have a regular interval timer, we re-fire the
* timeout, accounting for clock drift.
*/
if (timeout->interval) {
/* Compute time to next timeout for interval timer. */
PRInt32 delay32;
PRInt64 interval, delay;
LL_I2L(interval, PR_MillisecondsToInterval(timeout->interval));
LL_ADD(timeout->when, timeout->when, interval);
LL_I2L(now, PR_IntervalNow());
LL_SUB(delay, timeout->when, now);
LL_L2I(delay32, delay);
/* If the next interval timeout is already supposed to
* have happened then run the timeout immediately.
*/
if (delay32 < 0) {
delay32 = 0;
}
delay32 = PR_IntervalToMilliseconds(delay32);
NS_IF_RELEASE(timeout->timer);
/* Reschedule timeout. Account for possible error return in
code below that checks for zero toid. */
nsresult err = NS_NewTimer(&timeout->timer);
if (NS_OK != err) {
return;
}
err = timeout->timer->Init(nsGlobalWindow_RunTimeout, timeout,
delay32);
if (NS_OK != err) {
return;
}
// Increment ref_count to indicate that this timer is holding
// on to the timeout struct.
HoldTimeout(timeout);
}
/* Running a timeout can cause another timeout to be deleted,
so we need to reset the pointer to the following timeout. */
next = timeout->next;
mTimeouts = next;
// Drop timeout struct since it's out of the list
DropTimeout(timeout);
/* Free the timeout if this is not a repeating interval
* timeout (or if it was an interval timeout, but we were
* unsuccessful at rescheduling it.)
*/
if (timeout->interval && timeout->timer) {
/* Reschedule an interval timeout */
/* Insert interval timeout onto list sorted in deadline order. */
InsertTimeoutIntoList(mTimeoutInsertionPoint, timeout);
}
}
/* Take the dummy timeout off the head of the list */
mTimeouts = dummy_timeout.next;
mTimeoutInsertionPoint = nsnull;
}
static const char *kSetIntervalStr = "setInterval";
static const char *kSetTimeoutStr = "setTimeout";
nsresult
GlobalWindowImpl::SetTimeoutOrInterval(JSContext *cx,
jsval *argv,
PRUint32 argc,
PRInt32* aReturn,
PRBool aIsInterval)
{
char *expr = nsnull;
JSObject *funobj = nsnull;
JSString *str;
nsTimeoutImpl *timeout, **insertion_point;
jsdouble interval;
PRInt64 now, delta;
if (argc >= 2) {
if (!JS_ValueToNumber(cx, argv[1], &interval)) {
JS_ReportError(cx, "Second argument to %s must be a millisecond interval",
aIsInterval ? kSetIntervalStr : kSetTimeoutStr);
return NS_ERROR_ILLEGAL_VALUE;
}
switch (JS_TypeOfValue(cx, argv[0])) {
case JSTYPE_FUNCTION:
funobj = JSVAL_TO_OBJECT(argv[0]);
break;
case JSTYPE_STRING:
case JSTYPE_OBJECT:
if (!(str = JS_ValueToString(cx, argv[0])))
return NS_ERROR_FAILURE;
expr = PL_strdup(JS_GetStringBytes(str));
if (nsnull == expr)
return NS_ERROR_OUT_OF_MEMORY;
break;
default:
JS_ReportError(cx, "useless %s call (missing quotes around argument?)", aIsInterval ? kSetIntervalStr : kSetTimeoutStr);
return NS_ERROR_FAILURE;
}
timeout = PR_NEWZAP(nsTimeoutImpl);
if (nsnull == timeout) {
PR_FREEIF(expr);
return NS_ERROR_OUT_OF_MEMORY;
}
// Initial ref_count to indicate that this timeout struct will
// be held as the closure of a timer.
timeout->ref_count = 1;
if (aIsInterval)
timeout->interval = (PRInt32)interval;
timeout->expr = expr;
timeout->funobj = funobj;
if (expr) {
timeout->argv = 0;
timeout->argc = 0;
}
else {
int i;
/* Leave an extra slot for a secret final argument that
indicates to the called function how "late" the timeout is. */
timeout->argv = (jsval *)PR_MALLOC((argc - 1) * sizeof(jsval));
if (nsnull == timeout->argv) {
DropTimeout(timeout);
return NS_ERROR_OUT_OF_MEMORY;
}
if (!JS_AddNamedRoot(cx, &timeout->funobj, "timeout.funobj")) {
DropTimeout(timeout);
return NS_ERROR_FAILURE;
}
timeout->argc = 0;
for (i = 2; (PRUint32)i < argc; i++) {
timeout->argv[i - 2] = argv[i];
if (!JS_AddNamedRoot(cx, &timeout->argv[i - 2], "timeout.argv[i]")) {
DropTimeout(timeout);
return NS_ERROR_FAILURE;
}
timeout->argc++;
}
}
LL_I2L(now, PR_IntervalNow());
LL_D2L(delta, PR_MillisecondsToInterval((PRUint32)interval));
LL_ADD(timeout->when, now, delta);
nsresult err = NS_NewTimer(&timeout->timer);
if (NS_OK != err) {
DropTimeout(timeout);
return err;
}
err = timeout->timer->Init(nsGlobalWindow_RunTimeout, timeout,
(PRInt32)interval);
if (NS_OK != err) {
DropTimeout(timeout);
return err;
}
timeout->window = this;
NS_ADDREF(this);
if (mTimeoutInsertionPoint == NULL)
insertion_point = &mTimeouts;
else
insertion_point = mTimeoutInsertionPoint;
InsertTimeoutIntoList(insertion_point, timeout);
timeout->public_id = ++mTimeoutPublicIdCounter;
*aReturn = timeout->public_id;
}
else {
JS_ReportError(cx, "Function %s requires at least 2 parameters", aIsInterval ? kSetIntervalStr : kSetTimeoutStr);
return NS_ERROR_FAILURE;
}
return NS_OK;
}
NS_IMETHODIMP
GlobalWindowImpl::SetTimeout(JSContext *cx,
jsval *argv,
PRUint32 argc,
PRInt32* aReturn)
{
return SetTimeoutOrInterval(cx, argv, argc, aReturn, PR_FALSE);
}
NS_IMETHODIMP
GlobalWindowImpl::SetInterval(JSContext *cx,
jsval *argv,
PRUint32 argc,
PRInt32* aReturn)
{
return SetTimeoutOrInterval(cx, argv, argc, aReturn, PR_TRUE);
}
extern "C" NS_DOM
NS_NewScriptGlobalObject(nsIScriptGlobalObject **aResult)
{
if (nsnull == aResult) {
return NS_ERROR_NULL_POINTER;
}
*aResult = NULL;
GlobalWindowImpl *global = new GlobalWindowImpl();
if (nsnull == global) {
return NS_ERROR_OUT_OF_MEMORY;
}
return global->QueryInterface(kIScriptGlobalObjectIID, (void **)aResult);
}
//
// Navigator class implementation
//
NavigatorImpl::NavigatorImpl()
{
mScriptObject = nsnull;
}
NavigatorImpl::~NavigatorImpl()
{
}
NS_IMPL_ADDREF(NavigatorImpl)
NS_IMPL_RELEASE(NavigatorImpl)
nsresult
NavigatorImpl::QueryInterface(const nsIID& aIID,
void** aInstancePtrResult)
{
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
if (nsnull == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kIScriptObjectOwnerIID)) {
*aInstancePtrResult = (void*) ((nsIScriptObjectOwner*)this);
AddRef();
return NS_OK;
}
if (aIID.Equals(kIDOMNavigatorIID)) {
*aInstancePtrResult = (void*) ((nsIDOMNavigator*)this);
AddRef();
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
*aInstancePtrResult = (void*)(nsISupports*)(nsIScriptObjectOwner*)this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
nsresult
NavigatorImpl::ResetScriptObject()
{
mScriptObject = nsnull;
return NS_OK;
}
nsresult
NavigatorImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
{
NS_PRECONDITION(nsnull != aScriptObject, "null arg");
nsresult res = NS_OK;
if (nsnull == mScriptObject) {
nsIScriptGlobalObject *global = aContext->GetGlobalObject();
res = NS_NewScriptNavigator(aContext, this, global, &mScriptObject);
NS_IF_RELEASE(global);
}
*aScriptObject = mScriptObject;
return res;
}
NS_IMETHODIMP
NavigatorImpl::GetUserAgent(nsString& aUserAgent)
{
nsINetService *service;
nsresult res = NS_OK;
res = NS_NewINetService(&service, nsnull);
if ((NS_OK == res) && (nsnull != service)) {
nsINetContainerApplication *container;
res = service->GetContainerApplication(&container);
if ((NS_OK == res) && (nsnull != container)) {
nsAutoString appVersion;
container->GetAppCodeName(aUserAgent);
container->GetAppVersion(appVersion);
aUserAgent.Append('/');
aUserAgent.Append(appVersion);
NS_RELEASE(container);
}
NS_RELEASE(service);
}
return res;
}
NS_IMETHODIMP
NavigatorImpl::GetAppCodeName(nsString& aAppCodeName)
{
nsINetService *service;
nsresult res = NS_OK;
res = NS_NewINetService(&service, nsnull);
if ((NS_OK == res) && (nsnull != service)) {
nsINetContainerApplication *container;
res = service->GetContainerApplication(&container);
if ((NS_OK == res) && (nsnull != container)) {
res = container->GetAppCodeName(aAppCodeName);
NS_RELEASE(container);
}
NS_RELEASE(service);
}
return res;
}
NS_IMETHODIMP
NavigatorImpl::GetAppVersion(nsString& aAppVersion)
{
nsINetService *service;
nsresult res = NS_OK;
res = NS_NewINetService(&service, nsnull);
if ((NS_OK == res) && (nsnull != service)) {
nsINetContainerApplication *container;
res = service->GetContainerApplication(&container);
if ((NS_OK == res) && (nsnull != container)) {
res = container->GetAppVersion(aAppVersion);
NS_RELEASE(container);
}
NS_RELEASE(service);
}
return res;
}
NS_IMETHODIMP
NavigatorImpl::GetAppName(nsString& aAppName)
{
nsINetService *service;
nsresult res = NS_OK;
res = NS_NewINetService(&service, nsnull);
if ((NS_OK == res) && (nsnull != service)) {
nsINetContainerApplication *container;
res = service->GetContainerApplication(&container);
if ((NS_OK == res) && (nsnull != container)) {
res = container->GetAppName(aAppName);
NS_RELEASE(container);
}
NS_RELEASE(service);
}
return res;
}
NS_IMETHODIMP
NavigatorImpl::GetLanguage(nsString& aLanguage)
{
nsINetService *service;
nsresult res = NS_OK;
res = NS_NewINetService(&service, nsnull);
if ((NS_OK == res) && (nsnull != service)) {
nsINetContainerApplication *container;
res = service->GetContainerApplication(&container);
if ((NS_OK == res) && (nsnull != container)) {
res = container->GetLanguage(aLanguage);
NS_RELEASE(container);
}
NS_RELEASE(service);
}
return res;
}
NS_IMETHODIMP
NavigatorImpl::GetPlatform(nsString& aPlatform)
{
nsINetService *service;
nsresult res = NS_OK;
res = NS_NewINetService(&service, nsnull);
if ((NS_OK == res) && (nsnull != service)) {
nsINetContainerApplication *container;
res = service->GetContainerApplication(&container);
if ((NS_OK == res) && (nsnull != container)) {
res = container->GetPlatform(aPlatform);
NS_RELEASE(container);
}
NS_RELEASE(service);
}
return res;
}
NS_IMETHODIMP
NavigatorImpl::GetSecurityPolicy(nsString& aSecurityPolicy)
{
return NS_OK;
}
NS_IMETHODIMP
NavigatorImpl::JavaEnabled(PRBool* aReturn)
{
*aReturn = PR_FALSE;
return NS_OK;
}

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

@ -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;

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

@ -0,0 +1,389 @@
/* -*- 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 "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(kINamedNodeMapIID, NS_IDOMNAMEDNODEMAP_IID);
static NS_DEFINE_IID(kIDocumentTypeIID, NS_IDOMDOCUMENTTYPE_IID);
NS_DEF_PTR(nsIDOMNamedNodeMap);
NS_DEF_PTR(nsIDOMDocumentType);
//
// DocumentType property ids
//
enum DocumentType_slots {
DOCUMENTTYPE_NAME = -11,
DOCUMENTTYPE_ENTITIES = -12
};
/***********************************************************************/
//
// DocumentType Properties Getter
//
PR_STATIC_CALLBACK(JSBool)
GetDocumentTypeProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMDocumentType *a = (nsIDOMDocumentType*)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 DOCUMENTTYPE_NAME:
{
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;
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;
if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {
PRBool rval;
rval = object->GetProperty(cx, id, vp);
NS_RELEASE(object);
return rval;
}
}
}
}
return PR_TRUE;
}
/***********************************************************************/
//
// DocumentType Properties Setter
//
PR_STATIC_CALLBACK(JSBool)
SetDocumentTypeProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMDocumentType *a = (nsIDOMDocumentType*)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 DOCUMENTTYPE_NAME:
{
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(kINamedNodeMapIID, (void **)&prop)) {
JS_ReportError(cx, "Parameter must be of type NamedNodeMap");
return JS_FALSE;
}
}
else {
JS_ReportError(cx, "Parameter must be an object");
return JS_FALSE;
}
a->SetEntities(prop);
if (prop) NS_RELEASE(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;
}
//
// DocumentType finalizer
//
PR_STATIC_CALLBACK(void)
FinalizeDocumentType(JSContext *cx, JSObject *obj)
{
nsIDOMDocumentType *a = (nsIDOMDocumentType*)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);
}
}
//
// DocumentType enumerate
//
PR_STATIC_CALLBACK(JSBool)
EnumerateDocumentType(JSContext *cx, JSObject *obj)
{
nsIDOMDocumentType *a = (nsIDOMDocumentType*)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;
}
//
// DocumentType resolve
//
PR_STATIC_CALLBACK(JSBool)
ResolveDocumentType(JSContext *cx, JSObject *obj, jsval id)
{
nsIDOMDocumentType *a = (nsIDOMDocumentType*)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 DocumentType
//
JSClass DocumentTypeClass = {
"DocumentType",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
GetDocumentTypeProperty,
SetDocumentTypeProperty,
EnumerateDocumentType,
ResolveDocumentType,
JS_ConvertStub,
FinalizeDocumentType
};
//
// DocumentType class properties
//
static JSPropertySpec DocumentTypeProperties[] =
{
{"name", DOCUMENTTYPE_NAME, JSPROP_ENUMERATE},
{"entities", DOCUMENTTYPE_ENTITIES, JSPROP_ENUMERATE},
{0}
};
//
// DocumentType class methods
//
static JSFunctionSpec DocumentTypeMethods[] =
{
{0}
};
//
// DocumentType constructor
//
PR_STATIC_CALLBACK(JSBool)
DocumentType(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
return JS_TRUE;
}
//
// DocumentType class initialization
//
nsresult NS_InitDocumentTypeClass(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, "DocumentType", &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
&DocumentTypeClass, // JSClass
DocumentType, // JSNative ctor
0, // ctor args
DocumentTypeProperties, // proto props
DocumentTypeMethods, // 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 DocumentType JavaScript object
//
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_NewScriptDocumentType");
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_InitDocumentTypeClass(aContext, (void **)&proto)) {
return NS_ERROR_FAILURE;
}
// create a js object for this class
*aReturn = JS_NewObject(jscontext, &DocumentTypeClass, 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,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;

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

@ -1,165 +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.
*/
#include "nsJSEnvironment.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsIDOMWindow.h"
#include "nsIDOMNode.h"
#include "nsIDOMElement.h"
#include "nsIDOMDocument.h"
#include "nsIDOMText.h"
#include "nsIDOMAttribute.h"
#include "nsIDOMAttributeList.h"
#include "nsIDOMNodeIterator.h"
const uint32 gGCSize = 4L * 1024L * 1024L;
const size_t gStackSize = 8192;
static NS_DEFINE_IID(kIScriptContextIID, NS_ISCRIPTCONTEXT_IID);
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
nsJSContext::nsJSContext(JSRuntime *aRuntime)
{
mRefCnt = 0;
mContext = JS_NewContext(aRuntime, gStackSize);
JS_SetContextPrivate(mContext, (void *)this);
}
nsJSContext::~nsJSContext()
{
JS_DestroyContext(mContext);
}
NS_IMPL_ISUPPORTS(nsJSContext, kIScriptContextIID);
PRBool nsJSContext::EvaluateString(const char *aScript,
PRUint32 aScriptSize,
jsval *aRetValue)
{
return ::JS_EvaluateScript(mContext,
JS_GetGlobalObject(mContext),
aScript,
aScriptSize,
NULL,
0,
aRetValue);
}
nsIScriptGlobalObject* nsJSContext::GetGlobalObject()
{
JSObject *global = JS_GetGlobalObject(mContext);
nsIScriptGlobalObject *script_global;
if (nsnull != global) {
script_global = (nsIScriptGlobalObject *)JS_GetPrivate(mContext, global);
NS_ADDREF(script_global);
return script_global;
}
else {
return nsnull;
}
}
void* nsJSContext::GetNativeContext()
{
return (void *)mContext;
}
nsresult nsJSContext::InitContext(nsIScriptGlobalObject *aGlobalObject)
{
nsresult result = NS_ERROR_FAILURE;
nsIScriptObjectOwner *owner;
JSObject *global;
nsresult res = aGlobalObject->QueryInterface(kIScriptObjectOwnerIID, (void **)&owner);
if (NS_OK == res) {
res = owner->GetScriptObject(this, (void **)&global);
// init standard classes
if ((NS_OK == res) && ::JS_InitStandardClasses(mContext, global)) {
JS_SetGlobalObject(mContext, global);
res = InitClasses(); // this will complete the global object initialization
}
NS_RELEASE(owner);
}
return res;
}
nsresult nsJSContext::InitClasses()
{
nsresult res = NS_ERROR_FAILURE;
nsIScriptGlobalObject *global = GetGlobalObject();
if (NS_OK == NS_InitWindowClass(this, global) &&
NS_OK == NS_InitNodeClass(this, nsnull) &&
NS_OK == NS_InitElementClass(this, nsnull) &&
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)) {
res = NS_OK;
}
NS_RELEASE(global);
return res;
}
nsJSEnvironment *nsJSEnvironment::sTheEnvironment = nsnull;
nsJSEnvironment *
nsJSEnvironment::GetScriptingEnvironment()
{
if (nsnull == sTheEnvironment) {
sTheEnvironment = new nsJSEnvironment();
}
return sTheEnvironment;
}
nsJSEnvironment::nsJSEnvironment()
{
mRuntime = JS_Init(gGCSize);
}
nsJSEnvironment::~nsJSEnvironment()
{
JS_Finish(mRuntime);
}
nsIScriptContext* nsJSEnvironment::GetNewContext()
{
nsIScriptContext *context;
context = new nsJSContext(mRuntime);
NS_ADDREF(context);
return context;
}
extern "C" NS_DOM NS_CreateContext(nsIScriptGlobalObject *aGlobal, nsIScriptContext **aContext)
{
nsJSEnvironment *environment = nsJSEnvironment::GetScriptingEnvironment();
*aContext = environment->GetNewContext();
(*aContext)->InitContext(aGlobal);
aGlobal->SetContext(*aContext);
return NS_OK;
}

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

@ -0,0 +1,548 @@
/* -*- 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 "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(kINamedNodeMapIID, NS_IDOMNAMEDNODEMAP_IID);
static NS_DEFINE_IID(kINodeIID, NS_IDOMNODE_IID);
NS_DEF_PTR(nsIDOMNamedNodeMap);
NS_DEF_PTR(nsIDOMNode);
//
// NamedNodeMap property ids
//
enum NamedNodeMap_slots {
NAMEDNODEMAP_LENGTH = -11
};
/***********************************************************************/
//
// NamedNodeMap Properties Getter
//
PR_STATIC_CALLBACK(JSBool)
GetNamedNodeMapProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMNamedNodeMap *a = (nsIDOMNamedNodeMap*)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 NAMEDNODEMAP_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;
}
/***********************************************************************/
//
// NamedNodeMap Properties Setter
//
PR_STATIC_CALLBACK(JSBool)
SetNamedNodeMapProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMNamedNodeMap *a = (nsIDOMNamedNodeMap*)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;
}
//
// NamedNodeMap finalizer
//
PR_STATIC_CALLBACK(void)
FinalizeNamedNodeMap(JSContext *cx, JSObject *obj)
{
nsIDOMNamedNodeMap *a = (nsIDOMNamedNodeMap*)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);
}
}
//
// NamedNodeMap enumerate
//
PR_STATIC_CALLBACK(JSBool)
EnumerateNamedNodeMap(JSContext *cx, JSObject *obj)
{
nsIDOMNamedNodeMap *a = (nsIDOMNamedNodeMap*)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;
}
//
// NamedNodeMap resolve
//
PR_STATIC_CALLBACK(JSBool)
ResolveNamedNodeMap(JSContext *cx, JSObject *obj, jsval id)
{
nsIDOMNamedNodeMap *a = (nsIDOMNamedNodeMap*)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 GetNamedItem
//
PR_STATIC_CALLBACK(JSBool)
NamedNodeMapGetNamedItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMNamedNodeMap *nativeThis = (nsIDOMNamedNodeMap*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMNode* nativeRet;
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->GetNamedItem(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 getNamedItem requires 1 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method SetNamedItem
//
PR_STATIC_CALLBACK(JSBool)
NamedNodeMapSetNamedItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMNamedNodeMap *nativeThis = (nsIDOMNamedNodeMap*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
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->SetNamedItem(b0)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function setNamedItem requires 1 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method RemoveNamedItem
//
PR_STATIC_CALLBACK(JSBool)
NamedNodeMapRemoveNamedItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMNamedNodeMap *nativeThis = (nsIDOMNamedNodeMap*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMNode* nativeRet;
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->RemoveNamedItem(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 removeNamedItem requires 1 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method Item
//
PR_STATIC_CALLBACK(JSBool)
NamedNodeMapItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMNamedNodeMap *nativeThis = (nsIDOMNamedNodeMap*)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 NamedNodeMap
//
JSClass NamedNodeMapClass = {
"NamedNodeMap",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
GetNamedNodeMapProperty,
SetNamedNodeMapProperty,
EnumerateNamedNodeMap,
ResolveNamedNodeMap,
JS_ConvertStub,
FinalizeNamedNodeMap
};
//
// NamedNodeMap class properties
//
static JSPropertySpec NamedNodeMapProperties[] =
{
{"length", NAMEDNODEMAP_LENGTH, JSPROP_ENUMERATE | JSPROP_READONLY},
{0}
};
//
// NamedNodeMap class methods
//
static JSFunctionSpec NamedNodeMapMethods[] =
{
{"getNamedItem", NamedNodeMapGetNamedItem, 1},
{"setNamedItem", NamedNodeMapSetNamedItem, 1},
{"removeNamedItem", NamedNodeMapRemoveNamedItem, 1},
{"item", NamedNodeMapItem, 1},
{0}
};
//
// NamedNodeMap constructor
//
PR_STATIC_CALLBACK(JSBool)
NamedNodeMap(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
return JS_TRUE;
}
//
// NamedNodeMap class initialization
//
nsresult NS_InitNamedNodeMapClass(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, "NamedNodeMap", &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
&NamedNodeMapClass, // JSClass
NamedNodeMap, // JSNative ctor
0, // ctor args
NamedNodeMapProperties, // proto props
NamedNodeMapMethods, // 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 NamedNodeMap JavaScript object
//
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_NewScriptNamedNodeMap");
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_InitNamedNodeMapClass(aContext, (void **)&proto)) {
return NS_ERROR_FAILURE;
}
// create a js object for this class
*aReturn = JS_NewObject(jscontext, &NamedNodeMapClass, 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;
}

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

@ -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;

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

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;
}

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

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

@ -0,0 +1,367 @@
/* -*- 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 "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(kIProcessingInstructionIID, NS_IDOMPROCESSINGINSTRUCTION_IID);
NS_DEF_PTR(nsIDOMProcessingInstruction);
//
// ProcessingInstruction property ids
//
enum ProcessingInstruction_slots {
PROCESSINGINSTRUCTION_TARGET = -11,
PROCESSINGINSTRUCTION_DATA = -12
};
/***********************************************************************/
//
// ProcessingInstruction Properties Getter
//
PR_STATIC_CALLBACK(JSBool)
GetProcessingInstructionProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMProcessingInstruction *a = (nsIDOMProcessingInstruction*)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 PROCESSINGINSTRUCTION_TARGET:
{
nsAutoString prop;
if (NS_OK == a->GetTarget(prop)) {
JSString *jsstring = JS_NewUCStringCopyN(cx, prop, prop.Length());
// set the return value
*vp = STRING_TO_JSVAL(jsstring);
}
else {
return JS_FALSE;
}
break;
}
case PROCESSINGINSTRUCTION_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;
}
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;
}
/***********************************************************************/
//
// ProcessingInstruction Properties Setter
//
PR_STATIC_CALLBACK(JSBool)
SetProcessingInstructionProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMProcessingInstruction *a = (nsIDOMProcessingInstruction*)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 PROCESSINGINSTRUCTION_TARGET:
{
nsAutoString prop;
JSString *jsstring;
if ((jsstring = JS_ValueToString(cx, *vp)) != nsnull) {
prop.SetString(JS_GetStringChars(jsstring));
}
else {
prop.SetString((const char *)nsnull);
}
a->SetTarget(prop);
break;
}
case PROCESSINGINSTRUCTION_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;
}
//
// ProcessingInstruction finalizer
//
PR_STATIC_CALLBACK(void)
FinalizeProcessingInstruction(JSContext *cx, JSObject *obj)
{
nsIDOMProcessingInstruction *a = (nsIDOMProcessingInstruction*)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);
}
}
//
// ProcessingInstruction enumerate
//
PR_STATIC_CALLBACK(JSBool)
EnumerateProcessingInstruction(JSContext *cx, JSObject *obj)
{
nsIDOMProcessingInstruction *a = (nsIDOMProcessingInstruction*)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;
}
//
// ProcessingInstruction resolve
//
PR_STATIC_CALLBACK(JSBool)
ResolveProcessingInstruction(JSContext *cx, JSObject *obj, jsval id)
{
nsIDOMProcessingInstruction *a = (nsIDOMProcessingInstruction*)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 ProcessingInstruction
//
JSClass ProcessingInstructionClass = {
"ProcessingInstruction",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
GetProcessingInstructionProperty,
SetProcessingInstructionProperty,
EnumerateProcessingInstruction,
ResolveProcessingInstruction,
JS_ConvertStub,
FinalizeProcessingInstruction
};
//
// ProcessingInstruction class properties
//
static JSPropertySpec ProcessingInstructionProperties[] =
{
{"target", PROCESSINGINSTRUCTION_TARGET, JSPROP_ENUMERATE},
{"data", PROCESSINGINSTRUCTION_DATA, JSPROP_ENUMERATE},
{0}
};
//
// ProcessingInstruction class methods
//
static JSFunctionSpec ProcessingInstructionMethods[] =
{
{0}
};
//
// ProcessingInstruction constructor
//
PR_STATIC_CALLBACK(JSBool)
ProcessingInstruction(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
return JS_TRUE;
}
//
// ProcessingInstruction class initialization
//
nsresult NS_InitProcessingInstructionClass(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, "ProcessingInstruction", &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
&ProcessingInstructionClass, // JSClass
ProcessingInstruction, // JSNative ctor
0, // ctor args
ProcessingInstructionProperties, // proto props
ProcessingInstructionMethods, // 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 ProcessingInstruction JavaScript object
//
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_NewScriptProcessingInstruction");
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_InitProcessingInstructionClass(aContext, (void **)&proto)) {
return NS_ERROR_FAILURE;
}
// create a js object for this class
*aReturn = JS_NewObject(jscontext, &ProcessingInstructionClass, 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,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;

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

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

@ -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;
}

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