2001-09-25 01:32:19 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1998-09-06 00:16:36 +00:00
|
|
|
*
|
2001-09-25 01:32:19 +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
|
|
|
*
|
2001-09-25 01:32:19 +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.
|
|
|
|
*
|
2001-09-25 01:32:19 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 03:40:37 +00:00
|
|
|
*
|
2001-09-25 01:32:19 +00:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1998-09-06 04:16:22 +00:00
|
|
|
#include "nsGenericDOMDataNode.h"
|
1999-01-14 23:14:02 +00:00
|
|
|
#include "nsGenericElement.h"
|
1999-01-21 19:33:03 +00:00
|
|
|
#include "nsIDocument.h"
|
1998-09-06 00:16:36 +00:00
|
|
|
#include "nsIEventListenerManager.h"
|
1998-12-17 07:22:28 +00:00
|
|
|
#include "nsIDOMRange.h"
|
1999-01-21 19:33:03 +00:00
|
|
|
#include "nsIDOMDocument.h"
|
1999-01-03 14:29:54 +00:00
|
|
|
#include "nsRange.h"
|
1999-10-21 20:40:51 +00:00
|
|
|
#include "nsTextContentChangeData.h"
|
2000-09-14 11:45:01 +00:00
|
|
|
#include "nsISelection.h"
|
|
|
|
#include "nsISelectionPrivate.h"
|
2000-08-23 17:27:06 +00:00
|
|
|
#include "nsReadableUtils.h"
|
2000-11-27 07:55:20 +00:00
|
|
|
#include "nsMutationEvent.h"
|
2001-12-16 06:59:31 +00:00
|
|
|
#include "nsINameSpaceManager.h"
|
1999-01-21 21:45:17 +00:00
|
|
|
|
1998-09-06 00:16:36 +00:00
|
|
|
#include "nsIPrivateDOMEvent.h"
|
2000-12-30 19:22:22 +00:00
|
|
|
#include "nsIDOMEvent.h"
|
1999-03-31 20:49:25 +00:00
|
|
|
#include "nsIDOMText.h"
|
1999-01-21 21:45:17 +00:00
|
|
|
#include "nsCOMPtr.h"
|
1998-09-06 00:16:36 +00:00
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
#include "pldhash.h"
|
|
|
|
#include "prprf.h"
|
|
|
|
|
|
|
|
static PLDHashTable *gEventListenerHash = nsnull;
|
|
|
|
static PLDHashTable *gRangeListsHash = nsnull;
|
|
|
|
|
|
|
|
|
|
|
|
class EventListenerManagerMapEntry : public PLDHashEntryHdr
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void *mKey; // must be first, to look like PLDHashEntryStub
|
|
|
|
nsIEventListenerManager *mListenerManager;
|
|
|
|
};
|
|
|
|
|
|
|
|
class RangeListMapEntry : public PLDHashEntryHdr
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void *mKey; // must be first, to look like PLDHashEntryStub
|
|
|
|
nsVoidArray *mRangeList;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
PR_STATIC_CALLBACK(PLDHashOperator)
|
|
|
|
EventListenerHashTeardownEnumFunc(PLDHashTable *table, PLDHashEntryHdr *hdr,
|
|
|
|
PRUint32 number, void *arg)
|
|
|
|
{
|
|
|
|
EventListenerManagerMapEntry *entry =
|
|
|
|
NS_STATIC_CAST(EventListenerManagerMapEntry *, hdr);
|
|
|
|
|
|
|
|
NS_RELEASE(entry->mListenerManager);
|
|
|
|
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PR_STATIC_CALLBACK(PLDHashOperator)
|
|
|
|
RangeListsHashTeardownEnumFunc(PLDHashTable *table, PLDHashEntryHdr *hdr,
|
|
|
|
PRUint32 number, void *arg)
|
|
|
|
{
|
|
|
|
RangeListMapEntry *entry = NS_STATIC_CAST(RangeListMapEntry *, hdr);
|
|
|
|
|
|
|
|
delete entry->mRangeList;
|
|
|
|
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
|
|
|
nsGenericDOMDataNode::Shutdown()
|
|
|
|
{
|
|
|
|
if (gEventListenerHash) {
|
|
|
|
PL_DHashTableEnumerate(gEventListenerHash,
|
|
|
|
EventListenerHashTeardownEnumFunc, nsnull);
|
|
|
|
|
|
|
|
PL_DHashTableDestroy(gEventListenerHash);
|
|
|
|
|
|
|
|
gEventListenerHash = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gRangeListsHash) {
|
|
|
|
PL_DHashTableEnumerate(gRangeListsHash, RangeListsHashTeardownEnumFunc,
|
|
|
|
nsnull);
|
|
|
|
|
|
|
|
PL_DHashTableDestroy(gRangeListsHash);
|
|
|
|
|
|
|
|
gRangeListsHash = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-09-06 00:16:36 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1998-09-06 04:16:22 +00:00
|
|
|
nsGenericDOMDataNode::nsGenericDOMDataNode()
|
2001-12-16 06:59:31 +00:00
|
|
|
: mText(), mDocument(nsnull), mParentPtrBits(0)
|
1998-09-06 00:16:36 +00:00
|
|
|
{
|
2001-12-16 06:59:31 +00:00
|
|
|
NS_INIT_ISUPPORTS();
|
1998-09-06 00:16:36 +00:00
|
|
|
}
|
|
|
|
|
1998-09-06 04:16:22 +00:00
|
|
|
nsGenericDOMDataNode::~nsGenericDOMDataNode()
|
1998-09-06 00:16:36 +00:00
|
|
|
{
|
2001-12-16 06:59:31 +00:00
|
|
|
if (HasEventListenerManager() && gEventListenerHash) {
|
|
|
|
EventListenerManagerMapEntry *entry =
|
|
|
|
NS_STATIC_CAST(EventListenerManagerMapEntry*,
|
|
|
|
PL_DHashTableOperate(gEventListenerHash, this,
|
|
|
|
PL_DHASH_LOOKUP));
|
|
|
|
|
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
|
|
|
|
entry->mListenerManager->SetListenerTarget(nsnull);
|
|
|
|
|
|
|
|
NS_RELEASE(entry->mListenerManager);
|
|
|
|
|
|
|
|
PL_DHashTableRawRemove(gEventListenerHash, entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (HasRangeList() && gRangeListsHash) {
|
|
|
|
RangeListMapEntry *entry =
|
|
|
|
NS_STATIC_CAST(RangeListMapEntry*,
|
|
|
|
PL_DHashTableOperate(gRangeListsHash, this,
|
|
|
|
PL_DHASH_LOOKUP));
|
|
|
|
|
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
|
|
|
|
NS_ASSERTION(entry->mRangeList, "No range list in entry!");
|
|
|
|
|
|
|
|
delete entry->mRangeList;
|
|
|
|
|
|
|
|
PL_DHashTableRawRemove(gRangeListsHash, entry);
|
|
|
|
}
|
2000-05-16 11:35:12 +00:00
|
|
|
}
|
1998-09-06 00:16:36 +00:00
|
|
|
}
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsGenericDOMDataNode)
|
|
|
|
NS_IMPL_RELEASE(nsGenericDOMDataNode)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsGenericDOMDataNode)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIContent)
|
|
|
|
if (aIID.Equals(NS_GET_IID(nsIDOMEventReceiver)) ||
|
|
|
|
aIID.Equals(NS_GET_IID(nsIDOMEventTarget))) {
|
|
|
|
foundInterface = NS_STATIC_CAST(nsIDOMEventReceiver *,
|
|
|
|
nsDOMEventRTTearoff::Create(this));
|
|
|
|
NS_ENSURE_TRUE(foundInterface, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
} else
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIContent)
|
|
|
|
// No nsITextContent since all subclasses might not want that.
|
|
|
|
NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOM3Node, nsNode3Tearoff(this))
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
|
1998-09-06 00:16:36 +00:00
|
|
|
nsresult
|
2000-08-23 17:27:06 +00:00
|
|
|
nsGenericDOMDataNode::GetNodeValue(nsAWritableString& aNodeValue)
|
1998-09-06 00:16:36 +00:00
|
|
|
{
|
1999-01-21 19:33:03 +00:00
|
|
|
return GetData(aNodeValue);
|
1998-09-06 00:16:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2001-12-16 06:59:31 +00:00
|
|
|
nsGenericDOMDataNode::SetNodeValue(const nsAReadableString& aNodeValue)
|
1998-09-06 00:16:36 +00:00
|
|
|
{
|
2001-12-16 06:59:31 +00:00
|
|
|
return SetData(aNodeValue);
|
1998-09-06 00:16:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
1998-09-06 04:16:22 +00:00
|
|
|
nsGenericDOMDataNode::GetParentNode(nsIDOMNode** aParentNode)
|
1998-09-06 00:16:36 +00:00
|
|
|
{
|
1999-04-17 00:56:25 +00:00
|
|
|
nsresult res = NS_OK;
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
nsIContent *parent_weak = GetParentWeak();
|
|
|
|
|
|
|
|
if (parent_weak) {
|
|
|
|
res = CallQueryInterface(parent_weak, aParentNode);
|
|
|
|
} else if (mDocument) {
|
1999-01-21 19:33:03 +00:00
|
|
|
// If we don't have a parent, but we're in the document, we must
|
1999-04-17 00:56:25 +00:00
|
|
|
// be the root node of the document. The DOM says that the root
|
|
|
|
// is the document.
|
2001-12-16 06:59:31 +00:00
|
|
|
res = CallQueryInterface(mDocument, aParentNode);
|
|
|
|
} else {
|
|
|
|
*aParentNode = nsnull;
|
1998-09-06 00:16:36 +00:00
|
|
|
}
|
1999-04-17 00:56:25 +00:00
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
NS_ASSERTION(NS_OK == res, "Must be a DOM Node");
|
|
|
|
|
1999-04-17 00:56:25 +00:00
|
|
|
return res;
|
1998-09-06 00:16:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2001-12-16 06:59:31 +00:00
|
|
|
nsGenericDOMDataNode::GetPreviousSibling(nsIDOMNode** aPrevSibling)
|
1998-09-06 00:16:36 +00:00
|
|
|
{
|
2001-12-16 06:59:31 +00:00
|
|
|
nsCOMPtr<nsIContent> sibling;
|
|
|
|
nsresult rv = NS_OK;
|
1999-03-31 20:49:25 +00:00
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
nsIContent *parent_weak = GetParentWeak();
|
|
|
|
|
|
|
|
if (parent_weak) {
|
1998-09-06 00:16:36 +00:00
|
|
|
PRInt32 pos;
|
2001-12-16 06:59:31 +00:00
|
|
|
parent_weak->IndexOf(this, pos);
|
1999-03-31 20:49:25 +00:00
|
|
|
if (pos > -1 ) {
|
2001-12-16 06:59:31 +00:00
|
|
|
parent_weak->ChildAt(--pos, *getter_AddRefs(sibling));
|
1998-09-06 00:16:36 +00:00
|
|
|
}
|
2001-12-16 06:59:31 +00:00
|
|
|
} else if (mDocument) {
|
1999-03-31 20:49:25 +00:00
|
|
|
// Nodes that are just below the document (their parent is the
|
|
|
|
// document) need to go to the document to find their next sibling.
|
|
|
|
PRInt32 pos;
|
2001-12-16 06:59:31 +00:00
|
|
|
mDocument->IndexOf(this, pos);
|
1999-03-31 20:49:25 +00:00
|
|
|
if (pos > -1 ) {
|
2001-12-16 06:59:31 +00:00
|
|
|
mDocument->ChildAt(--pos, *getter_AddRefs(sibling));
|
|
|
|
}
|
1999-03-31 20:49:25 +00:00
|
|
|
}
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
if (sibling) {
|
|
|
|
rv = CallQueryInterface(sibling, aPrevSibling);
|
|
|
|
NS_ASSERTION(rv == NS_OK, "Must be a DOM Node");
|
|
|
|
} else {
|
1999-03-31 20:49:25 +00:00
|
|
|
*aPrevSibling = nsnull;
|
|
|
|
}
|
2001-12-16 06:59:31 +00:00
|
|
|
|
|
|
|
return rv;
|
1998-09-06 00:16:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2001-12-16 06:59:31 +00:00
|
|
|
nsGenericDOMDataNode::GetNextSibling(nsIDOMNode** aNextSibling)
|
1998-09-06 00:16:36 +00:00
|
|
|
{
|
2001-12-16 06:59:31 +00:00
|
|
|
nsCOMPtr<nsIContent> sibling;
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
nsIContent *parent_weak = GetParentWeak();
|
1999-03-31 20:49:25 +00:00
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
if (parent_weak) {
|
1998-09-06 00:16:36 +00:00
|
|
|
PRInt32 pos;
|
2001-12-16 06:59:31 +00:00
|
|
|
parent_weak->IndexOf(this, pos);
|
1998-09-06 00:16:36 +00:00
|
|
|
if (pos > -1 ) {
|
2001-12-16 06:59:31 +00:00
|
|
|
parent_weak->ChildAt(++pos, *getter_AddRefs(sibling));
|
1998-09-06 00:16:36 +00:00
|
|
|
}
|
|
|
|
}
|
2001-12-16 06:59:31 +00:00
|
|
|
else if (mDocument) {
|
1999-03-31 20:49:25 +00:00
|
|
|
// Nodes that are just below the document (their parent is the
|
|
|
|
// document) need to go to the document to find their next sibling.
|
|
|
|
PRInt32 pos;
|
2001-12-16 06:59:31 +00:00
|
|
|
mDocument->IndexOf(this, pos);
|
1999-03-31 20:49:25 +00:00
|
|
|
if (pos > -1 ) {
|
2001-12-16 06:59:31 +00:00
|
|
|
mDocument->ChildAt(++pos, *getter_AddRefs(sibling));
|
|
|
|
}
|
1999-03-31 20:49:25 +00:00
|
|
|
}
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
if (sibling) {
|
|
|
|
rv = CallQueryInterface(sibling, aNextSibling);
|
|
|
|
NS_ASSERTION(rv == NS_OK, "Must be a DOM Node");
|
|
|
|
} else {
|
1999-03-31 20:49:25 +00:00
|
|
|
*aNextSibling = nsnull;
|
|
|
|
}
|
2001-12-16 06:59:31 +00:00
|
|
|
|
|
|
|
return rv;
|
1998-09-06 00:16:36 +00:00
|
|
|
}
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
nsresult
|
1999-08-25 07:35:45 +00:00
|
|
|
nsGenericDOMDataNode::GetChildNodes(nsIDOMNodeList** aChildNodes)
|
|
|
|
{
|
|
|
|
// XXX Since we believe this won't be done very often, we won't
|
|
|
|
// burn another slot in the data node and just create a new
|
|
|
|
// (empty) childNodes list every time we're asked.
|
|
|
|
nsChildContentList* list = new nsChildContentList(nsnull);
|
2001-12-16 06:59:31 +00:00
|
|
|
if (!list) {
|
1999-08-25 07:35:45 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2001-12-16 06:59:31 +00:00
|
|
|
|
|
|
|
return CallQueryInterface(list, aChildNodes);
|
1999-08-25 07:35:45 +00:00
|
|
|
}
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
nsresult
|
1998-10-20 17:07:23 +00:00
|
|
|
nsGenericDOMDataNode::GetOwnerDocument(nsIDOMDocument** aOwnerDocument)
|
|
|
|
{
|
|
|
|
// XXX Actually the owner document is the document in whose context
|
|
|
|
// the node has been created. We should be able to get at it
|
|
|
|
// whether or not we are attached to the document.
|
2001-12-16 06:59:31 +00:00
|
|
|
if (mDocument) {
|
|
|
|
return CallQueryInterface(mDocument, aOwnerDocument);
|
1998-10-20 17:07:23 +00:00
|
|
|
}
|
2001-12-16 06:59:31 +00:00
|
|
|
|
|
|
|
*aOwnerDocument = nsnull;
|
|
|
|
return NS_OK;
|
1998-10-20 17:07:23 +00:00
|
|
|
}
|
|
|
|
|
2000-04-01 13:31:23 +00:00
|
|
|
nsresult
|
2000-08-23 17:27:06 +00:00
|
|
|
nsGenericDOMDataNode::GetNamespaceURI(nsAWritableString& aNamespaceURI)
|
2000-04-01 13:31:23 +00:00
|
|
|
{
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
SetDOMStringToNull(aNamespaceURI);
|
|
|
|
|
2000-04-01 13:31:23 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2000-08-23 17:27:06 +00:00
|
|
|
nsGenericDOMDataNode::GetPrefix(nsAWritableString& aPrefix)
|
2000-04-01 13:31:23 +00:00
|
|
|
{
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
SetDOMStringToNull(aPrefix);
|
|
|
|
|
2000-04-01 13:31:23 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2000-08-23 17:27:06 +00:00
|
|
|
nsGenericDOMDataNode::SetPrefix(const nsAReadableString& aPrefix)
|
2000-04-01 13:31:23 +00:00
|
|
|
{
|
|
|
|
return NS_ERROR_DOM_NAMESPACE_ERR;
|
|
|
|
}
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
nsresult
|
|
|
|
nsGenericDOMDataNode::GetLocalName(nsAWritableString& aLocalName)
|
|
|
|
{
|
|
|
|
SetDOMStringToNull(aLocalName);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-04-01 13:31:23 +00:00
|
|
|
nsresult
|
|
|
|
nsGenericDOMDataNode::Normalize()
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2000-09-14 05:19:00 +00:00
|
|
|
nsGenericDOMDataNode::IsSupported(const nsAReadableString& aFeature,
|
|
|
|
const nsAReadableString& aVersion,
|
|
|
|
PRBool* aReturn)
|
2000-04-01 13:31:23 +00:00
|
|
|
{
|
2000-09-14 05:19:00 +00:00
|
|
|
return nsGenericElement::InternalIsSupported(aFeature, aVersion, aReturn);
|
2000-04-01 13:31:23 +00:00
|
|
|
}
|
|
|
|
|
2001-03-30 02:15:21 +00:00
|
|
|
nsresult
|
|
|
|
nsGenericDOMDataNode::GetBaseURI(nsAWritableString& aURI)
|
|
|
|
{
|
|
|
|
aURI.Truncate();
|
|
|
|
nsresult rv = NS_OK;
|
2001-12-16 06:59:31 +00:00
|
|
|
|
2001-03-30 02:15:21 +00:00
|
|
|
// DOM Data Node inherits the base from its parent element/document
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
nsCOMPtr<nsIDOM3Node> node;
|
2001-12-16 06:59:31 +00:00
|
|
|
|
|
|
|
nsIContent *parent_weak = GetParentWeak();
|
|
|
|
|
|
|
|
if (parent_weak) {
|
|
|
|
node = do_QueryInterface(parent_weak);
|
2001-03-30 02:15:21 +00:00
|
|
|
} else if (mDocument) {
|
|
|
|
node = do_QueryInterface(mDocument);
|
|
|
|
}
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
if (node) {
|
2001-03-30 02:15:21 +00:00
|
|
|
rv = node->GetBaseURI(aURI);
|
2001-12-16 06:59:31 +00:00
|
|
|
}
|
2001-03-30 02:15:21 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-09-11 03:04:49 +00:00
|
|
|
nsresult
|
|
|
|
nsGenericDOMDataNode::LookupNamespacePrefix(const nsAReadableString& aNamespaceURI,
|
2001-12-16 06:59:31 +00:00
|
|
|
nsAWritableString& aPrefix)
|
2001-09-11 03:04:49 +00:00
|
|
|
{
|
|
|
|
aPrefix.Truncate();
|
2001-12-16 06:59:31 +00:00
|
|
|
|
|
|
|
nsIContent *parent_weak = GetParentWeak();
|
|
|
|
|
2001-09-11 03:04:49 +00:00
|
|
|
// DOM Data Node passes the query on to its parent
|
2001-12-16 06:59:31 +00:00
|
|
|
nsCOMPtr<nsIDOM3Node> node(do_QueryInterface(parent_weak));
|
|
|
|
|
2001-09-11 03:04:49 +00:00
|
|
|
if (node) {
|
|
|
|
return node->LookupNamespacePrefix(aNamespaceURI, aPrefix);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsGenericDOMDataNode::LookupNamespaceURI(const nsAReadableString& aNamespacePrefix,
|
|
|
|
nsAWritableString& aNamespaceURI)
|
|
|
|
{
|
|
|
|
aNamespaceURI.Truncate();
|
2001-12-16 06:59:31 +00:00
|
|
|
|
|
|
|
nsIContent *parent_weak = GetParentWeak();
|
|
|
|
|
2001-09-11 03:04:49 +00:00
|
|
|
// DOM Data Node passes the query on to its parent
|
2001-12-16 06:59:31 +00:00
|
|
|
nsCOMPtr<nsIDOM3Node> node(do_QueryInterface(parent_weak));
|
|
|
|
|
2001-09-11 03:04:49 +00:00
|
|
|
if (node) {
|
|
|
|
return node->LookupNamespaceURI(aNamespacePrefix, aNamespaceURI);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-09-06 00:16:36 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1998-10-20 17:07:23 +00:00
|
|
|
// Implementation of nsIDOMCharacterData
|
1998-09-06 00:16:36 +00:00
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
nsresult
|
2000-08-23 17:27:06 +00:00
|
|
|
nsGenericDOMDataNode::GetData(nsAWritableString& aData)
|
1998-09-06 00:16:36 +00:00
|
|
|
{
|
1998-10-20 00:20:04 +00:00
|
|
|
if (mText.Is2b()) {
|
2000-03-12 09:14:14 +00:00
|
|
|
aData.Assign(mText.Get2b(), mText.GetLength());
|
2001-12-16 06:59:31 +00:00
|
|
|
} else {
|
|
|
|
// Must use Substring() since nsDependentCString() requires null
|
|
|
|
// terminated strings.
|
|
|
|
|
|
|
|
const char *data = mText.Get1b();
|
|
|
|
CopyASCIItoUCS2(Substring(data, data + mText.GetLength()), aData);
|
1998-10-20 00:20:04 +00:00
|
|
|
}
|
2001-12-16 06:59:31 +00:00
|
|
|
|
1998-09-06 00:16:36 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
nsresult
|
|
|
|
nsGenericDOMDataNode::SetData(const nsAReadableString& aData)
|
1998-09-06 00:16:36 +00:00
|
|
|
{
|
1999-01-03 14:29:54 +00:00
|
|
|
// inform any enclosed ranges of change
|
|
|
|
// we can lie and say we are deleting all the text, since in a total
|
|
|
|
// text replacement we should just collapse all the ranges.
|
1999-08-25 07:35:45 +00:00
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
if (HasRangeList()) {
|
|
|
|
nsRange::TextOwnerChanged(this, 0, mText.GetLength(), 0);
|
1999-08-25 07:35:45 +00:00
|
|
|
}
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
nsCOMPtr<nsITextContent> textContent = do_QueryInterface(this);
|
|
|
|
|
|
|
|
return SetText(aData, PR_TRUE);
|
1998-09-06 00:16:36 +00:00
|
|
|
}
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
nsresult
|
1998-10-20 17:07:23 +00:00
|
|
|
nsGenericDOMDataNode::GetLength(PRUint32* aLength)
|
1998-09-06 00:16:36 +00:00
|
|
|
{
|
1998-10-20 17:07:23 +00:00
|
|
|
*aLength = mText.GetLength();
|
1998-09-06 00:16:36 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
nsresult
|
2001-12-16 06:59:31 +00:00
|
|
|
nsGenericDOMDataNode::SubstringData(PRUint32 aStart, PRUint32 aCount,
|
2000-08-23 17:27:06 +00:00
|
|
|
nsAWritableString& aReturn)
|
1998-09-06 00:16:36 +00:00
|
|
|
{
|
|
|
|
aReturn.Truncate();
|
1998-10-20 00:20:04 +00:00
|
|
|
|
|
|
|
// XXX add <0 checks if types change
|
|
|
|
PRUint32 textLength = PRUint32( mText.GetLength() );
|
1999-10-15 22:18:23 +00:00
|
|
|
if (aStart > textLength) {
|
1999-10-06 00:06:53 +00:00
|
|
|
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
1998-09-06 00:16:36 +00:00
|
|
|
}
|
1998-10-20 00:20:04 +00:00
|
|
|
|
|
|
|
PRUint32 amount = aCount;
|
2001-11-16 03:01:29 +00:00
|
|
|
if (amount > textLength - aStart) {
|
1998-10-20 00:20:04 +00:00
|
|
|
amount = textLength - aStart;
|
|
|
|
}
|
2001-11-16 03:01:29 +00:00
|
|
|
|
1998-10-20 00:20:04 +00:00
|
|
|
if (mText.Is2b()) {
|
2000-03-12 09:14:14 +00:00
|
|
|
aReturn.Assign(mText.Get2b() + aStart, amount);
|
2001-12-16 06:59:31 +00:00
|
|
|
} else {
|
|
|
|
// Must use Substring() since nsDependentCString() requires null
|
|
|
|
// terminated strings.
|
|
|
|
|
|
|
|
const char *data = mText.Get1b() + aStart;
|
|
|
|
CopyASCIItoUCS2(Substring(data, data + amount), aReturn);
|
1998-10-20 00:20:04 +00:00
|
|
|
}
|
|
|
|
|
1998-09-06 00:16:36 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-10-21 20:40:51 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
nsresult
|
|
|
|
nsGenericDOMDataNode::AppendData(const nsAReadableString& aData)
|
1998-09-06 00:16:36 +00:00
|
|
|
{
|
1999-10-21 20:40:51 +00:00
|
|
|
#if 1
|
2001-12-16 06:59:31 +00:00
|
|
|
nsresult rv = NS_OK;
|
1999-11-23 23:13:03 +00:00
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
nsAutoString old_data;
|
1999-11-11 01:28:32 +00:00
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
mText.AppendTo(old_data);
|
1999-10-21 20:40:51 +00:00
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
rv = SetText(old_data + aData, PR_FALSE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1999-10-21 20:40:51 +00:00
|
|
|
|
|
|
|
// Trigger a reflow
|
2001-12-16 06:59:31 +00:00
|
|
|
if (mDocument) {
|
|
|
|
// This seems bad, why do we need to *allocate* a
|
|
|
|
// nsTextContentChangeData thingy here? Could it not be on the stack?
|
|
|
|
|
1999-10-21 20:40:51 +00:00
|
|
|
nsTextContentChangeData* tccd = nsnull;
|
2001-12-16 06:59:31 +00:00
|
|
|
rv = NS_NewTextContentChangeData(&tccd);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
tccd->SetData(nsITextContentChangeData::Append, old_data.Length(),
|
|
|
|
aData.Length());
|
|
|
|
rv = mDocument->ContentChanged(this, tccd);
|
1999-10-21 20:40:51 +00:00
|
|
|
NS_RELEASE(tccd);
|
2001-12-16 06:59:31 +00:00
|
|
|
} else {
|
|
|
|
rv = mDocument->ContentChanged(this, nsnull);
|
1999-10-21 20:40:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
return rv;
|
1999-10-21 20:40:51 +00:00
|
|
|
#else
|
1998-10-20 17:07:23 +00:00
|
|
|
return ReplaceData(mText.GetLength(), 0, aData);
|
1999-10-21 20:40:51 +00:00
|
|
|
#endif
|
1998-09-06 00:16:36 +00:00
|
|
|
}
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
nsresult
|
|
|
|
nsGenericDOMDataNode::InsertData(PRUint32 aOffset,
|
2000-08-23 17:27:06 +00:00
|
|
|
const nsAReadableString& aData)
|
1998-09-06 00:16:36 +00:00
|
|
|
{
|
2001-12-16 06:59:31 +00:00
|
|
|
return ReplaceData(aOffset, 0, aData);
|
1998-09-06 00:16:36 +00:00
|
|
|
}
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
nsresult
|
|
|
|
nsGenericDOMDataNode::DeleteData(PRUint32 aOffset, PRUint32 aCount)
|
1998-09-06 00:16:36 +00:00
|
|
|
{
|
|
|
|
nsAutoString empty;
|
2001-12-16 06:59:31 +00:00
|
|
|
return ReplaceData(aOffset, aCount, empty);
|
1998-09-06 00:16:36 +00:00
|
|
|
}
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
nsresult
|
|
|
|
nsGenericDOMDataNode::ReplaceData(PRUint32 aOffset, PRUint32 aCount,
|
|
|
|
const nsAReadableString& aData)
|
1998-09-06 00:16:36 +00:00
|
|
|
{
|
1999-08-25 07:35:45 +00:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
1998-09-06 00:16:36 +00:00
|
|
|
// sanitize arguments
|
1998-10-20 00:20:04 +00:00
|
|
|
PRUint32 textLength = mText.GetLength();
|
2001-03-27 15:40:15 +00:00
|
|
|
if (aOffset > textLength) {
|
1999-11-11 01:48:25 +00:00
|
|
|
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
1998-09-06 00:16:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate new buffer
|
1998-10-20 00:20:04 +00:00
|
|
|
PRUint32 endOffset = aOffset + aCount;
|
|
|
|
if (endOffset > textLength) {
|
|
|
|
aCount = textLength - aOffset;
|
|
|
|
endOffset = textLength;
|
1998-09-06 00:16:36 +00:00
|
|
|
}
|
|
|
|
PRInt32 dataLength = aData.Length();
|
1998-10-20 00:20:04 +00:00
|
|
|
PRInt32 newLength = textLength - aCount + dataLength;
|
2001-12-16 06:59:31 +00:00
|
|
|
PRUnichar* to = new PRUnichar[newLength + 1];
|
|
|
|
if (!to) {
|
1998-09-06 00:16:36 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
1999-01-03 14:29:54 +00:00
|
|
|
// inform any enclosed ranges of change
|
2001-12-16 06:59:31 +00:00
|
|
|
|
|
|
|
if (HasRangeList()) {
|
|
|
|
nsRange::TextOwnerChanged(this, aOffset, endOffset, dataLength);
|
|
|
|
}
|
|
|
|
|
1998-09-06 00:16:36 +00:00
|
|
|
// Copy over appropriate data
|
|
|
|
if (0 != aOffset) {
|
1998-10-20 00:20:04 +00:00
|
|
|
mText.CopyTo(to, 0, aOffset);
|
1998-09-06 00:16:36 +00:00
|
|
|
}
|
|
|
|
if (0 != dataLength) {
|
2000-12-12 21:58:13 +00:00
|
|
|
CopyUnicodeTo(aData, 0, to+aOffset, dataLength);
|
1998-09-06 00:16:36 +00:00
|
|
|
}
|
1998-10-20 00:20:04 +00:00
|
|
|
if (endOffset != textLength) {
|
|
|
|
mText.CopyTo(to + aOffset + dataLength, endOffset, textLength - endOffset);
|
1998-09-06 00:16:36 +00:00
|
|
|
}
|
|
|
|
|
1999-08-28 05:12:11 +00:00
|
|
|
// Null terminate the new buffer...
|
|
|
|
to[newLength] = (PRUnichar)0;
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
result = SetText(to, newLength, PR_TRUE);
|
1999-08-25 07:35:45 +00:00
|
|
|
delete [] to;
|
1998-09-06 00:16:36 +00:00
|
|
|
|
1999-08-25 07:35:45 +00:00
|
|
|
return result;
|
1998-09-06 00:16:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGenericDOMDataNode::GetListenerManager(nsIEventListenerManager** aResult)
|
1998-09-06 00:16:36 +00:00
|
|
|
{
|
2001-12-16 06:59:31 +00:00
|
|
|
nsCOMPtr<nsIEventListenerManager> listener_manager;
|
|
|
|
LookupListenerManager(getter_AddRefs(listener_manager));
|
|
|
|
|
|
|
|
if (listener_manager) {
|
|
|
|
*aResult = listener_manager;
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
|
1998-09-06 00:16:36 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-12-16 06:59:31 +00:00
|
|
|
|
|
|
|
if (!gEventListenerHash) {
|
|
|
|
gEventListenerHash =
|
|
|
|
PL_NewDHashTable(PL_DHashGetStubOps(), nsnull,
|
|
|
|
sizeof(EventListenerManagerMapEntry), 16);
|
|
|
|
|
|
|
|
if (!gEventListenerHash) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1998-09-06 00:16:36 +00:00
|
|
|
}
|
2001-12-16 06:59:31 +00:00
|
|
|
|
|
|
|
nsresult rv = NS_NewEventListenerManager(aResult);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Add a mapping to the hash table
|
|
|
|
EventListenerManagerMapEntry *entry =
|
|
|
|
NS_STATIC_CAST(EventListenerManagerMapEntry *,
|
|
|
|
PL_DHashTableOperate(gEventListenerHash, this,
|
|
|
|
PL_DHASH_ADD));
|
|
|
|
|
|
|
|
entry->mKey = this;
|
|
|
|
entry->mListenerManager = *aResult;
|
|
|
|
NS_ADDREF(entry->mListenerManager);
|
|
|
|
|
|
|
|
entry->mListenerManager->SetListenerTarget(this);
|
|
|
|
|
|
|
|
SetHasEventListenerManager(PR_TRUE);
|
|
|
|
|
|
|
|
return NS_OK;
|
1998-09-06 00:16:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Implementation of nsIContent
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
#ifdef DEBUG
|
1998-09-06 00:16:36 +00:00
|
|
|
void
|
2000-08-23 17:27:06 +00:00
|
|
|
nsGenericDOMDataNode::ToCString(nsAWritableString& aBuf, PRInt32 aOffset,
|
1998-09-06 00:16:36 +00:00
|
|
|
PRInt32 aLen) const
|
|
|
|
{
|
1998-10-20 00:20:04 +00:00
|
|
|
if (mText.Is2b()) {
|
|
|
|
const PRUnichar* cp = mText.Get2b() + aOffset;
|
|
|
|
const PRUnichar* end = cp + aLen;
|
2001-12-16 06:59:31 +00:00
|
|
|
|
1998-10-20 00:20:04 +00:00
|
|
|
while (cp < end) {
|
|
|
|
PRUnichar ch = *cp++;
|
|
|
|
if (ch == '\r') {
|
2000-08-23 17:27:06 +00:00
|
|
|
aBuf.Append(NS_LITERAL_STRING("\\r"));
|
1998-10-20 00:20:04 +00:00
|
|
|
} else if (ch == '\n') {
|
2000-08-23 17:27:06 +00:00
|
|
|
aBuf.Append(NS_LITERAL_STRING("\\n"));
|
1998-10-20 00:20:04 +00:00
|
|
|
} else if (ch == '\t') {
|
2000-08-23 17:27:06 +00:00
|
|
|
aBuf.Append(NS_LITERAL_STRING("\\t"));
|
1998-10-20 00:20:04 +00:00
|
|
|
} else if ((ch < ' ') || (ch >= 127)) {
|
|
|
|
char buf[10];
|
|
|
|
PR_snprintf(buf, sizeof(buf), "\\u%04x", ch);
|
2000-08-23 17:27:06 +00:00
|
|
|
aBuf.Append(NS_ConvertASCIItoUCS2(buf));
|
1998-10-20 00:20:04 +00:00
|
|
|
} else {
|
|
|
|
aBuf.Append(ch);
|
|
|
|
}
|
|
|
|
}
|
2001-12-16 06:59:31 +00:00
|
|
|
} else {
|
1998-10-20 00:20:04 +00:00
|
|
|
unsigned char* cp = (unsigned char*)mText.Get1b() + aOffset;
|
|
|
|
const unsigned char* end = cp + aLen;
|
2001-12-16 06:59:31 +00:00
|
|
|
|
1998-10-20 00:20:04 +00:00
|
|
|
while (cp < end) {
|
|
|
|
PRUnichar ch = *cp++;
|
|
|
|
if (ch == '\r') {
|
2000-08-23 17:27:06 +00:00
|
|
|
aBuf.Append(NS_LITERAL_STRING("\\r"));
|
1998-10-20 00:20:04 +00:00
|
|
|
} else if (ch == '\n') {
|
2000-08-23 17:27:06 +00:00
|
|
|
aBuf.Append(NS_LITERAL_STRING("\\n"));
|
1998-10-20 00:20:04 +00:00
|
|
|
} else if (ch == '\t') {
|
2000-08-23 17:27:06 +00:00
|
|
|
aBuf.Append(NS_LITERAL_STRING("\\t"));
|
1998-10-20 00:20:04 +00:00
|
|
|
} else if ((ch < ' ') || (ch >= 127)) {
|
|
|
|
char buf[10];
|
|
|
|
PR_snprintf(buf, sizeof(buf), "\\u%04x", ch);
|
2000-08-23 17:27:06 +00:00
|
|
|
aBuf.Append(NS_ConvertASCIItoUCS2(buf));
|
1998-10-20 00:20:04 +00:00
|
|
|
} else {
|
|
|
|
aBuf.Append(ch);
|
|
|
|
}
|
1998-09-06 00:16:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-12-16 06:59:31 +00:00
|
|
|
#endif
|
1998-09-06 00:16:36 +00:00
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
NS_IMETHODIMP
|
1998-09-06 04:16:22 +00:00
|
|
|
nsGenericDOMDataNode::GetDocument(nsIDocument*& aResult) const
|
1998-09-06 00:16:36 +00:00
|
|
|
{
|
|
|
|
aResult = mDocument;
|
|
|
|
NS_IF_ADDREF(mDocument);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-10-26 23:26:01 +00:00
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGenericDOMDataNode::SetDocument(nsIDocument* aDocument, PRBool aDeep,
|
|
|
|
PRBool aCompileEventHandlers)
|
1998-10-26 23:26:01 +00:00
|
|
|
{
|
1998-09-06 00:16:36 +00:00
|
|
|
mDocument = aDocument;
|
1998-10-26 23:26:01 +00:00
|
|
|
|
2001-12-12 04:28:25 +00:00
|
|
|
#ifdef IBMBIDI
|
2001-12-16 06:59:31 +00:00
|
|
|
if (mDocument && mText.IsBidi()) {
|
|
|
|
mDocument->SetBidiEnabled(PR_TRUE);
|
1998-10-26 23:26:01 +00:00
|
|
|
}
|
2001-12-16 06:59:31 +00:00
|
|
|
#endif
|
1998-10-26 23:26:01 +00:00
|
|
|
|
1998-09-06 00:16:36 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
NS_IMETHODIMP
|
1998-09-06 04:16:22 +00:00
|
|
|
nsGenericDOMDataNode::GetParent(nsIContent*& aResult) const
|
1998-09-06 00:16:36 +00:00
|
|
|
{
|
2001-12-16 06:59:31 +00:00
|
|
|
aResult = GetParentWeak();
|
|
|
|
NS_IF_ADDREF(aResult);
|
|
|
|
|
1998-09-06 00:16:36 +00:00
|
|
|
return NS_OK;;
|
|
|
|
}
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
NS_IMETHODIMP
|
1998-09-06 04:16:22 +00:00
|
|
|
nsGenericDOMDataNode::SetParent(nsIContent* aParent)
|
1998-09-06 00:16:36 +00:00
|
|
|
{
|
2001-12-16 06:59:31 +00:00
|
|
|
PtrBits new_bits = NS_REINTERPRET_CAST(PtrBits, aParent);
|
|
|
|
|
|
|
|
new_bits |= mParentPtrBits & PARENT_BIT_MASK;
|
|
|
|
|
|
|
|
mParentPtrBits = new_bits;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGenericDOMDataNode::GetNameSpaceID(PRInt32& aID) const
|
|
|
|
{
|
|
|
|
aID = kNameSpaceID_None;
|
1998-09-06 00:16:36 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGenericDOMDataNode::NormalizeAttrString(const nsAReadableString& aStr,
|
|
|
|
nsINodeInfo*& aNodeInfo)
|
|
|
|
{
|
|
|
|
aNodeInfo = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGenericDOMDataNode::SetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttr,
|
|
|
|
const nsAReadableString& aValue, PRBool aNotify)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGenericDOMDataNode::SetAttr(nsINodeInfo *aNodeInfo,
|
|
|
|
const nsAReadableString& aValue, PRBool aNotify)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGenericDOMDataNode::UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttr,
|
|
|
|
PRBool aNotify)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGenericDOMDataNode::GetAttr(PRInt32 aNameSpaceID, nsIAtom *aAttr,
|
|
|
|
nsAWritableString& aResult) const
|
|
|
|
{
|
|
|
|
aResult.Truncate();
|
|
|
|
|
|
|
|
return NS_CONTENT_ATTR_NOT_THERE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGenericDOMDataNode::GetAttr(PRInt32 aNameSpaceID, nsIAtom *aAttr,
|
|
|
|
nsIAtom*& aPrefix,
|
|
|
|
nsAWritableString& aResult) const
|
|
|
|
{
|
|
|
|
aPrefix = nsnull;
|
|
|
|
aResult.Truncate();
|
|
|
|
|
|
|
|
return NS_CONTENT_ATTR_NOT_THERE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(PRBool)
|
|
|
|
nsGenericDOMDataNode::HasAttr(PRInt32 aNameSpaceID, nsIAtom *aAttribute) const
|
|
|
|
{
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGenericDOMDataNode::GetAttrNameAt(PRInt32 aIndex, PRInt32& aNameSpaceID,
|
|
|
|
nsIAtom*& aName, nsIAtom*& aPrefix) const
|
|
|
|
{
|
|
|
|
aNameSpaceID = kNameSpaceID_None;
|
|
|
|
aName = nsnull;
|
|
|
|
aPrefix = nsnull;
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGenericDOMDataNode::GetAttrCount(PRInt32& aResult) const
|
|
|
|
{
|
|
|
|
aResult = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-24 06:03:41 +00:00
|
|
|
nsGenericDOMDataNode::HandleDOMEvent(nsIPresContext* aPresContext,
|
2001-12-16 06:59:31 +00:00
|
|
|
nsEvent* aEvent, nsIDOMEvent** aDOMEvent,
|
1998-09-06 00:16:36 +00:00
|
|
|
PRUint32 aFlags,
|
1999-11-24 06:03:41 +00:00
|
|
|
nsEventStatus* aEventStatus)
|
1998-09-06 00:16:36 +00:00
|
|
|
{
|
|
|
|
nsresult ret = NS_OK;
|
|
|
|
nsIDOMEvent* domEvent = nsnull;
|
1999-03-28 22:22:54 +00:00
|
|
|
|
2001-11-14 10:06:21 +00:00
|
|
|
PRBool externalDOMEvent = PR_FALSE;
|
2001-12-16 06:59:31 +00:00
|
|
|
|
2000-05-16 11:35:12 +00:00
|
|
|
if (NS_EVENT_FLAG_INIT & aFlags) {
|
2000-05-17 05:27:22 +00:00
|
|
|
if (!aDOMEvent) {
|
|
|
|
aDOMEvent = &domEvent;
|
2001-11-14 10:06:21 +00:00
|
|
|
} else {
|
|
|
|
externalDOMEvent = PR_TRUE;
|
2000-05-17 05:27:22 +00:00
|
|
|
}
|
2001-12-16 06:59:31 +00:00
|
|
|
|
2000-05-16 11:35:12 +00:00
|
|
|
aEvent->flags = aFlags;
|
|
|
|
aFlags &= ~(NS_EVENT_FLAG_CANT_BUBBLE | NS_EVENT_FLAG_CANT_CANCEL);
|
2001-03-13 11:37:16 +00:00
|
|
|
}
|
1999-03-28 22:22:54 +00:00
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
nsIContent *parent_weak = GetParentWeak();
|
|
|
|
|
2001-03-13 11:37:16 +00:00
|
|
|
//Capturing stage evaluation
|
|
|
|
if (NS_EVENT_FLAG_BUBBLE != aFlags) {
|
1999-03-28 22:22:54 +00:00
|
|
|
//Initiate capturing phase. Special case first call to document
|
2001-12-16 06:59:31 +00:00
|
|
|
if (parent_weak) {
|
|
|
|
parent_weak->HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
|
|
|
|
NS_EVENT_FLAG_CAPTURE, aEventStatus);
|
|
|
|
} else if (mDocument) {
|
|
|
|
ret = mDocument->HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
|
|
|
|
NS_EVENT_FLAG_CAPTURE, aEventStatus);
|
1999-03-28 22:22:54 +00:00
|
|
|
}
|
|
|
|
}
|
2001-12-16 06:59:31 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIEventListenerManager> listener_manager;
|
|
|
|
LookupListenerManager(getter_AddRefs(listener_manager));
|
|
|
|
|
1998-09-06 00:16:36 +00:00
|
|
|
//Local handling stage
|
2001-12-16 06:59:31 +00:00
|
|
|
if (listener_manager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH) &&
|
|
|
|
!(NS_EVENT_FLAG_BUBBLE & aFlags &&
|
|
|
|
NS_EVENT_FLAG_CANT_BUBBLE & aEvent->flags)
|
2001-11-07 06:29:29 +00:00
|
|
|
&& !(aEvent->flags & NS_EVENT_FLAG_NO_CONTENT_DISPATCH)) {
|
2000-02-08 02:05:57 +00:00
|
|
|
aEvent->flags |= aFlags;
|
2001-12-16 06:59:31 +00:00
|
|
|
listener_manager->HandleEvent(aPresContext, aEvent, aDOMEvent, nsnull,
|
|
|
|
aFlags, aEventStatus);
|
2000-02-08 02:05:57 +00:00
|
|
|
aEvent->flags &= ~aFlags;
|
1998-09-06 00:16:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Bubbling stage
|
2001-12-16 06:59:31 +00:00
|
|
|
if (NS_EVENT_FLAG_CAPTURE != aFlags && parent_weak) {
|
|
|
|
ret = parent_weak->HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
|
|
|
|
NS_EVENT_FLAG_BUBBLE, aEventStatus);
|
1998-09-06 00:16:36 +00:00
|
|
|
}
|
|
|
|
|
2000-05-16 11:35:12 +00:00
|
|
|
if (NS_EVENT_FLAG_INIT & aFlags) {
|
1998-09-06 00:16:36 +00:00
|
|
|
// We're leaving the DOM event loop so if we created a DOM event,
|
|
|
|
// release here.
|
2001-12-16 06:59:31 +00:00
|
|
|
|
|
|
|
if (!externalDOMEvent && *aDOMEvent) {
|
1998-09-06 00:16:36 +00:00
|
|
|
if (0 != (*aDOMEvent)->Release()) {
|
|
|
|
// 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.
|
2001-12-16 06:59:31 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIPrivateDOMEvent> privateEvent =
|
|
|
|
do_QueryInterface(*aDOMEvent);
|
|
|
|
|
|
|
|
if (privateEvent) {
|
1998-09-06 00:16:36 +00:00
|
|
|
privateEvent->DuplicatePrivateData();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-12-16 06:59:31 +00:00
|
|
|
|
1998-09-06 00:16:36 +00:00
|
|
|
aDOMEvent = nsnull;
|
|
|
|
}
|
2001-12-16 06:59:31 +00:00
|
|
|
|
1998-09-06 00:16:36 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGenericDOMDataNode::GetContentID(PRUint32* aID)
|
|
|
|
{
|
|
|
|
*aID = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGenericDOMDataNode::SetContentID(PRUint32 aID)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGenericDOMDataNode::GetNodeInfo(nsINodeInfo*& aResult) const
|
|
|
|
{
|
|
|
|
aResult = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGenericDOMDataNode::CanContainChildren(PRBool& aResult) const
|
|
|
|
{
|
|
|
|
aResult = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGenericDOMDataNode::ChildCount(PRInt32& aResult) const
|
|
|
|
{
|
|
|
|
aResult = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGenericDOMDataNode::ChildAt(PRInt32 aIndex, nsIContent*& aResult) const
|
|
|
|
{
|
|
|
|
aResult = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGenericDOMDataNode::IndexOf(nsIContent* aPossibleChild,
|
|
|
|
PRInt32& aResult) const
|
|
|
|
{
|
|
|
|
aResult = -1;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGenericDOMDataNode::InsertChildAt(nsIContent* aKid, PRInt32 aIndex,
|
|
|
|
PRBool aNotify, PRBool aDeepSetDocument)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGenericDOMDataNode::ReplaceChildAt(nsIContent* aKid, PRInt32 aIndex,
|
|
|
|
PRBool aNotify, PRBool aDeepSetDocument)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGenericDOMDataNode::AppendChildTo(nsIContent* aKid, PRBool aNotify,
|
|
|
|
PRBool aDeepSetDocument)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGenericDOMDataNode::RemoveChildAt(PRInt32 aIndex, PRBool aNotify)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-12-17 07:22:28 +00:00
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
NS_IMETHODIMP
|
2001-12-11 09:03:38 +00:00
|
|
|
nsGenericDOMDataNode::RangeAdd(nsIDOMRange* aRange)
|
1998-12-17 07:22:28 +00:00
|
|
|
{
|
1999-01-04 16:48:33 +00:00
|
|
|
// lazy allocation of range list
|
2001-12-16 06:59:31 +00:00
|
|
|
|
|
|
|
if (!gRangeListsHash) {
|
|
|
|
gRangeListsHash = PL_NewDHashTable(PL_DHashGetStubOps(), nsnull,
|
|
|
|
sizeof(RangeListMapEntry), 16);
|
|
|
|
|
|
|
|
if (!gRangeListsHash) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1998-12-17 07:22:28 +00:00
|
|
|
}
|
1999-08-06 10:33:09 +00:00
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
nsVoidArray *range_list = LookupRangeList();
|
|
|
|
|
|
|
|
if (!range_list) {
|
|
|
|
range_list = new nsAutoVoidArray();
|
|
|
|
NS_ENSURE_TRUE(range_list, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
// Add a mapping to the hash table
|
|
|
|
RangeListMapEntry *entry =
|
|
|
|
NS_STATIC_CAST(RangeListMapEntry *,
|
|
|
|
PL_DHashTableOperate(gRangeListsHash, this,
|
|
|
|
PL_DHASH_ADD));
|
|
|
|
|
|
|
|
entry->mKey = this;
|
|
|
|
entry->mRangeList = range_list;
|
|
|
|
|
|
|
|
SetHasRangeList(PR_TRUE);
|
|
|
|
} else {
|
|
|
|
// Make sure we don't add a range that is already
|
|
|
|
// in the list!
|
|
|
|
PRInt32 i = range_list->IndexOf(aRange);
|
|
|
|
|
|
|
|
if (i >= 0) {
|
|
|
|
// Range is already in the list, so there is nothing to do!
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-08-06 10:33:09 +00:00
|
|
|
}
|
2001-12-16 06:59:31 +00:00
|
|
|
|
1998-12-17 07:22:28 +00:00
|
|
|
// dont need to addref - this call is made by the range object itself
|
2001-12-16 06:59:31 +00:00
|
|
|
PRBool rv = range_list->AppendElement(aRange);
|
|
|
|
|
|
|
|
return rv ? NS_OK : NS_ERROR_FAILURE;
|
1998-12-17 07:22:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
NS_IMETHODIMP
|
2001-12-11 09:03:38 +00:00
|
|
|
nsGenericDOMDataNode::RangeRemove(nsIDOMRange* aRange)
|
1998-12-17 07:22:28 +00:00
|
|
|
{
|
2001-12-16 06:59:31 +00:00
|
|
|
RangeListMapEntry *entry = nsnull;
|
|
|
|
|
|
|
|
if (HasRangeList()) {
|
|
|
|
entry = NS_STATIC_CAST(RangeListMapEntry*,
|
|
|
|
PL_DHashTableOperate(gRangeListsHash, this,
|
|
|
|
PL_DHASH_LOOKUP));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (entry && PL_DHASH_ENTRY_IS_BUSY(entry)) {
|
|
|
|
// dont need to release - this call is made by the range object
|
|
|
|
// itself
|
|
|
|
PRBool rv = entry->mRangeList->RemoveElement(aRange);
|
|
|
|
|
1998-12-18 02:51:34 +00:00
|
|
|
if (rv) {
|
2001-12-16 06:59:31 +00:00
|
|
|
if (entry->mRangeList->Count() == 0) {
|
|
|
|
delete entry->mRangeList;
|
|
|
|
|
|
|
|
PL_DHashTableRawRemove(gRangeListsHash, entry);
|
|
|
|
|
|
|
|
SetHasRangeList(PR_FALSE);
|
1998-12-18 02:51:34 +00:00
|
|
|
}
|
2001-12-16 06:59:31 +00:00
|
|
|
|
1998-12-18 02:51:34 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-12-17 07:22:28 +00:00
|
|
|
}
|
2001-12-16 06:59:31 +00:00
|
|
|
|
1998-12-17 07:22:28 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
1998-12-18 02:51:34 +00:00
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
NS_IMETHODIMP
|
1998-12-18 02:51:34 +00:00
|
|
|
nsGenericDOMDataNode::GetRangeList(nsVoidArray*& aResult) const
|
|
|
|
{
|
2001-12-16 06:59:31 +00:00
|
|
|
aResult = LookupRangeList();
|
1998-12-18 02:51:34 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-03-31 20:49:25 +00:00
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
NS_IMETHODIMP
|
2000-04-04 23:55:31 +00:00
|
|
|
nsGenericDOMDataNode::SetFocus(nsIPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
NS_IMETHODIMP
|
2000-04-04 23:55:31 +00:00
|
|
|
nsGenericDOMDataNode::RemoveFocus(nsIPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGenericDOMDataNode::GetBindingParent(nsIContent** aContent)
|
2000-08-12 06:28:02 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
NS_IMETHODIMP
|
2000-08-12 06:28:02 +00:00
|
|
|
nsGenericDOMDataNode::SetBindingParent(nsIContent* aParent)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
2001-12-16 06:59:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(PRBool)
|
|
|
|
nsGenericDOMDataNode::IsContentOfType(PRUint32 aFlags)
|
|
|
|
{
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2000-08-12 06:28:02 +00:00
|
|
|
|
2001-10-16 05:31:36 +00:00
|
|
|
#ifdef DEBUG
|
2001-12-16 06:59:31 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGenericDOMDataNode::List(FILE* out, PRInt32 aIndent) const
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGenericDOMDataNode::DumpContent(FILE* out, PRInt32 aIndent,
|
|
|
|
PRBool aDumpAll) const
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGenericDOMDataNode::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const
|
1999-10-05 23:47:46 +00:00
|
|
|
{
|
|
|
|
if (!aResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2001-12-16 06:59:31 +00:00
|
|
|
PRUint32 sum = sizeof(*this);
|
|
|
|
sum += mText.GetLength() * (mText.Is2b() ? sizeof(PRUnichar) : sizeof(char));
|
1999-10-05 23:47:46 +00:00
|
|
|
*aResult = sum;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-10-16 05:31:36 +00:00
|
|
|
#endif
|
1999-03-31 20:49:25 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Implementation of the nsIDOMText interface
|
|
|
|
|
|
|
|
nsresult
|
2001-12-16 06:59:31 +00:00
|
|
|
nsGenericDOMDataNode::SplitText(PRUint32 aOffset, nsIDOMText** aReturn)
|
1999-03-31 20:49:25 +00:00
|
|
|
{
|
1999-12-22 01:51:58 +00:00
|
|
|
nsresult rv = NS_OK;
|
1999-03-31 20:49:25 +00:00
|
|
|
nsAutoString cutText;
|
|
|
|
PRUint32 length;
|
|
|
|
|
|
|
|
GetLength(&length);
|
1999-12-22 01:51:58 +00:00
|
|
|
if (aOffset > length) {
|
|
|
|
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
1999-03-31 20:49:25 +00:00
|
|
|
}
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
rv = SubstringData(aOffset, length - aOffset, cutText);
|
1999-12-22 01:51:58 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-12-16 07:04:44 +00:00
|
|
|
rv = DeleteData(aOffset, length - aOffset);
|
1999-12-22 01:51:58 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Use CloneContent() for creating the new node so that the new node is of
|
|
|
|
* same class as this node!
|
|
|
|
*/
|
|
|
|
|
|
|
|
nsCOMPtr<nsITextContent> newContent;
|
2001-12-16 06:59:31 +00:00
|
|
|
rv = CloneContent(PR_FALSE, getter_AddRefs(newContent));
|
1999-12-22 01:51:58 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> newNode = do_QueryInterface(newContent, &rv);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = newNode->SetNodeValue(cutText);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> parentNode;
|
|
|
|
GetParent(*getter_AddRefs(parentNode));
|
|
|
|
|
|
|
|
if (parentNode) {
|
|
|
|
PRInt32 index;
|
2001-12-16 06:59:31 +00:00
|
|
|
|
|
|
|
rv = parentNode->IndexOf(this, index);
|
1999-12-22 01:51:58 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(newNode));
|
2001-12-16 06:59:31 +00:00
|
|
|
|
2001-04-02 00:45:52 +00:00
|
|
|
rv = parentNode->InsertChildAt(content, index+1, PR_TRUE, PR_FALSE);
|
1999-12-22 01:51:58 +00:00
|
|
|
}
|
|
|
|
}
|
2001-12-16 06:59:31 +00:00
|
|
|
|
2000-09-09 05:46:14 +00:00
|
|
|
return newNode->QueryInterface(NS_GET_IID(nsIDOMText), (void**)aReturn);
|
1999-03-31 20:49:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Implementation of the nsITextContent interface
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
NS_IMETHODIMP
|
1999-10-15 23:36:07 +00:00
|
|
|
nsGenericDOMDataNode::GetText(const nsTextFragment** aFragmentsResult)
|
1999-03-31 20:49:25 +00:00
|
|
|
{
|
1999-10-15 23:36:07 +00:00
|
|
|
*aFragmentsResult = &mText;
|
1999-03-31 20:49:25 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
NS_IMETHODIMP
|
1999-08-27 21:40:47 +00:00
|
|
|
nsGenericDOMDataNode::GetTextLength(PRInt32* aLengthResult)
|
|
|
|
{
|
|
|
|
if (!aLengthResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2001-12-16 06:59:31 +00:00
|
|
|
|
1999-08-27 21:40:47 +00:00
|
|
|
*aLengthResult = mText.GetLength();
|
2001-12-16 06:59:31 +00:00
|
|
|
|
1999-08-27 21:40:47 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
nsGenericDOMDataNode::CopyText(nsAWritableString& aResult)
|
1999-08-27 21:40:47 +00:00
|
|
|
{
|
|
|
|
if (mText.Is2b()) {
|
2000-03-12 09:14:14 +00:00
|
|
|
aResult.Assign(mText.Get2b(), mText.GetLength());
|
2001-12-16 06:59:31 +00:00
|
|
|
} else {
|
|
|
|
// Must use Substring() since nsDependentCString() requires null
|
|
|
|
// terminated strings.
|
|
|
|
|
|
|
|
const char *data = mText.Get1b();
|
|
|
|
CopyASCIItoUCS2(Substring(data, data + mText.GetLength()), aResult);
|
1999-08-27 21:40:47 +00:00
|
|
|
}
|
2001-12-16 06:59:31 +00:00
|
|
|
|
1999-08-27 21:40:47 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGenericDOMDataNode::SetText(const PRUnichar* aBuffer,
|
2000-03-22 01:23:42 +00:00
|
|
|
PRInt32 aLength,
|
1999-03-31 20:49:25 +00:00
|
|
|
PRBool aNotify)
|
|
|
|
{
|
2001-12-16 06:59:31 +00:00
|
|
|
NS_PRECONDITION((aLength >= 0) && aBuffer, "bad args");
|
1999-03-31 20:49:25 +00:00
|
|
|
if (aLength < 0) {
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
2001-12-16 06:59:31 +00:00
|
|
|
if (!aBuffer) {
|
1999-03-31 20:49:25 +00:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2001-12-16 06:59:31 +00:00
|
|
|
|
|
|
|
if (aNotify && mDocument) {
|
2000-01-28 23:43:12 +00:00
|
|
|
mDocument->BeginUpdate();
|
|
|
|
}
|
2001-12-16 06:59:31 +00:00
|
|
|
|
2001-12-12 04:28:25 +00:00
|
|
|
mText.SetTo(aBuffer, aLength);
|
2001-12-16 06:59:31 +00:00
|
|
|
|
2001-04-12 23:35:24 +00:00
|
|
|
#ifdef IBMBIDI
|
2001-12-12 04:28:25 +00:00
|
|
|
SetBidiStatus();
|
2001-04-12 23:35:24 +00:00
|
|
|
#endif // IBMBIDI
|
1999-03-31 20:49:25 +00:00
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
if (mDocument && nsGenericElement::HasMutationListeners(this, NS_EVENT_BITS_MUTATION_CHARACTERDATAMODIFIED)) {
|
|
|
|
nsCOMPtr<nsIDOMEventTarget> node(do_QueryInterface(this));
|
2000-11-27 07:55:20 +00:00
|
|
|
nsMutationEvent mutation;
|
|
|
|
mutation.eventStructType = NS_MUTATION_EVENT;
|
|
|
|
mutation.message = NS_MUTATION_CHARACTERDATAMODIFIED;
|
|
|
|
mutation.mTarget = node;
|
|
|
|
|
|
|
|
// XXX Handle the setting of prevValue!
|
|
|
|
nsAutoString newVal(aBuffer);
|
|
|
|
if (!newVal.IsEmpty())
|
|
|
|
mutation.mNewAttrValue = getter_AddRefs(NS_NewAtom(newVal));
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2001-04-04 04:30:03 +00:00
|
|
|
HandleDOMEvent(nsnull, &mutation, nsnull,
|
2000-12-23 10:56:31 +00:00
|
|
|
NS_EVENT_FLAG_INIT, &status);
|
2000-11-27 07:55:20 +00:00
|
|
|
}
|
|
|
|
|
1999-03-31 20:49:25 +00:00
|
|
|
// Trigger a reflow
|
2001-12-16 06:59:31 +00:00
|
|
|
if (aNotify && mDocument) {
|
|
|
|
mDocument->ContentChanged(this, nsnull);
|
2000-01-28 23:43:12 +00:00
|
|
|
mDocument->EndUpdate();
|
1999-03-31 20:49:25 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGenericDOMDataNode::SetText(const char* aBuffer, PRInt32 aLength,
|
|
|
|
PRBool aNotify)
|
1999-03-31 20:49:25 +00:00
|
|
|
{
|
2001-12-16 06:59:31 +00:00
|
|
|
NS_PRECONDITION((aLength >= 0) && aBuffer, "bad args");
|
1999-03-31 20:49:25 +00:00
|
|
|
if (aLength < 0) {
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
2001-12-16 06:59:31 +00:00
|
|
|
if (!aBuffer) {
|
1999-03-31 20:49:25 +00:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2001-12-16 06:59:31 +00:00
|
|
|
|
|
|
|
if (aNotify && mDocument) {
|
2000-01-28 23:43:12 +00:00
|
|
|
mDocument->BeginUpdate();
|
|
|
|
}
|
2001-12-16 06:59:31 +00:00
|
|
|
|
1999-03-31 20:49:25 +00:00
|
|
|
mText.SetTo(aBuffer, aLength);
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
if (mDocument && nsGenericElement::HasMutationListeners(this, NS_EVENT_BITS_MUTATION_CHARACTERDATAMODIFIED)) {
|
|
|
|
nsCOMPtr<nsIDOMEventTarget> node(do_QueryInterface(this));
|
2000-11-27 07:55:20 +00:00
|
|
|
nsMutationEvent mutation;
|
|
|
|
mutation.eventStructType = NS_MUTATION_EVENT;
|
|
|
|
mutation.message = NS_MUTATION_CHARACTERDATAMODIFIED;
|
|
|
|
mutation.mTarget = node;
|
|
|
|
|
|
|
|
// XXX Handle the setting of prevValue!
|
|
|
|
nsAutoString newVal; newVal.AssignWithConversion(aBuffer);
|
|
|
|
if (!newVal.IsEmpty())
|
|
|
|
mutation.mNewAttrValue = getter_AddRefs(NS_NewAtom(newVal));
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2001-04-04 04:30:03 +00:00
|
|
|
HandleDOMEvent(nsnull, &mutation, nsnull,
|
2000-12-23 10:56:31 +00:00
|
|
|
NS_EVENT_FLAG_INIT, &status);
|
2000-11-27 07:55:20 +00:00
|
|
|
}
|
|
|
|
|
1999-03-31 20:49:25 +00:00
|
|
|
// Trigger a reflow
|
2001-12-16 06:59:31 +00:00
|
|
|
if (aNotify && mDocument) {
|
|
|
|
mDocument->ContentChanged(this, nsnull);
|
2000-01-28 23:43:12 +00:00
|
|
|
mDocument->EndUpdate();
|
1999-03-31 20:49:25 +00:00
|
|
|
}
|
2001-12-16 06:59:31 +00:00
|
|
|
|
1999-03-31 20:49:25 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGenericDOMDataNode::SetText(const nsAReadableString& aStr,
|
2000-08-23 17:27:06 +00:00
|
|
|
PRBool aNotify)
|
|
|
|
{
|
2001-12-16 06:59:31 +00:00
|
|
|
if (aNotify && mDocument) {
|
2000-08-23 17:27:06 +00:00
|
|
|
mDocument->BeginUpdate();
|
|
|
|
}
|
2001-12-16 06:59:31 +00:00
|
|
|
|
2000-08-23 17:27:06 +00:00
|
|
|
mText = aStr;
|
2001-12-16 06:59:31 +00:00
|
|
|
|
2001-12-12 04:28:25 +00:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
SetBidiStatus();
|
|
|
|
#endif // IBMBIDI
|
2000-08-23 17:27:06 +00:00
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
if (mDocument && nsGenericElement::HasMutationListeners(this, NS_EVENT_BITS_MUTATION_CHARACTERDATAMODIFIED)) {
|
|
|
|
nsCOMPtr<nsIDOMEventTarget> node(do_QueryInterface(this));
|
2001-04-04 04:30:03 +00:00
|
|
|
nsMutationEvent mutation;
|
|
|
|
mutation.eventStructType = NS_MUTATION_EVENT;
|
|
|
|
mutation.message = NS_MUTATION_CHARACTERDATAMODIFIED;
|
|
|
|
mutation.mTarget = node;
|
|
|
|
|
|
|
|
// XXX Handle the setting of prevValue!
|
|
|
|
nsAutoString newVal(aStr);
|
|
|
|
if (!newVal.IsEmpty())
|
|
|
|
mutation.mNewAttrValue = getter_AddRefs(NS_NewAtom(newVal));
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
HandleDOMEvent(nsnull, &mutation, nsnull,
|
|
|
|
NS_EVENT_FLAG_INIT, &status);
|
|
|
|
}
|
|
|
|
|
2000-08-23 17:27:06 +00:00
|
|
|
// Trigger a reflow
|
2001-12-16 06:59:31 +00:00
|
|
|
if (aNotify && mDocument) {
|
|
|
|
mDocument->ContentChanged(this, nsnull);
|
2000-08-23 17:27:06 +00:00
|
|
|
mDocument->EndUpdate();
|
|
|
|
}
|
2001-12-16 06:59:31 +00:00
|
|
|
|
2000-08-23 17:27:06 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-03-31 20:49:25 +00:00
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
NS_IMETHODIMP
|
1999-03-31 20:49:25 +00:00
|
|
|
nsGenericDOMDataNode::IsOnlyWhitespace(PRBool* aResult)
|
|
|
|
{
|
|
|
|
nsTextFragment& frag = mText;
|
|
|
|
if (frag.Is2b()) {
|
|
|
|
const PRUnichar* cp = frag.Get2b();
|
|
|
|
const PRUnichar* end = cp + frag.GetLength();
|
2001-12-16 06:59:31 +00:00
|
|
|
|
1999-03-31 20:49:25 +00:00
|
|
|
while (cp < end) {
|
|
|
|
PRUnichar ch = *cp++;
|
2001-12-16 06:59:31 +00:00
|
|
|
|
1999-03-31 20:49:25 +00:00
|
|
|
if (!XP_IS_SPACE(ch)) {
|
|
|
|
*aResult = PR_FALSE;
|
2001-12-16 06:59:31 +00:00
|
|
|
|
1999-03-31 20:49:25 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
2001-12-16 06:59:31 +00:00
|
|
|
} else {
|
1999-03-31 20:49:25 +00:00
|
|
|
const char* cp = frag.Get1b();
|
|
|
|
const char* end = cp + frag.GetLength();
|
2001-12-16 06:59:31 +00:00
|
|
|
|
1999-03-31 20:49:25 +00:00
|
|
|
while (cp < end) {
|
|
|
|
PRUnichar ch = PRUnichar(*(unsigned char*)cp);
|
2001-12-16 06:59:31 +00:00
|
|
|
++cp;
|
|
|
|
|
1999-03-31 20:49:25 +00:00
|
|
|
if (!XP_IS_SPACE(ch)) {
|
|
|
|
*aResult = PR_FALSE;
|
2001-12-16 06:59:31 +00:00
|
|
|
|
1999-03-31 20:49:25 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*aResult = PR_TRUE;
|
2001-12-16 06:59:31 +00:00
|
|
|
|
1999-03-31 20:49:25 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-12-12 04:28:25 +00:00
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGenericDOMDataNode::CloneContent(PRBool aCloneText, nsITextContent** aClone)
|
|
|
|
{
|
|
|
|
NS_ERROR("Override me!");
|
|
|
|
|
|
|
|
*aClone = nsnull;
|
|
|
|
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGenericDOMDataNode::LookupListenerManager(nsIEventListenerManager **aListenerManager) const
|
|
|
|
{
|
|
|
|
*aListenerManager = nsnull;
|
|
|
|
|
|
|
|
if (!HasEventListenerManager()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
EventListenerManagerMapEntry *entry =
|
|
|
|
NS_STATIC_CAST(EventListenerManagerMapEntry*,
|
|
|
|
PL_DHashTableOperate(gEventListenerHash, this,
|
|
|
|
PL_DHASH_LOOKUP));
|
|
|
|
|
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
|
|
|
|
*aListenerManager = entry->mListenerManager;
|
|
|
|
NS_ADDREF(*aListenerManager);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsVoidArray *
|
|
|
|
nsGenericDOMDataNode::LookupRangeList() const
|
|
|
|
{
|
|
|
|
if (!HasRangeList()) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
RangeListMapEntry *entry =
|
|
|
|
NS_STATIC_CAST(RangeListMapEntry*,
|
|
|
|
PL_DHashTableOperate(gRangeListsHash, this,
|
|
|
|
PL_DHASH_LOOKUP));
|
|
|
|
|
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
|
|
|
|
return entry->mRangeList;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2001-12-12 04:28:25 +00:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
void nsGenericDOMDataNode::SetBidiStatus()
|
|
|
|
{
|
|
|
|
if (mDocument) {
|
2001-12-16 06:59:31 +00:00
|
|
|
PRBool isBidiDocument = PR_FALSE;
|
|
|
|
|
2001-12-12 04:28:25 +00:00
|
|
|
mDocument->GetBidiEnabled(&isBidiDocument);
|
2001-12-16 06:59:31 +00:00
|
|
|
|
2001-12-12 04:28:25 +00:00
|
|
|
if (isBidiDocument) {
|
|
|
|
// OK, we already know it's Bidi, so we won't test again
|
2001-12-16 06:59:31 +00:00
|
|
|
|
2001-12-12 04:28:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2001-12-16 06:59:31 +00:00
|
|
|
|
2001-12-12 04:28:25 +00:00
|
|
|
mText.SetBidiFlag();
|
2001-12-16 06:59:31 +00:00
|
|
|
|
2001-12-12 04:28:25 +00:00
|
|
|
if (mDocument && mText.IsBidi()) {
|
|
|
|
mDocument->SetBidiEnabled(PR_TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // IBMBIDI
|