2001-09-25 01:32:19 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2006-03-30 08:03:04 +00:00
|
|
|
|
|
|
|
/*
|
2006-03-31 08:41:49 +00:00
|
|
|
* Base class for DOM Core's nsIDOMComment, nsIDOMDocumentType, nsIDOMText,
|
|
|
|
* nsIDOMCDATASection, and nsIDOMProcessingInstruction nodes.
|
2006-03-30 08:03:04 +00:00
|
|
|
*/
|
|
|
|
|
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"
|
2011-06-24 02:18:01 +00:00
|
|
|
#include "nsEventListenerManager.h"
|
1999-01-21 19:33:03 +00:00
|
|
|
#include "nsIDOMDocument.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-07-03 02:45:34 +00:00
|
|
|
#include "nsIURI.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"
|
2004-04-01 19:44:17 +00:00
|
|
|
#include "nsDOMString.h"
|
2005-10-27 14:09:23 +00:00
|
|
|
#include "nsIDOMUserDataHandler.h"
|
2005-11-02 00:41:51 +00:00
|
|
|
#include "nsChangeHint.h"
|
2006-03-07 17:08:51 +00:00
|
|
|
#include "nsEventDispatcher.h"
|
2006-03-22 18:36:36 +00:00
|
|
|
#include "nsCOMArray.h"
|
2006-07-02 07:23:10 +00:00
|
|
|
#include "nsNodeUtils.h"
|
2007-02-16 23:02:08 +00:00
|
|
|
#include "nsBindingManager.h"
|
2008-03-28 14:09:00 +00:00
|
|
|
#include "nsCCUncollectableMarker.h"
|
2008-04-11 17:29:06 +00:00
|
|
|
#include "mozAutoDocUpdate.h"
|
2011-12-17 06:02:05 +00:00
|
|
|
#include "nsAsyncDOMEvent.h"
|
1998-09-06 00:16:36 +00:00
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
#include "pldhash.h"
|
|
|
|
#include "prprf.h"
|
2011-05-26 19:58:35 +00:00
|
|
|
#include "nsWrapperCacheInlines.h"
|
2001-12-16 06:59:31 +00:00
|
|
|
|
2011-07-19 17:04:09 +00:00
|
|
|
using namespace mozilla;
|
2011-03-11 02:48:57 +00:00
|
|
|
|
2010-07-23 09:49:57 +00:00
|
|
|
nsGenericDOMDataNode::nsGenericDOMDataNode(already_AddRefed<nsINodeInfo> aNodeInfo)
|
2008-02-02 23:41:24 +00:00
|
|
|
: nsIContent(aNodeInfo)
|
1998-09-06 00:16:36 +00:00
|
|
|
{
|
2011-06-14 07:56:49 +00:00
|
|
|
NS_ABORT_IF_FALSE(mNodeInfo->NodeType() == nsIDOMNode::TEXT_NODE ||
|
|
|
|
mNodeInfo->NodeType() == nsIDOMNode::CDATA_SECTION_NODE ||
|
|
|
|
mNodeInfo->NodeType() == nsIDOMNode::COMMENT_NODE ||
|
|
|
|
mNodeInfo->NodeType() ==
|
|
|
|
nsIDOMNode::PROCESSING_INSTRUCTION_NODE ||
|
|
|
|
mNodeInfo->NodeType() == nsIDOMNode::DOCUMENT_TYPE_NODE,
|
|
|
|
"Bad NodeType in aNodeInfo");
|
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
|
|
|
{
|
2006-07-02 07:23:10 +00:00
|
|
|
NS_PRECONDITION(!IsInDoc(),
|
|
|
|
"Please remove this from the document properly");
|
2011-07-26 11:11:14 +00:00
|
|
|
if (GetParent()) {
|
|
|
|
NS_RELEASE(mParent);
|
|
|
|
}
|
1998-09-06 00:16:36 +00:00
|
|
|
}
|
|
|
|
|
2007-01-04 22:31:26 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsGenericDOMDataNode)
|
2001-12-16 06:59:31 +00:00
|
|
|
|
2009-05-12 20:20:42 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsGenericDOMDataNode)
|
2011-08-28 14:07:24 +00:00
|
|
|
nsINode::Trace(tmp, aCallback, aClosure);
|
2009-05-12 20:20:42 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
2012-01-30 20:08:13 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(nsGenericDOMDataNode)
|
2012-02-13 20:59:14 +00:00
|
|
|
return nsGenericElement::CanSkip(tmp, aRemovingAllowed);
|
2012-01-30 20:08:13 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_BEGIN(nsGenericDOMDataNode)
|
|
|
|
return nsGenericElement::CanSkipInCC(tmp);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_BEGIN(nsGenericDOMDataNode)
|
|
|
|
return nsGenericElement::CanSkipThis(tmp);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_END
|
|
|
|
|
2007-02-18 14:38:04 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsGenericDOMDataNode)
|
2009-05-12 20:20:42 +00:00
|
|
|
// Always need to traverse script objects, so do that before we check
|
|
|
|
// if we're uncollectable.
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
|
|
|
|
2011-08-28 14:07:24 +00:00
|
|
|
if (!nsINode::Traverse(tmp, cb)) {
|
2009-03-03 12:14:13 +00:00
|
|
|
return NS_SUCCESS_INTERRUPTED_TRAVERSE;
|
2008-03-28 14:09:00 +00:00
|
|
|
}
|
|
|
|
|
2011-10-18 11:19:44 +00:00
|
|
|
tmp->OwnerDoc()->BindingManager()->Traverse(tmp, cb);
|
2007-01-04 22:31:26 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2007-02-18 14:38:04 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGenericDOMDataNode)
|
2011-08-28 14:07:24 +00:00
|
|
|
nsINode::Unlink(tmp);
|
2007-01-04 22:31:26 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2001-12-16 06:59:31 +00:00
|
|
|
|
2008-11-13 16:54:52 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN(nsGenericDOMDataNode)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(nsGenericDOMDataNode)
|
2006-11-11 00:28:20 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIContent)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsINode)
|
2011-06-24 02:17:58 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMEventTarget)
|
2006-11-11 00:36:03 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY_TEAROFF(nsISupportsWeakReference,
|
|
|
|
new nsNodeSupportsWeakRefTearoff(this))
|
2009-06-14 18:06:22 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOMXPathNSResolver,
|
|
|
|
new nsNode3Tearoff(this))
|
2007-12-11 01:19:18 +00:00
|
|
|
// nsNodeSH::PreCreate() depends on the identity pointer being the
|
|
|
|
// same as nsINode (which nsIContent inherits), so if you change the
|
|
|
|
// below line, make sure nsNodeSH::PreCreate() still does the right
|
|
|
|
// thing!
|
2006-11-11 00:28:20 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIContent)
|
2001-12-16 06:59:31 +00:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2011-03-06 11:11:31 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsGenericDOMDataNode)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_DESTROY(nsGenericDOMDataNode,
|
|
|
|
nsNodeUtils::LastRelease(this))
|
2007-01-04 22:31:26 +00:00
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
|
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
|
|
|
{
|
2006-10-28 01:22:53 +00:00
|
|
|
return SetTextInternal(0, mText.GetLength(), aNodeValue.BeginReading(),
|
2011-10-17 14:59:28 +00:00
|
|
|
aNodeValue.Length(), true);
|
1998-09-06 00:16:36 +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::IsSupported(const nsAString& aFeature,
|
|
|
|
const nsAString& aVersion,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool* aReturn)
|
2000-04-01 13:31:23 +00:00
|
|
|
{
|
2007-07-08 07:08:04 +00:00
|
|
|
return nsGenericElement::InternalIsSupported(static_cast<nsIContent*>(this),
|
2005-02-18 21:32:46 +00:00
|
|
|
aFeature, aVersion, aReturn);
|
2000-04-01 13:31:23 +00:00
|
|
|
}
|
|
|
|
|
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
|
2005-09-11 17:15:08 +00:00
|
|
|
nsGenericDOMDataNode::GetData(nsAString& aData) const
|
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) {
|
2006-02-03 14:18:39 +00:00
|
|
|
CopyASCIItoUTF16(Substring(data, data + mText.GetLength()), aData);
|
2002-05-10 18:21:50 +00:00
|
|
|
} 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
|
|
|
{
|
2006-10-28 01:22:53 +00:00
|
|
|
return SetTextInternal(0, mText.GetLength(), aData.BeginReading(),
|
2011-10-17 14:59:28 +00:00
|
|
|
aData.Length(), 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
|
2012-08-22 15:56:38 +00:00
|
|
|
nsGenericDOMDataNode::GetLength(uint32_t* 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
|
2012-08-22 15:56:38 +00:00
|
|
|
nsGenericDOMDataNode::SubstringData(uint32_t aStart, uint32_t 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
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t textLength = 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
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t 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;
|
2006-02-03 14:18:39 +00:00
|
|
|
CopyASCIItoUTF16(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
|
|
|
{
|
2006-10-28 01:22:53 +00:00
|
|
|
return SetTextInternal(mText.GetLength(), 0, aData.BeginReading(),
|
2011-10-17 14:59:28 +00:00
|
|
|
aData.Length(), true);
|
1998-09-06 00:16:36 +00:00
|
|
|
}
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
nsresult
|
2012-08-22 15:56:38 +00:00
|
|
|
nsGenericDOMDataNode::InsertData(uint32_t aOffset,
|
2002-03-23 23:54:46 +00:00
|
|
|
const nsAString& aData)
|
1998-09-06 00:16:36 +00:00
|
|
|
{
|
2006-10-28 01:22:53 +00:00
|
|
|
return SetTextInternal(aOffset, 0, aData.BeginReading(),
|
2011-10-17 14:59:28 +00:00
|
|
|
aData.Length(), true);
|
1998-09-06 00:16:36 +00:00
|
|
|
}
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
nsresult
|
2012-08-22 15:56:38 +00:00
|
|
|
nsGenericDOMDataNode::DeleteData(uint32_t aOffset, uint32_t aCount)
|
1998-09-06 00:16:36 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
return SetTextInternal(aOffset, aCount, nullptr, 0, true);
|
1998-09-06 00:16:36 +00:00
|
|
|
}
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
nsresult
|
2012-08-22 15:56:38 +00:00
|
|
|
nsGenericDOMDataNode::ReplaceData(uint32_t aOffset, uint32_t aCount,
|
2002-03-23 23:54:46 +00:00
|
|
|
const nsAString& aData)
|
1998-09-06 00:16:36 +00:00
|
|
|
{
|
2006-10-28 01:22:53 +00:00
|
|
|
return SetTextInternal(aOffset, aCount, aData.BeginReading(),
|
2011-10-17 14:59:28 +00:00
|
|
|
aData.Length(), true);
|
2006-10-28 01:22:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 15:56:38 +00:00
|
|
|
nsGenericDOMDataNode::SetTextInternal(uint32_t aOffset, uint32_t aCount,
|
2006-10-28 01:22:53 +00:00
|
|
|
const PRUnichar* aBuffer,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aLength, bool aNotify,
|
2011-08-16 00:55:20 +00:00
|
|
|
CharacterDataChangeInfo::Details* aDetails)
|
2006-10-28 01:22:53 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aBuffer || !aLength,
|
|
|
|
"Null buffer passed to SetTextInternal!");
|
|
|
|
|
1998-09-06 00:16:36 +00:00
|
|
|
// sanitize arguments
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t 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
|
|
|
}
|
|
|
|
|
2010-04-09 22:55:11 +00:00
|
|
|
if (aCount > textLength - aOffset) {
|
|
|
|
aCount = textLength - aOffset;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t endOffset = aOffset + aCount;
|
2010-04-09 22:55:11 +00:00
|
|
|
|
|
|
|
// Make sure the text fragment can hold the new data.
|
|
|
|
if (aLength > aCount && !mText.CanGrowBy(aLength - aCount)) {
|
2012-04-11 21:55:21 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2010-04-09 22:55:11 +00:00
|
|
|
}
|
|
|
|
|
2006-10-28 01:22:53 +00:00
|
|
|
nsIDocument *document = GetCurrentDoc();
|
|
|
|
mozAutoDocUpdate updateBatch(document, UPDATE_CONTENT_MODEL, aNotify);
|
2005-07-19 20:52:12 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool haveMutationListeners = aNotify &&
|
2006-10-28 01:22:53 +00:00
|
|
|
nsContentUtils::HasMutationListeners(this,
|
2007-07-04 20:39:10 +00:00
|
|
|
NS_EVENT_BITS_MUTATION_CHARACTERDATAMODIFIED,
|
|
|
|
this);
|
2006-10-28 01:22:53 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> oldValue;
|
|
|
|
if (haveMutationListeners) {
|
|
|
|
oldValue = GetCurrentValueAtom();
|
|
|
|
}
|
|
|
|
|
2007-09-05 08:22:17 +00:00
|
|
|
if (aNotify) {
|
|
|
|
CharacterDataChangeInfo info = {
|
|
|
|
aOffset == textLength,
|
|
|
|
aOffset,
|
|
|
|
endOffset,
|
2011-08-16 00:55:20 +00:00
|
|
|
aLength,
|
|
|
|
aDetails
|
2007-09-05 08:22:17 +00:00
|
|
|
};
|
|
|
|
nsNodeUtils::CharacterDataWillChange(this, &info);
|
|
|
|
}
|
|
|
|
|
2006-10-28 01:22:53 +00:00
|
|
|
if (aOffset == 0 && endOffset == textLength) {
|
2011-09-09 16:27:00 +00:00
|
|
|
// Replacing whole text or old text was empty. Don't bother to check for
|
|
|
|
// bidi in this string if the document already has bidi enabled.
|
|
|
|
mText.SetTo(aBuffer, aLength, !document || !document->GetBidiEnabled());
|
2006-10-28 01:22:53 +00:00
|
|
|
}
|
|
|
|
else if (aOffset == textLength) {
|
|
|
|
// Appending to existing
|
2011-09-09 16:27:00 +00:00
|
|
|
mText.Append(aBuffer, aLength, !document || !document->GetBidiEnabled());
|
1998-09-06 00:16:36 +00:00
|
|
|
}
|
2006-10-28 01:22:53 +00:00
|
|
|
else {
|
|
|
|
// Merging old and new
|
|
|
|
|
|
|
|
// Allocate new buffer
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t newLength = textLength - aCount + aLength;
|
2006-10-28 01:22:53 +00:00
|
|
|
PRUnichar* to = new PRUnichar[newLength];
|
|
|
|
NS_ENSURE_TRUE(to, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
// Copy over appropriate data
|
2010-04-09 22:55:11 +00:00
|
|
|
if (aOffset) {
|
2006-10-28 01:22:53 +00:00
|
|
|
mText.CopyTo(to, 0, aOffset);
|
|
|
|
}
|
2010-04-09 22:55:11 +00:00
|
|
|
if (aLength) {
|
2006-10-28 01:22:53 +00:00
|
|
|
memcpy(to + aOffset, aBuffer, aLength * sizeof(PRUnichar));
|
|
|
|
}
|
|
|
|
if (endOffset != textLength) {
|
|
|
|
mText.CopyTo(to + aOffset + aLength, endOffset, textLength - endOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX Add OOM checking to this
|
2011-09-09 16:27:00 +00:00
|
|
|
mText.SetTo(to, newLength, !document || !document->GetBidiEnabled());
|
2006-10-28 01:22:53 +00:00
|
|
|
|
|
|
|
delete [] to;
|
|
|
|
}
|
|
|
|
|
2011-09-09 16:27:00 +00:00
|
|
|
if (document && mText.IsBidi()) {
|
|
|
|
// If we found bidi characters in mText.SetTo() above, indicate that the
|
|
|
|
// document contains bidi characters.
|
|
|
|
document->SetBidiEnabled();
|
|
|
|
}
|
1998-09-06 00:16:36 +00:00
|
|
|
|
2006-10-28 01:22:53 +00:00
|
|
|
// Notify observers
|
|
|
|
if (aNotify) {
|
2007-09-10 23:46:22 +00:00
|
|
|
CharacterDataChangeInfo info = {
|
|
|
|
aOffset == textLength,
|
|
|
|
aOffset,
|
|
|
|
endOffset,
|
2011-08-16 00:55:20 +00:00
|
|
|
aLength,
|
|
|
|
aDetails
|
2007-09-10 23:46:22 +00:00
|
|
|
};
|
|
|
|
nsNodeUtils::CharacterDataChanged(this, &info);
|
|
|
|
|
2006-10-28 01:22:53 +00:00
|
|
|
if (haveMutationListeners) {
|
2011-10-17 14:59:28 +00:00
|
|
|
nsMutationEvent mutation(true, NS_MUTATION_CHARACTERDATAMODIFIED);
|
2008-04-18 17:20:11 +00:00
|
|
|
|
|
|
|
mutation.mPrevAttrValue = oldValue;
|
|
|
|
if (aLength > 0) {
|
|
|
|
nsAutoString val;
|
|
|
|
mText.AppendTo(val);
|
|
|
|
mutation.mNewAttrValue = do_GetAtom(val);
|
2008-04-14 23:59:21 +00:00
|
|
|
}
|
2008-04-18 17:20:11 +00:00
|
|
|
|
2011-10-18 10:53:36 +00:00
|
|
|
mozAutoSubtreeModified subtree(OwnerDoc(), this);
|
2011-12-17 06:02:05 +00:00
|
|
|
(new nsAsyncDOMEvent(this, mutation))->RunDOMEventWhenSafe();
|
2006-10-28 01:22:53 +00:00
|
|
|
}
|
|
|
|
}
|
1998-09-06 00:16:36 +00:00
|
|
|
|
2004-05-07 20:55:17 +00:00
|
|
|
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
|
2012-08-22 15:56:38 +00:00
|
|
|
nsGenericDOMDataNode::ToCString(nsAString& aBuf, int32_t aOffset,
|
|
|
|
int32_t aLen) const
|
1998-09-06 00:16:36 +00:00
|
|
|
{
|
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++;
|
2006-05-07 12:15:36 +00:00
|
|
|
if (ch == '&') {
|
2006-05-07 01:39:21 +00:00
|
|
|
aBuf.AppendLiteral("&");
|
|
|
|
} else if (ch == '<') {
|
|
|
|
aBuf.AppendLiteral("<");
|
|
|
|
} else if (ch == '>') {
|
|
|
|
aBuf.AppendLiteral(">");
|
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++;
|
2006-05-07 12:15:36 +00:00
|
|
|
if (ch == '&') {
|
2006-05-07 01:39:21 +00:00
|
|
|
aBuf.AppendLiteral("&");
|
|
|
|
} else if (ch == '<') {
|
|
|
|
aBuf.AppendLiteral("<");
|
|
|
|
} else if (ch == '>') {
|
|
|
|
aBuf.AppendLiteral(">");
|
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
|
|
|
|
2005-12-03 07:42:40 +00:00
|
|
|
|
2005-04-05 23:54:35 +00:00
|
|
|
nsresult
|
|
|
|
nsGenericDOMDataNode::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aCompileEventHandlers)
|
2005-04-05 23:54:35 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aParent || aDocument, "Must have document if no parent!");
|
2006-11-22 18:35:05 +00:00
|
|
|
NS_PRECONDITION(HasSameOwnerDoc(NODE_FROM(aParent, aDocument)),
|
|
|
|
"Must have the same owner document");
|
2007-05-16 01:13:47 +00:00
|
|
|
NS_PRECONDITION(!aParent || aDocument == aParent->GetCurrentDoc(),
|
2005-04-05 23:54:35 +00:00
|
|
|
"aDocument must be current doc of aParent");
|
2006-04-15 05:09:16 +00:00
|
|
|
NS_PRECONDITION(!GetCurrentDoc() && !IsInDoc(),
|
|
|
|
"Already have a document. Unbind first!");
|
2005-04-05 23:54:35 +00:00
|
|
|
// Note that as we recurse into the kids, they'll have a non-null parent. So
|
|
|
|
// only assert if our parent is _changing_ while we have a parent.
|
|
|
|
NS_PRECONDITION(!GetParent() || aParent == GetParent(),
|
|
|
|
"Already have a parent. Unbind first!");
|
2006-05-17 16:14:33 +00:00
|
|
|
NS_PRECONDITION(!GetBindingParent() ||
|
|
|
|
aBindingParent == GetBindingParent() ||
|
|
|
|
(!aBindingParent && aParent &&
|
|
|
|
aParent->GetBindingParent() == GetBindingParent()),
|
|
|
|
"Already have a binding parent. Unbind first!");
|
2008-07-23 04:50:20 +00:00
|
|
|
NS_PRECONDITION(aBindingParent != this,
|
|
|
|
"Content must not be its own binding parent");
|
|
|
|
NS_PRECONDITION(!IsRootOfNativeAnonymousSubtree() ||
|
|
|
|
aBindingParent == aParent,
|
|
|
|
"Native anonymous content must have its parent as its "
|
2007-05-05 06:47:09 +00:00
|
|
|
"own binding parent");
|
2006-05-17 16:14:33 +00:00
|
|
|
|
|
|
|
if (!aBindingParent && aParent) {
|
|
|
|
aBindingParent = aParent->GetBindingParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
// First set the binding parent
|
|
|
|
if (aBindingParent) {
|
2008-07-23 04:50:20 +00:00
|
|
|
NS_ASSERTION(IsRootOfNativeAnonymousSubtree() ||
|
|
|
|
!HasFlag(NODE_IS_IN_ANONYMOUS_SUBTREE) ||
|
2008-12-03 10:18:57 +00:00
|
|
|
(aParent && aParent->IsInNativeAnonymousSubtree()),
|
2008-09-05 04:37:48 +00:00
|
|
|
"Trying to re-bind content from native anonymous subtree to "
|
2008-04-11 22:44:48 +00:00
|
|
|
"non-native anonymous parent!");
|
2012-08-10 22:27:28 +00:00
|
|
|
DataSlots()->mBindingParent = aBindingParent; // Weak, so no addref happens.
|
2009-02-24 18:39:09 +00:00
|
|
|
if (aParent->IsInNativeAnonymousSubtree()) {
|
2008-04-11 22:44:48 +00:00
|
|
|
SetFlags(NODE_IS_IN_ANONYMOUS_SUBTREE);
|
|
|
|
}
|
2006-05-17 16:14:33 +00:00
|
|
|
}
|
2005-09-24 18:43:15 +00:00
|
|
|
|
2005-04-05 23:54:35 +00:00
|
|
|
// Set parent
|
2006-04-15 05:09:16 +00:00
|
|
|
if (aParent) {
|
2011-07-26 11:11:14 +00:00
|
|
|
if (!GetParent()) {
|
|
|
|
NS_ADDREF(aParent);
|
|
|
|
}
|
2011-04-08 02:29:49 +00:00
|
|
|
mParent = aParent;
|
2006-04-15 05:09:16 +00:00
|
|
|
}
|
|
|
|
else {
|
2011-04-08 02:29:49 +00:00
|
|
|
mParent = aDocument;
|
2006-04-15 05:09:16 +00:00
|
|
|
}
|
2011-04-08 02:29:49 +00:00
|
|
|
SetParentIsContent(aParent);
|
2005-04-05 23:54:35 +00:00
|
|
|
|
2006-04-11 03:49:44 +00:00
|
|
|
// XXXbz sXBL/XBL2 issue!
|
|
|
|
|
2005-04-05 23:54:35 +00:00
|
|
|
// Set document
|
2005-09-24 18:43:15 +00:00
|
|
|
if (aDocument) {
|
2012-03-14 20:14:02 +00:00
|
|
|
// We no longer need to track the subtree pointer (and in fact we'll assert
|
|
|
|
// if we do this any later).
|
|
|
|
ClearSubtreeRootPointer();
|
|
|
|
|
2006-05-17 16:14:33 +00:00
|
|
|
// XXX See the comment in nsGenericElement::BindToTree
|
2011-04-08 02:29:49 +00:00
|
|
|
SetInDocument();
|
2005-09-24 18:43:15 +00:00
|
|
|
if (mText.IsBidi()) {
|
2008-06-16 09:28:17 +00:00
|
|
|
aDocument->SetBidiEnabled();
|
2005-09-24 18:43:15 +00:00
|
|
|
}
|
2010-01-18 09:26:40 +00:00
|
|
|
// Clear the lazy frame construction bits.
|
|
|
|
UnsetFlags(NODE_NEEDS_FRAME | NODE_DESCENDANTS_NEED_FRAMES);
|
2012-03-14 20:14:02 +00:00
|
|
|
} else {
|
|
|
|
// If we're not in the doc, update our subtree pointer.
|
|
|
|
SetSubtreeRootPointer(aParent->SubtreeRoot());
|
2006-06-02 13:28:14 +00:00
|
|
|
}
|
|
|
|
|
2007-03-10 13:49:43 +00:00
|
|
|
nsNodeUtils::ParentChainChanged(this);
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
UpdateEditableState(false);
|
2007-06-28 02:48:16 +00:00
|
|
|
|
2005-04-05 23:54:35 +00:00
|
|
|
NS_POSTCONDITION(aDocument == GetCurrentDoc(), "Bound to wrong document");
|
|
|
|
NS_POSTCONDITION(aParent == GetParent(), "Bound to wrong parent");
|
2006-05-17 16:14:33 +00:00
|
|
|
NS_POSTCONDITION(aBindingParent == GetBindingParent(),
|
|
|
|
"Bound to wrong binding parent");
|
2005-04-05 23:54:35 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
1998-09-06 00:16:36 +00:00
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
void
|
2011-09-29 06:19:26 +00:00
|
|
|
nsGenericDOMDataNode::UnbindFromTree(bool aDeep, bool aNullParent)
|
1998-09-06 00:16:36 +00:00
|
|
|
{
|
2009-06-28 22:48:24 +00:00
|
|
|
// Unset frame flags; if we need them again later, they'll get set again.
|
|
|
|
UnsetFlags(NS_CREATE_FRAME_IF_NON_WHITESPACE |
|
|
|
|
NS_REFRAME_IF_WHITESPACE);
|
2009-04-08 16:56:16 +00:00
|
|
|
|
2006-05-17 16:14:33 +00:00
|
|
|
nsIDocument *document = GetCurrentDoc();
|
|
|
|
if (document) {
|
|
|
|
// Notify XBL- & nsIAnonymousContentCreator-generated
|
|
|
|
// anonymous content that the document is changing.
|
|
|
|
// This is needed to update the insertion point.
|
2010-06-04 01:09:08 +00:00
|
|
|
document->BindingManager()->RemovedFromDocument(this, document);
|
2006-05-17 16:14:33 +00:00
|
|
|
}
|
|
|
|
|
2011-04-08 02:29:49 +00:00
|
|
|
if (aNullParent) {
|
2011-07-26 11:11:14 +00:00
|
|
|
if (GetParent()) {
|
|
|
|
NS_RELEASE(mParent);
|
|
|
|
} else {
|
2012-07-30 14:20:58 +00:00
|
|
|
mParent = nullptr;
|
2011-07-26 11:11:14 +00:00
|
|
|
}
|
2011-04-08 02:29:49 +00:00
|
|
|
SetParentIsContent(false);
|
|
|
|
}
|
|
|
|
ClearInDocument();
|
2006-05-17 16:14:33 +00:00
|
|
|
|
2012-03-14 20:14:02 +00:00
|
|
|
// Begin keeping track of our subtree root.
|
|
|
|
SetSubtreeRootPointer(aNullParent ? this : mParent->SubtreeRoot());
|
|
|
|
|
2006-05-17 16:14:33 +00:00
|
|
|
nsDataSlots *slots = GetExistingDataSlots();
|
|
|
|
if (slots) {
|
2012-07-30 14:20:58 +00:00
|
|
|
slots->mBindingParent = nullptr;
|
2006-05-17 16:14:33 +00:00
|
|
|
}
|
2007-03-10 13:49:43 +00:00
|
|
|
|
|
|
|
nsNodeUtils::ParentChainChanged(this);
|
2001-12-16 06:59:31 +00:00
|
|
|
}
|
|
|
|
|
2010-02-11 17:34:01 +00:00
|
|
|
already_AddRefed<nsINodeList>
|
2012-08-22 15:56:38 +00:00
|
|
|
nsGenericDOMDataNode::GetChildren(uint32_t aFilter)
|
2010-02-11 17:34:01 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-02-11 17:34:01 +00:00
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
nsIAtom *
|
2007-07-26 14:16:19 +00:00
|
|
|
nsGenericDOMDataNode::GetIDAttributeName() const
|
2003-10-21 16:16:42 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2003-10-21 16:16:42 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2001-12-16 06:59:31 +00:00
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
nsresult
|
2012-08-22 15:56:38 +00:00
|
|
|
nsGenericDOMDataNode::SetAttr(int32_t aNameSpaceID, nsIAtom* aAttr,
|
2004-01-15 17:07:27 +00:00
|
|
|
nsIAtom* aPrefix, const nsAString& aValue,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aNotify)
|
2001-12-16 06:59:31 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
nsresult
|
2012-08-22 15:56:38 +00:00
|
|
|
nsGenericDOMDataNode::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttr,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aNotify)
|
2001-12-16 06:59:31 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2012-08-22 15:56:38 +00:00
|
|
|
nsGenericDOMDataNode::GetAttr(int32_t aNameSpaceID, nsIAtom *aAttr,
|
2002-03-23 23:54:46 +00:00
|
|
|
nsAString& aResult) const
|
2001-12-16 06:59:31 +00:00
|
|
|
{
|
|
|
|
aResult.Truncate();
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2001-12-16 06:59:31 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2012-08-22 15:56:38 +00:00
|
|
|
nsGenericDOMDataNode::HasAttr(int32_t aNameSpaceID, nsIAtom *aAttribute) const
|
2001-12-16 06:59:31 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2001-12-16 06:59:31 +00:00
|
|
|
}
|
|
|
|
|
2005-12-28 21:52:39 +00:00
|
|
|
const nsAttrName*
|
2012-08-22 15:56:38 +00:00
|
|
|
nsGenericDOMDataNode::GetAttrNameAt(uint32_t aIndex) const
|
2001-12-16 06:59:31 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2001-12-16 06:59:31 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t
|
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
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t
|
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 *
|
2012-08-22 15:56:38 +00:00
|
|
|
nsGenericDOMDataNode::GetChildAt(uint32_t aIndex) const
|
2001-12-16 06:59:31 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2001-12-16 06:59:31 +00:00
|
|
|
}
|
|
|
|
|
2008-07-11 20:42:19 +00:00
|
|
|
nsIContent * const *
|
2012-08-22 15:56:38 +00:00
|
|
|
nsGenericDOMDataNode::GetChildArray(uint32_t* aChildCount) const
|
2008-07-11 20:42:19 +00:00
|
|
|
{
|
2008-12-03 14:02:03 +00:00
|
|
|
*aChildCount = 0;
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2008-07-11 20:42:19 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t
|
2012-10-06 07:19:46 +00:00
|
|
|
nsGenericDOMDataNode::IndexOf(const nsINode* 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
|
2012-08-22 15:56:38 +00:00
|
|
|
nsGenericDOMDataNode::InsertChildAt(nsIContent* aKid, uint32_t aIndex,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aNotify)
|
2001-12-16 06:59:31 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-29 21:09:07 +00:00
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
nsGenericDOMDataNode::RemoveChildAt(uint32_t aIndex, bool aNotify)
|
2001-12-16 06:59:31 +00:00
|
|
|
{
|
|
|
|
}
|
1998-12-17 07:22:28 +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
|
|
|
{
|
2006-05-17 16:14:33 +00:00
|
|
|
nsDataSlots *slots = GetExistingDataSlots();
|
2012-07-30 14:20:58 +00:00
|
|
|
return slots ? slots->mBindingParent : nullptr;
|
2000-08-12 06:28:02 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2012-08-22 15:56:38 +00:00
|
|
|
nsGenericDOMDataNode::IsNodeOfType(uint32_t aFlags) const
|
2001-12-16 06:59:31 +00:00
|
|
|
{
|
2006-07-19 04:36:36 +00:00
|
|
|
return !(aFlags & ~(eCONTENT | eDATA_NODE));
|
2001-12-16 06:59:31 +00:00
|
|
|
}
|
2000-08-12 06:28:02 +00:00
|
|
|
|
2008-04-10 22:47:01 +00:00
|
|
|
void
|
|
|
|
nsGenericDOMDataNode::SaveSubtreeState()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-11-30 17:57:03 +00:00
|
|
|
void
|
|
|
|
nsGenericDOMDataNode::DestroyContent()
|
|
|
|
{
|
2008-11-13 16:54:52 +00:00
|
|
|
// XXX We really should let cycle collection do this, but that currently still
|
|
|
|
// leaks (see https://bugzilla.mozilla.org/show_bug.cgi?id=406684).
|
2009-05-12 20:20:42 +00:00
|
|
|
nsContentUtils::ReleaseWrapper(this, this);
|
2007-11-30 17:57:03 +00:00
|
|
|
}
|
2006-05-05 06:52:21 +00:00
|
|
|
|
2001-10-16 05:31:36 +00:00
|
|
|
#ifdef DEBUG
|
2004-01-09 23:54:21 +00:00
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
nsGenericDOMDataNode::List(FILE* out, int32_t aIndent) const
|
2001-12-16 06:59:31 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
nsGenericDOMDataNode::DumpContent(FILE* out, int32_t aIndent,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aDumpAll) const
|
2001-12-16 06:59:31 +00:00
|
|
|
{
|
|
|
|
}
|
2001-10-16 05:31:36 +00:00
|
|
|
#endif
|
1999-03-31 20:49:25 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2007-01-04 10:53:59 +00:00
|
|
|
nsGenericDOMDataNode::IsLink(nsIURI** aURI) const
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
*aURI = nullptr;
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2007-01-04 10:53:59 +00:00
|
|
|
}
|
|
|
|
|
2006-07-02 07:23:10 +00:00
|
|
|
nsINode::nsSlots*
|
|
|
|
nsGenericDOMDataNode::CreateSlots()
|
|
|
|
{
|
2011-04-08 02:29:49 +00:00
|
|
|
return new nsDataSlots();
|
2006-07-02 07:23:10 +00:00
|
|
|
}
|
|
|
|
|
1999-03-31 20:49:25 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Implementation of the nsIDOMText interface
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 15:56:38 +00:00
|
|
|
nsGenericDOMDataNode::SplitData(uint32_t aOffset, nsIContent** aReturn,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aCloneAfterOriginal)
|
1999-03-31 20:49:25 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
*aReturn = nullptr;
|
1999-12-22 01:51:58 +00:00
|
|
|
nsresult rv = NS_OK;
|
1999-03-31 20:49:25 +00:00
|
|
|
nsAutoString cutText;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t length = TextLength();
|
1999-03-31 20:49:25 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t cutStartOffset = aCloneAfterOriginal ? aOffset : 0;
|
|
|
|
uint32_t cutLength = aCloneAfterOriginal ? length - aOffset : aOffset;
|
2008-07-25 10:37:37 +00:00
|
|
|
rv = SubstringData(cutStartOffset, cutLength, cutText);
|
1999-12-22 01:51:58 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-02-12 21:21:49 +00:00
|
|
|
nsIDocument* document = GetCurrentDoc();
|
|
|
|
mozAutoDocUpdate updateBatch(document, UPDATE_CONTENT_MODEL, true);
|
|
|
|
|
2011-08-16 00:55:20 +00:00
|
|
|
// Use Clone for creating the new node so that the new node is of same class
|
|
|
|
// as this node!
|
2011-10-17 14:59:28 +00:00
|
|
|
nsCOMPtr<nsIContent> newContent = CloneDataNode(mNodeInfo, false);
|
2004-05-07 20:55:17 +00:00
|
|
|
if (!newContent) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1999-12-22 01:51:58 +00:00
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
newContent->SetText(cutText, true); // XXX should be false?
|
1999-12-22 01:51:58 +00:00
|
|
|
|
2011-08-16 00:55:20 +00:00
|
|
|
CharacterDataChangeInfo::Details details = {
|
|
|
|
CharacterDataChangeInfo::Details::eSplit, newContent
|
|
|
|
};
|
2012-07-30 14:20:58 +00:00
|
|
|
rv = SetTextInternal(cutStartOffset, cutLength, nullptr, 0, true,
|
|
|
|
aCloneAfterOriginal ? &details : nullptr);
|
2011-08-16 00:55:20 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
1999-12-22 01:51:58 +00:00
|
|
|
|
2008-07-25 10:37:37 +00:00
|
|
|
nsCOMPtr<nsINode> parent = GetNodeParent();
|
2004-05-07 20:55:17 +00:00
|
|
|
if (parent) {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t insertionIndex = parent->IndexOf(this);
|
2008-07-25 10:37:37 +00:00
|
|
|
if (aCloneAfterOriginal) {
|
|
|
|
++insertionIndex;
|
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
parent->InsertChildAt(newContent, insertionIndex, true);
|
1999-12-22 01:51:58 +00:00
|
|
|
}
|
2001-12-16 06:59:31 +00:00
|
|
|
|
2008-07-25 10:37:37 +00:00
|
|
|
newContent.swap(*aReturn);
|
|
|
|
return rv;
|
|
|
|
}
|
2004-08-10 10:22:36 +00:00
|
|
|
|
2008-07-25 10:37:37 +00:00
|
|
|
nsresult
|
2012-08-22 15:56:38 +00:00
|
|
|
nsGenericDOMDataNode::SplitText(uint32_t aOffset, nsIDOMText** aReturn)
|
2008-07-25 10:37:37 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> newChild;
|
|
|
|
nsresult rv = SplitData(aOffset, getter_AddRefs(newChild));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = CallQueryInterface(newChild, aReturn);
|
|
|
|
}
|
|
|
|
return rv;
|
1999-03-31 20:49:25 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
/* static */ int32_t
|
2008-06-04 17:53:34 +00:00
|
|
|
nsGenericDOMDataNode::FirstLogicallyAdjacentTextNode(nsIContent* aParent,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aIndex)
|
2008-06-04 17:53:34 +00:00
|
|
|
{
|
|
|
|
while (aIndex-- > 0) {
|
|
|
|
nsIContent* sibling = aParent->GetChildAt(aIndex);
|
|
|
|
if (!sibling->IsNodeOfType(nsINode::eTEXT))
|
|
|
|
return aIndex + 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
/* static */ int32_t
|
2008-06-04 17:53:34 +00:00
|
|
|
nsGenericDOMDataNode::LastLogicallyAdjacentTextNode(nsIContent* aParent,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aIndex,
|
|
|
|
uint32_t aCount)
|
2008-06-04 17:53:34 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
while (++aIndex < int32_t(aCount)) {
|
2008-06-04 17:53:34 +00:00
|
|
|
nsIContent* sibling = aParent->GetChildAt(aIndex);
|
|
|
|
if (!sibling->IsNodeOfType(nsINode::eTEXT))
|
|
|
|
return aIndex - 1;
|
|
|
|
}
|
|
|
|
return aCount - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2011-05-21 05:21:28 +00:00
|
|
|
nsGenericDOMDataNode::GetWholeText(nsAString& aWholeText)
|
2008-06-04 17:53:34 +00:00
|
|
|
{
|
|
|
|
nsIContent* parent = GetParent();
|
|
|
|
|
|
|
|
// Handle parent-less nodes
|
|
|
|
if (!parent)
|
|
|
|
return GetData(aWholeText);
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t index = parent->IndexOf(this);
|
2008-07-13 19:28:22 +00:00
|
|
|
NS_WARN_IF_FALSE(index >= 0,
|
|
|
|
"Trying to use .wholeText with an anonymous"
|
|
|
|
"text node child of a binding parent?");
|
|
|
|
NS_ENSURE_TRUE(index >= 0, NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t first =
|
2008-06-04 17:53:34 +00:00
|
|
|
FirstLogicallyAdjacentTextNode(parent, index);
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t last =
|
2008-06-04 17:53:34 +00:00
|
|
|
LastLogicallyAdjacentTextNode(parent, index, parent->GetChildCount());
|
|
|
|
|
|
|
|
aWholeText.Truncate();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMText> node;
|
|
|
|
nsAutoString tmp;
|
|
|
|
do {
|
|
|
|
node = do_QueryInterface(parent->GetChildAt(first));
|
|
|
|
node->GetData(tmp);
|
|
|
|
aWholeText.Append(tmp);
|
|
|
|
} while (first++ < last);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2006-07-19 04:36:36 +00:00
|
|
|
// Implementation of the nsIContent interface text functions
|
1999-03-31 20:49:25 +00:00
|
|
|
|
2004-05-07 20:55:17 +00:00
|
|
|
const nsTextFragment *
|
2006-07-19 04:36:36 +00:00
|
|
|
nsGenericDOMDataNode::GetText()
|
1999-08-27 21:40:47 +00:00
|
|
|
{
|
2004-05-07 20:55:17 +00:00
|
|
|
return &mText;
|
1999-08-27 21:40:47 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t
|
2012-03-29 21:09:04 +00:00
|
|
|
nsGenericDOMDataNode::TextLength() const
|
1999-08-27 21:40:47 +00:00
|
|
|
{
|
2004-05-07 20:55:17 +00:00
|
|
|
return mText.GetLength();
|
1999-08-27 21:40:47 +00:00
|
|
|
}
|
|
|
|
|
2006-07-19 04:36:36 +00:00
|
|
|
nsresult
|
2001-12-16 06:59:31 +00:00
|
|
|
nsGenericDOMDataNode::SetText(const PRUnichar* aBuffer,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aLength,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aNotify)
|
1999-03-31 20:49:25 +00:00
|
|
|
{
|
2006-10-28 01:22:53 +00:00
|
|
|
return SetTextInternal(0, mText.GetLength(), aBuffer, aLength, aNotify);
|
|
|
|
}
|
2006-07-19 04:36:36 +00:00
|
|
|
|
2006-10-28 01:22:53 +00:00
|
|
|
nsresult
|
|
|
|
nsGenericDOMDataNode::AppendText(const PRUnichar* aBuffer,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aLength,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aNotify)
|
2006-10-28 01:22:53 +00:00
|
|
|
{
|
|
|
|
return SetTextInternal(mText.GetLength(), 0, aBuffer, aLength, aNotify);
|
1999-03-31 20:49:25 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2006-07-19 04:36:36 +00:00
|
|
|
nsGenericDOMDataNode::TextIsOnlyWhitespace()
|
1999-03-31 20:49:25 +00:00
|
|
|
{
|
2006-03-24 03:29:52 +00:00
|
|
|
if (mText.Is2b()) {
|
|
|
|
// The fragment contains non-8bit characters and such characters
|
|
|
|
// are never considered whitespace.
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2006-03-24 03:29:52 +00:00
|
|
|
}
|
2001-12-16 06:59:31 +00:00
|
|
|
|
2006-03-24 03:29:52 +00:00
|
|
|
const char* cp = mText.Get1b();
|
|
|
|
const char* end = cp + mText.GetLength();
|
2001-12-16 06:59:31 +00:00
|
|
|
|
2006-03-24 03:29:52 +00:00
|
|
|
while (cp < end) {
|
|
|
|
char ch = *cp;
|
2001-12-16 06:59:31 +00:00
|
|
|
|
2006-03-24 03:29:52 +00:00
|
|
|
if (!XP_IS_SPACE(ch)) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
1999-03-31 20:49:25 +00:00
|
|
|
}
|
2006-03-24 03:29:52 +00:00
|
|
|
|
|
|
|
++cp;
|
1999-03-31 20:49:25 +00:00
|
|
|
}
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2001-12-16 06:59:31 +00:00
|
|
|
}
|
|
|
|
|
2004-05-07 20:55:17 +00:00
|
|
|
void
|
2003-08-01 11:44:17 +00:00
|
|
|
nsGenericDOMDataNode::AppendTextTo(nsAString& aResult)
|
|
|
|
{
|
2004-07-14 21:43:12 +00:00
|
|
|
mText.AppendTo(aResult);
|
2003-08-01 11:44:17 +00:00
|
|
|
}
|
|
|
|
|
2004-02-24 23:10:38 +00:00
|
|
|
already_AddRefed<nsIAtom>
|
|
|
|
nsGenericDOMDataNode::GetCurrentValueAtom()
|
|
|
|
{
|
|
|
|
nsAutoString val;
|
|
|
|
GetData(val);
|
|
|
|
return NS_NewAtom(val);
|
|
|
|
}
|
2005-11-02 00:41:51 +00:00
|
|
|
|
|
|
|
nsIAtom*
|
2010-06-04 01:09:20 +00:00
|
|
|
nsGenericDOMDataNode::DoGetID() const
|
2005-11-02 00:41:51 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2005-11-02 00:41:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const nsAttrValue*
|
2008-09-11 03:22:20 +00:00
|
|
|
nsGenericDOMDataNode::DoGetClasses() const
|
2005-11-02 00:41:51 +00:00
|
|
|
{
|
2008-09-11 03:22:20 +00:00
|
|
|
NS_NOTREACHED("Shouldn't ever be called");
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2005-11-02 00:41:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGenericDOMDataNode::WalkContentStyleRules(nsRuleWalker* aRuleWalker)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHODIMP_(bool)
|
2005-11-02 00:41:51 +00:00
|
|
|
nsGenericDOMDataNode::IsAttributeMapped(const nsIAtom* aAttribute) const
|
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2005-11-02 00:41:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsChangeHint
|
|
|
|
nsGenericDOMDataNode::GetAttributeChangeHint(const nsIAtom* aAttribute,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aModType) const
|
2005-11-02 00:41:51 +00:00
|
|
|
{
|
|
|
|
NS_NOTREACHED("Shouldn't be calling this!");
|
|
|
|
return nsChangeHint(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom*
|
|
|
|
nsGenericDOMDataNode::GetClassAttributeName() const
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2005-11-02 00:41:51 +00:00
|
|
|
}
|
2011-07-19 17:04:09 +00:00
|
|
|
|
2012-03-05 18:09:05 +00:00
|
|
|
size_t
|
|
|
|
nsGenericDOMDataNode::SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
2011-07-19 17:04:09 +00:00
|
|
|
{
|
2012-03-05 18:09:05 +00:00
|
|
|
size_t n = nsIContent::SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
n += mText.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
return n;
|
2011-07-19 17:04:09 +00:00
|
|
|
}
|
|
|
|
|