1998-09-06 00:16:36 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1998-09-06 00:16:36 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* 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.
|
1998-09-06 00:16:36 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape Communications
|
1999-11-06 03:40:37 +00:00
|
|
|
* Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1998-09-06 00:16:36 +00:00
|
|
|
*/
|
1999-03-31 20:49:25 +00:00
|
|
|
|
1998-09-06 00:16:36 +00:00
|
|
|
#include "nsIDOMText.h"
|
|
|
|
#include "nsIScriptObjectOwner.h"
|
|
|
|
#include "nsIDOMEventReceiver.h"
|
1999-01-14 23:14:02 +00:00
|
|
|
#include "nsIContent.h"
|
1998-09-06 00:16:36 +00:00
|
|
|
#include "nsITextContent.h"
|
1999-03-31 20:49:25 +00:00
|
|
|
#include "nsGenericDOMDataNode.h"
|
1998-09-06 00:16:36 +00:00
|
|
|
#include "nsFrame.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsCRT.h"
|
1999-01-22 22:48:00 +00:00
|
|
|
#include "nsLayoutAtoms.h"
|
1998-09-06 00:16:36 +00:00
|
|
|
|
|
|
|
static NS_DEFINE_IID(kIDOMTextIID, NS_IDOMTEXT_IID);
|
|
|
|
static NS_DEFINE_IID(kITextContentIID, NS_ITEXT_CONTENT_IID);
|
|
|
|
|
|
|
|
class nsTextNode : public nsIDOMText,
|
|
|
|
public nsIScriptObjectOwner,
|
|
|
|
public nsITextContent
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsTextNode();
|
1999-05-13 02:11:25 +00:00
|
|
|
virtual ~nsTextNode();
|
1998-09-06 04:16:22 +00:00
|
|
|
|
1998-09-06 00:16:36 +00:00
|
|
|
// nsISupports
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// nsIDOMNode
|
|
|
|
NS_IMPL_IDOMNODE_USING_GENERIC_DOM_DATA(mInner)
|
|
|
|
|
1998-10-20 17:07:23 +00:00
|
|
|
// nsIDOMCharacterData
|
|
|
|
NS_IMPL_IDOMCHARACTERDATA_USING_GENERIC_DOM_DATA(mInner)
|
1998-09-06 00:16:36 +00:00
|
|
|
|
|
|
|
// nsIDOMText
|
1999-03-31 20:49:25 +00:00
|
|
|
NS_IMPL_IDOMTEXT_USING_GENERIC_DOM_DATA(mInner)
|
1998-09-06 00:16:36 +00:00
|
|
|
|
|
|
|
// nsIScriptObjectOwner
|
|
|
|
NS_IMPL_ISCRIPTOBJECTOWNER_USING_GENERIC_DOM_DATA(mInner)
|
|
|
|
|
|
|
|
// nsIContent
|
|
|
|
NS_IMPL_ICONTENT_USING_GENERIC_DOM_DATA(mInner)
|
|
|
|
|
1999-10-07 00:35:04 +00:00
|
|
|
NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const {
|
|
|
|
return mInner.SizeOf(aSizer, aResult, sizeof(*this));
|
|
|
|
}
|
|
|
|
|
1998-09-06 00:16:36 +00:00
|
|
|
// nsITextContent
|
1999-03-31 20:49:25 +00:00
|
|
|
NS_IMPL_ITEXTCONTENT_USING_GENERIC_DOM_DATA(mInner)
|
1999-03-27 01:20:15 +00:00
|
|
|
|
1998-09-06 00:16:36 +00:00
|
|
|
protected:
|
1998-09-06 04:16:22 +00:00
|
|
|
nsGenericDOMDataNode mInner;
|
1999-08-31 10:06:17 +00:00
|
|
|
PRUint32 mContentID;
|
1998-09-06 00:16:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
nsresult
|
1999-01-14 23:14:02 +00:00
|
|
|
NS_NewTextNode(nsIContent** aInstancePtrResult)
|
1998-09-06 00:16:36 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
|
|
|
|
if (nsnull == aInstancePtrResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1998-09-12 19:33:48 +00:00
|
|
|
nsTextNode* it;
|
|
|
|
NS_NEWXPCOM(it, nsTextNode);
|
1998-09-06 00:16:36 +00:00
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1999-01-14 23:14:02 +00:00
|
|
|
return it->QueryInterface(kIContentIID, (void **) aInstancePtrResult);
|
1998-09-06 00:16:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsTextNode::nsTextNode()
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
1999-08-31 10:06:17 +00:00
|
|
|
mContentID = 0;
|
1998-09-06 00:16:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsTextNode::~nsTextNode()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsTextNode)
|
|
|
|
NS_IMPL_RELEASE(nsTextNode)
|
|
|
|
|
1998-09-06 04:16:22 +00:00
|
|
|
NS_IMETHODIMP
|
1998-09-06 00:16:36 +00:00
|
|
|
nsTextNode::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
NS_IMPL_DOM_DATA_QUERY_INTERFACE(aIID, aInstancePtr, this)
|
|
|
|
if (aIID.Equals(kIDOMTextIID)) {
|
|
|
|
nsIDOMText* tmp = this;
|
|
|
|
*aInstancePtr = (void*) tmp;
|
1998-09-12 19:33:48 +00:00
|
|
|
NS_ADDREF_THIS();
|
1998-09-06 00:16:36 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kITextContentIID)) {
|
|
|
|
nsITextContent* tmp = this;
|
|
|
|
*aInstancePtr = (void*) tmp;
|
1998-09-12 19:33:48 +00:00
|
|
|
NS_ADDREF_THIS();
|
1998-09-06 00:16:36 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
1999-01-22 22:48:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextNode::GetTag(nsIAtom*& aResult) const
|
|
|
|
{
|
|
|
|
aResult = nsLayoutAtoms::textTagName;
|
|
|
|
NS_ADDREF(aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-05-12 14:09:28 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextNode::GetNodeInfo(nsINodeInfo*& aResult) const
|
|
|
|
{
|
|
|
|
aResult = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-01-19 23:07:33 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextNode::GetNodeName(nsString& aNodeName)
|
|
|
|
{
|
2000-04-03 11:20:35 +00:00
|
|
|
aNodeName.AssignWithConversion("#text");
|
1999-01-19 23:07:33 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-09-06 00:16:36 +00:00
|
|
|
NS_IMETHODIMP
|
1998-10-20 17:07:23 +00:00
|
|
|
nsTextNode::GetNodeType(PRUint16* aNodeType)
|
1998-09-06 00:16:36 +00:00
|
|
|
{
|
1998-10-20 17:07:23 +00:00
|
|
|
*aNodeType = (PRUint16)nsIDOMNode::TEXT_NODE;
|
1998-09-06 00:16:36 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-09-06 04:16:22 +00:00
|
|
|
NS_IMETHODIMP
|
1998-10-20 17:07:23 +00:00
|
|
|
nsTextNode::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
1998-09-06 00:16:36 +00:00
|
|
|
{
|
1999-08-25 07:35:45 +00:00
|
|
|
nsresult result = NS_OK;
|
1998-09-12 19:33:48 +00:00
|
|
|
nsTextNode* it;
|
|
|
|
NS_NEWXPCOM(it, nsTextNode);
|
1998-09-06 00:16:36 +00:00
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1999-08-25 07:35:45 +00:00
|
|
|
// XXX Increment the ref count before calling any
|
|
|
|
// methods. If they do a QI and then a Release()
|
|
|
|
// the instance will be deleted.
|
|
|
|
result = it->QueryInterface(kIDOMNodeIID, (void**) aReturn);
|
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
return result;
|
|
|
|
}
|
1999-01-06 00:57:17 +00:00
|
|
|
nsAutoString data;
|
1999-08-25 07:35:45 +00:00
|
|
|
result = GetData(data);
|
1999-01-06 00:57:17 +00:00
|
|
|
if (NS_FAILED(result)) {
|
1999-08-25 07:35:45 +00:00
|
|
|
NS_RELEASE(*aReturn);
|
1999-01-06 00:57:17 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
result = it->SetData(data);
|
|
|
|
if (NS_FAILED(result)) {
|
1999-08-25 07:35:45 +00:00
|
|
|
NS_RELEASE(*aReturn);
|
1999-01-06 00:57:17 +00:00
|
|
|
return result;
|
|
|
|
}
|
1999-08-25 07:35:45 +00:00
|
|
|
return result;
|
1998-09-06 00:16:36 +00:00
|
|
|
}
|
|
|
|
|
1999-12-22 01:51:58 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextNode::CloneContent(PRBool aCloneText, nsITextContent** aReturn)
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
nsTextNode* it;
|
|
|
|
NS_NEWXPCOM(it, nsTextNode);
|
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
result = it->QueryInterface(kITextContentIID, (void**) aReturn);
|
|
|
|
if (NS_FAILED(result) || !aCloneText) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
nsAutoString data;
|
|
|
|
result = GetData(data);
|
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
NS_RELEASE(*aReturn);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
result = it->SetData(data);
|
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
NS_RELEASE(*aReturn);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-09-06 00:16:36 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextNode::List(FILE* out, PRInt32 aIndent) const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != mInner.mDocument, "bad content");
|
|
|
|
|
|
|
|
PRInt32 index;
|
|
|
|
for (index = aIndent; --index >= 0; ) fputs(" ", out);
|
|
|
|
|
1999-11-01 15:23:06 +00:00
|
|
|
fprintf(out, "Text@%p refcount=%d<", this, mRefCnt);
|
1998-09-06 00:16:36 +00:00
|
|
|
|
|
|
|
nsAutoString tmp;
|
1998-10-20 00:20:04 +00:00
|
|
|
mInner.ToCString(tmp, 0, mInner.mText.GetLength());
|
1998-09-06 00:16:36 +00:00
|
|
|
fputs(tmp, out);
|
|
|
|
|
|
|
|
fputs(">\n", out);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-24 06:03:41 +00:00
|
|
|
nsTextNode::HandleDOMEvent(nsIPresContext* aPresContext,
|
1998-09-06 00:16:36 +00:00
|
|
|
nsEvent* aEvent,
|
|
|
|
nsIDOMEvent** aDOMEvent,
|
|
|
|
PRUint32 aFlags,
|
1999-11-24 06:03:41 +00:00
|
|
|
nsEventStatus* aEventStatus)
|
1998-09-06 00:16:36 +00:00
|
|
|
{
|
|
|
|
return mInner.HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
|
|
|
|
aFlags, aEventStatus);
|
|
|
|
}
|
1999-08-31 10:06:17 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextNode::GetContentID(PRUint32* aID)
|
|
|
|
{
|
|
|
|
*aID = mContentID;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextNode::SetContentID(PRUint32 aID)
|
|
|
|
{
|
|
|
|
mContentID = aID;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-12-22 01:51:58 +00:00
|
|
|
|