Adding files that implement the entity, notation, documenttype and namednodemap interfaces. Contributed by Johnny Stenback (jst@citec.fi).

This commit is contained in:
nisheeth%netscape.com 1999-08-24 22:22:36 +00:00
Родитель 8d11ab3f1f
Коммит 4f94ca838d
11 изменённых файлов: 2090 добавлений и 0 удалений

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

@ -42,6 +42,10 @@ CPPSRCS = \
nsGenericXMLElement.cpp \
nsXMLCDATASection.cpp \
nsXMLProcessingInstruction.cpp \
nsXMLEntity.cpp \
nsXMLNotation.cpp \
nsXMLDocumentType.cpp \
nsXMLNamedNodeMap.cpp \
$(NULL)
EXPORTS = \

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

@ -28,6 +28,10 @@ CPPSRCS= \
nsGenericXMLElement.cpp \
nsXMLCDATASection.cpp \
nsXMLProcessingInstruction.cpp \
nsXMLEntity.cpp \
nsXMLNotation.cpp \
nsXMLDocumentType.cpp \
nsXMLNamedNodeMap.cpp \
$(NULL)
CPP_OBJS= \
@ -35,6 +39,10 @@ CPP_OBJS= \
.\$(OBJDIR)\nsGenericXMLElement.obj \
.\$(OBJDIR)\nsXMLCDATASection.obj \
.\$(OBJDIR)\nsXMLProcessingInstruction.obj \
.\$(OBJDIR)\nsXMLEntity.obj \
.\$(OBJDIR)\nsXMLNotation.obj \
.\$(OBJDIR)\nsXMLDocumentType.obj \
.\$(OBJDIR)\nsXMLNamedNodeMap.obj \
$(NULL)
EXPORTS = \

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

