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"
|
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"
|
2003-06-16 11:17:18 +00:00
|
|
|
#include "nsIDOM3Node.h"
|
2003-07-03 02:45:34 +00:00
|
|
|
#include "nsIURI.h"
|
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"
|
|
|
|
|
1998-09-06 04:16:22 +00:00
|
|
|
nsGenericDOMDataNode::nsGenericDOMDataNode()
|
2003-11-07 09:47:23 +00:00
|
|
|
: mText()
|
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
|
|
|
{
|
2002-08-13 00:50:50 +00:00
|
|
|
if (HasEventListenerManager()) {
|
|
|
|
PL_DHashTableOperate(&nsGenericElement::sEventListenerManagersHash,
|
|
|
|
this, PL_DHASH_REMOVE);
|
2001-12-16 06:59:31 +00:00
|
|
|
}
|
|
|
|
|
2002-08-13 00:50:50 +00:00
|
|
|
if (HasRangeList()) {
|
|
|
|
PL_DHashTableOperate(&nsGenericElement::sRangeListsHash,
|
|
|
|
this, PL_DHASH_REMOVE);
|
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)
|
2004-01-06 00:36:01 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOMEventReceiver,
|
|
|
|
nsDOMEventRTTearoff::Create(this))
|
|
|
|
NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOMEventTarget,
|
|
|
|
nsDOMEventRTTearoff::Create(this))
|
|
|
|
NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOM3EventTarget,
|
|
|
|
nsDOMEventRTTearoff::Create(this))
|
2001-12-16 06:59:31 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIContent)
|
|
|
|
// No nsITextContent since all subclasses might not want that.
|
2004-01-06 00:36:01 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOM3Node, new nsNode3Tearoff(this))
|
2001-12-16 06:59:31 +00:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
|
1998-09-06 00:16:36 +00:00
|
|
|
nsresult
|
2002-03-23 23:54:46 +00:00
|
|
|
nsGenericDOMDataNode::GetNodeValue(nsAString& 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
|
2002-03-23 23:54:46 +00:00
|
|
|
nsGenericDOMDataNode::SetNodeValue(const nsAString& 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;
|
|
|
|
|
2003-11-07 09:47:23 +00:00
|
|
|
nsIContent *parent_weak = GetParent();
|
2001-12-16 06:59:31 +00:00
|
|
|
|
|
|
|
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
|
|
|
nsresult rv = NS_OK;
|
1999-03-31 20:49:25 +00:00
|
|
|
|
2003-11-07 09:47:23 +00:00
|
|
|
nsIContent *parent_weak = GetParent();
|
2003-09-27 04:18:26 +00:00
|
|
|
nsIContent *sibling = nsnull;
|
2001-12-16 06:59:31 +00:00
|
|
|
|
|
|
|
if (parent_weak) {
|
2003-09-27 04:18:26 +00:00
|
|
|
PRInt32 pos = parent_weak->IndexOf(this);
|
|
|
|
if (pos > 0) {
|
|
|
|
sibling = parent_weak->GetChildAt(pos - 1);
|
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.
|
2003-09-27 04:18:26 +00:00
|
|
|
PRInt32 pos = mDocument->IndexOf(this);
|
|
|
|
if (pos > 0) {
|
|
|
|
sibling = mDocument->GetChildAt(pos - 1);
|
2001-12-16 06:59:31 +00:00
|
|
|
}
|
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
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2003-11-07 09:47:23 +00:00
|
|
|
nsIContent *parent_weak = GetParent();
|
2003-09-27 04:18:26 +00:00
|
|
|
nsIContent *sibling = nsnull;
|
1999-03-31 20:49:25 +00:00
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
if (parent_weak) {
|
2003-09-27 04:18:26 +00:00
|
|
|
PRInt32 pos = parent_weak->IndexOf(this);
|
1998-09-06 00:16:36 +00:00
|
|
|
if (pos > -1 ) {
|
2003-09-27 04:18:26 +00:00
|
|
|
sibling = parent_weak->GetChildAt(pos + 1);
|
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.
|
2003-09-27 04:18:26 +00:00
|
|
|
PRInt32 pos = mDocument->IndexOf(this);
|
1999-03-31 20:49:25 +00:00
|
|
|
if (pos > -1 ) {
|
2003-09-27 04:18:26 +00:00
|
|
|
sibling = mDocument->GetChildAt(pos + 1);
|
2001-12-16 06:59:31 +00:00
|
|
|
}
|
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
|
2002-03-23 23:54:46 +00:00
|
|
|
nsGenericDOMDataNode::GetNamespaceURI(nsAString& 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
|
2002-03-23 23:54:46 +00:00
|
|
|
nsGenericDOMDataNode::GetPrefix(nsAString& 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
|
2002-03-23 23:54:46 +00:00
|
|
|
nsGenericDOMDataNode::SetPrefix(const nsAString& 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
|
2002-03-23 23:54:46 +00:00
|
|
|
nsGenericDOMDataNode::GetLocalName(nsAString& aLocalName)
|
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(aLocalName);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-04-01 13:31:23 +00:00
|
|
|
nsresult
|
|
|
|
nsGenericDOMDataNode::Normalize()
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2002-03-23 23:54:46 +00:00
|
|
|
nsGenericDOMDataNode::IsSupported(const nsAString& aFeature,
|
|
|
|
const nsAString& aVersion,
|
2000-09-14 05:19:00 +00:00
|
|
|
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
|
2002-03-23 23:54:46 +00:00
|
|
|
nsGenericDOMDataNode::GetBaseURI(nsAString& aURI)
|
2001-03-30 02:15:21 +00:00
|
|
|
{
|
2004-01-09 23:54:21 +00:00
|
|
|
nsCOMPtr<nsIURI> baseURI = GetBaseURI();
|
2003-07-03 02:45:34 +00:00
|
|
|
nsCAutoString spec;
|
2004-01-09 23:54:21 +00:00
|
|
|
|
|
|
|
if (baseURI) {
|
2003-07-03 02:45:34 +00:00
|
|
|
baseURI->GetSpec(spec);
|
2001-12-16 06:59:31 +00:00
|
|
|
}
|
2004-01-09 23:54:21 +00:00
|
|
|
|
2003-07-03 02:45:34 +00:00
|
|
|
CopyUTF8toUTF16(spec, aURI);
|
2001-03-30 02:15:21 +00:00
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
return NS_OK;
|
2001-03-30 02:15:21 +00:00
|
|
|
}
|
|
|
|
|
2001-09-11 03:04:49 +00:00
|
|
|
nsresult
|
2003-06-24 21:39:39 +00:00
|
|
|
nsGenericDOMDataNode::LookupPrefix(const nsAString& aNamespaceURI,
|
|
|
|
nsAString& aPrefix)
|
2001-09-11 03:04:49 +00:00
|
|
|
{
|
|
|
|
aPrefix.Truncate();
|
2001-12-16 06:59:31 +00:00
|
|
|
|
2003-11-07 09:47:23 +00:00
|
|
|
nsIContent *parent_weak = GetParent();
|
2001-12-16 06:59:31 +00:00
|
|
|
|
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) {
|
2003-06-24 21:39:39 +00:00
|
|
|
return node->LookupPrefix(aNamespaceURI, aPrefix);
|
2001-09-11 03:04:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2002-03-23 23:54:46 +00:00
|
|
|
nsGenericDOMDataNode::LookupNamespaceURI(const nsAString& aNamespacePrefix,
|
|
|
|
nsAString& aNamespaceURI)
|
2001-09-11 03:04:49 +00:00
|
|
|
{
|
|
|
|
aNamespaceURI.Truncate();
|
2001-12-16 06:59:31 +00:00
|
|
|
|
2003-11-07 09:47:23 +00:00
|
|
|
nsIContent *parent_weak = GetParent();
|
2001-12-16 06:59:31 +00:00
|
|
|
|
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
|
2002-03-23 23:54:46 +00:00
|
|
|
nsGenericDOMDataNode::GetData(nsAString& 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();
|
2002-05-10 18:21:50 +00:00
|
|
|
|
|
|
|
if (data) {
|
|
|
|
CopyASCIItoUCS2(Substring(data, data + mText.GetLength()), aData);
|
|
|
|
} else {
|
|
|
|
aData.Truncate();
|
|
|
|
}
|
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
|
2002-03-23 23:54:46 +00:00
|
|
|
nsGenericDOMDataNode::SetData(const nsAString& 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,
|
2002-03-23 23:54:46 +00:00
|
|
|
nsAString& 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
|
2002-03-23 23:54:46 +00:00
|
|
|
nsGenericDOMDataNode::AppendData(const nsAString& 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;
|
2002-04-10 21:44:04 +00:00
|
|
|
PRInt32 length = 0;
|
|
|
|
|
|
|
|
// See bugzilla bug 77585.
|
|
|
|
if (mText.Is2b() || (!IsASCII(aData))) {
|
|
|
|
nsAutoString old_data;
|
|
|
|
mText.AppendTo(old_data);
|
|
|
|
length = old_data.Length();
|
2002-04-16 06:27:16 +00:00
|
|
|
// XXXjag We'd like to just say |old_data + aData|, but due
|
|
|
|
// to issues with dependent concatenation and sliding (sub)strings
|
|
|
|
// we'll just have to copy for now. See bug 121841 for details.
|
|
|
|
old_data.Append(aData);
|
|
|
|
rv = SetText(old_data, PR_FALSE);
|
2002-04-10 21:44:04 +00:00
|
|
|
} else {
|
2002-04-22 23:48:14 +00:00
|
|
|
// We know aData and the current data is ASCII, so use a
|
|
|
|
// nsC*String, no need for any fancy unicode stuff here.
|
2002-04-10 21:44:04 +00:00
|
|
|
nsCAutoString old_data;
|
|
|
|
mText.AppendTo(old_data);
|
|
|
|
length = old_data.Length();
|
|
|
|
old_data.AppendWithConversion(aData);
|
|
|
|
rv = SetText(old_data.get(), old_data.Length(), PR_FALSE);
|
|
|
|
}
|
1999-11-23 23:13:03 +00:00
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
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) {
|
2004-02-20 21:38:31 +00:00
|
|
|
mDocument->CharacterDataChanged(this, PR_TRUE);
|
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,
|
2002-03-23 23:54:46 +00:00
|
|
|
const nsAString& 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,
|
2002-03-23 23:54:46 +00:00
|
|
|
const nsAString& 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
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
nsresult
|
|
|
|
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
|
|
|
|
2002-08-13 00:50:50 +00:00
|
|
|
if (!nsGenericElement::sEventListenerManagersHash.ops) {
|
|
|
|
nsresult rv = nsGenericElement::InitHashes();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
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 *,
|
2002-08-13 00:50:50 +00:00
|
|
|
PL_DHashTableOperate(&nsGenericElement::
|
|
|
|
sEventListenerManagersHash, this,
|
2001-12-16 06:59:31 +00:00
|
|
|
PL_DHASH_ADD));
|
|
|
|
|
|
|
|
entry->mListenerManager = *aResult;
|
|
|
|
|
|
|
|
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
|
2002-03-23 23:54:46 +00:00
|
|
|
nsGenericDOMDataNode::ToCString(nsAString& 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);
|
2003-11-01 10:57:41 +00:00
|
|
|
AppendASCIItoUTF16(buf, aBuf);
|
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);
|
2003-11-01 10:57:41 +00:00
|
|
|
AppendASCIItoUTF16(buf, aBuf);
|
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
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
void
|
2001-12-16 06:59:31 +00:00
|
|
|
nsGenericDOMDataNode::SetDocument(nsIDocument* aDocument, PRBool aDeep,
|
|
|
|
PRBool aCompileEventHandlers)
|
1998-10-26 23:26:01 +00:00
|
|
|
{
|
2003-11-07 09:47:23 +00:00
|
|
|
nsIContent::SetDocument(aDocument, aDeep, aCompileEventHandlers);
|
1998-10-26 23:26:01 +00:00
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
if (mDocument && mText.IsBidi()) {
|
|
|
|
mDocument->SetBidiEnabled(PR_TRUE);
|
1998-10-26 23:26:01 +00:00
|
|
|
}
|
1998-09-06 00:16:36 +00:00
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
void
|
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);
|
|
|
|
|
2003-11-07 09:47:23 +00:00
|
|
|
new_bits |= mParentPtrBits & nsIContent::kParentBitMask;
|
2001-12-16 06:59:31 +00:00
|
|
|
|
|
|
|
mParentPtrBits = new_bits;
|
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
PRBool
|
2002-08-29 04:05:39 +00:00
|
|
|
nsGenericDOMDataNode::IsNativeAnonymous() const
|
|
|
|
{
|
2003-11-07 09:47:23 +00:00
|
|
|
nsIContent* parent = GetParent();
|
2002-08-29 04:05:39 +00:00
|
|
|
return parent && parent->IsNativeAnonymous();
|
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
void
|
2002-08-29 04:05:39 +00:00
|
|
|
nsGenericDOMDataNode::SetNativeAnonymous(PRBool aAnonymous)
|
|
|
|
{
|
|
|
|
// XXX Need to fix this to do something - bug 165110
|
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
void
|
2003-06-13 20:10:01 +00:00
|
|
|
nsGenericDOMDataNode::GetNameSpaceID(PRInt32* aID) const
|
2001-12-16 06:59:31 +00:00
|
|
|
{
|
2003-06-13 20:10:01 +00:00
|
|
|
*aID = kNameSpaceID_None;
|
1998-09-06 00:16:36 +00:00
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
nsIAtom *
|
2003-10-21 16:16:42 +00:00
|
|
|
nsGenericDOMDataNode::GetIDAttributeName() const
|
|
|
|
{
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
nsIAtom *
|
2003-10-21 16:16:42 +00:00
|
|
|
nsGenericDOMDataNode::GetClassAttributeName() const
|
|
|
|
{
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
already_AddRefed<nsINodeInfo>
|
|
|
|
nsGenericDOMDataNode::GetExistingAttrNameFromQName(const nsAString& aStr) const
|
2001-12-16 06:59:31 +00:00
|
|
|
{
|
2003-10-30 13:47:29 +00:00
|
|
|
return nsnull;
|
2001-12-16 06:59:31 +00:00
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
nsresult
|
2001-12-16 06:59:31 +00:00
|
|
|
nsGenericDOMDataNode::SetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttr,
|
2004-01-15 17:07:27 +00:00
|
|
|
nsIAtom* aPrefix, const nsAString& aValue,
|
|
|
|
PRBool aNotify)
|
2001-12-16 06:59:31 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
nsresult
|
2001-12-16 06:59:31 +00:00
|
|
|
nsGenericDOMDataNode::UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttr,
|
|
|
|
PRBool aNotify)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
nsresult
|
2001-12-16 06:59:31 +00:00
|
|
|
nsGenericDOMDataNode::GetAttr(PRInt32 aNameSpaceID, nsIAtom *aAttr,
|
2002-03-23 23:54:46 +00:00
|
|
|
nsAString& aResult) const
|
2001-12-16 06:59:31 +00:00
|
|
|
{
|
|
|
|
aResult.Truncate();
|
|
|
|
|
|
|
|
return NS_CONTENT_ATTR_NOT_THERE;
|
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
PRBool
|
2001-12-16 06:59:31 +00:00
|
|
|
nsGenericDOMDataNode::HasAttr(PRInt32 aNameSpaceID, nsIAtom *aAttribute) const
|
|
|
|
{
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
nsresult
|
2003-09-27 04:18:26 +00:00
|
|
|
nsGenericDOMDataNode::GetAttrNameAt(PRUint32 aIndex, PRInt32* aNameSpaceID,
|
2003-06-13 20:10:01 +00:00
|
|
|
nsIAtom** aName, nsIAtom** aPrefix) const
|
2001-12-16 06:59:31 +00:00
|
|
|
{
|
2003-06-13 20:10:01 +00:00
|
|
|
*aNameSpaceID = kNameSpaceID_None;
|
|
|
|
*aName = nsnull;
|
|
|
|
*aPrefix = nsnull;
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
PRUint32
|
2003-09-27 04:18:26 +00:00
|
|
|
nsGenericDOMDataNode::GetAttrCount() const
|
2001-12-16 06:59:31 +00:00
|
|
|
{
|
2003-09-27 04:18:26 +00:00
|
|
|
return 0;
|
2001-12-16 06:59:31 +00:00
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
nsresult
|
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
|
|
|
|
2002-11-09 00:25:25 +00:00
|
|
|
aEvent->flags |= aFlags;
|
2000-05-16 11:35:12 +00:00
|
|
|
aFlags &= ~(NS_EVENT_FLAG_CANT_BUBBLE | NS_EVENT_FLAG_CANT_CANCEL);
|
2002-11-09 00:25:25 +00:00
|
|
|
aFlags |= NS_EVENT_FLAG_BUBBLE | NS_EVENT_FLAG_CAPTURE;
|
2001-03-13 11:37:16 +00:00
|
|
|
}
|
1999-03-28 22:22:54 +00:00
|
|
|
|
2003-11-07 09:47:23 +00:00
|
|
|
nsIContent *parent_weak = GetParent();
|
2001-12-16 06:59:31 +00:00
|
|
|
|
2001-03-13 11:37:16 +00:00
|
|
|
//Capturing stage evaluation
|
2002-11-09 00:25:25 +00:00
|
|
|
if (NS_EVENT_FLAG_CAPTURE & 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,
|
2002-11-09 00:25:25 +00:00
|
|
|
aFlags & NS_EVENT_CAPTURE_MASK, aEventStatus);
|
2001-12-16 06:59:31 +00:00
|
|
|
} else if (mDocument) {
|
|
|
|
ret = mDocument->HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
|
2002-11-09 00:25:25 +00:00
|
|
|
aFlags & NS_EVENT_CAPTURE_MASK, 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
|
2002-11-09 00:25:25 +00:00
|
|
|
//Check for null ELM, check if we're a non-bubbling event in the bubbling state (bubbling state
|
|
|
|
//is indicated by the presence of the NS_EVENT_FLAG_BUBBLE flag and not the NS_EVENT_FLAG_INIT), and check
|
|
|
|
//if we're a no content dispatch event
|
|
|
|
if (listener_manager &&
|
|
|
|
!(NS_EVENT_FLAG_CANT_BUBBLE & aEvent->flags && NS_EVENT_FLAG_BUBBLE & aFlags && !(NS_EVENT_FLAG_INIT & aFlags)) &&
|
|
|
|
!(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
|
2002-11-09 00:25:25 +00:00
|
|
|
if (NS_EVENT_FLAG_BUBBLE & aFlags && parent_weak) {
|
2001-12-16 06:59:31 +00:00
|
|
|
ret = parent_weak->HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
|
2002-11-09 00:25:25 +00:00
|
|
|
aFlags & NS_EVENT_BUBBLE_MASK, 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;
|
|
|
|
}
|
|
|
|
|
2003-11-19 01:20:56 +00:00
|
|
|
PRUint32
|
|
|
|
nsGenericDOMDataNode::ContentID() const
|
2001-12-16 06:59:31 +00:00
|
|
|
{
|
2003-11-19 01:20:56 +00:00
|
|
|
return 0;
|
2001-12-16 06:59:31 +00:00
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
nsINodeInfo *
|
2003-09-27 04:18:26 +00:00
|
|
|
nsGenericDOMDataNode::GetNodeInfo() const
|
2001-12-16 06:59:31 +00:00
|
|
|
{
|
2003-09-27 04:18:26 +00:00
|
|
|
return nsnull;
|
2001-12-16 06:59:31 +00:00
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
PRUint32
|
2003-09-27 04:18:26 +00:00
|
|
|
nsGenericDOMDataNode::GetChildCount() const
|
2001-12-16 06:59:31 +00:00
|
|
|
{
|
2003-09-27 04:18:26 +00:00
|
|
|
return 0;
|
2001-12-16 06:59:31 +00:00
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
nsIContent *
|
2003-09-27 04:18:26 +00:00
|
|
|
nsGenericDOMDataNode::GetChildAt(PRUint32 aIndex) const
|
2001-12-16 06:59:31 +00:00
|
|
|
{
|
2003-09-27 04:18:26 +00:00
|
|
|
return nsnull;
|
2001-12-16 06:59:31 +00:00
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
PRInt32
|
2003-09-27 04:18:26 +00:00
|
|
|
nsGenericDOMDataNode::IndexOf(nsIContent* aPossibleChild) const
|
2001-12-16 06:59:31 +00:00
|
|
|
{
|
2003-09-27 04:18:26 +00:00
|
|
|
return -1;
|
2001-12-16 06:59:31 +00:00
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
nsresult
|
2003-09-27 04:18:26 +00:00
|
|
|
nsGenericDOMDataNode::InsertChildAt(nsIContent* aKid, PRUint32 aIndex,
|
2001-12-16 06:59:31 +00:00
|
|
|
PRBool aNotify, PRBool aDeepSetDocument)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
nsresult
|
2003-09-27 04:18:26 +00:00
|
|
|
nsGenericDOMDataNode::ReplaceChildAt(nsIContent* aKid, PRUint32 aIndex,
|
2001-12-16 06:59:31 +00:00
|
|
|
PRBool aNotify, PRBool aDeepSetDocument)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
nsresult
|
2001-12-16 06:59:31 +00:00
|
|
|
nsGenericDOMDataNode::AppendChildTo(nsIContent* aKid, PRBool aNotify,
|
|
|
|
PRBool aDeepSetDocument)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
nsresult
|
2003-09-27 04:18:26 +00:00
|
|
|
nsGenericDOMDataNode::RemoveChildAt(PRUint32 aIndex, PRBool aNotify)
|
2001-12-16 06:59:31 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-12-17 07:22:28 +00:00
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
nsresult
|
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
|
|
|
|
2002-08-13 00:50:50 +00:00
|
|
|
if (!nsGenericElement::sRangeListsHash.ops) {
|
|
|
|
nsresult rv = nsGenericElement::InitHashes();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
RangeListMapEntry *entry =
|
|
|
|
NS_STATIC_CAST(RangeListMapEntry *,
|
|
|
|
PL_DHashTableOperate(&nsGenericElement::sRangeListsHash,
|
|
|
|
this, PL_DHASH_ADD));
|
2001-12-16 06:59:31 +00:00
|
|
|
|
2002-08-13 00:50:50 +00:00
|
|
|
if (!entry) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1998-12-17 07:22:28 +00:00
|
|
|
}
|
1999-08-06 10:33:09 +00:00
|
|
|
|
2002-08-13 00:50:50 +00:00
|
|
|
nsVoidArray *range_list = entry->mRangeList;
|
2001-12-16 06:59:31 +00:00
|
|
|
|
|
|
|
if (!range_list) {
|
|
|
|
range_list = new nsAutoVoidArray();
|
|
|
|
|
2002-08-13 00:50:50 +00:00
|
|
|
if (!range_list) {
|
|
|
|
PL_DHashTableRawRemove(&nsGenericElement::sRangeListsHash, entry);
|
|
|
|
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2001-12-16 06:59:31 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
void
|
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()) {
|
2002-08-13 00:50:50 +00:00
|
|
|
entry =
|
|
|
|
NS_STATIC_CAST(RangeListMapEntry *,
|
|
|
|
PL_DHashTableOperate(&nsGenericElement::sRangeListsHash,
|
|
|
|
this, PL_DHASH_LOOKUP));
|
2001-12-16 06:59:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2002-08-13 00:50:50 +00:00
|
|
|
PL_DHashTableRawRemove(&nsGenericElement::sRangeListsHash, entry);
|
2001-12-16 06:59:31 +00:00
|
|
|
|
|
|
|
SetHasRangeList(PR_FALSE);
|
1998-12-18 02:51:34 +00:00
|
|
|
}
|
|
|
|
}
|
1998-12-17 07:22:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-19 01:20:56 +00:00
|
|
|
const nsVoidArray *
|
|
|
|
nsGenericDOMDataNode::GetRangeList() const
|
1998-12-18 02:51:34 +00:00
|
|
|
{
|
2003-11-19 01:20:56 +00:00
|
|
|
return LookupRangeList();
|
1998-12-18 02:51:34 +00:00
|
|
|
}
|
1999-03-31 20:49:25 +00:00
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
nsIContent *
|
2003-07-28 21:09:56 +00:00
|
|
|
nsGenericDOMDataNode::GetBindingParent() const
|
2000-08-12 06:28:02 +00:00
|
|
|
{
|
2004-01-05 23:52:57 +00:00
|
|
|
nsIContent* parent = GetParent();
|
|
|
|
return parent ? parent->GetBindingParent() : nsnull;
|
2000-08-12 06:28:02 +00:00
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
nsresult
|
2000-08-12 06:28:02 +00:00
|
|
|
nsGenericDOMDataNode::SetBindingParent(nsIContent* aParent)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
2001-12-16 06:59:31 +00:00
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
PRBool
|
|
|
|
nsGenericDOMDataNode::IsContentOfType(PRUint32 aFlags) const
|
2001-12-16 06:59:31 +00:00
|
|
|
{
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2000-08-12 06:28:02 +00:00
|
|
|
|
2001-10-16 05:31:36 +00:00
|
|
|
#ifdef DEBUG
|
2004-01-09 23:54:21 +00:00
|
|
|
void
|
2001-12-16 06:59:31 +00:00
|
|
|
nsGenericDOMDataNode::List(FILE* out, PRInt32 aIndent) const
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
void
|
2001-12-16 06:59:31 +00:00
|
|
|
nsGenericDOMDataNode::DumpContent(FILE* out, PRInt32 aIndent,
|
|
|
|
PRBool aDumpAll) const
|
|
|
|
{
|
|
|
|
}
|
2001-10-16 05:31:36 +00:00
|
|
|
#endif
|
1999-03-31 20:49:25 +00:00
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
already_AddRefed<nsIURI>
|
|
|
|
nsGenericDOMDataNode::GetBaseURI() const
|
2003-07-03 02:45:34 +00:00
|
|
|
{
|
|
|
|
// DOM Data Node inherits the base from its parent element/document
|
2003-11-07 09:47:23 +00:00
|
|
|
nsIContent* parent_weak = GetParent();
|
2003-07-03 02:45:34 +00:00
|
|
|
if (parent_weak) {
|
2004-01-09 23:54:21 +00:00
|
|
|
return parent_weak->GetBaseURI();
|
2003-07-03 02:45:34 +00:00
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
nsIURI *uri;
|
2003-07-03 02:45:34 +00:00
|
|
|
if (mDocument) {
|
2004-01-09 23:54:21 +00:00
|
|
|
NS_IF_ADDREF(uri = mDocument->GetBaseURI());
|
2003-10-22 06:09:48 +00:00
|
|
|
} else {
|
2004-01-09 23:54:21 +00:00
|
|
|
uri = nsnull;
|
2003-07-03 02:45:34 +00:00
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
return uri;
|
2003-07-03 02:45:34 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2003-11-07 09:47:23 +00:00
|
|
|
nsIContent* parentNode = GetParent();
|
1999-12-22 01:51:58 +00:00
|
|
|
|
|
|
|
if (parentNode) {
|
2003-09-27 04:18:26 +00:00
|
|
|
PRInt32 index = parentNode->IndexOf(this);
|
2001-12-16 06:59:31 +00:00
|
|
|
|
2003-09-27 04:18:26 +00:00
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(newNode));
|
2001-12-16 06:59:31 +00:00
|
|
|
|
2003-09-27 04:18:26 +00:00
|
|
|
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
|
|
|
|
2002-12-11 14:24:49 +00:00
|
|
|
return CallQueryInterface(newNode, 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
|
2002-03-23 23:54:46 +00:00
|
|
|
nsGenericDOMDataNode::CopyText(nsAString& aResult)
|
1999-08-27 21:40:47 +00:00
|
|
|
{
|
2004-02-24 23:10:38 +00:00
|
|
|
return GetData(aResult);
|
1999-08-27 21:40:47 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2003-10-16 18:14:25 +00:00
|
|
|
mozAutoDocUpdate updateBatch(mDocument, UPDATE_CONTENT_MODEL, aNotify);
|
2001-12-16 06:59:31 +00:00
|
|
|
|
2004-02-24 23:10:38 +00:00
|
|
|
PRBool haveMutationListeners =
|
|
|
|
mDocument && nsGenericElement::HasMutationListeners(this, NS_EVENT_BITS_MUTATION_CHARACTERDATAMODIFIED);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> oldValue;
|
|
|
|
if (haveMutationListeners) {
|
|
|
|
oldValue = GetCurrentValueAtom();
|
|
|
|
}
|
|
|
|
|
2001-12-12 04:28:25 +00:00
|
|
|
mText.SetTo(aBuffer, aLength);
|
2001-12-16 06:59:31 +00:00
|
|
|
|
2001-12-12 04:28:25 +00:00
|
|
|
SetBidiStatus();
|
1999-03-31 20:49:25 +00:00
|
|
|
|
2004-02-24 23:10:38 +00:00
|
|
|
if (haveMutationListeners) {
|
2001-12-16 06:59:31 +00:00
|
|
|
nsCOMPtr<nsIDOMEventTarget> node(do_QueryInterface(this));
|
2004-01-12 08:25:18 +00:00
|
|
|
nsMutationEvent mutation(NS_MUTATION_CHARACTERDATAMODIFIED, node);
|
2000-11-27 07:55:20 +00:00
|
|
|
|
2004-02-24 23:10:38 +00:00
|
|
|
mutation.mPrevAttrValue = oldValue;
|
2004-01-12 08:25:18 +00:00
|
|
|
nsDependentString newVal(aBuffer);
|
2000-11-27 07:55:20 +00:00
|
|
|
if (!newVal.IsEmpty())
|
2002-12-11 14:24:49 +00:00
|
|
|
mutation.mNewAttrValue = do_GetAtom(newVal);
|
2000-11-27 07:55:20 +00:00
|
|
|
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) {
|
2004-02-20 21:38:31 +00:00
|
|
|
mDocument->CharacterDataChanged(this, PR_FALSE);
|
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
|
|
|
|
2003-10-16 18:14:25 +00:00
|
|
|
mozAutoDocUpdate updateBatch(mDocument, UPDATE_CONTENT_MODEL, aNotify);
|
2001-12-16 06:59:31 +00:00
|
|
|
|
2004-02-24 23:10:38 +00:00
|
|
|
PRBool haveMutationListeners =
|
|
|
|
mDocument && nsGenericElement::HasMutationListeners(this, NS_EVENT_BITS_MUTATION_CHARACTERDATAMODIFIED);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> oldValue;
|
|
|
|
if (haveMutationListeners) {
|
|
|
|
oldValue = GetCurrentValueAtom();
|
|
|
|
}
|
|
|
|
|
1999-03-31 20:49:25 +00:00
|
|
|
mText.SetTo(aBuffer, aLength);
|
|
|
|
|
2004-02-24 23:10:38 +00:00
|
|
|
if (haveMutationListeners) {
|
2001-12-16 06:59:31 +00:00
|
|
|
nsCOMPtr<nsIDOMEventTarget> node(do_QueryInterface(this));
|
2004-01-12 08:25:18 +00:00
|
|
|
nsMutationEvent mutation(NS_MUTATION_CHARACTERDATAMODIFIED, node);
|
2000-11-27 07:55:20 +00:00
|
|
|
|
2004-02-24 23:10:38 +00:00
|
|
|
mutation.mPrevAttrValue = oldValue;
|
2004-01-12 08:25:18 +00:00
|
|
|
if (*aBuffer)
|
|
|
|
mutation.mNewAttrValue = do_GetAtom(aBuffer);
|
2000-11-27 07:55:20 +00:00
|
|
|
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) {
|
2004-02-20 21:38:31 +00:00
|
|
|
mDocument->CharacterDataChanged(this, PR_FALSE);
|
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
|
2002-03-23 23:54:46 +00:00
|
|
|
nsGenericDOMDataNode::SetText(const nsAString& aStr,
|
2000-08-23 17:27:06 +00:00
|
|
|
PRBool aNotify)
|
|
|
|
{
|
2003-10-16 18:14:25 +00:00
|
|
|
mozAutoDocUpdate updateBatch(mDocument, UPDATE_CONTENT_MODEL, aNotify);
|
2001-12-16 06:59:31 +00:00
|
|
|
|
2004-02-24 23:10:38 +00:00
|
|
|
PRBool haveMutationListeners =
|
|
|
|
mDocument && nsGenericElement::HasMutationListeners(this, NS_EVENT_BITS_MUTATION_CHARACTERDATAMODIFIED);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> oldValue;
|
|
|
|
if (haveMutationListeners) {
|
|
|
|
oldValue = GetCurrentValueAtom();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
SetBidiStatus();
|
2000-08-23 17:27:06 +00:00
|
|
|
|
2004-02-24 23:10:38 +00:00
|
|
|
if (haveMutationListeners) {
|
2001-12-16 06:59:31 +00:00
|
|
|
nsCOMPtr<nsIDOMEventTarget> node(do_QueryInterface(this));
|
2004-01-12 08:25:18 +00:00
|
|
|
nsMutationEvent mutation(NS_MUTATION_CHARACTERDATAMODIFIED, node);
|
2001-04-04 04:30:03 +00:00
|
|
|
|
2004-02-24 23:10:38 +00:00
|
|
|
mutation.mPrevAttrValue = oldValue;
|
2004-01-12 08:25:18 +00:00
|
|
|
if (!aStr.IsEmpty())
|
|
|
|
mutation.mNewAttrValue = do_GetAtom(aStr);
|
2001-04-04 04:30:03 +00:00
|
|
|
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) {
|
2004-02-20 21:38:31 +00:00
|
|
|
mDocument->CharacterDataChanged(this, PR_FALSE);
|
2000-08-23 17:27:06 +00:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2003-08-01 11:44:17 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGenericDOMDataNode::AppendTextTo(nsAString& aResult)
|
|
|
|
{
|
|
|
|
if (mText.Is2b()) {
|
|
|
|
aResult.Append(mText.Get2b(), mText.GetLength());
|
|
|
|
} else {
|
2003-11-07 16:46:15 +00:00
|
|
|
const char *str = mText.Get1b();
|
|
|
|
AppendASCIItoUTF16(Substring(str, str + mText.GetLength()), aResult);
|
2003-08-01 11:44:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
void
|
|
|
|
nsGenericDOMDataNode::LookupListenerManager(nsIEventListenerManager **aListenerManager) const
|
|
|
|
{
|
|
|
|
*aListenerManager = nsnull;
|
|
|
|
|
|
|
|
if (!HasEventListenerManager()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
EventListenerManagerMapEntry *entry =
|
2002-08-13 00:50:50 +00:00
|
|
|
NS_STATIC_CAST(EventListenerManagerMapEntry *,
|
|
|
|
PL_DHashTableOperate(&nsGenericElement::
|
|
|
|
sEventListenerManagersHash, this,
|
2001-12-16 06:59:31 +00:00
|
|
|
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 =
|
2002-08-13 00:50:50 +00:00
|
|
|
NS_STATIC_CAST(RangeListMapEntry *,
|
|
|
|
PL_DHashTableOperate(&nsGenericElement::sRangeListsHash,
|
|
|
|
this, PL_DHASH_LOOKUP));
|
2001-12-16 06:59:31 +00:00
|
|
|
|
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
|
|
|
|
return entry->mRangeList;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2001-12-12 04:28:25 +00:00
|
|
|
void nsGenericDOMDataNode::SetBidiStatus()
|
|
|
|
{
|
2003-10-22 06:09:48 +00:00
|
|
|
if (mDocument && mDocument->GetBidiEnabled()) {
|
|
|
|
// OK, we already know it's Bidi, so we won't test again
|
|
|
|
return;
|
2001-12-12 04:28:25 +00:00
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
}
|
2004-02-24 23:10:38 +00:00
|
|
|
|
|
|
|
already_AddRefed<nsIAtom>
|
|
|
|
nsGenericDOMDataNode::GetCurrentValueAtom()
|
|
|
|
{
|
|
|
|
nsAutoString val;
|
|
|
|
GetData(val);
|
|
|
|
return NS_NewAtom(val);
|
|
|
|
}
|
|
|
|
|