2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla 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/MPL/
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of 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 MPL, 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 MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Base class for DOM Core's nsIDOMComment, nsIDOMDocumentType, nsIDOMText,
|
|
|
|
* nsIDOMCDATASection, and nsIDOMProcessingInstruction nodes.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsGenericDOMDataNode.h"
|
|
|
|
#include "nsGenericElement.h"
|
|
|
|
#include "nsIDocument.h"
|
2011-06-23 19:18:01 -07:00
|
|
|
#include "nsEventListenerManager.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
#include "nsMutationEvent.h"
|
|
|
|
#include "nsINameSpaceManager.h"
|
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsIPrivateDOMEvent.h"
|
|
|
|
#include "nsIDOMEvent.h"
|
|
|
|
#include "nsIDOMText.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsDOMString.h"
|
|
|
|
#include "nsIDOMUserDataHandler.h"
|
|
|
|
#include "nsChangeHint.h"
|
|
|
|
#include "nsEventDispatcher.h"
|
|
|
|
#include "nsCOMArray.h"
|
|
|
|
#include "nsNodeUtils.h"
|
|
|
|
#include "nsBindingManager.h"
|
2008-03-28 07:09:00 -07:00
|
|
|
#include "nsCCUncollectableMarker.h"
|
2008-04-11 10:29:06 -07:00
|
|
|
#include "mozAutoDocUpdate.h"
|
2011-12-16 22:02:05 -08:00
|
|
|
#include "nsAsyncDOMEvent.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "pldhash.h"
|
|
|
|
#include "prprf.h"
|
2011-05-26 12:58:35 -07:00
|
|
|
#include "nsWrapperCacheInlines.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-07-19 10:04:09 -07:00
|
|
|
using namespace mozilla;
|
2011-03-10 18:48:57 -08:00
|
|
|
|
2010-07-23 02:49:57 -07:00
|
|
|
nsGenericDOMDataNode::nsGenericDOMDataNode(already_AddRefed<nsINodeInfo> aNodeInfo)
|
2008-02-02 15:41:24 -08:00
|
|
|
: nsIContent(aNodeInfo)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-06-14 00:56:49 -07: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");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsGenericDOMDataNode::~nsGenericDOMDataNode()
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(!IsInDoc(),
|
|
|
|
"Please remove this from the document properly");
|
2011-07-26 04:11:14 -07:00
|
|
|
if (GetParent()) {
|
|
|
|
NS_RELEASE(mParent);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsGenericDOMDataNode)
|
|
|
|
|
2009-05-12 13:20:42 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsGenericDOMDataNode)
|
2011-08-28 07:07:24 -07:00
|
|
|
nsINode::Trace(tmp, aCallback, aClosure);
|
2009-05-12 13:20:42 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
2012-01-30 12:08:13 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(nsGenericDOMDataNode)
|
2012-02-13 12:59:14 -08:00
|
|
|
return nsGenericElement::CanSkip(tmp, aRemovingAllowed);
|
2012-01-30 12:08:13 -08: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-03-22 10:30:00 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsGenericDOMDataNode)
|
2009-05-12 13:20:42 -07: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 07:07:24 -07:00
|
|
|
if (!nsINode::Traverse(tmp, cb)) {
|
2009-03-03 04:14:13 -08:00
|
|
|
return NS_SUCCESS_INTERRUPTED_TRAVERSE;
|
2008-03-28 07:09:00 -07:00
|
|
|
}
|
|
|
|
|
2011-10-18 04:19:44 -07:00
|
|
|
tmp->OwnerDoc()->BindingManager()->Traverse(tmp, cb);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGenericDOMDataNode)
|
2011-08-28 07:07:24 -07:00
|
|
|
nsINode::Unlink(tmp);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2008-11-13 08:54:52 -08:00
|
|
|
NS_INTERFACE_MAP_BEGIN(nsGenericDOMDataNode)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(nsGenericDOMDataNode)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIContent)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsINode)
|
2011-06-23 19:17:58 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMEventTarget)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY_TEAROFF(nsISupportsWeakReference,
|
|
|
|
new nsNodeSupportsWeakRefTearoff(this))
|
2009-06-14 11:06:22 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOMXPathNSResolver,
|
|
|
|
new nsNode3Tearoff(this))
|
2007-12-10 17:19:18 -08: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!
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIContent)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2011-03-06 03:11:31 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsGenericDOMDataNode)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_DESTROY(nsGenericDOMDataNode,
|
|
|
|
nsNodeUtils::LastRelease(this))
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsGenericDOMDataNode::GetNodeValue(nsAString& aNodeValue)
|
|
|
|
{
|
|
|
|
return GetData(aNodeValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsGenericDOMDataNode::SetNodeValue(const nsAString& aNodeValue)
|
|
|
|
{
|
|
|
|
return SetTextInternal(0, mText.GetLength(), aNodeValue.BeginReading(),
|
2011-10-17 07:59:28 -07:00
|
|
|
aNodeValue.Length(), true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsGenericDOMDataNode::GetNamespaceURI(nsAString& aNamespaceURI)
|
|
|
|
{
|
|
|
|
SetDOMStringToNull(aNamespaceURI);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsGenericDOMDataNode::GetPrefix(nsAString& aPrefix)
|
|
|
|
{
|
|
|
|
SetDOMStringToNull(aPrefix);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsGenericDOMDataNode::IsSupported(const nsAString& aFeature,
|
|
|
|
const nsAString& aVersion,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* aReturn)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
return nsGenericElement::InternalIsSupported(static_cast<nsIContent*>(this),
|
2007-03-22 10:30:00 -07:00
|
|
|
aFeature, aVersion, aReturn);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Implementation of nsIDOMCharacterData
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsGenericDOMDataNode::GetData(nsAString& aData) const
|
|
|
|
{
|
|
|
|
if (mText.Is2b()) {
|
|
|
|
aData.Assign(mText.Get2b(), mText.GetLength());
|
|
|
|
} else {
|
|
|
|
// Must use Substring() since nsDependentCString() requires null
|
|
|
|
// terminated strings.
|
|
|
|
|
|
|
|
const char *data = mText.Get1b();
|
|
|
|
|
|
|
|
if (data) {
|
|
|
|
CopyASCIItoUTF16(Substring(data, data + mText.GetLength()), aData);
|
|
|
|
} else {
|
|
|
|
aData.Truncate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsGenericDOMDataNode::SetData(const nsAString& aData)
|
|
|
|
{
|
|
|
|
return SetTextInternal(0, mText.GetLength(), aData.BeginReading(),
|
2011-10-17 07:59:28 -07:00
|
|
|
aData.Length(), true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsGenericDOMDataNode::GetLength(PRUint32* aLength)
|
|
|
|
{
|
|
|
|
*aLength = mText.GetLength();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsGenericDOMDataNode::SubstringData(PRUint32 aStart, PRUint32 aCount,
|
|
|
|
nsAString& aReturn)
|
|
|
|
{
|
|
|
|
aReturn.Truncate();
|
|
|
|
|
2010-04-09 15:55:11 -07:00
|
|
|
PRUint32 textLength = mText.GetLength();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aStart > textLength) {
|
|
|
|
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32 amount = aCount;
|
|
|
|
if (amount > textLength - aStart) {
|
|
|
|
amount = textLength - aStart;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mText.Is2b()) {
|
|
|
|
aReturn.Assign(mText.Get2b() + aStart, amount);
|
|
|
|
} else {
|
|
|
|
// Must use Substring() since nsDependentCString() requires null
|
|
|
|
// terminated strings.
|
|
|
|
|
|
|
|
const char *data = mText.Get1b() + aStart;
|
|
|
|
CopyASCIItoUTF16(Substring(data, data + amount), aReturn);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsGenericDOMDataNode::AppendData(const nsAString& aData)
|
|
|
|
{
|
|
|
|
return SetTextInternal(mText.GetLength(), 0, aData.BeginReading(),
|
2011-10-17 07:59:28 -07:00
|
|
|
aData.Length(), true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsGenericDOMDataNode::InsertData(PRUint32 aOffset,
|
|
|
|
const nsAString& aData)
|
|
|
|
{
|
|
|
|
return SetTextInternal(aOffset, 0, aData.BeginReading(),
|
2011-10-17 07:59:28 -07:00
|
|
|
aData.Length(), true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsGenericDOMDataNode::DeleteData(PRUint32 aOffset, PRUint32 aCount)
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
return SetTextInternal(aOffset, aCount, nsnull, 0, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsGenericDOMDataNode::ReplaceData(PRUint32 aOffset, PRUint32 aCount,
|
|
|
|
const nsAString& aData)
|
|
|
|
{
|
|
|
|
return SetTextInternal(aOffset, aCount, aData.BeginReading(),
|
2011-10-17 07:59:28 -07:00
|
|
|
aData.Length(), true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsGenericDOMDataNode::SetTextInternal(PRUint32 aOffset, PRUint32 aCount,
|
|
|
|
const PRUnichar* aBuffer,
|
2011-09-28 23:19:26 -07:00
|
|
|
PRUint32 aLength, bool aNotify,
|
2011-08-15 17:55:20 -07:00
|
|
|
CharacterDataChangeInfo::Details* aDetails)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aBuffer || !aLength,
|
|
|
|
"Null buffer passed to SetTextInternal!");
|
|
|
|
|
|
|
|
// sanitize arguments
|
|
|
|
PRUint32 textLength = mText.GetLength();
|
|
|
|
if (aOffset > textLength) {
|
|
|
|
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
|
|
|
}
|
|
|
|
|
2010-04-09 15:55:11 -07:00
|
|
|
if (aCount > textLength - aOffset) {
|
|
|
|
aCount = textLength - aOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32 endOffset = aOffset + aCount;
|
|
|
|
|
|
|
|
// Make sure the text fragment can hold the new data.
|
|
|
|
if (aLength > aCount && !mText.CanGrowBy(aLength - aCount)) {
|
|
|
|
// This exception isn't per spec, but the spec doesn't actually
|
|
|
|
// say what to do here.
|
|
|
|
|
|
|
|
return NS_ERROR_DOM_DOMSTRING_SIZE_ERR;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIDocument *document = GetCurrentDoc();
|
|
|
|
mozAutoDocUpdate updateBatch(document, UPDATE_CONTENT_MODEL, aNotify);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool haveMutationListeners = aNotify &&
|
2007-03-22 10:30:00 -07:00
|
|
|
nsContentUtils::HasMutationListeners(this,
|
2007-07-04 13:39:10 -07:00
|
|
|
NS_EVENT_BITS_MUTATION_CHARACTERDATAMODIFIED,
|
|
|
|
this);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> oldValue;
|
|
|
|
if (haveMutationListeners) {
|
|
|
|
oldValue = GetCurrentValueAtom();
|
|
|
|
}
|
|
|
|
|
2007-09-05 01:22:17 -07:00
|
|
|
if (aNotify) {
|
|
|
|
CharacterDataChangeInfo info = {
|
|
|
|
aOffset == textLength,
|
|
|
|
aOffset,
|
|
|
|
endOffset,
|
2011-08-15 17:55:20 -07:00
|
|
|
aLength,
|
|
|
|
aDetails
|
2007-09-05 01:22:17 -07:00
|
|
|
};
|
|
|
|
nsNodeUtils::CharacterDataWillChange(this, &info);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aOffset == 0 && endOffset == textLength) {
|
2011-09-09 09:27:00 -07: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());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else if (aOffset == textLength) {
|
|
|
|
// Appending to existing
|
2011-09-09 09:27:00 -07:00
|
|
|
mText.Append(aBuffer, aLength, !document || !document->GetBidiEnabled());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Merging old and new
|
|
|
|
|
|
|
|
// Allocate new buffer
|
|
|
|
PRInt32 newLength = textLength - aCount + aLength;
|
|
|
|
PRUnichar* to = new PRUnichar[newLength];
|
|
|
|
NS_ENSURE_TRUE(to, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
// Copy over appropriate data
|
2010-04-09 15:55:11 -07:00
|
|
|
if (aOffset) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mText.CopyTo(to, 0, aOffset);
|
|
|
|
}
|
2010-04-09 15:55:11 -07:00
|
|
|
if (aLength) {
|
2007-03-22 10:30:00 -07: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 09:27:00 -07:00
|
|
|
mText.SetTo(to, newLength, !document || !document->GetBidiEnabled());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
delete [] to;
|
|
|
|
}
|
|
|
|
|
2011-09-09 09:27:00 -07:00
|
|
|
if (document && mText.IsBidi()) {
|
|
|
|
// If we found bidi characters in mText.SetTo() above, indicate that the
|
|
|
|
// document contains bidi characters.
|
|
|
|
document->SetBidiEnabled();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Notify observers
|
|
|
|
if (aNotify) {
|
2007-09-10 16:46:22 -07:00
|
|
|
CharacterDataChangeInfo info = {
|
|
|
|
aOffset == textLength,
|
|
|
|
aOffset,
|
|
|
|
endOffset,
|
2011-08-15 17:55:20 -07:00
|
|
|
aLength,
|
|
|
|
aDetails
|
2007-09-10 16:46:22 -07:00
|
|
|
};
|
|
|
|
nsNodeUtils::CharacterDataChanged(this, &info);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (haveMutationListeners) {
|
2011-10-17 07:59:28 -07:00
|
|
|
nsMutationEvent mutation(true, NS_MUTATION_CHARACTERDATAMODIFIED);
|
2008-04-18 10:20:11 -07:00
|
|
|
|
|
|
|
mutation.mPrevAttrValue = oldValue;
|
|
|
|
if (aLength > 0) {
|
|
|
|
nsAutoString val;
|
|
|
|
mText.AppendTo(val);
|
|
|
|
mutation.mNewAttrValue = do_GetAtom(val);
|
2008-04-14 16:59:21 -07:00
|
|
|
}
|
2008-04-18 10:20:11 -07:00
|
|
|
|
2011-10-18 03:53:36 -07:00
|
|
|
mozAutoSubtreeModified subtree(OwnerDoc(), this);
|
2011-12-16 22:02:05 -08:00
|
|
|
(new nsAsyncDOMEvent(this, mutation))->RunDOMEventWhenSafe();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Implementation of nsIContent
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
|
|
|
nsGenericDOMDataNode::ToCString(nsAString& aBuf, PRInt32 aOffset,
|
|
|
|
PRInt32 aLen) const
|
|
|
|
{
|
|
|
|
if (mText.Is2b()) {
|
|
|
|
const PRUnichar* cp = mText.Get2b() + aOffset;
|
|
|
|
const PRUnichar* end = cp + aLen;
|
|
|
|
|
|
|
|
while (cp < end) {
|
|
|
|
PRUnichar ch = *cp++;
|
|
|
|
if (ch == '&') {
|
|
|
|
aBuf.AppendLiteral("&");
|
|
|
|
} else if (ch == '<') {
|
|
|
|
aBuf.AppendLiteral("<");
|
|
|
|
} else if (ch == '>') {
|
|
|
|
aBuf.AppendLiteral(">");
|
|
|
|
} else if ((ch < ' ') || (ch >= 127)) {
|
|
|
|
char buf[10];
|
|
|
|
PR_snprintf(buf, sizeof(buf), "\\u%04x", ch);
|
|
|
|
AppendASCIItoUTF16(buf, aBuf);
|
|
|
|
} else {
|
|
|
|
aBuf.Append(ch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
unsigned char* cp = (unsigned char*)mText.Get1b() + aOffset;
|
|
|
|
const unsigned char* end = cp + aLen;
|
|
|
|
|
|
|
|
while (cp < end) {
|
|
|
|
PRUnichar ch = *cp++;
|
|
|
|
if (ch == '&') {
|
|
|
|
aBuf.AppendLiteral("&");
|
|
|
|
} else if (ch == '<') {
|
|
|
|
aBuf.AppendLiteral("<");
|
|
|
|
} else if (ch == '>') {
|
|
|
|
aBuf.AppendLiteral(">");
|
|
|
|
} else if ((ch < ' ') || (ch >= 127)) {
|
|
|
|
char buf[10];
|
|
|
|
PR_snprintf(buf, sizeof(buf), "\\u%04x", ch);
|
|
|
|
AppendASCIItoUTF16(buf, aBuf);
|
|
|
|
} else {
|
|
|
|
aBuf.Append(ch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsGenericDOMDataNode::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aCompileEventHandlers)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aParent || aDocument, "Must have document if no parent!");
|
|
|
|
NS_PRECONDITION(HasSameOwnerDoc(NODE_FROM(aParent, aDocument)),
|
|
|
|
"Must have the same owner document");
|
2007-05-15 18:13:47 -07:00
|
|
|
NS_PRECONDITION(!aParent || aDocument == aParent->GetCurrentDoc(),
|
2007-03-22 10:30:00 -07:00
|
|
|
"aDocument must be current doc of aParent");
|
|
|
|
NS_PRECONDITION(!GetCurrentDoc() && !IsInDoc(),
|
|
|
|
"Already have a document. Unbind first!");
|
|
|
|
// 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!");
|
|
|
|
NS_PRECONDITION(!GetBindingParent() ||
|
|
|
|
aBindingParent == GetBindingParent() ||
|
|
|
|
(!aBindingParent && aParent &&
|
|
|
|
aParent->GetBindingParent() == GetBindingParent()),
|
|
|
|
"Already have a binding parent. Unbind first!");
|
2008-07-22 21:50:20 -07: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-04 23:47:09 -07:00
|
|
|
"own binding parent");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (!aBindingParent && aParent) {
|
|
|
|
aBindingParent = aParent->GetBindingParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
// First set the binding parent
|
|
|
|
if (aBindingParent) {
|
|
|
|
nsDataSlots *slots = GetDataSlots();
|
|
|
|
NS_ENSURE_TRUE(slots, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2008-07-22 21:50:20 -07:00
|
|
|
NS_ASSERTION(IsRootOfNativeAnonymousSubtree() ||
|
|
|
|
!HasFlag(NODE_IS_IN_ANONYMOUS_SUBTREE) ||
|
2008-12-03 02:18:57 -08:00
|
|
|
(aParent && aParent->IsInNativeAnonymousSubtree()),
|
2008-09-04 21:37:48 -07:00
|
|
|
"Trying to re-bind content from native anonymous subtree to "
|
2008-04-11 15:44:48 -07:00
|
|
|
"non-native anonymous parent!");
|
2007-03-22 10:30:00 -07:00
|
|
|
slots->mBindingParent = aBindingParent; // Weak, so no addref happens.
|
2009-02-24 10:39:09 -08:00
|
|
|
if (aParent->IsInNativeAnonymousSubtree()) {
|
2008-04-11 15:44:48 -07:00
|
|
|
SetFlags(NODE_IS_IN_ANONYMOUS_SUBTREE);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set parent
|
|
|
|
if (aParent) {
|
2011-07-26 04:11:14 -07:00
|
|
|
if (!GetParent()) {
|
|
|
|
NS_ADDREF(aParent);
|
|
|
|
}
|
2011-04-07 19:29:49 -07:00
|
|
|
mParent = aParent;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
2011-04-07 19:29:49 -07:00
|
|
|
mParent = aDocument;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-04-07 19:29:49 -07:00
|
|
|
SetParentIsContent(aParent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// XXXbz sXBL/XBL2 issue!
|
|
|
|
|
|
|
|
// Set document
|
|
|
|
if (aDocument) {
|
|
|
|
// XXX See the comment in nsGenericElement::BindToTree
|
2011-04-07 19:29:49 -07:00
|
|
|
SetInDocument();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mText.IsBidi()) {
|
2008-06-16 02:28:17 -07:00
|
|
|
aDocument->SetBidiEnabled();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-01-18 01:26:40 -08:00
|
|
|
// Clear the lazy frame construction bits.
|
|
|
|
UnsetFlags(NODE_NEEDS_FRAME | NODE_DESCENDANTS_NEED_FRAMES);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsNodeUtils::ParentChainChanged(this);
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
UpdateEditableState(false);
|
2007-06-27 19:48:16 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_POSTCONDITION(aDocument == GetCurrentDoc(), "Bound to wrong document");
|
|
|
|
NS_POSTCONDITION(aParent == GetParent(), "Bound to wrong parent");
|
|
|
|
NS_POSTCONDITION(aBindingParent == GetBindingParent(),
|
|
|
|
"Bound to wrong binding parent");
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsGenericDOMDataNode::UnbindFromTree(bool aDeep, bool aNullParent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-06-28 15:48:24 -07: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 09:56:16 -07:00
|
|
|
|
2007-03-22 10:30:00 -07: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-03 18:09:08 -07:00
|
|
|
document->BindingManager()->RemovedFromDocument(this, document);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-04-07 19:29:49 -07:00
|
|
|
if (aNullParent) {
|
2011-07-26 04:11:14 -07:00
|
|
|
if (GetParent()) {
|
|
|
|
NS_RELEASE(mParent);
|
|
|
|
} else {
|
|
|
|
mParent = nsnull;
|
|
|
|
}
|
2011-04-07 19:29:49 -07:00
|
|
|
SetParentIsContent(false);
|
|
|
|
}
|
|
|
|
ClearInDocument();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsDataSlots *slots = GetExistingDataSlots();
|
|
|
|
if (slots) {
|
|
|
|
slots->mBindingParent = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsNodeUtils::ParentChainChanged(this);
|
|
|
|
}
|
|
|
|
|
2010-02-11 09:34:01 -08:00
|
|
|
already_AddRefed<nsINodeList>
|
2010-10-15 08:34:35 -07:00
|
|
|
nsGenericDOMDataNode::GetChildren(PRUint32 aFilter)
|
2010-02-11 09:34:01 -08:00
|
|
|
{
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom *
|
2007-07-26 07:16:19 -07:00
|
|
|
nsGenericDOMDataNode::GetIDAttributeName() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsINodeInfo>
|
|
|
|
nsGenericDOMDataNode::GetExistingAttrNameFromQName(const nsAString& aStr) const
|
|
|
|
{
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsGenericDOMDataNode::SetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttr,
|
|
|
|
nsIAtom* aPrefix, const nsAString& aValue,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aNotify)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsGenericDOMDataNode::UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttr,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aNotify)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsGenericDOMDataNode::GetAttr(PRInt32 aNameSpaceID, nsIAtom *aAttr,
|
|
|
|
nsAString& aResult) const
|
|
|
|
{
|
|
|
|
aResult.Truncate();
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsGenericDOMDataNode::HasAttr(PRInt32 aNameSpaceID, nsIAtom *aAttribute) const
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const nsAttrName*
|
|
|
|
nsGenericDOMDataNode::GetAttrNameAt(PRUint32 aIndex) const
|
|
|
|
{
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32
|
|
|
|
nsGenericDOMDataNode::GetAttrCount() const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32
|
|
|
|
nsGenericDOMDataNode::GetChildCount() const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent *
|
|
|
|
nsGenericDOMDataNode::GetChildAt(PRUint32 aIndex) const
|
|
|
|
{
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2008-07-11 13:42:19 -07:00
|
|
|
nsIContent * const *
|
2008-12-03 06:02:03 -08:00
|
|
|
nsGenericDOMDataNode::GetChildArray(PRUint32* aChildCount) const
|
2008-07-11 13:42:19 -07:00
|
|
|
{
|
2008-12-03 06:02:03 -08:00
|
|
|
*aChildCount = 0;
|
2008-07-11 13:42:19 -07:00
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt32
|
|
|
|
nsGenericDOMDataNode::IndexOf(nsINode* aPossibleChild) const
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsGenericDOMDataNode::InsertChildAt(nsIContent* aKid, PRUint32 aIndex,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aNotify)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2011-09-28 23:19:26 -07:00
|
|
|
nsGenericDOMDataNode::RemoveChildAt(PRUint32 aIndex, bool aNotify)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent *
|
|
|
|
nsGenericDOMDataNode::GetBindingParent() const
|
|
|
|
{
|
|
|
|
nsDataSlots *slots = GetExistingDataSlots();
|
|
|
|
return slots ? slots->mBindingParent : nsnull;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsGenericDOMDataNode::IsNodeOfType(PRUint32 aFlags) const
|
|
|
|
{
|
|
|
|
return !(aFlags & ~(eCONTENT | eDATA_NODE));
|
|
|
|
}
|
|
|
|
|
2008-04-10 15:47:01 -07:00
|
|
|
void
|
|
|
|
nsGenericDOMDataNode::SaveSubtreeState()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-11-30 09:57:03 -08:00
|
|
|
void
|
|
|
|
nsGenericDOMDataNode::DestroyContent()
|
|
|
|
{
|
2008-11-13 08:54:52 -08: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 13:20:42 -07:00
|
|
|
nsContentUtils::ReleaseWrapper(this, this);
|
2007-11-30 09:57:03 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
|
|
|
nsGenericDOMDataNode::List(FILE* out, PRInt32 aIndent) const
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGenericDOMDataNode::DumpContent(FILE* out, PRInt32 aIndent,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aDumpAll) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsGenericDOMDataNode::IsLink(nsIURI** aURI) const
|
|
|
|
{
|
|
|
|
*aURI = nsnull;
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsINode::nsSlots*
|
|
|
|
nsGenericDOMDataNode::CreateSlots()
|
|
|
|
{
|
2011-04-07 19:29:49 -07:00
|
|
|
return new nsDataSlots();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Implementation of the nsIDOMText interface
|
|
|
|
|
|
|
|
nsresult
|
2008-07-25 03:37:37 -07:00
|
|
|
nsGenericDOMDataNode::SplitData(PRUint32 aOffset, nsIContent** aReturn,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aCloneAfterOriginal)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-07-25 03:37:37 -07:00
|
|
|
*aReturn = nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsAutoString cutText;
|
|
|
|
PRUint32 length = TextLength();
|
|
|
|
|
|
|
|
if (aOffset > length) {
|
|
|
|
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
|
|
|
}
|
|
|
|
|
2008-07-25 03:37:37 -07:00
|
|
|
PRUint32 cutStartOffset = aCloneAfterOriginal ? aOffset : 0;
|
|
|
|
PRUint32 cutLength = aCloneAfterOriginal ? length - aOffset : aOffset;
|
|
|
|
rv = SubstringData(cutStartOffset, cutLength, cutText);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-02-12 13:21:49 -08:00
|
|
|
nsIDocument* document = GetCurrentDoc();
|
|
|
|
mozAutoDocUpdate updateBatch(document, UPDATE_CONTENT_MODEL, true);
|
|
|
|
|
2011-08-15 17:55:20 -07:00
|
|
|
// Use Clone for creating the new node so that the new node is of same class
|
|
|
|
// as this node!
|
2011-10-17 07:59:28 -07:00
|
|
|
nsCOMPtr<nsIContent> newContent = CloneDataNode(mNodeInfo, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!newContent) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
newContent->SetText(cutText, true); // XXX should be false?
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-08-15 17:55:20 -07:00
|
|
|
CharacterDataChangeInfo::Details details = {
|
|
|
|
CharacterDataChangeInfo::Details::eSplit, newContent
|
|
|
|
};
|
2011-10-17 07:59:28 -07:00
|
|
|
rv = SetTextInternal(cutStartOffset, cutLength, nsnull, 0, true,
|
2011-09-08 14:32:07 -07:00
|
|
|
aCloneAfterOriginal ? &details : nsnull);
|
2011-08-15 17:55:20 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-07-25 03:37:37 -07:00
|
|
|
nsCOMPtr<nsINode> parent = GetNodeParent();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (parent) {
|
2008-07-25 03:37:37 -07:00
|
|
|
PRInt32 insertionIndex = parent->IndexOf(this);
|
|
|
|
if (aCloneAfterOriginal) {
|
|
|
|
++insertionIndex;
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
parent->InsertChildAt(newContent, insertionIndex, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-07-25 03:37:37 -07:00
|
|
|
newContent.swap(*aReturn);
|
|
|
|
return rv;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-07-25 03:37:37 -07:00
|
|
|
nsresult
|
|
|
|
nsGenericDOMDataNode::SplitText(PRUint32 aOffset, nsIDOMText** aReturn)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> newChild;
|
|
|
|
nsresult rv = SplitData(aOffset, getter_AddRefs(newChild));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = CallQueryInterface(newChild, aReturn);
|
|
|
|
}
|
|
|
|
return rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-07-13 12:28:22 -07:00
|
|
|
/* static */ PRInt32
|
2008-06-04 10:53:34 -07:00
|
|
|
nsGenericDOMDataNode::FirstLogicallyAdjacentTextNode(nsIContent* aParent,
|
2008-07-13 12:28:22 -07:00
|
|
|
PRInt32 aIndex)
|
2008-06-04 10:53:34 -07:00
|
|
|
{
|
|
|
|
while (aIndex-- > 0) {
|
|
|
|
nsIContent* sibling = aParent->GetChildAt(aIndex);
|
|
|
|
if (!sibling->IsNodeOfType(nsINode::eTEXT))
|
|
|
|
return aIndex + 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-07-13 12:28:22 -07:00
|
|
|
/* static */ PRInt32
|
2008-06-04 10:53:34 -07:00
|
|
|
nsGenericDOMDataNode::LastLogicallyAdjacentTextNode(nsIContent* aParent,
|
2008-07-13 12:28:22 -07:00
|
|
|
PRInt32 aIndex,
|
2008-06-04 10:53:34 -07:00
|
|
|
PRUint32 aCount)
|
|
|
|
{
|
2008-07-13 12:28:22 -07:00
|
|
|
while (++aIndex < PRInt32(aCount)) {
|
2008-06-04 10:53:34 -07:00
|
|
|
nsIContent* sibling = aParent->GetChildAt(aIndex);
|
|
|
|
if (!sibling->IsNodeOfType(nsINode::eTEXT))
|
|
|
|
return aIndex - 1;
|
|
|
|
}
|
|
|
|
return aCount - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2011-05-20 22:21:28 -07:00
|
|
|
nsGenericDOMDataNode::GetWholeText(nsAString& aWholeText)
|
2008-06-04 10:53:34 -07:00
|
|
|
{
|
|
|
|
nsIContent* parent = GetParent();
|
|
|
|
|
|
|
|
// Handle parent-less nodes
|
|
|
|
if (!parent)
|
|
|
|
return GetData(aWholeText);
|
|
|
|
|
2008-07-13 12:28:22 -07:00
|
|
|
PRInt32 index = parent->IndexOf(this);
|
|
|
|
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);
|
|
|
|
PRInt32 first =
|
2008-06-04 10:53:34 -07:00
|
|
|
FirstLogicallyAdjacentTextNode(parent, index);
|
2008-07-13 12:28:22 -07:00
|
|
|
PRInt32 last =
|
2008-06-04 10:53:34 -07: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Implementation of the nsIContent interface text functions
|
|
|
|
|
|
|
|
const nsTextFragment *
|
|
|
|
nsGenericDOMDataNode::GetText()
|
|
|
|
{
|
|
|
|
return &mText;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32
|
|
|
|
nsGenericDOMDataNode::TextLength()
|
|
|
|
{
|
|
|
|
return mText.GetLength();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsGenericDOMDataNode::SetText(const PRUnichar* aBuffer,
|
|
|
|
PRUint32 aLength,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aNotify)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return SetTextInternal(0, mText.GetLength(), aBuffer, aLength, aNotify);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsGenericDOMDataNode::AppendText(const PRUnichar* aBuffer,
|
|
|
|
PRUint32 aLength,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aNotify)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return SetTextInternal(mText.GetLength(), 0, aBuffer, aLength, aNotify);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsGenericDOMDataNode::TextIsOnlyWhitespace()
|
|
|
|
{
|
|
|
|
if (mText.Is2b()) {
|
|
|
|
// The fragment contains non-8bit characters and such characters
|
|
|
|
// are never considered whitespace.
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* cp = mText.Get1b();
|
|
|
|
const char* end = cp + mText.GetLength();
|
|
|
|
|
|
|
|
while (cp < end) {
|
|
|
|
char ch = *cp;
|
|
|
|
|
|
|
|
if (!XP_IS_SPACE(ch)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
++cp;
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGenericDOMDataNode::AppendTextTo(nsAString& aResult)
|
|
|
|
{
|
|
|
|
mText.AppendTo(aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIAtom>
|
|
|
|
nsGenericDOMDataNode::GetCurrentValueAtom()
|
|
|
|
{
|
|
|
|
nsAutoString val;
|
|
|
|
GetData(val);
|
|
|
|
return NS_NewAtom(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom*
|
2010-06-03 18:09:20 -07:00
|
|
|
nsGenericDOMDataNode::DoGetID() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsAttrValue*
|
2008-09-10 20:22:20 -07:00
|
|
|
nsGenericDOMDataNode::DoGetClasses() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-09-10 20:22:20 -07:00
|
|
|
NS_NOTREACHED("Shouldn't ever be called");
|
2007-03-22 10:30:00 -07:00
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGenericDOMDataNode::WalkContentStyleRules(nsRuleWalker* aRuleWalker)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-03-28 20:32:11 -07:00
|
|
|
nsIDOMCSSStyleDeclaration*
|
|
|
|
nsGenericDOMDataNode::GetSMILOverrideStyle()
|
2009-09-02 17:28:37 -07:00
|
|
|
{
|
2011-03-28 20:32:11 -07:00
|
|
|
return nsnull;
|
2009-09-02 17:28:37 -07:00
|
|
|
}
|
|
|
|
|
2011-03-10 18:48:57 -08:00
|
|
|
css::StyleRule*
|
2009-09-02 17:28:37 -07:00
|
|
|
nsGenericDOMDataNode::GetSMILOverrideStyleRule()
|
|
|
|
{
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2011-03-10 18:48:57 -08:00
|
|
|
nsGenericDOMDataNode::SetSMILOverrideStyleRule(css::StyleRule* aStyleRule,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aNotify)
|
2009-09-02 17:28:37 -07:00
|
|
|
{
|
|
|
|
NS_NOTREACHED("How come we're setting SMILOverrideStyle on a non-element?");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2011-03-10 18:48:57 -08:00
|
|
|
css::StyleRule*
|
2007-03-22 10:30:00 -07:00
|
|
|
nsGenericDOMDataNode::GetInlineStyleRule()
|
|
|
|
{
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-10 18:48:57 -08:00
|
|
|
nsGenericDOMDataNode::SetInlineStyleRule(css::StyleRule* aStyleRule,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aNotify)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_NOTREACHED("How come we're setting inline style on a non-element?");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP_(bool)
|
2007-03-22 10:30:00 -07:00
|
|
|
nsGenericDOMDataNode::IsAttributeMapped(const nsIAtom* aAttribute) const
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsChangeHint
|
|
|
|
nsGenericDOMDataNode::GetAttributeChangeHint(const nsIAtom* aAttribute,
|
|
|
|
PRInt32 aModType) const
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("Shouldn't be calling this!");
|
|
|
|
return nsChangeHint(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom*
|
|
|
|
nsGenericDOMDataNode::GetClassAttributeName() const
|
|
|
|
{
|
|
|
|
return nsnull;
|
|
|
|
}
|
2011-07-19 10:04:09 -07:00
|
|
|
|
2012-03-02 15:32:46 -08:00
|
|
|
PRInt64
|
|
|
|
nsGenericDOMDataNode::SizeOf() const
|
2011-07-19 10:04:09 -07:00
|
|
|
{
|
2012-03-02 15:32:46 -08:00
|
|
|
PRInt64 size = dom::MemoryReporter::GetBasicSize<nsGenericDOMDataNode,
|
|
|
|
nsIContent>(this);
|
|
|
|
size += mText.SizeOf() - sizeof(mText);
|
|
|
|
return size;
|
2011-07-19 10:04:09 -07:00
|
|
|
}
|
|
|
|
|