@ -0,0 +1,302 @@
/* -*- 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 "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsIDOMEntity.h"
#include "nsIScriptObjectOwner.h"
#include "nsIDOMEventReceiver.h"
#include "nsIContent.h"
#include "nsGenericDOMDataNode.h"
#include "nsGenericElement.h"
#include "nsIDOMScriptObjectFactory.h"
#include "nsLayoutAtoms.h"
#include "nsString.h"
#include "nsIXMLContent.h"
static NS_DEFINE_IID(kIDOMEntityIID, NS_IDOMENTITY_IID);
class nsXMLEntity : public nsIDOMEntity,
public nsIScriptObjectOwner,
public nsIDOMEventReceiver,
public nsIContent
{
public:
nsXMLEntity(const nsString& aName, const nsString& aPublicId,
const nsString& aSystemId, const nsString aNotationName);
virtual ~nsXMLEntity();
// nsISupports
NS_DECL_ISUPPORTS
// nsIDOMNode
NS_IMPL_IDOMNODE_USING_GENERIC_DOM_DATA(mInner)
// nsIDOMEntity
NS_IMETHOD GetPublicId(nsString& aPublicId);
NS_IMETHOD GetSystemId(nsString& aSystemId);
NS_IMETHOD GetNotationName(nsString& aNotationName);
// nsIScriptObjectOwner interface
NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void *aScriptObject);
// nsIDOMEventReceiver
NS_IMPL_IDOMEVENTRECEIVER_USING_GENERIC_DOM_DATA(mInner)
// nsIContent
NS_IMPL_ICONTENT_USING_GENERIC_DOM_DATA(mInner)
protected:
// XXX Processing instructions are currently implemented by using
// the generic CharacterData inner object, even though PIs are not
// character data. This is done simply for convenience and should
// be changed if this restricts what should be done for character data.
nsGenericDOMDataNode mInner;
nsString mName;
nsString mPublicId;
nsString mSystemId;
nsString mNotationName;
void* mScriptObject;
};
nsresult
NS_NewXMLEntity(nsIContent** aInstancePtrResult,
const nsString& aName,
const nsString& aPublicId,
const nsString& aSystemId,
const nsString aNotationName)
{
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
if (nsnull == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
nsIContent* it = new nsXMLEntity(aName, aPublicId, aSystemId, aNotationName);
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;
}
return it->QueryInterface(kIContentIID, (void **) aInstancePtrResult);
}
nsXMLEntity::nsXMLEntity(const nsString& aName,
const nsString& aPublicId,
const nsString& aSystemId,
const nsString aNotationName) :
mName(aName), mPublicId(aPublicId), mSystemId(aSystemId), mNotationName(aNotationName)
{
NS_INIT_REFCNT();
mInner.Init(this);
mScriptObject = nsnull;
}
nsXMLEntity::~nsXMLEntity()
{
}
NS_IMPL_ADDREF(nsXMLEntity)
NS_IMPL_RELEASE(nsXMLEntity)
nsresult
nsXMLEntity::QueryInterface(REFNSIID aIID, void** aInstancePtrResult)
{
if (NULL == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kISupportsIID)) {
nsIDOMEntity* tmp = this;
nsISupports* tmp2 = tmp;
*aInstancePtrResult = (void*) tmp2;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIDOMNodeIID)) {
nsIDOMNode* tmp = this;
*aInstancePtrResult = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIDOMEventReceiverIID)) {
nsIDOMEventReceiver* tmp = this;
*aInstancePtrResult = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIScriptObjectOwnerIID)) {
nsIScriptObjectOwner* tmp = this;
*aInstancePtrResult = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIContentIID)) {
nsIContent* tmp = this;
*aInstancePtrResult = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIDOMEntityIID)) {
nsIDOMEntity* tmp = this;
*aInstancePtrResult = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMETHODIMP
nsXMLEntity::GetPublicId(nsString& aPublicId)
{
aPublicId=mPublicId;
return NS_OK;
}
NS_IMETHODIMP
nsXMLEntity::GetSystemId(nsString& aSystemId)
{
aSystemId=mSystemId;
return NS_OK;
}
NS_IMETHODIMP
nsXMLEntity::GetNotationName(nsString& aNotationName)
{
aNotationName=mNotationName;
return NS_OK;
}
NS_IMETHODIMP
nsXMLEntity::GetScriptObject(nsIScriptContext* aContext,
void** aScriptObject)
{
nsresult res = NS_OK;
if (nsnull == mScriptObject) {
nsIDOMScriptObjectFactory *factory;
res = nsGenericElement::GetScriptObjectFactory(&factory);
if (NS_OK != res) {
return res;
}
res = factory->NewScriptEntity(aContext,
(nsISupports*)(nsIDOMEntity*)this,
mInner.mParent,
(void**)&mScriptObject);
NS_RELEASE(factory);
}
*aScriptObject = mScriptObject;
return res;
}
NS_IMETHODIMP
nsXMLEntity::SetScriptObject(void *aScriptObject)
{
mScriptObject = aScriptObject;
return NS_OK;
}
NS_IMETHODIMP
nsXMLEntity::GetTag(nsIAtom*& aResult) const
{
// aResult = nsLayoutAtoms::EntityTagName;
// NS_ADDREF(aResult);
aResult = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsXMLEntity::GetNodeName(nsString& aNodeName)
{
aNodeName=mName;
return NS_OK;
}
NS_IMETHODIMP
nsXMLEntity::GetNodeType(PRUint16* aNodeType)
{
*aNodeType = (PRUint16)nsIDOMNode::ENTITY_NODE;
return NS_OK;
}
NS_IMETHODIMP
nsXMLEntity::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
{
nsXMLEntity* it = new nsXMLEntity(mName,
mSystemId,
mPublicId,
mNotationName);
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;
}
return it->QueryInterface(kIDOMNodeIID, (void**) aReturn);
}
NS_IMETHODIMP
nsXMLEntity::List(FILE* out, PRInt32 aIndent) const
{
NS_PRECONDITION(nsnull != mInner.mDocument, "bad content");
PRInt32 index;
for (index = aIndent; --index >= 0; ) fputs(" ", out);
fprintf(out, "Entity refcount=%d<!ENTITY ", mRefCnt);
nsAutoString tmp(mName);
if (mPublicId.Length()) {
tmp.Append(" PUBLIC \"");
tmp.Append(mPublicId);
tmp.Append("\"");
}
if (mSystemId.Length()) {
tmp.Append(" SYSTEM \"");
tmp.Append(mSystemId);
tmp.Append("\"");
}
if (mNotationName.Length()) {
tmp.Append(" NDATA ");
tmp.Append(mNotationName);
}
fputs(tmp, out);
fputs(">\n", out);
return NS_OK;
}
NS_IMETHODIMP
nsXMLEntity::HandleDOMEvent(nsIPresContext& aPresContext,
nsEvent* aEvent,
nsIDOMEvent** aDOMEvent,
PRUint32 aFlags,
nsEventStatus& aEventStatus)
{
// We should never be getting events
NS_ASSERTION(0, "event handler called for entity");
return mInner.HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
aFlags, aEventStatus);
}

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

@ -0,0 +1,297 @@
/* -*- 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 "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsIDOMNamedNodeMap.h"
#include "nsIScriptObjectOwner.h"
#include "nsIDOMEventReceiver.h"
#include "nsIContent.h"
#include "nsGenericDOMDataNode.h"
#include "nsGenericElement.h"
#include "nsIDOMScriptObjectFactory.h"
#include "nsLayoutAtoms.h"
#include "nsString.h"
#include "nsIXMLContent.h"
#include "nsCOMPtr.h"
#include "nsISupportsArray.h"
static NS_DEFINE_IID(kIDOMNamedNodeMapIID, NS_IDOMNAMEDNODEMAP_IID);
class nsXMLNamedNodeMap : public nsIDOMNamedNodeMap,
public nsIScriptObjectOwner
{
public:
nsXMLNamedNodeMap(nsISupportsArray *aArray);
virtual ~nsXMLNamedNodeMap();
// nsISupports
NS_DECL_ISUPPORTS
// nsIDOMNamedNodeMap
NS_IMETHOD GetLength(PRUint32* aLength);
NS_IMETHOD GetNamedItem(const nsString& aName, nsIDOMNode** aReturn);
NS_IMETHOD SetNamedItem(nsIDOMNode* aArg, nsIDOMNode** aReturn);
NS_IMETHOD RemoveNamedItem(const nsString& aName, nsIDOMNode** aReturn);
NS_IMETHOD Item(PRUint32 aIndex, nsIDOMNode** aReturn);
// nsIScriptObjectOwner interface
NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void *aScriptObject);
protected:
nsISupportsArray *mArray;
void* mScriptObject;
};
nsresult
NS_NewXMLNamedNodeMap(nsIDOMNamedNodeMap** aInstancePtrResult,
nsISupportsArray *aArray)
{
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
if (nsnull == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
nsIDOMNamedNodeMap* it = new nsXMLNamedNodeMap(aArray);
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;
}
return it->QueryInterface(kIDOMNamedNodeMapIID, (void **) aInstancePtrResult);
}
nsXMLNamedNodeMap::nsXMLNamedNodeMap(nsISupportsArray *aArray)
{
NS_INIT_REFCNT();
mScriptObject = nsnull;
mArray = aArray;
NS_IF_ADDREF(mArray);
}
nsXMLNamedNodeMap::~nsXMLNamedNodeMap()
{
NS_IF_RELEASE(mArray);
}
NS_IMPL_ADDREF(nsXMLNamedNodeMap)
NS_IMPL_RELEASE(nsXMLNamedNodeMap)
nsresult
nsXMLNamedNodeMap::QueryInterface(REFNSIID aIID, void** aInstancePtrResult)
{
if (NULL == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kISupportsIID)) {
nsIDOMNamedNodeMap* tmp = this;
nsISupports* tmp2 = tmp;
*aInstancePtrResult = (void*) tmp2;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIScriptObjectOwnerIID)) {
nsIScriptObjectOwner* tmp = this;
*aInstancePtrResult = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIDOMNamedNodeMapIID)) {
nsIDOMNamedNodeMap* tmp = this;
*aInstancePtrResult = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMETHODIMP
nsXMLNamedNodeMap::GetLength(PRUint32* aLength)
{
if (mArray)
*aLength = mArray->Count();
else
*aLength = 0;
return NS_OK;
}
NS_IMETHODIMP
nsXMLNamedNodeMap::GetNamedItem(const nsString& aName, nsIDOMNode** aReturn)
{
if (!aReturn)
return NS_ERROR_NULL_POINTER;
*aReturn = 0;
if (!mArray)
return NS_OK;
PRUint32 i, count = mArray->Count();
for (i = 0; i < count; i++) {
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(mArray->ElementAt(i)));
if (!node)
break;
nsAutoString tmpName;
node->GetNodeName(tmpName);
if (aName.Equals(tmpName)) {
*aReturn = node;
break;
}
}
return NS_OK;
}
NS_IMETHODIMP
nsXMLNamedNodeMap::SetNamedItem(nsIDOMNode* aArg, nsIDOMNode** aReturn)
{
if (!aReturn || !aArg)
return NS_ERROR_NULL_POINTER;
*aReturn = 0;
nsAutoString argName;
aArg->GetNodeName(argName);
if (mArray) {
PRUint32 i, count = mArray->Count();
for (i = 0; i < count; i++) {
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(mArray->ElementAt(i)));
if (!node)
break;
nsAutoString tmpName;
node->GetNodeName(tmpName);
if (argName.Equals(tmpName)) {
mArray->ReplaceElementAt(aArg, i);
*aReturn = node;
break;
}
}
} else {
nsresult rv = NS_NewISupportsArray(&mArray);
if (NS_FAILED(rv))
return rv;
}
if (!*aReturn)
mArray->AppendElement(aArg);
return NS_OK;
}
NS_IMETHODIMP
nsXMLNamedNodeMap::RemoveNamedItem(const nsString& aName, nsIDOMNode** aReturn)
{
if (!aReturn)
return NS_ERROR_NULL_POINTER;
*aReturn = 0;
if (!mArray)
return NS_OK;
PRUint32 i, count = mArray->Count();
for (i = 0; i < count; i++) {
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(mArray->ElementAt(i)));
if (!node)
break;
nsAutoString tmpName;
node->GetNodeName(tmpName);
if (aName.Equals(tmpName)) {
*aReturn = node;
mArray->RemoveElementAt(i);
break;
}
}
return NS_OK;
}
NS_IMETHODIMP
nsXMLNamedNodeMap::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
{
if (!aReturn)
return NS_ERROR_NULL_POINTER;
if (mArray && aIndex < mArray->Count()) {
nsCOMPtr<nsIDOMNode> domNode(do_QueryInterface(mArray->ElementAt(aIndex)));
*aReturn = domNode;
} else
*aReturn = 0;
return NS_OK;
}
NS_IMETHODIMP
nsXMLNamedNodeMap::GetScriptObject(nsIScriptContext* aContext,
void** aScriptObject)
{
nsresult res = NS_OK;
if (nsnull == mScriptObject) {
nsIDOMScriptObjectFactory *factory;
res = nsGenericElement::GetScriptObjectFactory(&factory);
if (NS_OK != res) {
return res;
}
res = factory->NewScriptNamedNodeMap(aContext,
(nsISupports*)(nsIDOMNamedNodeMap*)this,
nsnull /*mInner.mParent*/,
(void**)&mScriptObject);
NS_RELEASE(factory);
}
*aScriptObject = mScriptObject;
return res;
}
NS_IMETHODIMP
nsXMLNamedNodeMap::SetScriptObject(void *aScriptObject)
{
mScriptObject = aScriptObject;
return NS_OK;
}

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

