2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04: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 12:03:04 +04:00
|
|
|
|
|
|
|
/*
|
2018-03-19 22:15:39 +03:00
|
|
|
* Base class for DOM Core's Comment, DocumentType, Text,
|
2018-03-19 22:15:40 +03:00
|
|
|
* CDATASection and ProcessingInstruction nodes.
|
2006-03-30 12:03:04 +04:00
|
|
|
*/
|
|
|
|
|
2018-03-19 22:18:07 +03:00
|
|
|
#include "mozilla/dom/CharacterData.h"
|
|
|
|
|
2012-12-15 03:58:45 +04:00
|
|
|
#include "mozilla/DebugOnly.h"
|
|
|
|
|
2014-03-17 10:56:54 +04:00
|
|
|
#include "mozilla/AsyncEventDispatcher.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2012-11-15 02:10:08 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2017-10-19 09:31:36 +03:00
|
|
|
#include "mozilla/dom/HTMLSlotElement.h"
|
2013-12-02 14:26:11 +04:00
|
|
|
#include "mozilla/dom/ShadowRoot.h"
|
1999-01-21 22:33:03 +03:00
|
|
|
#include "nsIDocument.h"
|
2000-08-23 21:27:06 +04:00
|
|
|
#include "nsReadableUtils.h"
|
2014-02-27 14:51:15 +04:00
|
|
|
#include "mozilla/InternalMutationEvent.h"
|
2003-07-03 06:45:34 +04:00
|
|
|
#include "nsIURI.h"
|
1999-01-22 00:45:17 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2004-04-01 23:44:17 +04:00
|
|
|
#include "nsDOMString.h"
|
2005-11-02 03:41:51 +03:00
|
|
|
#include "nsChangeHint.h"
|
2006-03-22 21:36:36 +03:00
|
|
|
#include "nsCOMArray.h"
|
2006-07-02 11:23:10 +04:00
|
|
|
#include "nsNodeUtils.h"
|
2012-11-21 14:13:57 +04:00
|
|
|
#include "mozilla/dom/DirectionalityUtils.h"
|
2007-02-17 02:02:08 +03:00
|
|
|
#include "nsBindingManager.h"
|
2008-03-28 17:09:00 +03:00
|
|
|
#include "nsCCUncollectableMarker.h"
|
2008-04-11 21:29:06 +04:00
|
|
|
#include "mozAutoDocUpdate.h"
|
2016-04-25 10:15:55 +03:00
|
|
|
#include "nsTextNode.h"
|
2017-08-31 14:54:46 +03:00
|
|
|
#include "nsBidiUtils.h"
|
2015-09-16 06:49:53 +03:00
|
|
|
#include "PLDHashTable.h"
|
2016-08-15 09:43:21 +03:00
|
|
|
#include "mozilla/Sprintf.h"
|
2018-03-28 02:44:49 +03:00
|
|
|
#include "nsWindowSizes.h"
|
2011-05-26 23:58:35 +04:00
|
|
|
#include "nsWrapperCacheInlines.h"
|
2001-12-16 09:59:31 +03:00
|
|
|
|
2018-03-19 22:18:06 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2011-03-11 05:48:57 +03:00
|
|
|
|
2018-03-19 22:18:06 +03:00
|
|
|
CharacterData::CharacterData(already_AddRefed<dom::NodeInfo>& aNodeInfo)
|
2014-03-15 23:00:17 +04:00
|
|
|
: nsIContent(aNodeInfo)
|
|
|
|
{
|
2018-01-30 07:10:53 +03:00
|
|
|
MOZ_ASSERT(mNodeInfo->NodeType() == TEXT_NODE ||
|
|
|
|
mNodeInfo->NodeType() == CDATA_SECTION_NODE ||
|
|
|
|
mNodeInfo->NodeType() == COMMENT_NODE ||
|
|
|
|
mNodeInfo->NodeType() == PROCESSING_INSTRUCTION_NODE ||
|
|
|
|
mNodeInfo->NodeType() == DOCUMENT_TYPE_NODE,
|
2015-02-10 01:34:50 +03:00
|
|
|
"Bad NodeType in aNodeInfo");
|
2014-03-15 23:00:17 +04:00
|
|
|
}
|
|
|
|
|
2018-03-19 22:18:06 +03:00
|
|
|
CharacterData::CharacterData(already_AddRefed<dom::NodeInfo>&& aNodeInfo)
|
2008-02-03 02:41:24 +03:00
|
|
|
: nsIContent(aNodeInfo)
|
1998-09-06 04:16:36 +04:00
|
|
|
{
|
2018-01-30 07:10:53 +03:00
|
|
|
MOZ_ASSERT(mNodeInfo->NodeType() == TEXT_NODE ||
|
|
|
|
mNodeInfo->NodeType() == CDATA_SECTION_NODE ||
|
|
|
|
mNodeInfo->NodeType() == COMMENT_NODE ||
|
|
|
|
mNodeInfo->NodeType() == PROCESSING_INSTRUCTION_NODE ||
|
|
|
|
mNodeInfo->NodeType() == DOCUMENT_TYPE_NODE,
|
2015-02-10 01:34:50 +03:00
|
|
|
"Bad NodeType in aNodeInfo");
|
1998-09-06 04:16:36 +04:00
|
|
|
}
|
|
|
|
|
2018-03-19 22:18:06 +03:00
|
|
|
CharacterData::~CharacterData()
|
1998-09-06 04:16:36 +04:00
|
|
|
{
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(!IsInUncomposedDoc(),
|
|
|
|
"Please remove this from the document properly");
|
2011-07-26 15:11:14 +04:00
|
|
|
if (GetParent()) {
|
|
|
|
NS_RELEASE(mParent);
|
|
|
|
}
|
1998-09-06 04:16:36 +04:00
|
|
|
}
|
|
|
|
|
2018-03-19 22:18:06 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(CharacterData)
|
2013-08-02 05:29:05 +04:00
|
|
|
|
2018-03-19 22:18:06 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(CharacterData)
|
2009-05-13 00:20:42 +04:00
|
|
|
|
2018-03-19 22:18:06 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(CharacterData)
|
2012-11-15 02:10:08 +04:00
|
|
|
return Element::CanSkip(tmp, aRemovingAllowed);
|
2012-01-31 00:08:13 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_END
|
|
|
|
|
2018-03-19 22:18:06 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_BEGIN(CharacterData)
|
2012-11-15 02:10:08 +04:00
|
|
|
return Element::CanSkipInCC(tmp);
|
2012-01-31 00:08:13 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_END
|
|
|
|
|
2018-03-19 22:18:06 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_BEGIN(CharacterData)
|
2012-11-15 02:10:08 +04:00
|
|
|
return Element::CanSkipThis(tmp);
|
2012-01-31 00:08:13 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_END
|
|
|
|
|
2018-03-29 01:07:40 +03:00
|
|
|
// We purposefully don't TRAVERSE_BEGIN_INHERITED here. All the bits
|
|
|
|
// we should traverse should be added here or in nsINode::Traverse.
|
2018-03-19 22:18:06 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(CharacterData)
|
2014-07-18 21:41:34 +04:00
|
|
|
if (MOZ_UNLIKELY(cb.WantDebugInfo())) {
|
|
|
|
char name[40];
|
2018-03-19 22:18:06 +03:00
|
|
|
SprintfLiteral(name, "CharacterData (len=%d)",
|
2016-08-15 09:44:00 +03:00
|
|
|
tmp->mText.GetLength());
|
2014-07-18 21:41:34 +04:00
|
|
|
cb.DescribeRefCountedNode(tmp->mRefCnt.get(), name);
|
|
|
|
} else {
|
2018-03-19 22:18:06 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_DESCRIBE(CharacterData, tmp->mRefCnt.get())
|
2014-07-18 21:41:34 +04:00
|
|
|
}
|
|
|
|
|
2017-12-23 11:23:42 +03:00
|
|
|
if (!nsIContent::Traverse(tmp, cb)) {
|
2009-03-03 15:14:13 +03:00
|
|
|
return NS_SUCCESS_INTERRUPTED_TRAVERSE;
|
2008-03-28 17:09:00 +03:00
|
|
|
}
|
2007-01-05 01:31:26 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2018-03-29 01:07:40 +03:00
|
|
|
// We purposefully don't UNLINK_BEGIN_INHERITED here.
|
2018-03-19 22:18:06 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(CharacterData)
|
2017-12-23 11:23:42 +03:00
|
|
|
nsIContent::Unlink(tmp);
|
2013-07-17 20:05:06 +04:00
|
|
|
|
2015-02-09 21:01:23 +03:00
|
|
|
// Clear flag here because unlinking slots will clear the
|
|
|
|
// containing shadow root pointer.
|
|
|
|
tmp->UnsetFlags(NODE_IS_IN_SHADOW_TREE);
|
|
|
|
|
2017-12-23 11:23:42 +03:00
|
|
|
nsContentSlots* slots = tmp->GetExistingContentSlots();
|
2013-07-17 20:05:06 +04:00
|
|
|
if (slots) {
|
|
|
|
slots->Unlink();
|
|
|
|
}
|
2007-01-05 01:31:26 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2001-12-16 09:59:31 +03:00
|
|
|
|
2018-03-19 22:18:06 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN(CharacterData)
|
|
|
|
NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(CharacterData)
|
2018-03-29 01:07:40 +03:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsIContent)
|
2001-12-16 09:59:31 +03:00
|
|
|
|
2012-10-09 16:31:24 +04:00
|
|
|
void
|
2018-03-19 22:18:06 +03:00
|
|
|
CharacterData::GetNodeValueInternal(nsAString& aNodeValue)
|
2000-04-01 17:31:23 +04:00
|
|
|
{
|
2018-03-19 22:18:07 +03:00
|
|
|
GetData(aNodeValue);
|
2000-04-01 17:31:23 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 16:31:24 +04:00
|
|
|
void
|
2018-03-19 22:18:06 +03:00
|
|
|
CharacterData::SetNodeValueInternal(const nsAString& aNodeValue,
|
2012-10-09 16:31:24 +04:00
|
|
|
ErrorResult& aError)
|
2000-04-01 17:31:23 +04:00
|
|
|
{
|
2012-10-09 16:31:24 +04:00
|
|
|
aError = SetTextInternal(0, mText.GetLength(), aNodeValue.BeginReading(),
|
|
|
|
aNodeValue.Length(), true);
|
2000-04-01 17:31:23 +04:00
|
|
|
}
|
|
|
|
|
1998-09-06 04:16:36 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2018-03-19 22:47:42 +03:00
|
|
|
// Implementation of CharacterData
|
1998-09-06 04:16:36 +04:00
|
|
|
|
2018-03-19 22:18:07 +03:00
|
|
|
void
|
2018-03-19 22:18:06 +03:00
|
|
|
CharacterData::GetData(nsAString& aData) const
|
1998-09-06 04:16:36 +04:00
|
|
|
{
|
1998-10-20 04:20:04 +04:00
|
|
|
if (mText.Is2b()) {
|
2017-08-31 14:48:07 +03:00
|
|
|
aData.Truncate();
|
|
|
|
mText.AppendTo(aData);
|
2001-12-16 09:59:31 +03:00
|
|
|
} else {
|
|
|
|
// Must use Substring() since nsDependentCString() requires null
|
|
|
|
// terminated strings.
|
|
|
|
|
|
|
|
const char *data = mText.Get1b();
|
2002-05-10 22:21:50 +04:00
|
|
|
|
|
|
|
if (data) {
|
2006-02-03 17:18:39 +03:00
|
|
|
CopyASCIItoUTF16(Substring(data, data + mText.GetLength()), aData);
|
2002-05-10 22:21:50 +04:00
|
|
|
} else {
|
|
|
|
aData.Truncate();
|
|
|
|
}
|
1998-10-20 04:20:04 +04:00
|
|
|
}
|
1998-09-06 04:16:36 +04:00
|
|
|
}
|
|
|
|
|
2018-03-19 22:18:07 +03:00
|
|
|
void
|
|
|
|
CharacterData::SetData(const nsAString& aData, ErrorResult& aRv)
|
1998-09-06 04:16:36 +04:00
|
|
|
{
|
2018-03-19 22:18:07 +03:00
|
|
|
nsresult rv = SetTextInternal(0, mText.GetLength(), aData.BeginReading(),
|
|
|
|
aData.Length(), true);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
}
|
1998-09-06 04:16:36 +04:00
|
|
|
}
|
|
|
|
|
2013-01-04 21:02:14 +04:00
|
|
|
void
|
2018-03-19 22:18:06 +03:00
|
|
|
CharacterData::SubstringData(uint32_t aStart, uint32_t aCount,
|
|
|
|
nsAString& aReturn, ErrorResult& rv)
|
1998-09-06 04:16:36 +04:00
|
|
|
{
|
|
|
|
aReturn.Truncate();
|
1998-10-20 04:20:04 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t textLength = mText.GetLength();
|
1999-10-16 02:18:23 +04:00
|
|
|
if (aStart > textLength) {
|
2013-01-04 21:02:14 +04:00
|
|
|
rv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return;
|
1998-09-06 04:16:36 +04:00
|
|
|
}
|
1998-10-20 04:20:04 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t amount = aCount;
|
2001-11-16 06:01:29 +03:00
|
|
|
if (amount > textLength - aStart) {
|
1998-10-20 04:20:04 +04:00
|
|
|
amount = textLength - aStart;
|
|
|
|
}
|
2001-11-16 06:01:29 +03:00
|
|
|
|
1998-10-20 04:20:04 +04:00
|
|
|
if (mText.Is2b()) {
|
2000-03-12 12:14:14 +03:00
|
|
|
aReturn.Assign(mText.Get2b() + aStart, amount);
|
2001-12-16 09:59:31 +03:00
|
|
|
} else {
|
|
|
|
// Must use Substring() since nsDependentCString() requires null
|
|
|
|
// terminated strings.
|
|
|
|
|
|
|
|
const char *data = mText.Get1b() + aStart;
|
2006-02-03 17:18:39 +03:00
|
|
|
CopyASCIItoUTF16(Substring(data, data + amount), aReturn);
|
1998-10-20 04:20:04 +04:00
|
|
|
}
|
1998-09-06 04:16:36 +04:00
|
|
|
}
|
|
|
|
|
1999-10-22 00:40:51 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2018-03-19 22:33:25 +03:00
|
|
|
void
|
|
|
|
CharacterData::AppendData(const nsAString& aData, ErrorResult& aRv)
|
1998-09-06 04:16:36 +04:00
|
|
|
{
|
2018-03-19 23:10:06 +03:00
|
|
|
InsertData(mText.GetLength(), aData, aRv);
|
1998-09-06 04:16:36 +04:00
|
|
|
}
|
|
|
|
|
2018-03-19 22:38:04 +03:00
|
|
|
void
|
2018-03-19 22:18:06 +03:00
|
|
|
CharacterData::InsertData(uint32_t aOffset,
|
2018-03-19 22:38:04 +03:00
|
|
|
const nsAString& aData,
|
|
|
|
ErrorResult& aRv)
|
1998-09-06 04:16:36 +04:00
|
|
|
{
|
2018-03-19 22:38:04 +03:00
|
|
|
nsresult rv = SetTextInternal(aOffset, 0, aData.BeginReading(),
|
|
|
|
aData.Length(), true);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
}
|
1998-09-06 04:16:36 +04:00
|
|
|
}
|
|
|
|
|
2018-03-19 22:45:31 +03:00
|
|
|
void
|
|
|
|
CharacterData::DeleteData(uint32_t aOffset, uint32_t aCount, ErrorResult& aRv)
|
1998-09-06 04:16:36 +04:00
|
|
|
{
|
2018-03-19 22:45:31 +03:00
|
|
|
nsresult rv = SetTextInternal(aOffset, aCount, nullptr, 0, true);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
}
|
1998-09-06 04:16:36 +04:00
|
|
|
}
|
|
|
|
|
2018-03-19 22:45:34 +03:00
|
|
|
void
|
2018-03-19 22:18:06 +03:00
|
|
|
CharacterData::ReplaceData(uint32_t aOffset, uint32_t aCount,
|
2018-03-19 22:45:34 +03:00
|
|
|
const nsAString& aData, ErrorResult& aRv)
|
1998-09-06 04:16:36 +04:00
|
|
|
{
|
2018-03-19 22:45:34 +03:00
|
|
|
nsresult rv = SetTextInternal(aOffset, aCount, aData.BeginReading(),
|
|
|
|
aData.Length(), true);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
}
|
2006-10-28 05:22:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2018-03-19 22:18:06 +03:00
|
|
|
CharacterData::SetTextInternal(uint32_t aOffset, uint32_t aCount,
|
|
|
|
const char16_t* aBuffer,
|
|
|
|
uint32_t aLength, bool aNotify,
|
|
|
|
CharacterDataChangeInfo::Details* aDetails)
|
2006-10-28 05:22:53 +04:00
|
|
|
{
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(aBuffer || !aLength,
|
|
|
|
"Null buffer passed to SetTextInternal!");
|
2006-10-28 05:22:53 +04:00
|
|
|
|
1998-09-06 04:16:36 +04:00
|
|
|
// sanitize arguments
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t textLength = mText.GetLength();
|
2001-03-27 19:40:15 +04:00
|
|
|
if (aOffset > textLength) {
|
1999-11-11 04:48:25 +03:00
|
|
|
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
1998-09-06 04:16:36 +04:00
|
|
|
}
|
|
|
|
|
2010-04-10 02:55:11 +04:00
|
|
|
if (aCount > textLength - aOffset) {
|
|
|
|
aCount = textLength - aOffset;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t endOffset = aOffset + aCount;
|
2010-04-10 02:55:11 +04:00
|
|
|
|
|
|
|
// Make sure the text fragment can hold the new data.
|
|
|
|
if (aLength > aCount && !mText.CanGrowBy(aLength - aCount)) {
|
2012-04-12 01:55:21 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2010-04-10 02:55:11 +04:00
|
|
|
}
|
|
|
|
|
2014-10-02 22:45:44 +04:00
|
|
|
nsIDocument *document = GetComposedDoc();
|
2018-05-15 16:56:38 +03:00
|
|
|
mozAutoDocUpdate updateBatch(document, aNotify);
|
2005-07-20 00:52:12 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool haveMutationListeners = aNotify &&
|
2006-10-28 05:22:53 +04:00
|
|
|
nsContentUtils::HasMutationListeners(this,
|
2007-07-05 00:39:10 +04:00
|
|
|
NS_EVENT_BITS_MUTATION_CHARACTERDATAMODIFIED,
|
|
|
|
this);
|
2006-10-28 05:22:53 +04:00
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
RefPtr<nsAtom> oldValue;
|
2006-10-28 05:22:53 +04:00
|
|
|
if (haveMutationListeners) {
|
|
|
|
oldValue = GetCurrentValueAtom();
|
|
|
|
}
|
2016-07-08 10:07:06 +03:00
|
|
|
|
2007-09-05 12:22:17 +04:00
|
|
|
if (aNotify) {
|
|
|
|
CharacterDataChangeInfo info = {
|
|
|
|
aOffset == textLength,
|
|
|
|
aOffset,
|
|
|
|
endOffset,
|
2011-08-16 04:55:20 +04:00
|
|
|
aLength,
|
|
|
|
aDetails
|
2007-09-05 12:22:17 +04:00
|
|
|
};
|
2018-02-27 17:30:27 +03:00
|
|
|
nsNodeUtils::CharacterDataWillChange(this, info);
|
2007-09-05 12:22:17 +04:00
|
|
|
}
|
|
|
|
|
2014-08-06 13:02:59 +04:00
|
|
|
Directionality oldDir = eDir_NotSet;
|
2018-01-30 07:10:53 +03:00
|
|
|
bool dirAffectsAncestor = (NodeType() == TEXT_NODE &&
|
2014-08-06 13:02:59 +04:00
|
|
|
TextNodeWillChangeDirection(this, &oldDir, aOffset));
|
2012-11-21 14:13:57 +04:00
|
|
|
|
2006-10-28 05:22:53 +04:00
|
|
|
if (aOffset == 0 && endOffset == textLength) {
|
2011-09-09 20:27:00 +04: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.
|
2017-08-18 10:05:16 +03:00
|
|
|
// If this is marked as "maybe modified frequently", the text should be
|
|
|
|
// stored as char16_t since converting char* to char16_t* is expensive.
|
|
|
|
bool ok =
|
|
|
|
mText.SetTo(aBuffer, aLength, !document || !document->GetBidiEnabled(),
|
|
|
|
HasFlag(NS_MAYBE_MODIFIED_FREQUENTLY));
|
2013-12-19 18:09:00 +04:00
|
|
|
NS_ENSURE_TRUE(ok, NS_ERROR_OUT_OF_MEMORY);
|
2006-10-28 05:22:53 +04:00
|
|
|
}
|
|
|
|
else if (aOffset == textLength) {
|
|
|
|
// Appending to existing
|
2017-08-18 10:05:16 +03:00
|
|
|
bool ok =
|
|
|
|
mText.Append(aBuffer, aLength, !document || !document->GetBidiEnabled(),
|
|
|
|
HasFlag(NS_MAYBE_MODIFIED_FREQUENTLY));
|
2013-12-19 18:09:00 +04:00
|
|
|
NS_ENSURE_TRUE(ok, NS_ERROR_OUT_OF_MEMORY);
|
1998-09-06 04:16:36 +04:00
|
|
|
}
|
2006-10-28 05:22:53 +04:00
|
|
|
else {
|
|
|
|
// Merging old and new
|
|
|
|
|
2017-08-31 14:54:46 +03:00
|
|
|
bool bidi = mText.IsBidi();
|
|
|
|
|
2006-10-28 05:22:53 +04:00
|
|
|
// Allocate new buffer
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t newLength = textLength - aCount + aLength;
|
2017-08-31 14:54:46 +03:00
|
|
|
// Use nsString and not nsAutoString so that we get a nsStringBuffer which
|
|
|
|
// can be just AddRefed in nsTextFragment.
|
|
|
|
nsString to;
|
|
|
|
to.SetCapacity(newLength);
|
2006-10-28 05:22:53 +04:00
|
|
|
|
|
|
|
// Copy over appropriate data
|
2010-04-10 02:55:11 +04:00
|
|
|
if (aOffset) {
|
2017-08-31 14:54:46 +03:00
|
|
|
mText.AppendTo(to, 0, aOffset);
|
2006-10-28 05:22:53 +04:00
|
|
|
}
|
2010-04-10 02:55:11 +04:00
|
|
|
if (aLength) {
|
2017-08-31 14:54:46 +03:00
|
|
|
to.Append(aBuffer, aLength);
|
|
|
|
if (!bidi && (!document || !document->GetBidiEnabled())) {
|
2018-01-18 15:28:15 +03:00
|
|
|
bidi = HasRTLChars(MakeSpan(aBuffer, aLength));
|
2017-08-31 14:54:46 +03:00
|
|
|
}
|
2006-10-28 05:22:53 +04:00
|
|
|
}
|
|
|
|
if (endOffset != textLength) {
|
2017-08-31 14:54:46 +03:00
|
|
|
mText.AppendTo(to, endOffset, textLength - endOffset);
|
2006-10-28 05:22:53 +04:00
|
|
|
}
|
|
|
|
|
2017-08-18 10:05:16 +03:00
|
|
|
// If this is marked as "maybe modified frequently", the text should be
|
|
|
|
// stored as char16_t since converting char* to char16_t* is expensive.
|
2017-08-31 14:54:46 +03:00
|
|
|
// Use char16_t also when we have bidi characters.
|
|
|
|
bool use2b = HasFlag(NS_MAYBE_MODIFIED_FREQUENTLY) || bidi;
|
|
|
|
bool ok = mText.SetTo(to, false, use2b);
|
|
|
|
mText.SetBidi(bidi);
|
2013-12-19 18:09:00 +04:00
|
|
|
|
|
|
|
NS_ENSURE_TRUE(ok, NS_ERROR_OUT_OF_MEMORY);
|
2006-10-28 05:22:53 +04:00
|
|
|
}
|
|
|
|
|
2013-07-18 07:23:52 +04:00
|
|
|
UnsetFlags(NS_CACHED_TEXT_IS_ONLY_WHITESPACE);
|
|
|
|
|
2011-09-09 20:27:00 +04: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 04:16:36 +04:00
|
|
|
|
2014-08-06 13:02:59 +04:00
|
|
|
if (dirAffectsAncestor) {
|
2016-03-19 00:21:50 +03:00
|
|
|
// dirAffectsAncestor being true implies that we have a text node, see
|
|
|
|
// above.
|
2018-01-30 07:10:53 +03:00
|
|
|
MOZ_ASSERT(NodeType() == TEXT_NODE);
|
2016-03-19 00:21:50 +03:00
|
|
|
TextNodeChangedDirection(static_cast<nsTextNode*>(this), oldDir, aNotify);
|
2014-08-06 13:02:59 +04:00
|
|
|
}
|
|
|
|
|
2006-10-28 05:22:53 +04:00
|
|
|
// Notify observers
|
|
|
|
if (aNotify) {
|
2007-09-11 03:46:22 +04:00
|
|
|
CharacterDataChangeInfo info = {
|
|
|
|
aOffset == textLength,
|
|
|
|
aOffset,
|
|
|
|
endOffset,
|
2011-08-16 04:55:20 +04:00
|
|
|
aLength,
|
|
|
|
aDetails
|
2007-09-11 03:46:22 +04:00
|
|
|
};
|
2018-02-27 17:30:27 +03:00
|
|
|
nsNodeUtils::CharacterDataChanged(this, info);
|
2007-09-11 03:46:22 +04:00
|
|
|
|
2006-10-28 05:22:53 +04:00
|
|
|
if (haveMutationListeners) {
|
2015-09-07 17:55:50 +03:00
|
|
|
InternalMutationEvent mutation(true, eLegacyCharacterDataModified);
|
2008-04-18 21:20:11 +04:00
|
|
|
|
|
|
|
mutation.mPrevAttrValue = oldValue;
|
|
|
|
if (aLength > 0) {
|
|
|
|
nsAutoString val;
|
|
|
|
mText.AppendTo(val);
|
2016-03-29 02:09:43 +03:00
|
|
|
mutation.mNewAttrValue = NS_Atomize(val);
|
2008-04-15 03:59:21 +04:00
|
|
|
}
|
2008-04-18 21:20:11 +04:00
|
|
|
|
2011-10-18 14:53:36 +04:00
|
|
|
mozAutoSubtreeModified subtree(OwnerDoc(), this);
|
2014-03-17 10:56:54 +04:00
|
|
|
(new AsyncEventDispatcher(this, mutation))->RunDOMEventWhenSafe();
|
2006-10-28 05:22:53 +04:00
|
|
|
}
|
|
|
|
}
|
1998-09-06 04:16:36 +04:00
|
|
|
|
2004-05-08 00:55:17 +04:00
|
|
|
return NS_OK;
|
1998-09-06 04:16:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Implementation of nsIContent
|
|
|
|
|
2001-12-16 09:59:31 +03:00
|
|
|
#ifdef DEBUG
|
1998-09-06 04:16:36 +04:00
|
|
|
void
|
2018-03-19 22:18:06 +03:00
|
|
|
CharacterData::ToCString(nsAString& aBuf, int32_t aOffset,
|
|
|
|
int32_t aLen) const
|
1998-09-06 04:16:36 +04:00
|
|
|
{
|
1998-10-20 04:20:04 +04:00
|
|
|
if (mText.Is2b()) {
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* cp = mText.Get2b() + aOffset;
|
|
|
|
const char16_t* end = cp + aLen;
|
2001-12-16 09:59:31 +03:00
|
|
|
|
1998-10-20 04:20:04 +04:00
|
|
|
while (cp < end) {
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t ch = *cp++;
|
2006-05-07 16:15:36 +04:00
|
|
|
if (ch == '&') {
|
2006-05-07 05:39:21 +04:00
|
|
|
aBuf.AppendLiteral("&");
|
|
|
|
} else if (ch == '<') {
|
|
|
|
aBuf.AppendLiteral("<");
|
|
|
|
} else if (ch == '>') {
|
|
|
|
aBuf.AppendLiteral(">");
|
1998-10-20 04:20:04 +04:00
|
|
|
} else if ((ch < ' ') || (ch >= 127)) {
|
2018-03-24 22:00:38 +03:00
|
|
|
aBuf.AppendPrintf("\\u%04x", ch);
|
1998-10-20 04:20:04 +04:00
|
|
|
} else {
|
|
|
|
aBuf.Append(ch);
|
|
|
|
}
|
|
|
|
}
|
2001-12-16 09:59:31 +03:00
|
|
|
} else {
|
1998-10-20 04:20:04 +04:00
|
|
|
unsigned char* cp = (unsigned char*)mText.Get1b() + aOffset;
|
|
|
|
const unsigned char* end = cp + aLen;
|
2001-12-16 09:59:31 +03:00
|
|
|
|
1998-10-20 04:20:04 +04:00
|
|
|
while (cp < end) {
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t ch = *cp++;
|
2006-05-07 16:15:36 +04:00
|
|
|
if (ch == '&') {
|
2006-05-07 05:39:21 +04:00
|
|
|
aBuf.AppendLiteral("&");
|
|
|
|
} else if (ch == '<') {
|
|
|
|
aBuf.AppendLiteral("<");
|
|
|
|
} else if (ch == '>') {
|
|
|
|
aBuf.AppendLiteral(">");
|
1998-10-20 04:20:04 +04:00
|
|
|
} else if ((ch < ' ') || (ch >= 127)) {
|
2018-03-24 22:00:38 +03:00
|
|
|
aBuf.AppendPrintf("\\u%04x", ch);
|
1998-10-20 04:20:04 +04:00
|
|
|
} else {
|
|
|
|
aBuf.Append(ch);
|
|
|
|
}
|
1998-09-06 04:16:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-12-16 09:59:31 +03:00
|
|
|
#endif
|
1998-09-06 04:16:36 +04:00
|
|
|
|
2005-12-03 10:42:40 +03:00
|
|
|
|
2005-04-06 03:54:35 +04:00
|
|
|
nsresult
|
2018-07-01 18:17:40 +03:00
|
|
|
CharacterData::BindToTree(nsIDocument* aDocument,
|
|
|
|
nsIContent* aParent,
|
2018-07-31 21:18:38 +03:00
|
|
|
nsIContent* aBindingParent)
|
2005-04-06 03:54:35 +04:00
|
|
|
{
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(aParent || aDocument, "Must have document if no parent!");
|
|
|
|
MOZ_ASSERT(NODE_FROM(aParent, aDocument)->OwnerDoc() == OwnerDoc(),
|
|
|
|
"Must have the same owner document");
|
|
|
|
MOZ_ASSERT(!aParent || aDocument == aParent->GetUncomposedDoc(),
|
|
|
|
"aDocument must be current doc of aParent");
|
|
|
|
MOZ_ASSERT(!GetUncomposedDoc() && !IsInUncomposedDoc(),
|
|
|
|
"Already have a document. Unbind first!");
|
2018-08-20 14:56:27 +03:00
|
|
|
MOZ_ASSERT(!IsInComposedDoc(),
|
|
|
|
"Already have a document. Unbind first!");
|
2005-04-06 03:54:35 +04: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.
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(!GetParent() || aParent == GetParent(),
|
|
|
|
"Already have a parent. Unbind first!");
|
|
|
|
MOZ_ASSERT(!GetBindingParent() ||
|
|
|
|
aBindingParent == GetBindingParent() ||
|
|
|
|
(!aBindingParent && aParent &&
|
|
|
|
aParent->GetBindingParent() == GetBindingParent()),
|
|
|
|
"Already have a binding parent. Unbind first!");
|
|
|
|
MOZ_ASSERT(aBindingParent != this,
|
|
|
|
"Content must not be its own binding parent");
|
|
|
|
MOZ_ASSERT(!IsRootOfNativeAnonymousSubtree() ||
|
|
|
|
aBindingParent == aParent,
|
|
|
|
"Native anonymous content must have its parent as its "
|
|
|
|
"own binding parent");
|
2006-05-17 20:14:33 +04:00
|
|
|
|
|
|
|
if (!aBindingParent && aParent) {
|
|
|
|
aBindingParent = aParent->GetBindingParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
// First set the binding parent
|
|
|
|
if (aBindingParent) {
|
2008-07-23 08:50:20 +04:00
|
|
|
NS_ASSERTION(IsRootOfNativeAnonymousSubtree() ||
|
2014-04-06 23:32:38 +04:00
|
|
|
!HasFlag(NODE_IS_IN_NATIVE_ANONYMOUS_SUBTREE) ||
|
2008-12-03 13:18:57 +03:00
|
|
|
(aParent && aParent->IsInNativeAnonymousSubtree()),
|
2008-09-05 08:37:48 +04:00
|
|
|
"Trying to re-bind content from native anonymous subtree to "
|
2008-04-12 02:44:48 +04:00
|
|
|
"non-native anonymous parent!");
|
2017-12-23 11:23:42 +03:00
|
|
|
ExtendedContentSlots()->mBindingParent = aBindingParent; // Weak, so no addref happens.
|
2009-02-24 21:39:09 +03:00
|
|
|
if (aParent->IsInNativeAnonymousSubtree()) {
|
2014-04-06 23:32:38 +04:00
|
|
|
SetFlags(NODE_IS_IN_NATIVE_ANONYMOUS_SUBTREE);
|
2008-04-12 02:44:48 +04:00
|
|
|
}
|
2012-10-10 23:04:42 +04:00
|
|
|
if (aParent->HasFlag(NODE_CHROME_ONLY_ACCESS)) {
|
|
|
|
SetFlags(NODE_CHROME_ONLY_ACCESS);
|
|
|
|
}
|
2017-06-28 09:56:12 +03:00
|
|
|
if (HasFlag(NODE_IS_ANONYMOUS_ROOT)) {
|
|
|
|
aParent->SetMayHaveAnonymousChildren();
|
|
|
|
}
|
2018-08-20 14:56:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aParent && aParent->IsInShadowTree()) {
|
|
|
|
ClearSubtreeRootPointer();
|
|
|
|
SetFlags(NODE_IS_IN_SHADOW_TREE);
|
|
|
|
SetIsConnected(aParent->IsInComposedDoc());
|
|
|
|
MOZ_ASSERT(aParent->GetContainingShadow());
|
|
|
|
ExtendedContentSlots()->mContainingShadow = aParent->GetContainingShadow();
|
2006-05-17 20:14:33 +04:00
|
|
|
}
|
2005-09-24 22:43:15 +04:00
|
|
|
|
2015-09-24 18:23:32 +03:00
|
|
|
bool hadParent = !!GetParentNode();
|
|
|
|
|
2005-04-06 03:54:35 +04:00
|
|
|
// Set parent
|
2006-04-15 09:09:16 +04:00
|
|
|
if (aParent) {
|
2011-07-26 15:11:14 +04:00
|
|
|
if (!GetParent()) {
|
|
|
|
NS_ADDREF(aParent);
|
|
|
|
}
|
2011-04-08 06:29:49 +04:00
|
|
|
mParent = aParent;
|
2018-08-20 14:56:27 +03:00
|
|
|
} else {
|
2011-04-08 06:29:49 +04:00
|
|
|
mParent = aDocument;
|
2006-04-15 09:09:16 +04:00
|
|
|
}
|
2011-04-08 06:29:49 +04:00
|
|
|
SetParentIsContent(aParent);
|
2005-04-06 03:54:35 +04:00
|
|
|
|
2006-04-11 07:49:44 +04:00
|
|
|
// XXXbz sXBL/XBL2 issue!
|
|
|
|
|
2005-04-06 03:54:35 +04:00
|
|
|
// Set document
|
2005-09-24 22:43:15 +04:00
|
|
|
if (aDocument) {
|
2012-03-15 00:14:02 +04:00
|
|
|
// We no longer need to track the subtree pointer (and in fact we'll assert
|
|
|
|
// if we do this any later).
|
|
|
|
ClearSubtreeRootPointer();
|
|
|
|
|
2012-11-15 02:10:08 +04:00
|
|
|
// XXX See the comment in Element::BindToTree
|
2016-07-08 10:07:06 +03:00
|
|
|
SetIsInDocument();
|
2018-08-20 14:56:27 +03:00
|
|
|
SetIsConnected(true);
|
2005-09-24 22:43:15 +04:00
|
|
|
if (mText.IsBidi()) {
|
2008-06-16 13:28:17 +04:00
|
|
|
aDocument->SetBidiEnabled();
|
2005-09-24 22:43:15 +04:00
|
|
|
}
|
2010-01-18 12:26:40 +03:00
|
|
|
// Clear the lazy frame construction bits.
|
|
|
|
UnsetFlags(NODE_NEEDS_FRAME | NODE_DESCENDANTS_NEED_FRAMES);
|
2014-07-03 21:02:07 +04:00
|
|
|
} else if (!IsInShadowTree()) {
|
2014-06-07 12:42:53 +04:00
|
|
|
// If we're not in the doc and not in a shadow tree,
|
|
|
|
// update our subtree pointer.
|
2012-03-15 00:14:02 +04:00
|
|
|
SetSubtreeRootPointer(aParent->SubtreeRoot());
|
2006-06-02 17:28:14 +04:00
|
|
|
}
|
|
|
|
|
2007-03-10 16:49:43 +03:00
|
|
|
nsNodeUtils::ParentChainChanged(this);
|
2015-09-24 18:23:32 +03:00
|
|
|
if (!hadParent && IsRootOfNativeAnonymousSubtree()) {
|
|
|
|
nsNodeUtils::NativeAnonymousChildListChange(this, false);
|
|
|
|
}
|
2007-03-10 16:49:43 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
UpdateEditableState(false);
|
2007-06-28 06:48:16 +04:00
|
|
|
|
2017-11-05 08:48:48 +03:00
|
|
|
MOZ_ASSERT(aDocument == GetUncomposedDoc(), "Bound to wrong document");
|
|
|
|
MOZ_ASSERT(aParent == GetParent(), "Bound to wrong parent");
|
|
|
|
MOZ_ASSERT(aBindingParent == GetBindingParent(),
|
|
|
|
"Bound to wrong binding parent");
|
2005-04-06 03:54:35 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
1998-09-06 04:16:36 +04:00
|
|
|
}
|
|
|
|
|
2004-01-10 02:54:21 +03:00
|
|
|
void
|
2018-03-19 22:18:06 +03:00
|
|
|
CharacterData::UnbindFromTree(bool aDeep, bool aNullParent)
|
1998-09-06 04:16:36 +04:00
|
|
|
{
|
2009-06-29 02:48:24 +04:00
|
|
|
// Unset frame flags; if we need them again later, they'll get set again.
|
2018-08-20 14:56:27 +03:00
|
|
|
UnsetFlags(NS_CREATE_FRAME_IF_NON_WHITESPACE | NS_REFRAME_IF_WHITESPACE);
|
2014-10-02 22:45:44 +04:00
|
|
|
|
2018-03-12 23:24:10 +03:00
|
|
|
nsIDocument* document = GetComposedDoc();
|
2006-05-17 20:14:33 +04:00
|
|
|
|
2011-04-08 06:29:49 +04:00
|
|
|
if (aNullParent) {
|
2015-09-24 18:23:32 +03:00
|
|
|
if (this->IsRootOfNativeAnonymousSubtree()) {
|
|
|
|
nsNodeUtils::NativeAnonymousChildListChange(this, true);
|
|
|
|
}
|
2011-07-26 15:11:14 +04:00
|
|
|
if (GetParent()) {
|
|
|
|
NS_RELEASE(mParent);
|
|
|
|
} else {
|
2012-07-30 18:20:58 +04:00
|
|
|
mParent = nullptr;
|
2011-07-26 15:11:14 +04:00
|
|
|
}
|
2011-04-08 06:29:49 +04:00
|
|
|
SetParentIsContent(false);
|
|
|
|
}
|
|
|
|
ClearInDocument();
|
2018-08-20 14:56:27 +03:00
|
|
|
SetIsConnected(false);
|
2006-05-17 20:14:33 +04:00
|
|
|
|
2014-09-27 02:07:40 +04:00
|
|
|
if (aNullParent || !mParent->IsInShadowTree()) {
|
|
|
|
UnsetFlags(NODE_IS_IN_SHADOW_TREE);
|
|
|
|
|
|
|
|
// Begin keeping track of our subtree root.
|
|
|
|
SetSubtreeRootPointer(aNullParent ? this : mParent->SubtreeRoot());
|
|
|
|
}
|
2012-03-15 00:14:02 +04:00
|
|
|
|
2014-10-04 05:32:05 +04:00
|
|
|
if (document && !GetContainingShadow()) {
|
2014-10-02 22:45:44 +04:00
|
|
|
// Notify XBL- & nsIAnonymousContentCreator-generated
|
|
|
|
// anonymous content that the document is changing.
|
2014-10-04 05:32:05 +04:00
|
|
|
// Unlike XBL, bindings for web components shadow DOM
|
|
|
|
// do not get uninstalled.
|
2014-10-02 22:45:44 +04:00
|
|
|
if (HasFlag(NODE_MAY_BE_IN_BINDING_MNGR)) {
|
|
|
|
nsContentUtils::AddScriptRunner(
|
|
|
|
new RemoveFromBindingManagerRunnable(document->BindingManager(), this,
|
|
|
|
document));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-23 11:23:42 +03:00
|
|
|
nsExtendedContentSlots* slots = GetExistingExtendedContentSlots();
|
2006-05-17 20:14:33 +04:00
|
|
|
if (slots) {
|
2012-07-30 18:20:58 +04:00
|
|
|
slots->mBindingParent = nullptr;
|
2014-09-27 02:07:40 +04:00
|
|
|
if (aNullParent || !mParent->IsInShadowTree()) {
|
|
|
|
slots->mContainingShadow = nullptr;
|
|
|
|
}
|
2006-05-17 20:14:33 +04:00
|
|
|
}
|
2007-03-10 16:49:43 +03:00
|
|
|
|
|
|
|
nsNodeUtils::ParentChainChanged(this);
|
2001-12-16 09:59:31 +03:00
|
|
|
}
|
|
|
|
|
1999-04-01 00:49:25 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2006-07-19 08:36:36 +04:00
|
|
|
// Implementation of the nsIContent interface text functions
|
1999-04-01 00:49:25 +04:00
|
|
|
|
2006-07-19 08:36:36 +04:00
|
|
|
nsresult
|
2018-03-19 22:18:06 +03:00
|
|
|
CharacterData::SetText(const char16_t* aBuffer,
|
|
|
|
uint32_t aLength,
|
|
|
|
bool aNotify)
|
1999-04-01 00:49:25 +04:00
|
|
|
{
|
2006-10-28 05:22:53 +04:00
|
|
|
return SetTextInternal(0, mText.GetLength(), aBuffer, aLength, aNotify);
|
|
|
|
}
|
2006-07-19 08:36:36 +04:00
|
|
|
|
2006-10-28 05:22:53 +04:00
|
|
|
nsresult
|
2018-03-19 22:18:06 +03:00
|
|
|
CharacterData::AppendText(const char16_t* aBuffer,
|
|
|
|
uint32_t aLength,
|
|
|
|
bool aNotify)
|
2006-10-28 05:22:53 +04:00
|
|
|
{
|
|
|
|
return SetTextInternal(mText.GetLength(), 0, aBuffer, aLength, aNotify);
|
1999-04-01 00:49:25 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2018-03-19 22:18:06 +03:00
|
|
|
CharacterData::TextIsOnlyWhitespace()
|
2017-03-17 00:10:22 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
if (!ThreadSafeTextIsOnlyWhitespace()) {
|
|
|
|
UnsetFlags(NS_TEXT_IS_ONLY_WHITESPACE);
|
|
|
|
SetFlags(NS_CACHED_TEXT_IS_ONLY_WHITESPACE);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetFlags(NS_CACHED_TEXT_IS_ONLY_WHITESPACE | NS_TEXT_IS_ONLY_WHITESPACE);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2018-03-19 22:18:06 +03:00
|
|
|
CharacterData::ThreadSafeTextIsOnlyWhitespace() const
|
1999-04-01 00:49:25 +04:00
|
|
|
{
|
2012-11-30 20:04:11 +04:00
|
|
|
// FIXME: should this method take content language into account?
|
2006-03-24 06:29:52 +03:00
|
|
|
if (mText.Is2b()) {
|
|
|
|
// The fragment contains non-8bit characters and such characters
|
|
|
|
// are never considered whitespace.
|
Bug 1427625: Optimize appends to avoid restyling unnecessarily. r=xidorn
This unfortunately doesn't fix my test-case (because we're replacing the text
content all the time and all that), but it's still worth it, since it fixes the
case we care about (the parser appending).
We could also optimize pure insertions (since in that case we can still figure
out what the old text was), but it's probably annoying and not worth the churn.
In any case, we cannot optimize anything that resembles any kind of removal,
because from there we don't know the old text in any way (and the text nodes
like to reuse string buffers and such).
We could do two other optimizations to replace / extend this one, in that order:
* Pass the buffer and length to CharacterDataWillChange, and use that to get
the exact old text and the new one in RestyleManager. That would make the
optimization exact.
* Pass some sort of Maybe<bool> mWasWhitespace down the CharacterDataChangeInfo
which is computed like:
HasFlag(NS_CACHED_TEXT_IS_ONLY_WHITESPACE)
? Some(NS_TEXT_IS_ONLY_WHITESPACE)
: Nothing()
It's not clear to me it's going to be completely worth the churn, so I haven't
done those yet, if we see code in the wild which resembles my testcase, we can
think of doing it.
MozReview-Commit-ID: 2rTWaZti8rv
--HG--
extra : rebase_source : 7390b8740801eb7b91700bb2533c43c173ac5db9
2018-02-27 19:02:52 +03:00
|
|
|
//
|
|
|
|
// FIXME(emilio): This is not quite true in presence of the
|
|
|
|
// NS_MAYBE_MODIFIED_FREQUENTLY flag... But looks like we only set that on
|
|
|
|
// anonymous nodes, so should be fine...
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2006-03-24 06:29:52 +03:00
|
|
|
}
|
2001-12-16 09:59:31 +03:00
|
|
|
|
2013-07-18 07:23:52 +04:00
|
|
|
if (HasFlag(NS_CACHED_TEXT_IS_ONLY_WHITESPACE)) {
|
|
|
|
return HasFlag(NS_TEXT_IS_ONLY_WHITESPACE);
|
|
|
|
}
|
|
|
|
|
2006-03-24 06:29:52 +03:00
|
|
|
const char* cp = mText.Get1b();
|
|
|
|
const char* end = cp + mText.GetLength();
|
2001-12-16 09:59:31 +03:00
|
|
|
|
2006-03-24 06:29:52 +03:00
|
|
|
while (cp < end) {
|
|
|
|
char ch = *cp;
|
2001-12-16 09:59:31 +03:00
|
|
|
|
Bug 1427625: Optimize appends to avoid restyling unnecessarily. r=xidorn
This unfortunately doesn't fix my test-case (because we're replacing the text
content all the time and all that), but it's still worth it, since it fixes the
case we care about (the parser appending).
We could also optimize pure insertions (since in that case we can still figure
out what the old text was), but it's probably annoying and not worth the churn.
In any case, we cannot optimize anything that resembles any kind of removal,
because from there we don't know the old text in any way (and the text nodes
like to reuse string buffers and such).
We could do two other optimizations to replace / extend this one, in that order:
* Pass the buffer and length to CharacterDataWillChange, and use that to get
the exact old text and the new one in RestyleManager. That would make the
optimization exact.
* Pass some sort of Maybe<bool> mWasWhitespace down the CharacterDataChangeInfo
which is computed like:
HasFlag(NS_CACHED_TEXT_IS_ONLY_WHITESPACE)
? Some(NS_TEXT_IS_ONLY_WHITESPACE)
: Nothing()
It's not clear to me it's going to be completely worth the churn, so I haven't
done those yet, if we see code in the wild which resembles my testcase, we can
think of doing it.
MozReview-Commit-ID: 2rTWaZti8rv
--HG--
extra : rebase_source : 7390b8740801eb7b91700bb2533c43c173ac5db9
2018-02-27 19:02:52 +03:00
|
|
|
// NOTE(emilio): If you ever change the definition of "whitespace" here, you
|
|
|
|
// need to change it too in RestyleManager::CharacterDataChanged.
|
2012-11-30 20:04:11 +04:00
|
|
|
if (!dom::IsSpaceCharacter(ch)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
1999-04-01 00:49:25 +04:00
|
|
|
}
|
2006-03-24 06:29:52 +03:00
|
|
|
|
|
|
|
++cp;
|
1999-04-01 00:49:25 +04:00
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2001-12-16 09:59:31 +03:00
|
|
|
}
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
already_AddRefed<nsAtom>
|
2018-03-19 22:18:06 +03:00
|
|
|
CharacterData::GetCurrentValueAtom()
|
2004-02-25 02:10:38 +03:00
|
|
|
{
|
|
|
|
nsAutoString val;
|
|
|
|
GetData(val);
|
2016-03-29 02:09:43 +03:00
|
|
|
return NS_Atomize(val);
|
2004-02-25 02:10:38 +03:00
|
|
|
}
|
2005-11-02 03:41:51 +03:00
|
|
|
|
Bug 1387956 - Overhaul ComputedValues measurement, and add style structs measurement. r=bholley.
This patch moves measurement of ComputedValues objects from Rust to C++.
Measurement now happens (a) via DOM elements and (b) remaining elements via
the frame tree. Likewise for the style structs hanging off ComputedValues
objects.
Here is an example of the output.
> ├──27,600,448 B (26.49%) -- active/window(https://en.wikipedia.org/wiki/Barack_Obama)
> │ ├──12,772,544 B (12.26%) -- layout
> │ │ ├───4,483,744 B (04.30%) -- frames
> │ │ │ ├──1,653,552 B (01.59%) ── nsInlineFrame
> │ │ │ ├──1,415,760 B (01.36%) ── nsTextFrame
> │ │ │ ├────431,376 B (00.41%) ── nsBlockFrame
> │ │ │ ├────340,560 B (00.33%) ── nsHTMLScrollFrame
> │ │ │ ├────302,544 B (00.29%) ── nsContinuingTextFrame
> │ │ │ ├────156,408 B (00.15%) ── nsBulletFrame
> │ │ │ ├─────73,024 B (00.07%) ── nsPlaceholderFrame
> │ │ │ ├─────27,656 B (00.03%) ── sundries
> │ │ │ ├─────23,520 B (00.02%) ── nsTableCellFrame
> │ │ │ ├─────16,704 B (00.02%) ── nsImageFrame
> │ │ │ ├─────15,488 B (00.01%) ── nsTableRowFrame
> │ │ │ ├─────13,776 B (00.01%) ── nsTableColFrame
> │ │ │ └─────13,376 B (00.01%) ── nsTableFrame
> │ │ ├───3,412,192 B (03.28%) -- servo-style-structs
> │ │ │ ├──1,288,224 B (01.24%) ── Display
> │ │ │ ├────742,400 B (00.71%) ── Position
> │ │ │ ├────308,736 B (00.30%) ── Font
> │ │ │ ├────226,512 B (00.22%) ── Background
> │ │ │ ├────218,304 B (00.21%) ── TextReset
> │ │ │ ├────214,896 B (00.21%) ── Text
> │ │ │ ├────130,560 B (00.13%) ── Border
> │ │ │ ├─────81,408 B (00.08%) ── UIReset
> │ │ │ ├─────61,440 B (00.06%) ── Padding
> │ │ │ ├─────38,176 B (00.04%) ── UserInterface
> │ │ │ ├─────29,232 B (00.03%) ── Margin
> │ │ │ ├─────21,824 B (00.02%) ── sundries
> │ │ │ ├─────20,080 B (00.02%) ── Color
> │ │ │ ├─────20,080 B (00.02%) ── Column
> │ │ │ └─────10,320 B (00.01%) ── Effects
> │ │ ├───2,227,680 B (02.14%) -- computed-values
> │ │ │ ├──1,182,928 B (01.14%) ── non-dom
> │ │ │ └──1,044,752 B (01.00%) ── dom
> │ │ ├───1,500,016 B (01.44%) ── text-runs
> │ │ ├─────492,640 B (00.47%) ── line-boxes
> │ │ ├─────326,688 B (00.31%) ── frame-properties
> │ │ ├─────301,760 B (00.29%) ── pres-shell
> │ │ ├──────27,648 B (00.03%) ── pres-contexts
> │ │ └─────────176 B (00.00%) ── style-sets
The 'servo-style-structs' and 'computed-values' sub-trees are new. (Prior to
this patch, ComputedValues under DOM elements were tallied under the the
'dom/element-nodes' sub-tree, and ComputedValues not under DOM element were
ignored.) 'servo-style-structs/sundries' aggregates all the style structs that
are smaller than 8 KiB.
Other notable things done by the patch are as follows.
- It significantly changes the signatures of the methods measuring nsINode and
its subclasses, in order to handle the tallying of style structs separately
from element-nodes. Likewise for nsIFrame.
- It renames the 'layout/style-structs' sub-tree as
'layout/gecko-style-structs', to clearly distinguish it from the new
'layout/servo-style-structs' sub-tree.
- It adds some FFI functions to access various Rust-side data structures from
C++ code.
- There is a nasty hack used twice to measure Arcs, by stepping backwards from
an interior pointer to a base pointer. It works, but I want to replace it
with something better eventually. The "XXX WARNING" comments have details.
- It makes DMD print a line to the console if it sees a pointer it doesn't
recognise. This is useful for detecting when we are measuring an interior
pointer instead of a base pointer, which is bad but easy to do when Arcs are
involved.
- It removes the Rust code for measuring CVs, because it's now all done on the
C++ side.
MozReview-Commit-ID: BKebACLKtCi
--HG--
extra : rebase_source : 4d9a8c6b198a0ff025b811759a6bfa9f33a260ba
2017-08-11 09:37:33 +03:00
|
|
|
void
|
2018-03-19 22:18:06 +03:00
|
|
|
CharacterData::AddSizeOfExcludingThis(nsWindowSizes& aSizes,
|
|
|
|
size_t* aNodeSize) const
|
2011-07-19 21:04:09 +04:00
|
|
|
{
|
2017-08-25 07:47:54 +03:00
|
|
|
nsIContent::AddSizeOfExcludingThis(aSizes, aNodeSize);
|
|
|
|
*aNodeSize += mText.SizeOfExcludingThis(aSizes.mState.mMallocSizeOf);
|
2011-07-19 21:04:09 +04:00
|
|
|
}
|
|
|
|
|
2018-03-19 22:18:06 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|