mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 04:15:43 +00:00
nuked
This commit is contained in:
parent
a388e31cbd
commit
2ca9353b6b
@ -1,381 +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 "nsDOMAttributes.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIHTMLContent.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsISupportsArray.h"
|
||||
|
||||
nsDOMAttribute::nsDOMAttribute(const nsString &aName, const nsString &aValue)
|
||||
{
|
||||
mName = new nsString(aName);
|
||||
mValue = new nsString(aValue);
|
||||
mRefCnt = 1;
|
||||
mScriptObject = nsnull;
|
||||
}
|
||||
|
||||
nsDOMAttribute::~nsDOMAttribute()
|
||||
{
|
||||
NS_PRECONDITION(nsnull != mName && nsnull != mValue, "attribute must be valid");
|
||||
delete mName;
|
||||
delete mValue;
|
||||
}
|
||||
|
||||
nsresult nsDOMAttribute::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(kIDOMAttributeIID, NS_IDOMATTRIBUTE_IID);
|
||||
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
|
||||
if (aIID.Equals(kIDOMAttributeIID)) {
|
||||
*aInstancePtr = (void*)(nsIDOMAttribute*)this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIScriptObjectOwnerIID)) {
|
||||
*aInstancePtr = (void*)(nsIScriptObjectOwner*)this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtr = (void*)(nsISupports*)(nsIDOMAttribute*)this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsDOMAttribute)
|
||||
|
||||
NS_IMPL_RELEASE(nsDOMAttribute)
|
||||
|
||||
|
||||
nsresult nsDOMAttribute::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
|
||||
{
|
||||
nsresult res = NS_OK;
|
||||
if (nsnull == mScriptObject) {
|
||||
res = NS_NewScriptAttribute(aContext, (nsISupports *)(nsIDOMAttribute *)this, nsnull, (void **)&mScriptObject);
|
||||
}
|
||||
*aScriptObject = mScriptObject;
|
||||
return res;
|
||||
}
|
||||
|
||||
nsresult nsDOMAttribute::SetScriptObject(void *aScriptObject)
|
||||
{
|
||||
mScriptObject = aScriptObject;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//
|
||||
// nsIDOMAttribute interface
|
||||
//
|
||||
nsresult nsDOMAttribute::GetName(nsString &aName)
|
||||
{
|
||||
aName = *mName;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsDOMAttribute::GetValue(nsString &aValue)
|
||||
{
|
||||
aValue = *mValue;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsDOMAttribute::GetSpecified(PRBool *aSpecified)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsresult nsDOMAttribute::SetSpecified(PRBool specified)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
// nsIDOMNode interface
|
||||
NS_IMETHODIMP
|
||||
nsDOMAttribute::GetNodeName(nsString& aNodeName)
|
||||
{
|
||||
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::AppendChild(nsIDOMNode* aNewChild, 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
|
||||
//
|
||||
nsDOMAttributeMap::nsDOMAttributeMap(nsIHTMLContent &aContent) :
|
||||
mContent(aContent)
|
||||
{
|
||||
mRefCnt = 1;
|
||||
mContent.AddRef();
|
||||
mScriptObject = nsnull;
|
||||
}
|
||||
|
||||
nsDOMAttributeMap::~nsDOMAttributeMap()
|
||||
{
|
||||
mContent.Release();
|
||||
}
|
||||
|
||||
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(kIDOMNamedNodeMapIID, NS_IDOMNAMEDNODEMAP_IID);
|
||||
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
|
||||
if (aIID.Equals(kIDOMNamedNodeMapIID)) {
|
||||
*aInstancePtr = (void*)(nsIDOMNamedNodeMap*)this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIScriptObjectOwnerIID)) {
|
||||
*aInstancePtr = (void*)(nsIScriptObjectOwner*)this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtr = (void*)(nsISupports*)(nsIDOMNamedNodeMap*)this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsDOMAttributeMap)
|
||||
|
||||
NS_IMPL_RELEASE(nsDOMAttributeMap)
|
||||
|
||||
nsresult nsDOMAttributeMap::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
|
||||
{
|
||||
nsresult res = NS_OK;
|
||||
if (nsnull == mScriptObject) {
|
||||
res = NS_NewScriptNamedNodeMap(aContext, (nsISupports *)(nsIDOMNamedNodeMap *)this, nsnull, (void**)&mScriptObject);
|
||||
}
|
||||
*aScriptObject = mScriptObject;
|
||||
return res;
|
||||
}
|
||||
|
||||
nsresult nsDOMAttributeMap::SetScriptObject(void *aScriptObject)
|
||||
{
|
||||
mScriptObject = aScriptObject;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsDOMAttributeMap::GetNamedItem(const nsString &aAttrName, nsIDOMNode** aAttribute)
|
||||
{
|
||||
nsAutoString value;
|
||||
mContent.GetAttribute(aAttrName, value);
|
||||
*aAttribute = (nsIDOMNode *)new nsDOMAttribute(aAttrName, value);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsDOMAttributeMap::SetNamedItem(nsIDOMNode *aNode)
|
||||
{
|
||||
nsIDOMAttribute *attribute;
|
||||
nsAutoString name, 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, PR_TRUE);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMAttributeMap::RemoveNamedItem(const nsString& aName, nsIDOMNode** aReturn)
|
||||
{
|
||||
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 nsDOMAttributeMap::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
|
||||
{
|
||||
nsresult res = NS_ERROR_FAILURE;
|
||||
nsAutoString name, value;
|
||||
nsISupportsArray *attributes = nsnull;
|
||||
if (NS_OK == NS_NewISupportsArray(&attributes)) {
|
||||
PRInt32 count;
|
||||
mContent.GetAllAttributeNames(attributes, count);
|
||||
if (count > 0) {
|
||||
if ((PRInt32)aIndex < count) {
|
||||
nsISupports *att = attributes->ElementAt(aIndex);
|
||||
static NS_DEFINE_IID(kIAtom, NS_IATOM_IID);
|
||||
nsIAtom *atName = nsnull;
|
||||
if (nsnull != att && NS_OK == att->QueryInterface(kIAtom, (void**)&atName)) {
|
||||
atName->ToString(name);
|
||||
if (NS_CONTENT_ATTR_NOT_THERE != mContent.GetAttribute(name, value)) {
|
||||
*aReturn = (nsIDOMNode *)new nsDOMAttribute(name, value);
|
||||
res = NS_OK;
|
||||
}
|
||||
NS_RELEASE(atName);
|
||||
}
|
||||
}
|
||||
}
|
||||
NS_RELEASE(attributes);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
nsresult nsDOMAttributeMap::GetLength(PRUint32 *aLength)
|
||||
{
|
||||
PRInt32 n;
|
||||
mContent.GetAttributeCount(n);
|
||||
*aLength = PRUint32(n);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,96 +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.
|
||||
*/
|
||||
|
||||
#ifndef nsDOMAttributes_h__
|
||||
#define nsDOMAttributes_h__
|
||||
|
||||
#include "nsIDOMAttribute.h"
|
||||
#include "nsIDOMNamedNodeMap.h"
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
|
||||
class nsIContent;
|
||||
class nsIHTMLContent;
|
||||
|
||||
class nsDOMAttribute : public nsIDOMAttribute, public nsIScriptObjectOwner {
|
||||
public:
|
||||
nsDOMAttribute(const nsString &aName, const nsString &aValue);
|
||||
virtual ~nsDOMAttribute();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
||||
NS_IMETHOD SetScriptObject(void *aScriptObject);
|
||||
|
||||
// nsIDOMAttribute interface
|
||||
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 AppendChild(nsIDOMNode* aNewChild, nsIDOMNode** aReturn);
|
||||
NS_IMETHOD CloneNode(nsIDOMNode** aReturn);
|
||||
NS_IMETHOD Equals(nsIDOMNode* aNode, PRBool aDeep, PRBool* aReturn);
|
||||
|
||||
private:
|
||||
nsString *mName;
|
||||
nsString *mValue;
|
||||
void *mScriptObject;
|
||||
};
|
||||
|
||||
|
||||
class nsDOMAttributeMap : public nsIDOMNamedNodeMap, public nsIScriptObjectOwner {
|
||||
public:
|
||||
nsDOMAttributeMap(nsIHTMLContent &aContent);
|
||||
virtual ~nsDOMAttributeMap();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
||||
NS_IMETHOD SetScriptObject(void *aScriptObject);
|
||||
|
||||
// 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;
|
||||
void *mScriptObject;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -1,190 +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 "nsDOMIterator.h"
|
||||
#include "nsIDOMNode.h"
|
||||
|
||||
static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID);
|
||||
|
||||
nsDOMIterator::nsDOMIterator(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();
|
||||
|
||||
mPosition = -1;
|
||||
mScriptObject = nsnull;
|
||||
}
|
||||
|
||||
nsDOMIterator::~nsDOMIterator()
|
||||
{
|
||||
mContent.Release();
|
||||
}
|
||||
|
||||
nsresult nsDOMIterator::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(kIDOMNodeIteratorIID, NS_IDOMNODEITERATOR_IID);
|
||||
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
|
||||
if (aIID.Equals(kIDOMNodeIteratorIID)) {
|
||||
*aInstancePtr = (void*)(nsIDOMNodeIterator*)this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIScriptObjectOwnerIID)) {
|
||||
*aInstancePtr = (void*)(nsIScriptObjectOwner*)this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtr = (void*)(nsISupports*)(nsIDOMNodeIterator*)this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsDOMIterator)
|
||||
|
||||
NS_IMPL_RELEASE(nsDOMIterator)
|
||||
|
||||
|
||||
nsresult nsDOMIterator::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
|
||||
{
|
||||
nsresult res = NS_OK;
|
||||
if (nsnull == mScriptObject) {
|
||||
res = NS_NewScriptNodeIterator(aContext, this, nsnull, (void**)&mScriptObject);
|
||||
}
|
||||
*aScriptObject = mScriptObject;
|
||||
return res;
|
||||
}
|
||||
|
||||
nsresult nsDOMIterator::SetScriptObject(void *aScriptObject)
|
||||
{
|
||||
mScriptObject = aScriptObject;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// nsIDOMIterator interface
|
||||
nsresult nsDOMIterator::SetFilter(PRInt32 aFilter, PRBool aFilterOn)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsresult nsDOMIterator::GetLength(PRUint32 *aLength)
|
||||
{
|
||||
*aLength = mContent.ChildCount();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsDOMIterator::GetCurrentNode(nsIDOMNode **aNode)
|
||||
{
|
||||
nsIContent *content = nsnull;
|
||||
nsresult res = NS_OK;
|
||||
content = mContent.ChildAt(mPosition);
|
||||
if (nsnull != content) {
|
||||
res = content->QueryInterface(kIDOMNodeIID, (void**)aNode);
|
||||
NS_RELEASE(content);
|
||||
}
|
||||
else {
|
||||
*aNode = nsnull;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
nsresult nsDOMIterator::GetNextNode(nsIDOMNode **aNode)
|
||||
{
|
||||
nsIContent *content = nsnull;
|
||||
nsresult res = NS_OK;
|
||||
content = mContent.ChildAt(++mPosition);
|
||||
if (nsnull != content) {
|
||||
res = content->QueryInterface(kIDOMNodeIID, (void**)aNode);
|
||||
NS_RELEASE(content);
|
||||
}
|
||||
else {
|
||||
mPosition = mContent.ChildCount();
|
||||
*aNode = nsnull;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
nsresult nsDOMIterator::GetPreviousNode(nsIDOMNode **aNode)
|
||||
{
|
||||
nsIContent *content = nsnull;
|
||||
nsresult res = NS_OK;
|
||||
content = mContent.ChildAt(--mPosition);
|
||||
if (nsnull != content) {
|
||||
res = content->QueryInterface(kIDOMNodeIID, (void**)aNode);
|
||||
NS_RELEASE(content);
|
||||
}
|
||||
else {
|
||||
mPosition = -1;
|
||||
*aNode = nsnull;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
nsresult nsDOMIterator::ToFirst(nsIDOMNode **aNode)
|
||||
{
|
||||
nsIContent *content = nsnull;
|
||||
nsresult res = NS_OK;
|
||||
mPosition = 0;
|
||||
content = mContent.ChildAt(mPosition);
|
||||
if (nsnull != content) {
|
||||
res = content->QueryInterface(kIDOMNodeIID, (void**)aNode);
|
||||
NS_RELEASE(content);
|
||||
}
|
||||
else {
|
||||
*aNode = nsnull;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
nsresult nsDOMIterator::ToLast(nsIDOMNode **aNode)
|
||||
{
|
||||
nsIContent *content = nsnull;
|
||||
nsresult res = NS_OK;
|
||||
mPosition = mPosition = mContent.ChildCount();
|
||||
content = mContent.ChildAt(mPosition);
|
||||
if (nsnull != content) {
|
||||
res = content->QueryInterface(kIDOMNodeIID, (void**)aNode);
|
||||
NS_RELEASE(content);
|
||||
}
|
||||
else {
|
||||
*aNode = nsnull;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
nsresult nsDOMIterator::MoveTo(int aNth, nsIDOMNode **aNode)
|
||||
{
|
||||
mPosition = aNth;
|
||||
return GetCurrentNode(aNode);
|
||||
}
|
||||
|
||||
|
@ -1,54 +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.
|
||||
*/
|
||||
|
||||
#ifndef nsDOMIterator_h__
|
||||
#define nsDOMIterator_h__
|
||||
|
||||
#include "nsIDOMNodeIterator.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
|
||||
class nsDOMIterator : public nsIDOMNodeIterator, public nsIScriptObjectOwner {
|
||||
public:
|
||||
nsDOMIterator(nsIContent &aContent);
|
||||
virtual ~nsDOMIterator();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
||||
NS_IMETHOD SetScriptObject(void *aScriptObject);
|
||||
|
||||
// nsIDOMIterator interface
|
||||
NS_IMETHOD SetFilter(PRInt32 aFilter, PRBool aFilterOn);
|
||||
NS_IMETHOD GetLength(PRUint32 *aLength);
|
||||
NS_IMETHOD GetCurrentNode(nsIDOMNode **aNode);
|
||||
NS_IMETHOD GetNextNode(nsIDOMNode **aNode);
|
||||
NS_IMETHOD GetPreviousNode(nsIDOMNode **aNode);
|
||||
NS_IMETHOD ToFirst(nsIDOMNode **aNode);
|
||||
NS_IMETHOD ToLast(nsIDOMNode **aNode);
|
||||
NS_IMETHOD MoveTo(int aNth, nsIDOMNode **aNode);
|
||||
|
||||
private:
|
||||
nsIContent &mContent;
|
||||
PRInt32 mPosition;
|
||||
void *mScriptObject;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -1,129 +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 "nsDOMNodeList.h"
|
||||
#include "nsIDOMNode.h"
|
||||
|
||||
static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID);
|
||||
|
||||
nsDOMNodeList::nsDOMNodeList(nsIContent *aContent) : mContent(aContent)
|
||||
{
|
||||
// Note that we don't add a reference to the content (to avoid
|
||||
// circular references). The content will tell us if it's going
|
||||
// away.
|
||||
mRefCnt = 0;
|
||||
mScriptObject = nsnull;
|
||||
}
|
||||
|
||||
nsDOMNodeList::~nsDOMNodeList()
|
||||
{
|
||||
}
|
||||
|
||||
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, (nsISupports *)(nsIDOMNodeList *)this, nsnull, (void**)&mScriptObject);
|
||||
}
|
||||
*aScriptObject = mScriptObject;
|
||||
return res;
|
||||
}
|
||||
|
||||
nsresult nsDOMNodeList::SetScriptObject(void *aScriptObject)
|
||||
{
|
||||
mScriptObject = aScriptObject;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// nsIDOMNodeList interface
|
||||
NS_IMETHODIMP
|
||||
nsDOMNodeList::GetLength(PRUint32* aLength)
|
||||
{
|
||||
if (nsnull != mContent) {
|
||||
PRInt32 n;
|
||||
mContent->ChildCount(n);
|
||||
*aLength = PRUint32(n);
|
||||
}
|
||||
else {
|
||||
*aLength = 0;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMNodeList::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
|
||||
{
|
||||
nsIContent *content = nsnull;
|
||||
nsresult res = NS_OK;
|
||||
if (nsnull != mContent) {
|
||||
mContent->ChildAt(aIndex, content);
|
||||
if (nsnull != content) {
|
||||
res = content->QueryInterface(kIDOMNodeIID, (void**)aReturn);
|
||||
NS_RELEASE(content);
|
||||
}
|
||||
else {
|
||||
*aReturn = nsnull;
|
||||
}
|
||||
}
|
||||
else {
|
||||
*aReturn = nsnull;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void
|
||||
nsDOMNodeList::ReleaseContent()
|
||||
{
|
||||
if (nsnull != mContent) {
|
||||
mContent = nsnull;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,50 +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.
|
||||
*/
|
||||
|
||||
#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 SetScriptObject(void *aScriptObject);
|
||||
|
||||
// nsIDOMNodeList interface
|
||||
NS_DECL_IDOMNODELIST
|
||||
|
||||
// Called to tell us that the content is going away and that we
|
||||
// should drop our (non ref-counted) reference to it
|
||||
void ReleaseContent();
|
||||
|
||||
private:
|
||||
nsIContent *mContent;
|
||||
void *mScriptObject;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -1,502 +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 "nsHTMLParts.h"
|
||||
#include "nsHTMLContainer.h"
|
||||
#include "nsIHTMLDocument.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsIArena.h"
|
||||
#include "nsIStyleContext.h"
|
||||
#include "nsStyleConsts.h"
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsIDeviceContext.h"
|
||||
#include "nsHTMLIIDs.h"
|
||||
#include "nsHTMLAtoms.h"
|
||||
#include "nsIHTMLAttributes.h"
|
||||
#include "nsIHTMLStyleSheet.h"
|
||||
#include "nsDOMNodeList.h"
|
||||
#include "nsUnitConversion.h"
|
||||
#include "nsStyleUtil.h"
|
||||
#include "nsIURL.h"
|
||||
#include "prprf.h"
|
||||
#include "nsISizeOfHandler.h"
|
||||
|
||||
|
||||
static NS_DEFINE_IID(kIHTMLDocumentIID, NS_IHTMLDOCUMENT_IID);
|
||||
|
||||
nsresult
|
||||
NS_NewHTMLContainer(nsIHTMLContent** aInstancePtrResult,
|
||||
nsIAtom* aTag)
|
||||
{
|
||||
nsHTMLContainer* it = new nsHTMLContainer(aTag);
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
return it->QueryInterface(kIHTMLContentIID, (void **) aInstancePtrResult);
|
||||
}
|
||||
|
||||
nsresult
|
||||
NS_NewHTMLContainer(nsIHTMLContent** aInstancePtrResult,
|
||||
nsIArena* aArena, nsIAtom* aTag)
|
||||
{
|
||||
nsHTMLContainer* it = new(aArena) nsHTMLContainer(aTag);
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
return it->QueryInterface(kIHTMLContentIID, (void **) aInstancePtrResult);
|
||||
}
|
||||
|
||||
nsHTMLContainer::nsHTMLContainer()
|
||||
{
|
||||
mChildNodes = nsnull;
|
||||
}
|
||||
|
||||
nsHTMLContainer::nsHTMLContainer(nsIAtom* aTag)
|
||||
: nsHTMLTagContent(aTag)
|
||||
{
|
||||
mChildNodes = nsnull;
|
||||
}
|
||||
|
||||
nsHTMLContainer::~nsHTMLContainer()
|
||||
{
|
||||
PRInt32 n = mChildren.Count();
|
||||
for (PRInt32 i = 0; i < n; i++) {
|
||||
nsIContent* kid = (nsIContent*) mChildren.ElementAt(i);
|
||||
NS_RELEASE(kid);
|
||||
}
|
||||
|
||||
if (nsnull != mChildNodes) {
|
||||
mChildNodes->ReleaseContent();
|
||||
NS_RELEASE(mChildNodes);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContainer::SizeOf(nsISizeOfHandler* aHandler) const
|
||||
{
|
||||
aHandler->Add(sizeof(*this));
|
||||
nsHTMLContainer::SizeOfWithoutThis(aHandler);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsHTMLContainer::SizeOfWithoutThis(nsISizeOfHandler* aHandler) const
|
||||
{
|
||||
aHandler->Add((size_t) (- (PRInt32)sizeof(mChildren) ) );
|
||||
mChildren.SizeOf(aHandler);
|
||||
|
||||
PRInt32 i, n = mChildren.Count();
|
||||
for (i = 0; i < n; i++) {
|
||||
nsIContent* child = (nsIContent*) mChildren[i];
|
||||
if (!aHandler->HaveSeen(child)) {
|
||||
child->SizeOf(aHandler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContainer::CanContainChildren(PRBool& aResult) const
|
||||
{
|
||||
aResult = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContainer::ChildCount(PRInt32& aCount) const
|
||||
{
|
||||
aCount = mChildren.Count();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContainer::ChildAt(PRInt32 aIndex, nsIContent*& aResult) const
|
||||
{
|
||||
nsIContent *child = (nsIContent*) mChildren.ElementAt(aIndex);
|
||||
if (nsnull != child) {
|
||||
NS_ADDREF(child);
|
||||
}
|
||||
aResult = child;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContainer::IndexOf(nsIContent* aPossibleChild, PRInt32& aIndex) const
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aPossibleChild, "null ptr");
|
||||
aIndex = mChildren.IndexOf(aPossibleChild);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContainer::InsertChildAt(nsIContent* aKid, PRInt32 aIndex,
|
||||
PRBool aNotify)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aKid, "null ptr");
|
||||
PRBool rv = mChildren.InsertElementAt(aKid, aIndex);/* XXX fix up void array api to use nsresult's*/
|
||||
if (rv) {
|
||||
NS_ADDREF(aKid);
|
||||
aKid->SetParent(this);
|
||||
nsIDocument* doc = mDocument;
|
||||
if (nsnull != doc) {
|
||||
aKid->SetDocument(doc);
|
||||
if (aNotify) {
|
||||
doc->ContentInserted(this, aKid, aIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContainer::ReplaceChildAt(nsIContent* aKid, PRInt32 aIndex,
|
||||
PRBool aNotify)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aKid, "null ptr");
|
||||
nsIContent* oldKid = (nsIContent*) mChildren.ElementAt(aIndex);
|
||||
PRBool rv = mChildren.ReplaceElementAt(aKid, aIndex);
|
||||
if (rv) {
|
||||
NS_ADDREF(aKid);
|
||||
aKid->SetParent(this);
|
||||
nsIDocument* doc = mDocument;
|
||||
if (nsnull != doc) {
|
||||
aKid->SetDocument(doc);
|
||||
if (aNotify) {
|
||||
doc->ContentReplaced(this, oldKid, aKid, aIndex);
|
||||
}
|
||||
}
|
||||
oldKid->SetDocument(nsnull);
|
||||
oldKid->SetParent(nsnull);
|
||||
NS_RELEASE(oldKid);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContainer::AppendChildTo(nsIContent* aKid, PRBool aNotify)
|
||||
{
|
||||
NS_PRECONDITION((nsnull != aKid) && (aKid != this), "null ptr");
|
||||
PRBool rv = mChildren.AppendElement(aKid);
|
||||
if (rv) {
|
||||
NS_ADDREF(aKid);
|
||||
aKid->SetParent(this);
|
||||
nsIDocument* doc = mDocument;
|
||||
if (nsnull != doc) {
|
||||
aKid->SetDocument(doc);
|
||||
if (aNotify) {
|
||||
doc->ContentAppended(this, mChildren.Count() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContainer::RemoveChildAt(PRInt32 aIndex, PRBool aNotify)
|
||||
{
|
||||
nsIContent* oldKid = (nsIContent*) mChildren.ElementAt(aIndex);
|
||||
if (nsnull != oldKid ) {
|
||||
nsIDocument* doc = mDocument;
|
||||
if (aNotify) {
|
||||
if (nsnull != doc) {
|
||||
doc->ContentWillBeRemoved(this, oldKid, aIndex);
|
||||
}
|
||||
}
|
||||
PRBool rv = mChildren.RemoveElementAt(aIndex);
|
||||
if (aNotify) {
|
||||
if (nsnull != doc) {
|
||||
doc->ContentHasBeenRemoved(this, oldKid, aIndex);
|
||||
}
|
||||
}
|
||||
oldKid->SetDocument(nsnull);
|
||||
oldKid->SetParent(nsnull);
|
||||
NS_RELEASE(oldKid);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContainer::Compact()
|
||||
{
|
||||
//XXX I'll turn this on in a bit... mChildren.Compact();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContainer::SetAttribute(nsIAtom* aAttribute,
|
||||
const nsString& aValue,
|
||||
PRBool aNotify)
|
||||
{
|
||||
return nsHTMLTagContent::SetAttribute(aAttribute, aValue, aNotify);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContainer::AttributeToString(nsIAtom* aAttribute,
|
||||
nsHTMLValue& aValue,
|
||||
nsString& aResult) const
|
||||
{
|
||||
return nsHTMLTagContent::AttributeToString(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContainer::GetAttributeMappingFunction(nsMapAttributesFunc& aMapFunc) const
|
||||
{
|
||||
NS_ERROR("you must override this method");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsHTMLContainer::MapBackgroundAttributesInto(nsIStyleContext* aContext,
|
||||
nsIPresContext* aPresContext)
|
||||
{
|
||||
nsHTMLValue value;
|
||||
|
||||
// background
|
||||
if (NS_CONTENT_ATTR_HAS_VALUE == GetAttribute(nsHTMLAtoms::background, value)) {
|
||||
if (eHTMLUnit_String == value.GetUnit()) {
|
||||
nsAutoString absURLSpec;
|
||||
nsAutoString spec;
|
||||
value.GetStringValue(spec);
|
||||
if (spec.Length() > 0) {
|
||||
// Resolve url to an absolute url
|
||||
nsIURL* docURL = nsnull;
|
||||
nsIDocument* doc = mDocument;
|
||||
if (nsnull != doc) {
|
||||
docURL = doc->GetDocumentURL();
|
||||
}
|
||||
|
||||
nsresult rv = NS_MakeAbsoluteURL(docURL, "", spec, absURLSpec);
|
||||
if (nsnull != docURL) {
|
||||
NS_RELEASE(docURL);
|
||||
}
|
||||
nsStyleColor* color = (nsStyleColor*)aContext->GetMutableStyleData(eStyleStruct_Color);
|
||||
color->mBackgroundImage = absURLSpec;
|
||||
color->mBackgroundFlags &= ~NS_STYLE_BG_IMAGE_NONE;
|
||||
color->mBackgroundRepeat = NS_STYLE_BG_REPEAT_XY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// bgcolor
|
||||
if (NS_CONTENT_ATTR_HAS_VALUE == GetAttribute(nsHTMLAtoms::bgcolor, value)) {
|
||||
if (eHTMLUnit_Color == value.GetUnit()) {
|
||||
nsStyleColor* color = (nsStyleColor*)aContext->GetMutableStyleData(eStyleStruct_Color);
|
||||
color->mBackgroundColor = value.GetColorValue();
|
||||
color->mBackgroundFlags &= ~NS_STYLE_BG_COLOR_TRANSPARENT;
|
||||
}
|
||||
else if (eHTMLUnit_String == value.GetUnit()) {
|
||||
nsAutoString buffer;
|
||||
value.GetStringValue(buffer);
|
||||
char cbuf[40];
|
||||
buffer.ToCString(cbuf, sizeof(cbuf));
|
||||
|
||||
nsStyleColor* color = (nsStyleColor*)aContext->GetMutableStyleData(eStyleStruct_Color);
|
||||
NS_ColorNameToRGB(cbuf, &(color->mBackgroundColor));
|
||||
color->mBackgroundFlags &= ~NS_STYLE_BG_COLOR_TRANSPARENT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// nsIDOMNode interface
|
||||
static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID);
|
||||
static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContainer::GetChildNodes(nsIDOMNodeList** aChildNodes)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aChildNodes, "null pointer");
|
||||
if (nsnull == mChildNodes) {
|
||||
mChildNodes = new nsDOMNodeList(this);
|
||||
NS_ADDREF(mChildNodes);
|
||||
}
|
||||
*aChildNodes = mChildNodes;
|
||||
NS_ADDREF(mChildNodes);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContainer::GetHasChildNodes(PRBool* aReturn)
|
||||
{
|
||||
if (0 != mChildren.Count()) {
|
||||
*aReturn = PR_TRUE;
|
||||
}
|
||||
else {
|
||||
*aReturn = PR_FALSE;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContainer::GetFirstChild(nsIDOMNode **aNode)
|
||||
{
|
||||
nsIContent *child = (nsIContent*) mChildren.ElementAt(0);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
PRInt32 i, n;
|
||||
aContent->ChildCount(n);
|
||||
for (i = 0; i < n; i++) {
|
||||
nsIContent* child;
|
||||
aContent->ChildAt(i, child);
|
||||
if (nsnull != child) {
|
||||
child->SetDocument(aDocument);
|
||||
SetDocumentInChildrenOf(child, aDocument);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// XXX It's possible that newChild has already been inserted in the
|
||||
// tree; if this is the case then we need to remove it from where it
|
||||
// was before placing it in it's new home
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContainer::InsertBefore(nsIDOMNode* aNewChild,
|
||||
nsIDOMNode* aRefChild,
|
||||
nsIDOMNode** aReturn)
|
||||
{
|
||||
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 = aNewChild->QueryInterface(kIContentIID, (void**)&newContent);
|
||||
NS_ASSERTION(NS_OK == res, "New child must be an nsIContent");
|
||||
if (NS_OK == res) {
|
||||
if (nsnull == aRefChild) {
|
||||
// Append the new child to the end
|
||||
SetDocumentInChildrenOf(newContent, mDocument);
|
||||
res = AppendChildTo(newContent, PR_TRUE);
|
||||
}
|
||||
else {
|
||||
// Get the index of where to insert the new child
|
||||
nsIContent* refContent = nsnull;
|
||||
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, pos);
|
||||
if (pos >= 0) {
|
||||
SetDocumentInChildrenOf(newContent, mDocument);
|
||||
res = InsertChildAt(newContent, pos, PR_TRUE);
|
||||
}
|
||||
NS_RELEASE(refContent);
|
||||
}
|
||||
}
|
||||
NS_RELEASE(newContent);
|
||||
|
||||
*aReturn = aNewChild;
|
||||
NS_ADDREF(aNewChild);
|
||||
}
|
||||
else {
|
||||
*aReturn = nsnull;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContainer::ReplaceChild(nsIDOMNode* aNewChild,
|
||||
nsIDOMNode* aOldChild,
|
||||
nsIDOMNode** aReturn)
|
||||
{
|
||||
nsIContent* content = nsnull;
|
||||
*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, pos);
|
||||
if (pos >= 0) {
|
||||
nsIContent* newContent = nsnull;
|
||||
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;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContainer::RemoveChild(nsIDOMNode* aOldChild,
|
||||
nsIDOMNode** aReturn)
|
||||
{
|
||||
nsIContent* content = nsnull;
|
||||
*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, pos);
|
||||
if (pos >= 0) {
|
||||
res = RemoveChildAt(pos, PR_TRUE);
|
||||
*aReturn = aOldChild;
|
||||
NS_ADDREF(aOldChild);
|
||||
}
|
||||
NS_RELEASE(content);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContainer::AppendChild(nsIDOMNode* aNewChild,
|
||||
nsIDOMNode** aReturn)
|
||||
{
|
||||
return InsertBefore(aNewChild, nsnull, aReturn);
|
||||
}
|
@ -1,88 +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.
|
||||
*/
|
||||
#ifndef nsHTMLContainer_h___
|
||||
#define nsHTMLContainer_h___
|
||||
|
||||
#include "nsHTMLTagContent.h"
|
||||
#include "nsVoidArray.h"
|
||||
|
||||
class nsDOMNodeList;
|
||||
// Generic HTML container class. This code manages an array of
|
||||
// children nodes that can be any kind of nsIContent
|
||||
class nsHTMLContainer : public nsHTMLTagContent {
|
||||
public:
|
||||
nsHTMLContainer(nsIAtom* aTag);
|
||||
|
||||
NS_IMETHOD SizeOf(nsISizeOfHandler* aHandler) const;
|
||||
|
||||
NS_IMETHOD CanContainChildren(PRBool& aResult) const;
|
||||
|
||||
NS_IMETHOD ChildCount(PRInt32& aResult) const;
|
||||
|
||||
NS_IMETHOD ChildAt(PRInt32 aIndex, nsIContent*& aResult) const;
|
||||
|
||||
NS_IMETHOD IndexOf(nsIContent* aPossibleChild, PRInt32& aIndex) const;
|
||||
|
||||
NS_IMETHOD InsertChildAt(nsIContent* aKid, PRInt32 aIndex, PRBool aNotify);
|
||||
NS_IMETHOD ReplaceChildAt(nsIContent* aKid, PRInt32 aIndex, PRBool aNotify);
|
||||
NS_IMETHOD AppendChildTo(nsIContent* aKid, PRBool aNotify);
|
||||
NS_IMETHOD RemoveChildAt(PRInt32 aIndex, PRBool aNotify);
|
||||
|
||||
NS_IMETHOD Compact();
|
||||
|
||||
NS_IMETHOD SetAttribute(nsIAtom* aAttribute, const nsString& aValue,
|
||||
PRBool aNotify);
|
||||
NS_IMETHOD GetAttributeMappingFunction(nsMapAttributesFunc& aMapFunc) const;
|
||||
|
||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
||||
nsHTMLValue& aValue,
|
||||
nsString& aResult) const;
|
||||
|
||||
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);
|
||||
NS_IMETHOD AppendChild(nsIDOMNode* aNewChild,
|
||||
nsIDOMNode** aReturn);
|
||||
|
||||
protected:
|
||||
nsHTMLContainer();
|
||||
virtual ~nsHTMLContainer();
|
||||
void SizeOfWithoutThis(nsISizeOfHandler* aHandler) const;
|
||||
|
||||
|
||||
/**
|
||||
* Helper method that maps "background" and "bgcolor" into
|
||||
* the style context.
|
||||
*/
|
||||
void MapBackgroundAttributesInto(nsIStyleContext* aContext,
|
||||
nsIPresContext* aPresContext);
|
||||
|
||||
nsVoidArray mChildren;
|
||||
nsDOMNodeList *mChildNodes;
|
||||
};
|
||||
|
||||
#endif /* nsHTMLContainer_h___ */
|
@ -1,669 +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 "nsHTMLContent.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIArena.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsIHTMLAttributes.h"
|
||||
#include "nsFrame.h"
|
||||
#include "nsHTMLIIDs.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsEventListenerManager.h"
|
||||
#include "nsIEventStateManager.h"
|
||||
#include "nsISizeOfHandler.h"
|
||||
#include "nsDOMEvent.h"
|
||||
#include "nsIPrivateDOMEvent.h"
|
||||
|
||||
static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID);
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID);
|
||||
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
|
||||
static NS_DEFINE_IID(kIEventListenerManagerIID, NS_IEVENTLISTENERMANAGER_IID);
|
||||
static NS_DEFINE_IID(kIDOMEventReceiverIID, NS_IDOMEVENTRECEIVER_IID);
|
||||
static NS_DEFINE_IID(kIPrivateDOMEventIID, NS_IPRIVATEDOMEVENT_IID);
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
void* nsHTMLContent::operator new(size_t size)
|
||||
{
|
||||
nsHTMLContent* rv = (nsHTMLContent*) ::operator new(size);
|
||||
nsCRT::zero(rv, size);
|
||||
rv->mInHeap = 1;
|
||||
return (void*) rv;
|
||||
}
|
||||
|
||||
void* nsHTMLContent::operator new(size_t size, nsIArena* aArena)
|
||||
{
|
||||
nsHTMLContent* rv = (nsHTMLContent*) aArena->Alloc(PRInt32(size));
|
||||
nsCRT::zero(rv, size);
|
||||
return (void*) rv;
|
||||
}
|
||||
|
||||
void nsHTMLContent::operator delete(void* ptr)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != ptr, "null ptr");
|
||||
nsHTMLContent* hc = (nsHTMLContent*) ptr;
|
||||
if (nsnull != hc) {
|
||||
if (hc->mInHeap) {
|
||||
::delete ptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsHTMLContent::nsHTMLContent()
|
||||
{
|
||||
mListenerManager = nsnull;
|
||||
}
|
||||
|
||||
nsHTMLContent::~nsHTMLContent()
|
||||
{
|
||||
NS_IF_RELEASE(mListenerManager);
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsHTMLContent)
|
||||
NS_IMPL_RELEASE(nsHTMLContent)
|
||||
|
||||
nsresult nsHTMLContent::QueryInterface(const nsIID& aIID,
|
||||
void** aInstancePtrResult)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
|
||||
if (nsnull == aInstancePtrResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aIID.Equals(kIHTMLContentIID)) {
|
||||
*aInstancePtrResult = (void*) ((nsIHTMLContent*)this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIContentIID)) {
|
||||
*aInstancePtrResult = (void*) ((nsIContent*)this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtrResult = (void*)(nsISupports*)(nsIContent*)this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIDOMNodeIID)) {
|
||||
*aInstancePtrResult = (void*)(nsIDOMNode*)this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIScriptObjectOwnerIID)) {
|
||||
*aInstancePtrResult = (void*)(nsIScriptObjectOwner*)this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIDOMEventReceiverIID)) {
|
||||
*aInstancePtrResult = (void*)(nsIDOMEventReceiver*)this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsHTMLContent::IsSynthetic(PRBool& aResult)
|
||||
{
|
||||
aResult = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::Compact()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::GetDocument(nsIDocument*& aResult) const
|
||||
{
|
||||
aResult = mDocument;
|
||||
NS_IF_ADDREF(mDocument);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::SetDocument(nsIDocument* aDocument)
|
||||
{
|
||||
mDocument = aDocument;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::GetParent(nsIContent*& aResult) const
|
||||
{
|
||||
NS_IF_ADDREF(mParent);
|
||||
aResult = mParent;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::SetParent(nsIContent* aParent)
|
||||
{
|
||||
mParent = aParent;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::CanContainChildren(PRBool& aResult) const
|
||||
{
|
||||
aResult = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::ChildCount(PRInt32& aCount) const
|
||||
{
|
||||
aCount = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::ChildAt(PRInt32 aIndex, nsIContent*& aResult) const
|
||||
{
|
||||
aResult = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::IndexOf(nsIContent* aPossibleChild, PRInt32& aResult) const
|
||||
{
|
||||
aResult = -1;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::InsertChildAt(nsIContent* aKid, PRInt32 aIndex, PRBool aNotify)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::ReplaceChildAt(nsIContent* aKid, PRInt32 aIndex, PRBool aNotify)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::AppendChildTo(nsIContent* aKid, PRBool aNotify)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::RemoveChildAt(PRInt32 aIndex, PRBool aNotify)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::SetAttribute(const nsString& aName, const nsString& aValue,
|
||||
PRBool aNotify)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::GetAttribute(const nsString& aName,
|
||||
nsString& aResult) const
|
||||
{
|
||||
aResult.SetLength(0);
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::SetAttribute(nsIAtom* aAttribute, const nsString& aValue,
|
||||
PRBool aNotify)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::GetAttribute(nsIAtom *aAttribute,
|
||||
nsString &aResult) const
|
||||
{
|
||||
aResult.SetLength(0);
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::SetAttribute(nsIAtom* aAttribute, const nsHTMLValue& aValue,
|
||||
PRBool aNotify)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::UnsetAttribute(nsIAtom* aAttribute)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::GetAttribute(nsIAtom* aAttribute,
|
||||
nsHTMLValue& aValue) const
|
||||
{
|
||||
aValue.Reset();
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::GetAllAttributeNames(nsISupportsArray* aArray,
|
||||
PRInt32& aCount) const
|
||||
{
|
||||
aCount = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::GetAttributeCount(PRInt32& aCount) const
|
||||
{
|
||||
aCount = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::GetAttributeMappingFunction(nsMapAttributesFunc& aMapFunc) const
|
||||
{
|
||||
aMapFunc = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::SetID(nsIAtom* aID)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::GetID(nsIAtom*& aResult) const
|
||||
{
|
||||
aResult = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::SetClass(nsIAtom* aClass)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::GetClass(nsIAtom*& aResult) const
|
||||
{
|
||||
aResult = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::GetStyleRule(nsIStyleRule*& aResult)
|
||||
{
|
||||
aResult = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void nsHTMLContent::ListAttributes(FILE* out) const
|
||||
{
|
||||
nsISupportsArray* attrs;
|
||||
if (NS_OK == NS_NewISupportsArray(&attrs)) {
|
||||
PRInt32 index, count;
|
||||
GetAllAttributeNames(attrs, count);
|
||||
for (index = 0; index < count; index++) {
|
||||
// name
|
||||
nsIAtom* attr = (nsIAtom*)attrs->ElementAt(index);
|
||||
nsAutoString buffer;
|
||||
attr->ToString(buffer);
|
||||
|
||||
// value
|
||||
nsAutoString value;
|
||||
GetAttribute(buffer, value);
|
||||
buffer.Append("=");
|
||||
buffer.Append(value);
|
||||
|
||||
fputs(" ", out);
|
||||
fputs(buffer, out);
|
||||
NS_RELEASE(attr);
|
||||
}
|
||||
NS_RELEASE(attrs);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::List(FILE* out, PRInt32 aIndent) const
|
||||
{
|
||||
NS_PRECONDITION(nsnull != mDocument, "bad content");
|
||||
|
||||
PRInt32 index;
|
||||
for (index = aIndent; --index >= 0; ) fputs(" ", out);
|
||||
|
||||
nsIAtom* tag;
|
||||
GetTag(tag);
|
||||
if (tag != nsnull) {
|
||||
nsAutoString buf;
|
||||
tag->ToString(buf);
|
||||
fputs(buf, out);
|
||||
NS_RELEASE(tag);
|
||||
}
|
||||
|
||||
ListAttributes(out);
|
||||
|
||||
fprintf(out, " RefCount=%d<\n", mRefCnt);
|
||||
|
||||
PRBool canHaveKids;
|
||||
CanContainChildren(canHaveKids);
|
||||
if (canHaveKids) {
|
||||
PRInt32 kids;
|
||||
ChildCount(kids);
|
||||
for (index = 0; index < kids; index++) {
|
||||
nsIContent* kid;
|
||||
ChildAt(index, kid);
|
||||
kid->List(out, aIndent + 1);
|
||||
NS_RELEASE(kid);
|
||||
}
|
||||
}
|
||||
|
||||
for (index = aIndent; --index >= 0; ) fputs(" ", out);
|
||||
fputs(">\n", out);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::SizeOf(nsISizeOfHandler* aHandler) const
|
||||
{
|
||||
aHandler->Add(sizeof(*this));
|
||||
nsHTMLContent::SizeOfWithoutThis(aHandler);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsHTMLContent::SizeOfWithoutThis(nsISizeOfHandler* aHandler) const
|
||||
{
|
||||
// XXX mScriptObject
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::GetTag(nsIAtom*& aResult) const
|
||||
{
|
||||
aResult = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::ToHTML(FILE* out) const
|
||||
{
|
||||
nsAutoString tmp;
|
||||
ToHTMLString(tmp);
|
||||
fputs(tmp, out);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsHTMLContent::SetScriptObject(void *aScriptObject)
|
||||
{
|
||||
mScriptObject = aScriptObject;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//
|
||||
// Implementation of nsIDOMNode interface
|
||||
//
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::GetParentNode(nsIDOMNode** aParentNode)
|
||||
{
|
||||
if (nsnull != mParent) {
|
||||
nsresult res = mParent->QueryInterface(kIDOMNodeIID, (void**)aParentNode);
|
||||
NS_ASSERTION(NS_OK == res, "Must be a DOM Node");
|
||||
return res;
|
||||
}
|
||||
else {
|
||||
*aParentNode = nsnull;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::GetChildNodes(nsIDOMNodeList** aChildNodes)
|
||||
{
|
||||
*aChildNodes = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::GetHasChildNodes(PRBool* aHasChildNodes)
|
||||
{
|
||||
*aHasChildNodes = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::GetFirstChild(nsIDOMNode** aFirstChild)
|
||||
{
|
||||
*aFirstChild = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
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, pos);
|
||||
if (pos > -1) {
|
||||
nsIContent* prev;
|
||||
mParent->ChildAt(--pos, prev);
|
||||
if (nsnull != prev) {
|
||||
nsresult res = prev->QueryInterface(kIDOMNodeIID, (void**)aNode);
|
||||
NS_ASSERTION(NS_OK == res, "Must be a DOM Node");
|
||||
|
||||
NS_RELEASE(prev); // balance the AddRef in ChildAt()
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*aNode = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::GetNextSibling(nsIDOMNode** aNextSibling)
|
||||
{
|
||||
if (nsnull != mParent) {
|
||||
PRInt32 pos;
|
||||
mParent->IndexOf(this, pos);
|
||||
if (pos > -1 ) {
|
||||
nsIContent* prev;
|
||||
mParent->ChildAt(++pos, prev);
|
||||
if (nsnull != prev) {
|
||||
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()
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*aNextSibling = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, nsIDOMNode** aReturn)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLContent::AppendChild(nsIDOMNode* aNewChild, nsIDOMNode** aReturn)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult nsHTMLContent::GetListenerManager(nsIEventListenerManager **aInstancePtrResult)
|
||||
{
|
||||
if (nsnull != mListenerManager) {
|
||||
return mListenerManager->QueryInterface(kIEventListenerManagerIID, (void**) aInstancePtrResult);;
|
||||
}
|
||||
if (NS_OK == NS_NewEventListenerManager(aInstancePtrResult)) {
|
||||
mListenerManager = *aInstancePtrResult;
|
||||
NS_ADDREF(mListenerManager);
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult nsHTMLContent::GetNewListenerManager(nsIEventListenerManager **aInstancePtrResult)
|
||||
{
|
||||
return NS_NewEventListenerManager(aInstancePtrResult);
|
||||
}
|
||||
|
||||
nsresult nsHTMLContent::AddEventListener(nsIDOMEventListener *aListener, const nsIID& aIID)
|
||||
{
|
||||
nsIEventListenerManager *mManager;
|
||||
|
||||
if (NS_OK == GetListenerManager(&mManager)) {
|
||||
mManager->AddEventListener(aListener, aIID);
|
||||
NS_RELEASE(mManager);
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult nsHTMLContent::RemoveEventListener(nsIDOMEventListener *aListener, const nsIID& aIID)
|
||||
{
|
||||
if (nsnull != mListenerManager) {
|
||||
mListenerManager->RemoveEventListener(aListener, aIID);
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult nsHTMLContent::HandleDOMEvent(nsIPresContext& aPresContext,
|
||||
nsEvent* aEvent,
|
||||
nsIDOMEvent** aDOMEvent,
|
||||
PRUint32 aFlags,
|
||||
nsEventStatus& aEventStatus)
|
||||
{
|
||||
nsresult ret = NS_OK;
|
||||
nsIDOMEvent* DOMEvent = nsnull;
|
||||
|
||||
if (DOM_EVENT_INIT == aFlags) {
|
||||
nsIEventStateManager *mManager;
|
||||
if (NS_OK == aPresContext.GetEventStateManager(&mManager)) {
|
||||
mManager->SetEventTarget((nsIHTMLContent*)this);
|
||||
NS_RELEASE(mManager);
|
||||
}
|
||||
|
||||
aDOMEvent = &DOMEvent;
|
||||
}
|
||||
|
||||
//Capturing stage
|
||||
/*if (mDocument->GetEventCapturer) {
|
||||
ret = mEventCapturer->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, aFlags, aEventStatus);
|
||||
}*/
|
||||
|
||||
//Local handling stage
|
||||
if (nsnull != mListenerManager) {
|
||||
ret = mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, aEventStatus);
|
||||
}
|
||||
|
||||
//Bubbling stage
|
||||
if (DOM_EVENT_CAPTURE != aFlags && mParent != nsnull) {
|
||||
ret = mParent->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, DOM_EVENT_BUBBLE, aEventStatus);
|
||||
}
|
||||
|
||||
if (DOM_EVENT_INIT == aFlags) {
|
||||
// We're leaving the DOM event loop so if we created a DOM event, release here.
|
||||
if (nsnull != *aDOMEvent) {
|
||||
nsrefcnt rc;
|
||||
NS_RELEASE2(*aDOMEvent, rc);
|
||||
if (0 != rc) {
|
||||
//Okay, so someone in the DOM loop (a listener, JS object) still has a ref to the DOM Event but
|
||||
//the internal data hasn't been malloc'd. Force a copy of the data here so the DOM Event is still valid.
|
||||
nsIPrivateDOMEvent *privateEvent;
|
||||
if (NS_OK == (*aDOMEvent)->QueryInterface(kIPrivateDOMEventIID, (void**)&privateEvent)) {
|
||||
privateEvent->DuplicatePrivateData();
|
||||
NS_RELEASE(privateEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
aDOMEvent = nsnull;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// XXX i18n: this is wrong (?) because we need to know the outgoing
|
||||
// character set (I think)
|
||||
void
|
||||
nsHTMLContent::QuoteForHTML(const nsString& aValue, nsString& aResult)
|
||||
{
|
||||
aResult.Truncate();
|
||||
const PRUnichar* cp = aValue.GetUnicode();
|
||||
const PRUnichar* end = aValue.GetUnicode() + aValue.Length();
|
||||
aResult.Append('"');
|
||||
while (cp < end) {
|
||||
PRUnichar ch = *cp++;
|
||||
if ((ch >= 0x20) && (ch <= 0x7f)) {
|
||||
if (ch == '\"') {
|
||||
aResult.Append(""");
|
||||
}
|
||||
else {
|
||||
aResult.Append(ch);
|
||||
}
|
||||
}
|
||||
else {
|
||||
aResult.Append("&#");
|
||||
aResult.Append((PRInt32) ch, 10);
|
||||
aResult.Append(';');
|
||||
}
|
||||
}
|
||||
aResult.Append('"');
|
||||
}
|
@ -1,187 +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.
|
||||
*/
|
||||
#ifndef nsHTMLContent_h___
|
||||
#define nsHTMLContent_h___
|
||||
|
||||
#include "nsIHTMLContent.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
#include "nsIDOMEventReceiver.h"
|
||||
#include "nsGUIEvent.h"
|
||||
class nsIEventListenerManager;
|
||||
class nsIArena;
|
||||
class nsIAtom;
|
||||
class nsXIFConverter;
|
||||
|
||||
/**
|
||||
* Abstract base class for un-tagged html content objects. Supports
|
||||
* allocation from the malloc heap as well as from an arena. Note
|
||||
* that instances of this object are created with zero'd memory.
|
||||
*/
|
||||
class nsHTMLContent : public nsIHTMLContent,
|
||||
public nsIDOMNode,
|
||||
public nsIScriptObjectOwner,
|
||||
public nsIDOMEventReceiver
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* This new method allocates memory from the standard malloc heap
|
||||
* and zeros out the content object.
|
||||
*/
|
||||
void* operator new(size_t size);
|
||||
|
||||
/**
|
||||
* This new method allocates memory from the given arena and
|
||||
* and zeros out the content object.
|
||||
*/
|
||||
void* operator new(size_t size, nsIArena* aArena);
|
||||
|
||||
/**
|
||||
* Release the memory associated with the content object. If the
|
||||
* object was allocated from an arena then nothing happens.
|
||||
*/
|
||||
void operator delete(void* ptr);
|
||||
|
||||
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
|
||||
NS_IMETHOD_(nsrefcnt) AddRef();
|
||||
NS_IMETHOD_(nsrefcnt) Release();
|
||||
|
||||
NS_IMETHOD GetDocument(nsIDocument*& aResult) const;
|
||||
NS_IMETHOD SetDocument(nsIDocument* aDocument);
|
||||
|
||||
NS_IMETHOD GetParent(nsIContent*& aResult) const;
|
||||
NS_IMETHOD SetParent(nsIContent* aParent);
|
||||
|
||||
NS_IMETHOD CanContainChildren(PRBool& aResult) const;
|
||||
|
||||
NS_IMETHOD ChildCount(PRInt32& aResult) const;
|
||||
|
||||
NS_IMETHOD ChildAt(PRInt32 aIndex, nsIContent*& aResult) const;
|
||||
|
||||
NS_IMETHOD IndexOf(nsIContent* aPossibleChild, PRInt32& aIndex) const;
|
||||
|
||||
NS_IMETHOD InsertChildAt(nsIContent* aKid, PRInt32 aIndex,
|
||||
PRBool aNotify);
|
||||
|
||||
NS_IMETHOD ReplaceChildAt(nsIContent* aKid, PRInt32 aIndex,
|
||||
PRBool aNotify);
|
||||
|
||||
NS_IMETHOD AppendChildTo(nsIContent* aKid, PRBool aNotify);
|
||||
|
||||
NS_IMETHOD RemoveChildAt(PRInt32 aIndex, PRBool aNotify);
|
||||
|
||||
NS_IMETHOD IsSynthetic(PRBool& aResult);
|
||||
|
||||
NS_IMETHOD Compact();
|
||||
|
||||
NS_IMETHOD SetAttribute(const nsString& aName,
|
||||
const nsString& aValue,
|
||||
PRBool aNotify);
|
||||
|
||||
NS_IMETHOD GetAttribute(const nsString& aName, nsString& aResult) const;
|
||||
|
||||
NS_IMETHOD SetAttribute(nsIAtom* aAttribute, const nsString& aValue,
|
||||
PRBool aNotify);
|
||||
|
||||
NS_IMETHOD SetAttribute(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
PRBool aNotify);
|
||||
|
||||
NS_IMETHOD UnsetAttribute(nsIAtom* aAttribute);
|
||||
|
||||
NS_IMETHOD GetAttribute(nsIAtom *aAttribute,
|
||||
nsString &aResult) const;
|
||||
NS_IMETHOD GetAttribute(nsIAtom* aAttribute,
|
||||
nsHTMLValue& aValue) const;
|
||||
|
||||
NS_IMETHOD GetAllAttributeNames(nsISupportsArray* aArray,
|
||||
PRInt32& aCountResult) const;
|
||||
NS_IMETHOD GetAttributeCount(PRInt32& aCountResult) const;
|
||||
NS_IMETHOD GetAttributeMappingFunction(nsMapAttributesFunc& aMapFunc) const;
|
||||
|
||||
NS_IMETHOD SetID(nsIAtom* aID);
|
||||
NS_IMETHOD GetID(nsIAtom*& aResult) const;
|
||||
// XXX this will have to change for CSS2
|
||||
NS_IMETHOD SetClass(nsIAtom* aClass);
|
||||
// XXX this will have to change for CSS2
|
||||
NS_IMETHOD GetClass(nsIAtom*& aResult) const;
|
||||
|
||||
NS_IMETHOD GetStyleRule(nsIStyleRule*& aResult);
|
||||
|
||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
||||
nsHTMLValue& aValue,
|
||||
nsString& aResult) const = 0;
|
||||
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsString& aValue,
|
||||
nsHTMLValue& aResult) = 0;
|
||||
|
||||
NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
||||
|
||||
NS_IMETHOD SizeOf(nsISizeOfHandler* aHandler) const;
|
||||
|
||||
NS_IMETHOD GetTag(nsIAtom*& aResult) const;
|
||||
|
||||
NS_IMETHOD ToHTML(FILE* out) const;
|
||||
|
||||
static void QuoteForHTML(const nsString& aValue, nsString& aResult);
|
||||
|
||||
NS_IMETHOD SetScriptObject(void *aScriptObject);
|
||||
|
||||
// nsIDOMNode interface
|
||||
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 AppendChild(nsIDOMNode* aNewChild, nsIDOMNode** aReturn);
|
||||
|
||||
// nsIDOMEventReceiver interface
|
||||
NS_IMETHOD AddEventListener(nsIDOMEventListener *aListener, const nsIID& aIID);
|
||||
NS_IMETHOD RemoveEventListener(nsIDOMEventListener *aListener, const nsIID& aIID);
|
||||
NS_IMETHOD GetListenerManager(nsIEventListenerManager** aInstancePtrResult);
|
||||
NS_IMETHOD GetNewListenerManager(nsIEventListenerManager** aInstancePtrResult);
|
||||
|
||||
NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext,
|
||||
nsEvent* aEvent,
|
||||
nsIDOMEvent** aDOMEvent,
|
||||
PRUint32 aFlags,
|
||||
nsEventStatus& aEventStatus);
|
||||
|
||||
protected:
|
||||
nsHTMLContent();
|
||||
virtual ~nsHTMLContent();
|
||||
virtual void ListAttributes(FILE* out) const;
|
||||
void SizeOfWithoutThis(nsISizeOfHandler* aHandler) const;
|
||||
|
||||
PRUint32 mInHeap : 1;
|
||||
PRUint32 mRefCnt : 31;
|
||||
nsIDocument* mDocument;
|
||||
nsIContent* mParent;
|
||||
void* mScriptObject;
|
||||
|
||||
nsIEventListenerManager* mListenerManager;
|
||||
};
|
||||
|
||||
#endif /* nsHTMLContent_h___ */
|
File diff suppressed because it is too large
Load Diff
@ -1,258 +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.
|
||||
*/
|
||||
#ifndef nsHTMLTagContent_h___
|
||||
#define nsHTMLTagContent_h___
|
||||
|
||||
#include "nsHTMLContent.h"
|
||||
#include "nsHTMLValue.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMHTMLElement.h"
|
||||
#include "nsIJSScriptObject.h"
|
||||
|
||||
class nsIHTMLAttributes;
|
||||
class nsIPresContext;
|
||||
class nsIStyleContext;
|
||||
|
||||
/**
|
||||
* Base class for tagged html content objects, holds attributes.
|
||||
*/
|
||||
class nsHTMLTagContent : public nsHTMLContent, public nsIDOMHTMLElement, public nsIJSScriptObject {
|
||||
public:
|
||||
|
||||
// nsIContent
|
||||
NS_IMETHOD GetTag(nsIAtom*& aResult) const;
|
||||
|
||||
NS_IMETHOD SizeOf(nsISizeOfHandler* aHandler) const;
|
||||
|
||||
// nsIHTMLContent
|
||||
/**
|
||||
* Translate the content object into it's source html format
|
||||
*/
|
||||
NS_IMETHOD ToHTMLString(nsString& aResult) const;
|
||||
|
||||
/**
|
||||
* Translate the content object into the (XIF) XML Interchange Format
|
||||
* XIF is an intermediate form of the content model, the buffer
|
||||
* will then be parsed into any number of formats including HTML, TXT, etc.
|
||||
|
||||
* BeginConvertToXIF -- opens a container and writes out the attributes
|
||||
* ConvertContentToXIF -- typically does nothing unless there is text content
|
||||
* FinishConvertToXIF -- closes a container
|
||||
*/
|
||||
NS_IMETHOD BeginConvertToXIF(nsXIFConverter& aConverter) const;
|
||||
NS_IMETHOD ConvertContentToXIF(nsXIFConverter& aConverter) const;
|
||||
NS_IMETHOD FinishConvertToXIF(nsXIFConverter& aConverter) const;
|
||||
|
||||
|
||||
/**
|
||||
* Generic implementation of SetAttribute that translates aName into
|
||||
* an uppercase'd atom and invokes SetAttribute(atom, aValue).
|
||||
*/
|
||||
NS_IMETHOD SetAttribute(const nsString& aName,
|
||||
const nsString& aValue,
|
||||
PRBool aNotify);
|
||||
|
||||
/**
|
||||
* Generic implementation of GetAttribute that knows how to map
|
||||
* nsHTMLValue's to string's. Note that it cannot map enumerated
|
||||
* values directly, but will use AttributeToString to supply a
|
||||
* conversion. Subclasses must override AttributeToString to map
|
||||
* enumerates to strings and return eContentAttr_HasValue when a
|
||||
* conversion is succesful. Subclasses should also override this
|
||||
* method if the default string conversions used don't apply
|
||||
* correctly to the given attribute.
|
||||
*/
|
||||
NS_IMETHOD GetAttribute(const nsString& aName, nsString& aResult) const;
|
||||
NS_IMETHOD GetAttribute(nsIAtom *aAttribute, nsString &aResult) const;
|
||||
NS_IMETHOD GetAttribute(nsIAtom* aAttribute, nsHTMLValue& aValue) const;
|
||||
|
||||
NS_IMETHOD SetAttribute(nsIAtom* aAttribute, const nsString& aValue,
|
||||
PRBool aNotify);
|
||||
NS_IMETHOD SetAttribute(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
PRBool aNotify);
|
||||
NS_IMETHOD UnsetAttribute(nsIAtom* aAttribute);
|
||||
|
||||
NS_IMETHOD GetAllAttributeNames(nsISupportsArray* aArray,
|
||||
PRInt32& aCountResult) const;
|
||||
NS_IMETHOD GetAttributeCount(PRInt32& aCountResult) const;
|
||||
NS_IMETHOD SetID(nsIAtom* aID);
|
||||
NS_IMETHOD GetID(nsIAtom*& aResult) const;
|
||||
// XXX this will have to change for CSS2
|
||||
NS_IMETHOD SetClass(nsIAtom* aClass);
|
||||
// XXX this will have to change for CSS2
|
||||
NS_IMETHOD GetClass(nsIAtom*& aResult) const;
|
||||
|
||||
NS_IMETHOD GetStyleRule(nsIStyleRule*& aResult);
|
||||
|
||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
||||
nsHTMLValue& aValue,
|
||||
nsString& aResult) const;
|
||||
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
|
||||
// Override from nsHTMLContent to allow setting of event handlers once
|
||||
// tag content is added to the doc tree.
|
||||
NS_IMETHOD SetDocument(nsIDocument* aDocument);
|
||||
|
||||
// nsIScriptObjectOwner interface
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
||||
|
||||
// nsIJSScriptObject interface
|
||||
virtual PRBool AddProperty(JSContext *aContext, jsval aID, jsval *aVp);
|
||||
virtual PRBool DeleteProperty(JSContext *aContext, jsval aID, jsval *aVp);
|
||||
virtual PRBool GetProperty(JSContext *aContext, jsval aID, jsval *aVp);
|
||||
virtual PRBool SetProperty(JSContext *aContext, jsval aID, jsval *aVp);
|
||||
virtual PRBool EnumerateProperty(JSContext *aContext);
|
||||
virtual PRBool Resolve(JSContext *aContext, jsval aID);
|
||||
virtual PRBool Convert(JSContext *aContext, jsval aID);
|
||||
virtual void Finalize(JSContext *aContext);
|
||||
virtual PRBool Construct(JSContext *cx, JSObject *obj, uintN argc,
|
||||
jsval *argv, jsval *rval);
|
||||
|
||||
// nsISupports interface
|
||||
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
||||
NS_IMETHOD_(nsrefcnt) Release(void);
|
||||
|
||||
// nsIDOMNode interface
|
||||
NS_DECL_IDOMNODE
|
||||
|
||||
// nsIDOMElement interface
|
||||
NS_DECL_IDOMELEMENT
|
||||
|
||||
// nsIDOMHTMLElement interface
|
||||
NS_DECL_IDOMHTMLELEMENT
|
||||
|
||||
// nsIDOMEventReceiver interface
|
||||
NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext,
|
||||
nsEvent* aEvent,
|
||||
nsIDOMEvent** aDOMEvent,
|
||||
PRUint32 aFlags,
|
||||
nsEventStatus& aEventStatus);
|
||||
|
||||
// Utility routines for making attribute parsing easier
|
||||
|
||||
struct EnumTable {
|
||||
const char* tag;
|
||||
PRInt32 value;
|
||||
};
|
||||
|
||||
static PRBool ParseEnumValue(const nsString& aValue,
|
||||
EnumTable* aTable,
|
||||
nsHTMLValue& aResult);
|
||||
|
||||
static PRBool EnumValueToString(const nsHTMLValue& aValue,
|
||||
EnumTable* aTable,
|
||||
nsString& aResult);
|
||||
|
||||
static PRBool ParseValueOrPercent(const nsString& aString,
|
||||
nsHTMLValue& aResult, nsHTMLUnit aValueUnit);
|
||||
|
||||
/** used to parser attribute values that could be either:
|
||||
* integer (n),
|
||||
* percent (n%),
|
||||
* or proportional (n*)
|
||||
*/
|
||||
static void ParseValueOrPercentOrProportional(const nsString& aString,
|
||||
nsHTMLValue& aResult,
|
||||
nsHTMLUnit aValueUnit);
|
||||
|
||||
static PRBool ValueOrPercentToString(const nsHTMLValue& aValue,
|
||||
nsString& aResult);
|
||||
|
||||
static PRBool ParseValue(const nsString& aString, PRInt32 aMin,
|
||||
nsHTMLValue& aResult, nsHTMLUnit aValueUnit);
|
||||
|
||||
static PRBool ParseValue(const nsString& aString, PRInt32 aMin, PRInt32 aMax,
|
||||
nsHTMLValue& aResult, nsHTMLUnit aValueUnit);
|
||||
|
||||
static PRBool ParseColor(const nsString& aString, nsHTMLValue& aResult);
|
||||
|
||||
static PRBool ColorToString(const nsHTMLValue& aValue,
|
||||
nsString& aResult);
|
||||
|
||||
/**
|
||||
* Parse width, height, border, hspace, vspace. Returns PR_TRUE if
|
||||
* the aAttribute is one of the listed attributes.
|
||||
*/
|
||||
static PRBool ParseImageProperty(nsIAtom* aAttribute,
|
||||
const nsString& aString,
|
||||
nsHTMLValue& aResult);
|
||||
|
||||
static PRBool ImagePropertyToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsString& aResult);
|
||||
|
||||
void MapImagePropertiesInto(nsIStyleContext* aContext,
|
||||
nsIPresContext* aPresContext);
|
||||
|
||||
void MapImageBorderInto(nsIStyleContext* aContext,
|
||||
nsIPresContext* aPresContext,
|
||||
nscolor aBorderColors[4]);
|
||||
|
||||
static PRBool ParseAlignParam(const nsString& aString, nsHTMLValue& aResult);
|
||||
|
||||
static PRBool AlignParamToString(const nsHTMLValue& aValue,
|
||||
nsString& aResult);
|
||||
|
||||
static PRBool ParseDivAlignParam(const nsString& aString, nsHTMLValue& aRes);
|
||||
|
||||
static PRBool DivAlignParamToString(const nsHTMLValue& aValue,
|
||||
nsString& aResult);
|
||||
|
||||
/** HTML4 table align attributes
|
||||
*/
|
||||
static PRBool ParseTableAlignParam(const nsString& aString, nsHTMLValue& aRes);
|
||||
|
||||
/** HTML4 table align attributes
|
||||
*/
|
||||
static PRBool TableAlignParamToString(const nsHTMLValue& aValue,
|
||||
nsString& aResult);
|
||||
|
||||
/** HTML4 table caption align attributes
|
||||
*/
|
||||
static PRBool ParseTableCaptionAlignParam(const nsString& aString, nsHTMLValue& aRes);
|
||||
|
||||
/** HTML4 table caption align attributes
|
||||
*/
|
||||
static PRBool TableCaptionAlignParamToString(const nsHTMLValue& aValue,
|
||||
nsString& aResult);
|
||||
|
||||
protected:
|
||||
nsHTMLTagContent();
|
||||
nsHTMLTagContent(nsIAtom* aTag);
|
||||
virtual ~nsHTMLTagContent();
|
||||
void SizeOfWithoutThis(nsISizeOfHandler* aHandler) const;
|
||||
|
||||
|
||||
virtual nsresult AddScriptEventListener(nsIAtom* aAttribute, const nsString& aValue, REFNSIID aIID);
|
||||
|
||||
void TriggerLink(nsIPresContext& aPresContext,
|
||||
const nsString& aBase,
|
||||
const nsString& aURLSpec,
|
||||
const nsString& aTargetSpec,
|
||||
PRBool aClick);
|
||||
|
||||
nsIAtom* mTag;
|
||||
nsIHTMLAttributes* mAttributes;
|
||||
};
|
||||
|
||||
#endif /* nsHTMLTagContent_h___ */
|
Loading…
Reference in New Issue
Block a user