@ -0,0 +1,285 @@
/* -*- 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 "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsIDOMNotation.h"
#include "nsIScriptObjectOwner.h"
#include "nsIDOMEventReceiver.h"
#include "nsIContent.h"
#include "nsGenericDOMDataNode.h"
#include "nsGenericElement.h"
#include "nsIDOMScriptObjectFactory.h"
#include "nsLayoutAtoms.h"
#include "nsString.h"
#include "nsIXMLContent.h"
static NS_DEFINE_IID(kIDOMNotationIID, NS_IDOMNOTATION_IID);
class nsXMLNotation : public nsIDOMNotation,
public nsIScriptObjectOwner,
public nsIDOMEventReceiver,
public nsIContent
{
public:
nsXMLNotation(const nsString& aName,
const nsString& aPublicId,
const nsString& aSystemId);
virtual ~nsXMLNotation();
// nsISupports
NS_DECL_ISUPPORTS
// nsIDOMNode
NS_IMPL_IDOMNODE_USING_GENERIC_DOM_DATA(mInner)
// nsIDOMNotation
NS_IMETHOD GetPublicId(nsString& aPublicId);
NS_IMETHOD GetSystemId(nsString& aSystemId);
// nsIScriptObjectOwner interface
NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void *aScriptObject);
// nsIDOMEventReceiver
NS_IMPL_IDOMEVENTRECEIVER_USING_GENERIC_DOM_DATA(mInner)
// nsIContent
NS_IMPL_ICONTENT_USING_GENERIC_DOM_DATA(mInner)
protected:
// XXX Processing instructions are currently implemented by using
// the generic CharacterData inner object, even though PIs are not
// character data. This is done simply for convenience and should
// be changed if this restricts what should be done for character data.
nsGenericDOMDataNode mInner;
nsString mName;
nsString mPublicId;
nsString mSystemId;
void* mScriptObject;
};
nsresult
NS_NewXMLNotation(nsIContent** aInstancePtrResult,
const nsString& aName,
const nsString& aPublicId,
const nsString& aSystemId)
{
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
if (nsnull == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
nsIContent* it = new nsXMLNotation(aName, aPublicId, aSystemId);
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;
}
return it->QueryInterface(kIContentIID, (void **) aInstancePtrResult);
}
nsXMLNotation::nsXMLNotation(const nsString& aName,
const nsString& aPublicId,
const nsString& aSystemId) :
mName(aName), mPublicId(aPublicId), mSystemId(aSystemId)
{
NS_INIT_REFCNT();
mInner.Init(this);
mScriptObject = nsnull;
}
nsXMLNotation::~nsXMLNotation()
{
}
NS_IMPL_ADDREF(nsXMLNotation)
NS_IMPL_RELEASE(nsXMLNotation)
nsresult
nsXMLNotation::QueryInterface(REFNSIID aIID, void** aInstancePtrResult)
{
if (NULL == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kISupportsIID)) {
nsIDOMNotation* tmp = this;
nsISupports* tmp2 = tmp;
*aInstancePtrResult = (void*) tmp2;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIDOMNodeIID)) {
nsIDOMNode* tmp = this;
*aInstancePtrResult = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIDOMEventReceiverIID)) {
nsIDOMEventReceiver* tmp = this;
*aInstancePtrResult = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIScriptObjectOwnerIID)) {
nsIScriptObjectOwner* tmp = this;
*aInstancePtrResult = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIContentIID)) {
nsIContent* tmp = this;
*aInstancePtrResult = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIDOMNotationIID)) {
nsIDOMNotation* tmp = this;
*aInstancePtrResult = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMETHODIMP
nsXMLNotation::GetPublicId(nsString& aPublicId)
{
aPublicId=mPublicId;
return NS_OK;
}
NS_IMETHODIMP
nsXMLNotation::GetSystemId(nsString& aSystemId)
{
aSystemId=mSystemId;
return NS_OK;
}
NS_IMETHODIMP
nsXMLNotation::GetScriptObject(nsIScriptContext* aContext,
void** aScriptObject)
{
nsresult res = NS_OK;
if (nsnull == mScriptObject) {
nsIDOMScriptObjectFactory *factory;
res = nsGenericElement::GetScriptObjectFactory(&factory);
if (NS_OK != res) {
return res;
}
res = factory->NewScriptNotation(aContext,
(nsISupports*)(nsIDOMNotation*)this,
mInner.mParent,
(void**)&mScriptObject);
NS_RELEASE(factory);
}
*aScriptObject = mScriptObject;
return res;
}
NS_IMETHODIMP
nsXMLNotation::SetScriptObject(void *aScriptObject)
{
mScriptObject = aScriptObject;
return NS_OK;
}
NS_IMETHODIMP
nsXMLNotation::GetTag(nsIAtom*& aResult) const
{
// aResult = nsLayoutAtoms::NotationTagName;
// NS_ADDREF(aResult);
aResult = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsXMLNotation::GetNodeName(nsString& aNodeName)
{
aNodeName=mName;
return NS_OK;
}
NS_IMETHODIMP
nsXMLNotation::GetNodeType(PRUint16* aNodeType)
{
*aNodeType = (PRUint16)nsIDOMNode::NOTATION_NODE;
return NS_OK;
}
NS_IMETHODIMP
nsXMLNotation::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
{
nsXMLNotation* it = new nsXMLNotation(mName,
mSystemId,
mPublicId);
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;
}
return it->QueryInterface(kIDOMNodeIID, (void**) aReturn);
}
NS_IMETHODIMP
nsXMLNotation::List(FILE* out, PRInt32 aIndent) const
{
NS_PRECONDITION(nsnull != mInner.mDocument, "bad content");
PRInt32 index;
for (index = aIndent; --index >= 0; ) fputs(" ", out);
fprintf(out, "Notation refcount=%d<!NOTATION ", mRefCnt);
nsAutoString tmp(mName);
if (mPublicId.Length()) {
tmp.Append(" PUBLIC \"");
tmp.Append(mPublicId);
tmp.Append("\"");
}
if (mSystemId.Length()) {
tmp.Append(" SYSTEM \"");
tmp.Append(mSystemId);
tmp.Append("\"");
}
fputs(tmp, out);
fputs(">\n", out);
return NS_OK;
}
NS_IMETHODIMP
nsXMLNotation::HandleDOMEvent(nsIPresContext& aPresContext,
nsEvent* aEvent,
nsIDOMEvent** aDOMEvent,
PRUint32 aFlags,
nsEventStatus& aEventStatus)
{
// We should never be getting events
NS_ASSERTION(0, "event handler called for notation");
return mInner.HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
aFlags, aEventStatus);
}

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

@ -42,6 +42,10 @@ CPPSRCS = \
nsGenericXMLElement.cpp \
nsXMLCDATASection.cpp \
nsXMLProcessingInstruction.cpp \
nsXMLEntity.cpp \
nsXMLNotation.cpp \
nsXMLDocumentType.cpp \
nsXMLNamedNodeMap.cpp \
$(NULL)
EXPORTS = \

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

@ -28,6 +28,10 @@ CPPSRCS= \
nsGenericXMLElement.cpp \
nsXMLCDATASection.cpp \
nsXMLProcessingInstruction.cpp \
nsXMLEntity.cpp \
nsXMLNotation.cpp \
nsXMLDocumentType.cpp \
nsXMLNamedNodeMap.cpp \
$(NULL)
CPP_OBJS= \
@ -35,6 +39,10 @@ CPP_OBJS= \
.\$(OBJDIR)\nsGenericXMLElement.obj \
.\$(OBJDIR)\nsXMLCDATASection.obj \
.\$(OBJDIR)\nsXMLProcessingInstruction.obj \
.\$(OBJDIR)\nsXMLEntity.obj \
.\$(OBJDIR)\nsXMLNotation.obj \
.\$(OBJDIR)\nsXMLDocumentType.obj \
.\$(OBJDIR)\nsXMLNamedNodeMap.obj \
$(NULL)
EXPORTS = \

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

@ -0,0 +1,298 @@
/* -*- 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 "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsIDOMDocumentType.h"
#include "nsIScriptObjectOwner.h"
#include "nsIDOMEventReceiver.h"
#include "nsIContent.h"
#include "nsGenericDOMDataNode.h"
#include "nsGenericElement.h"
#include "nsIDOMScriptObjectFactory.h"
#include "nsLayoutAtoms.h"
#include "nsString.h"
#include "nsIXMLContent.h"
static NS_DEFINE_IID(kIDOMDocumentTypeIID, NS_IDOMDOCUMENTTYPE_IID);
class nsXMLDocumentType : public nsIDOMDocumentType,
public nsIScriptObjectOwner,
public nsIDOMEventReceiver,
public nsIContent
{
public:
nsXMLDocumentType(const nsString& aTarget,
nsIDOMNamedNodeMap *aEntities,
nsIDOMNamedNodeMap *aNotations);
virtual ~nsXMLDocumentType();
// nsISupports
NS_DECL_ISUPPORTS
// nsIDOMNode
NS_IMPL_IDOMNODE_USING_GENERIC_DOM_DATA(mInner)
// nsIDOMDocumentType
NS_IMETHOD GetName(nsString& aName);
NS_IMETHOD GetEntities(nsIDOMNamedNodeMap** aEntities);
NS_IMETHOD GetNotations(nsIDOMNamedNodeMap** aNotations);
// nsIScriptObjectOwner interface
NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void *aScriptObject);
// nsIDOMEventReceiver
NS_IMPL_IDOMEVENTRECEIVER_USING_GENERIC_DOM_DATA(mInner)
// nsIContent
NS_IMPL_ICONTENT_USING_GENERIC_DOM_DATA(mInner)
protected:
// XXX Processing instructions are currently implemented by using
// the generic CharacterData inner object, even though PIs are not
// character data. This is done simply for convenience and should
// be changed if this restricts what should be done for character data.
nsGenericDOMDataNode mInner;
nsString mName;
nsIDOMNamedNodeMap* mEntities;
nsIDOMNamedNodeMap* mNotations;
void* mScriptObject;
};
nsresult
NS_NewXMLDocumentType(nsIContent** aInstancePtrResult,
const nsString& aName,
nsIDOMNamedNodeMap *aEntities,
nsIDOMNamedNodeMap *aNotations)
{
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
if (nsnull == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
nsIContent* it = new nsXMLDocumentType(aName, aEntities, aNotations);
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;
}
return it->QueryInterface(kIContentIID, (void **) aInstancePtrResult);
}
nsXMLDocumentType::nsXMLDocumentType(const nsString& aName,
nsIDOMNamedNodeMap *aEntities,
nsIDOMNamedNodeMap *aNotations) :
mName(aName)
{
NS_INIT_REFCNT();
mInner.Init(this);
mScriptObject = nsnull;
mEntities = aEntities;
mNotations = aNotations;
NS_IF_ADDREF(mEntities);
NS_IF_ADDREF(mNotations);
}
nsXMLDocumentType::~nsXMLDocumentType()
{
NS_IF_RELEASE(mEntities);
NS_IF_RELEASE(mNotations);
}
NS_IMPL_ADDREF(nsXMLDocumentType)
NS_IMPL_RELEASE(nsXMLDocumentType)
nsresult
nsXMLDocumentType::QueryInterface(REFNSIID aIID, void** aInstancePtrResult)
{
if (NULL == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kISupportsIID)) {
nsIDOMDocumentType* tmp = this;
nsISupports* tmp2 = tmp;
*aInstancePtrResult = (void*) tmp2;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIDOMNodeIID)) {
nsIDOMNode* tmp = this;
*aInstancePtrResult = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIDOMEventReceiverIID)) {
nsIDOMEventReceiver* tmp = this;
*aInstancePtrResult = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIScriptObjectOwnerIID)) {
nsIScriptObjectOwner* tmp = this;
*aInstancePtrResult = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIContentIID)) {
nsIContent* tmp = this;
*aInstancePtrResult = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIDOMDocumentTypeIID)) {
nsIDOMDocumentType* tmp = this;
*aInstancePtrResult = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMETHODIMP
nsXMLDocumentType::GetName(nsString& aName)
{
aName=mName;
return NS_OK;
}
NS_IMETHODIMP
nsXMLDocumentType::GetEntities(nsIDOMNamedNodeMap** aEntities)
{
if (!aEntities)
return NS_ERROR_FAILURE;
*aEntities = mEntities;
NS_IF_ADDREF(*aEntities);
return NS_OK;
}
NS_IMETHODIMP
nsXMLDocumentType::GetNotations(nsIDOMNamedNodeMap** aNotations)
{
if (!aNotations)
return NS_ERROR_FAILURE;
*aNotations = mNotations;
NS_IF_ADDREF(*aNotations);
return NS_OK;
}
NS_IMETHODIMP
nsXMLDocumentType::GetScriptObject(nsIScriptContext* aContext,
void** aScriptObject)
{
nsresult res = NS_OK;
if (nsnull == mScriptObject) {
nsIDOMScriptObjectFactory *factory;
res = nsGenericElement::GetScriptObjectFactory(&factory);
if (NS_OK != res) {
return res;
}
res = factory->NewScriptDocumentType(aContext,
(nsISupports*)(nsIDOMDocumentType*)this,
mInner.mParent,
(void**)&mScriptObject);
NS_RELEASE(factory);
}
*aScriptObject = mScriptObject;
return res;
}
NS_IMETHODIMP
nsXMLDocumentType::SetScriptObject(void *aScriptObject)
{
mScriptObject = aScriptObject;
return NS_OK;
}
NS_IMETHODIMP
nsXMLDocumentType::GetTag(nsIAtom*& aResult) const
{
// aResult = nsLayoutAtoms::processingInstructionTagName;
// NS_ADDREF(aResult);
aResult = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsXMLDocumentType::GetNodeName(nsString& aNodeName)
{
aNodeName=mName;
return NS_OK;
}
NS_IMETHODIMP
nsXMLDocumentType::GetNodeType(PRUint16* aNodeType)
{
*aNodeType = (PRUint16)nsIDOMNode::DOCUMENT_TYPE_NODE;
return NS_OK;
}
NS_IMETHODIMP
nsXMLDocumentType::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
{
nsString data;
mInner.GetData(data);
nsXMLDocumentType* it = new nsXMLDocumentType(mName,
mEntities,
mNotations);
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;
}
return it->QueryInterface(kIDOMNodeIID, (void**) aReturn);
}
NS_IMETHODIMP
nsXMLDocumentType::List(FILE* out, PRInt32 aIndent) const
{
NS_PRECONDITION(nsnull != mInner.mDocument, "bad content");
PRInt32 index;
for (index = aIndent; --index >= 0; ) fputs(" ", out);
fprintf(out, "Document type...\n", mRefCnt);
return NS_OK;
}
NS_IMETHODIMP
nsXMLDocumentType::HandleDOMEvent(nsIPresContext& aPresContext,
nsEvent* aEvent,
nsIDOMEvent** aDOMEvent,
PRUint32 aFlags,
nsEventStatus& aEventStatus)
{
// We should never be getting events
NS_ASSERTION(0, "event handler called for processing instruction");
return mInner.HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
aFlags, aEventStatus);
}

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

@ -0,0 +1,302 @@
/* -*- 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 "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsIDOMEntity.h"
#include "nsIScriptObjectOwner.h"
#include "nsIDOMEventReceiver.h"
#include "nsIContent.h"
#include "nsGenericDOMDataNode.h"
#include "nsGenericElement.h"
#include "nsIDOMScriptObjectFactory.h"
#include "nsLayoutAtoms.h"
#include "nsString.h"
#include "nsIXMLContent.h"
static NS_DEFINE_IID(kIDOMEntityIID, NS_IDOMENTITY_IID);
class nsXMLEntity : public nsIDOMEntity,
public nsIScriptObjectOwner,
public nsIDOMEventReceiver,
public nsIContent
{
public:
nsXMLEntity(const nsString& aName, const nsString& aPublicId,
const nsString& aSystemId, const nsString aNotationName);
virtual ~nsXMLEntity();
// nsISupports
NS_DECL_ISUPPORTS
// nsIDOMNode
NS_IMPL_IDOMNODE_USING_GENERIC_DOM_DATA(mInner)
// nsIDOMEntity
NS_IMETHOD GetPublicId(nsString& aPublicId);
NS_IMETHOD GetSystemId(nsString& aSystemId);
NS_IMETHOD GetNotationName(nsString& aNotationName);
// nsIScriptObjectOwner interface
NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void *aScriptObject);
// nsIDOMEventReceiver
NS_IMPL_IDOMEVENTRECEIVER_USING_GENERIC_DOM_DATA(mInner)
// nsIContent
NS_IMPL_ICONTENT_USING_GENERIC_DOM_DATA(mInner)
protected:
// XXX Processing instructions are currently implemented by using
// the generic CharacterData inner object, even though PIs are not
// character data. This is done simply for convenience and should
// be changed if this restricts what should be done for character data.
nsGenericDOMDataNode mInner;
nsString mName;
nsString mPublicId;
nsString mSystemId;
nsString mNotationName;
void* mScriptObject;
};
nsresult
NS_NewXMLEntity(nsIContent** aInstancePtrResult,
const nsString& aName,
const nsString& aPublicId,
const nsString& aSystemId,
const nsString aNotationName)
{
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
if (nsnull == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
nsIContent* it = new nsXMLEntity(aName, aPublicId, aSystemId, aNotationName);
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;
}
return it->QueryInterface(kIContentIID, (void **) aInstancePtrResult);
}
nsXMLEntity::nsXMLEntity(const nsString& aName,
const nsString& aPublicId,
const nsString& aSystemId,
const nsString aNotationName) :
mName(aName), mPublicId(aPublicId), mSystemId(aSystemId), mNotationName(aNotationName)
{
NS_INIT_REFCNT();
mInner.Init(this);
mScriptObject = nsnull;
}
nsXMLEntity::~nsXMLEntity()
{
}
NS_IMPL_ADDREF(nsXMLEntity)
NS_IMPL_RELEASE(nsXMLEntity)
nsresult
nsXMLEntity::QueryInterface(REFNSIID aIID, void** aInstancePtrResult)
{
if (NULL == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kISupportsIID)) {
nsIDOMEntity* tmp = this;
nsISupports* tmp2 = tmp;
*aInstancePtrResult = (void*) tmp2;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIDOMNodeIID)) {
nsIDOMNode* tmp = this;
*aInstancePtrResult = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIDOMEventReceiverIID)) {
nsIDOMEventReceiver* tmp = this;
*aInstancePtrResult = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIScriptObjectOwnerIID)) {
nsIScriptObjectOwner* tmp = this;
*aInstancePtrResult = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIContentIID)) {
nsIContent* tmp = this;
*aInstancePtrResult = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIDOMEntityIID)) {
nsIDOMEntity* tmp = this;
*aInstancePtrResult = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMETHODIMP
nsXMLEntity::GetPublicId(nsString& aPublicId)
{
aPublicId=mPublicId;
return NS_OK;
}
NS_IMETHODIMP
nsXMLEntity::GetSystemId(nsString& aSystemId)
{
aSystemId=mSystemId;
return NS_OK;
}
NS_IMETHODIMP
nsXMLEntity::GetNotationName(nsString& aNotationName)
{
aNotationName=mNotationName;
return NS_OK;
}
NS_IMETHODIMP
nsXMLEntity::GetScriptObject(nsIScriptContext* aContext,
void** aScriptObject)
{
nsresult res = NS_OK;
if (nsnull == mScriptObject) {
nsIDOMScriptObjectFactory *factory;
res = nsGenericElement::GetScriptObjectFactory(&factory);
if (NS_OK != res) {
return res;
}
res = factory->NewScriptEntity(aContext,
(nsISupports*)(nsIDOMEntity*)this,
mInner.mParent,
(void**)&mScriptObject);
NS_RELEASE(factory);
}
*aScriptObject = mScriptObject;
return res;
}
NS_IMETHODIMP
nsXMLEntity::SetScriptObject(void *aScriptObject)
{
mScriptObject = aScriptObject;
return NS_OK;
}
NS_IMETHODIMP
nsXMLEntity::GetTag(nsIAtom*& aResult) const
{
// aResult = nsLayoutAtoms::EntityTagName;
// NS_ADDREF(aResult);
aResult = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsXMLEntity::GetNodeName(nsString& aNodeName)
{
aNodeName=mName;
return NS_OK;
}
NS_IMETHODIMP
nsXMLEntity::GetNodeType(PRUint16* aNodeType)
{
*aNodeType = (PRUint16)nsIDOMNode::ENTITY_NODE;
return NS_OK;
}
NS_IMETHODIMP
nsXMLEntity::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
{
nsXMLEntity* it = new nsXMLEntity(mName,
mSystemId,
mPublicId,
mNotationName);
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;
}
return it->QueryInterface(kIDOMNodeIID, (void**) aReturn);
}
NS_IMETHODIMP
nsXMLEntity::List(FILE* out, PRInt32 aIndent) const
{
NS_PRECONDITION(nsnull != mInner.mDocument, "bad content");
PRInt32 index;
for (index = aIndent; --index >= 0; ) fputs(" ", out);
fprintf(out, "Entity refcount=%d<!ENTITY ", mRefCnt);
nsAutoString tmp(mName);
if (mPublicId.Length()) {
tmp.Append(" PUBLIC \"");
tmp.Append(mPublicId);
tmp.Append("\"");
}
if (mSystemId.Length()) {
tmp.Append(" SYSTEM \"");
tmp.Append(mSystemId);
tmp.Append("\"");
}
if (mNotationName.Length()) {
tmp.Append(" NDATA ");
tmp.Append(mNotationName);
}
fputs(tmp, out);
fputs(">\n", out);
return NS_OK;
}
NS_IMETHODIMP
nsXMLEntity::HandleDOMEvent(nsIPresContext& aPresContext,
nsEvent* aEvent,
nsIDOMEvent** aDOMEvent,
PRUint32 aFlags,
nsEventStatus& aEventStatus)
{
// We should never be getting events
NS_ASSERTION(0, "event handler called for entity");
return mInner.HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
aFlags, aEventStatus);
}

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

@ -0,0 +1,297 @@
/* -*- 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 "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsIDOMNamedNodeMap.h"
#include "nsIScriptObjectOwner.h"
#include "nsIDOMEventReceiver.h"
#include "nsIContent.h"
#include "nsGenericDOMDataNode.h"
#include "nsGenericElement.h"
#include "nsIDOMScriptObjectFactory.h"
#include "nsLayoutAtoms.h"
#include "nsString.h"
#include "nsIXMLContent.h"
#include "nsCOMPtr.h"
#include "nsISupportsArray.h"
static NS_DEFINE_IID(kIDOMNamedNodeMapIID, NS_IDOMNAMEDNODEMAP_IID);
class nsXMLNamedNodeMap : public nsIDOMNamedNodeMap,
public nsIScriptObjectOwner
{
public:
nsXMLNamedNodeMap(nsISupportsArray *aArray);
virtual ~nsXMLNamedNodeMap();
// nsISupports
NS_DECL_ISUPPORTS
// nsIDOMNamedNodeMap
NS_IMETHOD GetLength(PRUint32* aLength);
NS_IMETHOD GetNamedItem(const nsString& aName, nsIDOMNode** aReturn);
NS_IMETHOD SetNamedItem(nsIDOMNode* aArg, nsIDOMNode** aReturn);
NS_IMETHOD RemoveNamedItem(const nsString& aName, nsIDOMNode** aReturn);
NS_IMETHOD Item(PRUint32 aIndex, nsIDOMNode** aReturn);
// nsIScriptObjectOwner interface
NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void *aScriptObject);
protected:
nsISupportsArray *mArray;
void* mScriptObject;
};
nsresult
NS_NewXMLNamedNodeMap(nsIDOMNamedNodeMap** aInstancePtrResult,
nsISupportsArray *aArray)
{
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
if (nsnull == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
nsIDOMNamedNodeMap* it = new nsXMLNamedNodeMap(aArray);
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;
}
return it->QueryInterface(kIDOMNamedNodeMapIID, (void **) aInstancePtrResult);
}
nsXMLNamedNodeMap::nsXMLNamedNodeMap(nsISupportsArray *aArray)
{
NS_INIT_REFCNT();
mScriptObject = nsnull;
mArray = aArray;
NS_IF_ADDREF(mArray);
}
nsXMLNamedNodeMap::~nsXMLNamedNodeMap()
{
NS_IF_RELEASE(mArray);
}
NS_IMPL_ADDREF(nsXMLNamedNodeMap)
NS_IMPL_RELEASE(nsXMLNamedNodeMap)
nsresult
nsXMLNamedNodeMap::QueryInterface(REFNSIID aIID, void** aInstancePtrResult)
{
if (NULL == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kISupportsIID)) {
nsIDOMNamedNodeMap* tmp = this;
nsISupports* tmp2 = tmp;
*aInstancePtrResult = (void*) tmp2;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIScriptObjectOwnerIID)) {
nsIScriptObjectOwner* tmp = this;
*aInstancePtrResult = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIDOMNamedNodeMapIID)) {
nsIDOMNamedNodeMap* tmp = this;
*aInstancePtrResult = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMETHODIMP
nsXMLNamedNodeMap::GetLength(PRUint32* aLength)
{
if (mArray)
*aLength = mArray->Count();
else
*aLength = 0;
return NS_OK;
}
NS_IMETHODIMP
nsXMLNamedNodeMap::GetNamedItem(const nsString& aName, nsIDOMNode** aReturn)
{
if (!aReturn)
return NS_ERROR_NULL_POINTER;
*aReturn = 0;
if (!mArray)
return NS_OK;
PRUint32 i, count = mArray->Count();
for (i = 0; i < count; i++) {
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(mArray->ElementAt(i)));
if (!node)
break;
nsAutoString tmpName;
node->GetNodeName(tmpName);
if (aName.Equals(tmpName)) {
*aReturn = node;
break;
}
}
return NS_OK;
}
NS_IMETHODIMP
nsXMLNamedNodeMap::SetNamedItem(nsIDOMNode* aArg, nsIDOMNode** aReturn)
{
if (!aReturn || !aArg)
return NS_ERROR_NULL_POINTER;
*aReturn = 0;
nsAutoString argName;
aArg->GetNodeName(argName);
if (mArray) {
PRUint32 i, count = mArray->Count();
for (i = 0; i < count; i++) {
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(mArray->ElementAt(i)));
if (!node)
break;
nsAutoString tmpName;
node->GetNodeName(tmpName);
if (argName.Equals(tmpName)) {
mArray->ReplaceElementAt(aArg, i);
*aReturn = node;
break;
}
}
} else {
nsresult rv = NS_NewISupportsArray(&mArray);
if (NS_FAILED(rv))
return rv;
}
if (!*aReturn)
mArray->AppendElement(aArg);
return NS_OK;
}
NS_IMETHODIMP
nsXMLNamedNodeMap::RemoveNamedItem(const nsString& aName, nsIDOMNode** aReturn)
{
if (!aReturn)
return NS_ERROR_NULL_POINTER;
*aReturn = 0;
if (!mArray)
return NS_OK;
PRUint32 i, count = mArray->Count();
for (i = 0; i < count; i++) {
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(mArray->ElementAt(i)));
if (!node)
break;
nsAutoString tmpName;
node->GetNodeName(tmpName);
if (aName.Equals(tmpName)) {
*aReturn = node;
mArray->RemoveElementAt(i);
break;
}
}
return NS_OK;
}
NS_IMETHODIMP
nsXMLNamedNodeMap::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
{
if (!aReturn)
return NS_ERROR_NULL_POINTER;
if (mArray && aIndex < mArray->Count()) {
nsCOMPtr<nsIDOMNode> domNode(do_QueryInterface(mArray->ElementAt(aIndex)));
*aReturn = domNode;
} else
*aReturn = 0;
return NS_OK;
}
NS_IMETHODIMP
nsXMLNamedNodeMap::GetScriptObject(nsIScriptContext* aContext,
void** aScriptObject)
{
nsresult res = NS_OK;
if (nsnull == mScriptObject) {
nsIDOMScriptObjectFactory *factory;
res = nsGenericElement::GetScriptObjectFactory(&factory);
if (NS_OK != res) {
return res;
}
res = factory->NewScriptNamedNodeMap(aContext,
(nsISupports*)(nsIDOMNamedNodeMap*)this,
nsnull /*mInner.mParent*/,
(void**)&mScriptObject);
NS_RELEASE(factory);
}
*aScriptObject = mScriptObject;
return res;
}
NS_IMETHODIMP
nsXMLNamedNodeMap::SetScriptObject(void *aScriptObject)
{
mScriptObject = aScriptObject;
return NS_OK;
}

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

@ -0,0 +1,285 @@
/* -*- 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 "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsIDOMNotation.h"
#include "nsIScriptObjectOwner.h"
#include "nsIDOMEventReceiver.h"
#include "nsIContent.h"
#include "nsGenericDOMDataNode.h"
#include "nsGenericElement.h"
#include "nsIDOMScriptObjectFactory.h"
#include "nsLayoutAtoms.h"
#include "nsString.h"
#include "nsIXMLContent.h"
static NS_DEFINE_IID(kIDOMNotationIID, NS_IDOMNOTATION_IID);
class nsXMLNotation : public nsIDOMNotation,
public nsIScriptObjectOwner,
public nsIDOMEventReceiver,
public nsIContent
{
public:
nsXMLNotation(const nsString& aName,
const nsString& aPublicId,
const nsString& aSystemId);
virtual ~nsXMLNotation();
// nsISupports
NS_DECL_ISUPPORTS
// nsIDOMNode
NS_IMPL_IDOMNODE_USING_GENERIC_DOM_DATA(mInner)
// nsIDOMNotation
NS_IMETHOD GetPublicId(nsString& aPublicId);
NS_IMETHOD GetSystemId(nsString& aSystemId);
// nsIScriptObjectOwner interface
NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void *aScriptObject);
// nsIDOMEventReceiver
NS_IMPL_IDOMEVENTRECEIVER_USING_GENERIC_DOM_DATA(mInner)
// nsIContent
NS_IMPL_ICONTENT_USING_GENERIC_DOM_DATA(mInner)
protected:
// XXX Processing instructions are currently implemented by using
// the generic CharacterData inner object, even though PIs are not
// character data. This is done simply for convenience and should
// be changed if this restricts what should be done for character data.
nsGenericDOMDataNode mInner;
nsString mName;
nsString mPublicId;
nsString mSystemId;
void* mScriptObject;
};
nsresult
NS_NewXMLNotation(nsIContent** aInstancePtrResult,
const nsString& aName,
const nsString& aPublicId,
const nsString& aSystemId)
{
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
if (nsnull == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
nsIContent* it = new nsXMLNotation(aName, aPublicId, aSystemId);
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;
}
return it->QueryInterface(kIContentIID, (void **) aInstancePtrResult);
}
nsXMLNotation::nsXMLNotation(const nsString& aName,
const nsString& aPublicId,
const nsString& aSystemId) :
mName(aName), mPublicId(aPublicId), mSystemId(aSystemId)
{
NS_INIT_REFCNT();
mInner.Init(this);
mScriptObject = nsnull;
}
nsXMLNotation::~nsXMLNotation()
{
}
NS_IMPL_ADDREF(nsXMLNotation)
NS_IMPL_RELEASE(nsXMLNotation)
nsresult
nsXMLNotation::QueryInterface(REFNSIID aIID, void** aInstancePtrResult)
{
if (NULL == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kISupportsIID)) {
nsIDOMNotation* tmp = this;
nsISupports* tmp2 = tmp;
*aInstancePtrResult = (void*) tmp2;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIDOMNodeIID)) {
nsIDOMNode* tmp = this;
*aInstancePtrResult = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIDOMEventReceiverIID)) {
nsIDOMEventReceiver* tmp = this;
*aInstancePtrResult = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIScriptObjectOwnerIID)) {
nsIScriptObjectOwner* tmp = this;
*aInstancePtrResult = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIContentIID)) {
nsIContent* tmp = this;
*aInstancePtrResult = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIDOMNotationIID)) {
nsIDOMNotation* tmp = this;
*aInstancePtrResult = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMETHODIMP
nsXMLNotation::GetPublicId(nsString& aPublicId)
{
aPublicId=mPublicId;
return NS_OK;
}
NS_IMETHODIMP
nsXMLNotation::GetSystemId(nsString& aSystemId)
{
aSystemId=mSystemId;
return NS_OK;
}
NS_IMETHODIMP
nsXMLNotation::GetScriptObject(nsIScriptContext* aContext,
void** aScriptObject)
{
nsresult res = NS_OK;
if (nsnull == mScriptObject) {
nsIDOMScriptObjectFactory *factory;
res = nsGenericElement::GetScriptObjectFactory(&factory);
if (NS_OK != res) {
return res;
}
res = factory->NewScriptNotation(aContext,
(nsISupports*)(nsIDOMNotation*)this,
mInner.mParent,
(void**)&mScriptObject);
NS_RELEASE(factory);
}
*aScriptObject = mScriptObject;
return res;
}
NS_IMETHODIMP
nsXMLNotation::SetScriptObject(void *aScriptObject)
{
mScriptObject = aScriptObject;
return NS_OK;
}
NS_IMETHODIMP
nsXMLNotation::GetTag(nsIAtom*& aResult) const
{
// aResult = nsLayoutAtoms::NotationTagName;
// NS_ADDREF(aResult);
aResult = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsXMLNotation::GetNodeName(nsString& aNodeName)
{
aNodeName=mName;
return NS_OK;
}
NS_IMETHODIMP
nsXMLNotation::GetNodeType(PRUint16* aNodeType)
{
*aNodeType = (PRUint16)nsIDOMNode::NOTATION_NODE;
return NS_OK;
}
NS_IMETHODIMP
nsXMLNotation::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
{
nsXMLNotation* it = new nsXMLNotation(mName,
mSystemId,
mPublicId);
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;
}
return it->QueryInterface(kIDOMNodeIID, (void**) aReturn);
}
NS_IMETHODIMP
nsXMLNotation::List(FILE* out, PRInt32 aIndent) const
{
NS_PRECONDITION(nsnull != mInner.mDocument, "bad content");
PRInt32 index;
for (index = aIndent; --index >= 0; ) fputs(" ", out);
fprintf(out, "Notation refcount=%d<!NOTATION ", mRefCnt);
nsAutoString tmp(mName);
if (mPublicId.Length()) {
tmp.Append(" PUBLIC \"");
tmp.Append(mPublicId);
tmp.Append("\"");
}
if (mSystemId.Length()) {
tmp.Append(" SYSTEM \"");
tmp.Append(mSystemId);
tmp.Append("\"");
}
fputs(tmp, out);
fputs(">\n", out);
return NS_OK;
}
NS_IMETHODIMP
nsXMLNotation::HandleDOMEvent(nsIPresContext& aPresContext,
nsEvent* aEvent,
nsIDOMEvent** aDOMEvent,
PRUint32 aFlags,
nsEventStatus& aEventStatus)
{
// We should never be getting events
NS_ASSERTION(0, "event handler called for notation");
return mInner.HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
aFlags, aEventStatus);
}